@@ -7,36 +7,58 @@ import {ExportDoc} from 'dgeni-packages/typescript/api-doc-types/ExportDoc';
7
7
*
8
8
* ```ts
9
9
* // Some file in @angular /cdk/scrolling
10
- * export {ScrollDispatcher} from './scroll-dispatcher.ts ';
10
+ * export {ScrollDispatcher} from './scroll-dispatcher';
11
11
*
12
12
* // Other file in @angular /cdk/overlay
13
13
* 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';
14
17
* ```
15
18
*
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 .
18
21
*/
19
22
export class FilterDuplicateExports implements Processor {
20
23
name = 'filter-duplicate-exports' ;
21
- $runBefore = [ 'filter-export-aliases ' ] ;
24
+ $runBefore = [ 'categorizer ' ] ;
22
25
23
26
$process ( docs : DocCollection ) {
24
- return docs . forEach ( this . checkForDuplicateExports ) ;
27
+ const duplicateDocs = this . findDuplicateExports ( docs ) ;
28
+ return docs . filter ( d => ! duplicateDocs . has ( d ) ) ;
25
29
}
26
30
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 > ( ) ;
31
33
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
+ }
36
38
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 ) ) ;
41
50
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
+ }
42
64
}
0 commit comments