Registry / serialization / ast-kit

ast-kit

JSON →
library2.2.0jsnpmunverified

A TypeScript-first toolkit for easy Babel AST generation and manipulation, currently at version 2.2.0 (stable). Provides utilities like babelParse, babelParseFile, walkAST, walkIdentifiers, and AST generation helpers. Released under active development with frequent updates and a v3 beta upgrading to Babel 8. Key differentiators: tree-shakable, full TypeScript support, 100% test coverage, lightweight with only two runtime dependencies. Requires Node.js >=20.19.0 since v2.0.0 (which dropped CJS and older Node versions).

npm install ast-kit
INSTALL
IMPORT
SIG · AST-KIT
A
ast-kit
serializationjavascriptv2.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

babelParse
import { babelParse } from 'ast-kit'
const { babelParse } = require('ast-kit')
Package is ESM-only since v2.0.0; require() will fail.
babelParseFile
import { babelParseFile } from 'ast-kit'
import babelParseFile from 'ast-kit'
Named export, not default.
walkAST
import { walkAST } from 'ast-kit'
import { walk } from 'ast-kit'
Function is named walkAST, not walk.

Demonstrates parsing, file reading, AST walking, identifier extraction, and code generation.

import { babelParse, babelParseFile, walkAST, walkIdentifiers, generate } from 'ast-kit' // Parse a code string const ast = babelParse('const x = 1 + 2', { sourceType: 'module' }) console.log(ast.program.body[0].type) // 'VariableDeclaration' // Parse a file const fileAst = await babelParseFile('./example.js') // Walk the AST walkAST(ast, { enter(node) { console.log('Entering:', node.type) }, leave(node) { console.log('Leaving:', node.type) } }) // Walk only identifiers walkIdentifiers(ast, (id) => { console.log('Found identifier:', id.name) }) // Generate code from AST (requires @babel/generator) import generateCode from '@babel/generator' const output = generateCode(ast).code console.log(output) // 'const x = 1 + 2;'
Debug
Known issues
breakingDropped support for Node.js 16 and 18, and removed CJS build in v2.0.0.
fix
Use Node.js >=20.19.0 and switch to ESM imports (import syntax, not require).
affects: >=2.0.0
deprecatedThe v3.0.0 beta upgrades Babel to v8, which may introduce breaking changes in AST types and parser options.
fix
If using v3 beta, migrate to @babel/types v8 and adjust for new AST node shapes.
affects: >=3.0.0-beta.1
gotchawalkIdentifiers may not infer identifiers in function parameters or JSXNamespacedName as references (fixed in v2.1.1).
fix
Upgrade to >=2.1.1 to correctly handle these cases.
affects: <2.1.1
gotchaThe package does not expose a default export; all utilities are named exports.
fix
Use named imports like import { babelParse } from 'ast-kit'.
affects: >=1.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/ast-kit/index.mjs not supported.
Package is ESM-only since v2.0.0; calling require() is invalid.
fix
Use import { ... } from 'ast-kit' or dynamic import() instead of require().
TypeError: babelParse is not a function
Using default import (import babelParse from 'ast-kit') instead of named import.
fix
Use import { babelParse } from 'ast-kit'.
SyntaxError: Unexpected token 'export'
Using CommonJS (require) with ESM-only package without transpilation.
fix
Set { type: 'module' } in package.json and use import syntax, or upgrade Node to >=20.19.0.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
@babel/typesrequiredUsed for AST node types and manipulation; deep dependency of ast-kit.
@babel/parserrequiredUsed in babelParse and babelParseFile for parsing code into AST.
Agent activity
20 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
ast-kit — npm install ast-kit · libregistry