Skip to content

Commit 3046d71

Browse files
authored
fix(es/minifier): Abort seq inliner on ** (#8947)
**Related issue:** - Closes #8942
1 parent 8baa0e5 commit 3046d71

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

crates/swc_ecma_minifier/src/compress/optimize/dead_code.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ impl Optimizer<'_> {
6868
if let Expr::Assign(assign) = e {
6969
// x += 1 => x + 1
7070
if let Some(op) = assign.op.to_update() {
71+
if op == op!("**") {
72+
return false;
73+
}
74+
7175
if let Some(lhs) = assign.left.as_ident() {
7276
//
7377
if self

crates/swc_ecma_minifier/src/compress/optimize/sequences.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,7 @@ impl Optimizer<'_> {
15621562
| Expr::Tpl(..)
15631563
| Expr::TaggedTpl(..) => return Ok(false),
15641564

1565+
// See https://github.com/swc-project/swc/issues/8924 and https://github.com/swc-project/swc/issues/8942
15651566
Expr::Assign(AssignExpr {
15661567
op: op!("**="),
15671568
right,
@@ -1572,7 +1573,7 @@ impl Optimizer<'_> {
15721573
right,
15731574
..
15741575
}) => {
1575-
if is_pure_undefined(&self.expr_ctx, right) {
1576+
if !right.is_lit() {
15761577
return Ok(false);
15771578
}
15781579
}

crates/swc_ecma_minifier/tests/exec.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11224,6 +11224,21 @@ console.log(eval(foo));",
1122411224
);
1122511225
}
1122611226

11227+
#[test]
11228+
fn issue_8942() {
11229+
run_default_exec_test(
11230+
"
11231+
'use strict';
11232+
const k = (() => {
11233+
let x = 1;
11234+
x **= undefined / x;
11235+
return x;
11236+
})();
11237+
console.log(k);
11238+
",
11239+
);
11240+
}
11241+
1122711242
#[test]
1122811243
fn issue_8937() {
1122911244
run_default_exec_test(
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
"use strict";
2-
const k = NaN;
2+
const k = (()=>{
3+
let x = 1;
4+
return x **= void 0;
5+
})();

0 commit comments

Comments
 (0)