fix dead_code on AST_Destructuring

fixes #2383
This commit is contained in:
alexlamsl 2017-10-22 21:23:03 +08:00
parent 44352eb26a
commit 2122a18124
2 changed files with 28 additions and 1 deletions

View File

@ -3315,7 +3315,18 @@ merge(Compressor.prototype, {
});
AST_Definitions.DEFMETHOD("remove_initializers", function(){
this.definitions.forEach(function(def){ def.value = null });
var decls = [];
this.definitions.forEach(function(def) {
def.name.walk(new TreeWalker(function(node) {
if (node instanceof AST_SymbolDeclaration) {
decls.push(make_node(AST_VarDef, def, {
name: node,
value: null
}));
}
}));
});
this.definitions = decls;
});
AST_Definitions.DEFMETHOD("to_assignments", function(compressor){

View File

@ -560,3 +560,19 @@ global_fns: {
"RangeError",
]
}
issue_2383: {
options = {
conditionals: true,
dead_code: true,
evaluate: true,
}
input: {
if (0) {
var {x, y} = foo();
}
}
expect: {
var x, y;
}
}