Skip to content
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

Make sure that jsdoc is always in range with parameter declaration #58538

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2474,6 +2474,7 @@ export function getJSDocCommentRanges(node: Node, text: string) {
getLeadingCommentRanges(text, node.pos);
// True if the comment starts with '/**' but not if it is '/**/'
return filter(commentRanges, comment =>
comment.end <= node.end && // Due to parse errors sometime empty parameter may get comments assigned to it that end up not in parameter range
text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk &&
text.charCodeAt(comment.pos + 2) === CharacterCodes.asterisk &&
text.charCodeAt(comment.pos + 3) !== CharacterCodes.slash);
Expand Down
11 changes: 10 additions & 1 deletion src/testRunner/unittests/incrementalParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function insertCode(source: string, index: number, toInsert: string) {
}
}

describe("unittests:: Incremental Parser", () => {
describe("unittests:: incrementalParser::", () => {
it("Inserting into method", () => {
const source = "class C {\r\n" +
" public foo1() { }\r\n" +
Expand Down Expand Up @@ -806,6 +806,15 @@ module m3 { }\
deleteCode(source, index, "extends IFoo<T>");
});

it("when comment changes to incomplete", () => {
const source = "function bug(\r\n test /** */ true = test test 123\r\n) {}";
const oldText = ts.ScriptSnapshot.fromString(source);
const index = source.indexOf("/");
const newTextAndChange = withChange(oldText, index, 1, "");

compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
});

it("Type after incomplete enum 1", () => {
const source = "function foo() {\r\n" +
" function getOccurrencesAtPosition() {\r\n" +
Expand Down