diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 0c3f1a2444d..803c9f60709 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -280,14 +280,7 @@ namespace ts { Debug.assert(node.parent.kind === SyntaxKind.JSDocFunctionType); const functionType = node.parent; const index = indexOf(functionType.parameters, node); - switch ((node as ParameterDeclaration).type.kind) { - case SyntaxKind.JSDocThisType: - return "this" as __String; - case SyntaxKind.JSDocConstructorType: - return "new" as __String; - default: - return "arg" + index as __String; - } + return "arg" + index as __String; case SyntaxKind.JSDocTypedefTag: const parentNode = node.parent && node.parent.parent; let nameFromParentNode: __String; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b5d1cf5bcc6..fa44b6a3f5b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6339,7 +6339,7 @@ namespace ts { const resolvedSymbol = resolveName(param, paramSymbol.name, SymbolFlags.Value, undefined, undefined); paramSymbol = resolvedSymbol; } - if (i === 0 && paramSymbol.name === "this" || (param.type && param.type.kind === SyntaxKind.JSDocThisType)) { + if (i === 0 && paramSymbol.name === "this") { hasThisParameter = true; thisParameter = param.symbol; } @@ -6882,7 +6882,6 @@ namespace ts { case "Null": return nullType; case "Object": - case "object": return anyType; case "Function": case "function": @@ -7842,12 +7841,7 @@ namespace ts { case SyntaxKind.NeverKeyword: return neverType; case SyntaxKind.ObjectKeyword: - if (node.flags & NodeFlags.JavaScriptFile) { - return anyType; - } - else { - return nonPrimitiveType; - } + return node.flags & NodeFlags.JavaScriptFile ? anyType : nonPrimitiveType; case SyntaxKind.ThisType: case SyntaxKind.ThisKeyword: return getTypeFromThisTypeNode(node); @@ -7873,8 +7867,6 @@ namespace ts { return getTypeFromJSDocNullableTypeNode(node); case SyntaxKind.ParenthesizedType: case SyntaxKind.JSDocNonNullableType: - case SyntaxKind.JSDocConstructorType: - case SyntaxKind.JSDocThisType: case SyntaxKind.JSDocOptionalType: return getTypeFromTypeNode((node).type); case SyntaxKind.FunctionType: @@ -12367,7 +12359,9 @@ namespace ts { const jsdocType = getJSDocType(node); if (jsdocType && jsdocType.kind === SyntaxKind.JSDocFunctionType) { const jsDocFunctionType = jsdocType; - if (jsDocFunctionType.parameters.length > 0 && jsDocFunctionType.parameters[0].type.kind === SyntaxKind.JSDocThisType) { + if (jsDocFunctionType.parameters.length > 0 && + jsDocFunctionType.parameters[0].name && + (jsDocFunctionType.parameters[0].name as Identifier).text === "this") { return getTypeFromTypeNode(jsDocFunctionType.parameters[0].type); } } @@ -19361,17 +19355,31 @@ namespace ts { } } - function checkJsDoc(node: FunctionDeclaration | MethodDeclaration) { - if (!node.jsDoc) { + function checkJSDoc(node: FunctionDeclaration | MethodDeclaration) { + if (!isInJavaScriptFile(node)) { return; } - for (const doc of node.jsDoc) { - checkSourceElement(doc); + forEach(node.jsDoc, checkSourceElement); + } + + function checkJSDocComment(node: JSDoc) { + if ((node as JSDoc).tags) { + for (const tag of (node as JSDoc).tags) { + checkSourceElement(tag); + } } } + function checkJSDocFunctionType(node: JSDocFunctionType) { + for (const p of node.parameters) { + // don't bother with normal parameter checking since jsdoc function parameters only consist of a type + checkSourceElement(p.type); + } + checkSourceElement(node.type); + } + function checkFunctionOrMethodDeclaration(node: FunctionDeclaration | MethodDeclaration): void { - checkJsDoc(node); + checkJSDoc(node); checkDecorators(node); checkSignatureDeclaration(node); const functionFlags = getFunctionFlags(node); @@ -21970,22 +21978,6 @@ namespace ts { } } - function checkJSDocComment(node: JSDoc) { - if (isInJavaScriptFile(node) && (node as JSDoc).tags) { - for (const tag of (node as JSDoc).tags) { - checkSourceElement(tag); - } - } - } - - function checkJSDocFunctionType(node: JSDocFunctionType) { - for (const p of node.parameters) { - // don't bother with normal parameter checking since jsdoc function parameters only consist of a type - checkSourceElement(p.type); - } - checkSourceElement(node.type); - } - function checkSourceElement(node: Node): void { if (!node) { return; @@ -22052,8 +22044,6 @@ namespace ts { case SyntaxKind.JSDocFunctionType: checkJSDocFunctionType(node as JSDocFunctionType); // falls through - case SyntaxKind.JSDocConstructorType: - case SyntaxKind.JSDocThisType: case SyntaxKind.JSDocVariadicType: case SyntaxKind.JSDocNonNullableType: case SyntaxKind.JSDocNullableType: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 41abbf59305..1ecd654d86a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -404,10 +404,6 @@ namespace ts { visitNode(cbNode, (node).type); case SyntaxKind.JSDocVariadicType: return visitNode(cbNode, (node).type); - case SyntaxKind.JSDocConstructorType: - return visitNode(cbNode, (node).type); - case SyntaxKind.JSDocThisType: - return visitNode(cbNode, (node).type); case SyntaxKind.JSDocComment: return visitNodes(cbNode, cbNodes, (node).tags); case SyntaxKind.JSDocParameterTag: @@ -2134,13 +2130,17 @@ namespace ts { } function parseJSDocParameter(): ParameterDeclaration { - const parameter = createNode(SyntaxKind.Parameter); + const parameter = createNode(SyntaxKind.Parameter) as ParameterDeclaration; + if (token() === SyntaxKind.ThisKeyword || token() === SyntaxKind.NewKeyword) { + parameter.name = parseIdentifierName(); + parseExpected(SyntaxKind.ColonToken); + } parameter.type = parseType(); return finishNode(parameter); } function parseJSDocNodeWithType(kind: SyntaxKind): TypeNode { - const result = createNode(kind) as JSDocVariadicType | JSDocNonNullableType | JSDocThisType | JSDocConstructorType; + const result = createNode(kind) as JSDocVariadicType | JSDocNonNullableType; nextToken(); result.type = parseType(); return finishNode(result); @@ -2567,14 +2567,10 @@ namespace ts { return finishNode(node); } - function parseFunctionOrConstructorType(kind: SyntaxKind): FunctionOrConstructorTypeNode | JSDocConstructorType { + function parseFunctionOrConstructorType(kind: SyntaxKind): FunctionOrConstructorTypeNode { const node = createNode(kind); if (kind === SyntaxKind.ConstructorType) { parseExpected(SyntaxKind.NewKeyword); - if (token() === SyntaxKind.ColonToken) { - // JSDoc -- `new:T` as in `function(new:T, string, string)`; an infix constructor-return-type - return parseJSDocNodeWithType(SyntaxKind.JSDocConstructorType) as JSDocConstructorType; - } } fillSignature(SyntaxKind.EqualsGreaterThanToken, SignatureFlags.Type, node); return finishNode(node); @@ -2633,9 +2629,6 @@ namespace ts { if (token() === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) { return parseThisTypePredicate(thisKeyword); } - else if (token() === SyntaxKind.ColonToken) { - return parseJSDocNodeWithType(SyntaxKind.JSDocThisType); - } else { return thisKeyword; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b2fb24fa0e4..85e859603d7 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -352,8 +352,6 @@ namespace ts { JSDocOptionalType, JSDocFunctionType, JSDocVariadicType, - JSDocConstructorType, - JSDocThisType, JSDocComment, JSDocTag, JSDocAugmentsTag, @@ -2067,17 +2065,7 @@ namespace ts { type: TypeNode; } - export interface JSDocConstructorType extends JSDocType { - kind: SyntaxKind.JSDocConstructorType; - type: TypeNode; - } - - export interface JSDocThisType extends JSDocType { - kind: SyntaxKind.JSDocThisType; - type: TypeNode; - } - - export type JSDocTypeReferencingNode = JSDocThisType | JSDocConstructorType | JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType; + export type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType; export interface JSDoc extends Node { kind: SyntaxKind.JSDocComment; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index f7356f425fe..dcfad8e776e 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1447,8 +1447,9 @@ namespace ts { export function isJSDocConstructSignature(node: Node) { return node.kind === SyntaxKind.JSDocFunctionType && - (node).parameters.length > 0 && - (node).parameters[0].type.kind === SyntaxKind.JSDocConstructorType; + (node as JSDocFunctionType).parameters.length > 0 && + (node as JSDocFunctionType).parameters[0].name && + ((node as JSDocFunctionType).parameters[0].name as Identifier).text === "new"; } export function hasJSDocParameterTags(node: FunctionLikeDeclaration | SignatureDeclaration): boolean { @@ -4687,14 +4688,6 @@ namespace ts { return node.kind === SyntaxKind.JSDocVariadicType; } - export function isJSDocConstructorType(node: Node): node is JSDocConstructorType { - return node.kind === SyntaxKind.JSDocConstructorType; - } - - export function isJSDocThisType(node: Node): node is JSDocThisType { - return node.kind === SyntaxKind.JSDocThisType; - } - export function isJSDoc(node: Node): node is JSDoc { return node.kind === SyntaxKind.JSDocComment; }