sebastienros / esprima-dotnet

Esprima .NET (BSD license) is a .NET port of the esprima.org project. It is a standard-compliant ECMAScript parser (also popularly known as JavaScript).
BSD 3-Clause "New" or "Revised" License
425 stars 75 forks source link

Keeping trivia #391

Closed ChrML closed 1 year ago

ChrML commented 1 year ago

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 commented 1 year ago

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.