From 1c0defdc030debc608e6fa21d8d503d6d6033843 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sat, 2 Nov 2019 03:34:32 +0800 Subject: enhance `unsafe` `evaluate` (#3564) --- lib/compress.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/compress.js') 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; } -- cgit v1.2.3