Skip to content

Commit

Permalink
Merge pull request #2306 from hzoo/eval-typeof
Browse files Browse the repository at this point in the history
evaluation: evaluate typeof
  • Loading branch information
sebmck committed Sep 3, 2015
2 parents acc8018 + 5c58b52 commit 436ba9b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/babel/src/traversal/path/evaluation.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,20 @@ export function evaluate(): { confident: boolean; value: any } {
}

if (path.isUnaryExpression({ prefix: true })) {
var arg = evaluate(path.get("argument"));
var argument = path.get("argument");
var arg = evaluate(argument);
switch (node.operator) {
case "void": return undefined;
case "!": return !arg;
case "+": return +arg;
case "-": return -arg;
case "~": return ~arg;
case "typeof":
if (argument.isFunction()) {
return "function";
} else {
return typeof arg;
}
}
}

Expand Down

0 comments on commit 436ba9b

Please sign in to comment.