Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deadcode): account for impure paths inside for statements #834

Merged
merged 2 commits into from May 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,6 +19,10 @@ for (; true; ) {
for (; false; ) {
baz();
}
for (var j; false; ) {
blah();
}
for (0; false; ) {}

// do_while
do {
Expand Down
Expand Up @@ -16,6 +16,8 @@ for (;;) {
bar();
}

var j;

// do_while
do {
foo();
Expand Down
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
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);
`
);
});