babel-helper-evaluate-path
Advanced tools
Comparing version 0.3.0-alpha.7f4dc3d4 to 0.3.0-alpha.879f25ec
@@ -5,7 +5,3 @@ "use strict"; | ||
module.exports = function evaluate(path) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$tdz = _ref.tdz, | ||
tdz = _ref$tdz === undefined ? false : _ref$tdz; | ||
module.exports = function evaluate(path, { tdz = false } = {}) { | ||
if (!tdz) { | ||
@@ -19,3 +15,3 @@ return baseEvaluate(path); | ||
var state = { | ||
const state = { | ||
confident: true | ||
@@ -30,3 +26,3 @@ }; | ||
ReferencedIdentifier(idPath) { | ||
var binding = idPath.scope.getBinding(idPath.node.name); | ||
const binding = idPath.scope.getBinding(idPath.node.name); | ||
// don't deopt globals | ||
@@ -36,3 +32,3 @@ // let babel take care of it | ||
var evalResult = evaluateIdentifier(idPath); | ||
const evalResult = evaluateIdentifier(idPath); | ||
if (!evalResult.confident) { | ||
@@ -71,6 +67,6 @@ state.confident = evalResult.confident; | ||
var node = path.node; | ||
const node = path.node; | ||
var binding = path.scope.getBinding(node.name); | ||
const binding = path.scope.getBinding(node.name); | ||
@@ -92,3 +88,3 @@ if (!binding) { | ||
// or "var" referenced in an outer scope | ||
var flowEvalResult = evaluateBasedOnControlFlow(binding, path); | ||
const flowEvalResult = evaluateBasedOnControlFlow(binding, path); | ||
@@ -120,3 +116,3 @@ if (flowEvalResult.confident) { | ||
// early-exit | ||
var declaration = binding.path.parentPath; | ||
const declaration = binding.path.parentPath; | ||
if (declaration.parentPath.isIfStatement() || declaration.parentPath.isLoop() || declaration.parentPath.isSwitchCase()) { | ||
@@ -126,4 +122,4 @@ return { shouldDeopt: true }; | ||
var blockParent = binding.path.scope.getBlockParent().path; | ||
var fnParent = binding.path.getFunctionParent(); | ||
let blockParent = binding.path.scope.getBlockParent().path; | ||
const fnParent = binding.path.getFunctionParent(); | ||
@@ -135,5 +131,3 @@ if (blockParent === fnParent) { | ||
// detect Usage Outside Init Scope | ||
if (!blockParent.get("body").some(function (stmt) { | ||
return stmt.isAncestor(refPath); | ||
})) { | ||
if (!blockParent.get("body").some(stmt => stmt.isAncestor(refPath))) { | ||
return { shouldDeopt: true }; | ||
@@ -143,5 +137,5 @@ } | ||
// Detect usage before init | ||
var stmts = fnParent.isProgram() ? fnParent.get("body") : fnParent.get("body").get("body"); | ||
const stmts = fnParent.isProgram() ? fnParent.get("body") : fnParent.get("body").get("body"); | ||
var compareResult = compareBindingAndReference({ | ||
const compareResult = compareBindingAndReference({ | ||
binding, | ||
@@ -161,10 +155,10 @@ refPath, | ||
// binding.path is the declarator | ||
var declarator = binding.path; | ||
var _declaration = declarator.parentPath; | ||
const declarator = binding.path; | ||
const declaration = declarator.parentPath; | ||
if (_declaration.parentPath.isIfStatement() || _declaration.parentPath.isLoop() || _declaration.parentPath.isSwitchCase()) { | ||
if (declaration.parentPath.isIfStatement() || declaration.parentPath.isLoop() || declaration.parentPath.isSwitchCase()) { | ||
return { shouldDeopt: true }; | ||
} | ||
var scopePath = declarator.scope.path; | ||
let scopePath = declarator.scope.path; | ||
if (scopePath.isFunction() || scopePath.isCatchClause()) { | ||
@@ -175,15 +169,15 @@ scopePath = scopePath.get("body"); | ||
// Detect Usage before Init | ||
var _stmts = scopePath.get("body"); | ||
const stmts = scopePath.get("body"); | ||
var _compareResult = compareBindingAndReference({ | ||
const compareResult = compareBindingAndReference({ | ||
binding, | ||
refPath, | ||
stmts: _stmts | ||
stmts | ||
}); | ||
if (_compareResult.reference && _compareResult.binding) { | ||
if (_compareResult.reference.scope === "current" && _compareResult.reference.idx < _compareResult.binding.idx) { | ||
if (compareResult.reference && compareResult.binding) { | ||
if (compareResult.reference.scope === "current" && compareResult.reference.idx < compareResult.binding.idx) { | ||
throw new Error(`ReferenceError: Used ${refPath.node.name}: ` + `${binding.kind} binding before declaration`); | ||
} | ||
if (_compareResult.reference.scope === "other") { | ||
if (compareResult.reference.scope === "other") { | ||
return { shouldDeopt: true }; | ||
@@ -197,8 +191,4 @@ } | ||
function compareBindingAndReference(_ref2) { | ||
var binding = _ref2.binding, | ||
refPath = _ref2.refPath, | ||
stmts = _ref2.stmts; | ||
var state = { | ||
function compareBindingAndReference({ binding, refPath, stmts }) { | ||
const state = { | ||
binding: null, | ||
@@ -214,8 +204,8 @@ reference: null | ||
for (var _iterator = stmts.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _ref3 = _step.value; | ||
const _ref = _step.value; | ||
var _ref4 = _slicedToArray(_ref3, 2); | ||
var _ref2 = _slicedToArray(_ref, 2); | ||
var idx = _ref4[0]; | ||
var stmt = _ref4[1]; | ||
const idx = _ref2[0]; | ||
const stmt = _ref2[1]; | ||
@@ -231,3 +221,3 @@ if (stmt.isAncestor(binding.path)) { | ||
for (var _iterator2 = binding.referencePaths[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var ref = _step2.value; | ||
const ref = _step2.value; | ||
@@ -234,0 +224,0 @@ if (ref === refPath && stmt.isAncestor(ref)) { |
{ | ||
"name": "babel-helper-evaluate-path", | ||
"version": "0.3.0-alpha.7f4dc3d4", | ||
"version": "0.3.0-alpha.879f25ec", | ||
"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
8346
211