babel-helper-evaluate-path
Advanced tools
Comparing version 0.5.0-alpha.1cb46b73 to 0.5.0-alpha.2ec8ff72
@@ -168,12 +168,13 @@ "use strict"; | ||
const fnParent = (binding.path.scope.getFunctionParent() || binding.path.scope.getProgramParent()).path; | ||
let blockParent = binding.path.scope.getBlockParent().path; | ||
let blockParentPath = binding.path.scope.getBlockParent().path; | ||
let blockParent = blockParentPath.node; | ||
if (blockParent === fnParent && !fnParent.isProgram()) { | ||
blockParent = blockParent.get("body"); | ||
if (blockParentPath === fnParent && !fnParent.isProgram()) { | ||
blockParent = blockParent.body; | ||
} // detect Usage Outside Init Scope | ||
const blockBody = blockParent.get("body"); | ||
const blockBody = blockParent.body; | ||
if (Array.isArray(blockBody) && !blockBody.some(stmt => stmt.isAncestor(refPath))) { | ||
if (Array.isArray(blockBody) && !blockBody.some(stmt => isAncestor(stmt, refPath))) { | ||
return { | ||
@@ -185,3 +186,3 @@ shouldDeopt: true | ||
const stmts = fnParent.isProgram() ? fnParent.get("body") : fnParent.get("body").get("body"); | ||
const stmts = fnParent.isProgram() ? fnParent.node.body : fnParent.node.body.body; | ||
const compareResult = compareBindingAndReference({ | ||
@@ -212,10 +213,11 @@ binding, | ||
let scopePath = declarator.scope.path; | ||
const scopePath = declarator.scope.path; | ||
let scopeNode = scopePath.node; | ||
if (scopePath.isFunction() || scopePath.isCatchClause()) { | ||
scopePath = scopePath.get("body"); | ||
scopeNode = scopeNode.body; | ||
} // Detect Usage before Init | ||
let stmts = scopePath.get("body"); | ||
let stmts = scopeNode.body; | ||
@@ -270,3 +272,3 @@ if (!Array.isArray(stmts)) { | ||
if (stmt.isAncestor(binding.path)) { | ||
if (isAncestor(stmt, binding.path)) { | ||
state.binding = { | ||
@@ -285,3 +287,3 @@ idx | ||
if (ref === refPath && stmt.isAncestor(ref)) { | ||
if (ref === refPath && isAncestor(stmt, ref)) { | ||
state.reference = { | ||
@@ -332,2 +334,10 @@ idx, | ||
}; | ||
} | ||
/** | ||
* is nodeParent an ancestor of path | ||
*/ | ||
function isAncestor(nodeParent, path) { | ||
return !!path.findParent(parent => parent.node === nodeParent); | ||
} |
{ | ||
"name": "babel-helper-evaluate-path", | ||
"version": "0.5.0-alpha.1cb46b73", | ||
"version": "0.5.0-alpha.2ec8ff72", | ||
"description": "path.evaluate wrapped in a try catch", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
9733
271