Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keeping trivia #391

Closed
ChrML opened this issue Aug 1, 2023 · 1 comment
Closed

Keeping trivia #391

ChrML opened this issue Aug 1, 2023 · 1 comment
Labels

Comments

@ChrML
Copy link

ChrML commented Aug 1, 2023

I can't find any way to keep the trivia (whitespace, line-shifts etc...) when parsing the syntax-tree. Ideally, a roundtrip from a Javascript string, to AST and back to a Javascript string should in my case give the exact same string (like the Microsoft.CodeAnalysis.CSharp syntax tree). Is there a plan for a feature like this?

@adams85
Copy link
Collaborator

adams85 commented Aug 1, 2023

Short answer: full fidelity (or concrete) syntax (including trivia) is not supported currently.

Long answer: Esprima is based on the ESTree specification, which doesn't implement full fidelity syntax. There is an open proposal though, without a clear perspective.

But even if such thing gets spec'ed, it's unlikely that it will ever land here. Besides the fact that implementing it would be a huge amount of work, there are also other aspects to take into account:

[...] because its main consumer is Jint, which wouldn't want to pay the price of a more detailed AST model.

(Quote from a related discussion).

So, I'm pretty certain that full fidelity syntax can only happen in a fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants