From 57ce5bd9e085546a5c1cb8dd4a3ea71ab6c56f26 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 27 Mar 2017 01:30:21 +0800 Subject: 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. --- lib/compress.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'lib/compress.js') diff --git a/lib/compress.js b/lib/compress.js index 83486b61..590015ff 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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; + } } } -- cgit v1.2.3