mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 22:56:11 +03:00
fix(es/minifier): Fix usage counter to fix infinite loop (#6744)
**Description:** We skip non-computed property names while checking if we can inline an expression. **Related issue:** - Closes https://github.com/swc-project/swc/issues/6729.
This commit is contained in:
parent
62c0d7291a
commit
88d40e8ab8
19
crates/swc/tests/fixture/issues-6xxx/6729/input/.swcrc
Normal file
19
crates/swc/tests/fixture/issues-6xxx/6729/input/.swcrc
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"jsc": {
|
||||||
|
"parser": {
|
||||||
|
"syntax": "typescript",
|
||||||
|
"decorators": true,
|
||||||
|
"tsx": false
|
||||||
|
},
|
||||||
|
"target": "es2020",
|
||||||
|
"loose": false,
|
||||||
|
"minify": {
|
||||||
|
"compress": true,
|
||||||
|
"mangle": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"module": {
|
||||||
|
"type": "es6"
|
||||||
|
},
|
||||||
|
"isModule": true
|
||||||
|
}
|
13
crates/swc/tests/fixture/issues-6xxx/6729/input/index.js
Normal file
13
crates/swc/tests/fixture/issues-6xxx/6729/input/index.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
export async function foo() {
|
||||||
|
if (undefined_var_1) {
|
||||||
|
let replace;
|
||||||
|
|
||||||
|
if (undefined_var_2) {
|
||||||
|
replace = 1;
|
||||||
|
} else {
|
||||||
|
replace = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
await a({ replace })
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
export async function foo() {
|
||||||
|
undefined_var_1 && await a({
|
||||||
|
replace: undefined_var_2 ? 1 : 2
|
||||||
|
});
|
||||||
|
}
|
@ -2444,15 +2444,6 @@ impl Visit for UsageCounter<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_super_prop_expr(&mut self, e: &SuperPropExpr) {
|
|
||||||
if let SuperProp::Computed(c) = &e.prop {
|
|
||||||
let old = self.in_lhs;
|
|
||||||
self.in_lhs = false;
|
|
||||||
c.expr.visit_with(self);
|
|
||||||
self.in_lhs = old;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_pat(&mut self, p: &Pat) {
|
fn visit_pat(&mut self, p: &Pat) {
|
||||||
let old = self.in_lhs;
|
let old = self.in_lhs;
|
||||||
self.in_lhs = true;
|
self.in_lhs = true;
|
||||||
@ -2466,6 +2457,21 @@ impl Visit for UsageCounter<'_> {
|
|||||||
p.visit_children_with(self);
|
p.visit_children_with(self);
|
||||||
self.in_lhs = old;
|
self.in_lhs = old;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_prop_name(&mut self, p: &PropName) {
|
||||||
|
if let PropName::Computed(p) = p {
|
||||||
|
p.visit_with(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_super_prop_expr(&mut self, e: &SuperPropExpr) {
|
||||||
|
if let SuperProp::Computed(c) = &e.prop {
|
||||||
|
let old = self.in_lhs;
|
||||||
|
self.in_lhs = false;
|
||||||
|
c.expr.visit_with(self);
|
||||||
|
self.in_lhs = old;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -10407,3 +10407,25 @@ fn issue_6641() {
|
|||||||
"###,
|
"###,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn issue_6728() {
|
||||||
|
run_default_exec_test(
|
||||||
|
r###"
|
||||||
|
async function foo() {
|
||||||
|
if (undefined_var_1) {
|
||||||
|
let replace;
|
||||||
|
|
||||||
|
if (undefined_var_2) {
|
||||||
|
replace = 1;
|
||||||
|
} else {
|
||||||
|
replace = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
await a({ replace })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('PASS')
|
||||||
|
"###,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user