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

Use file and name as key for private type aliases #177

Merged
merged 3 commits into from
Dec 23, 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
7 changes: 5 additions & 2 deletions sphinx_js/js/convertType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,12 @@ class TypeConverter implements TypeVisitor<Type> {
throw new Error("This should not happen");
}
// See if this refers to a private type. In that case we should inline the
// type reflection rather than referring to the non-exported name.
// type reflection rather than referring to the non-exported name. Ideally
// we should key on position rather than name (the same file can have
// multiple private types with the same name potentially). But it doesn't
// seem to be working.
const newTarget = this.symbolToType.get(
`${type.symbolId.fileName}:${type.symbolId.pos}`,
`${type.symbolId.fileName}:${type.name}`,
);
if (newTarget) {
// TODO: this doesn't handle parentheses correctly.
Expand Down
14 changes: 6 additions & 8 deletions sphinx_js/js/redirectPrivateAliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ export function redirectPrivateTypes(app: Application): ReadonlySymbolToType {
const referenced = getReferencedSymbols(owningModule);
return Array.from(referenced).filter((s) => {
const refl = context.project.getReflectionFromSymbol(s);
return !refl || refl.flags.isPrivate;
return (
!refl ||
refl.flags.isPrivate ||
refl?.comment?.modifierTags.has("@hidden")
);
});
}

Expand Down Expand Up @@ -141,15 +145,9 @@ export function redirectPrivateTypes(app: Application): ReadonlySymbolToType {
if (ts.isTypeAliasDeclaration(decl)) {
const sf = decl.getSourceFile();
const fileName = sf.fileName;
const pos = Application.VERSION.startsWith("0.25")
? decl.pos
: decl.getStart();
const converted = context.converter.convertType(context, decl.type);
// Depending on whether we have a symbolId or a reflection in
// renderType we'll use different keys to look this up.
symbolToType.set(`${fileName}:${pos}`, converted);
// Ideally we should be able to key on position rather than file and
// name when the reflection is present but I couldn't figure out how.
// name but I couldn't figure out how.
symbolToType.set(`${fileName}:${decl.name.getText()}`, converted);
}
}
Expand Down
Loading