Skip to content

Commit 3ed4a12

Browse files
authored
fix(es/minifier): Remove the last break in the second switch (#10923)
**Related issue:** - Closes #10918
1 parent 9d55e88 commit 3ed4a12

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

.changeset/strong-eagles-own.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_ecma_minifier: patch
3+
swc_core: patch
4+
---
5+
6+
Draft: fix: remove last break in the 2nd case when turning 2 cases switch in…

crates/swc_ecma_minifier/src/compress/pure/switches.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ impl Pure<'_> {
524524

525525
if terminate {
526526
remove_last_break(&mut first.cons);
527+
remove_last_break(&mut second.cons);
527528
// they cannot both be default as that's syntax error
528529
let (def, case) = if first.test.is_none() {
529530
(first, second)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useState } from "react";
2+
import { getCondition, doSomething } from "./utils";
3+
4+
export default function useMeow() {
5+
const [state, setState] = useState("init");
6+
const onMeow = async () => {
7+
switch (state) {
8+
case "init": {
9+
const innerCondition = getCondition();
10+
switch (innerCondition) {
11+
case "a":
12+
break;
13+
case "b":
14+
break;
15+
default:
16+
await doSomething();
17+
}
18+
break;
19+
}
20+
default: {
21+
await doSomething();
22+
break;
23+
}
24+
}
25+
};
26+
return {
27+
onMeow,
28+
};
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { useState } from "react";
2+
import { getCondition, doSomething } from "./utils";
3+
export default function useMeow() {
4+
const [state, setState] = useState("init");
5+
return {
6+
onMeow: async ()=>{
7+
if ("init" === state) switch(getCondition()){
8+
case "a":
9+
case "b":
10+
break;
11+
default:
12+
await doSomething();
13+
}
14+
else await doSomething();
15+
}
16+
};
17+
}

0 commit comments

Comments
 (0)