handle overlapped variable definitions (#1691)
Process variable definitions with or without assigned values against: - `arguments` - named function arguments - multiple definitions within same scope Essentially demote variable declarations with no value assignments. Also fixed invalid use of `AST_VarDef` over `arguments` - should use a member of `AST_SymbolDeclaration` instead.
This commit is contained in:
@@ -260,7 +260,7 @@ merge(Compressor.prototype, {
|
||||
if (node instanceof AST_SymbolRef) {
|
||||
var d = node.definition();
|
||||
d.references.push(node);
|
||||
if (!d.fixed || !is_safe(d)
|
||||
if (d.fixed === undefined || !is_safe(d)
|
||||
|| is_modified(node, 0, d.fixed instanceof AST_Lambda)) {
|
||||
d.fixed = false;
|
||||
}
|
||||
@@ -270,10 +270,10 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
if (node instanceof AST_VarDef) {
|
||||
var d = node.name.definition();
|
||||
if (d.fixed === undefined) {
|
||||
d.fixed = node.value || make_node(AST_Undefined, node);
|
||||
if (d.fixed == null) {
|
||||
d.fixed = node.value;
|
||||
mark_as_safe(d);
|
||||
} else {
|
||||
} else if (node.value) {
|
||||
d.fixed = false;
|
||||
}
|
||||
}
|
||||
@@ -357,7 +357,14 @@ merge(Compressor.prototype, {
|
||||
|
||||
function is_safe(def) {
|
||||
for (var i = safe_ids.length, id = def.id; --i >= 0;) {
|
||||
if (safe_ids[i][id]) return true;
|
||||
if (safe_ids[i][id]) {
|
||||
if (def.fixed == null) {
|
||||
var orig = def.orig[0];
|
||||
if (orig instanceof AST_SymbolFunarg || orig.name == "arguments") return false;
|
||||
def.fixed = make_node(AST_Undefined, orig);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user