mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +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:
1 parent
b56f413e99
commit
7277897405
2 files changed
+49
No files matched your search
@@ -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