diff --git a/src/lib/converter/types.ts b/src/lib/converter/types.ts index 01b88154f..1fbf9478e 100644 --- a/src/lib/converter/types.ts +++ b/src/lib/converter/types.ts @@ -743,9 +743,17 @@ const referenceConverter: TypeConverter< return ref; } + let name; + if (ts.isIdentifier(node.typeName)) { + name = node.typeName.text; + } else { + name = node.typeName.right.text; + } + const ref = ReferenceType.createSymbolReference( context.resolveAliasedSymbol(symbol), context, + name, ); if (type.flags & ts.TypeFlags.Substitution) { // NoInfer diff --git a/src/lib/models/types.ts b/src/lib/models/types.ts index be93044d5..be49d3a91 100644 --- a/src/lib/models/types.ts +++ b/src/lib/models/types.ts @@ -907,39 +907,11 @@ export class ReferenceType extends Type { return new ReferenceType(name, target, project, name); } - /** - * In certain cases, TypeScript returns the name `default` for the name of a type that is defined with - * the format `export default class` or `export default function`. This method checks for that case and returns the - * declaration of the export instead of the name `default`. - */ - private static getNameForDefaultExport( - symbol: ts.Symbol, - ): string | undefined { - if ( - symbol.name !== "default" || - symbol.valueDeclaration === undefined - ) { - return; - } - - const name = ts.getNameOfDeclaration(symbol.valueDeclaration); - - if (!name) { - return; - } - - if (ts.isIdentifier(name)) { - return name.text; - } - } - static createSymbolReference( symbol: ts.Symbol, context: Context, name?: string, ) { - name ??= this.getNameForDefaultExport(symbol); - const ref = new ReferenceType( name ?? symbol.name, new ReflectionSymbolId(symbol), diff --git a/src/test/converter2/issues/gh2574/index.ts b/src/test/converter2/issues/gh2574/index.ts index 2fb7153e0..5f521cb67 100644 --- a/src/test/converter2/issues/gh2574/index.ts +++ b/src/test/converter2/issues/gh2574/index.ts @@ -1,3 +1,5 @@ -import { Default } from "./reexported"; +import { Default, NotDefault } from "./reexported"; export function usesDefaultExport(param: Default) {} + +export function usesNonDefaultExport(param: NotDefault) {} diff --git a/src/test/converter2/issues/gh2574/notDefault.ts b/src/test/converter2/issues/gh2574/notDefault.ts new file mode 100644 index 000000000..d2482e2c0 --- /dev/null +++ b/src/test/converter2/issues/gh2574/notDefault.ts @@ -0,0 +1,3 @@ +export class NotDefaultExport { + constructor() {} +} diff --git a/src/test/converter2/issues/gh2574/reexported.ts b/src/test/converter2/issues/gh2574/reexported.ts index 65fe0b80b..f09daf171 100644 --- a/src/test/converter2/issues/gh2574/reexported.ts +++ b/src/test/converter2/issues/gh2574/reexported.ts @@ -1 +1,2 @@ export { default as Default } from "./default"; +export { NotDefaultExport as NotDefault } from "./notDefault"; diff --git a/src/test/issues.c2.test.ts b/src/test/issues.c2.test.ts index 057b04767..ee25c0266 100644 --- a/src/test/issues.c2.test.ts +++ b/src/test/issues.c2.test.ts @@ -15,7 +15,6 @@ import { ProjectReflection, QueryType, ReferenceReflection, - ReferenceType, ReflectionKind, ReflectionType, SignatureReflection, @@ -92,21 +91,6 @@ describe("Issue Tests", () => { ); }); - it("#2574", () => { - const project = convert(); - const usesDefaultExport = query(project, "usesDefaultExport"); - const sig = usesDefaultExport.signatures?.[0]; - ok(sig, "Missing signature for usesDefaultExport"); - const param = sig.parameters?.[0]; - ok(param, "Missing parameter"); - equal(param.name, "param", "Incorrect parameter name"); - const paramType = param.type as ReferenceType | undefined; - ok(paramType, "Parameter type is not a reference type or undefined"); - equal(paramType.type, "reference", "Parameter is not a reference type"); - equal(paramType.name, "DefaultExport", "Incorrect reference name"); - equal(paramType.qualifiedName, "default", "Incorrect qualified name"); - }); - it("#671", () => { const project = convert(); const toNumber = query(project, "toNumber"); @@ -1460,4 +1444,40 @@ describe("Issue Tests", () => { app.validate(project); logger.expectNoOtherMessages(); }); + + it("#2574 default export", () => { + const project = convert(); + const sig = querySig(project, "usesDefaultExport"); + const param = sig.parameters?.[0]; + ok(param, "Missing parameter"); + equal(param.name, "param", "Incorrect parameter name"); + ok(param.type, "Parameter type is not a reference type or undefined"); + equal( + param.type!.type, + "reference", + "Parameter is not a reference type", + ); + equal(param.type!.name, "DefaultExport", "Incorrect reference name"); + equal(param.type!.qualifiedName, "default", "Incorrect qualified name"); + }); + + it("#2574 not default export", () => { + const project = convert(); + const sig = querySig(project, "usesNonDefaultExport"); + const param = sig.parameters?.[0]; + ok(param, "Missing parameter"); + equal(param.name, "param", "Incorrect parameter name"); + ok(param.type, "Parameter type is not a reference type or undefined"); + equal( + param.type!.type, + "reference", + "Parameter is not a reference type", + ); + equal(param.type!.name, "NotDefaultExport", "Incorrect reference name"); + equal( + param.type!.qualifiedName, + "NotDefaultExport", + "Incorrect qualified name", + ); + }); });