Skip to content

fix #393 - excludeNotExported with default exports in two statements #431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/lib/converter/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as _ from 'lodash';

import {Application} from '../application';
import {ParameterType} from '../utils/options/declaration';
import {Reflection, Type, ProjectReflection} from '../models/index';
import {Reflection, Type, ProjectReflection, DeclarationReflection} from '../models/index';
import {Context} from './context';
import {ConverterComponent, ConverterNodeComponent, ConverterTypeComponent, TypeTypeConverter, TypeNodeConverter} from './components';
import {CompilerHost} from './utils/compiler-host';
Expand Down Expand Up @@ -374,6 +374,33 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
return [];
}

/**
* prune non-exported reflections from the project
*
* This method is called by the resolve method if excludeNotExported
* is true, and it removes all reflections from the project whose flags.isExported
* is false.
*/
private removeNonExported(project: ProjectReflection): void {
function checkNodes(reflections: DeclarationReflection[]) {
for (let i = reflections.length - 1; i >= 0; --i) {
const node = reflections[i];
if (!node.flags.isExported) {
reflections.splice(i, 1);
delete project.reflections[node.id];
}

if (Array.isArray(node.children)) {
checkNodes(node.children);
}
}
}

if (Array.isArray(project.children)) {
checkNodes(project.children);
}
}

/**
* Resolve the project within the given context.
*
Expand All @@ -384,6 +411,10 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
this.trigger(Converter.EVENT_RESOLVE_BEGIN, context);
const project = context.project;

if (this.excludeNotExported) {
this.removeNonExported(context.project);
}

for (let id in project.reflections) {
if (!project.reflections.hasOwnProperty(id)) {
continue;
Expand Down
4 changes: 0 additions & 4 deletions src/lib/converter/factories/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ export function createDeclaration(context: Context, node: ts.Node, kind: Reflect
isExported = isExported || !!(modifiers & ts.ModifierFlags.Export);
}

if (!isExported && context.converter.excludeNotExported) {
return null;
}

// Test whether the node is private, when inheriting ignore private members
const isPrivate = !!(modifiers & ts.ModifierFlags.Private);
if (context.isInherit && isPrivate) {
Expand Down