mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 02:15:10 -05:00
Use jsdoc aliases if visible when printing types (#24153)
* Use jsdoc aliases if visible when printing types * Modify implementation a bit, add test that aughta change in the new future * Accept baselines- hold off on typedef template lookup change
This commit is contained in:
@@ -4024,6 +4024,10 @@ namespace ts {
|
||||
|
||||
function determineIfDeclarationIsVisible() {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
// Top-level jsdoc typedefs are considered exported
|
||||
// First parent is comment node, second is hosting declaration or token; we only care about those tokens or declarations whose parent is a source file
|
||||
return !!(node.parent && node.parent.parent && node.parent.parent.parent && isSourceFile(node.parent.parent.parent));
|
||||
case SyntaxKind.BindingElement:
|
||||
return isDeclarationVisible(node.parent.parent);
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
@@ -5163,8 +5167,8 @@ namespace ts {
|
||||
let result: TypeParameter[];
|
||||
for (const node of symbol.declarations) {
|
||||
if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.ClassDeclaration ||
|
||||
node.kind === SyntaxKind.ClassExpression || node.kind === SyntaxKind.TypeAliasDeclaration) {
|
||||
const declaration = <InterfaceDeclaration | TypeAliasDeclaration>node;
|
||||
node.kind === SyntaxKind.ClassExpression || node.kind === SyntaxKind.TypeAliasDeclaration || node.kind === SyntaxKind.JSDocTypedefTag) {
|
||||
const declaration = <InterfaceDeclaration | TypeAliasDeclaration | JSDocTypedefTag>node;
|
||||
const typeParameters = getEffectiveTypeParameterDeclarations(declaration);
|
||||
if (typeParameters) {
|
||||
result = appendTypeParameters(result, typeParameters);
|
||||
@@ -9046,7 +9050,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getAliasSymbolForTypeNode(node: TypeNode) {
|
||||
return node.parent.kind === SyntaxKind.TypeAliasDeclaration ? getSymbolOfNode(node.parent) : undefined;
|
||||
return (node.parent.kind === SyntaxKind.TypeAliasDeclaration || node.parent.kind === SyntaxKind.JSDocTypedefTag) ? getSymbolOfNode(node.parent) : undefined;
|
||||
}
|
||||
|
||||
function getAliasTypeArgumentsForTypeNode(node: TypeNode) {
|
||||
|
||||
@@ -3093,11 +3093,13 @@ namespace ts {
|
||||
* Gets the effective type parameters. If the node was parsed in a
|
||||
* JavaScript file, gets the type parameters from the `@template` tag from JSDoc.
|
||||
*/
|
||||
export function getEffectiveTypeParameterDeclarations(node: DeclarationWithTypeParameters) {
|
||||
return node.typeParameters || (isInJavaScriptFile(node) ? getJSDocTypeParameterDeclarations(node) : undefined);
|
||||
export function getEffectiveTypeParameterDeclarations(node: DeclarationWithTypeParameters | JSDocTypedefTag) {
|
||||
return isJSDocTypedefTag(node)
|
||||
? getJSDocTypeParameterDeclarations(node)
|
||||
: node.typeParameters || (isInJavaScriptFile(node) ? getJSDocTypeParameterDeclarations(node) : undefined);
|
||||
}
|
||||
|
||||
export function getJSDocTypeParameterDeclarations(node: DeclarationWithTypeParameters) {
|
||||
export function getJSDocTypeParameterDeclarations(node: DeclarationWithTypeParameters | JSDocTypedefTag) {
|
||||
const templateTag = getJSDocTemplateTag(node);
|
||||
return templateTag && templateTag.typeParameters;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user