-
Notifications
You must be signed in to change notification settings - Fork 47.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Allow hoisting of destructured variable declarations
Summary: It doesn't seem as though this invariant was necessary ghstack-source-id: b27e76525911d5cfc1991b5cfdb7b2074c039e21 Pull Request resolved: #30699
- Loading branch information
Showing
3 changed files
with
79 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...-plugin-react-compiler/src/__tests__/fixtures/compiler/hoist-destruct.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
//@flow | ||
component Foo() { | ||
function foo() { | ||
return ( | ||
<div> | ||
{a} {z} {y} | ||
</div> | ||
); | ||
} | ||
const [a, {x: z, y = 10}] = [1, {x: 2}]; | ||
return foo(); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
function Foo() { | ||
const $ = _c(1); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
const foo = function foo() { | ||
return ( | ||
<div> | ||
{a} {z} {y} | ||
</div> | ||
); | ||
}; | ||
|
||
const [t1, t2] = [1, { x: 2 }]; | ||
const a = t1; | ||
const { x: t3, y: t4 } = t2; | ||
const z = t3; | ||
const y = t4 === undefined ? 10 : t4; | ||
t0 = foo(); | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
return t0; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) <div>1 2 10</div> |
17 changes: 17 additions & 0 deletions
17
...er/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoist-destruct.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//@flow | ||
component Foo() { | ||
function foo() { | ||
return ( | ||
<div> | ||
{a} {z} {y} | ||
</div> | ||
); | ||
} | ||
const [a, {x: z, y = 10}] = [1, {x: 2}]; | ||
return foo(); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [], | ||
}; |