HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
benjamn
recast
TypeScript2016–2024
benjamn / recast

recast

JavaScript syntax tree transformer, nondestructive pretty-printer, and automatic source map generator

8Distinct people
8Mentions
0Explicit recommenders
5.3KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

JavaScript syntax tree transformer, nondestructive pretty-printer, and automatic source map generator

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 3:56:07 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year8 dated mentions

Observed mentions: 2016-02-04 15:48:41 UTC to 2024-06-16 03:18:44 UTC.

0122016-01-01 00:00:00 UTC to 2017-01-01 00:00:00 UTC (exclusive): 2 mentions; 1 submissions, 1 comments20162017-01-01 00:00:00 UTC to 2018-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2018-01-01 00:00:00 UTC to 2019-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments20202021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2024

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20162016-01-01 00:00:00 UTC2017-01-01 00:00:00 UTC211
20172017-01-01 00:00:00 UTC2018-01-01 00:00:00 UTC202
20182018-01-01 00:00:00 UTC2019-01-01 00:00:00 UTC101
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC101
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC000
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC000
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC101
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC000
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC101

What Hacker News says

8 sources
A sufficiently-motivated engineer could do this today by setting a different formatter in their editor than in their pre-commit hook. Then they need only activate the formatter in their editor as they edit, and ensure pre-commit hooks run as they commit. This saves you the trouble of authoring a separate programming language, or finding a way to preserve all of the niceties of the original syntax and formatting that wouldn't directly translate to an AST (like how many newlines are after a particular stanza or function). Case in point: Recast (https://github.com/benjamn/recast) is of particular interest with regards to JS/TS in this vein, because it does preserve a lot of the spirit of the source in its conception of the AST. But also last time I used it (couple years ago now) it would explode on any code with an emoji in it. It's genuinel
Read the rest
y not an easy problem.
In Reformatting 100k Files at Google in 2011
This is a powerful idea! If I understand Monocle's use case, JS has similar AST parsing and code generation tools that are used broadly. There may be some ideas to learn from that community. JS AST specs: estree [0] and babel's AST [1] Parsers: babel [2], acorn [3], or espree [4] Transformers: babel, recast [5], or jscodeshift [6] Codegen: babel or escodegen [7] [0] https://github.com/estree/estree [1] https://babeljs.io/docs/en/babel-parser#output [2] https://github.com/babel/babel [3] https://github.com/acornjs/acorn [4] https://github.com/eslint/espree [5] https://github.com/benjamn/recast [6] https://github.com/facebook/jscodeshift [7] https://github.com/estools/escodegen
In Show HN: Monocle – bidirectional code generation library
Personally I've moved away from the TypeScript compiler and towards the betas of `babel@7` and `@babel/preset-typescript` (https://www.npmjs.com/package/@babel/preset-typescript). It seems to be faster and there is better integration with `jest`, `rollup`, various css-in-js libraries and (maybe in future?) `create-react-app`. (I still run `tslint` and `typescript` in the background for type-checking and linting. And I've written a tiny CLI to generate flat `index.d.ts` files to share my packages.) The one thing I still miss about JavaScript is the possibility of writing codemods to speed-up upgrades. Unfortunately, in order for `jscodeshift` to support TypeScript, I think there would need to be some further work on `recast` (https://github.com/benjamn/recast/issues/424). Hopefully the TypeScript team will continue to work closely with the
Read the rest
Babel team, since this would be very good for the eco-system.
In Announcing TypeScript 2.7
I'm surprised that doesn't exist. When I did a lot of Perl in a team environment, we used perltidy. Helpful since Perl does little to encourage uniformity. It could take any sort of style in, and produce any sort of style out. Things like K&R blocks vs Allman-style blocks, tabs vs spaces, line wrapping, cuddled/not-cuddled else, etc. http://perltidy.sourceforge.net/stylekey.html Edit: this looks pretty close to the same thing for JavaScript. Missing some style options, and not command line driven, but the general idea seems close: https://github.com/benjamn/recast/blob/master/README.md
In Prettier 1.0
For JavaScript we have https://github.com/estree/estree as our JS AST spec for parsers like esprima, acorn, babylon (under a config flag), etc. JSCS (https://github.com/jscs-dev/node-jscs) (now merged with ESLint) started a CST project as well https://github.com/cst/cst to help deal with autoformatting by adding whitespace type nodes. Currently the community has a lot of interest in https://github.com/jlongster/prettier which just simply reprints the file from scratch in a consistent way (posted in https://news.ycombinator.com/item?id=13365470). We also have https://github.com/benjamn/recast to help source to source transformations and https://github.com/facebook/jscodeshift.
In From AST to Lossless Syntax Tree
jscodeshift is primarily a wrapper around recast. Recast takes care of all the printing. It's smart enough to reuse the original source code for AST nodes that haven't been changed. As for formatting, there are some options to influence the pretty printer, but not a lot [1]. It will infer things like indentation from the existing source code. I'm not sure right now how it handles long lines. Whenever we run into issues with the printer, we just create a PR to fix it. Getting automatic code formatting right is apparently quite hard. There are dedicated tools for this, such as https://github.com/millermedeiros/esformatter . [1]: https://github.com/benjamn/recast/blob/master/lib/options.js
In Write Code to Rewrite Your Code: jscodeshift

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.