-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempt to reuse type parameter constraint nodes #58539
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7459,8 +7459,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
return factory.createTypeParameterDeclaration(modifiers, name, constraintNode, defaultParameterNode); | ||
} | ||
|
||
function typeToTypeNodeHelperWithPossibleReusableTypeNode(type: Type, typeNode: TypeNode | undefined, context: NodeBuilderContext) { | ||
return typeNode && tryReuseExistingNonParameterTypeNode(context, typeNode, type) || typeToTypeNodeHelper(type, context); | ||
} | ||
|
||
function typeParameterToDeclaration(type: TypeParameter, context: NodeBuilderContext, constraint = getConstraintOfTypeParameter(type)): TypeParameterDeclaration { | ||
const constraintNode = constraint && typeToTypeNodeHelper(constraint, context); | ||
const constraintNode = constraint && typeToTypeNodeHelperWithPossibleReusableTypeNode(constraint, getConstraintDeclaration(type), context); | ||
return typeParameterToDeclarationWithConstraint(type, context, constraintNode); | ||
} | ||
|
||
|
@@ -8274,7 +8278,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
sym = resolveEntityName(leftmost, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true); | ||
if ( | ||
context.enclosingDeclaration && | ||
(getNodeLinks(context.enclosingDeclaration).fakeScopeForSignatureDeclaration || !findAncestor(node, n => n === context.enclosingDeclaration)) && | ||
!(sym && sym.flags & SymbolFlags.TypeParameter) | ||
) { | ||
sym = getExportSymbolOfValueSymbolIfExported(sym); | ||
|
@@ -8431,6 +8434,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
} | ||
|
||
function visitExistingNodeTreeSymbolsWorker(node: Node): Node | undefined { | ||
if (isJSDocTypeExpression(node)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The constraint type node for a type parameter declared in jsdoc is a |
||
// Unwrap JSDocTypeExpressions | ||
return visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode); | ||
} | ||
// We don't _actually_ support jsdoc namepath types, emit `any` instead | ||
if (isJSDocAllType(node) || node.kind === SyntaxKind.JSDocNamepathType) { | ||
return factory.createKeywordTypeNode(SyntaxKind.AnyKeyword); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A fourslash test was affected by the code change and made it clear this small change to #58516 was needed - checking that the entity name resolves within the enclosing context is just always required to ensure the name's actually available, not just when there's a fake scope.