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.1.0 to 0.2.0

4

dist/index.d.ts

@@ -29,7 +29,5 @@ import * as _babel_parser from '@babel/parser';

declare const walk: (code: string, walkHooks: WalkerHooks, { filename, parserPlugins }?: ParseOptions) => {
ast: _babel_parser.ParseResult<_babel_types.File>;
};
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;
export { HookContext, ParseOptions, Scope, WalkerContext, WalkerHooks, walk, walkAST };

@@ -141,6 +141,13 @@ "use strict";

// src/index.ts
var import_types2 = require("@babel/types");
// src/utils/babel.ts
var isFunctionType = (node) => {
return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
};
var import_types = require("@babel/types");
var NEW_SCOPE = [
"CatchClause",
"ForInStatement",
"ForOfStatement"
];
var isNewScope = (node) => NEW_SCOPE.includes(node.type) || (0, import_types.isFunction)(node);
function walkFunctionParams(node, onIdent) {

@@ -192,7 +199,2 @@ for (const p of node.params) {

// src/index.ts
var ADVANCED_SCOPE = [
"CatchClause",
"ForInStatement",
"ForOfStatement"
];
var walk2 = (code, walkHooks, { filename, parserPlugins } = {}) => {

@@ -211,3 +213,3 @@ const plugins = parserPlugins || [];

walkAST(ast.program, walkHooks);
return { ast };
return ast;
};

@@ -240,14 +242,16 @@ var walkAST = (ast, { enter, leave }) => {

function enterNode(node, parent) {
if (isFunctionType(node)) {
if (isNewScope(node) || node.type === "BlockStatement" && !isNewScope(parent))
scopeStack.push(currentScope = {});
if ((0, import_types2.isFunction)(node)) {
walkFunctionParams(node, registerBinding);
} else if (node.type === "CatchClause") {
scopeStack.push(currentScope = {});
if (node.param && node.param.type === "Identifier")
registerBinding(node.param);
return;
} else if (node.type === "ForOfStatement" || node.type === "ForInStatement") {
scopeStack.push(currentScope = {});
} else if (node.type === "BlockStatement" && !isFunctionType(parent) && !ADVANCED_SCOPE.includes(parent.type)) {
scopeStack.push(currentScope = {});
} 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 (stmt.type === "VariableDeclaration" && stmt.kind === "var") {
walkVariableDeclaration(stmt);
} else if (stmt.type === "FunctionDeclaration" && stmt.id) {
registerBinding(stmt.id);
}
}
}

@@ -254,0 +258,0 @@ }

{
"name": "ast-walker-scope",
"version": "0.1.0",
"version": "0.2.0",
"packageManager": "pnpm@7.6.0",

@@ -5,0 +5,0 @@ "description": "Traverse Babel AST with scope information.",

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