-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Correctly insert (Arrow)FunctionExpressions
Previously we would insert new (Arrow)FunctionExpressions as a sibling of the original function. However this would break in the outlining case as it would cause the original function expression's parent to become a SequenceExpression, breaking a bunch of assumptions in the babel plugin. To get around this, we synthesize a new VariableDeclaration to contain the newly inserted function expression and therefore insert it as a true sibling to the original function. Yeah, it's kinda gross ghstack-source-id: aefc2cdb2fa1b2f17fc6b9e5fc22b57ded78fd34 Pull Request resolved: #30446
- Loading branch information
Showing
4 changed files
with
138 additions
and
28 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
24 changes: 0 additions & 24 deletions
24
...iler/src/__tests__/fixtures/compiler/error.bug-outlining-in-func-expr.expect.md
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
...react-compiler/src/__tests__/fixtures/compiler/outlining-in-func-expr.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,49 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @debug | ||
const Component2 = props => { | ||
return ( | ||
<ul> | ||
{props.items.map(item => ( | ||
<li key={item.id}>{item.name}</li> | ||
))} | ||
</ul> | ||
); | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @debug | ||
const Component2 = (props) => { | ||
const $ = _c(4); | ||
let t0; | ||
if ($[0] !== props.items) { | ||
t0 = props.items.map(_temp); | ||
$[0] = props.items; | ||
$[1] = t0; | ||
} else { | ||
t0 = $[1]; | ||
} | ||
let t1; | ||
if ($[2] !== t0) { | ||
t1 = <ul>{t0}</ul>; | ||
$[2] = t0; | ||
$[3] = t1; | ||
} else { | ||
t1 = $[3]; | ||
} | ||
return t1; | ||
}; | ||
const _temp = (item) => { | ||
return <li key={item.id}>{item.name}</li>; | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: exception) Fixture not implemented |
1 change: 1 addition & 0 deletions
1
...piler/error.bug-outlining-in-func-expr.js → ...xtures/compiler/outlining-in-func-expr.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @debug | ||
const Component2 = props => { | ||
return ( | ||
<ul> | ||
|