Skip to content

Commit

Permalink
fix inline after single-use reduce_vars (#2623)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Dec 19, 2017
1 parent 01057cf commit 2273655
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/compress.js
Expand Up @@ -4004,7 +4004,9 @@ merge(Compressor.prototype, {
var catches = Object.create(null);
do {
scope = compressor.parent(level++);
if (scope instanceof AST_Catch) {
if (scope instanceof AST_SymbolRef) {
scope = scope.fixed_value();
} else if (scope instanceof AST_Catch) {
catches[scope.argname.name] = true;
}
} while (!(scope instanceof AST_Scope));
Expand Down
71 changes: 71 additions & 0 deletions test/compress/functions.js
Expand Up @@ -1101,3 +1101,74 @@ issue_2616: {
}
expect_stdout: "PASS"
}

issue_2620_1: {
options = {
inline: true,
reduce_vars: true,
sequences: true,
side_effects: true,
unused: true,
}
input: {
var c = "FAIL";
(function() {
function f(a) {
var b = function g(a) {
a && a();
}();
if (a) {
var d = c = "PASS";
}
}
f(1);
})();
console.log(c);
}
expect: {
var c = "FAIL";
(function() {
(function(a) {
if (function(a) {
a && a();
}(), a) c = "PASS";
})(1);
})(),
console.log(c);
}
expect_stdout: "PASS"
}

issue_2620_2: {
options = {
conditionals: true,
evaluate: true,
inline: true,
passes: 2,
reduce_vars: true,
sequences: true,
side_effects: true,
unused: true,
}
input: {
var c = "FAIL";
(function() {
function f(a) {
var b = function g(a) {
a && a();
}();
if (a) {
var d = c = "PASS";
}
}
f(1);
})();
console.log(c);
}
expect: {
var c = "FAIL";
c = "PASS",
console.log(c);
}
expect_stdout: "PASS"
}

0 comments on commit 2273655

Please sign in to comment.