diff --git a/src/babel/transformation/transformers/deprecated.json b/src/babel/transformation/transformers/deprecated.json index 8961cf2731..3677c988f5 100644 --- a/src/babel/transformation/transformers/deprecated.json +++ b/src/babel/transformation/transformers/deprecated.json @@ -2,7 +2,7 @@ "selfContained": "runtime", "unicode-regex": "regex.unicode", "spec.typeofSymbol": "es6.spec.symbols", - "es6.spec.symbols": "es6.symbols", + "es6.symbols": "es6.spec.symbols", "es6.blockScopingTDZ": "es6.spec.blockScoping", "utility.inlineExpressions": "minification.constantFolding", diff --git a/src/babel/transformation/transformers/es6/spec.symbols.js b/src/babel/transformation/transformers/es6/spec.symbols.js new file mode 100644 index 0000000000..953b29a18f --- /dev/null +++ b/src/babel/transformation/transformers/es6/spec.symbols.js @@ -0,0 +1,37 @@ +import * as t from "../../../types"; + +export var metadata = { + optional: true +}; + +export function UnaryExpression(node, parent, scope, file) { + if (node._ignoreSpecSymbols) return; + + if (node.operator === "typeof") { + var call = t.callExpression(file.addHelper("typeof"), [node.argument]); + if (this.get("argument").isIdentifier()) { + var undefLiteral = t.literal("undefined"); + var unary = t.unaryExpression("typeof", node.argument); + unary._ignoreSpecSymbols = true; + return t.conditionalExpression( + t.binaryExpression("===", unary, undefLiteral), + undefLiteral, + call + ); + } else { + return call; + } + } +} + +export function BinaryExpression(node, parent, scope, file) { + if (node.operator === "instanceof") { + return t.callExpression(file.addHelper("instanceof"), [node.left, node.right]); + } +} + +export function VariableDeclaration(node) { + if (node._generated) this.skip(); +} + +export { VariableDeclaration as FunctionDeclaration }; diff --git a/src/babel/transformation/transformers/es6/symbols.js b/src/babel/transformation/transformers/es6/symbols.js deleted file mode 100644 index 7e071a9129..0000000000 --- a/src/babel/transformation/transformers/es6/symbols.js +++ /dev/null @@ -1,44 +0,0 @@ -import * as t from "../../../types"; - -export var metadata = { - group: "builtin-pre" -}; - -const BINARY_COMPARISON_OPERATORS = ["!=", "==", "!==", "==="]; - -export function UnaryExpression(node, parent, scope, file) { - if (node._ignoreSpecSymbols || node.operator !== "typeof") return; - - if (t.isBinaryExpression(parent) && BINARY_COMPARISON_OPERATORS.indexOf(parent.operator) >= 0 && t.isLiteral(parent.right)) { - // don't touch binary comparisons with a string that doesn't equal symbol, we can statically determine - // that this condition will never be met which means faster code! - if (parent.right.value !== "symbol") return; - } - - - var call = t.callExpression(file.addHelper("typeof"), [node.argument]); - if (this.get("argument").isIdentifier()) { - var undefLiteral = t.literal("undefined"); - var unary = t.unaryExpression("typeof", node.argument); - unary._ignoreSpecSymbols = true; - return t.conditionalExpression( - t.binaryExpression("===", unary, undefLiteral), - undefLiteral, - call - ); - } else { - return call; - } -} - -export function BinaryExpression(node, parent, scope, file) { - if (node.operator === "instanceof") { - return t.callExpression(file.addHelper("instanceof"), [node.left, node.right]); - } -} - -export function VariableDeclaration(node) { - if (node._generated) this.skip(); -} - -export { VariableDeclaration as FunctionDeclaration }; diff --git a/src/babel/transformation/transformers/index.js b/src/babel/transformation/transformers/index.js index b9a98fdefa..903bd084b1 100644 --- a/src/babel/transformation/transformers/index.js +++ b/src/babel/transformation/transformers/index.js @@ -16,7 +16,6 @@ export default { "spec.functionName": require("./spec/function-name"), "es6.spec.templateLiterals": require("./es6/spec.template-literals"), "es6.templateLiterals": require("./es6/template-literals"), - "es6.symbols": require("./es6/symbols"), //- builtin-basic // this is where the bulk of the ES6 transformations take place, none of them require traversal state @@ -52,6 +51,7 @@ export default { "es7.exportExtensions": require("./es7/export-extensions"), "spec.protoToAssign": require("./spec/proto-to-assign"), "es7.doExpressions": require("./es7/do-expressions"), + "es6.spec.symbols": require("./es6/spec.symbols"), "es7.functionBind": require("./es7/function-bind"), "spec.undefinedToVoid": require("./spec/undefined-to-void"), diff --git a/test/core/fixtures/transformation/es6.symbols/instanceof/actual.js b/test/core/fixtures/transformation/es6.spec.symbols/instanceof/actual.js similarity index 100% rename from test/core/fixtures/transformation/es6.symbols/instanceof/actual.js rename to test/core/fixtures/transformation/es6.spec.symbols/instanceof/actual.js diff --git a/test/core/fixtures/transformation/es6.symbols/instanceof/exec.js b/test/core/fixtures/transformation/es6.spec.symbols/instanceof/exec.js similarity index 100% rename from test/core/fixtures/transformation/es6.symbols/instanceof/exec.js rename to test/core/fixtures/transformation/es6.spec.symbols/instanceof/exec.js diff --git a/test/core/fixtures/transformation/es6.symbols/instanceof/expected.js b/test/core/fixtures/transformation/es6.spec.symbols/instanceof/expected.js similarity index 100% rename from test/core/fixtures/transformation/es6.symbols/instanceof/expected.js rename to test/core/fixtures/transformation/es6.spec.symbols/instanceof/expected.js diff --git a/test/core/fixtures/transformation/es6.spec.symbols/options.json b/test/core/fixtures/transformation/es6.spec.symbols/options.json new file mode 100644 index 0000000000..e007f6a10a --- /dev/null +++ b/test/core/fixtures/transformation/es6.spec.symbols/options.json @@ -0,0 +1,4 @@ +{ + "externalHelpers": true, + "optional": ["es6.spec.symbols"] +} diff --git a/test/core/fixtures/transformation/es6.symbols/typeof/actual.js b/test/core/fixtures/transformation/es6.spec.symbols/typeof/actual.js similarity index 100% rename from test/core/fixtures/transformation/es6.symbols/typeof/actual.js rename to test/core/fixtures/transformation/es6.spec.symbols/typeof/actual.js diff --git a/test/core/fixtures/transformation/es6.symbols/typeof/exec.js b/test/core/fixtures/transformation/es6.spec.symbols/typeof/exec.js similarity index 100% rename from test/core/fixtures/transformation/es6.symbols/typeof/exec.js rename to test/core/fixtures/transformation/es6.spec.symbols/typeof/exec.js diff --git a/test/core/fixtures/transformation/es6.symbols/typeof/expected.js b/test/core/fixtures/transformation/es6.spec.symbols/typeof/expected.js similarity index 100% rename from test/core/fixtures/transformation/es6.symbols/typeof/expected.js rename to test/core/fixtures/transformation/es6.spec.symbols/typeof/expected.js diff --git a/test/core/fixtures/transformation/es6.symbols/options.json b/test/core/fixtures/transformation/es6.symbols/options.json deleted file mode 100644 index 7d6e6cda1c..0000000000 --- a/test/core/fixtures/transformation/es6.symbols/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "externalHelpers": true -}