Skip to content

Commit

Permalink
fix corner case in merge_vars (#5657)
Browse files Browse the repository at this point in the history
fixes #5656
  • Loading branch information
alexlamsl authored Sep 9, 2022
1 parent 9dec612 commit 88dfc49
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -1720,10 +1720,10 @@ Compressor.prototype.compress = function(node) {
}

function find_scope(compressor) {
var level = 0, node;
while (node = compressor.parent(level++)) {
var level = 0, node = compressor.self();
do {
if (node.variables) return node;
}
} while (node = compressor.parent(level++));
}

function find_try(compressor, level, node, scope, may_throw, sync) {
Expand Down Expand Up @@ -6733,6 +6733,7 @@ Compressor.prototype.compress = function(node) {
var refs = references[def.id];
if (!refs) return;
if (refs.start.block !== seg.block) return references[def.id] = false;
sym.scope = find_scope(tw);
refs.push(sym);
refs.end = seg;
if (def.id in prev) {
Expand All @@ -6747,6 +6748,7 @@ Compressor.prototype.compress = function(node) {
return references[def.id] = false;
} else {
var refs = declarations.get(def.id) || [];
sym.scope = find_scope(tw);
refs.push(sym);
references[def.id] = refs;
if (!read) {
Expand Down
25 changes: 25 additions & 0 deletions test/compress/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -2144,3 +2144,28 @@ issue_5591: {
]
node_version: ">=4"
}

issue_5656: {
options = {
collapse_vars: true,
merge_vars: true,
}
input: {
console.log(function(a) {
var b = a;
b++;
{
const a = b;
}
}());
}
expect: {
console.log(function(a) {
var b = a;
{
const a = ++b;
}
}());
}
expect_stdout: true
}

0 comments on commit 88dfc49

Please sign in to comment.