Skip to content

Commit

Permalink
Use file and name as key for private type aliases (#177)
Browse files Browse the repository at this point in the history
It's probably better to use the position as the key but since 0.26.0 it
doesn't seem to work correctly. This also redirects aliases that are marked
as `@hidden`
  • Loading branch information
hoodmane authored Dec 23, 2024
1 parent 52f13eb commit 6b206b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
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

0 comments on commit 6b206b0

Please sign in to comment.