mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-02 21:33:52 +02:00
Fix duplicated entries in generated API docs (#429)
This commit is contained in:
@@ -127,25 +127,22 @@ const generateDocs = (entryFiles: string[], apiConfigFile: string, dry = false)
|
|||||||
const declaration = exportSymbol.valueDeclaration || exportSymbol.declarations?.[0];
|
const declaration = exportSymbol.valueDeclaration || exportSymbol.declarations?.[0];
|
||||||
if (!declaration) return;
|
if (!declaration) return;
|
||||||
|
|
||||||
// If it's a reexport, follow it recursively
|
// If it's a reexport, resolve it to the underlying symbol (following chains of aliases,
|
||||||
|
// e.g. a re-export of a re-export) rather than recursing into the whole module it lives in
|
||||||
|
// -- `getExportsOfModule` above already gives us one entry per exported symbol, so a module
|
||||||
|
// recursion here would revisit (and duplicate) every other export of that module too.
|
||||||
if (exportSymbol.flags & ts.SymbolFlags.Alias) {
|
if (exportSymbol.flags & ts.SymbolFlags.Alias) {
|
||||||
const aliasedSymbol = typeChecker.getAliasedSymbol(exportSymbol);
|
let aliasedSymbol = typeChecker.getAliasedSymbol(exportSymbol);
|
||||||
|
while (aliasedSymbol.flags & ts.SymbolFlags.Alias) {
|
||||||
|
aliasedSymbol = typeChecker.getAliasedSymbol(aliasedSymbol);
|
||||||
|
}
|
||||||
const aliasedDeclaration = aliasedSymbol.valueDeclaration || aliasedSymbol.declarations?.[0];
|
const aliasedDeclaration = aliasedSymbol.valueDeclaration || aliasedSymbol.declarations?.[0];
|
||||||
if (aliasedDeclaration) {
|
if (aliasedDeclaration) {
|
||||||
const sourceFile = aliasedDeclaration.getSourceFile();
|
// Push the aliased symbol (not the alias) so downstream sees the real
|
||||||
const moduleSymbol = typeChecker.getSymbolAtLocation(sourceFile);
|
// declaration and its JSDoc rather than the empty ExportSpecifier.
|
||||||
// If the aliased declaration lives in a module we've already visited (e.g. a
|
const hasPublicTag = ts.getJSDocTags(aliasedDeclaration).some(tag => tag.tagName.text === 'public');
|
||||||
// same-file `export type { Foo }` re-export of a local declaration), recursing
|
if (hasPublicTag) {
|
||||||
// won't reach it, so add the alias symbol directly. Otherwise follow the reexport.
|
symbols.push(aliasedSymbol);
|
||||||
if (moduleSymbol && !visited.has(moduleSymbol)) {
|
|
||||||
symbols.push(...getAllExportedSymbols(moduleSymbol, visited));
|
|
||||||
} else {
|
|
||||||
// Push the aliased symbol (not the alias) so downstream sees the real
|
|
||||||
// declaration and its JSDoc rather than the empty ExportSpecifier.
|
|
||||||
const hasPublicTag = ts.getJSDocTags(aliasedDeclaration).some(tag => tag.tagName.text === 'public');
|
|
||||||
if (hasPublicTag) {
|
|
||||||
symbols.push(aliasedSymbol);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user