@samitouri / QOS-React-2 / commits / f0b8cfbf25

More concise output for labeled blocks

Joe Savona committed May 17, 2023 at 15:55 UTC f0b8cfbf254fd89a4ce2202b0ea5bd65123884b1
5 files changed +40 -49
compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+5 -4
@@ -125,11 +125,12 @@ function codegenBlock(cx: Context, block: ReactiveBlock): t.BlockStatement {
125 break;
126 }
127 if (item.label !== null) {
128 + const block =
129 + statement.type === "BlockStatement" && statement.body.length === 1
130 + ? statement.body[0]
131 + : statement;
132 statements.push(
129 - t.labeledStatement(
130 - t.identifier(codegenLabel(item.label)),
131 - statement
132 - )
133 + t.labeledStatement(t.identifier(codegenLabel(item.label)), block)
134 );
135 } else if (statement.type === "BlockStatement") {
136 statements.push(...statement.body);
compiler/forget/src/__tests__/fixtures/compiler/complex-while.expect.md
+4 -6
@@ -19,12 +19,10 @@ function foo(a, b, c) {
19
20 ```javascript
21 function foo(a, b, c) {
22 - bb1: {
23 - if (a) {
24 - while (b) {
25 - if (c) {
26 - break bb1;
27 - }
22 + bb1: if (a) {
23 + while (b) {
24 + if (c) {
25 + break bb1;
26 }
27 }
28 }
compiler/forget/src/__tests__/fixtures/compiler/dominator.expect.md
+18 -22
@@ -43,31 +43,27 @@ function Component(props) {
43 ```javascript
44 function Component(props) {
45 let x = 0;
46 - bb1: {
47 - if (props.a) {
48 - x = 1;
46 + bb1: if (props.a) {
47 + x = 1;
48 + } else {
49 + if (props.b) {
50 + x = 3;
51 } else {
50 - if (props.b) {
51 - x = 3;
52 - } else {
53 - break bb1;
54 - }
52 + break bb1;
53 }
54 }
57 - bb10: {
58 - bb12: switch (props.c) {
59 - case "a": {
60 - x = 4;
61 - break bb12;
62 - }
63 - case "b": {
64 - break bb10;
65 - }
66 - case "c": {
67 - }
68 - default: {
69 - x = 6;
70 - }
55 + bb10: bb12: switch (props.c) {
56 + case "a": {
57 + x = 4;
58 + break bb12;
59 + }
60 + case "b": {
61 + break bb10;
62 + }
63 + case "c": {
64 + }
65 + default: {
66 + x = 6;
67 }
68 }
69 if (props.d) {
compiler/forget/src/__tests__/fixtures/compiler/inverted-if.expect.md
+6 -8
@@ -29,15 +29,13 @@ function foo(a, b, c, d) {
29 let y;
30 if (c_0 || c_1 || c_2 || c_3) {
31 y = [];
32 - bb1: {
33 - if (a) {
34 - if (b) {
35 - y.push(c);
36 - break bb1;
37 - }
38 -
39 - y.push(d);
32 + bb1: if (a) {
33 + if (b) {
34 + y.push(c);
35 + break bb1;
36 }
37 +
38 + y.push(d);
39 }
40 $[0] = a;
41 $[1] = b;
compiler/forget/src/__tests__/fixtures/compiler/useMemo-switch-no-fallthrough.expect.md
+7 -9
@@ -23,15 +23,13 @@ function Component(props) {
23 ```javascript
24 function Component(props) {
25 let t18 = undefined;
26 - bb8: {
27 - switch (props.key) {
28 - case "key": {
29 - t18 = props.value;
30 - break bb8;
31 - }
32 - default: {
33 - t18 = props.defaultValue;
34 - }
26 + bb8: switch (props.key) {
27 + case "key": {
28 + t18 = props.value;
29 + break bb8;
30 + }
31 + default: {
32 + t18 = props.defaultValue;
33 }
34 }
35 const x = t18;