@@ -45,6 +45,7 @@ export interface MemberList {
45
45
functions : string [ ] ;
46
46
variables : string [ ] ;
47
47
enums : string [ ] ;
48
+ unknown : string [ ] ;
48
49
}
49
50
/** Contains the dependencies and the size of their code for a single export. */
50
51
export interface ExportData {
@@ -53,6 +54,7 @@ export interface ExportData {
53
54
functions : string [ ] ;
54
55
variables : string [ ] ;
55
56
enums : string [ ] ;
57
+ unknown : string [ ] ;
56
58
externals : { [ key : string ] : string [ ] } ;
57
59
size : number ;
58
60
sizeWithExtDeps : number ;
@@ -141,6 +143,7 @@ export async function extractDependenciesAndSize(
141
143
functions : [ ] ,
142
144
variables : [ ] ,
143
145
enums : [ ] ,
146
+ unknown : [ ] ,
144
147
externals : { } ,
145
148
size : 0 ,
146
149
sizeWithExtDeps : 0
@@ -181,7 +184,8 @@ export function extractAllTopLevelSymbols(filePath: string): MemberList {
181
184
functions : [ ] ,
182
185
classes : [ ] ,
183
186
variables : [ ] ,
184
- enums : [ ]
187
+ enums : [ ] ,
188
+ unknown : [ ]
185
189
} ;
186
190
187
191
ts . forEachChild ( sourceFile , node => {
@@ -238,7 +242,8 @@ export function extractExports(filePath: string): MemberList {
238
242
functions : [ ] ,
239
243
classes : [ ] ,
240
244
variables : [ ] ,
241
- enums : [ ]
245
+ enums : [ ] ,
246
+ unknown : [ ]
242
247
} ;
243
248
244
249
const program = ts . createProgram ( [ filePath ] , {
@@ -275,8 +280,18 @@ export function extractExports(filePath: string): MemberList {
275
280
exportDeclarations . classes . push ( expt . name ) ;
276
281
} else if ( ts . isVariableDeclaration ( sourceDeclaration ) ) {
277
282
exportDeclarations . variables . push ( expt . name ) ;
283
+ } else if ( ts . isEnumDeclaration ( sourceDeclaration ) ) {
284
+ // `const enum`s should not be analyzed. They do not add to bundle size and
285
+ // creating a file that imports them causes an error during the rollup step.
286
+ if (
287
+ // Identifies if this enum had a "const" modifier attached.
288
+ ! sourceDeclaration . modifiers ?. some ( mod => mod . kind === ts . SyntaxKind . ConstKeyword )
289
+ ) {
290
+ exportDeclarations . enums . push ( expt . name ) ;
291
+ }
278
292
} else {
279
- console . log ( 'unhandled export:' , expt . name ) ;
293
+ console . log ( `export of unknown type: ${ expt . name } ` ) ;
294
+ exportDeclarations . unknown . push ( expt . name ) ;
280
295
}
281
296
}
282
297
@@ -306,7 +321,8 @@ export function mapSymbolToType(
306
321
functions : [ ] ,
307
322
classes : [ ] ,
308
323
variables : [ ] ,
309
- enums : [ ]
324
+ enums : [ ] ,
325
+ unknown : [ ]
310
326
} ;
311
327
312
328
for ( const key of Object . keys ( memberList ) as Array < keyof MemberList > ) {
0 commit comments