mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
docs(dgeni): simplify filtering of alias exports (#9893)
Simplifies the processor that filters alias exports. This is now possible with https://github.com/angular/dgeni-packages/commit/f7034143390293f908cd94ca424fcf9420653d70
This commit is contained in:
committed by
Jeremy Elbourn
parent
f6c1b9a3a5
commit
47ab3367b9
@@ -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
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user