This commit is contained in:
Roman Bataev 2013-04-03 19:47:03 -07:00
commit 1c5274a8ae
2 changed files with 37 additions and 1 deletions

View File

@ -625,7 +625,18 @@ merge(Compressor.prototype, {
var e = this.expression; var e = this.expression;
switch (this.operator) { switch (this.operator) {
case "!": return !ev(e); 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 "void": return void ev(e);
case "~": return ~ev(e); case "~": return ~ev(e);
case "-": case "-":

25
test/compress/typeof.js Normal file
View File

@ -0,0 +1,25 @@
typeof_evaluation: {
options = {
evaluate: true
};
input: {
a = typeof 1;
b = typeof 'test';
c = typeof [];
d = typeof {};
e = typeof /./;
f = typeof false;
g = typeof function(){};
h = typeof undefined;
}
expect: {
a='number';
b='string';
c=typeof[];
d=typeof{};
e=typeof/./;
f='boolean';
g='function';
h='undefined';
}
}