throw error when attemping to replace a Program root node with another node not of type Program - closes #1762

This commit is contained in:
Sebastian McKenzie 2015-06-16 01:53:53 +01:00
parent 92c4bbd003
commit 94c34e0132

View File

@ -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)) {