{"id":18966,"library":"ast-kit","title":"ast-kit","description":"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).","status":"active","version":"2.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/sxzz/ast-kit","tags":["javascript","typescript"],"install":[{"cmd":"npm install ast-kit","lang":"bash","label":"npm"},{"cmd":"yarn add ast-kit","lang":"bash","label":"yarn"},{"cmd":"pnpm add ast-kit","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for AST node types and manipulation; deep dependency of ast-kit.","package":"@babel/types","optional":false},{"reason":"Used in babelParse and babelParseFile for parsing code into AST.","package":"@babel/parser","optional":false}],"imports":[{"note":"Package is ESM-only since v2.0.0; require() will fail.","wrong":"const { babelParse } = require('ast-kit')","symbol":"babelParse","correct":"import { babelParse } from 'ast-kit'"},{"note":"Named export, not default.","wrong":"import babelParseFile from 'ast-kit'","symbol":"babelParseFile","correct":"import { babelParseFile } from 'ast-kit'"},{"note":"Function is named walkAST, not walk.","wrong":"import { walk } from 'ast-kit'","symbol":"walkAST","correct":"import { walkAST } from 'ast-kit'"}],"quickstart":{"code":"import { babelParse, babelParseFile, walkAST, walkIdentifiers, generate } from 'ast-kit'\n\n// Parse a code string\nconst ast = babelParse('const x = 1 + 2', { sourceType: 'module' })\nconsole.log(ast.program.body[0].type) // 'VariableDeclaration'\n\n// Parse a file\nconst fileAst = await babelParseFile('./example.js')\n\n// Walk the AST\nwalkAST(ast, {\n  enter(node) {\n    console.log('Entering:', node.type)\n  },\n  leave(node) {\n    console.log('Leaving:', node.type)\n  }\n})\n\n// Walk only identifiers\nwalkIdentifiers(ast, (id) => {\n  console.log('Found identifier:', id.name)\n})\n\n// Generate code from AST (requires @babel/generator)\nimport generateCode from '@babel/generator'\nconst output = generateCode(ast).code\nconsole.log(output) // 'const x = 1 + 2;'","lang":"typescript","description":"Demonstrates parsing, file reading, AST walking, identifier extraction, and code generation."},"warnings":[{"fix":"Use Node.js >=20.19.0 and switch to ESM imports (import syntax, not require).","message":"Dropped support for Node.js 16 and 18, and removed CJS build in v2.0.0.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"If using v3 beta, migrate to @babel/types v8 and adjust for new AST node shapes.","message":"The v3.0.0 beta upgrades Babel to v8, which may introduce breaking changes in AST types and parser options.","severity":"deprecated","affected_versions":">=3.0.0-beta.1"},{"fix":"Upgrade to >=2.1.1 to correctly handle these cases.","message":"walkIdentifiers may not infer identifiers in function parameters or JSXNamespacedName as references (fixed in v2.1.1).","severity":"gotcha","affected_versions":"<2.1.1"},{"fix":"Use named imports like import { babelParse } from 'ast-kit'.","message":"The package does not expose a default export; all utilities are named exports.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use import { ... } from 'ast-kit' or dynamic import() instead of require().","cause":"Package is ESM-only since v2.0.0; calling require() is invalid.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/ast-kit/index.mjs not supported."},{"fix":"Use import { babelParse } from 'ast-kit'.","cause":"Using default import (import babelParse from 'ast-kit') instead of named import.","error":"TypeError: babelParse is not a function"},{"fix":"Set { type: 'module' } in package.json and use import syntax, or upgrade Node to >=20.19.0.","cause":"Using CommonJS (require) with ESM-only package without transpilation.","error":"SyntaxError: Unexpected token 'export'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}