mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +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:
1 parent
123d024af7
commit
3927281fe4
3 files changed
+55
No files matched your search
@@ -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