You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

ast-kit

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ast-kit - npm Package Compare versions

Comparing version
2.2.0
to
3.0.0-beta.1
+11
-326
dist/index.js
import { extname } from "pathe";
import { parse, parseExpression } from "@babel/parser";
import { asyncWalk, walk } from "estree-walker";

@@ -135,3 +136,2 @@ //#region src/check.ts

}
/* v8 ignore next -- @preserve */
/**

@@ -151,2 +151,3 @@ * Checks if the input `node` is a reference to a bound variable.

*/
/* v8 ignore next */
function isReferenced(node, parent, grandparent) {

@@ -409,4 +410,2 @@ switch (parent.type) {

if (!hasPlugin(plugins, "decorators") && !hasPlugin(plugins, "decorators-legacy")) plugins.push("decorators-legacy");
if (!hasPlugin(plugins, "importAttributes") && !hasPlugin(plugins, "importAssertions") && !hasPlugin(plugins, "deprecatedImportAssert")) plugins.push("importAttributes", "deprecatedImportAssert");
if (!hasPlugin(plugins, "explicitResourceManagement")) plugins.push("explicitResourceManagement");
if (REGEX_LANG_JSX.test(lang) && !hasPlugin(plugins, "jsx")) plugins.push("jsx");

@@ -429,3 +428,3 @@ } else if (!hasPlugin(plugins, "jsx")) plugins.push("jsx");

*/
function babelParse(code, lang, { cache,...options } = {}) {
function babelParse(code, lang, { cache, ...options } = {}) {
let result;

@@ -437,3 +436,3 @@ if (cache) result = parseCache.get(code);

}
const { program, type,...rest } = result;
const { program, type, ...rest } = result;
return {

@@ -492,3 +491,2 @@ ...program,

case "StringLiteral": return node.value;
case "DecimalLiteral": return Number(node.value);
}

@@ -565,315 +563,2 @@ }

//#endregion
//#region node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
/**
* @typedef { import('estree').Node} Node
* @typedef {{
* skip: () => void;
* remove: () => void;
* replace: (node: Node) => void;
* }} WalkerContext
*/
var WalkerBase = class {
constructor() {
/** @type {boolean} */
this.should_skip = false;
/** @type {boolean} */
this.should_remove = false;
/** @type {Node | null} */
this.replacement = null;
/** @type {WalkerContext} */
this.context = {
skip: () => this.should_skip = true,
remove: () => this.should_remove = true,
replace: (node) => this.replacement = node
};
}
/**
* @template {Node} Parent
* @param {Parent | null | undefined} parent
* @param {keyof Parent | null | undefined} prop
* @param {number | null | undefined} index
* @param {Node} node
*/
replace(parent, prop, index, node) {
if (parent && prop) if (index != null)
/** @type {Array<Node>} */ parent[prop][index] = node;
else
/** @type {Node} */ parent[prop] = node;
}
/**
* @template {Node} Parent
* @param {Parent | null | undefined} parent
* @param {keyof Parent | null | undefined} prop
* @param {number | null | undefined} index
*/
remove(parent, prop, index) {
if (parent && prop) if (index !== null && index !== void 0)
/** @type {Array<Node>} */ parent[prop].splice(index, 1);
else delete parent[prop];
}
};
//#endregion
//#region node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
/**
* @typedef { import('estree').Node} Node
* @typedef { import('./walker.js').WalkerContext} WalkerContext
* @typedef {(
* this: WalkerContext,
* node: Node,
* parent: Node | null,
* key: string | number | symbol | null | undefined,
* index: number | null | undefined
* ) => void} SyncHandler
*/
var SyncWalker = class extends WalkerBase {
/**
*
* @param {SyncHandler} [enter]
* @param {SyncHandler} [leave]
*/
constructor(enter, leave) {
super();
/** @type {boolean} */
this.should_skip = false;
/** @type {boolean} */
this.should_remove = false;
/** @type {Node | null} */
this.replacement = null;
/** @type {WalkerContext} */
this.context = {
skip: () => this.should_skip = true,
remove: () => this.should_remove = true,
replace: (node) => this.replacement = node
};
/** @type {SyncHandler | undefined} */
this.enter = enter;
/** @type {SyncHandler | undefined} */
this.leave = leave;
}
/**
* @template {Node} Parent
* @param {Node} node
* @param {Parent | null} parent
* @param {keyof Parent} [prop]
* @param {number | null} [index]
* @returns {Node | null}
*/
visit(node, parent, prop, index) {
if (node) {
if (this.enter) {
const _should_skip = this.should_skip;
const _should_remove = this.should_remove;
const _replacement = this.replacement;
this.should_skip = false;
this.should_remove = false;
this.replacement = null;
this.enter.call(this.context, node, parent, prop, index);
if (this.replacement) {
node = this.replacement;
this.replace(parent, prop, index, node);
}
if (this.should_remove) this.remove(parent, prop, index);
const skipped = this.should_skip;
const removed = this.should_remove;
this.should_skip = _should_skip;
this.should_remove = _should_remove;
this.replacement = _replacement;
if (skipped) return node;
if (removed) return null;
}
/** @type {keyof Node} */
let key;
for (key in node) {
/** @type {unknown} */
const value = node[key];
if (value && typeof value === "object") {
if (Array.isArray(value)) {
const nodes = value;
for (let i = 0; i < nodes.length; i += 1) {
const item = nodes[i];
if (isNode$1(item)) {
if (!this.visit(item, node, key, i)) i--;
}
}
} else if (isNode$1(value)) this.visit(value, node, key, null);
}
}
if (this.leave) {
const _replacement = this.replacement;
const _should_remove = this.should_remove;
this.replacement = null;
this.should_remove = false;
this.leave.call(this.context, node, parent, prop, index);
if (this.replacement) {
node = this.replacement;
this.replace(parent, prop, index, node);
}
if (this.should_remove) this.remove(parent, prop, index);
const removed = this.should_remove;
this.replacement = _replacement;
this.should_remove = _should_remove;
if (removed) return null;
}
}
return node;
}
};
/**
* Ducktype a node.
*
* @param {unknown} value
* @returns {value is Node}
*/
function isNode$1(value) {
return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
}
//#endregion
//#region node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/async.js
/**
* @typedef { import('estree').Node} Node
* @typedef { import('./walker.js').WalkerContext} WalkerContext
* @typedef {(
* this: WalkerContext,
* node: Node,
* parent: Node | null,
* key: string | number | symbol | null | undefined,
* index: number | null | undefined
* ) => Promise<void>} AsyncHandler
*/
var AsyncWalker = class extends WalkerBase {
/**
*
* @param {AsyncHandler} [enter]
* @param {AsyncHandler} [leave]
*/
constructor(enter, leave) {
super();
/** @type {boolean} */
this.should_skip = false;
/** @type {boolean} */
this.should_remove = false;
/** @type {Node | null} */
this.replacement = null;
/** @type {WalkerContext} */
this.context = {
skip: () => this.should_skip = true,
remove: () => this.should_remove = true,
replace: (node) => this.replacement = node
};
/** @type {AsyncHandler | undefined} */
this.enter = enter;
/** @type {AsyncHandler | undefined} */
this.leave = leave;
}
/**
* @template {Node} Parent
* @param {Node} node
* @param {Parent | null} parent
* @param {keyof Parent} [prop]
* @param {number | null} [index]
* @returns {Promise<Node | null>}
*/
async visit(node, parent, prop, index) {
if (node) {
if (this.enter) {
const _should_skip = this.should_skip;
const _should_remove = this.should_remove;
const _replacement = this.replacement;
this.should_skip = false;
this.should_remove = false;
this.replacement = null;
await this.enter.call(this.context, node, parent, prop, index);
if (this.replacement) {
node = this.replacement;
this.replace(parent, prop, index, node);
}
if (this.should_remove) this.remove(parent, prop, index);
const skipped = this.should_skip;
const removed = this.should_remove;
this.should_skip = _should_skip;
this.should_remove = _should_remove;
this.replacement = _replacement;
if (skipped) return node;
if (removed) return null;
}
/** @type {keyof Node} */
let key;
for (key in node) {
/** @type {unknown} */
const value = node[key];
if (value && typeof value === "object") {
if (Array.isArray(value)) {
const nodes = value;
for (let i = 0; i < nodes.length; i += 1) {
const item = nodes[i];
if (isNode(item)) {
if (!await this.visit(item, node, key, i)) i--;
}
}
} else if (isNode(value)) await this.visit(value, node, key, null);
}
}
if (this.leave) {
const _replacement = this.replacement;
const _should_remove = this.should_remove;
this.replacement = null;
this.should_remove = false;
await this.leave.call(this.context, node, parent, prop, index);
if (this.replacement) {
node = this.replacement;
this.replace(parent, prop, index, node);
}
if (this.should_remove) this.remove(parent, prop, index);
const removed = this.should_remove;
this.replacement = _replacement;
this.should_remove = _should_remove;
if (removed) return null;
}
}
return node;
}
};
/**
* Ducktype a node.
*
* @param {unknown} value
* @returns {value is Node}
*/
function isNode(value) {
return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
}
//#endregion
//#region node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
/**
* @typedef {import('estree').Node} Node
* @typedef {import('./sync.js').SyncHandler} SyncHandler
* @typedef {import('./async.js').AsyncHandler} AsyncHandler
*/
/**
* @param {Node} ast
* @param {{
* enter?: SyncHandler
* leave?: SyncHandler
* }} walker
* @returns {Node | null}
*/
function walk(ast, { enter, leave }) {
return new SyncWalker(enter, leave).visit(ast, null);
}
/**
* @param {Node} ast
* @param {{
* enter?: AsyncHandler
* leave?: AsyncHandler
* }} walker
* @returns {Promise<Node | null>}
*/
async function asyncWalk(ast, { enter, leave }) {
return await new AsyncWalker(enter, leave).visit(ast, null);
}
//#endregion
//#region src/utils.ts

@@ -986,5 +671,5 @@ const TS_NODE_TYPES = [

else if (!node.specifiers.length && node.declaration) {
/* v8 ignore else -- @preserve */
/* v8 ignore else */
if (node.declaration.type === "VariableDeclaration") for (const decl of node.declaration.declarations) {
/* v8 ignore if -- @preserve */
/* v8 ignore if */
if (decl.id.type !== "Identifier") continue;

@@ -1049,7 +734,7 @@ local = resolveString(decl.id);

else if (isFunctionType(node))
/* v8 ignore if -- @preserve */
/* v8 ignore if */
if (node.scopeIds) node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
else walkFunctionParams(node, (id) => markScopeIdentifier(node, id, knownIds));
else if (node.type === "BlockStatement")
/* v8 ignore if -- @preserve */
/* v8 ignore if */
if (node.scopeIds) node.scopeIds.forEach((id) => markKnownIds(id, knownIds));

@@ -1077,3 +762,3 @@ else walkBlockDeclarations(node, (id) => markScopeIdentifier(node, id, knownIds));

} else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
/* v8 ignore if -- @preserve */
/* v8 ignore if */
if (stmt.declare || !stmt.id) continue;

@@ -1093,3 +778,3 @@ onIdent(stmt.id);

const { name } = child;
/* v8 ignore if -- @preserve */
/* v8 ignore if */
if (node.scopeIds && node.scopeIds.has(name)) return;

@@ -1102,3 +787,3 @@ markKnownIds(name, knownIds);

//#region src/scope.ts
/* v8 ignore file -- @preserve */
/* v8 ignore file */
const extractors = {

@@ -1105,0 +790,0 @@ ArrayPattern(names, param) {

+32
-31
{
"name": "ast-kit",
"version": "2.2.0",
"type": "module",
"version": "3.0.0-beta.1",
"description": "A toolkit for easy Babel AST generation and manipulation.",
"type": "module",
"author": "Kevin Deng <sxzz@sxzz.moe>",
"license": "MIT",
"funding": "https://github.com/sponsors/sxzz",
"homepage": "https://github.com/sxzz/ast-kit#readme",
"bugs": {
"url": "https://github.com/sxzz/ast-kit/issues"
},
"repository": {

@@ -15,10 +14,5 @@ "type": "git",

},
"author": "Kevin Deng <sxzz@sxzz.moe>",
"funding": "https://github.com/sponsors/sxzz",
"files": [
"dist"
],
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"bugs": {
"url": "https://github.com/sxzz/ast-kit/issues"
},
"exports": {

@@ -28,28 +22,35 @@ ".": "./dist/index.js",

},
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=20.19.0"
},
"dependencies": {
"@babel/parser": "^7.28.5",
"@babel/parser": "^8.0.0-beta.4",
"estree-walker": "^3.0.3",
"pathe": "^2.0.3"
},
"devDependencies": {
"@babel/types": "^7.28.5",
"@sxzz/eslint-config": "^7.2.8",
"@sxzz/prettier-config": "^2.2.4",
"@types/node": "^24.10.0",
"@vitest/coverage-v8": "^4.0.8",
"@vitest/ui": "^4.0.8",
"bumpp": "^10.3.1",
"eslint": "^9.39.1",
"estree-walker": "^3.0.3",
"fast-glob": "^3.3.3",
"prettier": "^3.6.2",
"tsdown": "^0.16.1",
"tsx": "^4.20.6",
"@babel/types": "^8.0.0-beta.4",
"@sxzz/eslint-config": "^7.5.0",
"@sxzz/prettier-config": "^2.2.6",
"@types/node": "^25.0.9",
"@typescript/native-preview": "7.0.0-dev.20260119.1",
"@vitest/coverage-v8": "^4.0.17",
"@vitest/ui": "^4.0.17",
"bumpp": "^10.4.0",
"eslint": "^9.39.2",
"prettier": "^3.8.0",
"tsdown": "^0.20.0-beta.3",
"tsdown-preset-sxzz": "^0.3.0",
"typescript": "5.9.3",
"vitest": "^4.0.8"
"vitest": "^4.0.17"
},
"engines": {
"node": ">=20.19.0"
"resolutions": {
"vite": "^8.0.0-beta.7"
},

@@ -63,4 +64,4 @@ "prettier": "@sxzz/prettier-config",

"release": "bumpp",
"typecheck": "tsc --noEmit"
"typecheck": "tsgo --noEmit"
}
}