benjamn / benjamn/recast

Question: could recast potentially support recast.print(JSON.parse(ast-json))?

Open
#486 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
5.3k
Forks
363
Avg merge
3d 8h
Merged PRs (30d)
3

Description

I'm unfamiliar with the internals of recast, but could recast feasibly support `recast.print(JSON.parse(JSON.stringify(recast.parse(code)))).code`?

I tried it with some minimal input:

var foo = require("foo");

and encounter the exception:

TypeError: lines.skipSpaces is not a function…

util.getTrueLoc
Closure
printStatementSequence
Closure
call
genericPrintNoParens

The problem, of course, is that methods of objects in the AST are stripped in `JSON.stringify`.

This may seem like an odd question/request, but I'd like to experiment with delegating transformation to foreign (non-JS) code.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the reported failure with the minimal `var foo = require("foo");` input and inspect `lib/util.js` at `util.getTrueLoc` plus the printer path named in the stack trace. Compare the parsed AST with its JSON round trip, then define whether JSON-deserialized ASTs are supported and what test or documented behavior would demonstrate completion.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.