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 corner case in reduce_vars #5891

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -1397,15 +1397,24 @@ Compressor.prototype.compress = function(node) {
first = false;
push(tw, true);
}
})
});
if (!first) pop(tw);
walk_body(node, tw);
var defined_ids = tw.defined_ids;
var safe_ids = tw.safe_ids;
node.body.forEach(function(branch) {
push(tw, true);
branch.walk(tw);
if (aborts(branch)) {
tw.defined_ids = defined_ids;
tw.safe_ids = safe_ids;
}
});
tw.defined_ids = defined_ids;
tw.safe_ids = safe_ids;
return true;
});
def(AST_SwitchBranch, function(tw) {
push(tw, true);
walk_body(this, tw);
pop(tw);
return true;
});
def(AST_SymbolCatch, function() {
Expand Down Expand Up @@ -1501,7 +1510,7 @@ Compressor.prototype.compress = function(node) {
}
mark_fn_def(tw, d, value);
});
def(AST_Template, function(tw, descend) {
def(AST_Template, function(tw) {
var node = this;
var tag = node.tag;
if (!tag) return;
Expand Down Expand Up @@ -1549,7 +1558,7 @@ Compressor.prototype.compress = function(node) {
if (node.bfinally) node.bfinally.walk(tw);
return true;
});
def(AST_Unary, function(tw, descend) {
def(AST_Unary, function(tw) {
var node = this;
if (!UNARY_POSTFIX[node.operator]) return;
var exp = node.expression;
Expand Down
11 changes: 5 additions & 6 deletions test/compress/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5720,9 +5720,9 @@ issue_3929: {
var abc = function f() {
(function() {
switch (f) {
default:
default:
var abc = 0;
case 0:
case 0:
abc.p;
}
console.log(typeof f);
Expand All @@ -5736,10 +5736,9 @@ issue_3929: {
var abc = function f() {
(function() {
switch (f) {
default:
var abc = 0;
case 0:
abc.p;
default:
case 0:
0..p;
}
console.log(typeof f);
})();
Expand Down
39 changes: 39 additions & 0 deletions test/compress/switches.js
Original file line number Diff line number Diff line change
Expand Up @@ -1688,3 +1688,42 @@ issue_5543_2: {
}
expect_stdout: "PASS"
}

issue_5890: {
options = {
pure_getters: "strict",
reduce_vars: true,
side_effects: true,
}
input: {
var a = {};
a.p;
try {
switch (42) {
default:
a = null;
case false:
a.q;
}
console.log("FAIL");
} catch (e) {
console.log("PASS");
}
}
expect: {
var a = {};
a.p;
try {
switch (42) {
default:
a = null;
case false:
a.q;
}
console.log("FAIL");
} catch (e) {
console.log("PASS");
}
}
expect_stdout: "PASS"
}
Loading