fix Program can only be replaced with another Program error
This commit is contained in:
parent
4b6c954f5e
commit
2910d4f82c
@ -92,14 +92,14 @@ export function replaceWith(replacement, whateverAllowed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isProgram() && !t.isProgram(replacement)) {
|
||||
throw new Error("You can only replace a Program root node with another Program node");
|
||||
}
|
||||
|
||||
// normalise inserting an entire AST
|
||||
if (t.isProgram(replacement) && !this.isProgram()) {
|
||||
replacement = replacement.body;
|
||||
whateverAllowed = true;
|
||||
} else {
|
||||
if (this.isProgram()) {
|
||||
throw new Error("You can only replace a Program root node with another Program node");
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(replacement)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user