From 8a5a933ecce8f79679415a11ddd66ae2c5d682c4 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Thu, 24 Jun 2021 21:06:47 -0600 Subject: [PATCH] fix: Exclude empty modules from documentation Closes #1607 --- src/lib/application.ts | 8 +++++--- src/lib/converter/converter.ts | 20 ++++++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/lib/application.ts b/src/lib/application.ts index 37d4f46a9..9e6e7b465 100644 --- a/src/lib/application.ts +++ b/src/lib/application.ts @@ -332,10 +332,12 @@ export class Application extends ChildableComponent< entryPoints.push(...this.getEntryPointsForPaths(this.entryPoints)); } - const programs = entryPoints.map((e) => e.program); - this.logger.verbose(`Converting with ${programs.length} programs`); + const programs = new Set(entryPoints.map((e) => e.program)); + this.logger.verbose( + `Converting with ${programs.size} programs and ${entryPoints.length} entry points` + ); - const errors = flatMap(programs, ts.getPreEmitDiagnostics); + const errors = flatMap([...programs], ts.getPreEmitDiagnostics); if (errors.length) { this.logger.diagnostics(errors); return; diff --git a/src/lib/converter/converter.ts b/src/lib/converter/converter.ts index da9d15c98..8d8caf86e 100644 --- a/src/lib/converter/converter.ts +++ b/src/lib/converter/converter.ts @@ -1,6 +1,5 @@ import * as ts from "typescript"; import * as _ from "lodash"; -import * as assert from "assert"; import { Application } from "../application"; import { Type, ProjectReflection, ReflectionKind } from "../models/index"; @@ -283,8 +282,10 @@ export class Converter extends ChildableComponent< }); for (const { entryPoint, context } of entries) { // active program is already set on context - assert(context); - this.convertReExports(context, entryPoint.sourceFile); + // if we don't have a context, then this entry point is being ignored + if (context) { + this.convertReExports(context, entryPoint.sourceFile); + } } context.setActiveProgram(undefined); } @@ -298,6 +299,17 @@ export class Converter extends ChildableComponent< const symbol = getSymbolForModuleLike(context, node); let moduleContext: Context; + const allExports = getExports(context, node, symbol); + + if ( + allExports.every((exp) => this.shouldIgnore(exp, context.checker)) + ) { + this.owner.logger.verbose( + `Ignoring entry point ${entryName} since all members will be ignored.` + ); + return; + } + if (singleEntryPoint) { // Special case for when we're giving a single entry point, we don't need to // create modules for each entry. Register the project as this module. @@ -324,7 +336,7 @@ export class Converter extends ChildableComponent< moduleContext = context.withScope(reflection); } - for (const exp of getExports(context, node, symbol).filter((exp) => + for (const exp of allExports.filter((exp) => isDirectExport(context.resolveAliasedSymbol(exp), node) )) { convertSymbol(moduleContext, exp);