mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[λ] Add test for nested function declaration that captures a var
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function component(a) {
|
||||
let z = { a };
|
||||
let x = function () {
|
||||
function t() {
|
||||
z;
|
||||
}
|
||||
t();
|
||||
};
|
||||
return x;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
function component(a) {
|
||||
const $ = React.useMemoCache();
|
||||
const c_0 = $[0] !== a;
|
||||
let z;
|
||||
if (c_0) {
|
||||
z = {
|
||||
a: a,
|
||||
};
|
||||
$[0] = a;
|
||||
$[1] = z;
|
||||
} else {
|
||||
z = $[1];
|
||||
}
|
||||
|
||||
const c_2 = $[2] !== z;
|
||||
let x;
|
||||
|
||||
if (c_2) {
|
||||
x = function () {
|
||||
function t() {
|
||||
z;
|
||||
}
|
||||
|
||||
t();
|
||||
};
|
||||
|
||||
$[2] = z;
|
||||
$[3] = x;
|
||||
} else {
|
||||
x = $[3];
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
function component(a) {
|
||||
let z = { a };
|
||||
let x = function () {
|
||||
function t() {
|
||||
z;
|
||||
}
|
||||
t();
|
||||
};
|
||||
return x;
|
||||
}
|
||||
Reference in New Issue
Block a user