Specify sourceType "module" in hir-test and playground
This was preventing the playground and fixture tests from being able to compile an ExportDefaultDeclaration
Lauren Tan committed
Jan 23, 2023 at 13:11 UTC
8e08334a42a034a0f06b02c66fbca79e77e9aea5
10 files changed
+140
-152
compiler/forget/packages/playground/components/Editor/Output.tsx
+1
@@ -37,6 +37,7 @@ function parseFunctions(
37
try {
38
const ast = parse(source, {
39
plugins: ["typescript", "jsx"],
40
+ sourceType: "module",
41
});
42
const items: Array<NodePath<t.FunctionDeclaration>> = [];
43
traverse(ast, {
compiler/forget/src/Babel/RunReactForgetBabelPlugin.ts
+2
@@ -18,12 +18,14 @@ export default function runReactForgetBabelPlugin(
18
const ast = parser.parse(text, {
19
sourceFilename: file,
20
plugins: ["typescript", "jsx"],
21
+ sourceType: "module",
22
});
23
const result = transformFromAstSync(ast, text, {
24
filename: file,
25
highlightCode: false,
26
retainLines: true,
27
plugins: [ReactForgetBabelPlugin],
28
+ sourceType: "module",
29
});
30
invariant(
31
result?.code != null,
compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md
+8
-8
@@ -5,7 +5,7 @@
5
/**
6
* props.b does *not* influence `a`
7
*/
8
-function Component(props) {
8
+function ComponentA(props) {
9
const a_DEBUG = [];
10
a_DEBUG.push(props.a);
11
if (props.b) {
@@ -18,7 +18,7 @@ function Component(props) {
18
/**
19
* props.b *does* influence `a`
20
*/
21
-function Component(props) {
21
+function ComponentB(props) {
22
const a = [];
23
a.push(props.a);
24
if (props.b) {
@@ -31,7 +31,7 @@ function Component(props) {
31
/**
32
* props.b *does* influence `a`, but only in a way that is never observable
33
*/
34
-function Component(props) {
34
+function ComponentC(props) {
35
const a = [];
36
a.push(props.a);
37
if (props.b) {
@@ -45,7 +45,7 @@ function Component(props) {
45
/**
46
* props.b *does* influence `a`
47
*/
48
-function Component(props) {
48
+function ComponentD(props) {
49
const a = [];
50
a.push(props.a);
51
if (props.b) {
@@ -64,7 +64,7 @@ function Component(props) {
64
/**
65
* props.b does *not* influence `a`
66
*/
67
-function Component(props) {
67
+function ComponentA(props) {
68
const $ = React.useMemoCache();
69
const c_0 = $[0] !== props.a;
70
const c_1 = $[1] !== props.b;
@@ -91,7 +91,7 @@ function Component(props) {
91
/**
92
* props.b *does* influence `a`
93
*/
94
-function Component(props) {
94
+function ComponentB(props) {
95
const $ = React.useMemoCache();
96
const c_0 = $[0] !== props.a;
97
const c_1 = $[1] !== props.b;
@@ -120,7 +120,7 @@ function Component(props) {
120
/**
121
* props.b *does* influence `a`, but only in a way that is never observable
122
*/
123
-function Component(props) {
123
+function ComponentC(props) {
124
const $ = React.useMemoCache();
125
const c_0 = $[0] !== props.a;
126
const c_1 = $[1] !== props.b;
@@ -150,7 +150,7 @@ function Component(props) {
150
/**
151
* props.b *does* influence `a`
152
*/
153
-function Component(props) {
153
+function ComponentD(props) {
154
const $ = React.useMemoCache();
155
const c_0 = $[0] !== props.a;
156
const c_1 = $[1] !== props.b;
compiler/forget/src/__tests__/fixtures/hir/conditional-break.js
+4
-4
@@ -1,7 +1,7 @@
1
/**
2
* props.b does *not* influence `a`
3
*/
4
-function Component(props) {
4
+function ComponentA(props) {
5
const a_DEBUG = [];
6
a_DEBUG.push(props.a);
7
if (props.b) {
@@ -14,7 +14,7 @@ function Component(props) {
14
/**
15
* props.b *does* influence `a`
16
*/
17
-function Component(props) {
17
+function ComponentB(props) {
18
const a = [];
19
a.push(props.a);
20
if (props.b) {
@@ -27,7 +27,7 @@ function Component(props) {
27
/**
28
* props.b *does* influence `a`, but only in a way that is never observable
29
*/
30
-function Component(props) {
30
+function ComponentC(props) {
31
const a = [];
32
a.push(props.a);
33
if (props.b) {
@@ -41,7 +41,7 @@ function Component(props) {
41
/**
42
* props.b *does* influence `a`
43
*/
44
-function Component(props) {
44
+function ComponentD(props) {
45
const a = [];
46
a.push(props.a);
47
if (props.b) {
compiler/forget/src/__tests__/fixtures/hir/conditional-on-mutable.expect.md
+4
-4
@@ -2,7 +2,7 @@
2
## Input
3
4
```javascript
5
-function Component(props) {
5
+function ComponentA(props) {
6
const a = [];
7
const b = [];
8
if (b) {
@@ -14,7 +14,7 @@ function Component(props) {
14
return <Foo a={a} b={b} />;
15
}
16
17
-function Component(props) {
17
+function ComponentB(props) {
18
const a = [];
19
const b = [];
20
if (mayMutate(b)) {
@@ -34,7 +34,7 @@ function mayMutate() {}
34
## Code
35
36
```javascript
37
-function Component(props) {
37
+function ComponentA(props) {
38
const $ = React.useMemoCache();
39
const c_0 = $[0] !== props.p0;
40
const c_1 = $[1] !== props.p1;
@@ -73,7 +73,7 @@ function Component(props) {
73
return t7;
74
}
75
76
-function Component(props) {
76
+function ComponentB(props) {
77
const $ = React.useMemoCache();
78
const c_0 = $[0] !== props.p0;
79
const c_1 = $[1] !== props.p1;
compiler/forget/src/__tests__/fixtures/hir/conditional-on-mutable.js
+2
-2
@@ -1,4 +1,4 @@
1
-function Component(props) {
1
+function ComponentA(props) {
2
const a = [];
3
const b = [];
4
if (b) {
@@ -10,7 +10,7 @@ function Component(props) {
10
return <Foo a={a} b={b} />;
11
}
12
13
-function Component(props) {
13
+function ComponentB(props) {
14
const a = [];
15
const b = [];
16
if (mayMutate(b)) {
compiler/forget/src/__tests__/fixtures/hir/error.todo-kitchensink.expect.md
+116
-128
@@ -13,9 +13,6 @@ function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
13
}
14
}
15
16
- with (true) {
17
- }
18
-
16
const g = { ...a };
17
const h = [...b];
18
new c(...args);
@@ -91,191 +88,182 @@ function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
88
7 | constructor() {
89
8 | console.log(this.#secretSauce);
90
94
-[ReactForget] TodoError: Unhandled statement type: WithStatement
91
+[ReactForget] TodoError: Handle object property spread
92
10 | }
93
11 |
97
-> 12 | with (true) {
98
- | ^
99
- 13 | }
100
- 14 |
101
- 15 | const g = { ...a };
102
-
103
-[ReactForget] TodoError: Handle object property spread
104
- 13 | }
105
- 14 |
106
-> 15 | const g = { ...a };
94
+> 12 | const g = { ...a };
95
| ^^^^
108
- 16 | const h = [...b];
109
- 17 | new c(...args);
110
- 18 | c(...args);
96
+ 13 | const h = [...b];
97
+ 14 | new c(...args);
98
+ 15 | c(...args);
99
100
[ReactForget] TodoError: Handle non-expression array elements
113
- 14 |
114
- 15 | const g = { ...a };
115
-> 16 | const h = [...b];
101
+ 11 |
102
+ 12 | const g = { ...a };
103
+> 13 | const h = [...b];
104
| ^^^^
117
- 17 | new c(...args);
118
- 18 | c(...args);
119
- 19 | g["e"] += 1;
105
+ 14 | new c(...args);
106
+ 15 | c(...args);
107
+ 16 | g["e"] += 1;
108
109
[ReactForget] TodoError: Support non-expression arguments to NewExpression
122
- 15 | const g = { ...a };
123
- 16 | const h = [...b];
124
-> 17 | new c(...args);
110
+ 12 | const g = { ...a };
111
+ 13 | const h = [...b];
112
+> 14 | new c(...args);
113
| ^^^^^^^
126
- 18 | c(...args);
127
- 19 | g["e"] += 1;
128
- 20 | const [y, ...yy] = useState(0);
114
+ 15 | c(...args);
115
+ 16 | g["e"] += 1;
116
+ 17 | const [y, ...yy] = useState(0);
117
118
[ReactForget] TodoError: Support non-expression arguments to CallExpression
131
- 16 | const h = [...b];
132
- 17 | new c(...args);
133
-> 18 | c(...args);
119
+ 13 | const h = [...b];
120
+ 14 | new c(...args);
121
+> 15 | c(...args);
122
| ^^^^^^^
135
- 19 | g["e"] += 1;
136
- 20 | const [y, ...yy] = useState(0);
137
- 21 | const { z, aa = "aa", ...zz } = useCustom();
123
+ 16 | g["e"] += 1;
124
+ 17 | const [y, ...yy] = useState(0);
125
+ 18 | const { z, aa = "aa", ...zz } = useCustom();
126
127
[ReactForget] TodoError: Assignment expression to dynamic properties is not yet supported
140
- 17 | new c(...args);
141
- 18 | c(...args);
142
-> 19 | g["e"] += 1;
128
+ 14 | new c(...args);
129
+ 15 | c(...args);
130
+> 16 | g["e"] += 1;
131
| ^^^
144
- 20 | const [y, ...yy] = useState(0);
145
- 21 | const { z, aa = "aa", ...zz } = useCustom();
146
- 22 |
132
+ 17 | const [y, ...yy] = useState(0);
133
+ 18 | const { z, aa = "aa", ...zz } = useCustom();
134
+ 19 |
135
136
[ReactForget] TodoError: Rest elements are not supported yet
149
- 18 | c(...args);
150
- 19 | g["e"] += 1;
151
-> 20 | const [y, ...yy] = useState(0);
137
+ 15 | c(...args);
138
+ 16 | g["e"] += 1;
139
+> 17 | const [y, ...yy] = useState(0);
140
| ^^^^^
153
- 21 | const { z, aa = "aa", ...zz } = useCustom();
154
- 22 |
155
- 23 | <Button {...args}></Button>;
141
+ 18 | const { z, aa = "aa", ...zz } = useCustom();
142
+ 19 |
143
+ 20 | <Button {...args}></Button>;
144
145
[ReactForget] TodoError: Support other lvalue types beyond identifier
158
- 19 | g["e"] += 1;
159
- 20 | const [y, ...yy] = useState(0);
160
-> 21 | const { z, aa = "aa", ...zz } = useCustom();
146
+ 16 | g["e"] += 1;
147
+ 17 | const [y, ...yy] = useState(0);
148
+> 18 | const { z, aa = "aa", ...zz } = useCustom();
149
| ^^^^^^^^^
162
- 22 |
163
- 23 | <Button {...args}></Button>;
164
- 24 | <Button xlink:href="localhost:3000"></Button>;
150
+ 19 |
151
+ 20 | <Button {...args}></Button>;
152
+ 21 | <Button xlink:href="localhost:3000"></Button>;
153
154
[ReactForget] TodoError: Rest elements are not supported yet
167
- 19 | g["e"] += 1;
168
- 20 | const [y, ...yy] = useState(0);
169
-> 21 | const { z, aa = "aa", ...zz } = useCustom();
155
+ 16 | g["e"] += 1;
156
+ 17 | const [y, ...yy] = useState(0);
157
+> 18 | const { z, aa = "aa", ...zz } = useCustom();
158
| ^^^^^
171
- 22 |
172
- 23 | <Button {...args}></Button>;
173
- 24 | <Button xlink:href="localhost:3000"></Button>;
159
+ 19 |
160
+ 20 | <Button {...args}></Button>;
161
+ 21 | <Button xlink:href="localhost:3000"></Button>;
162
163
[ReactForget] TodoError: Handle spread attributes
176
- 21 | const { z, aa = "aa", ...zz } = useCustom();
177
- 22 |
178
-> 23 | <Button {...args}></Button>;
164
+ 18 | const { z, aa = "aa", ...zz } = useCustom();
165
+ 19 |
166
+> 20 | <Button {...args}></Button>;
167
| ^^^^^^^^^
180
- 24 | <Button xlink:href="localhost:3000"></Button>;
181
- 25 | <Button haha={1}></Button>;
182
- 26 | <Button>{/** empty */}</Button>;
168
+ 21 | <Button xlink:href="localhost:3000"></Button>;
169
+ 22 | <Button haha={1}></Button>;
170
+ 23 | <Button>{/** empty */}</Button>;
171
172
[ReactForget] TodoError: Handle non-identifier jsx attribute names
185
- 22 |
186
- 23 | <Button {...args}></Button>;
187
-> 24 | <Button xlink:href="localhost:3000"></Button>;
173
+ 19 |
174
+ 20 | <Button {...args}></Button>;
175
+> 21 | <Button xlink:href="localhost:3000"></Button>;
176
| ^^^^^^^^^^
189
- 25 | <Button haha={1}></Button>;
190
- 26 | <Button>{/** empty */}</Button>;
191
- 27 | <DesignSystem.Button />;
177
+ 22 | <Button haha={1}></Button>;
178
+ 23 | <Button>{/** empty */}</Button>;
179
+ 24 | <DesignSystem.Button />;
180
181
[ReactForget] TodoError: Handle empty expressions
194
- 24 | <Button xlink:href="localhost:3000"></Button>;
195
- 25 | <Button haha={1}></Button>;
196
-> 26 | <Button>{/** empty */}</Button>;
182
+ 21 | <Button xlink:href="localhost:3000"></Button>;
183
+ 22 | <Button haha={1}></Button>;
184
+> 23 | <Button>{/** empty */}</Button>;
185
| ^^^^^^^^^^^^
198
- 27 | <DesignSystem.Button />;
199
- 28 |
200
- 29 | const j = function bar([quz, qux], ...args) {};
186
+ 24 | <DesignSystem.Button />;
187
+ 25 |
188
+ 26 | const j = function bar([quz, qux], ...args) {};
189
190
[ReactForget] TodoError: Handle non-identifier tags
203
- 25 | <Button haha={1}></Button>;
204
- 26 | <Button>{/** empty */}</Button>;
205
-> 27 | <DesignSystem.Button />;
191
+ 22 | <Button haha={1}></Button>;
192
+ 23 | <Button>{/** empty */}</Button>;
193
+> 24 | <DesignSystem.Button />;
194
| ^^^^^^^^^^^^^^^^^^^
207
- 28 |
208
- 29 | const j = function bar([quz, qux], ...args) {};
209
- 30 |
195
+ 25 |
196
+ 26 | const j = function bar([quz, qux], ...args) {};
197
+ 27 |
198
199
[ReactForget] TodoError: Support non-identifier params: ArrayPattern
212
- 27 | <DesignSystem.Button />;
213
- 28 |
214
-> 29 | const j = function bar([quz, qux], ...args) {};
200
+ 24 | <DesignSystem.Button />;
201
+ 25 |
202
+> 26 | const j = function bar([quz, qux], ...args) {};
203
| ^^^^^^^^^^
216
- 30 |
217
- 31 | for (; i < 3; i += 1) {
218
- 32 | x.push(i);
204
+ 27 |
205
+ 28 | for (; i < 3; i += 1) {
206
+ 29 | x.push(i);
207
208
[ReactForget] TodoError: Support non-identifier params: RestElement
221
- 27 | <DesignSystem.Button />;
222
- 28 |
223
-> 29 | const j = function bar([quz, qux], ...args) {};
209
+ 24 | <DesignSystem.Button />;
210
+ 25 |
211
+> 26 | const j = function bar([quz, qux], ...args) {};
212
| ^^^^^^^
225
- 30 |
226
- 31 | for (; i < 3; i += 1) {
227
- 32 | x.push(i);
213
+ 27 |
214
+ 28 | for (; i < 3; i += 1) {
215
+ 29 | x.push(i);
216
217
[ReactForget] TodoError: Support non-variable initialization in for
230
- 29 | const j = function bar([quz, qux], ...args) {};
231
- 30 |
232
-> 31 | for (; i < 3; i += 1) {
218
+ 26 | const j = function bar([quz, qux], ...args) {};
219
+ 27 |
220
+> 28 | for (; i < 3; i += 1) {
221
| ^
234
- 32 | x.push(i);
235
- 33 | }
236
- 34 | for (; i < 3; ) {}
222
+ 29 | x.push(i);
223
+ 30 | }
224
+ 31 | for (; i < 3; ) {}
225
226
[ReactForget] TodoError: Support non-variable initialization in for
239
- 32 | x.push(i);
240
- 33 | }
241
-> 34 | for (; i < 3; ) {}
227
+ 29 | x.push(i);
228
+ 30 | }
229
+> 31 | for (; i < 3; ) {}
230
| ^^^^^^^^^^^^^^^^^^
243
- 35 | for (;;) {}
244
- 36 | }
245
- 37 |
231
+ 32 | for (;;) {}
232
+ 33 | }
233
+ 34 |
234
235
[ReactForget] TodoError: Handle empty for updater
248
- 32 | x.push(i);
249
- 33 | }
250
-> 34 | for (; i < 3; ) {}
236
+ 29 | x.push(i);
237
+ 30 | }
238
+> 31 | for (; i < 3; ) {}
239
| ^^^^^^^^^^^^^^^^^^
252
- 35 | for (;;) {}
253
- 36 | }
254
- 37 |
240
+ 32 | for (;;) {}
241
+ 33 | }
242
+ 34 |
243
244
[ReactForget] TodoError: Support non-variable initialization in for
257
- 33 | }
258
- 34 | for (; i < 3; ) {}
259
-> 35 | for (;;) {}
245
+ 30 | }
246
+ 31 | for (; i < 3; ) {}
247
+> 32 | for (;;) {}
248
| ^^^^^^^^^^^
261
- 36 | }
262
- 37 |
249
+ 33 | }
250
+ 34 |
251
252
[ReactForget] TodoError: Handle empty for updater
265
- 33 | }
266
- 34 | for (; i < 3; ) {}
267
-> 35 | for (;;) {}
253
+ 30 | }
254
+ 31 | for (; i < 3; ) {}
255
+> 32 | for (;;) {}
256
| ^^^^^^^^^^^
269
- 36 | }
270
- 37 |
257
+ 33 | }
258
+ 34 |
259
260
[ReactForget] TodoError: ForStatement without test
273
- 33 | }
274
- 34 | for (; i < 3; ) {}
275
-> 35 | for (;;) {}
261
+ 30 | }
262
+ 31 | for (; i < 3; ) {}
263
+> 32 | for (;;) {}
264
| ^^^^^^^^^^^
277
- 36 | }
278
- 37 |
265
+ 33 | }
266
+ 34 |
267
```
268
269
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/error.todo-kitchensink.js
-3
@@ -9,9 +9,6 @@ function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
9
}
10
}
11
12
- with (true) {
13
- }
14
-
12
const g = { ...a };
13
const h = [...b];
14
new c(...args);
compiler/forget/src/__tests__/fixtures/hir/simple.expect.md
+2
-2
@@ -2,7 +2,7 @@
2
## Input
3
4
```javascript
5
-function foo(x, y) {
5
+export default function foo(x, y) {
6
if (x) {
7
return foo(false, y);
8
}
@@ -14,7 +14,7 @@ function foo(x, y) {
14
## Code
15
16
```javascript
17
-function foo(x, y) {
17
+export default function foo(x, y) {
18
const $ = React.useMemoCache();
19
if (x) {
20
const c_0 = $[0] !== y;
compiler/forget/src/__tests__/fixtures/hir/simple.js
+1
-1
@@ -1,4 +1,4 @@
1
-function foo(x, y) {
1
+export default function foo(x, y) {
2
if (x) {
3
return foo(false, y);
4
}