diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5619d3db66d..f694bc6da54 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -7013,7 +7013,7 @@ namespace ts { forEachChild(node, visitNode, visitArray); if (hasJSDocNodes(node)) { for (const jsDocComment of node.jsDoc) { - forEachChild(jsDocComment, visitNode, visitArray); + visitNode(jsDocComment); } } checkNodePositions(node, aggressiveChecks); @@ -7119,10 +7119,16 @@ namespace ts { function checkNodePositions(node: Node, aggressiveChecks: boolean) { if (aggressiveChecks) { let pos = node.pos; - forEachChild(node, child => { + const visitNode = (child: Node) => { Debug.assert(child.pos >= pos); pos = child.end; - }); + }; + if (hasJSDocNodes(node)) { + for (const jsDocComment of node.jsDoc) { + visitNode(jsDocComment); + } + } + forEachChild(node, visitNode); Debug.assert(pos <= node.end); } } @@ -7160,7 +7166,11 @@ namespace ts { // Adjust the pos or end (or both) of the intersecting element accordingly. adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta); forEachChild(child, visitNode, visitArray); - + if (hasJSDocNodes(child)) { + for (const jsDocComment of child.jsDoc) { + visitNode(jsDocComment); + } + } checkNodePositions(child, aggressiveChecks); return; } diff --git a/tests/cases/fourslash/incrementalParsingWithJsDoc.ts b/tests/cases/fourslash/incrementalParsingWithJsDoc.ts new file mode 100644 index 00000000000..cd709530f9c --- /dev/null +++ b/tests/cases/fourslash/incrementalParsingWithJsDoc.ts @@ -0,0 +1,15 @@ +/// + +////import a from 'a/aaaaaaa/aaaaaaa/aaaaaa/aaaaaaa'; +/////**/import b from 'b'; +////import c from 'c'; +//// +////[|/** @internal */|] +////export class LanguageIdentifier[| { }|] + +// Force a syntax tree ot be created. +verify.outliningSpansInCurrentFile(test.ranges()); +goTo.marker(""); +edit.backspace(test.marker("").position); +verify.outliningSpansInCurrentFile(test.ranges()); +