throw error when attemping to replace a Program root node with another node not of type Program - closes #1762
This commit is contained in:
parent
92c4bbd003
commit
94c34e0132
@ -93,9 +93,13 @@ export function replaceWith(replacement, whateverAllowed) {
|
||||
}
|
||||
|
||||
// normalise inserting an entire AST
|
||||
if (t.isProgram(replacement)) {
|
||||
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