diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c034f12b2b7..d825b0d9717 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22340,7 +22340,6 @@ namespace ts { break; case SyntaxKind.MethodSignature: case SyntaxKind.CallSignature: - case SyntaxKind.JSDocSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9f60d2ee85e..dd197f7ab26 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6726,8 +6726,31 @@ namespace ts { const callbackTag = createNode(SyntaxKind.JSDocCallbackTag, atToken.pos) as JSDocCallbackTag; callbackTag.atToken = atToken; callbackTag.tagName = tagName; - callbackTag.fullName = parseJSDocTypeNameWithNamespace(/*flags*/ 0); - return callbackTag; + callbackTag.fullName = parseJSDocTypeNameWithNamespace(); + callbackTag.name = getJSDocTypeAliasName(callbackTag.fullName); + skipWhitespace(); + + let child: JSDocParameterTag | false; + const start = scanner.getStartPos(); + const jsdocSignature = createNode(SyntaxKind.JSDocSignature, start) as JSDocSignature; + while (child = tryParse(() => parseChildParameterOrPropertyTag(PropertyLikeParse.Parameter) as JSDocParameterTag)) { + // Debug.assert(child.kind !== SyntaxKind.JSDocTypeTag); + jsdocSignature.parameters = append(jsdocSignature.parameters as MutableNodeArray, child); + } + callbackTag.signature = finishNode(jsdocSignature); + return finishNode(callbackTag); + } + + function getJSDocTypeAliasName(fullName: JSDocNamespaceBody | undefined) { + if (fullName) { + let rightNode = fullName; + while (true) { + if (ts.isIdentifier(rightNode) || !rightNode.body) { + return ts.isIdentifier(rightNode) ? rightNode : rightNode.name; + } + rightNode = rightNode.body; + } + } } function parseTypedefTag(atToken: AtToken, tagName: Identifier): JSDocTypedefTag { @@ -6737,19 +6760,8 @@ namespace ts { const typedefTag = createNode(SyntaxKind.JSDocTypedefTag, atToken.pos); typedefTag.atToken = atToken; typedefTag.tagName = tagName; - typedefTag.fullName = parseJSDocTypeNameWithNamespace(/*flags*/ 0); - if (typedefTag.fullName) { - let rightNode = typedefTag.fullName; - while (true) { - if (rightNode.kind === SyntaxKind.Identifier || !rightNode.body) { - // if node is identifier - use it as name - // otherwise use name of the rightmost part that we were able to parse - typedefTag.name = rightNode.kind === SyntaxKind.Identifier ? rightNode : rightNode.name; - break; - } - rightNode = rightNode.body; - } - } + typedefTag.fullName = parseJSDocTypeNameWithNamespace(); + typedefTag.name = getJSDocTypeAliasName(typedefTag.fullName); skipWhitespace(); typedefTag.typeExpression = typeExpression; @@ -6787,19 +6799,21 @@ namespace ts { return finishNode(typedefTag); } - function parseJSDocTypeNameWithNamespace(flags: NodeFlags) { + function parseJSDocTypeNameWithNamespace(nested?: boolean) { const pos = scanner.getTokenPos(); const typeNameOrNamespaceName = parseJSDocIdentifierName(); if (typeNameOrNamespaceName && parseOptional(SyntaxKind.DotToken)) { const jsDocNamespaceNode = createNode(SyntaxKind.ModuleDeclaration, pos); - jsDocNamespaceNode.flags |= flags; + if (nested) { + jsDocNamespaceNode.flags |= NodeFlags.NestedNamespace; + } jsDocNamespaceNode.name = typeNameOrNamespaceName; - jsDocNamespaceNode.body = parseJSDocTypeNameWithNamespace(NodeFlags.NestedNamespace); + jsDocNamespaceNode.body = parseJSDocTypeNameWithNamespace(/*nested*/ true); return finishNode(jsDocNamespaceNode); } - if (typeNameOrNamespaceName && flags & NodeFlags.NestedNamespace) { + if (typeNameOrNamespaceName && nested) { typeNameOrNamespaceName.isInJSDocNamespace = true; } return typeNameOrNamespaceName; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d71aa8404e2..0458dc36420 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -824,7 +824,6 @@ namespace ts { | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType - | JSDocSignature // TODO: Different from JSDocFunctionType?????? | FunctionDeclaration | MethodDeclaration | ConstructorDeclaration @@ -2396,9 +2395,12 @@ namespace ts { signature: JSDocSignature; } - // TODO: name it JSDocSignatureDeclaration? Could just try to reuse JSDocTypeLiteral - export interface JSDocSignature extends JSDocType, SignatureDeclarationBase { + // TODO: Could just try to reuse JSDocTypeLiteral + export interface JSDocSignature extends JSDocType, Declaration { kind: SyntaxKind.JSDocSignature; + typeParameters?: ReadonlyArray; + parameters: ReadonlyArray; + type: JSDocReturnTag | undefined; } export interface JSDocPropertyLikeTag extends JSDocTag, Declaration { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b98582e982a..04db855d4f8 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -509,7 +509,6 @@ namespace ts { export function isDeclarationWithTypeParameters(node: DeclarationWithTypeParameters): node is DeclarationWithTypeParameters { switch (node.kind) { case SyntaxKind.CallSignature: - case SyntaxKind.JSDocSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.MethodSignature: case SyntaxKind.IndexSignature: