@esportsplus/typescript 0.29.0 → 0.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,101 @@
1
+ import { bench, describe, vi } from 'vitest';
2
+ import ts from 'typescript';
3
+
4
+ import type { Plugin, TransformContext } from '~/compiler/types';
5
+
6
+ import coordinator from '~/compiler/coordinator';
7
+
8
+
9
+ vi.mock('~/compiler/language-service', () => ({
10
+ default: {
11
+ invalidate: vi.fn(),
12
+ update: vi.fn((_root: string, fileName: string, content: string) => {
13
+ let file = ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true);
14
+
15
+ return {
16
+ getSourceFile: () => file,
17
+ getTypeChecker: () => ({} as ts.TypeChecker)
18
+ } as unknown as ts.Program;
19
+ })
20
+ }
21
+ }));
22
+
23
+
24
+ function parse(code: string, fileName = 'bench.ts'): ts.SourceFile {
25
+ return ts.createSourceFile(fileName, code, ts.ScriptTarget.Latest, true);
26
+ }
27
+
28
+ function makeProgram(file: ts.SourceFile): ts.Program {
29
+ return {
30
+ getSourceFile: () => file,
31
+ getTypeChecker: () => ({} as ts.TypeChecker)
32
+ } as unknown as ts.Program;
33
+ }
34
+
35
+ function makePlugin(transformFn: (ctx: TransformContext) => ReturnType<Plugin['transform']>): Plugin {
36
+ return { transform: transformFn };
37
+ }
38
+
39
+
40
+ let code = 'let x = 1;',
41
+ file = parse(code),
42
+ program = makeProgram(file);
43
+
44
+ describe('applyImports batching', () => {
45
+ bench('10 intents, 1 package', () => {
46
+ let plugin = makePlugin(() => ({
47
+ imports: [
48
+ { add: ['a'], package: '@pkg/a' },
49
+ { add: ['b'], package: '@pkg/a' },
50
+ { add: ['c'], package: '@pkg/a' },
51
+ { add: ['d'], package: '@pkg/a' },
52
+ { add: ['e'], package: '@pkg/a' },
53
+ { add: ['f'], package: '@pkg/a' },
54
+ { add: ['g'], package: '@pkg/a' },
55
+ { add: ['h'], package: '@pkg/a' },
56
+ { add: ['i'], package: '@pkg/a' },
57
+ { add: ['j'], package: '@pkg/a' }
58
+ ]
59
+ }));
60
+
61
+ coordinator.transform([plugin], code, file, program, '/root', new Map());
62
+ });
63
+
64
+ bench('10 intents, 3 packages', () => {
65
+ let plugin = makePlugin(() => ({
66
+ imports: [
67
+ { add: ['a'], package: '@pkg/a' },
68
+ { add: ['b'], package: '@pkg/a' },
69
+ { add: ['c'], package: '@pkg/a' },
70
+ { add: ['d'], package: '@pkg/b' },
71
+ { add: ['e'], package: '@pkg/b' },
72
+ { add: ['f'], package: '@pkg/b' },
73
+ { add: ['g'], package: '@pkg/b' },
74
+ { add: ['h'], package: '@pkg/c' },
75
+ { add: ['i'], package: '@pkg/c' },
76
+ { add: ['j'], package: '@pkg/c' }
77
+ ]
78
+ }));
79
+
80
+ coordinator.transform([plugin], code, file, program, '/root', new Map());
81
+ });
82
+
83
+ bench('10 intents, 10 packages', () => {
84
+ let plugin = makePlugin(() => ({
85
+ imports: [
86
+ { add: ['a'], package: '@pkg/a' },
87
+ { add: ['b'], package: '@pkg/b' },
88
+ { add: ['c'], package: '@pkg/c' },
89
+ { add: ['d'], package: '@pkg/d' },
90
+ { add: ['e'], package: '@pkg/e' },
91
+ { add: ['f'], package: '@pkg/f' },
92
+ { add: ['g'], package: '@pkg/g' },
93
+ { add: ['h'], package: '@pkg/h' },
94
+ { add: ['i'], package: '@pkg/i' },
95
+ { add: ['j'], package: '@pkg/j' }
96
+ ]
97
+ }));
98
+
99
+ coordinator.transform([plugin], code, file, program, '/root', new Map());
100
+ });
101
+ });