Skip to content

Commit 7688226

Browse files
committed
Handle namepaths inside JSDoc type expressions a bit better - fixes #31298
1 parent d982014 commit 7688226

File tree

6 files changed

+97
-58
lines changed

6 files changed

+97
-58
lines changed

src/compiler/parser.ts

+8
Original file line numberDiff line numberDiff line change
@@ -2429,8 +2429,16 @@ namespace ts {
24292429
function parseJSDocType(): TypeNode {
24302430
scanner.setInJSDocType(true);
24312431
const dotdotdot = parseOptionalToken(SyntaxKind.DotDotDotToken);
2432+
const moduleSpecifier = parseOptionalToken(SyntaxKind.ModuleKeyword);
24322433
let type = parseTypeOrTypePredicate();
24332434
scanner.setInJSDocType(false);
2435+
if (moduleSpecifier) {
2436+
const moduleTag = createNode(SyntaxKind.JSDocNamepathType, moduleSpecifier.pos) as JSDocNamepathType;
2437+
while(token() !== SyntaxKind.CloseBraceToken && token() !== SyntaxKind.EndOfFileToken) {
2438+
nextTokenJSDoc();
2439+
}
2440+
type = finishNode(moduleTag);
2441+
}
24342442
if (dotdotdot) {
24352443
const variadic = createNode(SyntaxKind.JSDocVariadicType, dotdotdot.pos) as JSDocVariadicType;
24362444
variadic.type = type;

src/compiler/types.ts

+7
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ namespace ts {
455455
JSDocOptionalType,
456456
JSDocFunctionType,
457457
JSDocVariadicType,
458+
// https://jsdoc.app/about-namepaths.html
459+
JSDocNamepathType,
458460
JSDocComment,
459461
JSDocTypeLiteral,
460462
JSDocSignature,
@@ -2430,6 +2432,11 @@ namespace ts {
24302432
type: TypeNode;
24312433
}
24322434

2435+
export interface JSDocNamepathType extends JSDocType {
2436+
kind: SyntaxKind.JSDocNamepathType;
2437+
type: TypeNode;
2438+
}
2439+
24332440
export type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType;
24342441

24352442
export interface JSDoc extends Node {

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

+31-26
Original file line numberDiff line numberDiff line change
@@ -374,29 +374,30 @@ declare namespace ts {
374374
JSDocOptionalType = 294,
375375
JSDocFunctionType = 295,
376376
JSDocVariadicType = 296,
377-
JSDocComment = 297,
378-
JSDocTypeLiteral = 298,
379-
JSDocSignature = 299,
380-
JSDocTag = 300,
381-
JSDocAugmentsTag = 301,
382-
JSDocAuthorTag = 302,
383-
JSDocClassTag = 303,
384-
JSDocCallbackTag = 304,
385-
JSDocEnumTag = 305,
386-
JSDocParameterTag = 306,
387-
JSDocReturnTag = 307,
388-
JSDocThisTag = 308,
389-
JSDocTypeTag = 309,
390-
JSDocTemplateTag = 310,
391-
JSDocTypedefTag = 311,
392-
JSDocPropertyTag = 312,
393-
SyntaxList = 313,
394-
NotEmittedStatement = 314,
395-
PartiallyEmittedExpression = 315,
396-
CommaListExpression = 316,
397-
MergeDeclarationMarker = 317,
398-
EndOfDeclarationMarker = 318,
399-
Count = 319,
377+
JSDocNamepathType = 297,
378+
JSDocComment = 298,
379+
JSDocTypeLiteral = 299,
380+
JSDocSignature = 300,
381+
JSDocTag = 301,
382+
JSDocAugmentsTag = 302,
383+
JSDocAuthorTag = 303,
384+
JSDocClassTag = 304,
385+
JSDocCallbackTag = 305,
386+
JSDocEnumTag = 306,
387+
JSDocParameterTag = 307,
388+
JSDocReturnTag = 308,
389+
JSDocThisTag = 309,
390+
JSDocTypeTag = 310,
391+
JSDocTemplateTag = 311,
392+
JSDocTypedefTag = 312,
393+
JSDocPropertyTag = 313,
394+
SyntaxList = 314,
395+
NotEmittedStatement = 315,
396+
PartiallyEmittedExpression = 316,
397+
CommaListExpression = 317,
398+
MergeDeclarationMarker = 318,
399+
EndOfDeclarationMarker = 319,
400+
Count = 320,
400401
FirstAssignment = 60,
401402
LastAssignment = 72,
402403
FirstCompoundAssignment = 61,
@@ -423,9 +424,9 @@ declare namespace ts {
423424
LastBinaryOperator = 72,
424425
FirstNode = 149,
425426
FirstJSDocNode = 289,
426-
LastJSDocNode = 312,
427-
FirstJSDocTagNode = 300,
428-
LastJSDocTagNode = 312,
427+
LastJSDocNode = 313,
428+
FirstJSDocTagNode = 301,
429+
LastJSDocTagNode = 313,
429430
}
430431
enum NodeFlags {
431432
None = 0,
@@ -1558,6 +1559,10 @@ declare namespace ts {
15581559
kind: SyntaxKind.JSDocVariadicType;
15591560
type: TypeNode;
15601561
}
1562+
interface JSDocNamepathType extends JSDocType {
1563+
kind: SyntaxKind.JSDocNamepathType;
1564+
type: TypeNode;
1565+
}
15611566
type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType;
15621567
interface JSDoc extends Node {
15631568
kind: SyntaxKind.JSDocComment;

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

+31-26
Original file line numberDiff line numberDiff line change
@@ -374,29 +374,30 @@ declare namespace ts {
374374
JSDocOptionalType = 294,
375375
JSDocFunctionType = 295,
376376
JSDocVariadicType = 296,
377-
JSDocComment = 297,
378-
JSDocTypeLiteral = 298,
379-
JSDocSignature = 299,
380-
JSDocTag = 300,
381-
JSDocAugmentsTag = 301,
382-
JSDocAuthorTag = 302,
383-
JSDocClassTag = 303,
384-
JSDocCallbackTag = 304,
385-
JSDocEnumTag = 305,
386-
JSDocParameterTag = 306,
387-
JSDocReturnTag = 307,
388-
JSDocThisTag = 308,
389-
JSDocTypeTag = 309,
390-
JSDocTemplateTag = 310,
391-
JSDocTypedefTag = 311,
392-
JSDocPropertyTag = 312,
393-
SyntaxList = 313,
394-
NotEmittedStatement = 314,
395-
PartiallyEmittedExpression = 315,
396-
CommaListExpression = 316,
397-
MergeDeclarationMarker = 317,
398-
EndOfDeclarationMarker = 318,
399-
Count = 319,
377+
JSDocNamepathType = 297,
378+
JSDocComment = 298,
379+
JSDocTypeLiteral = 299,
380+
JSDocSignature = 300,
381+
JSDocTag = 301,
382+
JSDocAugmentsTag = 302,
383+
JSDocAuthorTag = 303,
384+
JSDocClassTag = 304,
385+
JSDocCallbackTag = 305,
386+
JSDocEnumTag = 306,
387+
JSDocParameterTag = 307,
388+
JSDocReturnTag = 308,
389+
JSDocThisTag = 309,
390+
JSDocTypeTag = 310,
391+
JSDocTemplateTag = 311,
392+
JSDocTypedefTag = 312,
393+
JSDocPropertyTag = 313,
394+
SyntaxList = 314,
395+
NotEmittedStatement = 315,
396+
PartiallyEmittedExpression = 316,
397+
CommaListExpression = 317,
398+
MergeDeclarationMarker = 318,
399+
EndOfDeclarationMarker = 319,
400+
Count = 320,
400401
FirstAssignment = 60,
401402
LastAssignment = 72,
402403
FirstCompoundAssignment = 61,
@@ -423,9 +424,9 @@ declare namespace ts {
423424
LastBinaryOperator = 72,
424425
FirstNode = 149,
425426
FirstJSDocNode = 289,
426-
LastJSDocNode = 312,
427-
FirstJSDocTagNode = 300,
428-
LastJSDocTagNode = 312,
427+
LastJSDocNode = 313,
428+
FirstJSDocTagNode = 301,
429+
LastJSDocTagNode = 313,
429430
}
430431
enum NodeFlags {
431432
None = 0,
@@ -1558,6 +1559,10 @@ declare namespace ts {
15581559
kind: SyntaxKind.JSDocVariadicType;
15591560
type: TypeNode;
15601561
}
1562+
interface JSDocNamepathType extends JSDocType {
1563+
kind: SyntaxKind.JSDocNamepathType;
1564+
type: TypeNode;
1565+
}
15611566
type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType;
15621567
interface JSDoc extends Node {
15631568
kind: SyntaxKind.JSDocComment;

tests/baselines/reference/noAssertForUnparseableTypedefs.errors.txt

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
tests/cases/conformance/jsdoc/bug26693.js(1,15): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`.
2-
tests/cases/conformance/jsdoc/bug26693.js(1,21): error TS1005: '}' expected.
1+
tests/cases/conformance/jsdoc/bug26693.js(1,21): error TS1110: Type expected.
32
tests/cases/conformance/jsdoc/bug26693.js(2,22): error TS2307: Cannot find module 'nope'.
43

54

6-
==== tests/cases/conformance/jsdoc/bug26693.js (3 errors) ====
5+
==== tests/cases/conformance/jsdoc/bug26693.js (2 errors) ====
76
/** @typedef {module:locale} hi */
8-
~~~~~~
9-
!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`.
107
~
11-
!!! error TS1005: '}' expected.
8+
!!! error TS1110: Type expected.
129
import { nope } from 'nope';
1310
~~~~~~
1411
!!! error TS2307: Cannot find module 'nope'.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
///<reference path="fourslash.ts" />
2+
// @allowJs: true
3+
// @Filename: 31298.js
4+
/////**
5+
//// * @returns {module:@nodefuel/web~Webserver~wsServer#hello} Websocket server object
6+
//// */
7+
////function foo() { }
8+
////foo(''/**/);
9+
10+
verify.signatureHelp({
11+
marker: "",
12+
text: "foo(): any",
13+
docComment: "",
14+
tags: [
15+
{ name: "returns", text: "Websocket server object" },
16+
],
17+
});

0 commit comments

Comments
 (0)