recast

JavaScript AST transformer and nondestructive pretty-printer for building codemods

Library
npm
v0.24.0
5,255stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
81/100Excellent
Development Activity88
Maintenance72
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture85
Code Quality78
Innovation80
Learning Curve65

Recast parses JavaScript (and TypeScript, via configurable parsers) into an abstract syntax tree using the ast-types library, lets calling code freely mutate that tree, and then reprints it back to source — preserving the original formatting, comments, and whitespace of any part of the tree left untouched. This nondestructive reprinting is what distinguishes it from a plain parse-then-generate pipeline: hand-written code stays byte-identical except where it was actually changed.

Because of this property, recast is the parsing/printing engine underneath widely used codemod tools like jscodeshift and is used directly by Babel plugins, linters, and other JavaScript tooling that needs to programmatically rewrite source files without reformatting the rest of the file.

What You Get

  • parse/print functions for round-tripping JavaScript/TypeScript source through an editable AST
  • Nondestructive pretty-printing that preserves untouched code’s original formatting and comments
  • Pluggable parser support (Babel, esprima, acorn, TypeScript, Flow) via the parser option
  • Automatic source map generation for transformed output
  • Deep integration with ast-types for node construction, traversal, and type-checked builders

Common Use Cases

  • Writing codemods that rewrite a codebase’s API usage while preserving unrelated formatting
  • Building custom lint-fix or refactoring tools that programmatically edit source files
  • Powering higher-level codemod frameworks such as jscodeshift
  • Generating or patching configuration/boilerplate files while respecting hand-written surrounding code

Under The Hood

Architecture recast’s core (lib/parser.ts, lib/printer.ts, lib/patcher.ts) parses source into an ast-types tree annotated with original token/location info, then on print() walks the tree (lib/fast-path.ts for efficient traversal) comparing each node against its original source slice; unchanged subtrees are copied verbatim from the original text via lib/lines.ts and lib/patcher.ts, while changed subtrees are regenerated by the pretty-printer and spliced back in. lib/comments.ts handles reattaching comments to the correct nodes after mutation.

Tech Stack Written in TypeScript, built with tsc, and built on top of the author’s own ast-types package for AST node definitions and traversal; supports pluggable parsers (Babel parser by default, with esprima/acorn/TypeScript/Flow parser adapters available).

Code Quality Uses a Mocha-based test suite (test/run.sh) combined with ESLint and Prettier enforced via npm test, and has 109 contributors with a long, incremental commit history dating back over a decade — though maintenance has slowed to infrequent updates in recent years relative to its enormous download volume (31M+ weekly).

API Design The two-function parse/print surface is minimal and well documented via the README’s worked examples, and its tight coupling to ast-types gives typed node builders instead of hand-built plain objects — but effective use requires understanding ast-types’ node shape conventions, which adds a real learning curve beyond the basic parse/print calls.

Used by 7 apps in this directory

TypeScript
96%
Other

Amplication

Developer Tools · AI Code Assistants · Automation

16,011

Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.

View details
60
Repo Health
84
Technical
60
Dependency
Built with
TypeScript96%
Updated 2 months ago
TypeScript
96%
Other

Dyad

AI Development · Productivity · AI Code Assistants

21,390

Build AI-powered apps locally with your own keys, your own models, and zero cloud lock-in.

View details
88
Repo Health
83
Technical
69
Dependency
Built with
TypeScript96%
Updated yesterday
TypeScript
82%
MIT

evidence

Analytics · Data Engineering

6,911

Turn SQL queries and markdown files into polished, interactive data apps and business intelligence reports — no drag-and-drop, no GUI, just code.

View details
87
Repo Health
79
Technical
64
Dependency
Built with
TypeScript82%
Svelte18%
Updated 3 days ago
JavaScript
69%
AGPL 3.0

Fleetbase

Logistics

2,552

Modular open-source logistics and supply chain operating system

View details
91
Repo Health
75
Technical
67
Dependency
Built with
JavaScript69%
PHP12%
Updated yesterday
TypeScript
90%
Apache 2.0

HyperFrames

AI Development · AI Design Tools

44,430

Turn plain HTML and CSS into deterministic, pixel-perfect MP4 videos — authored by humans or AI agents, rendered by headless Chrome and FFmpeg.

View details
82
Repo Health
83
Technical
65
Dependency
Built with
TypeScript90%
Updated today
TypeScript
98%
Other

Kibana

Analytics · Monitoring

21,284

Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.

View details
98
Repo Health
87
Technical
66
Dependency
Built with
TypeScript98%
Updated yesterday
TypeScript
92%
Other

n8n

Automation · No Code Platforms

203,555

Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.

View details
95
Repo Health
87
Technical
66
Dependency
Built with
TypeScript92%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search