Skip to content

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

Merged
merged 8 commits into from
Jan 30, 2019
Merged

Conversation

ajafff
Copy link
Contributor

@ajafff ajafff commented Nov 12, 2018

* skip shebang if present (fixes: microsoft#28477)
* don't parse trailing comments as they are also treated like leading comments
let accumulator = initial;
if (pos === 0) {
if (collecting) {
Copy link
Member

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 ?

Copy link
Contributor Author

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

Copy link
Contributor Author

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)?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@sheetalkamat sheetalkamat requested a review from rbuckton January 3, 2019 16:52
let accumulator = initial;
if (pos === 0) {
if (collecting) {
Copy link
Contributor

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.

@rbuckton
Copy link
Contributor

@RyanCavanaugh do we want to take this for 3.3? If not I'll merge this in the afternoon.

@rbuckton
Copy link
Contributor

Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

comments following shebang are not recognised
4 participants