Teach Oxc::Node to read and print itself - #6
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request gives a node a way to answer questions about itself. Reading its source needed the source passed back in, there was no way to get the ESTree back out, and
inspectprinted almost none of what a node carries.The source comes with the tree
Oxc.parsealready holds the source, soOxc::ParseResultkeeps it and hands it down to every node it builds.slicestill takes an argument, for a node assembled by hand or read against a different string.Getting at the ESTree
keysanswers the field names a node carries andfieldsanswers those fields and their values without the span.to_handto_jsonanswer the ESTree itself, andto_jsonnests, so{ node: node }.to_jsonworks.Nodes also pattern match, and patterns nest, since a field holding a node comes back as one. Either spelling of a field name works.
There is no
deconstruct.eachyields every descendant, so an array pattern over direct children would disagree withto_a.Printing every field
A field holding a node prints as that node's type, one holding a list prints how many, and one holding nothing prints the
nil,falseor[]it holds. Nothing is left out, soinspectandkeyscan never disagree.Leaving out the empty fields was tried first and cost more than it saved. It hid nine of a TypeScript
PropertyDefinition's twelve fields, and the field cap it bought room for was spending that room oncomputed=false static=false override=false. Both the filter and the cap are gone.Spans print as
range=[start, end], matchingHerb::Token.Oxc::ParseResultandOxc::Labelprint theirs the same way.