Skip to content

Conversation

@ejsmith
Copy link
Contributor

@ejsmith ejsmith commented Jun 23, 2025

I would like to be able to have the ability to use other parsers or augment existing parsers and provide Jint with the AST directly. The main use case I'm trying to solve for is I would like to have a TypeScript parser that strips out any TypeScript code while preserving all source locations and pass that directly into Jint as a normal JavaScript AST. Thoughts?

@ejsmith ejsmith changed the title Ability to use Script and Module ASTs Ability to use Script and Module ASTs directly Jun 23, 2025
@niemyjski
Copy link

@sebastienros would you be willing to accept this pr?

@adams85
Copy link
Contributor

adams85 commented Oct 17, 2025

I have no say in the matter, but as someone who contributed to the current design, here's my two cents:

As I already mentioned here, the proposed approach would mess up the consistency of the current API design. Among others, it's not enough on its own to pass a preparsed AST to Jint because the script may contain code that require parsing of further code during execution (e.g., import statements, eval, shadow realms, etc.)

This is a nonissue in the current implementation since Jint handles parsing entirely internally. But as soon as it allows passing an AST created with the incorrect settings or some modified parser, it can't be consistent any more.

If Jint wanted to support alternative parsers, I think the correct way to do that would be accepting a parser factory callback via IPreparationOptions and IParsingOptions. Jint could use that internally to create parser instances whenever it's necessary to make sure that parsing is done consistently and with the right settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants