-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Feature/add comment in ast #2471
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Naveen Jain <[email protected]>
fc3ed54
to
0b877aa
Compare
d78a38d
to
e4cedca
Compare
Edit: Resolved the issue by abstracting advance in parser... Will update the PR soon. @IvanGoncharov while migrating the logic of comment skipping to the parser, I noticed that we are using Is it desired, or should I follow some other approach towards moving skipping functionality to parser like creating lexer.lookahead in the parser itself and renaming Reference:- |
19f2566
to
3da9a6a
Compare
@nveenjain If comments now included in AST as first-class nodes it means comments should be handled by the parser. So adding But please keep comments inside the double-linked list. P.S. Based on our Slack conversation please don't forget to investigate how comments are handled inside Babel, TS, etc. parsers. I'm especially interested in having some mechanism to allow comments to survive at least some AST modification. |
@IvanGoncharov, For acorn, comments are not parsed, i.e. skipped.
Sure will add the comments to the linked list. Also, Do we need to add Support for leading and trailing comments too? |
But if we keep nodes in linked list, there might be some edge cases:- """
Description
"""
# Even with comments between them
type Hello {
world: String
} Here the description string literal will has endPosition=19 according to current implementation now, but if we add comments to linked list endPosition would become 53 (since we check the last token and it will include the comment token)... |
3da9a6a
to
0e85fbc
Compare
… feature/addCommentInAST Signed-off-by: Naveen Jain <[email protected]>
0e85fbc
to
5aef47b
Compare
Ping @nveenjain, @IvanGoncharov |
@nveenjain @IvanGoncharov I'd also love this feature - are you open to someone continuing this work? I'm working on some codemod tooling to handle schema deprecations in a fleet of UI apps and a lot of the apps leverage comments in their |
Fixes #2241
Added support to add comments in lexer itself.
Modified the tests as the root structure of the response is changed.
Added some tests. Please comment if more test cases are required.