Skip to content
Browse files

Fix typeof evaluation for regex and function

  • Loading branch information...
1 parent b956e5f commit 4b818056cf1a19fe6251e026cac4894f618f0217 @rbataev rbataev committed
Showing with 12 additions and 1 deletion.
  1. +12 −1 lib/compress.js
View
13 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 "-":

0 comments on commit 4b81805

Please sign in to comment.
Something went wrong with that request. Please try again.