@@ -4,7 +4,7 @@ import { LogLevel } from "simplr-logger";
44
55import { ApiItem , ApiItemOptions } from "./abstractions/api-item" ;
66
7- import { ApiItemReferenceDictionary } from "./contracts/api-item-reference-dictionary " ;
7+ import { ApiItemReferenceTuple } from "./contracts/api-item-reference-tuple " ;
88import {
99 TypeDto ,
1010 TypeBasicDto ,
@@ -111,18 +111,43 @@ export namespace ApiHelpers {
111111 }
112112
113113 export function ShouldVisit ( declaration : ts . Declaration , options : ApiItemOptions ) : boolean {
114- const declarationFileName = declaration . getSourceFile ( ) . fileName ;
115- if ( PathIsInside ( declarationFileName , options . ExtractorOptions . ProjectDirectory ) ) {
116- return true ;
114+ const declarationSourceFile = declaration . getSourceFile ( ) ;
115+ const declarationFileName = declarationSourceFile . fileName ;
116+
117+ if ( ! PathIsInside ( declarationFileName , options . ExtractorOptions . ProjectDirectory ) ) {
118+ return false ;
117119 }
118- return false ;
120+
121+ if ( options . Program . isSourceFileFromExternalLibrary ( declarationSourceFile ) ) {
122+ return false ;
123+ }
124+
125+ return true ;
126+ }
127+
128+ export function GetItemId ( declaration : ts . Declaration , symbol : ts . Symbol , options : ApiItemOptions ) : string | undefined {
129+ if ( ! ShouldVisit ( declaration , options ) ) {
130+ return undefined ;
131+ }
132+
133+ if ( options . Registry . HasDeclaration ( declaration ) ) {
134+ return options . Registry . GetDeclarationId ( declaration ) ;
135+ }
136+
137+ const resolveRealSymbol = TSHelpers . FollowSymbolAliases ( symbol , options . Program . getTypeChecker ( ) ) ;
138+ const apiItem = VisitApiItem ( declaration , resolveRealSymbol , options ) ;
139+ if ( apiItem == null ) {
140+ return undefined ;
141+ }
142+
143+ return options . AddItemToRegistry ( apiItem ) ;
119144 }
120145
121146 export function GetItemsIdsFromSymbols (
122147 symbols : ts . UnderscoreEscapedMap < ts . Symbol > | undefined ,
123148 options : ApiItemOptions
124- ) : ApiItemReferenceDictionary {
125- const items : ApiItemReferenceDictionary = { } ;
149+ ) : ApiItemReferenceTuple {
150+ const items : ApiItemReferenceTuple = [ ] ;
126151 if ( symbols == null ) {
127152 return items ;
128153 }
@@ -134,27 +159,13 @@ export namespace ApiHelpers {
134159 const symbolItems : string [ ] = [ ] ;
135160
136161 symbol . declarations . forEach ( declaration => {
137- // Check if declaration already exists in the registry.
138- if ( options . Registry . HasDeclaration ( declaration ) ) {
139- const declarationId = options . Registry . GetDeclarationId ( declaration ) ;
140- if ( declarationId == null ) {
141- throw new Error ( `Declaration id cannot be undefined.` ) ;
142- }
143- symbolItems . push ( declarationId ) ;
144- return ;
162+ const itemId = GetItemId ( declaration , symbol , options ) ;
163+ if ( itemId != null ) {
164+ symbolItems . push ( itemId ) ;
145165 }
146-
147- const resolveRealSymbol = TSHelpers . FollowSymbolAliases ( symbol , options . Program . getTypeChecker ( ) ) ;
148-
149- const visitedItem = VisitApiItem ( declaration , resolveRealSymbol , options ) ;
150- if ( visitedItem == null || ! ShouldVisit ( declaration , options ) ) {
151- return ;
152- }
153-
154- symbolItems . push ( options . AddItemToRegistry ( visitedItem ) ) ;
155166 } ) ;
156167
157- items [ symbol . name ] = symbolItems . length === 1 ? symbolItems . toString ( ) : symbolItems ;
168+ items . push ( [ symbol . name , symbolItems ] ) ;
158169 } ) ;
159170
160171 return items ;
@@ -163,38 +174,27 @@ export namespace ApiHelpers {
163174 export function GetItemsIdsFromDeclarations (
164175 declarations : ts . NodeArray < ts . Declaration > ,
165176 options : ApiItemOptions
166- ) : ApiItemReferenceDictionary {
167- const items : ApiItemReferenceDictionary = { } ;
177+ ) : ApiItemReferenceTuple {
178+ const items : ApiItemReferenceTuple = [ ] ;
168179 const typeChecker = options . Program . getTypeChecker ( ) ;
169180
170181 declarations . forEach ( declaration => {
171182 const symbol = TSHelpers . GetSymbolFromDeclaration ( declaration , typeChecker ) ;
172183 if ( symbol == null ) {
173184 return ;
174185 }
175- const name = symbol . name ;
176186
177- let declarationId = options . Registry . GetDeclarationId ( declaration ) ;
178- if ( declarationId == null ) {
179- const resolveRealSymbol = TSHelpers . FollowSymbolAliases ( symbol , options . Program . getTypeChecker ( ) ) ;
180-
181- const visitedItem = VisitApiItem ( declaration , resolveRealSymbol , options ) ;
182- if ( visitedItem == null || ! ShouldVisit ( declaration , options ) ) {
183- return ;
184- }
185-
186- declarationId = options . AddItemToRegistry ( visitedItem ) ;
187+ const itemId = GetItemId ( declaration , symbol , options ) ;
188+ if ( itemId == null ) {
189+ return ;
187190 }
188191
189- if ( items [ name ] == null ) {
190- items [ name ] = declarationId ;
192+ const index = items . findIndex ( x => x != null && x . length === 2 && x [ 0 ] === symbol . name ) ;
193+
194+ if ( index === - 1 ) {
195+ items . push ( [ symbol . name , [ itemId ] ] ) ;
191196 } else {
192- const refs = items [ name ] ;
193- if ( Array . isArray ( refs ) ) {
194- refs . push ( declarationId ) ;
195- } else {
196- items [ name ] = [ refs , declarationId ] ;
197- }
197+ items [ index ] [ 1 ] . push ( itemId ) ;
198198 }
199199 } ) ;
200200
@@ -270,17 +270,7 @@ export namespace ApiHelpers {
270270 if ( symbol . declarations != null && symbol . declarations . length > 0 ) {
271271 const declaration : ts . Declaration = symbol . declarations [ 0 ] ;
272272
273- let declarationId = options . Registry . GetDeclarationId ( declaration ) ;
274-
275- if ( declarationId == null ) {
276- const resolveRealSymbol = TSHelpers . FollowSymbolAliases ( symbol , typeChecker ) ;
277-
278- const apiItem = VisitApiItem ( declaration , resolveRealSymbol , options ) ;
279- if ( apiItem != null ) {
280- declarationId = options . AddItemToRegistry ( apiItem ) ;
281- }
282- }
283-
273+ const declarationId = GetItemId ( declaration , symbol , options ) ;
284274 if ( declarationId != null ) {
285275 return {
286276 ApiTypeKind : TypeKinds . Reference ,
0 commit comments