aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-03-27 01:30:21 +0800
committerGitHub <noreply@github.com>2017-03-27 01:30:21 +0800
commit57ce5bd9e085546a5c1cb8dd4a3ea71ab6c56f26 (patch)
treeee5e196f4aa4fcbe867eb82287b73b9db6b4174e /lib/compress.js
parent861a79ac9fdb2cdbb54054306eb896e2c134af73 (diff)
downloadtracifyjs-57ce5bd9e085546a5c1cb8dd4a3ea71ab6c56f26.tar.gz
tracifyjs-57ce5bd9e085546a5c1cb8dd4a3ea71ab6c56f26.zip
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.
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js17
1 files changed, 12 insertions, 5 deletions
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;
+ }
}
}