aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-10-24 22:10:36 +0800
committerGitHub <noreply@github.com>2017-10-24 22:10:36 +0800
commit74ae16f9f88600c90438e85829a615b2377f6740 (patch)
tree1fa9576bd208d9197ac4d79ae518fe814c618a6b /lib
parent1968203d83ea6ba9dd34b36c0d6f3e4b1c5db340 (diff)
downloadtracifyjs-74ae16f9f88600c90438e85829a615b2377f6740.tar.gz
tracifyjs-74ae16f9f88600c90438e85829a615b2377f6740.zip
fix `unsafe` `reduce_vars` on arrays & objects (#2397)
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 25718a5e..670a3b0d 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -567,18 +567,18 @@ merge(Compressor.prototype, {
function read_property(obj, key) {
if (key instanceof AST_Constant) key = key.getValue();
if (key instanceof AST_Node) return null;
+ var value;
if (obj instanceof AST_Array) {
- return obj.elements[key];
+ value = obj.elements[key];
} else if (obj instanceof AST_Object) {
var props = obj.properties;
- var value;
for (var i = props.length; --i >= 0;) {
var prop = props[i];
if (!(prop instanceof AST_ObjectKeyVal)) return;
if (!value && props[i].key === key) value = props[i].value;
}
- return value;
}
+ return value instanceof AST_SymbolRef ? value.fixed_value() : value;
}
function is_modified(node, value, level, immutable) {
@@ -589,6 +589,8 @@ merge(Compressor.prototype, {
&& parent.expression === node
&& (!(value instanceof AST_Function) || value.contains_this())) {
return true;
+ } else if (parent instanceof AST_Array || parent instanceof AST_Object) {
+ return is_modified(parent, parent, level + 1);
} else if (parent instanceof AST_PropAccess && parent.expression === node) {
return !immutable && is_modified(parent, read_property(value, parent.property), level + 1);
}
@@ -602,6 +604,8 @@ merge(Compressor.prototype, {
|| parent instanceof AST_Return && node === parent.value && node.scope !== d.scope
|| parent instanceof AST_VarDef && node === parent.value) {
d.escaped = true;
+ } else if (parent instanceof AST_Array || parent instanceof AST_Object) {
+ mark_escaped(d, parent, parent, level + 1);
} else if (parent instanceof AST_PropAccess && node === parent.expression) {
mark_escaped(d, parent, read_property(value, parent.property), level + 1);
}