MCPcopy Create free account
hub / github.com/angular/angular / processFile

Function processFile

packages/compiler-cli/preprocessor/src/processor.ts:301–466  ·  view source on GitHub ↗
(
  rawCtx: HybridCompilerContext,
  filePath: string,
  content: string,
  metadata?: nga.AnalysisResult,
  chunkContext?: ChunkContext,
  fileId = 0,
)

Source from the content-addressed store, hash-verified

299}
300
301export async function processFile(
302 rawCtx: HybridCompilerContext,
303 filePath: string,
304 content: string,
305 metadata?: nga.AnalysisResult,
306 chunkContext?: ChunkContext,
307 fileId = 0,
308): Promise<ProcessedFile> {
309 const result = metadata || (await rawCtx.analyzer.getMetadataForFile(filePath));
310 if (!result) {
311 return unprocessedFile(new MagicString(content));
312 }
313 const {parsedTemplates: templatesByClass} = getOrCreateFileAnalysis(rawCtx.fileCache, filePath);
314 const resourceMap = new Map<string, nga.ResolvedResource | null>();
315 for (const classMeta of result.classes) {
316 if (!classMeta.component || !classMeta.className) continue;
317 const parsed = getOrParseComponentTemplate(
318 templatesByClass,
319 classMeta,
320 classMeta.component,
321 filePath,
322 content,
323 rawCtx.templateParseOptions,
324 rawCtx.tracer,
325 );
326 for (const styleUrl of parsed.styleUrls) {
327 if (!resourceMap.has(styleUrl)) {
328 const resource = await rawCtx.analyzer.readResource(filePath, styleUrl);
329 resourceMap.set(styleUrl, resource);
330 }
331 }
332 }
333 // Templates of dependencies declared in other files are needed to bind this file's
334 // templates for type-checking; read them here, where the analyzer can be awaited. The
335 // condition mirrors when `processFile` builds the TCB targets.
336 if (rawCtx.optimize && !rawCtx.emitDeclarationOnly) {
337 await new DependencyTemplates(
338 rawCtx.analyzer,
339 rawCtx.fileCache,
340 rawCtx.templateParseOptions,
341 chunkContext?.metadataMap || rawCtx.metadataMap,
342 rawCtx.tracer,
343 ).prefetch(result);
344 }
345 const ctx: ProcessFileContext = {
346 ...rawCtx,
347 remoteScopedClasses:
348 chunkContext?.remoteScopedClasses || rawCtx.remoteScopedClasses || new Set(),
349 metadataMap: chunkContext?.metadataMap || rawCtx.metadataMap || new Map(),
350 eagerlyUsedDeclarations: chunkContext?.eagerlyUsedDeclarations || new Map(),
351 };
352 const s = new MagicString(content);
353 const fileDiagnostics: nga.NgDiagnostic[] = [];
354 const referencedStyleFiles: string[] = [];
355
356 const {classes, imports: importDeclarations} = result;
357
358 // Inside `@angular/core` itself, generated imports of `@angular/core` go to `r3_symbols.ts`.

Callers 2

processFileMethod · 0.70
emitHmrUpdateModuleMethod · 0.70

Calls 15

unprocessedFileFunction · 0.85
getOrCreateFileAnalysisFunction · 0.85
insertSignalDebugNamesFunction · 0.85
compileClassesFunction · 0.85
serializeOutputFunction · 0.85
generateTcbFunction · 0.85
prefetchMethod · 0.80
valuesMethod · 0.80
someMethod · 0.80
getMetadataForFileMethod · 0.65
hasMethod · 0.65

Tested by

no test coverage detected