From 55750e05e75a101694b7bf4b751291bae070de57 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 5 Jun 2015 09:44:22 +0100 Subject: [PATCH] Revert "enable es6.spec.symbols by default" This reverts commit f3acedbf08565a7b0b3796f6ef6fb95150359602. --- .../transformers/deprecated.json | 2 +- .../transformers/es6/spec.symbols.js | 37 ++++++++++++++++ .../transformers/es6/symbols.js | 44 ------------------- .../transformation/transformers/index.js | 2 +- .../instanceof/actual.js | 0 .../instanceof/exec.js | 0 .../instanceof/expected.js | 0 .../es6.spec.symbols/options.json | 4 ++ .../typeof/actual.js | 0 .../typeof/exec.js | 0 .../typeof/expected.js | 0 .../transformation/es6.symbols/options.json | 3 -- 12 files changed, 43 insertions(+), 49 deletions(-) create mode 100644 src/babel/transformation/transformers/es6/spec.symbols.js delete mode 100644 src/babel/transformation/transformers/es6/symbols.js rename test/core/fixtures/transformation/{es6.symbols => es6.spec.symbols}/instanceof/actual.js (100%) rename test/core/fixtures/transformation/{es6.symbols => es6.spec.symbols}/instanceof/exec.js (100%) rename test/core/fixtures/transformation/{es6.symbols => es6.spec.symbols}/instanceof/expected.js (100%) create mode 100644 test/core/fixtures/transformation/es6.spec.symbols/options.json rename test/core/fixtures/transformation/{es6.symbols => es6.spec.symbols}/typeof/actual.js (100%) rename test/core/fixtures/transformation/{es6.symbols => es6.spec.symbols}/typeof/exec.js (100%) rename test/core/fixtures/transformation/{es6.symbols => es6.spec.symbols}/typeof/expected.js (100%) delete mode 100644 test/core/fixtures/transformation/es6.symbols/options.json 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 -}