From 2910d4f82c06069efe8232676a25bdabe5d844d6 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Mon, 22 Jun 2015 20:36:34 +0100 Subject: [PATCH] fix Program can only be replaced with another Program error --- src/babel/traversal/path/replacement.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/babel/traversal/path/replacement.js b/src/babel/traversal/path/replacement.js index 3f425b891e..e86a117392 100644 --- a/src/babel/traversal/path/replacement.js +++ b/src/babel/traversal/path/replacement.js @@ -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)) {