-
Notifications
You must be signed in to change notification settings - Fork 14
feat: getLeadingComments/getTrailingComments
#90
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
Conversation
🦋 Changeset detectedLatest commit: 47caf1c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
manuel3108
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I don't really mind. The other pr was probably too tailored around the needs for sv, but we can still totally do this with this api and just abstract it away. I don't see any notable differences to #79 so I'm happy if we wan't to proceed with this.
README.md
Outdated
| // a WeakMap of AST nodes to additional comments to insert at specific nodes | ||
| // useful for programmatically adding comments during code transformation, | ||
| // especially for nodes that were added programmatically | ||
| additionalComments: new WeakMap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should fix this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah whoops. AFK, on the subway, but can update later
Co-authored-by: Manuel <30698007+manuel3108@users.noreply.github.com>
…js/esrap into feat/additional-comments-function
This is an alternative to #79 — rather than passing in a
WeakMap, which is arguably a bit of an unusual API, this adds two new function options —getLeadingCommentsandgetTrailingComments. Both receive aTSESTree.Nodeand return either aBaseComment[]orundefined.I find function-based APIs tend to age a bit better, because they can be hammered into whatever shape you need that day. Obviously you can still use a
WeakMapon the consumer side if you prefer (just pass a function that reads from the map), but it's no longer required.Another reason I like this approach is that we don't need to add a new type with a
positionproperty — we can just the same types that are commonly found in the (TS)ESTree ecosystem.