Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/minifier): Fix usage counter to fix infinite loop #6744

Merged
merged 9 commits into from Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions crates/swc/tests/fixture/issues-6xxx/6729/input/.swcrc
@@ -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 changes: 13 additions & 0 deletions crates/swc/tests/fixture/issues-6xxx/6729/input/index.js
@@ -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 })
}
}
5 changes: 5 additions & 0 deletions crates/swc/tests/fixture/issues-6xxx/6729/output/index.js
@@ -0,0 +1,5 @@
export async function foo() {
undefined_var_1 && await a({
replace: undefined_var_2 ? 1 : 2
});
}
24 changes: 15 additions & 9 deletions crates/swc_ecma_minifier/src/compress/optimize/sequences.rs
Expand Up @@ -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) {
let old = self.in_lhs;
self.in_lhs = true;
Expand All @@ -2466,6 +2457,21 @@ impl Visit for UsageCounter<'_> {
p.visit_children_with(self);
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)]
Expand Down
22 changes: 22 additions & 0 deletions crates/swc_ecma_minifier/tests/exec.rs
Expand Up @@ -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')
"###,
)
}