Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84ed6a3

Browse files
authored
Make sure that jsdoc is always in range with parameter declaration (microsoft#58538)
1 parent 4ece0a3 commit 84ed6a3

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/compiler/utilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,6 +2474,7 @@ export function getJSDocCommentRanges(node: Node, text: string) {
24742474
getLeadingCommentRanges(text, node.pos);
24752475
// True if the comment starts with '/**' but not if it is '/**/'
24762476
return filter(commentRanges, comment =>
2477+
comment.end <= node.end && // Due to parse errors sometime empty parameter may get comments assigned to it that end up not in parameter range
24772478
text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk &&
24782479
text.charCodeAt(comment.pos + 2) === CharacterCodes.asterisk &&
24792480
text.charCodeAt(comment.pos + 3) !== CharacterCodes.slash);

src/testRunner/unittests/incrementalParser.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function insertCode(source: string, index: number, toInsert: string) {
120120
}
121121
}
122122

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

809+
it("when comment changes to incomplete", () => {
810+
const source = "function bug(\r\n test /** */ true = test test 123\r\n) {}";
811+
const oldText = ts.ScriptSnapshot.fromString(source);
812+
const index = source.indexOf("/");
813+
const newTextAndChange = withChange(oldText, index, 1, "");
814+
815+
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
816+
});
817+
809818
it("Type after incomplete enum 1", () => {
810819
const source = "function foo() {\r\n" +
811820
" function getOccurrencesAtPosition() {\r\n" +

0 commit comments

Comments
 (0)