Merge pull request #3583 from jhen0409/patch-3

Add block if parent is non-block statement for remove-console/debugger
This commit is contained in:
Logan Smyth 2016-07-18 22:21:10 -07:00 committed by GitHub
commit 40ec299df5
7 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,6 @@
if (blah) console.log(blah);
for (;;) console.log(blah);
for (var blah in []) console.log(blah);
for (var blah of []) console.log(blah);
while (blah) console.log(blah);
do console.log(blah); while (blah);

View File

@ -0,0 +1,6 @@
if (blah) {}
for (;;) {}
for (var blah in []) {}
for (var blah of []) {}
while (blah) {}
do {} while (blah);

View File

@ -0,0 +1,3 @@
{
"plugins": ["transform-remove-debugger"]
}

View File

@ -0,0 +1,6 @@
if (blah) debugger;
for (;;) debugger;
for (var blah in []) debugger;
for (var blah of []) debugger;
while (blah) debugger;
do debugger; while (blah);

View File

@ -0,0 +1,6 @@
if (blah) {}
for (;;) {}
for (var blah in []) {}
for (var blah of []) {}
while (blah) {}
do {} while (blah);

View File

@ -0,0 +1 @@
require("babel-helper-plugin-test-runner")(__dirname);

View File

@ -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;
}
}
];