Skip to content

Commit

Permalink
fix(dce): handle array and object patterns in assignment expressions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
boopathi committed Jul 17, 2018
1 parent 650149b commit 2ed8531
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
@@ -0,0 +1,7 @@
async function example() {
var foo, bar;
try {
[foo, bar] = await Promise.all([req(1), req(2)]);
} catch (e) {}
console.log(foo);
}
@@ -0,0 +1,9 @@
async function example() {
var foo, bar;

try {
[foo, bar] = await Promise.all([req(1), req(2)]);
} catch (e) {}

console.log(foo);
}
15 changes: 11 additions & 4 deletions packages/babel-plugin-minify-dead-code-elimination/src/index.js
Expand Up @@ -235,10 +235,17 @@ module.exports = ({ types: t, traverse }) => {
bail = true;
}

if (p.isAssignmentExpression() && !p.get("right").isPure()) {
mutations.push(() => p.replaceWith(p.get("right")));
} else {
mutations.push(() => removeOrVoid(p));
if (p.isAssignmentExpression()) {
if (
t.isArrayPattern(p.node.left) ||
t.isObjectPattern(p.node.left)
) {
bail = true;
} else if (p.get("right").isPure()) {
mutations.push(() => removeOrVoid(p));
} else {
mutations.push(() => p.replaceWith(p.get("right")));
}
}
});

Expand Down

0 comments on commit 2ed8531

Please sign in to comment.