Skip to content

Commit

Permalink
fix corner case in hoist_props (#3022)
Browse files Browse the repository at this point in the history
fixes #3021
  • Loading branch information
alexlamsl committed Mar 22, 2018
1 parent 49bfc6b commit 12985d8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/compress.js
Expand Up @@ -3624,8 +3624,9 @@ merge(Compressor.prototype, {
var sym = node.name, def, value;
if (sym.scope === self
&& (def = sym.definition()).escaped != 1
&& !def.single_use
&& !def.assignments
&& !def.direct_access
&& !def.single_use
&& !top_retain(def)
&& (value = sym.fixed_value()) === node.value
&& value instanceof AST_Object) {
Expand Down
30 changes: 30 additions & 0 deletions test/compress/hoist_props.js
Expand Up @@ -686,3 +686,33 @@ undefined_key: {
}
expect_stdout: "3"
}

issue_3021: {
options = {
hoist_props: true,
reduce_vars: true,
}
input: {
var a = 1, b = 2;
(function() {
b = a;
if (a++ + b--)
return 1;
return;
var b = {};
})();
console.log(a, b);
}
expect: {
var a = 1, b = 2;
(function() {
b = a;
if (a++ + b--)
return 1;
return;
var b = {};
})();
console.log(a, b);
}
expect_stdout: "2 2"
}

0 comments on commit 12985d8

Please sign in to comment.