From 2170f6e1f841f12841cb32c8e5c3c0f5a5b3df32 Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 8 Mar 2018 16:31:42 -0800 Subject: [PATCH] FunctionLike = SignatureDeclaration (#22365) --- src/compiler/checker.ts | 18 +++++++++--------- src/compiler/transformers/ts.ts | 2 +- src/compiler/types.ts | 13 +++---------- src/compiler/utilities.ts | 8 ++++---- .../reference/api/tsserverlibrary.d.ts | 7 ++++--- tests/baselines/reference/api/typescript.d.ts | 7 ++++--- 6 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f3f65bd7f0a..a86f18e4cce 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14110,7 +14110,7 @@ namespace ts { } } - function getContainingObjectLiteral(func: FunctionLike): ObjectLiteralExpression | undefined { + function getContainingObjectLiteral(func: SignatureDeclaration): ObjectLiteralExpression | undefined { return (func.kind === SyntaxKind.MethodDeclaration || func.kind === SyntaxKind.GetAccessor || func.kind === SyntaxKind.SetAccessor) && func.parent.kind === SyntaxKind.ObjectLiteralExpression ? func.parent : @@ -14128,7 +14128,7 @@ namespace ts { }); } - function getContextualThisParameterType(func: FunctionLike): Type { + function getContextualThisParameterType(func: SignatureDeclaration): Type { if (func.kind === SyntaxKind.ArrowFunction) { return undefined; } @@ -14325,7 +14325,7 @@ namespace ts { return false; } - function getContextualReturnType(functionDecl: FunctionLike): Type { + function getContextualReturnType(functionDecl: SignatureDeclaration): Type { // If the containing function has a return type annotation, is a constructor, or is a get accessor whose // corresponding set accessor has a type annotation, return statements in the function are contextually typed if (functionDecl.kind === SyntaxKind.Constructor || @@ -20680,12 +20680,12 @@ namespace ts { let hasOverloads = false; let bodyDeclaration: FunctionLikeDeclaration; let lastSeenNonAmbientDeclaration: FunctionLikeDeclaration; - let previousDeclaration: FunctionLike; + let previousDeclaration: SignatureDeclaration; const declarations = symbol.declarations; const isConstructor = (symbol.flags & SymbolFlags.Constructor) !== 0; - function reportImplementationExpectedError(node: FunctionLike): void { + function reportImplementationExpectedError(node: SignatureDeclaration): void { if (node.name && nodeIsMissing(node.name)) { return; } @@ -20747,7 +20747,7 @@ namespace ts { let duplicateFunctionDeclaration = false; let multipleConstructorImplementation = false; for (const current of declarations) { - const node = current; + const node = current; const inAmbientContext = node.flags & NodeFlags.Ambient; const inAmbientContextOrInterface = node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.TypeLiteral || inAmbientContext; if (inAmbientContextOrInterface) { @@ -22755,12 +22755,12 @@ namespace ts { // TODO: Check that target label is valid } - function isGetAccessorWithAnnotatedSetAccessor(node: FunctionLike) { + function isGetAccessorWithAnnotatedSetAccessor(node: SignatureDeclaration) { return node.kind === SyntaxKind.GetAccessor && getEffectiveSetAccessorTypeAnnotationNode(getDeclarationOfKind(node.symbol, SyntaxKind.SetAccessor)) !== undefined; } - function isUnwrappedReturnTypeVoidOrAny(func: FunctionLike, returnType: Type): boolean { + function isUnwrappedReturnTypeVoidOrAny(func: SignatureDeclaration, returnType: Type): boolean { const unwrappedReturnType = (getFunctionFlags(func) & FunctionFlags.AsyncGenerator) === FunctionFlags.Async ? getPromisedTypeOfPromise(returnType) // Async function : returnType; // AsyncGenerator function, Generator function, or normal function @@ -25481,7 +25481,7 @@ namespace ts { return false; } - function isImplementationOfOverload(node: FunctionLike) { + function isImplementationOfOverload(node: SignatureDeclaration) { if (nodeIsPresent((node as FunctionLikeDeclaration).body)) { const symbol = getSymbolOfNode(node); const signaturesOfSymbol = getSignaturesOfSymbol(symbol); diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 9cd0ab93303..ecde841bedd 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -1780,7 +1780,7 @@ namespace ts { return createArrayLiteral(expressions); } - function getParametersOfDecoratedDeclaration(node: FunctionLike, container: ClassLikeDeclaration) { + function getParametersOfDecoratedDeclaration(node: SignatureDeclaration, container: ClassLikeDeclaration) { if (container && node.kind === SyntaxKind.GetAccessor) { const { setAccessor } = getAllAccessorDeclarations(container.members, node); if (setAccessor) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 8aa700c437f..42d8462cecd 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -967,15 +967,8 @@ namespace ts { | SetAccessorDeclaration | FunctionExpression | ArrowFunction; - export type FunctionLike = - | FunctionLikeDeclaration - | FunctionTypeNode - | ConstructorTypeNode - | IndexSignatureDeclaration - | MethodSignature - | ConstructSignatureDeclaration - | CallSignatureDeclaration - | JSDocFunctionType; + /** @deprecated Use SignatureDeclaration */ + export type FunctionLike = SignatureDeclaration; export interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement { kind: SyntaxKind.FunctionDeclaration; @@ -2856,7 +2849,7 @@ namespace ts { */ getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[], argumentCount?: number): Signature; getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature | undefined; - isImplementationOfOverload(node: FunctionLike): boolean | undefined; + isImplementationOfOverload(node: SignatureDeclaration): boolean | undefined; isUndefinedSymbol(symbol: Symbol): boolean; isArgumentsSymbol(symbol: Symbol): boolean; isUnknownSymbol(symbol: Symbol): boolean; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 44a5f53061b..9cfdc0b80a7 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1035,7 +1035,7 @@ namespace ts { }); } - export function getContainingFunction(node: Node): FunctionLike { + export function getContainingFunction(node: Node): SignatureDeclaration { return findAncestor(node.parent, isFunctionLike); } @@ -1809,7 +1809,7 @@ namespace ts { return parameter && parameter.symbol; } - export function getHostSignatureFromJSDoc(node: JSDocParameterTag): FunctionLike | undefined { + export function getHostSignatureFromJSDoc(node: JSDocParameterTag): SignatureDeclaration | undefined { const host = getJSDocHost(node); const decl = getSourceOfDefaultedAssignment(host) || getSourceOfAssignment(host) || @@ -2144,7 +2144,7 @@ namespace ts { AsyncGenerator = Async | Generator, // Function is an async generator function } - export function getFunctionFlags(node: FunctionLike | undefined) { + export function getFunctionFlags(node: SignatureDeclaration | undefined) { if (!node) { return FunctionFlags.Invalid; } @@ -5309,7 +5309,7 @@ namespace ts { // Functions - export function isFunctionLike(node: Node): node is FunctionLike { + export function isFunctionLike(node: Node): node is SignatureDeclaration { return node && isFunctionLikeKind(node.kind); } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 77e288e79dd..b966ed4b6d1 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -644,7 +644,8 @@ declare namespace ts { body?: Block | Expression; } type FunctionLikeDeclaration = FunctionDeclaration | MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | FunctionExpression | ArrowFunction; - type FunctionLike = FunctionLikeDeclaration | FunctionTypeNode | ConstructorTypeNode | IndexSignatureDeclaration | MethodSignature | ConstructSignatureDeclaration | CallSignatureDeclaration | JSDocFunctionType; + /** @deprecated Use SignatureDeclaration */ + type FunctionLike = SignatureDeclaration; interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement { kind: SyntaxKind.FunctionDeclaration; name?: Identifier; @@ -1801,7 +1802,7 @@ declare namespace ts { */ getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[], argumentCount?: number): Signature; getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature | undefined; - isImplementationOfOverload(node: FunctionLike): boolean | undefined; + isImplementationOfOverload(node: SignatureDeclaration): boolean | undefined; isUndefinedSymbol(symbol: Symbol): boolean; isArgumentsSymbol(symbol: Symbol): boolean; isUnknownSymbol(symbol: Symbol): boolean; @@ -3211,7 +3212,7 @@ declare namespace ts { function isEntityName(node: Node): node is EntityName; function isPropertyName(node: Node): node is PropertyName; function isBindingName(node: Node): node is BindingName; - function isFunctionLike(node: Node): node is FunctionLike; + function isFunctionLike(node: Node): node is SignatureDeclaration; function isClassElement(node: Node): node is ClassElement; function isClassLike(node: Node): node is ClassLikeDeclaration; function isAccessor(node: Node): node is AccessorDeclaration; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 86cae0af609..99a9bd99a60 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -644,7 +644,8 @@ declare namespace ts { body?: Block | Expression; } type FunctionLikeDeclaration = FunctionDeclaration | MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | FunctionExpression | ArrowFunction; - type FunctionLike = FunctionLikeDeclaration | FunctionTypeNode | ConstructorTypeNode | IndexSignatureDeclaration | MethodSignature | ConstructSignatureDeclaration | CallSignatureDeclaration | JSDocFunctionType; + /** @deprecated Use SignatureDeclaration */ + type FunctionLike = SignatureDeclaration; interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement { kind: SyntaxKind.FunctionDeclaration; name?: Identifier; @@ -1801,7 +1802,7 @@ declare namespace ts { */ getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[], argumentCount?: number): Signature; getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature | undefined; - isImplementationOfOverload(node: FunctionLike): boolean | undefined; + isImplementationOfOverload(node: SignatureDeclaration): boolean | undefined; isUndefinedSymbol(symbol: Symbol): boolean; isArgumentsSymbol(symbol: Symbol): boolean; isUnknownSymbol(symbol: Symbol): boolean; @@ -3266,7 +3267,7 @@ declare namespace ts { function isEntityName(node: Node): node is EntityName; function isPropertyName(node: Node): node is PropertyName; function isBindingName(node: Node): node is BindingName; - function isFunctionLike(node: Node): node is FunctionLike; + function isFunctionLike(node: Node): node is SignatureDeclaration; function isClassElement(node: Node): node is ClassElement; function isClassLike(node: Node): node is ClassLikeDeclaration; function isAccessor(node: Node): node is AccessorDeclaration;