aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-11-24 14:07:39 +0800
committerGitHub <noreply@github.com>2017-11-24 14:07:39 +0800
commit3b28b915ebad2d9452c0e8649033ab4813eabca4 (patch)
tree408bb79e5b762fb0df1eb793c37153853223e7d7 /lib
parenteb001dc1d9efbb81841410c06d854091473061ee (diff)
downloadtracifyjs-3b28b915ebad2d9452c0e8649033ab4813eabca4.tar.gz
tracifyjs-3b28b915ebad2d9452c0e8649033ab4813eabca4.zip
extend escape analysis on constant expression properties (#2509)
fixes #2508
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js
index d8a0bd7c..744a1ea5 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -333,7 +333,7 @@ merge(Compressor.prototype, {
}
}
}
- mark_escaped(d, node, value, 0);
+ mark_escaped(d, node.scope, node, value, 0);
}
if (node instanceof AST_SymbolCatch) {
node.definition().fixed = false;
@@ -623,10 +623,12 @@ merge(Compressor.prototype, {
}
}
- function mark_escaped(d, node, value, level) {
+ function mark_escaped(d, scope, node, value, level) {
var parent = tw.parent(level);
- if (value instanceof AST_Constant) return;
- if (level > 0 && value instanceof AST_Function) return;
+ if (value) {
+ if (value.is_constant()) return;
+ if (level > 0 && value.is_constant_expression(scope)) return;
+ }
if (parent instanceof AST_Assign && parent.operator == "=" && node === parent.right
|| parent instanceof AST_Call && node !== parent.expression
|| parent instanceof AST_Return && node === parent.value && node.scope !== d.scope
@@ -634,13 +636,13 @@ merge(Compressor.prototype, {
d.escaped = true;
return;
} else if (parent instanceof AST_Array) {
- mark_escaped(d, parent, parent, level + 1);
+ mark_escaped(d, scope, parent, parent, level + 1);
} else if (parent instanceof AST_ObjectKeyVal && node === parent.value) {
var obj = tw.parent(level + 1);
- mark_escaped(d, obj, obj, level + 2);
+ mark_escaped(d, scope, obj, obj, level + 2);
} else if (parent instanceof AST_PropAccess && node === parent.expression) {
value = read_property(value, parent.property);
- mark_escaped(d, parent, value, level + 1);
+ mark_escaped(d, scope, parent, value, level + 1);
if (value) return;
}
if (level == 0) d.direct_access = true;