Skip to content
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

fix: Resolve the name of parameters referring to default exports #2574

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/lib/converter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>
Expand Down
6 changes: 6 additions & 0 deletions src/test/converter2/issues/gh2574/default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Default export and class implementation
*/
export default class DefaultExport {
constructor() {}
}
5 changes: 5 additions & 0 deletions src/test/converter2/issues/gh2574/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Default, NotDefault } from "./reexported";

export function usesDefaultExport(param: Default) {}

export function usesNonDefaultExport(param: NotDefault) {}
3 changes: 3 additions & 0 deletions src/test/converter2/issues/gh2574/notDefault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class NotDefaultExport {
constructor() {}
}
2 changes: 2 additions & 0 deletions src/test/converter2/issues/gh2574/reexported.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as Default } from "./default";
export { NotDefaultExport as NotDefault } from "./notDefault";
36 changes: 36 additions & 0 deletions src/test/issues.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1444,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",
);
});
});
Loading