diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 3a7c206ac650c..4cf5f0082cd20 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -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); diff --git a/src/testRunner/unittests/incrementalParser.ts b/src/testRunner/unittests/incrementalParser.ts index 7d4aa1cea04a0..f508f80db71f7 100644 --- a/src/testRunner/unittests/incrementalParser.ts +++ b/src/testRunner/unittests/incrementalParser.ts @@ -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" + @@ -806,6 +806,15 @@ module m3 { }\ deleteCode(source, index, "extends IFoo"); }); + 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" +