Skip to content

Commit

Permalink
fix collapse_vars regression in destructuring (#2897)
Browse files Browse the repository at this point in the history
fixes #2896
  • Loading branch information
kzc authored and alexlamsl committed Feb 8, 2018
1 parent aebc916 commit 569757d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,7 @@ merge(Compressor.prototype, {
}

function may_modify(sym) {
if (!sym.definition) return true; // AST_Destructuring
var def = sym.definition();
if (def.orig.length == 1 && def.orig[0] instanceof AST_SymbolDefun) return false;
if (def.scope.get_defun_scope() !== scope) return true;
Expand Down
33 changes: 33 additions & 0 deletions test/compress/destructuring.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,39 @@ mangle_destructuring_decl: {
node_version: ">=6"
}

mangle_destructuring_decl_collapse_vars: {
options = {
collapse_vars: true,
evaluate: true,
unused: true,
}
mangle = {
}
input: {
function test(opts) {
let a = opts.a || { e: 7, n: 8 };
let { t, e, n, s = 5 + 4, o, r } = a;
console.log(t, e, n, s, o, r);
}
test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }});
test({});
}
expect: {
function test(t) {
let e = t.a || { e: 7, n: 8 };
let {t: n, e: o, n: s, s: l = 9, o: a, r: c} = e;
console.log(n, o, s, l, a, c);
}
test({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } });
test({});
}
expect_stdout: [
"1 2 3 4 5 6",
"undefined 7 8 9 undefined undefined",
]
node_version: ">=6"
}

mangle_destructuring_assign_toplevel_true: {
options = {
toplevel: true,
Expand Down
2 changes: 1 addition & 1 deletion test/run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function run_compress_tests() {
});
return false;
}
if (0 && test.reminify && !reminify(test.options, input_code, input_formatted, test.expect_stdout)) {
if (test.reminify && !reminify(test.options, input_code, input_formatted, test.expect_stdout)) {
return false;
}
}
Expand Down

0 comments on commit 569757d

Please sign in to comment.