Socket
Socket
Sign inDemoInstall

ast-walker-scope

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ast-walker-scope - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

4

dist/index.d.ts
import * as _babel_parser from '@babel/parser';
import { ParserPlugin } from '@babel/parser';
import * as _babel_types from '@babel/types';
import { Node, Function, Identifier, Program } from '@babel/types';
import { Node, Function, Identifier } from '@babel/types';

@@ -34,4 +34,4 @@ interface ParseOptions {

declare const walk: (code: string, walkHooks: WalkerHooks, { filename, parserPlugins }?: ParseOptions) => _babel_parser.ParseResult<_babel_types.File>;
declare const walkAST: (ast: Program, { enter, leave }: WalkerHooks) => void;
declare const walkAST: (node: Node, { enter, leave }: WalkerHooks) => void;
export { HookContext, ParseOptions, Scope, WalkerContext, WalkerHooks, extractIdentifiers, isNewScope, walk, walkAST, walkFunctionParams };

@@ -216,13 +216,13 @@ "use strict";

};
var walkAST = (ast, { enter, leave }) => {
var walkAST = (node, { enter, leave }) => {
let currentScope = {};
const scopeStack = [currentScope];
walk(ast, {
enter(node, parent, ...args) {
enterNode(node, parent);
enter == null ? void 0 : enter.call(getHookContext(this, [parent, ...args]), node);
walk(node, {
enter(node2, parent, ...args) {
enterNode(node2, parent);
enter == null ? void 0 : enter.call(getHookContext(this, [parent, ...args]), node2);
},
leave(node, parent, ...args) {
leaveNode(node, parent);
leave == null ? void 0 : leave.call(getHookContext(this, [parent, ...args]), node);
leave(node2, parent, ...args) {
leaveNode(node2, parent);
leave == null ? void 0 : leave.call(getHookContext(this, [parent, ...args]), node2);
}

@@ -242,11 +242,11 @@ });

}
function enterNode(node, parent) {
if (isNewScope(node) || node.type === "BlockStatement" && !isNewScope(parent))
function enterNode(node2, parent) {
if (isNewScope(node2) || node2.type === "BlockStatement" && !isNewScope(parent))
scopeStack.push(currentScope = {});
if ((0, import_types2.isFunction)(node)) {
walkFunctionParams(node, registerBinding);
} else if (node.type === "CatchClause" && node.param && node.param.type === "Identifier")
registerBinding(node.param);
if (node.type === "BlockStatement" || node.type === "Program") {
for (const stmt of node.body) {
if ((0, import_types2.isFunction)(node2)) {
walkFunctionParams(node2, registerBinding);
} else if (node2.type === "CatchClause" && node2.param && node2.param.type === "Identifier")
registerBinding(node2.param);
if (node2.type === "BlockStatement" || node2.type === "Program") {
for (const stmt of node2.body) {
if (stmt.type === "VariableDeclaration" && stmt.kind === "var") {

@@ -260,14 +260,14 @@ walkVariableDeclaration(stmt);

}
function leaveNode(node, _parent) {
if (node.type === "BlockStatement") {
function leaveNode(node2, _parent) {
if (node2.type === "BlockStatement") {
scopeStack.pop();
currentScope = scopeStack[scopeStack.length - 1];
} else if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") {
if (node.declare || !node.id)
} else if (node2.type === "FunctionDeclaration" || node2.type === "ClassDeclaration") {
if (node2.declare || !node2.id)
return;
registerBinding(node.id);
} else if (node.type === "VariableDeclaration") {
walkVariableDeclaration(node);
} else if (node.type === "ExportNamedDeclaration" && node.declaration && node.declaration.type === "VariableDeclaration") {
walkVariableDeclaration(node.declaration);
registerBinding(node2.id);
} else if (node2.type === "VariableDeclaration") {
walkVariableDeclaration(node2);
} else if (node2.type === "ExportNamedDeclaration" && node2.declaration && node2.declaration.type === "VariableDeclaration") {
walkVariableDeclaration(node2.declaration);
}

@@ -294,5 +294,5 @@ }

}
function error(msg, node) {
function error(msg, node2) {
const e = new Error(msg);
e.node = node;
e.node = node2;
throw e;

@@ -299,0 +299,0 @@ }

{
"name": "ast-walker-scope",
"version": "0.2.1",
"version": "0.2.2",
"packageManager": "pnpm@7.6.0",

@@ -21,12 +21,12 @@ "description": "Traverse Babel AST with scope information.",

"dependencies": {
"@babel/parser": "^7.18.9",
"@babel/types": "^7.18.9"
"@babel/parser": "^7.18.13",
"@babel/types": "^7.18.13"
},
"devDependencies": {
"@sxzz/eslint-config-prettier": "^2.3.5",
"@sxzz/eslint-config-ts": "^2.3.5",
"@sxzz/eslint-config-prettier": "^2.4.1",
"@sxzz/eslint-config-ts": "^2.4.1",
"@types/node": "*",
"bumpp": "^8.2.1",
"eslint": "^8.20.0",
"eslint-define-config": "^1.5.1",
"eslint": "^8.22.0",
"eslint-define-config": "^1.6.0",
"estree-walker": "^3.0.1",

@@ -36,7 +36,7 @@ "fast-glob": "^3.2.11",

"prettier": "^2.7.1",
"tsup": "^6.2.0",
"tsx": "^3.8.0",
"typescript": "^4.7.4",
"vite": "^3.0.4",
"vitest": "^0.19.1"
"tsup": "^6.2.3",
"tsx": "^3.8.2",
"typescript": "^4.8.2",
"vite": "^3.0.9",
"vitest": "^0.22.1"
},

@@ -43,0 +43,0 @@ "engines": {

Sorry, the diff of this file is not supported yet

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