Skip to content

Commit

Permalink
fix(deadcode): account for impure paths inside for statements (#834)
Browse files Browse the repository at this point in the history
* fix(deadcode): account for impure paths inside for statements

* add env test
  • Loading branch information
vigneshshanmugam authored and boopathi committed May 10, 2018
1 parent 37ccf8c commit 5f60189
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ for (; true; ) {
for (; false; ) {
baz();
}
for (var j; false; ) {
blah();
}
for (0; false; ) {}

// do_while
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ for (;;) {
bar();
}

var j;

// do_while
do {
foo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,12 @@ module.exports = ({ types: t, traverse }) => {
if (result.value) {
test.remove();
} else {
path.remove();
const init = path.get("init");
if (init.node && !init.isPure()) {
path.replaceWith(init);
} else {
path.remove();
}
}
}
},
Expand Down
13 changes: 13 additions & 0 deletions packages/babel-preset-minify/__tests__/minify-env-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,17 @@ describe("preset along with env", () => {
})();
`
);

thePlugin(
"should fix issue#824 simplify + deadcode",
`
let foo;
while (0) {}
console.log(foo);
`,
`
var foo;
console.log(foo);
`
);
});

0 comments on commit 5f60189

Please sign in to comment.