Skip to content

Commit a0fa3bb

Browse files
committed
[compiler] avoid empty switch case bodies
ghstack-source-id: 6372bbd Pull Request resolved: facebook/react#33179
1 parent 63a015c commit a0fa3bb

File tree

6 files changed

+11
-21
lines changed

6 files changed

+11
-21
lines changed

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ function codegenTerminal(
11831183
? codegenPlaceToExpression(cx, case_.test)
11841184
: null;
11851185
const block = codegenBlock(cx, case_.block!);
1186-
return t.switchCase(test, [block]);
1186+
return t.switchCase(test, block.body.length === 0 ? [] : [block]);
11871187
}),
11881188
);
11891189
}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/block-scoping-switch-variable-scoping.expect.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ function Component(props) {
5050
console.log(handlers.value);
5151
break bb0;
5252
}
53-
default: {
54-
}
53+
default:
5554
}
5655

5756
t0 = handlers;

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/dominator.expect.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ function Component(props) {
6767
case "b": {
6868
break bb1;
6969
}
70-
case "c": {
71-
}
70+
case "c":
7271
default: {
7372
x = 6;
7473
}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reverse-postorder.expect.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ function Component(props) {
5050
case 1: {
5151
break bb0;
5252
}
53-
case 2: {
54-
}
55-
default: {
56-
}
53+
case 2:
54+
default:
5755
}
5856
} else {
5957
if (props.cond2) {

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-switch.expect.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ function foo() {
4141
case 2: {
4242
break bb0;
4343
}
44-
default: {
45-
}
44+
default:
4645
}
4746
}
4847

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/switch-with-fallthrough.expect.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,17 @@ export const FIXTURE_ENTRYPOINT = {
4343
```javascript
4444
function foo(x) {
4545
bb0: switch (x) {
46-
case 0: {
47-
}
48-
case 1: {
49-
}
46+
case 0:
47+
case 1:
5048
case 2: {
5149
break bb0;
5250
}
5351
case 3: {
5452
break bb0;
5553
}
56-
case 4: {
57-
}
58-
case 5: {
59-
}
60-
default: {
61-
}
54+
case 4:
55+
case 5:
56+
default:
6257
}
6358
}
6459

0 commit comments

Comments
 (0)