Skip to content

Commit 5472ca9

Browse files
authored
Merge pull request microsoft#22963 from Microsoft/incrementalEditWithJsDocNode
Correct the incremental parsing when there is jsDoc node
2 parents 7d39b45 + 33e9ef6 commit 5472ca9

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/compiler/parser.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6965,7 +6965,7 @@ namespace ts {
69656965
forEachChild(node, visitNode, visitArray);
69666966
if (hasJSDocNodes(node)) {
69676967
for (const jsDocComment of node.jsDoc) {
6968-
forEachChild(jsDocComment, visitNode, visitArray);
6968+
visitNode(<IncrementalNode><Node>jsDocComment);
69696969
}
69706970
}
69716971
checkNodePositions(node, aggressiveChecks);
@@ -7071,10 +7071,16 @@ namespace ts {
70717071
function checkNodePositions(node: Node, aggressiveChecks: boolean) {
70727072
if (aggressiveChecks) {
70737073
let pos = node.pos;
7074-
forEachChild(node, child => {
7074+
const visitNode = (child: Node) => {
70757075
Debug.assert(child.pos >= pos);
70767076
pos = child.end;
7077-
});
7077+
};
7078+
if (hasJSDocNodes(node)) {
7079+
for (const jsDocComment of node.jsDoc) {
7080+
visitNode(jsDocComment);
7081+
}
7082+
}
7083+
forEachChild(node, visitNode);
70787084
Debug.assert(pos <= node.end);
70797085
}
70807086
}
@@ -7112,7 +7118,11 @@ namespace ts {
71127118
// Adjust the pos or end (or both) of the intersecting element accordingly.
71137119
adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
71147120
forEachChild(child, visitNode, visitArray);
7115-
7121+
if (hasJSDocNodes(child)) {
7122+
for (const jsDocComment of child.jsDoc) {
7123+
visitNode(<IncrementalNode><Node>jsDocComment);
7124+
}
7125+
}
71167126
checkNodePositions(child, aggressiveChecks);
71177127
return;
71187128
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////import a from 'a/aaaaaaa/aaaaaaa/aaaaaa/aaaaaaa';
4+
/////**/import b from 'b';
5+
////import c from 'c';
6+
////
7+
////[|/** @internal */|]
8+
////export class LanguageIdentifier[| { }|]
9+
10+
// Force a syntax tree ot be created.
11+
verify.outliningSpansInCurrentFile(test.ranges());
12+
goTo.marker("");
13+
edit.backspace(test.marker("").position);
14+
verify.outliningSpansInCurrentFile(test.ranges());
15+

0 commit comments

Comments
 (0)