Fix node.getStart()
for nodes spanning multiline JSDoc comments (#43854)
This commit is contained in:
parent
046c65af0c
commit
58c54127a9
|
@ -554,11 +554,12 @@ namespace ts {
|
|||
}
|
||||
|
||||
/* @internal */
|
||||
export function skipTrivia(text: string, pos: number, stopAfterLineBreak?: boolean, stopAtComments = false): number {
|
||||
export function skipTrivia(text: string, pos: number, stopAfterLineBreak?: boolean, stopAtComments?: boolean, inJSDoc?: boolean): number {
|
||||
if (positionIsSynthesized(pos)) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
let canConsumeStar = false;
|
||||
// Keep in sync with couldStartTrivia
|
||||
while (true) {
|
||||
const ch = text.charCodeAt(pos);
|
||||
|
@ -573,6 +574,7 @@ namespace ts {
|
|||
if (stopAfterLineBreak) {
|
||||
return pos;
|
||||
}
|
||||
canConsumeStar = !!inJSDoc;
|
||||
continue;
|
||||
case CharacterCodes.tab:
|
||||
case CharacterCodes.verticalTab:
|
||||
|
@ -592,6 +594,7 @@ namespace ts {
|
|||
}
|
||||
pos++;
|
||||
}
|
||||
canConsumeStar = false;
|
||||
continue;
|
||||
}
|
||||
if (text.charCodeAt(pos + 1) === CharacterCodes.asterisk) {
|
||||
|
@ -603,6 +606,7 @@ namespace ts {
|
|||
}
|
||||
pos++;
|
||||
}
|
||||
canConsumeStar = false;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
@ -613,6 +617,7 @@ namespace ts {
|
|||
case CharacterCodes.greaterThan:
|
||||
if (isConflictMarkerTrivia(text, pos)) {
|
||||
pos = scanConflictMarkerTrivia(text, pos);
|
||||
canConsumeStar = false;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
@ -620,6 +625,15 @@ namespace ts {
|
|||
case CharacterCodes.hash:
|
||||
if (pos === 0 && isShebangTrivia(text, pos)) {
|
||||
pos = scanShebangTrivia(text, pos);
|
||||
canConsumeStar = false;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case CharacterCodes.asterisk:
|
||||
if (canConsumeStar) {
|
||||
pos++;
|
||||
canConsumeStar = false;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -478,7 +478,12 @@ namespace ts {
|
|||
return getTokenPosOfNode((<SyntaxList>node)._children[0], sourceFile, includeJsDoc);
|
||||
}
|
||||
|
||||
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
|
||||
return skipTrivia(
|
||||
(sourceFile || getSourceFileOfNode(node)).text,
|
||||
node.pos,
|
||||
/*stopAfterLineBreak*/ false,
|
||||
/*stopAtComments*/ false,
|
||||
isInJSDoc(node));
|
||||
}
|
||||
|
||||
export function getNonDecoratorTokenPosOfNode(node: Node, sourceFile?: SourceFileLike): number {
|
||||
|
|
20
tests/cases/fourslash/documentHighlightJSDocTypedef.ts
Normal file
20
tests/cases/fourslash/documentHighlightJSDocTypedef.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
|
||||
// @Filename: index.js
|
||||
//// /**
|
||||
//// * @typedef {{
|
||||
//// * [|foo|]: string;
|
||||
//// * [|bar|]: number;
|
||||
//// * }} Foo
|
||||
//// */
|
||||
////
|
||||
//// /** @type {Foo} */
|
||||
//// const x = {
|
||||
//// [|foo|]: "",
|
||||
//// [|bar|]: 42,
|
||||
//// };
|
||||
|
||||
verify.rangesWithSameTextAreDocumentHighlights();
|
Loading…
Reference in a new issue