diff --git a/src/lib/converter/converter.ts b/src/lib/converter/converter.ts index ccefb04cc..87366aa3b 100644 --- a/src/lib/converter/converter.ts +++ b/src/lib/converter/converter.ts @@ -303,7 +303,7 @@ export class Converter extends ChildableComponent< entryPoints: readonly string[], entryName: string ) { - const symbol = context.checker.getSymbolAtLocation(node) ?? node.symbol; + const symbol = getSymbolForModuleLike(context, node); let moduleContext: Context; if (entryPoints.length === 1) { @@ -320,7 +320,7 @@ export class Converter extends ChildableComponent< moduleContext = context.withScope(reflection); } - for (const exp of getExports(context, node).filter((exp) => + for (const exp of getExports(context, node, symbol).filter((exp) => isDirectExport(context.resolveAliasedSymbol(exp), node) )) { convertSymbol(moduleContext, exp); @@ -330,7 +330,11 @@ export class Converter extends ChildableComponent< } private convertReExports(moduleContext: Context, node: ts.SourceFile) { - for (const exp of getExports(moduleContext, node).filter( + for (const exp of getExports( + moduleContext, + node, + moduleContext.project.getSymbolFromReflection(moduleContext.scope) + ).filter( (exp) => !isDirectExport(moduleContext.resolveAliasedSymbol(exp), node) )) { @@ -399,24 +403,14 @@ function getModuleName(fileName: string, baseDir: string) { ); } -function getExports( +function getSymbolForModuleLike( context: Context, node: ts.SourceFile | ts.ModuleBlock -): ts.Symbol[] { - let symbol = context.checker.getSymbolAtLocation(node) ?? node.symbol; - if (!symbol && ts.isModuleBlock(node)) { - symbol = context.checker.getSymbolAtLocation(node.parent.name); - } - - // The generated docs aren't great, but you really ought not be using - // this in the first place... so it's better than nothing. - const exportEq = symbol?.exports?.get("export=" as ts.__String); - if (exportEq) { - return [exportEq]; - } +) { + const symbol = context.checker.getSymbolAtLocation(node) ?? node.symbol; if (symbol) { - return context.checker.getExportsOfModule(symbol); + return symbol; } // This is a global file, get all symbols declared in this file... @@ -430,7 +424,7 @@ function getExports( ); // Detect declaration files with declare module "foo" as their only export - // and lift that up one level + // and lift that up one level as the source file symbol if ( globalSymbols.length === 1 && globalSymbols[0] @@ -441,8 +435,35 @@ function getExports( ts.isStringLiteral(declaration.name) ) ) { - return context.checker.getExportsOfModule(globalSymbols[0]); + return globalSymbols[0]; } +} + +function getExports( + context: Context, + node: ts.SourceFile | ts.ModuleBlock, + symbol: ts.Symbol | undefined +): ts.Symbol[] { + // The generated docs aren't great, but you really ought not be using + // this in the first place... so it's better than nothing. + const exportEq = symbol?.exports?.get("export=" as ts.__String); + if (exportEq) { + return [exportEq]; + } + + if (symbol) { + return context.checker + .getExportsOfModule(symbol) + .filter((s) => !hasFlag(s.flags, ts.SymbolFlags.Prototype)); + } + + // Global file with no inferred top level symbol, get all symbols declared in this file. + const sourceFile = node.getSourceFile(); + const globalSymbols = context.checker + .getSymbolsInScope(node, ts.SymbolFlags.ModuleMember) + .filter((s) => + s.getDeclarations()?.some((d) => d.getSourceFile() === sourceFile) + ); return globalSymbols; } diff --git a/src/lib/converter/symbols.ts b/src/lib/converter/symbols.ts index 4470c30c5..622c702f9 100644 --- a/src/lib/converter/symbols.ts +++ b/src/lib/converter/symbols.ts @@ -478,8 +478,6 @@ function convertProperty( nameOverride?: string ) { const declarations = symbol.getDeclarations() ?? []; - const parentSymbol = context.project.getSymbolFromReflection(context.scope); - assert(parentSymbol); // Don't do anything if we inherited this property and it is private. if ( diff --git a/src/test/converter/class/specs-with-lump-categories.json b/src/test/converter/class/specs-with-lump-categories.json index 215fb1f8d..36533b35a 100644 --- a/src/test/converter/class/specs-with-lump-categories.json +++ b/src/test/converter/class/specs-with-lump-categories.json @@ -906,12 +906,12 @@ ], "categories": [ { - "title": "AnotherTest", - "children": [ - 32, - 30, - 28 - ] + "title": "AnotherTest", + "children": [ + 32, + 30, + 28 + ] }, { "title": "Other", @@ -3553,4 +3553,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/src/test/converter/class/specs.json b/src/test/converter/class/specs.json index d16ebebe2..fe758782f 100644 --- a/src/test/converter/class/specs.json +++ b/src/test/converter/class/specs.json @@ -904,12 +904,12 @@ ], "categories": [ { - "title": "AnotherTest", - "children": [ - 32, - 30, - 28 - ] + "title": "AnotherTest", + "children": [ + 32, + 30, + 28 + ] }, { "title": "Other", @@ -3549,4 +3549,4 @@ ] } ] -} +} \ No newline at end of file