-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/minifier): Handle switch cases (#8854)
**Related issue:** - Closes #8813
- Loading branch information
1 parent
fcc82a5
commit 7a89e5d
Showing
6 changed files
with
161 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
crates/swc_ecma_minifier/tests/fixture/issues/8813/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const k1 = (() => { | ||
const x = 'asdf'; | ||
let y = "PASS 1"; | ||
switch (x) { | ||
case x: | ||
default: | ||
case y = "FAIL": | ||
} | ||
console.log(y); | ||
})(); | ||
|
||
const k2 = (() => { | ||
const x = 'asdf'; | ||
let y = "PASS 2"; | ||
switch (x) { | ||
case x: | ||
case y = "FAIL": | ||
default: | ||
} | ||
console.log(y); | ||
})(); | ||
|
||
const k3 = (() => { | ||
const x = 'asdf'; | ||
let y = "FAIL"; | ||
switch (x) { | ||
case (y = "PASS 3", x): | ||
default: | ||
} | ||
console.log(y); | ||
})(); | ||
|
||
const k4 = (() => { | ||
const x = 'asdf'; | ||
let y = "FAIL"; | ||
switch (x) { | ||
case y = "PASS 4": | ||
case x: | ||
default: | ||
} | ||
console.log(y); | ||
})(); | ||
|
||
const k5 = (() => { | ||
const x = 'asdf'; | ||
let y = "FAIL"; | ||
let z = "FAIL"; | ||
switch (x) { | ||
case y = "PASS 5": | ||
case z = "PASS 5": | ||
case x: | ||
default: | ||
} | ||
console.log(y, z); | ||
})(); | ||
|
||
|
||
var c = "FAIL"; | ||
(function () { | ||
function f(a, NaN) { | ||
function g() { | ||
switch (a) { | ||
case a: | ||
break; | ||
case ((c = "PASS"), NaN): | ||
c = "FAIL" | ||
break; | ||
} | ||
} | ||
g(); | ||
} | ||
f(0 / 0); | ||
})(); | ||
console.log(c); |
36 changes: 36 additions & 0 deletions
36
crates/swc_ecma_minifier/tests/fixture/issues/8813/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
(()=>{ | ||
const x = 'asdf'; | ||
let y = "PASS 1"; | ||
switch(x){ | ||
case x: | ||
default: | ||
case y = "FAIL": | ||
} | ||
console.log(y); | ||
})(), (()=>{ | ||
const x = 'asdf'; | ||
let y = "PASS 2"; | ||
switch(x){ | ||
case x: | ||
case y = "FAIL": | ||
default: | ||
} | ||
console.log(y); | ||
})(), console.log("PASS 3"), console.log("PASS 4"), (()=>{ | ||
let y = "FAIL", z = "FAIL"; | ||
switch('asdf'){ | ||
case y = "PASS 5": | ||
case z = "PASS 5": | ||
default: | ||
} | ||
console.log(y, z); | ||
})(); | ||
var a, c = "FAIL"; | ||
a = 0 / 0, function() { | ||
switch(a){ | ||
case a: | ||
break; | ||
case void (c = "PASS"): | ||
c = "FAIL"; | ||
} | ||
}(), console.log(c); |
10 changes: 8 additions & 2 deletions
10
crates/swc_ecma_minifier/tests/terser/compress/functions/issue_2620_4/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
var c = "FAIL"; | ||
var a, NaN; | ||
a = 0, c = "PASS"; | ||
(function(a, NaN) { | ||
(function() { | ||
switch(a){ | ||
case a: | ||
case void (c = "PASS"): | ||
} | ||
})(); | ||
})(0 / 0); | ||
console.log(c); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters