-
Notifications
You must be signed in to change notification settings - Fork 12.9k
fix comment parsing at start of file #28489
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
* skip shebang if present (fixes: microsoft#28477) * don't parse trailing comments as they are also treated like leading comments
src/compiler/scanner.ts
Outdated
let accumulator = initial; | ||
if (pos === 0) { | ||
if (collecting) { |
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.
I don't understand this check.. Whats the reason for this change?
My expectation was that we only skip Shebang if pos = 0 and follow rest of the algorithm as is. Is that not sufficient ?
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.
While writing the tests I noticed that comments in the first line of a file were returned as leading and trailing comment. So I made this small change to never return trailing comments at position 0
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.
@sheetalkamat would you prefer these changes to be split into two PRs (one to skip the shebang and one to not parse trailing comments at the start of the file)?
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.
I believe the reason this hasn't been necessary is that forEachLeadingCommentToEmit
and forEachTrailingCommentToEmit
in emitter.ts handle not emitting overlapping comment ranges. I don't think this change is necessary for now and we should stick to just skipping the shebang in this PR.
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.
Ok, so I'll revert this change and open an issue to discuss changing it in a follow-up PR.
src/compiler/scanner.ts
Outdated
let accumulator = initial; | ||
if (pos === 0) { | ||
if (collecting) { |
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.
I believe the reason this hasn't been necessary is that forEachLeadingCommentToEmit
and forEachTrailingCommentToEmit
in emitter.ts handle not emitting overlapping comment ranges. I don't think this change is necessary for now and we should stick to just skipping the shebang in this PR.
@RyanCavanaugh do we want to take this for 3.3? If not I'll merge this in the afternoon. |
Thanks for the contribution! |
don't parse trailing comments to avoid duplicates that are also returned as leading comments