aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-11-02 03:34:32 +0800
committerGitHub <noreply@github.com>2019-11-02 03:34:32 +0800
commit1c0defdc030debc608e6fa21d8d503d6d6033843 (patch)
tree54dd9748799ae57afbb50f91ae81e7c4b93ac766 /lib/compress.js
parentdcbf2236c7df7ea4179dddf3e798229181868599 (diff)
downloadtracifyjs-1c0defdc030debc608e6fa21d8d503d6d6033843.tar.gz
tracifyjs-1c0defdc030debc608e6fa21d8d503d6d6033843.zip
enhance `unsafe` `evaluate` (#3564)
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js
index e3532fef..d8ee2bd3 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2995,6 +2995,7 @@ merge(Compressor.prototype, {
],
};
convert_to_predicate(static_values);
+ var regexp_props = makePredicate("global ignoreCase multiline source");
def(AST_PropAccess, function(compressor, cached, depth) {
if (compressor.option("unsafe")) {
var key = this.property;
@@ -3010,9 +3011,12 @@ merge(Compressor.prototype, {
val = global_objs[exp.name];
} else {
val = exp._eval(compressor, cached, depth + 1);
- if (!val || val === exp) return this;
- if (typeof val == "object" && !HOP(val, key)) return this;
- if (typeof val == "function") switch (key) {
+ if (val == null || val === exp) return this;
+ if (val instanceof RegExp) {
+ if (!regexp_props[key]) return this;
+ } else if (typeof val == "object") {
+ if (!HOP(val, key)) return this;
+ } else if (typeof val == "function") switch (key) {
case "name":
return val.node.name ? val.node.name.name : "";
case "length":
@@ -3060,7 +3064,7 @@ merge(Compressor.prototype, {
val = global_objs[e.name];
} else {
val = e._eval(compressor, cached, depth + 1);
- if (val === e || !val) return this;
+ if (val == null || val === e) return this;
var native_fn = native_fns[val.constructor.name];
if (!native_fn || !native_fn[key]) return this;
}