babel-plugin-minify-dead-code-elimination
Advanced tools
Comparing version 0.5.0-alpha.540d75e7 to 0.5.0-alpha.5a128fd5
@@ -278,6 +278,10 @@ "use strict"; | ||
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"))); | ||
} | ||
} | ||
@@ -609,6 +613,27 @@ }); | ||
exit(path) { | ||
const evaluated = evaluate(path.get("discriminant"), { | ||
const discriminantPath = path.get("discriminant"); | ||
const evaluated = evaluate(discriminantPath, { | ||
tdz: this.tdz | ||
}); | ||
if (!evaluated.confident) return; | ||
if (!evaluated.confident) return; // the simplify transformation might have brought in the previous | ||
// expressions into the switch's test expression and instead of | ||
// bailing out of impure path, we collect the impurities of it's | ||
// a sequence expression and bail out if the primary test itself | ||
// is impure | ||
let beforeTest = []; | ||
if (t.isSequenceExpression(discriminantPath.node)) { | ||
const expressions = discriminantPath.get("expressions"); | ||
const lastExpression = expressions[expressions.length - 1]; | ||
if (!lastExpression.isPure()) { | ||
return; | ||
} | ||
beforeTest = [t.expressionStatement(t.sequenceExpression(expressions.slice(0, expressions.length - 1).map(path => path.node)))]; | ||
} else if (!discriminantPath.isPure()) { | ||
return; | ||
} | ||
const discriminant = evaluated.value; | ||
@@ -658,3 +683,3 @@ const cases = path.get("cases"); | ||
replaceSwitch([...extractVars(path), ...result.statements]); | ||
replaceSwitch([...extractVars(path), ...beforeTest, ...result.statements]); | ||
@@ -661,0 +686,0 @@ function getStatementsUntilBreak(start) { |
{ | ||
"name": "babel-plugin-minify-dead-code-elimination", | ||
"version": "0.5.0-alpha.540d75e7", | ||
"version": "0.5.0-alpha.5a128fd5", | ||
"description": "", | ||
@@ -15,7 +15,7 @@ "keywords": [ | ||
"dependencies": { | ||
"babel-helper-evaluate-path": "^0.5.0-alpha.540d75e7", | ||
"babel-helper-mark-eval-scopes": "^0.5.0-alpha.540d75e7", | ||
"babel-helper-remove-or-void": "^0.5.0-alpha.540d75e7", | ||
"babel-helper-evaluate-path": "^0.5.0-alpha.5a128fd5", | ||
"babel-helper-mark-eval-scopes": "^0.5.0-alpha.5a128fd5", | ||
"babel-helper-remove-or-void": "^0.5.0-alpha.5a128fd5", | ||
"lodash.some": "^4.6.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46707
1193