(filePath: string, config: ScanConfig)
| 4 | import { extractModuleName } from './scanner'; |
| 5 | |
| 6 | export function parseFile(filePath: string, config: ScanConfig): ComponentFingerprint | undefined { |
| 7 | let content: string; |
| 8 | try { |
| 9 | content = fs.readFileSync(filePath, 'utf8'); |
| 10 | } catch { |
| 11 | return undefined; |
| 12 | } |
| 13 | |
| 14 | const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, false, ts.ScriptKind.TSX); |
| 15 | |
| 16 | const imports = extractImports(sourceFile); |
| 17 | const sharedLibImports = imports.filter(imp => isSharedLibImport(imp, config)); |
| 18 | const className = findComponentClassName(sourceFile); |
| 19 | if (!className) return undefined; |
| 20 | |
| 21 | const viewModelProps = extractViewModelProps(sourceFile); |
| 22 | const stateProps = extractStateProps(sourceFile); |
| 23 | const renderElements = extractRenderElements(sourceFile); |
| 24 | const flags = detectFlags(sourceFile, content, imports); |
| 25 | |
| 26 | return { |
| 27 | filePath, |
| 28 | moduleName: extractModuleName(filePath, config) ?? 'unknown', |
| 29 | className, |
| 30 | viewModelProps, |
| 31 | stateProps, |
| 32 | importPaths: imports, |
| 33 | sharedLibImports, |
| 34 | renderElements, |
| 35 | flags, |
| 36 | }; |
| 37 | } |
| 38 | |
| 39 | function extractImports(sourceFile: ts.SourceFile): string[] { |
| 40 | const imports: string[] = []; |
no test coverage detected