diff --git a/compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts b/compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts index 473dbb8906..6a3efc78f8 100644 --- a/compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts +++ b/compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts @@ -125,11 +125,12 @@ function codegenBlock(cx: Context, block: ReactiveBlock): t.BlockStatement { break; } if (item.label !== null) { + const block = + statement.type === "BlockStatement" && statement.body.length === 1 + ? statement.body[0] + : statement; statements.push( - t.labeledStatement( - t.identifier(codegenLabel(item.label)), - statement - ) + t.labeledStatement(t.identifier(codegenLabel(item.label)), block) ); } else if (statement.type === "BlockStatement") { statements.push(...statement.body); diff --git a/compiler/forget/src/__tests__/fixtures/compiler/complex-while.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/complex-while.expect.md index 882a9b0aeb..a057850476 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/complex-while.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/complex-while.expect.md @@ -19,12 +19,10 @@ function foo(a, b, c) { ```javascript function foo(a, b, c) { - bb1: { - if (a) { - while (b) { - if (c) { - break bb1; - } + bb1: if (a) { + while (b) { + if (c) { + break bb1; } } } diff --git a/compiler/forget/src/__tests__/fixtures/compiler/dominator.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/dominator.expect.md index cfa5fe6c71..e9035aa273 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/dominator.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/dominator.expect.md @@ -43,31 +43,27 @@ function Component(props) { ```javascript function Component(props) { let x = 0; - bb1: { - if (props.a) { - x = 1; + bb1: if (props.a) { + x = 1; + } else { + if (props.b) { + x = 3; } else { - if (props.b) { - x = 3; - } else { - break bb1; - } + break bb1; } } - bb10: { - bb12: switch (props.c) { - case "a": { - x = 4; - break bb12; - } - case "b": { - break bb10; - } - case "c": { - } - default: { - x = 6; - } + bb10: bb12: switch (props.c) { + case "a": { + x = 4; + break bb12; + } + case "b": { + break bb10; + } + case "c": { + } + default: { + x = 6; } } if (props.d) { diff --git a/compiler/forget/src/__tests__/fixtures/compiler/inverted-if.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/inverted-if.expect.md index e3b16d7f6e..b366f43557 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/inverted-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/inverted-if.expect.md @@ -29,15 +29,13 @@ function foo(a, b, c, d) { let y; if (c_0 || c_1 || c_2 || c_3) { y = []; - bb1: { - if (a) { - if (b) { - y.push(c); - break bb1; - } - - y.push(d); + bb1: if (a) { + if (b) { + y.push(c); + break bb1; } + + y.push(d); } $[0] = a; $[1] = b; diff --git a/compiler/forget/src/__tests__/fixtures/compiler/useMemo-switch-no-fallthrough.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/useMemo-switch-no-fallthrough.expect.md index e6bbc878ef..25f584d49e 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/useMemo-switch-no-fallthrough.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/useMemo-switch-no-fallthrough.expect.md @@ -23,15 +23,13 @@ function Component(props) { ```javascript function Component(props) { let t18 = undefined; - bb8: { - switch (props.key) { - case "key": { - t18 = props.value; - break bb8; - } - default: { - t18 = props.defaultValue; - } + bb8: switch (props.key) { + case "key": { + t18 = props.value; + break bb8; + } + default: { + t18 = props.defaultValue; } } const x = t18;