better typeof symbol transformer
This commit is contained in:
@@ -3,7 +3,19 @@ var t = require("../../types");
|
||||
exports.optional = true;
|
||||
|
||||
exports.UnaryExpression = function (node, parent, file) {
|
||||
this.skip();
|
||||
|
||||
if (node.operator === "typeof") {
|
||||
return t.callExpression(file.addHelper("typeof"), [node.argument]);
|
||||
var call = t.callExpression(file.addHelper("typeof"), [node.argument]);
|
||||
if (t.isIdentifier(node.argument)) {
|
||||
var undefLiteral = t.literal("undefined");
|
||||
return t.conditionalExpression(
|
||||
t.binaryExpression("===", t.unaryExpression("typeof", node.argument), undefLiteral),
|
||||
undefLiteral,
|
||||
call
|
||||
);
|
||||
} else {
|
||||
return call;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user