Skip to content

Commit 3809469

Browse files
committed
fix excludeNotExported with default exports
Fix issue where default exports are separated across two statements such as ``` const foo = {}; export default foo; ``` * remove the short-circuit in the declaration factory so all reflections exist after converter#convert is run * in converter#resolve, add check for excludeNotExported and then prune the references list and children in the project structure whose isExported flag is false fixes TypeStrong#393
1 parent 026cb81 commit 3809469

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/lib/converter/converter.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as _ from "lodash";
55

66
import {Application} from "../application";
77
import {ParameterType} from "../utils/options/declaration";
8-
import {Reflection, Type, ProjectReflection} from "../models/index";
8+
import {Reflection, Type, ProjectReflection, DeclarationReflection} from "../models/index";
99
import {Context} from "./context";
1010
import {ConverterComponent, ConverterNodeComponent, ConverterTypeComponent, ITypeTypeConverter, ITypeNodeConverter} from "./components";
1111
import {CompilerHost} from "./utils/compiler-host";
@@ -441,6 +441,33 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
441441
return [];
442442
}
443443

444+
/**
445+
* prune non-exported reflections from the project
446+
*
447+
* This method is called by the resolve method if excludeNotExported
448+
* is true, and it removes all reflections from the project whose flags.isExported
449+
* is false.
450+
*/
451+
private removeNonExported(project: ProjectReflection): void {
452+
function checkNodes(reflections: DeclarationReflection[]) {
453+
for (let i = reflections.length - 1; i >= 0; --i) {
454+
const node = reflections[i];
455+
if (!node.flags.isExported) {
456+
reflections.splice(i, 1);
457+
delete project.reflections[node.id];
458+
}
459+
460+
if (Array.isArray(node.children)) {
461+
checkNodes(node.children);
462+
}
463+
}
464+
}
465+
466+
if (Array.isArray(project.children)) {
467+
checkNodes(project.children);
468+
}
469+
}
470+
444471

445472
/**
446473
* Resolve the project within the given context.
@@ -452,6 +479,10 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
452479
this.trigger(Converter.EVENT_RESOLVE_BEGIN, context);
453480
const project = context.project;
454481

482+
if (this.excludeNotExported) {
483+
this.removeNonExported(context.project);
484+
}
485+
455486
for (let id in project.reflections) {
456487
if (!project.reflections.hasOwnProperty(id)) continue;
457488
this.trigger(Converter.EVENT_RESOLVE, context, project.reflections[id]);

src/lib/converter/factories/declaration.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ export function createDeclaration(context:Context, node:ts.Node, kind:Reflection
6262
isExported = isExported || !!(modifiers & ts.ModifierFlags.Export);
6363
}
6464

65-
if (!isExported && context.converter.excludeNotExported) {
66-
return null;
67-
}
68-
6965
// Test whether the node is private, when inheriting ignore private members
7066
const isPrivate = !!(modifiers & ts.ModifierFlags.Private);
7167
if (context.isInherit && isPrivate) {

0 commit comments

Comments
 (0)