Skip to content

Commit fdfd939

Browse files
committed
Skip asterisks after newline when parsing JSDoc types
1 parent 4510149 commit fdfd939

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

src/compiler/parser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,8 +2377,10 @@ namespace ts {
23772377
}
23782378

23792379
function parseJSDocType(): TypeNode {
2380+
scanner.setInJSDocType(true);
23802381
const dotdotdot = parseOptionalToken(SyntaxKind.DotDotDotToken);
23812382
let type = parseTypeOrTypePredicate();
2383+
scanner.setInJSDocType(false);
23822384
if (dotdotdot) {
23832385
const variadic = createNode(SyntaxKind.JSDocVariadicType, dotdotdot.pos) as JSDocVariadicType;
23842386
variadic.type = type;

src/compiler/scanner.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace ts {
4242
setScriptTarget(scriptTarget: ScriptTarget): void;
4343
setLanguageVariant(variant: LanguageVariant): void;
4444
setTextPos(textPos: number): void;
45+
setInJSDocType(inType: boolean): void;
4546
// Invokes the provided callback then unconditionally restores the scanner to the state it
4647
// was in immediately prior to invoking the callback. The result of invoking the callback
4748
// is returned from this function.
@@ -824,6 +825,8 @@ namespace ts {
824825
let tokenValue!: string;
825826
let tokenFlags: TokenFlags;
826827

828+
let inJSDocType = false;
829+
827830
setText(text, start, length);
828831

829832
return {
@@ -854,6 +857,7 @@ namespace ts {
854857
setLanguageVariant,
855858
setOnError,
856859
setTextPos,
860+
setInJSDocType,
857861
tryScan,
858862
lookAhead,
859863
scanRange,
@@ -1447,6 +1451,10 @@ namespace ts {
14471451
return pos += 2, token = SyntaxKind.AsteriskAsteriskToken;
14481452
}
14491453
pos++;
1454+
if (inJSDocType && (tokenFlags & TokenFlags.PrecedingLineBreak)) {
1455+
// decoration at the start of a JSDoc comment line
1456+
continue;
1457+
}
14501458
return token = SyntaxKind.AsteriskToken;
14511459
case CharacterCodes.plus:
14521460
if (text.charCodeAt(pos + 1) === CharacterCodes.plus) {
@@ -2078,5 +2086,9 @@ namespace ts {
20782086
tokenValue = undefined!;
20792087
tokenFlags = 0;
20802088
}
2089+
2090+
function setInJSDocType(inType: boolean) {
2091+
inJSDocType = inType;
2092+
}
20812093
}
20822094
}

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,6 +3087,7 @@ declare namespace ts {
30873087
setScriptTarget(scriptTarget: ScriptTarget): void;
30883088
setLanguageVariant(variant: LanguageVariant): void;
30893089
setTextPos(textPos: number): void;
3090+
setInJSDocType(inType: boolean): void;
30903091
lookAhead<T>(callback: () => T): T;
30913092
scanRange<T>(start: number, length: number, callback: () => T): T;
30923093
tryScan<T>(callback: () => T): T;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,6 +3087,7 @@ declare namespace ts {
30873087
setScriptTarget(scriptTarget: ScriptTarget): void;
30883088
setLanguageVariant(variant: LanguageVariant): void;
30893089
setTextPos(textPos: number): void;
3090+
setInJSDocType(inType: boolean): void;
30903091
lookAhead<T>(callback: () => T): T;
30913092
scanRange<T>(start: number, length: number, callback: () => T): T;
30923093
tryScan<T>(callback: () => T): T;

0 commit comments

Comments
 (0)