diff options
author | Roman Bataev <roman.bataev@gmail.com> | 2013-04-03 22:34:38 -0400 |
---|---|---|
committer | Roman Bataev <roman.bataev@gmail.com> | 2013-04-03 22:34:38 -0400 |
commit | 4b818056cf1a19fe6251e026cac4894f618f0217 (patch) | |
tree | f920275eeef8cad1229b1e72ba1513dd63e6f1cc /lib | |
parent | b956e5f1d9606f6fa6217826c4665316267e8a8f (diff) | |
download | tracifyjs-4b818056cf1a19fe6251e026cac4894f618f0217.tar.gz tracifyjs-4b818056cf1a19fe6251e026cac4894f618f0217.zip |
Fix typeof evaluation for regex and function
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 5a6adcd5..216826d6 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -625,7 +625,18 @@ merge(Compressor.prototype, { var e = this.expression; switch (this.operator) { case "!": return !ev(e); - case "typeof": return typeof ev(e); + case "typeof": + // Function would be evaluated to an array and so typeof would + // incorrectly return 'object'. Hence making is a special case. + if (e instanceof AST_Function) return typeof function(){}; + + e = ev(e); + + // typeof <RegExp> returns "object" or "function" on different platforms + // so cannot evaluate reliably + if (e instanceof RegExp) throw def; + + return typeof e; case "void": return void ev(e); case "~": return ~ev(e); case "-": |