add optional typeof symbol transformer

This commit is contained in:
Sebastian McKenzie
2015-01-05 00:06:57 +11:00
parent 103b619364
commit 9bfb8c440a
6 changed files with 23 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
(function (obj) {
return obj && obj.constructor === Symbol ? "symbol" : typeof obj;
});

View File

@@ -89,6 +89,7 @@ _.each({
_moduleFormatter: require("./transformers/_module-formatter"),
useStrict: require("./transformers/use-strict"),
typeofSymbol: require("./transformers/optional-typeof-symbol"),
coreAliasing: require("./transformers/optional-core-aliasing"),
undefinedToVoid: require("./transformers/optional-undefined-to-void"),

View File

@@ -0,0 +1,7 @@
var t = require("../../types");
exports.UnaryExpression = function (node, parent, file, scope) {
if (node.operator === "typeof") {
return t.callExpression(file.addHelper("typeof"), [node.argument]);
}
};

View File

@@ -0,0 +1,2 @@
var s = Symbol("s");
assert.equal(typeof s, "symbol");

View File

@@ -0,0 +1,2 @@
var s = Symbol("s");
assert.equal(typeof s, "symbol");

View File

@@ -0,0 +1,8 @@
"use strict";
var _typeof = function (obj) {
return obj && obj.constructor === Symbol ? "symbol" : typeof obj;
};
var s = Symbol("s");
assert.equal(_typeof(s), "symbol");