mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[test] Add test for broken lambda capturing
SSA redefines context refs which breaks our inference. The correct fix here is to not overwrite context refs in EnterSSA.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function component(a) {
|
||||
let x = { a };
|
||||
let y;
|
||||
(function () {
|
||||
y = x;
|
||||
})();
|
||||
mutate(y);
|
||||
return y;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
function component(a) {
|
||||
const $ = React.unstable_useMemoCache();
|
||||
const c_0 = $[0] !== a;
|
||||
let x;
|
||||
if (c_0) {
|
||||
x = { a: a };
|
||||
$[0] = a;
|
||||
$[1] = x;
|
||||
} else {
|
||||
x = $[1];
|
||||
}
|
||||
const y = undefined;
|
||||
(function () {
|
||||
y = x;
|
||||
})();
|
||||
mutate(y);
|
||||
return y;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
function component(a) {
|
||||
let x = { a };
|
||||
let y;
|
||||
(function () {
|
||||
y = x;
|
||||
})();
|
||||
mutate(y);
|
||||
return y;
|
||||
}
|
||||
Reference in New Issue
Block a user