diff --git a/src/babel/traversal/path/modification.js b/src/babel/traversal/path/modification.js index ea0bb4263d..8cc79aa229 100644 --- a/src/babel/traversal/path/modification.js +++ b/src/babel/traversal/path/modification.js @@ -140,6 +140,8 @@ export function _verifyNodeList(nodes) { throw new Error(`Node list contains a non-object node with the index of ${i}`); } else if (!node.type) { throw new Error(`Node list contains a node without a type with the index of ${i}`); + } else if (node instanceof NodePath) { + nodes[i] = node.node; } } diff --git a/src/babel/traversal/path/replacement.js b/src/babel/traversal/path/replacement.js index 24efd393a0..5aa9da0258 100644 --- a/src/babel/traversal/path/replacement.js +++ b/src/babel/traversal/path/replacement.js @@ -1,4 +1,5 @@ import codeFrame from "../../helpers/code-frame"; +import NodePath from "./index"; import traverse from "../index"; import * as t from "../../types"; import parse from "../../helpers/parse"; @@ -79,6 +80,10 @@ export function replaceWith(replacement, whateverAllowed) { throw new Error("You can't replace this node, we've already removed it"); } + if (replacement instanceof NodePath) { + replacement = replacement.node; + } + if (!replacement) { throw new Error("You passed `path.replaceWith()` a falsy node, use `path.dangerouslyRemove()` instead"); }