diff --git a/src/babel/transformation/transformers/deprecated.json b/src/babel/transformation/transformers/deprecated.json index 3677c988f5..ceb2a42800 100644 --- a/src/babel/transformation/transformers/deprecated.json +++ b/src/babel/transformation/transformers/deprecated.json @@ -8,5 +8,8 @@ "utility.inlineExpressions": "minification.constantFolding", "utility.deadCodeElimination": "minification.deadCodeElimination", "utility.removeConsoleCalls": "minification.removeConsole", - "utility.removeDebugger": "minification.removeDebugger" + "utility.removeDebugger": "minification.removeDebugger", + + "es6.parameters.rest": "es6.parameters", + "es6.parameters.default": "es6.parameters" } diff --git a/src/babel/transformation/transformers/es6/destructuring.js b/src/babel/transformation/transformers/es6/destructuring.js index d1c79fd5e0..ebf7751d7a 100644 --- a/src/babel/transformation/transformers/es6/destructuring.js +++ b/src/babel/transformation/transformers/es6/destructuring.js @@ -70,7 +70,15 @@ export var visitor = { let pattern = node.params[i]; if (!t.isPattern(pattern)) continue; - var ref = node.params[i] = scope.generateUidIdentifier("ref"); + var ref = scope.generateUidIdentifier("ref"); + if (t.isAssignmentPattern(pattern)) { + var _pattern = pattern; + pattern = pattern.left; + _pattern.left = ref; + } else { + node.params[i] = ref; + } + t.inherits(ref, pattern); var destructuring = new DestructuringTransformer({ diff --git a/src/babel/transformation/transformers/es6/parameters.default.js b/src/babel/transformation/transformers/es6/parameters/default.js similarity index 92% rename from src/babel/transformation/transformers/es6/parameters.default.js rename to src/babel/transformation/transformers/es6/parameters/default.js index f6cd429a2f..7e022d8811 100644 --- a/src/babel/transformation/transformers/es6/parameters.default.js +++ b/src/babel/transformation/transformers/es6/parameters/default.js @@ -1,7 +1,7 @@ -import callDelegate from "../../helpers/call-delegate"; -import getFunctionArity from "../../helpers/get-function-arity"; -import * as util from "../../../util"; -import * as t from "../../../types"; +import callDelegate from "../../../helpers/call-delegate"; +import getFunctionArity from "../../../helpers/get-function-arity"; +import * as util from "../../../../util"; +import * as t from "../../../../types"; var hasDefaults = function (node) { for (var i = 0; i < node.params.length; i++) { @@ -38,7 +38,7 @@ export var visitor = { // var argsIdentifier = t.identifier("arguments"); - argsIdentifier._shadowedFunctionLiteral = true; + argsIdentifier._shadowedFunctionLiteral = node; // push a default parameter definition function pushDefNode(left, right, i) { diff --git a/src/babel/transformation/transformers/es6/parameters/index.js b/src/babel/transformation/transformers/es6/parameters/index.js new file mode 100644 index 0000000000..a18bc96c28 --- /dev/null +++ b/src/babel/transformation/transformers/es6/parameters/index.js @@ -0,0 +1,11 @@ +import * as util from "../../../../util"; +import * as visitors from "../../../../traversal/visitors"; + +import * as def from "./default"; +import * as rest from "./rest"; + +export var metadata = { + group: "builtin-advanced" +}; + +export var visitor = visitors.merge([rest.visitor, def.visitor]); diff --git a/src/babel/transformation/transformers/es6/parameters.rest.js b/src/babel/transformation/transformers/es6/parameters/rest.js similarity index 97% rename from src/babel/transformation/transformers/es6/parameters.rest.js rename to src/babel/transformation/transformers/es6/parameters/rest.js index 1ccb6572c3..4d1ee7f93a 100644 --- a/src/babel/transformation/transformers/es6/parameters.rest.js +++ b/src/babel/transformation/transformers/es6/parameters/rest.js @@ -1,5 +1,5 @@ -import * as util from "../../../util"; -import * as t from "../../../types"; +import * as util from "../../../../util"; +import * as t from "../../../../types"; var memberExpressionOptimisationVisitor = { Scope(node, parent, scope, state) { @@ -84,7 +84,7 @@ export var visitor = { var argsId = t.identifier("arguments"); // otherwise `arguments` will be remapped in arrow functions - argsId._shadowedFunctionLiteral = true; + argsId._shadowedFunctionLiteral = node; // support patterns if (t.isPattern(rest)) { diff --git a/src/babel/transformation/transformers/es6/spread.js b/src/babel/transformation/transformers/es6/spread.js index 698f394c59..3d5c3a3663 100644 --- a/src/babel/transformation/transformers/es6/spread.js +++ b/src/babel/transformation/transformers/es6/spread.js @@ -43,6 +43,10 @@ function build(props, scope) { return nodes; } +export var metadata = { + group: "builtin-advanced" +}; + export var visitor = { ArrayExpression(node, parent, scope) { var elements = node.elements; diff --git a/src/babel/transformation/transformers/es6/tail-call.js b/src/babel/transformation/transformers/es6/tail-call.js index 104cd65a6c..115624241f 100644 --- a/src/babel/transformation/transformers/es6/tail-call.js +++ b/src/babel/transformation/transformers/es6/tail-call.js @@ -211,7 +211,7 @@ class TailCallTransformer { var decl = t.variableDeclarator(this.argumentsId); if (this.argumentsId) { decl.init = t.identifier("arguments"); - decl.init._shadowedFunctionLiteral = true; + decl.init._shadowedFunctionLiteral = node; } topVars.push(decl); } diff --git a/src/babel/transformation/transformers/index.js b/src/babel/transformation/transformers/index.js index b90d40d342..31e1bde216 100644 --- a/src/babel/transformation/transformers/index.js +++ b/src/babel/transformation/transformers/index.js @@ -46,9 +46,6 @@ export default { "es6.regex.sticky": require("./es6/regex.sticky"), "es6.regex.unicode": require("./es6/regex.unicode"), "es6.constants": require("./es6/constants"), - "es6.parameters.rest": require("./es6/parameters.rest"), - "es6.spread": require("./es6/spread"), - "es6.parameters.default": require("./es6/parameters.default"), "es7.exportExtensions": require("./es7/export-extensions"), "spec.protoToAssign": require("babel-plugin-proto-to-assign"), "es7.doExpressions": require("./es7/do-expressions"), @@ -57,6 +54,8 @@ export default { "spec.undefinedToVoid": require("babel-plugin-undefined-to-void"), //- builtin-advanced + "es6.spread": require("./es6/spread"), + "es6.parameters": require("./es6/parameters"), "es6.destructuring": require("./es6/destructuring"), "es6.blockScoping": require("./es6/block-scoping"), "es6.spec.blockScoping": require("./es6/spec.block-scoping"), diff --git a/src/babel/transformation/transformers/internal/shadow-functions.js b/src/babel/transformation/transformers/internal/shadow-functions.js index 2c8fc030f3..223cae1b82 100644 --- a/src/babel/transformation/transformers/internal/shadow-functions.js +++ b/src/babel/transformation/transformers/internal/shadow-functions.js @@ -10,6 +10,9 @@ function remap(path, key, create) { var fnPath = path.findParent((path) => !path.is("shadow") && (path.isFunction() || path.isProgram())); + var shadowed = path.node._shadowedFunctionLiteral; + if (shadowed && shadowed !== fnPath.node) return; + var cached = fnPath.getData(key); if (cached) return cached; @@ -28,7 +31,7 @@ export var visitor = { }, ReferencedIdentifier(node) { - if (node.name === "arguments" && !node._shadowedFunctionLiteral) { + if (node.name === "arguments") { return remap(this, "arguments", () => t.identifier("arguments")); } } diff --git a/src/babel/traversal/visitors.js b/src/babel/traversal/visitors.js index fa093d71d8..b51df8b642 100644 --- a/src/babel/traversal/visitors.js +++ b/src/babel/traversal/visitors.js @@ -126,6 +126,8 @@ export function merge(visitors) { var rootVisitor = {}; for (var visitor of (visitors: Array)) { + explode(visitor); + for (var type in visitor) { var nodeVisitor = rootVisitor[type] = rootVisitor[type] || {}; mergePair(nodeVisitor, visitor[type]); diff --git a/test/core/fixtures/transformation/es6.parameters.default/before-last/actual.js b/test/core/fixtures/transformation/es6.parameters/default-before-last/actual.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.default/before-last/actual.js rename to test/core/fixtures/transformation/es6.parameters/default-before-last/actual.js diff --git a/test/core/fixtures/transformation/es6.parameters.default/before-last/expected.js b/test/core/fixtures/transformation/es6.parameters/default-before-last/expected.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.default/before-last/expected.js rename to test/core/fixtures/transformation/es6.parameters/default-before-last/expected.js diff --git a/test/core/fixtures/transformation/es6.parameters.default/destructuring/exec.js b/test/core/fixtures/transformation/es6.parameters/default-destructuring/exec.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.default/destructuring/exec.js rename to test/core/fixtures/transformation/es6.parameters/default-destructuring/exec.js diff --git a/test/core/fixtures/transformation/es6.parameters.default/eval/actual.js b/test/core/fixtures/transformation/es6.parameters/default-eval/actual.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.default/eval/actual.js rename to test/core/fixtures/transformation/es6.parameters/default-eval/actual.js diff --git a/test/core/fixtures/transformation/es6.parameters.default/eval/expected.js b/test/core/fixtures/transformation/es6.parameters/default-eval/expected.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.default/eval/expected.js rename to test/core/fixtures/transformation/es6.parameters/default-eval/expected.js diff --git a/test/core/fixtures/transformation/es6.parameters.default/iife-1128/exec.js b/test/core/fixtures/transformation/es6.parameters/default-iife-1128/exec.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.default/iife-1128/exec.js rename to test/core/fixtures/transformation/es6.parameters/default-iife-1128/exec.js diff --git a/test/core/fixtures/transformation/es6.parameters.default/multiple/actual.js b/test/core/fixtures/transformation/es6.parameters/default-multiple/actual.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.default/multiple/actual.js rename to test/core/fixtures/transformation/es6.parameters/default-multiple/actual.js diff --git a/test/core/fixtures/transformation/es6.parameters.default/multiple/expected.js b/test/core/fixtures/transformation/es6.parameters/default-multiple/expected.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.default/multiple/expected.js rename to test/core/fixtures/transformation/es6.parameters/default-multiple/expected.js diff --git a/test/core/fixtures/transformation/es6.parameters.default/single/actual.js b/test/core/fixtures/transformation/es6.parameters/default-single/actual.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.default/single/actual.js rename to test/core/fixtures/transformation/es6.parameters/default-single/actual.js diff --git a/test/core/fixtures/transformation/es6.parameters.default/single/expected.js b/test/core/fixtures/transformation/es6.parameters/default-single/expected.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.default/single/expected.js rename to test/core/fixtures/transformation/es6.parameters/default-single/expected.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/arrow-functions/actual.js b/test/core/fixtures/transformation/es6.parameters/rest-arrow-functions/actual.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/arrow-functions/actual.js rename to test/core/fixtures/transformation/es6.parameters/rest-arrow-functions/actual.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/arrow-functions/expected.js b/test/core/fixtures/transformation/es6.parameters/rest-arrow-functions/expected.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/arrow-functions/expected.js rename to test/core/fixtures/transformation/es6.parameters/rest-arrow-functions/expected.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/async-function/actual.js b/test/core/fixtures/transformation/es6.parameters/rest-async-function/actual.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/async-function/actual.js rename to test/core/fixtures/transformation/es6.parameters/rest-async-function/actual.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/async-function/expected.js b/test/core/fixtures/transformation/es6.parameters/rest-async-function/expected.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/async-function/expected.js rename to test/core/fixtures/transformation/es6.parameters/rest-async-function/expected.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/async-function/options.json b/test/core/fixtures/transformation/es6.parameters/rest-async-function/options.json similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/async-function/options.json rename to test/core/fixtures/transformation/es6.parameters/rest-async-function/options.json diff --git a/test/core/fixtures/transformation/es6.parameters.rest/deepest-common-ancestor-earliest-child/actual.js b/test/core/fixtures/transformation/es6.parameters/rest-deepest-common-ancestor-earliest-child/actual.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/deepest-common-ancestor-earliest-child/actual.js rename to test/core/fixtures/transformation/es6.parameters/rest-deepest-common-ancestor-earliest-child/actual.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/deepest-common-ancestor-earliest-child/expected.js b/test/core/fixtures/transformation/es6.parameters/rest-deepest-common-ancestor-earliest-child/expected.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/deepest-common-ancestor-earliest-child/expected.js rename to test/core/fixtures/transformation/es6.parameters/rest-deepest-common-ancestor-earliest-child/expected.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/member-expression-deoptimisation/actual.js b/test/core/fixtures/transformation/es6.parameters/rest-member-expression-deoptimisation/actual.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/member-expression-deoptimisation/actual.js rename to test/core/fixtures/transformation/es6.parameters/rest-member-expression-deoptimisation/actual.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/member-expression-deoptimisation/expected.js b/test/core/fixtures/transformation/es6.parameters/rest-member-expression-deoptimisation/expected.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/member-expression-deoptimisation/expected.js rename to test/core/fixtures/transformation/es6.parameters/rest-member-expression-deoptimisation/expected.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/member-expression-optimisation/actual.js b/test/core/fixtures/transformation/es6.parameters/rest-member-expression-optimisation/actual.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/member-expression-optimisation/actual.js rename to test/core/fixtures/transformation/es6.parameters/rest-member-expression-optimisation/actual.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/member-expression-optimisation/expected.js b/test/core/fixtures/transformation/es6.parameters/rest-member-expression-optimisation/expected.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/member-expression-optimisation/expected.js rename to test/core/fixtures/transformation/es6.parameters/rest-member-expression-optimisation/expected.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/multiple/actual.js b/test/core/fixtures/transformation/es6.parameters/rest-multiple/actual.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/multiple/actual.js rename to test/core/fixtures/transformation/es6.parameters/rest-multiple/actual.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/multiple/expected.js b/test/core/fixtures/transformation/es6.parameters/rest-multiple/expected.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/multiple/expected.js rename to test/core/fixtures/transformation/es6.parameters/rest-multiple/expected.js diff --git a/test/core/fixtures/transformation/es6.parameters/rest-nested-iife/actual.js b/test/core/fixtures/transformation/es6.parameters/rest-nested-iife/actual.js new file mode 100644 index 0000000000..3a60098259 --- /dev/null +++ b/test/core/fixtures/transformation/es6.parameters/rest-nested-iife/actual.js @@ -0,0 +1,6 @@ +function broken(x, ...foo) { + if (true) { + class Foo extends Bar { } + return hello(...foo) + } +} diff --git a/test/core/fixtures/transformation/es6.parameters/rest-nested-iife/expected.js b/test/core/fixtures/transformation/es6.parameters/rest-nested-iife/expected.js new file mode 100644 index 0000000000..509591d150 --- /dev/null +++ b/test/core/fixtures/transformation/es6.parameters/rest-nested-iife/expected.js @@ -0,0 +1,35 @@ +"use strict"; + +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } + +function broken(x) { + for (var _len = arguments.length, foo = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + foo[_key - 1] = arguments[_key]; + } + + if (true) { + var _ret = (function () { + var Foo = (function (_Bar) { + function Foo() { + _classCallCheck(this, Foo); + + _get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments); + } + + _inherits(Foo, _Bar); + + return Foo; + })(Bar); + + return { + v: hello.apply(undefined, foo) + }; + })(); + + if (typeof _ret === "object") return _ret.v; + } +} diff --git a/test/core/fixtures/transformation/es6.parameters.rest/pattern/actual.js b/test/core/fixtures/transformation/es6.parameters/rest-pattern/actual.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/pattern/actual.js rename to test/core/fixtures/transformation/es6.parameters/rest-pattern/actual.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/pattern/expected.js b/test/core/fixtures/transformation/es6.parameters/rest-pattern/expected.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/pattern/expected.js rename to test/core/fixtures/transformation/es6.parameters/rest-pattern/expected.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/spread-optimisation/actual.js b/test/core/fixtures/transformation/es6.parameters/rest-spread-optimisation/actual.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/spread-optimisation/actual.js rename to test/core/fixtures/transformation/es6.parameters/rest-spread-optimisation/actual.js diff --git a/test/core/fixtures/transformation/es6.parameters.rest/spread-optimisation/expected.js b/test/core/fixtures/transformation/es6.parameters/rest-spread-optimisation/expected.js similarity index 100% rename from test/core/fixtures/transformation/es6.parameters.rest/spread-optimisation/expected.js rename to test/core/fixtures/transformation/es6.parameters/rest-spread-optimisation/expected.js