aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-03-15 02:48:23 +0800
committerGitHub <noreply@github.com>2019-03-15 02:48:23 +0800
commitb3ef5e514dd0cefeba926401d2538907a8712b99 (patch)
treec2077a04cd6105bface587f47489652f1cd66d9f /lib/compress.js
parent627f5fb41eac761fec7481b7429f5edb878f9c04 (diff)
downloadtracifyjs-b3ef5e514dd0cefeba926401d2538907a8712b99.tar.gz
tracifyjs-b3ef5e514dd0cefeba926401d2538907a8712b99.zip
enhance `evaluate` (#3339)
fixes #3299
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 2a4f0df8..b5d155ea 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2727,19 +2727,25 @@ merge(Compressor.prototype, {
return typeof function(){};
}
if (!non_converting_unary[this.operator]) depth++;
- e = e._eval(compressor, cached, depth);
- if (e === this.expression) return this;
+ var v = e._eval(compressor, cached, depth);
+ if (v === this.expression) return this;
switch (this.operator) {
- case "!": return !e;
+ case "!": return !v;
case "typeof":
// typeof <RegExp> returns "object" or "function" on different platforms
// so cannot evaluate reliably
- if (e instanceof RegExp) return this;
- return typeof e;
- case "void": return void e;
- case "~": return ~e;
- case "-": return -e;
- case "+": return +e;
+ if (v instanceof RegExp) return this;
+ return typeof v;
+ case "void": return void v;
+ case "~": return ~v;
+ case "-": return -v;
+ case "+": return +v;
+ case "++":
+ case "--":
+ if (e instanceof AST_SymbolRef) {
+ var refs = e.definition().references;
+ if (refs[refs.length - 1] === e) return v;
+ }
}
return this;
});