Skip to content

Fix node.getStart() for nodes spanning multiline JSDoc comments #43854

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 1 commit into from
Apr 28, 2021

Conversation

andrewbranch
Copy link
Member

Fixes #43442

skipTrivia needs to skip a leading * inside JSDoc.

@andrewbranch andrewbranch requested a review from sandersn April 27, 2021 23:13
@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Apr 27, 2021

case CharacterCodes.asterisk:
if (canConsumeStar) {
pos++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont you need to set canConsumeStar to false in the default case as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think so—the default case is either whitespace (which doesn’t change whether we can consume a leading *) or it breaks and returns.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question about whether skipTrivia is suitable in the first place.

@@ -478,7 +478,12 @@ namespace ts {
return getTokenPosOfNode((<SyntaxList>node)._children[0], sourceFile, includeJsDoc);
}

return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like an OK fix, but I don't think skipTrivia is called on the inside of jsdoc anywhere else. Maybe there should be a completely separate code path?

I haven't thought about it deeply, so it's likely that skipTrivia is 98% right and just needed this tweak to work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it’s definitely true that I didn’t pass the parameter anywhere else. It occurred to me that I could accomplish the same thing by wrapping skipTrivia and calling it in a loop with stopAfterLineBreak, but I felt like it was a little less clear what was happening. But I can go back to that—I’m pretty ambivalent about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ummm, me too. Neither one of these functions are specific to jsdoc, so jsdoc-specific code is surprise in both.

Probably means that this is good enough.

@andrewbranch andrewbranch merged commit 58c5412 into microsoft:master Apr 28, 2021
@andrewbranch andrewbranch deleted the bug/43442 branch April 28, 2021 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSDoc @typedef object literal property rename text includes leading '*' and space
4 participants