babel-helper-evaluate-path
Advanced tools
Comparing version 0.5.0-alpha.5f601890 to 0.5.0-alpha.6889f45d
@@ -14,3 +14,3 @@ "use strict"; | ||
} = {}) { | ||
if (!tdz) { | ||
if (!tdz && !path.isReferencedIdentifier()) { | ||
return baseEvaluate(path); | ||
@@ -77,3 +77,30 @@ } | ||
if (!binding) { | ||
return deopt(path); | ||
const name = node.name; | ||
if (!name) { | ||
return deopt(path); | ||
} | ||
switch (name) { | ||
case "undefined": | ||
return { | ||
confident: true, | ||
value: undefined | ||
}; | ||
case "NaN": | ||
return { | ||
confident: true, | ||
value: NaN | ||
}; | ||
case "Infinity": | ||
return { | ||
confident: true, | ||
value: Infinity | ||
}; | ||
default: | ||
return deopt(path); | ||
} | ||
} | ||
@@ -121,3 +148,15 @@ | ||
const declaration = binding.path.parentPath; | ||
/** | ||
* Handle when binding is created inside a parent block and | ||
* the corresponding parent is removed by other plugins | ||
* if (false) { var a } -> var a | ||
*/ | ||
if (declaration.parentPath && declaration.parentPath.removed) { | ||
return { | ||
confident: true, | ||
value: void 0 | ||
}; | ||
} | ||
if (declaration.parentPath.isIfStatement() || declaration.parentPath.isLoop() || declaration.parentPath.isSwitchCase()) { | ||
@@ -129,11 +168,13 @@ return { | ||
const fnParent = (binding.path.scope.getFunctionParent() || binding.path.scope.getProgramParent()).path; | ||
let blockParent = binding.path.scope.getBlockParent().path; | ||
const fnParent = binding.path.getFunctionParent(); | ||
if (blockParent === fnParent) { | ||
if (!fnParent.isProgram()) blockParent = blockParent.get("body"); | ||
if (blockParent === fnParent && !fnParent.isProgram()) { | ||
blockParent = blockParent.get("body"); | ||
} // detect Usage Outside Init Scope | ||
if (!blockParent.get("body").some(stmt => stmt.isAncestor(refPath))) { | ||
const blockBody = blockParent.get("body"); | ||
if (Array.isArray(blockBody) && !blockBody.some(stmt => stmt.isAncestor(refPath))) { | ||
return { | ||
@@ -159,6 +200,2 @@ shouldDeopt: true | ||
} | ||
return { | ||
shouldDeopt: true | ||
}; | ||
} | ||
@@ -170,3 +207,3 @@ } else if (binding.kind === "let" || binding.kind === "const") { | ||
if (declaration.parentPath.isIfStatement() || declaration.parentPath.isLoop() || declaration.parentPath.isSwitchCase()) { | ||
if (declaration.parentPath && (declaration.parentPath.isIfStatement() || declaration.parentPath.isLoop() || declaration.parentPath.isSwitchCase())) { | ||
return { | ||
@@ -184,3 +221,8 @@ shouldDeopt: true | ||
const stmts = scopePath.get("body"); | ||
let stmts = scopePath.get("body"); | ||
if (!Array.isArray(stmts)) { | ||
stmts = [stmts]; | ||
} | ||
const compareResult = compareBindingAndReference({ | ||
@@ -187,0 +229,0 @@ binding, |
{ | ||
"name": "babel-helper-evaluate-path", | ||
"version": "0.5.0-alpha.5f601890", | ||
"version": "0.5.0-alpha.6889f45d", | ||
"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
9478
261