add optional typeof symbol transformer
This commit is contained in:
3
lib/6to5/transformation/templates/typeof.js
Normal file
3
lib/6to5/transformation/templates/typeof.js
Normal file
@@ -0,0 +1,3 @@
|
||||
(function (obj) {
|
||||
return obj && obj.constructor === Symbol ? "symbol" : typeof obj;
|
||||
});
|
||||
@@ -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"),
|
||||
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
};
|
||||
2
test/fixtures/transformation/optional-typeof-symbol/basic/actual.js
vendored
Normal file
2
test/fixtures/transformation/optional-typeof-symbol/basic/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
var s = Symbol("s");
|
||||
assert.equal(typeof s, "symbol");
|
||||
2
test/fixtures/transformation/optional-typeof-symbol/basic/exec.js
vendored
Normal file
2
test/fixtures/transformation/optional-typeof-symbol/basic/exec.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
var s = Symbol("s");
|
||||
assert.equal(typeof s, "symbol");
|
||||
8
test/fixtures/transformation/optional-typeof-symbol/basic/expected.js
vendored
Normal file
8
test/fixtures/transformation/optional-typeof-symbol/basic/expected.js
vendored
Normal 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");
|
||||
Reference in New Issue
Block a user