@@ -235,7 +235,6 @@ import {
235235 GenericType,
236236 GetAccessorDeclaration,
237237 getAliasDeclarationFromName,
238- getAllAccessorDeclarations,
239238 getAllJSDocTags,
240239 getAllowSyntheticDefaultImports,
241240 getAncestor,
@@ -8507,7 +8506,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
85078506 }
85088507
85098508 function getDeclarationWithTypeAnnotation(symbol: Symbol, enclosingDeclaration: Node | undefined) {
8510- return symbol.declarations && find(symbol.declarations, s => !!getEffectiveTypeAnnotationNode (s) && (!enclosingDeclaration || !!findAncestor(s, n => n === enclosingDeclaration)));
8509+ return symbol.declarations && find(symbol.declarations, s => !!getNonlocalEffectiveTypeAnnotationNode (s) && (!enclosingDeclaration || !!findAncestor(s, n => n === enclosingDeclaration)));
85118510 }
85128511
85138512 function existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing: TypeNode, type: Type) {
@@ -8530,7 +8529,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
85308529 const declWithExistingAnnotation = getDeclarationWithTypeAnnotation(symbol, getEnclosingDeclarationIgnoringFakeScope(enclosingDeclaration));
85318530 if (declWithExistingAnnotation && !isFunctionLikeDeclaration(declWithExistingAnnotation) && !isGetAccessorDeclaration(declWithExistingAnnotation)) {
85328531 // try to reuse the existing annotation
8533- const existing = getEffectiveTypeAnnotationNode (declWithExistingAnnotation)!;
8532+ const existing = getNonlocalEffectiveTypeAnnotationNode (declWithExistingAnnotation)!;
85348533 const result = tryReuseExistingTypeNode(context, existing, type, declWithExistingAnnotation, addUndefined, includePrivateSymbol, bundled);
85358534 if (result) {
85368535 return result;
@@ -8583,7 +8582,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
85838582 const typePredicate = getTypePredicateOfSignature(signature);
85848583 const type = getReturnTypeOfSignature(signature);
85858584 if (!isErrorType(type) && context.enclosingDeclaration) {
8586- const annotation = signature.declaration && getEffectiveReturnTypeNode (signature.declaration);
8585+ const annotation = signature.declaration && getNonlocalEffectiveReturnTypeAnnotationNode (signature.declaration);
85878586 const enclosingDeclarationIgnoringFakeScope = getEnclosingDeclarationIgnoringFakeScope(context.enclosingDeclaration);
85888587 if (!!findAncestor(annotation, n => n === enclosingDeclarationIgnoringFakeScope) && annotation) {
85898588 const annotated = getTypeFromTypeNode(annotation);
@@ -48696,6 +48695,22 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4869648695 return isFunctionLike(declaration) || isExportAssignment(declaration) || isVariableLike(declaration);
4869748696 }
4869848697
48698+ function getAllAccessorDeclarationsForDeclaration(accessor: AccessorDeclaration): AllAccessorDeclarations {
48699+ accessor = getParseTreeNode(accessor, isGetOrSetAccessorDeclaration)!; // TODO: GH#18217
48700+ const otherKind = accessor.kind === SyntaxKind.SetAccessor ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor;
48701+ const otherAccessor = getDeclarationOfKind<AccessorDeclaration>(getSymbolOfDeclaration(accessor), otherKind);
48702+ const firstAccessor = otherAccessor && (otherAccessor.pos < accessor.pos) ? otherAccessor : accessor;
48703+ const secondAccessor = otherAccessor && (otherAccessor.pos < accessor.pos) ? accessor : otherAccessor;
48704+ const setAccessor = accessor.kind === SyntaxKind.SetAccessor ? accessor : otherAccessor as SetAccessorDeclaration;
48705+ const getAccessor = accessor.kind === SyntaxKind.GetAccessor ? accessor : otherAccessor as GetAccessorDeclaration;
48706+ return {
48707+ firstAccessor,
48708+ secondAccessor,
48709+ setAccessor,
48710+ getAccessor,
48711+ };
48712+ }
48713+
4869948714 function getPossibleTypeNodeReuseExpression(declaration: DeclarationWithPotentialInnerNodeReuse) {
4870048715 return isFunctionLike(declaration) && !isSetAccessor(declaration)
4870148716 ? getSingleReturnExpression(declaration)
@@ -48704,7 +48719,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4870448719 : !!(declaration as HasInitializer).initializer
4870548720 ? (declaration as HasInitializer & typeof declaration).initializer
4870648721 : isParameter(declaration) && isSetAccessor(declaration.parent)
48707- ? getSingleReturnExpression(getAllAccessorDeclarations(getSymbolOfDeclaration(declaration.parent)?.declarations, declaration.parent).getAccessor)
48722+ ? getSingleReturnExpression(getAllAccessorDeclarationsForDeclaration( declaration.parent).getAccessor)
4870848723 : undefined;
4870948724 }
4871048725
@@ -48894,6 +48909,37 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4889448909 }
4889548910 }
4889648911
48912+ function getNonlocalEffectiveTypeAnnotationNode(node: Node) {
48913+ const direct = getEffectiveTypeAnnotationNode(node);
48914+ if (direct) {
48915+ return direct;
48916+ }
48917+ if (node.kind === SyntaxKind.Parameter && node.parent.kind === SyntaxKind.SetAccessor) {
48918+ const other = getAllAccessorDeclarationsForDeclaration(node.parent as SetAccessorDeclaration).getAccessor;
48919+ if (other) {
48920+ return getEffectiveReturnTypeNode(other);
48921+ }
48922+ }
48923+ return undefined;
48924+ }
48925+
48926+ function getNonlocalEffectiveReturnTypeAnnotationNode(node: SignatureDeclaration | JSDocSignature) {
48927+ const direct = getEffectiveReturnTypeNode(node);
48928+ if (direct) {
48929+ return direct;
48930+ }
48931+ if (node.kind === SyntaxKind.GetAccessor) {
48932+ const other = getAllAccessorDeclarationsForDeclaration(node).setAccessor;
48933+ if (other) {
48934+ const param = getSetAccessorValueParameter(other);
48935+ if (param) {
48936+ return getEffectiveTypeAnnotationNode(param);
48937+ }
48938+ }
48939+ }
48940+ return undefined;
48941+ }
48942+
4889748943 function createResolver(): EmitResolver {
4889848944 return {
4889948945 getReferencedExportContainer,
@@ -48949,21 +48995,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4894948995 },
4895048996 getJsxFactoryEntity,
4895148997 getJsxFragmentFactoryEntity,
48952- getAllAccessorDeclarations(accessor: AccessorDeclaration): AllAccessorDeclarations {
48953- accessor = getParseTreeNode(accessor, isGetOrSetAccessorDeclaration)!; // TODO: GH#18217
48954- const otherKind = accessor.kind === SyntaxKind.SetAccessor ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor;
48955- const otherAccessor = getDeclarationOfKind<AccessorDeclaration>(getSymbolOfDeclaration(accessor), otherKind);
48956- const firstAccessor = otherAccessor && (otherAccessor.pos < accessor.pos) ? otherAccessor : accessor;
48957- const secondAccessor = otherAccessor && (otherAccessor.pos < accessor.pos) ? accessor : otherAccessor;
48958- const setAccessor = accessor.kind === SyntaxKind.SetAccessor ? accessor : otherAccessor as SetAccessorDeclaration;
48959- const getAccessor = accessor.kind === SyntaxKind.GetAccessor ? accessor : otherAccessor as GetAccessorDeclaration;
48960- return {
48961- firstAccessor,
48962- secondAccessor,
48963- setAccessor,
48964- getAccessor,
48965- };
48966- },
4896748998 isBindingCapturedByNode: (node, decl) => {
4896848999 const parseNode = getParseTreeNode(node);
4896949000 const parseDecl = getParseTreeNode(decl);
@@ -49280,7 +49311,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4928049311 }
4928149312 }
4928249313 else if (legacyDecorators && (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor)) {
49283- const accessors = getAllAccessorDeclarations((node.parent as ClassDeclaration).members, node as AccessorDeclaration);
49314+ const accessors = getAllAccessorDeclarationsForDeclaration( node as AccessorDeclaration);
4928449315 if (hasDecorators(accessors.firstAccessor) && node === accessors.secondAccessor) {
4928549316 return grammarErrorOnFirstToken(node, Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name);
4928649317 }
0 commit comments