committed by
GitHub
parent
20d2b4f98d
commit
e4f3964f67
15
node_modules/@babel/traverse/lib/path/replacement.js
generated
vendored
15
node_modules/@babel/traverse/lib/path/replacement.js
generated
vendored
@ -69,10 +69,11 @@ function replaceWithMultiple(nodes) {
|
||||
|
||||
function replaceWithSourceString(replacement) {
|
||||
this.resync();
|
||||
let ast;
|
||||
|
||||
try {
|
||||
replacement = `(${replacement})`;
|
||||
replacement = (0, _parser.parse)(replacement);
|
||||
ast = (0, _parser.parse)(replacement);
|
||||
} catch (err) {
|
||||
const loc = err.loc;
|
||||
|
||||
@ -89,23 +90,21 @@ function replaceWithSourceString(replacement) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
replacement = replacement.program.body[0].expression;
|
||||
const expressionAST = ast.program.body[0].expression;
|
||||
|
||||
_index.default.removeProperties(replacement);
|
||||
_index.default.removeProperties(expressionAST);
|
||||
|
||||
return this.replaceWith(replacement);
|
||||
return this.replaceWith(expressionAST);
|
||||
}
|
||||
|
||||
function replaceWith(replacement) {
|
||||
function replaceWith(replacementPath) {
|
||||
this.resync();
|
||||
|
||||
if (this.removed) {
|
||||
throw new Error("You can't replace this node, we've already removed it");
|
||||
}
|
||||
|
||||
if (replacement instanceof _index2.default) {
|
||||
replacement = replacement.node;
|
||||
}
|
||||
let replacement = replacementPath instanceof _index2.default ? replacementPath.node : replacementPath;
|
||||
|
||||
if (!replacement) {
|
||||
throw new Error("You passed `path.replaceWith()` a falsy node, use `path.remove()` instead");
|
||||
|
Reference in New Issue
Block a user