@@ -7,36 +7,58 @@ import {ExportDoc} from 'dgeni-packages/typescript/api-doc-types/ExportDoc';
77 *
88 * ```ts
99 * // Some file in @angular /cdk/scrolling
10- * export {ScrollDispatcher} from './scroll-dispatcher.ts ';
10+ * export {ScrollDispatcher} from './scroll-dispatcher';
1111 *
1212 * // Other file in @angular /cdk/overlay
1313 * export {ScrollDispatcher} from '@angular/cdk/scrolling';
14+ *
15+ * // Re-export of the same export with a different name (alias).
16+ * export {ScrollDispatcher as X} from './scroll-dispatcher';
1417 * ```
1518 *
16- * This issue occurs sometimes in the Angular Material repository, if specific imports are
17- * re-exported from a different secondary entry-point (e.g. ScrollDispatcher in the overlay) .
19+ * This issue occurs sometimes in the Angular Material repository, because some imports are
20+ * re-exported with a different name (for deprecation), or from a different secondary entry-point .
1821 */
1922export class FilterDuplicateExports implements Processor {
2023 name = 'filter-duplicate-exports' ;
21- $runBefore = [ 'filter-export-aliases ' ] ;
24+ $runBefore = [ 'categorizer ' ] ;
2225
2326 $process ( docs : DocCollection ) {
24- return docs . forEach ( this . checkForDuplicateExports ) ;
27+ const duplicateDocs = this . findDuplicateExports ( docs ) ;
28+ return docs . filter ( d => ! duplicateDocs . has ( d ) ) ;
2529 }
2630
27- checkForDuplicateExports = ( doc : ExportDoc , index : number , docs : DocCollection ) => {
28- if ( ! ( doc instanceof ExportDoc ) ) {
29- return ;
30- }
31+ findDuplicateExports ( docs : DocCollection ) {
32+ const duplicates = new Set < ExportDoc > ( ) ;
3133
32- // Checks for export documents that have the same name, originate from the same module, but
33- // have a different Dgeni document id. Those documents can be considered as duplicates.
34- const duplicateDocs = docs . filter ( d => doc . name === d . name &&
35- doc . originalModule === d . originalModule && doc . id !== d . id ) ;
34+ docs . forEach ( doc => {
35+ if ( ! ( doc instanceof ExportDoc ) ) {
36+ return ;
37+ }
3638
37- if ( duplicateDocs . length > 0 ) {
38- docs . splice ( index , 1 ) ;
39- }
40- }
39+ // Check for Dgeni documents that refer to the same TypeScript symbol. Those can be
40+ // considered as duplicates of the current document.
41+ const similarDocs = docs . filter ( d => d . symbol === doc . symbol ) ;
42+
43+ if ( similarDocs . length > 1 ) {
44+ // If there are multiple docs that refer to the same TypeScript symbol, but have a
45+ // different name than the resolved symbol, we can remove those documents, since they
46+ // are just aliasing an already existing export.
47+ similarDocs
48+ . filter ( d => d . symbol . name !== d . name )
49+ . forEach ( d => duplicates . add ( d ) ) ;
4150
51+ const docsWithSameName = similarDocs
52+ . filter ( d => d . symbol . name === d . name ) ;
53+
54+ // If there are multiple docs that refer to the same TypeScript symbol and have
55+ // the same name, we need to remove all of those duplicates except one.
56+ if ( docsWithSameName . length > 1 ) {
57+ docsWithSameName . slice ( 1 ) . forEach ( d => duplicates . add ( d ) ) ;
58+ }
59+ }
60+ } ) ;
61+
62+ return duplicates ;
63+ }
4264}
0 commit comments