[hir] Remove broken support for ForOf, ForIn, DoWhile
Sathya Gunasekaran committed
Jan 30, 2023 at 19:12 UTC
04fb507876eb1f86045c44777ef20a87fc73c951
4 files changed
+56
-141
compiler/forget/src/HIR/BuildHIR.ts
+3
-138
@@ -244,108 +244,6 @@ function lowerStatement(
244
);
245
return;
246
}
247
- case "ForInStatement": {
248
- const stmt = stmtPath as NodePath<t.ForInStatement>;
249
- // Block used to evaluate whether to (re)enter or exit the loop
250
- const conditionalBlock = builder.reserve("block");
251
- // Block for code following the loop
252
- const continuationBlock = builder.reserve("block");
253
- const loopBlock = builder.enter("block", (blockId) => {
254
- return builder.loop(
255
- label,
256
- conditionalBlock.id,
257
- continuationBlock.id,
258
- () => {
259
- lowerStatement(builder, stmt.get("body"));
260
- return {
261
- kind: "goto",
262
- block: conditionalBlock.id,
263
- variant: GotoVariant.Continue,
264
- id: makeInstructionId(0),
265
- };
266
- }
267
- );
268
- });
269
- // End the block leading up to the loop and jump to the conditional block
270
- builder.terminateWithContinuation(
271
- {
272
- kind: "goto",
273
- block: conditionalBlock.id,
274
- variant: GotoVariant.Break,
275
- id: makeInstructionId(0),
276
- },
277
- conditionalBlock
278
- );
279
- /**
280
- * Terminate the conditional block using the <right> value as the test condition:
281
- * this conceptually represents that the value of <right> influences which branch
282
- * is taken (if it has properties enter the loop, if no properties exit to the continuation)
283
- */
284
- const test = lowerExpressionToPlace(builder, stmt.get("right"));
285
- const terminal: IfTerminal = {
286
- kind: "if",
287
- test,
288
- consequent: loopBlock,
289
- alternate: continuationBlock.id,
290
- fallthrough: continuationBlock.id,
291
- id: makeInstructionId(0),
292
- };
293
- builder.terminateWithContinuation(terminal, continuationBlock);
294
- return;
295
- }
296
- case "ForOfStatement": {
297
- const stmt = stmtPath as NodePath<t.ForOfStatement>;
298
- // Block used to evaluate whether to (re)enter or exit the loop
299
- const conditionalBlock = builder.reserve("block");
300
- // Block for code following the loop
301
- const continuationBlock = builder.reserve("block");
302
- /**
303
- * Build the loop body, each iteration loops back to the conditional block
304
- * to check whether to continue or exit
305
- */
306
- const loopBlock = builder.enter("block", (blockId) => {
307
- return builder.loop(
308
- label,
309
- conditionalBlock.id,
310
- continuationBlock.id,
311
- () => {
312
- lowerStatement(builder, stmt.get("body"));
313
- return {
314
- kind: "goto",
315
- block: conditionalBlock.id,
316
- variant: GotoVariant.Continue,
317
- id: makeInstructionId(0),
318
- };
319
- }
320
- );
321
- });
322
- // End the block leading up to the loop and jump to the conditional block
323
- builder.terminateWithContinuation(
324
- {
325
- kind: "goto",
326
- block: conditionalBlock.id,
327
- variant: GotoVariant.Break,
328
- id: makeInstructionId(0),
329
- },
330
- conditionalBlock
331
- );
332
- /**
333
- * Terminate the conditional block using the <right> value as the test condition:
334
- * this conceptually represents that the value of <right> influences which branch
335
- * is taken (even though it isn't actually a boolean check in practice)
336
- */
337
- const test = lowerExpressionToPlace(builder, stmt.get("right"));
338
- const terminal: IfTerminal = {
339
- kind: "if",
340
- test,
341
- consequent: loopBlock,
342
- alternate: continuationBlock.id,
343
- fallthrough: continuationBlock.id,
344
- id: makeInstructionId(0),
345
- };
346
- builder.terminateWithContinuation(terminal, continuationBlock);
347
- return;
348
- }
247
case "ForStatement": {
248
const stmt = stmtPath as NodePath<t.ForStatement>;
249
@@ -441,42 +339,6 @@ function lowerStatement(
339
}
340
return;
341
}
444
- case "DoWhileStatement": {
445
- const stmt = stmtPath as NodePath<t.DoWhileStatement>;
446
- // Block for code following the loop
447
- const continuationBlock = builder.reserve("block");
448
- // Loop body
449
- const loopBlock = builder.enter("block", (loopBlock) => {
450
- return builder.loop(label, loopBlock, continuationBlock.id, () => {
451
- lowerStatement(builder, stmt.get("body"));
452
- /**
453
- * the loop terminates with the while condition, either looping
454
- * around (consequent) or exiting to the continuation (alternate)
455
- */
456
- const test = lowerExpressionToPlace(builder, stmt.get("test"));
457
- const terminal: IfTerminal = {
458
- kind: "if",
459
- test,
460
- consequent: loopBlock,
461
- alternate: continuationBlock.id,
462
- fallthrough: continuationBlock.id,
463
- id: makeInstructionId(0),
464
- };
465
- return terminal;
466
- });
467
- });
468
- // do-while unconditionally enters the loop
469
- builder.terminateWithContinuation(
470
- {
471
- kind: "goto",
472
- block: loopBlock,
473
- variant: GotoVariant.Break,
474
- id: makeInstructionId(0),
475
- },
476
- continuationBlock
477
- );
478
- return;
479
- }
342
case "WhileStatement": {
343
const stmt = stmtPath as NodePath<t.WhileStatement>;
344
// Block used to evaluate whether to (re)enter or exit the loop
@@ -726,6 +588,9 @@ function lowerStatement(
588
});
589
return;
590
}
591
+ case "ForOfStatement":
592
+ case "ForInStatement":
593
+ case "DoWhileStatement":
594
case "ClassDeclaration":
595
case "DebuggerStatement":
596
case "DeclareClass":
compiler/forget/src/__tests__/fixtures/hir/error.ssa-for-of.expect.md
+8
-1
@@ -19,7 +19,14 @@ function foo(cond) {
19
## Error
20
21
```
22
-Expected a break target
22
+[ReactForget] TodoError: (BuildHIR::lowerStatement) Handle ForOfStatement statements
23
+ 1 | function foo(cond) {
24
+ 2 | let items = [];
25
+> 3 | for (const item of items) {
26
+ | ^
27
+ 4 | let y = 0;
28
+ 5 | if (cond) {
29
+ 6 | y = 1;
30
```
31
32
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/error.todo-kitchensink.expect.md
+37
-2
@@ -44,6 +44,14 @@ function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
44
`;
45
46
graphql`\\t\n`;
47
+
48
+ for (const c of [1, 2]) {
49
+ }
50
+
51
+ for (let x in { a: 1 }) {
52
+ }
53
+
54
+ do {} while (i < 3);
55
}
56
57
```
@@ -301,8 +309,35 @@ function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
309
41 |
310
> 42 | graphql`\\t\n`;
311
| ^^^^^^^^^^^^^^
304
- 43 | }
305
- 44 |
312
+ 43 |
313
+ 44 | for (const c of [1, 2]) {
314
+ 45 | }
315
+
316
+[ReactForget] TodoError: (BuildHIR::lowerStatement) Handle ForOfStatement statements
317
+ 42 | graphql`\\t\n`;
318
+ 43 |
319
+> 44 | for (const c of [1, 2]) {
320
+ | ^
321
+ 45 | }
322
+ 46 |
323
+ 47 | for (let x in { a: 1 }) {
324
+
325
+[ReactForget] TodoError: (BuildHIR::lowerStatement) Handle ForInStatement statements
326
+ 45 | }
327
+ 46 |
328
+> 47 | for (let x in { a: 1 }) {
329
+ | ^
330
+ 48 | }
331
+ 49 |
332
+ 50 | do {} while (i < 3);
333
+
334
+[ReactForget] TodoError: (BuildHIR::lowerStatement) Handle DoWhileStatement statements
335
+ 48 | }
336
+ 49 |
337
+> 50 | do {} while (i < 3);
338
+ | ^^^^^^^^^^^^^^^^^^^^
339
+ 51 | }
340
+ 52 |
341
```
342
343
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/error.todo-kitchensink.js
+8
@@ -40,4 +40,12 @@ function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
40
`;
41
42
graphql`\\t\n`;
43
+
44
+ for (const c of [1, 2]) {
45
+ }
46
+
47
+ for (let x in { a: 1 }) {
48
+ }
49
+
50
+ do {} while (i < 3);
51
}