Skip to content

Commit 0cdcd29

Browse files
committed
address comments and add another test case
1 parent 3204c93 commit 0cdcd29

File tree

6 files changed

+51
-44
lines changed

6 files changed

+51
-44
lines changed

src/lib/converter/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,17 @@ const referenceConverter: TypeConverter<
743743
return ref;
744744
}
745745

746+
let name;
747+
if (ts.isIdentifier(node.typeName)) {
748+
name = node.typeName.text;
749+
} else {
750+
name = node.typeName.right.text;
751+
}
752+
746753
const ref = ReferenceType.createSymbolReference(
747754
context.resolveAliasedSymbol(symbol),
748755
context,
756+
name,
749757
);
750758
if (type.flags & ts.TypeFlags.Substitution) {
751759
// NoInfer<T>

src/lib/models/types.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -907,39 +907,11 @@ export class ReferenceType extends Type {
907907
return new ReferenceType(name, target, project, name);
908908
}
909909

910-
/**
911-
* In certain cases, TypeScript returns the name `default` for the name of a type that is defined with
912-
* the format `export default class` or `export default function`. This method checks for that case and returns the
913-
* declaration of the export instead of the name `default`.
914-
*/
915-
private static getNameForDefaultExport(
916-
symbol: ts.Symbol,
917-
): string | undefined {
918-
if (
919-
symbol.name !== "default" ||
920-
symbol.valueDeclaration === undefined
921-
) {
922-
return;
923-
}
924-
925-
const name = ts.getNameOfDeclaration(symbol.valueDeclaration);
926-
927-
if (!name) {
928-
return;
929-
}
930-
931-
if (ts.isIdentifier(name)) {
932-
return name.text;
933-
}
934-
}
935-
936910
static createSymbolReference(
937911
symbol: ts.Symbol,
938912
context: Context,
939913
name?: string,
940914
) {
941-
name ??= this.getNameForDefaultExport(symbol);
942-
943915
const ref = new ReferenceType(
944916
name ?? symbol.name,
945917
new ReflectionSymbolId(symbol),
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
import { Default } from "./reexported";
1+
import { Default, NotDefault } from "./reexported";
22

33
export function usesDefaultExport(param: Default) {}
4+
5+
export function usesNonDefaultExport(param: NotDefault) {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export class NotDefaultExport {
2+
constructor() {}
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default as Default } from "./default";
2+
export { NotDefaultExport as NotDefault } from "./notDefault";

src/test/issues.c2.test.ts

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
ProjectReflection,
1616
QueryType,
1717
ReferenceReflection,
18-
ReferenceType,
1918
ReflectionKind,
2019
ReflectionType,
2120
SignatureReflection,
@@ -92,20 +91,6 @@ describe("Issue Tests", () => {
9291
);
9392
});
9493

95-
it("#2574", () => {
96-
const project = convert();
97-
const usesDefaultExport = query(project, "usesDefaultExport");
98-
const sig = usesDefaultExport.signatures?.[0];
99-
ok(sig, "Missing signature for usesDefaultExport");
100-
const param = sig.parameters?.[0];
101-
ok(param, "Missing parameter");
102-
equal(param.name, "param", "Incorrect parameter name");
103-
const paramType = param.type as ReferenceType | undefined;
104-
ok(paramType, "Parameter type is not a reference type or undefined");
105-
equal(paramType.type, "reference", "Parameter is not a reference type");
106-
equal(paramType.name, "DefaultExport", "Incorrect reference name");
107-
equal(paramType.qualifiedName, "default", "Incorrect qualified name");
108-
});
10994

11095
it("#671", () => {
11196
const project = convert();
@@ -1460,4 +1445,40 @@ describe("Issue Tests", () => {
14601445
app.validate(project);
14611446
logger.expectNoOtherMessages();
14621447
});
1448+
1449+
it("#2574 default export", () => {
1450+
const project = convert();
1451+
const sig = querySig(project, "usesDefaultExport");
1452+
const param = sig.parameters?.[0];
1453+
ok(param, "Missing parameter");
1454+
equal(param.name, "param", "Incorrect parameter name");
1455+
ok(param.type, "Parameter type is not a reference type or undefined");
1456+
equal(
1457+
param.type!.type,
1458+
"reference",
1459+
"Parameter is not a reference type",
1460+
);
1461+
equal(param.type!.name, "Default", "Incorrect reference name");
1462+
equal(param.type!.qualifiedName, "default", "Incorrect qualified name");
1463+
});
1464+
1465+
it("#2574 not default export", () => {
1466+
const project = convert();
1467+
const sig = querySig(project, "usesNonDefaultExport");
1468+
const param = sig.parameters?.[0];
1469+
ok(param, "Missing parameter");
1470+
equal(param.name, "param", "Incorrect parameter name");
1471+
ok(param.type, "Parameter type is not a reference type or undefined");
1472+
equal(
1473+
param.type!.type,
1474+
"reference",
1475+
"Parameter is not a reference type",
1476+
);
1477+
equal(param.type!.name, "NotDefault", "Incorrect reference name");
1478+
equal(
1479+
param.type!.qualifiedName,
1480+
"NotDefault",
1481+
"Incorrect qualified name",
1482+
);
1483+
});
14631484
});

0 commit comments

Comments
 (0)