diff --git a/src/babel/transformation/helpers/remap-async-to-generator.js b/src/babel/transformation/helpers/remap-async-to-generator.js index dc22c076fd..e0ca170036 100644 --- a/src/babel/transformation/helpers/remap-async-to-generator.js +++ b/src/babel/transformation/helpers/remap-async-to-generator.js @@ -25,11 +25,13 @@ var referenceVisitor = { } }; -export default function (node, callId, scope) { +export default function (path, callId) { + var node = path.node; + node.async = false; node.generator = true; - scope.traverse(node, awaitVisitor, state); + path.traverse(awaitVisitor, state); var call = t.callExpression(callId, [node]); @@ -44,11 +46,11 @@ export default function (node, callId, scope) { return declar; } else { if (id) { - var state = { id: id }; - scope.traverse(node, referenceVisitor, state); + var state = { id }; + path.traverse(referenceVisitor, state); if (state.ref) { - scope.parent.push({ id: state.ref }); + path.scope.parent.push({ id: state.ref }); return t.assignmentExpression("=", state.ref, call); } } diff --git a/src/babel/transformation/transformers/es6/destructuring.js b/src/babel/transformation/transformers/es6/destructuring.js index 3cbb08c6ef..60db95a446 100644 --- a/src/babel/transformation/transformers/es6/destructuring.js +++ b/src/babel/transformation/transformers/es6/destructuring.js @@ -56,15 +56,22 @@ export function ForOfStatement(node, parent, scope, file) { export { ForOfStatement as ForInStatement }; export function Func/*tion*/(node, parent, scope, file) { + var hasDestructuring = false; + for (let pattern of (node.params: Array)) { + if (t.isPattern(pattern)) { + hasDestructuring = true; + break; + } + } + if (!hasDestructuring) return; + var nodes = []; - var hasDestructuring = false; + for (var i = 0; i < node.params.length; i++) { + let pattern = node.params[i]; + if (!t.isPattern(pattern)) continue; - node.params = node.params.map(function (pattern, i) { - if (!t.isPattern(pattern)) return pattern; - - hasDestructuring = true; - var ref = scope.generateUidIdentifier("ref"); + var ref = node.params[i] = scope.generateUidIdentifier("ref"); t.inherits(ref, pattern); var destructuring = new DestructuringTransformer({ @@ -74,12 +81,9 @@ export function Func/*tion*/(node, parent, scope, file) { file: file, kind: "let" }); + destructuring.init(pattern, ref); - - return ref; - }); - - if (!hasDestructuring) return; + } t.ensureBlock(node); @@ -216,8 +220,8 @@ function hasRest(pattern) { } var arrayUnpackVisitor = { - enter(node, parent, scope, state) { - if (this.isReferencedIdentifier() && state.bindings[node.name]) { + ReferencedIdentifier(node, parent, scope, state) { + if (state.bindings[node.name]) { state.deopt = true; this.stop(); } diff --git a/src/babel/transformation/transformers/es6/spread.js b/src/babel/transformation/transformers/es6/spread.js index 70e9e471e2..a6ae3a05cc 100644 --- a/src/babel/transformation/transformers/es6/spread.js +++ b/src/babel/transformation/transformers/es6/spread.js @@ -1,7 +1,7 @@ import * as t from "../../../types"; function getSpreadLiteral(spread, scope) { - if (scope.file.isLoose("es6.spread")) { + if (scope.hub.file.isLoose("es6.spread")) { return spread.argument; } else { return scope.toArray(spread.argument, true); diff --git a/src/babel/transformation/transformers/internal/modules.js b/src/babel/transformation/transformers/internal/modules.js index c1c2317b17..ab1e9fe699 100644 --- a/src/babel/transformation/transformers/internal/modules.js +++ b/src/babel/transformation/transformers/internal/modules.js @@ -83,7 +83,7 @@ export function ExportNamedDeclaration(node, parent, scope) { export var Program = { enter(node) { var imports = []; - var rest = []; + var rest = []; for (var i = 0; i < node.body.length; i++) { var bodyNode = node.body[i]; diff --git a/src/babel/transformation/transformers/other/async-to-generator.js b/src/babel/transformation/transformers/other/async-to-generator.js index fa33507c18..a3f9a1aaac 100644 --- a/src/babel/transformation/transformers/other/async-to-generator.js +++ b/src/babel/transformation/transformers/other/async-to-generator.js @@ -10,5 +10,5 @@ export var metadata = { export function Func/*tion*/(node, parent, scope, file) { if (!node.async || node.generator) return; - return remapAsyncToGenerator(node, file.addHelper("async-to-generator"), scope); + return remapAsyncToGenerator(this, file.addHelper("async-to-generator")); } diff --git a/src/babel/transformation/transformers/other/bluebird-coroutines.js b/src/babel/transformation/transformers/other/bluebird-coroutines.js index 1d45d46396..65f3eda4b2 100644 --- a/src/babel/transformation/transformers/other/bluebird-coroutines.js +++ b/src/babel/transformation/transformers/other/bluebird-coroutines.js @@ -14,8 +14,7 @@ export function Func/*tion*/(node, parent, scope, file) { if (!node.async || node.generator) return; return remapAsyncToGenerator( - node, - t.memberExpression(file.addImport("bluebird", null, "absolute"), t.identifier("coroutine")), - scope + this, + t.memberExpression(file.addImport("bluebird", null, "absolute"), t.identifier("coroutine")) ); } diff --git a/src/babel/traversal/path/verification.js b/src/babel/traversal/path/verification.js index 38a6d23b0d..38b5fde27f 100644 --- a/src/babel/traversal/path/verification.js +++ b/src/babel/traversal/path/verification.js @@ -151,7 +151,7 @@ export function isCompletionRecord(allowInsideFunction?) { */ export function isStatementOrBlock() { - if (t.isLabeledStatement(this.parent) || t.isBlockStatement(this.container)) { + if (this.parentPath.isLabeledStatement() || t.isBlockStatement(this.container)) { return false; } else { return includes(t.STATEMENT_OR_BLOCK_KEYS, this.key);