Skip to content

Commit 72776b0

Browse files
authored
Merge pull request #22965 from Microsoft/incrementalEditWithJsDocNode
[release-2.8] Correct the incremental parsing when there is jsDoc node
2 parents d45eb25 + 4fcf5bc commit 72776b0

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
@@ -7013,7 +7013,7 @@ namespace ts {
70137013
forEachChild(node, visitNode, visitArray);
70147014
if (hasJSDocNodes(node)) {
70157015
for (const jsDocComment of node.jsDoc) {
7016-
forEachChild(jsDocComment, visitNode, visitArray);
7016+
visitNode(<IncrementalNode><Node>jsDocComment);
70177017
}
70187018
}
70197019
checkNodePositions(node, aggressiveChecks);
@@ -7119,10 +7119,16 @@ namespace ts {
71197119
function checkNodePositions(node: Node, aggressiveChecks: boolean) {
71207120
if (aggressiveChecks) {
71217121
let pos = node.pos;
7122-
forEachChild(node, child => {
7122+
const visitNode = (child: Node) => {
71237123
Debug.assert(child.pos >= pos);
71247124
pos = child.end;
7125-
});
7125+
};
7126+
if (hasJSDocNodes(node)) {
7127+
for (const jsDocComment of node.jsDoc) {
7128+
visitNode(jsDocComment);
7129+
}
7130+
}
7131+
forEachChild(node, visitNode);
71267132
Debug.assert(pos <= node.end);
71277133
}
71287134
}
@@ -7160,7 +7166,11 @@ namespace ts {
71607166
// Adjust the pos or end (or both) of the intersecting element accordingly.
71617167
adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
71627168
forEachChild(child, visitNode, visitArray);
7163-
7169+
if (hasJSDocNodes(child)) {
7170+
for (const jsDocComment of child.jsDoc) {
7171+
visitNode(<IncrementalNode><Node>jsDocComment);
7172+
}
7173+
}
71647174
checkNodePositions(child, aggressiveChecks);
71657175
return;
71667176
}
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)