fix dead_code on AST_Destructuring (#2392)

fixes #2383
This commit is contained in:
Alex Lam S.L
2017-10-23 00:34:34 +08:00
committed by GitHub
parent 44352eb26a
commit 7d9a8596a9
2 changed files with 76 additions and 1 deletions

View File

@@ -3315,7 +3315,21 @@ merge(Compressor.prototype, {
});
AST_Definitions.DEFMETHOD("remove_initializers", function(){
this.definitions.forEach(function(def){ def.value = null });
var decls = [];
this.definitions.forEach(function(def) {
if (def.name instanceof AST_SymbolDeclaration) {
def.value = null;
decls.push(def);
} else 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){