From 760d9837dcd555e2b7571b683780e86f1d4160d9 Mon Sep 17 00:00:00 2001 From: Boopathi Rajaa Date: Thu, 10 Aug 2017 11:37:29 +0200 Subject: [PATCH] Add deopt paths for let/const bindings in evaluate helper --- packages/babel-helper-evaluate-path/src/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/babel-helper-evaluate-path/src/index.js b/packages/babel-helper-evaluate-path/src/index.js index 4247d3f4d..debf58588 100644 --- a/packages/babel-helper-evaluate-path/src/index.js +++ b/packages/babel-helper-evaluate-path/src/index.js @@ -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");