diff --git a/packages/babel-plugin-transform-es2015-classes/src/index.js b/packages/babel-plugin-transform-es2015-classes/src/index.js index 8089594177da..6bdea6031d9a 100644 --- a/packages/babel-plugin-transform-es2015-classes/src/index.js +++ b/packages/babel-plugin-transform-es2015-classes/src/index.js @@ -38,7 +38,10 @@ export default function ({ types: t }) { if (node[VISITED]) return; const inferred = nameFunction(path); - if (inferred && inferred !== node) return path.replaceWith(inferred); + if (inferred && inferred !== node) { + path.replaceWith(inferred); + return; + } node[VISITED] = true; diff --git a/packages/babel-plugin-transform-es2015-for-of/src/index.js b/packages/babel-plugin-transform-es2015-for-of/src/index.js index 9b7c0ed8135e..3d18041e83ec 100644 --- a/packages/babel-plugin-transform-es2015-for-of/src/index.js +++ b/packages/babel-plugin-transform-es2015-for-of/src/index.js @@ -95,9 +95,11 @@ export default function ({ messages, template, types: t }) { ForOfStatement(path, state) { if (path.get("right").isArrayExpression()) { if (path.parentPath.isLabeledStatement()) { - return path.parentPath.replaceWithMultiple(_ForOfStatementArray(path)); + path.parentPath.replaceWithMultiple(_ForOfStatementArray(path)); + return; } else { - return path.replaceWithMultiple(_ForOfStatementArray(path)); + path.replaceWithMultiple(_ForOfStatementArray(path)); + return; } } diff --git a/packages/babel-traverse/src/path/modification.js b/packages/babel-traverse/src/path/modification.js index 052cd1afecc2..d80c1c331331 100644 --- a/packages/babel-traverse/src/path/modification.js +++ b/packages/babel-traverse/src/path/modification.js @@ -21,21 +21,19 @@ export function insertBefore(nodes) { (this.parentPath.isForStatement() && this.key === "init") ) { if (this.node) nodes.push(this.node); - this.replaceExpressionWithStatements(nodes); + return this.replaceExpressionWithStatements(nodes); } else { this._maybePopFromStatements(nodes); if (Array.isArray(this.container)) { return this._containerInsertBefore(nodes); } else if (this.isStatementOrBlock()) { if (this.node) nodes.push(this.node); - this._replaceWith(t.blockStatement(nodes)); + return this._replaceWith(t.blockStatement(nodes)); } else { throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?"); } } - - return [this]; } export function _containerInsert(from, nodes) { @@ -120,21 +118,19 @@ export function insertAfter(nodes) { nodes.unshift(t.expressionStatement(t.assignmentExpression("=", temp, this.node))); nodes.push(t.expressionStatement(temp)); } - this.replaceExpressionWithStatements(nodes); + return this.replaceExpressionWithStatements(nodes); } else { this._maybePopFromStatements(nodes); if (Array.isArray(this.container)) { return this._containerInsertAfter(nodes); } else if (this.isStatementOrBlock()) { if (this.node) nodes.unshift(this.node); - this._replaceWith(t.blockStatement(nodes)); + return this._replaceWith(t.blockStatement(nodes)); } else { throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?"); } } - - return [this]; } /** diff --git a/packages/babel-traverse/src/path/replacement.js b/packages/babel-traverse/src/path/replacement.js index b021f6c895a2..715a45a4f377 100644 --- a/packages/babel-traverse/src/path/replacement.js +++ b/packages/babel-traverse/src/path/replacement.js @@ -48,13 +48,14 @@ export function replaceWithMultiple(nodes: Array) { t.inheritLeadingComments(nodes[0], this.node); t.inheritTrailingComments(nodes[nodes.length - 1], this.node); this.node = this.container[this.key] = null; - this.insertAfter(nodes); + const paths = this.insertAfter(nodes); if (this.node) { this.requeue(); } else { this.remove(); } + return paths; } /** @@ -158,6 +159,8 @@ export function replaceWith(replacement) { // requeue for visiting this.requeue(); + + return [this]; } /** @@ -200,12 +203,12 @@ export function replaceExpressionWithStatements(nodes: Array) { // could be just one element due to the previous maybe popping if (exprs.length === 1) { - this.replaceWith(exprs[0]); + return this.replaceWith(exprs[0]); } else { - this.replaceWith(toSequenceExpression); + return this.replaceWith(toSequenceExpression); } } else if (toSequenceExpression) { - this.replaceWith(toSequenceExpression); + return this.replaceWith(toSequenceExpression); } else { const container = t.arrowFunctionExpression([], t.blockStatement(nodes)); @@ -240,7 +243,7 @@ export function replaceExpressionWithStatements(nodes: Array) { this.get("callee").arrowFunctionToExpression(); - return this.node; + return [this]; } } @@ -250,8 +253,9 @@ export function replaceInline(nodes: Object | Array) { if (Array.isArray(nodes)) { if (Array.isArray(this.container)) { nodes = this._verifyNodeList(nodes); - this._containerInsertAfter(nodes); - return this.remove(); + const paths = this._containerInsertAfter(nodes); + this.remove(); + return paths; } else { return this.replaceWithMultiple(nodes); }