recast

JavaScript AST transformer and nondestructive pretty-printer for building codemods

Library
npm
v0.24.0
5,253 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
79 /100 Good
Development Activity 80
Maintenance 72
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
77 /100 Good
Architecture 85
Code Quality 78
Innovation 80
Learning Curve 65

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

AI Code Assistants · Automation · Developer Tools

16,015

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
58
Repo Health
84
Technical
60
Dependency
Built with
TypeScript 96%
Updated 3 months ago
TypeScript
96%
Other

Dyad

AI Assistants · AI Code Assistants · AI Development

21,616

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
TypeScript 96%
Updated 6 days ago
TypeScript
82%
MIT

evidence

Analytics · Data Engineering

6,962

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
90
Repo Health
79
Technical
64
Dependency
Built with
TypeScript 82%
Svelte 17%
Updated 1 weeks ago
JavaScript
69%
AGPL 3.0

Fleetbase

Logistics

3,940

Modular open-source logistics and supply chain operating system

View details
93
Repo Health
75
Technical
68
Dependency
Built with
JavaScript 69%
PHP 11%
Updated 5 days ago
TypeScript
87%
Apache 2.0

HyperFrames

AI Design Tools · AI Development

53,695

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
84
Repo Health
83
Technical
65
Dependency
Built with
TypeScript 87%
JavaScript 12%
Updated 5 days ago
TypeScript
98%
Other

Kibana

Analytics · Monitoring

21,301

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
63
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
92%
Other

n8n

Automation · No Code Platforms

206,147

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
65
Dependency
Built with
TypeScript 92%
Updated 5 days ago

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