Skip to content

docs: simplify filtering of alias exports #9893

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

Merged
merged 1 commit into from
Feb 13, 2018
Merged
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
31 changes: 7 additions & 24 deletions tools/dgeni/processors/filter-export-aliases.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {DocCollection, Processor} from 'dgeni';
import {ExportDoc} from 'dgeni-packages/typescript/api-doc-types/ExportDoc';
import {ModuleDoc} from 'dgeni-packages/typescript/api-doc-types/ModuleDoc';

/**
* Processor to filter out Dgeni documents that are export aliases. Keeping them means
Expand All @@ -22,27 +20,12 @@ export class FilterExportAliases implements Processor {
$runBefore = ['categorizer'];

$process(docs: DocCollection) {
return docs.filter(doc => this.filterAliasExport(doc));
return docs.filter(doc => {
// If the alias symbol and the actual resolved symbol have the same name, then this doc
// shouldn't be filtered. This check is necessary, because technically as per TypeScript,
// explicit and individual re-exports are being considered as aliases.
// For example: export {Test} from './my-file`;
return !(doc.aliasSymbol && doc.aliasSymbol.name !== doc.symbol.name);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could have been made without the parentheses, but I wanted to make clear what is considered a aliased export.

});
}

private filterAliasExport(doc: ExportDoc) {
if (!doc.moduleDoc) {
return true;
}

const moduleDoc = doc.moduleDoc as ModuleDoc;
const duplicateDocs = moduleDoc.exports.filter(exportDoc => exportDoc.id === doc.id);

// Remove the current export document if there are multiple Dgeni export documents with the
// same document id. If there are multiple docs with the same id, we can assume that this doc
// is an alias export.
if (duplicateDocs && duplicateDocs.length > 1) {
moduleDoc.exports.splice(
moduleDoc.exports.findIndex(exportDoc => exportDoc.id === doc.id), 1);
return false;
}

return true;
}

}