fix destructing crash in reduce_vars

fixes #1531
This commit is contained in:
alexlamsl
2017-03-03 07:23:46 +08:00
parent 0b77d861a8
commit f704e9b65c
2 changed files with 51 additions and 5 deletions

View File

@@ -205,6 +205,9 @@ merge(Compressor.prototype, {
} }
} }
if (node instanceof AST_VarDef) { if (node instanceof AST_VarDef) {
if (node.name instanceof AST_Destructuring) {
node.name.walk(suppressor);
} else {
var d = node.name.definition(); var d = node.name.definition();
if (d.fixed === undefined) { if (d.fixed === undefined) {
d.fixed = node.value || make_node(AST_Undefined, node); d.fixed = node.value || make_node(AST_Undefined, node);
@@ -213,6 +216,7 @@ merge(Compressor.prototype, {
d.fixed = false; d.fixed = false;
} }
} }
}
var iife; var iife;
if (node instanceof AST_Function if (node instanceof AST_Function
&& (iife = tw.parent()) instanceof AST_Call && (iife = tw.parent()) instanceof AST_Call

View File

@@ -251,3 +251,45 @@ destructuring_dont_evaluate_with_undefined_as_default_assignment: {
[foo = void 0] = bar; [foo = void 0] = bar;
} }
} }
reduce_vars: {
options = {
reduce_vars: true,
}
input: {
{const [aa, [bb, cc]] = dd;}
{let [aa, [bb, cc]] = dd;}
var [aa, [bb, cc]] = dd;
[aa, [bb, cc]] = dd;
{const {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
{let {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};
({aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}});
const [{a},b] = c;
let [{a},b] = c;
var [{a},b] = c;
[{a},b] = c;
for (const [x,y] in pairs);
for (let [x,y] in pairs);
for (var [x,y] in pairs);
for ([x,y] in pairs);
}
expect: {
{const [aa, [bb, cc]] = dd;}
{let [aa, [bb, cc]] = dd;}
var [aa, [bb, cc]] = dd;
[aa, [bb, cc]] = dd;
{const {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
{let {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};
({aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}});
const [{a},b] = c;
let [{a},b] = c;
var [{a},b] = c;
[{a},b] = c;
for (const [x,y] in pairs);
for (let [x,y] in pairs);
for (var [x,y] in pairs);
for ([x,y] in pairs);
}
}