Skip to content

Commit

Permalink
Add deopt paths for let/const bindings in evaluate helper (babel#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
boopathi authored Aug 10, 2017
1 parent 391440b commit 56e87e6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/babel-helper-evaluate-path/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ function evaluateBasedOnControlFlow(binding, refPath) {
} else if (binding.kind === "let" || binding.kind === "const") {
// binding.path is the declarator
const declarator = binding.path;
const declaration = declarator.parentPath;

if (
declaration.parentPath.isIfStatement() ||
declaration.parentPath.isLoop() ||
declaration.parentPath.isSwitchCase()
) {
return { shouldDeopt: true };
}

let scopePath = declarator.scope.path;
if (scopePath.isFunction()) {
scopePath = scopePath.get("body");
Expand Down

0 comments on commit 56e87e6

Please sign in to comment.