Skip to content

Commit 436ba9b

Browse files
committed
Merge pull request babel#2306 from hzoo/eval-typeof
evaluation: evaluate typeof
2 parents acc8018 + 5c58b52 commit 436ba9b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/babel/src/traversal/path/evaluation.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,20 @@ export function evaluate(): { confident: boolean; value: any } {
119119
}
120120

121121
if (path.isUnaryExpression({ prefix: true })) {
122-
var arg = evaluate(path.get("argument"));
122+
var argument = path.get("argument");
123+
var arg = evaluate(argument);
123124
switch (node.operator) {
124125
case "void": return undefined;
125126
case "!": return !arg;
126127
case "+": return +arg;
127128
case "-": return -arg;
128129
case "~": return ~arg;
130+
case "typeof":
131+
if (argument.isFunction()) {
132+
return "function";
133+
} else {
134+
return typeof arg;
135+
}
129136
}
130137
}
131138

0 commit comments

Comments
 (0)