feat: add additionalComments
option for programmatic comment insertion
#79
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.
Imagine parsing an AST, making a few codemods and printing the AST again. All comment handling up until now is based on knowing where exactly the node is located (based on its
loc
property). While doing codemods you might add new nodes programmatically that therefore do not have anyloc
property. Thus,esrap
understandably fails to print comments for them.We don't want to move away from handling most comments via
loc
, as this is by far the most reliable way.To support the codemod use case, I created a new option
additionalComments
. These comments use the leading/trailing pattern and are therefore not as accurate as theloc
ones, but it's easily possible to add them to the printed code.I also considered calling these comments syntheticComments instead of additional, but for me, it didn't feel right. Happy for better suggestions.
Edit: Forgot to mention, this unblocks:
esrap
cli#620parse
&print
fromsvelte/compiler
cli#568