/** * SMI-1308: Worker Pool Utilities * * Utility functions for the worker thread pool. * Extracted from worker-pool.ts for better modularity. * * @see docs/internal/architecture/multi-language-analysis.md * @module analysis/worker-utils */ /** * Map of file extensions to language names * Used for metrics recording */ export declare const EXTENSION_TO_LANGUAGE: Record; /** * Get language from file extension * * @param ext - File extension (without leading dot) * @returns Language name or undefined if not supported * * @example * ```typescript * getLanguageFromExtension('ts') // 'typescript' * getLanguageFromExtension('py') // 'python' * getLanguageFromExtension('unknown') // undefined * ``` */ export declare function getLanguageFromExtension(ext?: string): string | undefined; /** * Chunk an array into smaller arrays of specified size * * @param array - Array to chunk * @param size - Maximum size of each chunk * @returns Array of chunks * * @example * ```typescript * chunkArray([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]] * ``` */ export declare function chunkArray(array: T[], size: number): T[][]; /** * Worker code template for inline parsing * * This code runs inside worker threads to perform basic regex-based parsing. * Full adapter-based parsing happens in main thread for accuracy. */ export declare const WORKER_PARSE_CODE = "\nconst { parentPort, workerData } = require('worker_threads');\n\nfunction processTask(task) {\n const start = Date.now();\n try {\n const result = {\n imports: [],\n exports: [],\n functions: [],\n };\n\n const lines = task.content.split('\\n');\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n\n // Detect imports (TypeScript/JavaScript)\n if (/^import\\s/.test(line) || /^from\\s/.test(line)) {\n const moduleMatch = line.match(/from\\s+['\"]([^'\"]+)['\"]/);\n result.imports.push({\n module: moduleMatch ? moduleMatch[1] : line.trim(),\n namedImports: [],\n isTypeOnly: /^import\\s+type/.test(line),\n sourceFile: task.filePath,\n line: i + 1,\n });\n }\n\n // Detect imports (Python)\n if (/^import\\s+\\w/.test(line) || /^from\\s+\\w/.test(line)) {\n const moduleMatch = line.match(/^(?:from\\s+)?(\\w+(?:\\.\\w+)*)/);\n if (moduleMatch && !result.imports.some(imp => imp.line === i + 1)) {\n result.imports.push({\n module: moduleMatch[1],\n namedImports: [],\n isTypeOnly: false,\n sourceFile: task.filePath,\n line: i + 1,\n });\n }\n }\n\n // Detect imports (Go)\n if (/^\\s*\"[^\"]+\"/.test(line) || /^import\\s+/.test(line)) {\n const pathMatch = line.match(/\"([^\"]+)\"/);\n if (pathMatch) {\n result.imports.push({\n module: pathMatch[1],\n namedImports: [],\n isTypeOnly: false,\n sourceFile: task.filePath,\n line: i + 1,\n });\n }\n }\n\n // Detect functions (TypeScript/JavaScript)\n const tsFuncMatch = line.match(/^(export\\s+)?(async\\s+)?function\\s+(\\w+)/);\n if (tsFuncMatch) {\n result.functions.push({\n name: tsFuncMatch[3],\n parameterCount: 0,\n isAsync: !!tsFuncMatch[2],\n isExported: !!tsFuncMatch[1],\n sourceFile: task.filePath,\n line: i + 1,\n });\n }\n\n // Detect functions (Python)\n const pyFuncMatch = line.match(/^(async\\s+)?def\\s+(\\w+)/);\n if (pyFuncMatch) {\n result.functions.push({\n name: pyFuncMatch[2],\n parameterCount: 0,\n isAsync: !!pyFuncMatch[1],\n isExported: !pyFuncMatch[2].startsWith('_'),\n sourceFile: task.filePath,\n line: i + 1,\n });\n }\n\n // Detect functions (Go)\n const goFuncMatch = line.match(/^func\\s+(?:\\([^)]+\\)\\s+)?(\\w+)/);\n if (goFuncMatch) {\n const isExported = goFuncMatch[1][0] === goFuncMatch[1][0].toUpperCase();\n result.functions.push({\n name: goFuncMatch[1],\n parameterCount: 0,\n isAsync: false,\n isExported: isExported,\n sourceFile: task.filePath,\n line: i + 1,\n });\n }\n\n // Detect exports (TypeScript/JavaScript)\n if (/^export\\s+(default\\s+)?(const|let|var|class|function|interface|type|enum)/.test(line)) {\n const exportMatch = line.match(/^export\\s+(default\\s+)?(const|let|var|class|function|interface|type|enum)\\s+(\\w+)/);\n if (exportMatch) {\n result.exports.push({\n name: exportMatch[3],\n kind: exportMatch[2] === 'function' ? 'function' :\n exportMatch[2] === 'class' ? 'class' :\n exportMatch[2] === 'interface' ? 'interface' :\n exportMatch[2] === 'type' ? 'type' :\n exportMatch[2] === 'enum' ? 'enum' : 'variable',\n isDefault: !!exportMatch[1],\n sourceFile: task.filePath,\n line: i + 1,\n });\n }\n }\n }\n\n return {\n filePath: task.filePath,\n result,\n durationMs: Date.now() - start,\n };\n } catch (error) {\n return {\n filePath: task.filePath,\n result: { imports: [], exports: [], functions: [] },\n durationMs: Date.now() - start,\n error: error.message || String(error),\n };\n }\n}\n\nconst results = workerData.tasks.map(processTask);\nparentPort.postMessage(results);\n"; //# sourceMappingURL=worker-utils.d.ts.map