From f41a96b24d44a6b696d39eee9e91ef7f606bea52 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 1 May 2018 15:59:12 -0700 Subject: [PATCH] Rename the rest of typeExpressions Turns out there is a constraint in services such that they all need to be named the same. --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 22 +++++++++++----------- src/compiler/parser.ts | 18 +++++++++--------- src/compiler/types.ts | 6 +++--- src/compiler/utilities.ts | 8 ++++---- src/services/classifier.ts | 12 ++++++------ src/services/completions.ts | 8 ++++---- src/services/jsDoc.ts | 2 +- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index d189c69e2bb10..15925377cd956 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2214,7 +2214,7 @@ namespace ts { // falls through case SyntaxKind.JSDocPropertyTag: const propTag = node as JSDocPropertyLikeTag; - const flags = propTag.isBracketed || propTag.typeExpression && propTag.typeExpression.type.kind === SyntaxKind.JSDocOptionalType ? + const flags = propTag.isBracketed || propTag.type && propTag.type.type.kind === SyntaxKind.JSDocOptionalType ? SymbolFlags.Property | SymbolFlags.Optional : SymbolFlags.Property; return declareSymbolAndAddToSymbolTable(propTag, flags, SymbolFlags.PropertyExcludes); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2b2e3e00cd014..8936f5cc1b78a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4708,8 +4708,8 @@ namespace ts { if (declaration.kind === SyntaxKind.ExportAssignment) { return links.type = checkExpression((declaration).expression); } - if (isInJavaScriptFile(declaration) && isJSDocPropertyLikeTag(declaration) && declaration.typeExpression) { - return links.type = getTypeFromTypeNode(declaration.typeExpression.type); + if (isInJavaScriptFile(declaration) && isJSDocPropertyLikeTag(declaration) && declaration.type) { + return links.type = getTypeFromTypeNode(declaration.type.type); } // Handle variable, parameter or property if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) { @@ -6911,8 +6911,8 @@ namespace ts { return isInJavaScriptFile(node) && ( // node.type should only be a JSDocOptionalType when node is a parameter of a JSDocFunctionType node.type && node.type.kind === SyntaxKind.JSDocOptionalType - || getJSDocParameterTags(node).some(({ isBracketed, typeExpression }) => - isBracketed || !!typeExpression && typeExpression.type.kind === SyntaxKind.JSDocOptionalType)); + || getJSDocParameterTags(node).some(({ isBracketed, type }) => + isBracketed || !!type && type.type.kind === SyntaxKind.JSDocOptionalType)); } function tryFindAmbientModule(moduleName: string, withAugmentations: boolean) { @@ -7105,7 +7105,7 @@ namespace ts { const lastParam = lastOrUndefined(declaration.parameters); const lastParamTags = lastParam ? getJSDocParameterTags(lastParam) : getJSDocTags(declaration).filter(isJSDocParameterTag); const lastParamVariadicType = firstDefined(lastParamTags, p => - p.typeExpression && isJSDocVariadicType(p.typeExpression.type) ? p.typeExpression.type : undefined); + p.type && isJSDocVariadicType(p.type.type) ? p.type.type : undefined); const syntheticArgsSymbol = createSymbol(SymbolFlags.Variable, "args" as __String); syntheticArgsSymbol.type = lastParamVariadicType ? createArrayType(getTypeFromTypeNode(lastParamVariadicType.type)) : anyArrayType; @@ -15166,7 +15166,7 @@ namespace ts { case SyntaxKind.ParenthesizedExpression: { // Like in `checkParenthesizedExpression`, an `/** @type {xyz} */` comment before a parenthesized expression acts as a type cast. const tag = isInJavaScriptFile(parent) ? getJSDocTypeTag(parent) : undefined; - return tag ? getTypeFromTypeNode(tag.typeExpression.type) : getContextualType(parent); + return tag ? getTypeFromTypeNode(tag.type.type) : getContextualType(parent); } case SyntaxKind.JsxExpression: return getContextualTypeForJsxExpression(parent); @@ -20465,7 +20465,7 @@ namespace ts { function checkParenthesizedExpression(node: ParenthesizedExpression, checkMode?: CheckMode): Type { const tag = isInJavaScriptFile(node) ? getJSDocTypeTag(node) : undefined; if (tag) { - return checkAssertionWorker(tag, tag.typeExpression.type, node.expression, checkMode); + return checkAssertionWorker(tag, tag.type.type, node.expression, checkMode); } return checkExpression(node.expression, checkMode); } @@ -22147,7 +22147,7 @@ namespace ts { function checkJSDocTypedefTag(node: JSDocTypedefTag) { if (!node.type) { - // If the node had `@property` tags, `typeExpression` would have been set to the first property tag. + // If the node had `@property` tags, `type` would have been set to the first property tag. error(node.name, Diagnostics.JSDoc_typedef_tag_should_either_have_a_type_annotation_or_be_followed_by_property_or_member_tags); } @@ -22158,7 +22158,7 @@ namespace ts { } function checkJSDocParameterTag(node: JSDocParameterTag) { - checkSourceElement(node.typeExpression); + checkSourceElement(node.type); if (!getParameterSymbolFromJSDoc(node)) { const decl = getHostSignatureFromJSDoc(node); // don't issue an error for invalid hosts -- just functions -- @@ -22175,8 +22175,8 @@ namespace ts { idText(node.name.kind === SyntaxKind.QualifiedName ? node.name.right : node.name)); } else if (findLast(getJSDocTags(decl), isJSDocParameterTag) === node && - node.typeExpression && node.typeExpression.type && - !isArrayType(getTypeFromTypeNode(node.typeExpression.type))) { + node.type && node.type.type && + !isArrayType(getTypeFromTypeNode(node.type.type))) { error(node.name, Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type, idText(node.name.kind === SyntaxKind.QualifiedName ? node.name.right : node.name)); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index d516c3898bad3..e47908efa32bc 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -465,16 +465,16 @@ namespace ts { case SyntaxKind.JSDocPropertyTag: if ((node as JSDocPropertyLikeTag).isNameFirst) { return visitNode(cbNode, (node).name) || - visitNode(cbNode, (node).typeExpression); + visitNode(cbNode, (node).type); } else { - return visitNode(cbNode, (node).typeExpression) || + return visitNode(cbNode, (node).type) || visitNode(cbNode, (node).name); } case SyntaxKind.JSDocReturnTag: - return visitNode(cbNode, (node).typeExpression); + return visitNode(cbNode, (node).type); case SyntaxKind.JSDocTypeTag: - return visitNode(cbNode, (node).typeExpression); + return visitNode(cbNode, (node).type); case SyntaxKind.JSDocAugmentsTag: return visitNode(cbNode, (node).class); case SyntaxKind.JSDocTemplateTag: @@ -6628,7 +6628,7 @@ namespace ts { } result.atToken = atToken; result.tagName = tagName; - result.typeExpression = typeExpression; + result.type = typeExpression; result.name = name; result.isNameFirst = isNameFirst; result.isBracketed = isBracketed; @@ -6668,7 +6668,7 @@ namespace ts { const result = createNode(SyntaxKind.JSDocReturnTag, atToken.pos); result.atToken = atToken; result.tagName = tagName; - result.typeExpression = tryParseTypeExpression(); + result.type = tryParseTypeExpression(); return finishNode(result); } @@ -6680,7 +6680,7 @@ namespace ts { const result = createNode(SyntaxKind.JSDocTypeTag, atToken.pos); result.atToken = atToken; result.tagName = tagName; - result.typeExpression = parseJSDocTypeExpression(/*mayOmitBraces*/ true); + result.type = parseJSDocTypeExpression(/*mayOmitBraces*/ true); return finishNode(result); } @@ -6790,8 +6790,8 @@ namespace ts { if (typeExpression && typeExpression.type.kind === SyntaxKind.ArrayType) { jsdocTypeLiteral.isArrayType = true; } - typedefTag.type = childTypeTag && childTypeTag.typeExpression && !isObjectOrObjectArrayTypeReference(childTypeTag.typeExpression.type) ? - childTypeTag.typeExpression : + typedefTag.type = childTypeTag && childTypeTag.type && !isObjectOrObjectArrayTypeReference(childTypeTag.type.type) ? + childTypeTag.type : finishNode(jsdocTypeLiteral); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b0939668d91af..35e2254c2dca6 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2371,12 +2371,12 @@ namespace ts { export interface JSDocReturnTag extends JSDocTag { kind: SyntaxKind.JSDocReturnTag; - typeExpression: JSDocTypeExpression; + type: JSDocTypeExpression; } export interface JSDocTypeTag extends JSDocTag { kind: SyntaxKind.JSDocTypeTag; - typeExpression: JSDocTypeExpression; + type: JSDocTypeExpression; } export interface JSDocTypedefTag extends JSDocTag, NamedDeclaration { @@ -2406,7 +2406,7 @@ namespace ts { export interface JSDocPropertyLikeTag extends JSDocTag, Declaration { parent: JSDoc; name: EntityName; - typeExpression?: JSDocTypeExpression; + type?: JSDocTypeExpression; /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ isNameFirst: boolean; isBracketed: boolean; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index e41502c9e6db7..9c6e82ff0b05f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4702,7 +4702,7 @@ namespace ts { export function getJSDocTypeTag(node: Node): JSDocTypeTag | undefined { // We should have already issued an error if there were multiple type jsdocs, so just use the first one. const tag = getFirstJSDocTag(node, isJSDocTypeTag); - if (tag && tag.typeExpression && tag.typeExpression.type) { + if (tag && tag.type && tag.type.type) { return tag; } return undefined; @@ -4722,10 +4722,10 @@ namespace ts { export function getJSDocType(node: Node): TypeNode | undefined { let tag: JSDocTypeTag | JSDocParameterTag | undefined = getFirstJSDocTag(node, isJSDocTypeTag); if (!tag && isParameter(node)) { - tag = find(getJSDocParameterTags(node), tag => !!tag.typeExpression); + tag = find(getJSDocParameterTags(node), tag => !!tag.type); } - return tag && tag.typeExpression && tag.typeExpression.type; + return tag && tag.type && tag.type.type; } /** @@ -4736,7 +4736,7 @@ namespace ts { */ export function getJSDocReturnType(node: Node): TypeNode | undefined { const returnTag = getJSDocReturnTag(node); - return returnTag && returnTag.typeExpression && returnTag.typeExpression.type; + return returnTag && returnTag.type && returnTag.type.type; } /** Get all JSDoc tags related to a node, including those on parent nodes. */ diff --git a/src/services/classifier.ts b/src/services/classifier.ts index 89c96a45021b9..9b39d3a7c5d34 100644 --- a/src/services/classifier.ts +++ b/src/services/classifier.ts @@ -708,10 +708,10 @@ namespace ts { processJSDocTemplateTag(tag); break; case SyntaxKind.JSDocTypeTag: - processElement((tag).typeExpression); + processElement((tag).type); break; case SyntaxKind.JSDocReturnTag: - processElement((tag).typeExpression); + processElement((tag).type); break; } @@ -732,10 +732,10 @@ namespace ts { pos = tag.name.end; } - if (tag.typeExpression) { - pushCommentRange(pos, tag.typeExpression.pos - pos); - processElement(tag.typeExpression); - pos = tag.typeExpression.end; + if (tag.type) { + pushCommentRange(pos, tag.type.pos - pos); + processElement(tag.type); + pos = tag.type.end; } if (!tag.isNameFirst) { diff --git a/src/services/completions.ts b/src/services/completions.ts index f5aba7f99e8f7..0fba04868e78a 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -817,14 +817,14 @@ namespace ts.Completions { if (tag.tagName.pos <= position && position <= tag.tagName.end) { return { kind: CompletionDataKind.JsDocTagName }; } - if (isTagWithTypeExpression(tag) && tag.typeExpression && tag.typeExpression.kind === SyntaxKind.JSDocTypeExpression) { + if (isTagWithType(tag) && tag.type && tag.type.kind === SyntaxKind.JSDocTypeExpression) { currentToken = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ true); if (!currentToken || (!isDeclarationName(currentToken) && (currentToken.parent.kind !== SyntaxKind.JSDocPropertyTag || (currentToken.parent).name !== currentToken))) { // Use as type location if inside tag's type expression - insideJsDocTagTypeExpression = isCurrentlyEditingNode(tag.typeExpression); + insideJsDocTagTypeExpression = isCurrentlyEditingNode(tag.type); } } if (isJSDocParameterTag(tag) && (nodeIsMissing(tag.name) || tag.name.pos <= position && position <= tag.name.end)) { @@ -1002,9 +1002,9 @@ namespace ts.Completions { const recommendedCompletion = previousToken && getRecommendedCompletion(previousToken, position, sourceFile, typeChecker); return { kind: CompletionDataKind.Data, symbols, completionKind, isInSnippetScope, propertyAccessToConvert, isNewIdentifierLocation, location, keywordFilters, symbolToOriginInfoMap, recommendedCompletion, previousToken, isJsxInitializer }; - type JSDocTagWithTypeExpression = JSDocParameterTag | JSDocPropertyTag | JSDocReturnTag | JSDocTypeTag | JSDocTypedefTag; + type JSDocTagWithType = JSDocParameterTag | JSDocPropertyTag | JSDocReturnTag | JSDocTypeTag | JSDocTypedefTag; - function isTagWithTypeExpression(tag: JSDocTag): tag is JSDocTagWithTypeExpression { + function isTagWithType(tag: JSDocTag): tag is JSDocTagWithType { switch (tag.kind) { case SyntaxKind.JSDocParameterTag: case SyntaxKind.JSDocPropertyTag: diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index ca0dafbc74cb4..cdf42bf8b0ca7 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -96,7 +96,7 @@ namespace ts.JsDoc { case SyntaxKind.JSDocTemplateTag: return withList((tag as JSDocTemplateTag).typeParameters); case SyntaxKind.JSDocTypeTag: - return withNode((tag as JSDocTypeTag).typeExpression); + return withNode((tag as JSDocTypeTag).type); case SyntaxKind.JSDocTypedefTag: case SyntaxKind.JSDocPropertyTag: case SyntaxKind.JSDocParameterTag: