MCPcopy Create free account
hub / github.com/Snapchat/Valdi / parseFile

Function parseFile

npm_modules/cli/src/core/analyze/parser.ts:6–37  ·  view source on GitHub ↗
(filePath: string, config: ScanConfig)

Source from the content-addressed store, hash-verified

4import { extractModuleName } from './scanner';
5
6export 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
39function extractImports(sourceFile: ts.SourceFile): string[] {
40 const imports: string[] = [];

Callers 1

analyzeDuplicatesFunction · 0.90

Calls 11

extractModuleNameFunction · 0.90
extractImportsFunction · 0.85
isSharedLibImportFunction · 0.85
findComponentClassNameFunction · 0.85
extractViewModelPropsFunction · 0.85
extractStatePropsFunction · 0.85
extractRenderElementsFunction · 0.85
detectFlagsFunction · 0.85
readFileSyncMethod · 0.80
filterMethod · 0.80
createSourceFileMethod · 0.45

Tested by

no test coverage detected