Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-helper-evaluate-path

Package Overview
Dependencies
Maintainers
7
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-helper-evaluate-path - npm Package Compare versions

Comparing version 0.3.0-alpha.5ee3078e to 0.3.0-alpha.636ae276

70

lib/index.js

@@ -5,3 +5,7 @@ "use strict";

module.exports = function evaluate(path, { tdz = false } = {}) {
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;
if (!tdz) {

@@ -15,3 +19,3 @@ return baseEvaluate(path);

const state = {
var state = {
confident: true

@@ -26,3 +30,3 @@ };

ReferencedIdentifier(idPath) {
const binding = idPath.scope.getBinding(idPath.node.name);
var binding = idPath.scope.getBinding(idPath.node.name);
// don't deopt globals

@@ -32,3 +36,3 @@ // let babel take care of it

const evalResult = evaluateIdentifier(idPath);
var evalResult = evaluateIdentifier(idPath);
if (!evalResult.confident) {

@@ -67,6 +71,6 @@ state.confident = evalResult.confident;

const node = path.node;
var node = path.node;
const binding = path.scope.getBinding(node.name);
var binding = path.scope.getBinding(node.name);

@@ -88,3 +92,3 @@ if (!binding) {

// or "var" referenced in an outer scope
const flowEvalResult = evaluateBasedOnControlFlow(binding, path);
var flowEvalResult = evaluateBasedOnControlFlow(binding, path);

@@ -116,3 +120,3 @@ if (flowEvalResult.confident) {

// early-exit
const declaration = binding.path.parentPath;
var declaration = binding.path.parentPath;
if (declaration.parentPath.isIfStatement() || declaration.parentPath.isLoop() || declaration.parentPath.isSwitchCase()) {

@@ -122,4 +126,4 @@ return { shouldDeopt: true };

let blockParent = binding.path.scope.getBlockParent().path;
const fnParent = binding.path.getFunctionParent();
var blockParent = binding.path.scope.getBlockParent().path;
var fnParent = binding.path.getFunctionParent();

@@ -131,3 +135,5 @@ if (blockParent === fnParent) {

// detect Usage Outside Init Scope
if (!blockParent.get("body").some(stmt => stmt.isAncestor(refPath))) {
if (!blockParent.get("body").some(function (stmt) {
return stmt.isAncestor(refPath);
})) {
return { shouldDeopt: true };

@@ -137,5 +143,5 @@ }

// Detect usage before init
const stmts = fnParent.isProgram() ? fnParent.get("body") : fnParent.get("body").get("body");
var stmts = fnParent.isProgram() ? fnParent.get("body") : fnParent.get("body").get("body");
const compareResult = compareBindingAndReference({
var compareResult = compareBindingAndReference({
binding,

@@ -155,10 +161,10 @@ refPath,

// binding.path is the declarator
const declarator = binding.path;
const declaration = declarator.parentPath;
var declarator = binding.path;
var _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 };
}
let scopePath = declarator.scope.path;
var scopePath = declarator.scope.path;
if (scopePath.isFunction() || scopePath.isCatchClause()) {

@@ -169,15 +175,15 @@ scopePath = scopePath.get("body");

// Detect Usage before Init
const stmts = scopePath.get("body");
var _stmts = scopePath.get("body");
const compareResult = compareBindingAndReference({
var _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 };

@@ -191,4 +197,8 @@ }

function compareBindingAndReference({ binding, refPath, stmts }) {
const state = {
function compareBindingAndReference(_ref2) {
var binding = _ref2.binding,
refPath = _ref2.refPath,
stmts = _ref2.stmts;
var state = {
binding: null,

@@ -204,8 +214,8 @@ reference: null

for (var _iterator = stmts.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
const _ref = _step.value;
var _ref3 = _step.value;
var _ref2 = _slicedToArray(_ref, 2);
var _ref4 = _slicedToArray(_ref3, 2);
const idx = _ref2[0];
const stmt = _ref2[1];
var idx = _ref4[0];
var stmt = _ref4[1];

@@ -221,3 +231,3 @@ if (stmt.isAncestor(binding.path)) {

for (var _iterator2 = binding.referencePaths[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
const ref = _step2.value;
var ref = _step2.value;

@@ -224,0 +234,0 @@ if (ref === refPath && stmt.isAncestor(ref)) {

{
"name": "babel-helper-evaluate-path",
"version": "0.3.0-alpha.5ee3078e",
"version": "0.3.0-alpha.636ae276",
"description": "path.evaluate wrapped in a try catch",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc