mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[λ] Re run SSA on function expr
Functions can capture variables declared after the definition of the function. This re runs SSA to map the captured identifiers to the new SSA identifiers if available.
This commit is contained in:
@@ -226,4 +226,12 @@ export default function enterSSA(func: HIRFunction) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const [_, block] of func.body.blocks) {
|
||||
for (const instr of block.instructions) {
|
||||
if (instr.value.kind === "FunctionExpression") {
|
||||
mapInstructionOperands(instr, (place) => builder.getPlace(place));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function component(a) {
|
||||
let y = function () {
|
||||
m(x);
|
||||
};
|
||||
|
||||
let x = { a };
|
||||
m(x);
|
||||
return y;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
function component(a) {
|
||||
const $ = React.useMemoCache();
|
||||
let y;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
y = function () {
|
||||
m(x);
|
||||
};
|
||||
$[0] = y;
|
||||
} else {
|
||||
y = $[0];
|
||||
}
|
||||
|
||||
const x = { a: a };
|
||||
m(x);
|
||||
return y;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
function component(a) {
|
||||
let y = function () {
|
||||
m(x);
|
||||
};
|
||||
|
||||
let x = { a };
|
||||
m(x);
|
||||
return y;
|
||||
}
|
||||
Reference in New Issue
Block a user