-
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: 8a458917c1c314c5b94426238e9d9575e0b71e69 Pull Request resolved: #30446
- Loading branch information
Showing
4 changed files
with
137 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.
48 changes: 48 additions & 0 deletions
48
...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,48 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
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"; | ||
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 |
File renamed without changes.