Skip to content

Commit 2bc0bf0

Browse files
committed
fix tests
1 parent 5275e18 commit 2bc0bf0

File tree

4 files changed

+513
-502
lines changed

4 files changed

+513
-502
lines changed

repo-scripts/size-analysis/analysis-helper.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export interface MemberList {
4545
functions: string[];
4646
variables: string[];
4747
enums: string[];
48+
unknown: string[];
4849
}
4950
/** Contains the dependencies and the size of their code for a single export. */
5051
export interface ExportData {
@@ -53,6 +54,7 @@ export interface ExportData {
5354
functions: string[];
5455
variables: string[];
5556
enums: string[];
57+
unknown: string[];
5658
externals: { [key: string]: string[] };
5759
size: number;
5860
sizeWithExtDeps: number;
@@ -141,6 +143,7 @@ export async function extractDependenciesAndSize(
141143
functions: [],
142144
variables: [],
143145
enums: [],
146+
unknown: [],
144147
externals: {},
145148
size: 0,
146149
sizeWithExtDeps: 0
@@ -181,7 +184,8 @@ export function extractAllTopLevelSymbols(filePath: string): MemberList {
181184
functions: [],
182185
classes: [],
183186
variables: [],
184-
enums: []
187+
enums: [],
188+
unknown: []
185189
};
186190

187191
ts.forEachChild(sourceFile, node => {
@@ -238,7 +242,8 @@ export function extractExports(filePath: string): MemberList {
238242
functions: [],
239243
classes: [],
240244
variables: [],
241-
enums: []
245+
enums: [],
246+
unknown: []
242247
};
243248

244249
const program = ts.createProgram([filePath], {
@@ -275,8 +280,18 @@ export function extractExports(filePath: string): MemberList {
275280
exportDeclarations.classes.push(expt.name);
276281
} else if (ts.isVariableDeclaration(sourceDeclaration)) {
277282
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+
}
278292
} else {
279-
console.log('unhandled export:', expt.name);
293+
console.log(`export of unknown type: ${expt.name}`);
294+
exportDeclarations.unknown.push(expt.name);
280295
}
281296
}
282297

@@ -306,7 +321,8 @@ export function mapSymbolToType(
306321
functions: [],
307322
classes: [],
308323
variables: [],
309-
enums: []
324+
enums: [],
325+
unknown: []
310326
};
311327

312328
for (const key of Object.keys(memberList) as Array<keyof MemberList>) {

repo-scripts/size-analysis/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const deps = Object.keys(
2424
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
2525
);
2626

27-
const nodeInternals = ['fs', 'path'];
27+
const nodeInternals = ['fs', 'path', 'util'];
2828

2929
export default [
3030
{

0 commit comments

Comments
 (0)