diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-12-02 02:18:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-02 02:18:33 +0800 |
commit | 8da3754e51140c0eee80f02fcf3f5d99a74ca86e (patch) | |
tree | 3e1e381f2e650cf648d9b184a22a7561e4aa2754 /lib/compress.js | |
parent | 9a6b11f8e628c66731c4037ff408bb969003e6f7 (diff) | |
download | tracifyjs-8da3754e51140c0eee80f02fcf3f5d99a74ca86e.tar.gz tracifyjs-8da3754e51140c0eee80f02fcf3f5d99a74ca86e.zip |
improve `evaluate` on `typeof` (#2550)
- gated through `typeofs`
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js index 5301d48f..7d87c4a6 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1828,12 +1828,17 @@ merge(Compressor.prototype, { return this; }); def(AST_UnaryPrefix, function(compressor){ + var e = this.expression; // Function would be evaluated to an array and so typeof would // incorrectly return 'object'. Hence making is a special case. - if (this.operator == "typeof" && this.expression instanceof AST_Function) { + if (compressor.option("typeofs") + && this.operator == "typeof" + && (e instanceof AST_Lambda + || e instanceof AST_SymbolRef + && e.fixed_value() instanceof AST_Lambda)) { return typeof function(){}; } - var e = ev(this.expression, compressor); + e = ev(e, compressor); if (e === this.expression) return this; switch (this.operator) { case "!": return !e; @@ -1894,7 +1899,6 @@ merge(Compressor.prototype, { return value === node ? this : value; }); def(AST_SymbolRef, function(compressor){ - if (!compressor.option("reduce_vars")) return this; var fixed = this.fixed_value(); if (!fixed) return this; this._eval = return_this; |