allow NodePaths to be returned in node removal/replacement methods and coerce them to nodes
This commit is contained in:
parent
48ecec1e2e
commit
7b676d608b
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user