From e464b9ab87400d1d6e3024f38a6a02c9e2243118 Mon Sep 17 00:00:00 2001 From: Jhen Date: Mon, 18 Jul 2016 02:18:11 +0800 Subject: [PATCH] Add block if parent is no block statement for remove-console/debugger --- .../babel-traverse/src/path/lib/removal-hooks.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/babel-traverse/src/path/lib/removal-hooks.js b/packages/babel-traverse/src/path/lib/removal-hooks.js index 97cacbca8b..fc232871e5 100644 --- a/packages/babel-traverse/src/path/lib/removal-hooks.js +++ b/packages/babel-traverse/src/path/lib/removal-hooks.js @@ -64,5 +64,18 @@ export let hooks = [ } return true; } + }, + + function (self, parent) { + if ( + (parent.isIfStatement() && (self.key === 'consequent' || self.key === 'alternate')) || + (parent.isLoop() && self.key === 'body') + ) { + self.replaceWith({ + type: 'BlockStatement', + body: [] + }); + return true; + } } ];