@@ -23,6 +23,7 @@ const defaultHost = ts.createCompilerHost(compilerOptions)
2323 * immutable so parsing them once and reusing across all ts.createProgram
2424 * invocations is safe and eliminates the dominant cost per call (~100 lib files).
2525 */
26+ const MODULE_MARKER_RE = / e x p o r t | i m p o r t /
2627const LIB_CACHE_MAX = 200
2728const libSourceFileCache = new Map < string , ts . SourceFile | undefined > ( )
2829
@@ -40,9 +41,9 @@ let lastProgram: ts.Program | null = null
4041 * Falls back to the real filesystem for lib files (e.g. lib.d.ts).
4142 * Uses oldProgram for incremental reuse of lib SourceFiles and checker state.
4243 */
43- export function createTestProgram ( files : Record < string , string > ) : ts . Program {
44+ export function createTestProgram ( files : Map < string , string > ) : ts . Program {
4445 const fileMap = new Map < string , string > ( )
45- for ( const [ key , value ] of Object . entries ( files ) ) {
46+ for ( const [ key , value ] of files ) {
4647 fileMap . set ( resolve ( key ) , value )
4748 }
4849
@@ -84,7 +85,7 @@ export function createTestProgram(files: Record<string, string>): ts.Program {
8485 */
8586export function parseCode ( code : string , filePath = "test.tsx" ) : SolidInput {
8687 const resolvedPath = resolve ( filePath )
87- const program = createTestProgram ( { [ filePath ] : code } )
88+ const program = createTestProgram ( new Map ( [ [ filePath , code ] ] ) )
8889 return createSolidInput ( resolvedPath , program )
8990}
9091
@@ -139,25 +140,28 @@ export function createRuleBatch(
139140 // Build a single program with all snippets as separate virtual files.
140141 // Each snippet gets `export {}` appended to force TypeScript module mode,
141142 // ensuring separate module scopes (no global variable collisions).
142- const fileMap : Record < string , string > = { }
143+ const fileMap = new Map < string , string > ( )
143144 for ( let i = 0 ; i < snippets . length ; i ++ ) {
144145 const code = snippets [ i ] !
145146 // Only add export {} if the snippet doesn't already have an export/import
146- const needsModuleMarker = ! code . includes ( "export " ) && ! code . includes ( "import " )
147- fileMap [ `batch_${ i } .tsx` ] = needsModuleMarker ? code + "\nexport {}" : code
147+ const needsModuleMarker = ! MODULE_MARKER_RE . test ( code )
148+ fileMap . set ( `batch_${ i } .tsx` , needsModuleMarker ? code + "\nexport {}" : code )
148149 }
149150 const program = createTestProgram ( fileMap )
150151
151152 // Build SolidGraph and run rule for each file independently
152153 const results : RuleTestResult [ ] = [ ]
154+ const collector : { target : Diagnostic [ ] | null } = { target : null }
155+ const collect = ( d : Diagnostic ) => collector . target ! . push ( d )
153156 for ( let i = 0 ; i < snippets . length ; i ++ ) {
154157 const filePath = resolve ( `batch_${ i } .tsx` )
155158 const input = createSolidInput ( filePath , program )
156159 const graph = buildSolidGraph ( input )
157160 const diagnostics : Diagnostic [ ] = [ ]
158161 const setup = setupPerSnippet ?. [ i ]
159162 if ( setup ) setup ( )
160- rule . check ( graph , ( d ) => diagnostics . push ( d ) )
163+ collector . target = diagnostics
164+ rule . check ( graph , collect )
161165 results . push ( { diagnostics, graph, code : snippets [ i ] ! } )
162166 }
163167
@@ -250,12 +254,12 @@ export function lazyParseBatch(): {
250254 } ,
251255 result ( index : number ) : SolidInput {
252256 if ( results === null ) {
253- const fileMap : Record < string , string > = { }
257+ const fileMap = new Map < string , string > ( )
254258 for ( let i = 0 ; i < entries . length ; i ++ ) {
255259 const entry = entries [ i ] !
256260 const code = entry . code
257- const needsModuleMarker = ! code . includes ( "export " ) && ! code . includes ( "import " )
258- fileMap [ entry . filePath ] = needsModuleMarker ? code + "\nexport {}" : code
261+ const needsModuleMarker = ! MODULE_MARKER_RE . test ( code )
262+ fileMap . set ( entry . filePath , needsModuleMarker ? code + "\nexport {}" : code )
259263 }
260264 const program = createTestProgram ( fileMap )
261265 results = [ ]
0 commit comments