Remove JSDocConstructor/ThisType and just use named parameters

This commit is contained in:
Nathan Shively-Sanders 2017-07-14 09:36:12 -07:00
parent da5285e979
commit 6e861fd3e6
5 changed files with 36 additions and 79 deletions

View file

@ -280,14 +280,7 @@ namespace ts {
Debug.assert(node.parent.kind === SyntaxKind.JSDocFunctionType);
const functionType = <JSDocFunctionType>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;

View file

@ -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(<JSDocNullableType>node);
case SyntaxKind.ParenthesizedType:
case SyntaxKind.JSDocNonNullableType:
case SyntaxKind.JSDocConstructorType:
case SyntaxKind.JSDocThisType:
case SyntaxKind.JSDocOptionalType:
return getTypeFromTypeNode((<ParenthesizedTypeNode | JSDocTypeReferencingNode>node).type);
case SyntaxKind.FunctionType:
@ -12367,7 +12359,9 @@ namespace ts {
const jsdocType = getJSDocType(node);
if (jsdocType && jsdocType.kind === SyntaxKind.JSDocFunctionType) {
const jsDocFunctionType = <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:

View file

@ -404,10 +404,6 @@ namespace ts {
visitNode(cbNode, (<JSDocFunctionType>node).type);
case SyntaxKind.JSDocVariadicType:
return visitNode(cbNode, (<JSDocVariadicType>node).type);
case SyntaxKind.JSDocConstructorType:
return visitNode(cbNode, (<JSDocConstructorType>node).type);
case SyntaxKind.JSDocThisType:
return visitNode(cbNode, (<JSDocThisType>node).type);
case SyntaxKind.JSDocComment:
return visitNodes(cbNode, cbNodes, (<JSDoc>node).tags);
case SyntaxKind.JSDocParameterTag:
@ -2134,13 +2130,17 @@ namespace ts {
}
function parseJSDocParameter(): ParameterDeclaration {
const parameter = <ParameterDeclaration>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 = <FunctionOrConstructorTypeNode>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;
}

View file

@ -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;

View file

@ -1447,8 +1447,9 @@ namespace ts {
export function isJSDocConstructSignature(node: Node) {
return node.kind === SyntaxKind.JSDocFunctionType &&
(<JSDocFunctionType>node).parameters.length > 0 &&
(<JSDocFunctionType>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;
}