-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: properly assign trailing comments #12471
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
Trailing comments were added even if they started before the node end, which violates the definition of trailing comments. This fixes that, with the consequence that some comments no longer show up in the AST at all. Previously they were stuffed _somewhere_, but arguably at the wrong positions. For example the last comment in a function body got assigned as a trailing comma for the body, which is wrong, because the body ends _after_ the comma. The special case is comments at the end of an expression tag - they are added even if there are multiple, and they are added regardless of whether they are separated by newlines or not. This ensures the expression tag end is calculated correctly. Fixes #12466
🦋 Changeset detectedLatest commit: 1280a60 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 |
Ohhh now i get it...it did seem strange to me that the comments at the end of the body were added as the trailing comments of the whole arrow function expression but i naively assumed the parsing was done by acorn and it was just a weird quirk of acorn. Instead the comments are manually added later. My bad. |
Updated the PR to handle multiple trailing comments in a body, which resolves the one drawback this PR previously had (swallowing comments) |
I guess if this doesn't have drawbacks is a no brainer...should I close mine? Sorry for misjudging the issue initially |
Man, comments are a PITA to deal with. Let's go with this one since it's slightly more expansive |
Trailing comments were added even if they started before the node end, which violates the definition of trailing comments. This fixes that: Previously they were stuffed somewhere, but arguably at the wrong positions. For example the last comment in a function body got assigned as a trailing comma for the body, which is wrong, because the body ends after the comma. The special case is comments at the end of a body or an expression tag - they are added even if there are multiple, and they are added regardless of whether they are separated by newlines or not. This ensures the expression tag end is calculated correctly.
Fixes #12466
Alternative to #12469. Comparison (also see #12469 (comment)):
, with the consequence that some never show up in the AST, which means the AST is a bit lossy, which might be a problem for certain AST->string convertersand adds them at the correct positionsBefore submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint