Handle namepaths inside JSDoc type expressions a bit better - fixes #31298
This commit is contained in:
parent
d982014d73
commit
b902a71e5f
|
@ -2429,8 +2429,16 @@ namespace ts {
|
|||
function parseJSDocType(): TypeNode {
|
||||
scanner.setInJSDocType(true);
|
||||
const dotdotdot = parseOptionalToken(SyntaxKind.DotDotDotToken);
|
||||
const moduleSpecifier = parseOptionalToken(SyntaxKind.ModuleKeyword);
|
||||
let type = parseTypeOrTypePredicate();
|
||||
scanner.setInJSDocType(false);
|
||||
if (moduleSpecifier) {
|
||||
const moduleTag = createNode(SyntaxKind.JSDocNamepathType, moduleSpecifier.pos) as JSDocNamepathType;
|
||||
while (token() !== SyntaxKind.CloseBraceToken && token() !== SyntaxKind.EndOfFileToken) {
|
||||
nextTokenJSDoc();
|
||||
}
|
||||
type = finishNode(moduleTag);
|
||||
}
|
||||
if (dotdotdot) {
|
||||
const variadic = createNode(SyntaxKind.JSDocVariadicType, dotdotdot.pos) as JSDocVariadicType;
|
||||
variadic.type = type;
|
||||
|
|
|
@ -455,6 +455,8 @@ namespace ts {
|
|||
JSDocOptionalType,
|
||||
JSDocFunctionType,
|
||||
JSDocVariadicType,
|
||||
// https://jsdoc.app/about-namepaths.html
|
||||
JSDocNamepathType,
|
||||
JSDocComment,
|
||||
JSDocTypeLiteral,
|
||||
JSDocSignature,
|
||||
|
@ -2430,6 +2432,11 @@ namespace ts {
|
|||
type: TypeNode;
|
||||
}
|
||||
|
||||
export interface JSDocNamepathType extends JSDocType {
|
||||
kind: SyntaxKind.JSDocNamepathType;
|
||||
type: TypeNode;
|
||||
}
|
||||
|
||||
export type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType;
|
||||
|
||||
export interface JSDoc extends Node {
|
||||
|
|
|
@ -374,29 +374,30 @@ declare namespace ts {
|
|||
JSDocOptionalType = 294,
|
||||
JSDocFunctionType = 295,
|
||||
JSDocVariadicType = 296,
|
||||
JSDocComment = 297,
|
||||
JSDocTypeLiteral = 298,
|
||||
JSDocSignature = 299,
|
||||
JSDocTag = 300,
|
||||
JSDocAugmentsTag = 301,
|
||||
JSDocAuthorTag = 302,
|
||||
JSDocClassTag = 303,
|
||||
JSDocCallbackTag = 304,
|
||||
JSDocEnumTag = 305,
|
||||
JSDocParameterTag = 306,
|
||||
JSDocReturnTag = 307,
|
||||
JSDocThisTag = 308,
|
||||
JSDocTypeTag = 309,
|
||||
JSDocTemplateTag = 310,
|
||||
JSDocTypedefTag = 311,
|
||||
JSDocPropertyTag = 312,
|
||||
SyntaxList = 313,
|
||||
NotEmittedStatement = 314,
|
||||
PartiallyEmittedExpression = 315,
|
||||
CommaListExpression = 316,
|
||||
MergeDeclarationMarker = 317,
|
||||
EndOfDeclarationMarker = 318,
|
||||
Count = 319,
|
||||
JSDocNamepathType = 297,
|
||||
JSDocComment = 298,
|
||||
JSDocTypeLiteral = 299,
|
||||
JSDocSignature = 300,
|
||||
JSDocTag = 301,
|
||||
JSDocAugmentsTag = 302,
|
||||
JSDocAuthorTag = 303,
|
||||
JSDocClassTag = 304,
|
||||
JSDocCallbackTag = 305,
|
||||
JSDocEnumTag = 306,
|
||||
JSDocParameterTag = 307,
|
||||
JSDocReturnTag = 308,
|
||||
JSDocThisTag = 309,
|
||||
JSDocTypeTag = 310,
|
||||
JSDocTemplateTag = 311,
|
||||
JSDocTypedefTag = 312,
|
||||
JSDocPropertyTag = 313,
|
||||
SyntaxList = 314,
|
||||
NotEmittedStatement = 315,
|
||||
PartiallyEmittedExpression = 316,
|
||||
CommaListExpression = 317,
|
||||
MergeDeclarationMarker = 318,
|
||||
EndOfDeclarationMarker = 319,
|
||||
Count = 320,
|
||||
FirstAssignment = 60,
|
||||
LastAssignment = 72,
|
||||
FirstCompoundAssignment = 61,
|
||||
|
@ -423,9 +424,9 @@ declare namespace ts {
|
|||
LastBinaryOperator = 72,
|
||||
FirstNode = 149,
|
||||
FirstJSDocNode = 289,
|
||||
LastJSDocNode = 312,
|
||||
FirstJSDocTagNode = 300,
|
||||
LastJSDocTagNode = 312,
|
||||
LastJSDocNode = 313,
|
||||
FirstJSDocTagNode = 301,
|
||||
LastJSDocTagNode = 313,
|
||||
}
|
||||
enum NodeFlags {
|
||||
None = 0,
|
||||
|
@ -1558,6 +1559,10 @@ declare namespace ts {
|
|||
kind: SyntaxKind.JSDocVariadicType;
|
||||
type: TypeNode;
|
||||
}
|
||||
interface JSDocNamepathType extends JSDocType {
|
||||
kind: SyntaxKind.JSDocNamepathType;
|
||||
type: TypeNode;
|
||||
}
|
||||
type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType;
|
||||
interface JSDoc extends Node {
|
||||
kind: SyntaxKind.JSDocComment;
|
||||
|
|
57
tests/baselines/reference/api/typescript.d.ts
vendored
57
tests/baselines/reference/api/typescript.d.ts
vendored
|
@ -374,29 +374,30 @@ declare namespace ts {
|
|||
JSDocOptionalType = 294,
|
||||
JSDocFunctionType = 295,
|
||||
JSDocVariadicType = 296,
|
||||
JSDocComment = 297,
|
||||
JSDocTypeLiteral = 298,
|
||||
JSDocSignature = 299,
|
||||
JSDocTag = 300,
|
||||
JSDocAugmentsTag = 301,
|
||||
JSDocAuthorTag = 302,
|
||||
JSDocClassTag = 303,
|
||||
JSDocCallbackTag = 304,
|
||||
JSDocEnumTag = 305,
|
||||
JSDocParameterTag = 306,
|
||||
JSDocReturnTag = 307,
|
||||
JSDocThisTag = 308,
|
||||
JSDocTypeTag = 309,
|
||||
JSDocTemplateTag = 310,
|
||||
JSDocTypedefTag = 311,
|
||||
JSDocPropertyTag = 312,
|
||||
SyntaxList = 313,
|
||||
NotEmittedStatement = 314,
|
||||
PartiallyEmittedExpression = 315,
|
||||
CommaListExpression = 316,
|
||||
MergeDeclarationMarker = 317,
|
||||
EndOfDeclarationMarker = 318,
|
||||
Count = 319,
|
||||
JSDocNamepathType = 297,
|
||||
JSDocComment = 298,
|
||||
JSDocTypeLiteral = 299,
|
||||
JSDocSignature = 300,
|
||||
JSDocTag = 301,
|
||||
JSDocAugmentsTag = 302,
|
||||
JSDocAuthorTag = 303,
|
||||
JSDocClassTag = 304,
|
||||
JSDocCallbackTag = 305,
|
||||
JSDocEnumTag = 306,
|
||||
JSDocParameterTag = 307,
|
||||
JSDocReturnTag = 308,
|
||||
JSDocThisTag = 309,
|
||||
JSDocTypeTag = 310,
|
||||
JSDocTemplateTag = 311,
|
||||
JSDocTypedefTag = 312,
|
||||
JSDocPropertyTag = 313,
|
||||
SyntaxList = 314,
|
||||
NotEmittedStatement = 315,
|
||||
PartiallyEmittedExpression = 316,
|
||||
CommaListExpression = 317,
|
||||
MergeDeclarationMarker = 318,
|
||||
EndOfDeclarationMarker = 319,
|
||||
Count = 320,
|
||||
FirstAssignment = 60,
|
||||
LastAssignment = 72,
|
||||
FirstCompoundAssignment = 61,
|
||||
|
@ -423,9 +424,9 @@ declare namespace ts {
|
|||
LastBinaryOperator = 72,
|
||||
FirstNode = 149,
|
||||
FirstJSDocNode = 289,
|
||||
LastJSDocNode = 312,
|
||||
FirstJSDocTagNode = 300,
|
||||
LastJSDocTagNode = 312,
|
||||
LastJSDocNode = 313,
|
||||
FirstJSDocTagNode = 301,
|
||||
LastJSDocTagNode = 313,
|
||||
}
|
||||
enum NodeFlags {
|
||||
None = 0,
|
||||
|
@ -1558,6 +1559,10 @@ declare namespace ts {
|
|||
kind: SyntaxKind.JSDocVariadicType;
|
||||
type: TypeNode;
|
||||
}
|
||||
interface JSDocNamepathType extends JSDocType {
|
||||
kind: SyntaxKind.JSDocNamepathType;
|
||||
type: TypeNode;
|
||||
}
|
||||
type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType;
|
||||
interface JSDoc extends Node {
|
||||
kind: SyntaxKind.JSDocComment;
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
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`.
|
||||
tests/cases/conformance/jsdoc/bug26693.js(1,21): error TS1005: '}' expected.
|
||||
tests/cases/conformance/jsdoc/bug26693.js(1,21): error TS1110: Type expected.
|
||||
tests/cases/conformance/jsdoc/bug26693.js(2,22): error TS2307: Cannot find module 'nope'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsdoc/bug26693.js (3 errors) ====
|
||||
==== tests/cases/conformance/jsdoc/bug26693.js (2 errors) ====
|
||||
/** @typedef {module:locale} hi */
|
||||
~~~~~~
|
||||
!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`.
|
||||
~
|
||||
!!! error TS1005: '}' expected.
|
||||
!!! error TS1110: Type expected.
|
||||
import { nope } from 'nope';
|
||||
~~~~~~
|
||||
!!! error TS2307: Cannot find module 'nope'.
|
||||
|
|
17
tests/cases/fourslash/jsDocDontBreakWithNamespaces.ts
Normal file
17
tests/cases/fourslash/jsDocDontBreakWithNamespaces.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
///<reference path="fourslash.ts" />
|
||||
// @allowJs: true
|
||||
// @Filename: 31298.js
|
||||
/////**
|
||||
//// * @returns {module:@nodefuel/web~Webserver~wsServer#hello} Websocket server object
|
||||
//// */
|
||||
////function foo() { }
|
||||
////foo(''/**/);
|
||||
|
||||
verify.signatureHelp({
|
||||
marker: "",
|
||||
text: "foo(): any",
|
||||
docComment: "",
|
||||
tags: [
|
||||
{ name: "returns", text: "Websocket server object" },
|
||||
],
|
||||
});
|
Loading…
Reference in a new issue