[λ] Add test for nested function declaration that captures a var
Sathya Gunasekaran committed
Jan 14, 2023 at 10:19 UTC
ab6a1dbbd430a61f95ec0d239ea99f114a554ee7
2 files changed
+67
compiler/forget/src/__tests__/fixtures/hir/capturing-var-in-nested-func-decl.expect.md
new
+57
@@ -0,0 +1,57 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function component(a) {
6
+ let z = { a };
7
+ let x = function () {
8
+ function t() {
9
+ z;
10
+ }
11
+ t();
12
+ };
13
+ return x;
14
+}
15
+
16
+```
17
+
18
+## Code
19
+
20
+```javascript
21
+function component(a) {
22
+ const $ = React.useMemoCache();
23
+ const c_0 = $[0] !== a;
24
+ let z;
25
+ if (c_0) {
26
+ z = {
27
+ a: a,
28
+ };
29
+ $[0] = a;
30
+ $[1] = z;
31
+ } else {
32
+ z = $[1];
33
+ }
34
+
35
+ const c_2 = $[2] !== z;
36
+ let x;
37
+
38
+ if (c_2) {
39
+ x = function () {
40
+ function t() {
41
+ z;
42
+ }
43
+
44
+ t();
45
+ };
46
+
47
+ $[2] = z;
48
+ $[3] = x;
49
+ } else {
50
+ x = $[3];
51
+ }
52
+
53
+ return x;
54
+}
55
+
56
+```
57
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/capturing-var-in-nested-func-decl.js
new
+10
@@ -0,0 +1,10 @@
1
+function component(a) {
2
+ let z = { a };
3
+ let x = function () {
4
+ function t() {
5
+ z;
6
+ }
7
+ t();
8
+ };
9
+ return x;
10
+}