From 0c7d45a9eddcec7ef2bfa1a99208de670db244d2 Mon Sep 17 00:00:00 2001 From: Alex T Date: Tue, 6 Oct 2020 17:51:01 +0300 Subject: [PATCH] fix: change deprecated FunctionLike type to SignatureDeclaration (#40795) --- src/compiler/checker.ts | 2 +- src/compiler/transformers/declarations.ts | 4 ++-- src/compiler/types.ts | 2 +- src/services/codefixes/inferFromUsage.ts | 8 ++++---- src/services/outliningElementsCollector.ts | 4 ++-- src/services/symbolDisplay.ts | 2 +- src/services/textChanges.ts | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8d4bec287a9..d328ed25f54 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2124,7 +2124,7 @@ namespace ts { return isTypeQueryNode(location) || (( isFunctionLikeDeclaration(location) || (location.kind === SyntaxKind.PropertyDeclaration && !hasSyntacticModifier(location, ModifierFlags.Static)) - ) && (!lastLocation || lastLocation !== (location as FunctionLike | PropertyDeclaration).name)); // A name is evaluated within the enclosing scope - so it shouldn't count as deferred + ) && (!lastLocation || lastLocation !== (location as SignatureDeclaration | PropertyDeclaration).name)); // A name is evaluated within the enclosing scope - so it shouldn't count as deferred } if (lastLocation && lastLocation === (location as FunctionExpression | ArrowFunction).name) { return false; diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index af12fbe1925..43539cb06ad 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -14,8 +14,8 @@ namespace ts { export function isInternalDeclaration(node: Node, currentSourceFile: SourceFile) { const parseTreeNode = getParseTreeNode(node); if (parseTreeNode && parseTreeNode.kind === SyntaxKind.Parameter) { - const paramIdx = (parseTreeNode.parent as FunctionLike).parameters.indexOf(parseTreeNode as ParameterDeclaration); - const previousSibling = paramIdx > 0 ? (parseTreeNode.parent as FunctionLike).parameters[paramIdx - 1] : undefined; + const paramIdx = (parseTreeNode.parent as SignatureDeclaration).parameters.indexOf(parseTreeNode as ParameterDeclaration); + const previousSibling = paramIdx > 0 ? (parseTreeNode.parent as SignatureDeclaration).parameters[paramIdx - 1] : undefined; const text = currentSourceFile.text; const commentRanges = previousSibling ? concatenate( diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3bf7ebbdb8d..2c37d20298d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4508,7 +4508,7 @@ namespace ts { isDeclarationVisible(node: Declaration | AnyImportSyntax): boolean; isLateBound(node: Declaration): node is LateBoundDeclaration; collectLinkedAliases(node: Identifier, setVisibility?: boolean): Node[] | undefined; - isImplementationOfOverload(node: FunctionLike): boolean | undefined; + isImplementationOfOverload(node: SignatureDeclaration): boolean | undefined; isRequiredInitializedParameter(node: ParameterDeclaration): boolean; isOptionalUninitializedParameterProperty(node: ParameterDeclaration): boolean; isExpandoFunctionDeclaration(node: FunctionDeclaration): boolean; diff --git a/src/services/codefixes/inferFromUsage.ts b/src/services/codefixes/inferFromUsage.ts index a07153378f5..efad417248a 100644 --- a/src/services/codefixes/inferFromUsage.ts +++ b/src/services/codefixes/inferFromUsage.ts @@ -222,7 +222,7 @@ namespace ts.codefix { importAdder: ImportAdder, sourceFile: SourceFile, parameterDeclaration: ParameterDeclaration, - containingFunction: FunctionLike, + containingFunction: SignatureDeclaration, program: Program, host: LanguageServiceHost, cancellationToken: CancellationToken, @@ -268,7 +268,7 @@ namespace ts.codefix { } } - function annotateJSDocThis(changes: textChanges.ChangeTracker, sourceFile: SourceFile, containingFunction: FunctionLike, typeNode: TypeNode) { + function annotateJSDocThis(changes: textChanges.ChangeTracker, sourceFile: SourceFile, containingFunction: SignatureDeclaration, typeNode: TypeNode) { addJSDocTags(changes, sourceFile, containingFunction, [ factory.createJSDocThisTag(/*tagName*/ undefined, factory.createJSDocTypeExpression(typeNode)), ]); @@ -409,7 +409,7 @@ namespace ts.codefix { })); } - function getFunctionReferences(containingFunction: FunctionLike, sourceFile: SourceFile, program: Program, cancellationToken: CancellationToken): readonly Identifier[] | undefined { + function getFunctionReferences(containingFunction: SignatureDeclaration, sourceFile: SourceFile, program: Program, cancellationToken: CancellationToken): readonly Identifier[] | undefined { let searchToken; switch (containingFunction.kind) { case SyntaxKind.Constructor: @@ -534,7 +534,7 @@ namespace ts.codefix { return combineTypes(inferTypesFromReferencesSingle(references)); } - function parameters(declaration: FunctionLike): ParameterInference[] | undefined { + function parameters(declaration: SignatureDeclaration): ParameterInference[] | undefined { if (references.length === 0 || !declaration.parameters) { return undefined; } diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 0baacad43bf..4f755aebca6 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -288,7 +288,7 @@ namespace ts.OutliningElementsCollector { } } - function functionSpan(node: FunctionLike, body: Block, sourceFile: SourceFile): OutliningSpan | undefined { + function functionSpan(node: SignatureDeclaration, body: Block, sourceFile: SourceFile): OutliningSpan | undefined { const openToken = tryGetFunctionOpenToken(node, body, sourceFile); const closeToken = findChildOfKind(body, SyntaxKind.CloseBraceToken, sourceFile); return openToken && closeToken && spanBetweenTokens(openToken, closeToken, node, sourceFile, /*autoCollapse*/ node.kind !== SyntaxKind.ArrowFunction); @@ -303,7 +303,7 @@ namespace ts.OutliningElementsCollector { return { textSpan, kind, hintSpan, bannerText, autoCollapse }; } - function tryGetFunctionOpenToken(node: FunctionLike, body: Block, sourceFile: SourceFile): Node | undefined { + function tryGetFunctionOpenToken(node: SignatureDeclaration, body: Block, sourceFile: SourceFile): Node | undefined { if (isNodeArrayMultiLine(node.parameters, sourceFile)) { const openParenToken = findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile); if (openParenToken) { diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index d62be264903..65543399c30 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -236,7 +236,7 @@ namespace ts.SymbolDisplay { else if ((isNameOfFunctionDeclaration(location) && !(symbolFlags & SymbolFlags.Accessor)) || // name of function declaration (location.kind === SyntaxKind.ConstructorKeyword && location.parent.kind === SyntaxKind.Constructor)) { // At constructor keyword of constructor declaration // get the signature from the declaration and write it - const functionDeclaration = location.parent; + const functionDeclaration = location.parent; // Use function declaration to write the signatures only if the symbol corresponding to this declaration const locationIsSymbolDeclaration = symbol.declarations && find(symbol.declarations, declaration => declaration === (location.kind === SyntaxKind.ConstructorKeyword ? functionDeclaration.parent : functionDeclaration)); diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index c1ef8e82b08..17f5ee4adf6 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -254,7 +254,7 @@ namespace ts.textChanges { export type ThisTypeAnnotatable = FunctionDeclaration | FunctionExpression; - export function isThisTypeAnnotatable(containingFunction: FunctionLike): containingFunction is ThisTypeAnnotatable { + export function isThisTypeAnnotatable(containingFunction: SignatureDeclaration): containingFunction is ThisTypeAnnotatable { return isFunctionExpression(containingFunction) || isFunctionDeclaration(containingFunction); }