ReviewOS

also looking at this

stacks/dtsx

perf(isolated): benchmark declaration generation paths

#3106
Merged chris wants to merge codex/isolated-mode-benchmarks into main
4 files +215 -6
packages/dtsx/test/generation-paths.test.tsmodified+41-0
Changes to packages/dtsx/test/generation-paths.test.ts
@@ -114,6 +114,47 @@ describe('declaration generation paths', () => {
114114 expect(declaration.value).toBeUndefined()
115115 })
116116
117 it('fast-skips terminated single-line literals without consuming following declarations', () => {
118 const source = [
119 `export const object: { nested: { value: string }, callback: () => number } = { nested: { value: ';' }, callback: () => 42 };`,
120 `export const array: readonly string[] = ['one', ';', 'three'];`,
121 `export const quoted: string = 'a value with ; and } delimiters';`,
122 'export const template: string = `a template with ; and ] delimiters`;',
123 `export const after: number = 42;`,
124 `export const sameLineObject: { value: string } = { value: 'one' }; export const sameLineAfter: { value: string } = { value: 'two' };`,
125 ].join('\n')
126
127 const isolated = processSourceIsolated(source, 'terminated.ts', false)
128 const semantic = processSourceSemantic(source, 'terminated.ts', false)
129
130 expect(isolated).toBe(semantic)
131 expect(isolated).toContain('export declare const object: { nested: { value: string }, callback: () => number };')
132 expect(isolated).toContain('export declare const array: readonly string[];')
133 expect(isolated).toContain('export declare const quoted: string;')
134 expect(isolated).toContain('export declare const template: string;')
135 expect(isolated).toContain('export declare const after: number;')
136 expect(isolated).toContain('export declare const sameLineObject: { value: string };')
137 expect(isolated).toContain('export declare const sameLineAfter: { value: string };')
138 })
139
140 it('falls back to balanced scanning for multiline and semicolonless initializers', () => {
141 const source = [
142 'export const multiline: { value: string } = {',
143 ` value: 'kept private',`,
144 '};',
145 `export const semicolonless: readonly number[] = [1, 2, 3]`,
146 `export const after: boolean = true`,
147 ].join('\n')
148
149 const isolated = processSourceIsolated(source, 'fallback.ts', false)
150 const semantic = processSourceSemantic(source, 'fallback.ts', false)
151
152 expect(isolated).toBe(semantic)
153 expect(isolated).toContain('export declare const multiline: { value: string };')
154 expect(isolated).toContain('export declare const semicolonless: readonly number[];')
155 expect(isolated).toContain('export declare const after: boolean;')
156 })
157
117158 it('preserves broad contracts and documents their initializer values', () => {
118159 const source = `
119160 export const conf: { [key: string]: string } = {