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

Function generateTcb

packages/compiler-cli/preprocessor/src/processor.ts:1985–2059  ·  view source on GitHub ↗

* The `GenerateTcb` pass, when optimizing: generates the file's type-check block and adds its * diagnostics to `file.fileDiagnostics`.

(file: FileCompilation)

Source from the content-addressed store, hash-verified

1983 * diagnostics to `file.fileDiagnostics`.
1984 */
1985function generateTcb(file: FileCompilation): TcbResult | undefined {
1986 const {ctx, filePath, content, result, templatesByClass, fileDiagnostics} = file;
1987 const {classes} = result;
1988 const analysis = getOrCreateFileAnalysis(ctx.fileCache, filePath);
1989 let prepared: ReturnType<typeof prepareTcbTargets>;
1990 if (analysis.preparedTcbData !== undefined && analysis.sourceContent === content) {
1991 prepared = analysis.preparedTcbData;
1992 } else {
1993 const tcbTargets = buildTcbTargets(
1994 filePath,
1995 content,
1996 classes,
1997 templatesByClass,
1998 ctx.templateParseOptions,
1999 ctx.tcbConfig,
2000 new DependencyTemplates(
2001 ctx.analyzer,
2002 ctx.fileCache,
2003 ctx.templateParseOptions,
2004 ctx.metadataMap,
2005 ctx.tracer,
2006 ),
2007 ctx.tracer,
2008 );
2009 prepared =
2010 tcbTargets.length > 0
2011 ? prepareTcbTargets(filePath, tcbTargets, content, ctx.tcbConfig, classes, ctx.tracer)
2012 : null;
2013 analysis.preparedTcbData = prepared;
2014 analysis.sourceContent = content;
2015 }
2016 const tcb = prepared
2017 ? (generateTcbCode(filePath, prepared, ctx.tcbConfig, result.namespaceAliasConflicts) ??
2018 undefined)
2019 : undefined;
2020
2021 const returnTcb = tcb
2022 ? {...tcb, code: combineTcbContent(tcb, filePath, {sourceContent: content, classes})}
2023 : undefined;
2024 if (returnTcb) {
2025 analysis.tcb = returnTcb.code;
2026 ctx.tracer.count(Counter.TcbFilesGenerated);
2027 }
2028
2029 if (tcb?.diagnostics && tcb.diagnostics.length > 0) {
2030 for (const diag of tcb.diagnostics) {
2031 let component: nga.ComponentMetadata | undefined;
2032 if (prepared?.typeCheckIdMap) {
2033 for (const [classKey, id] of prepared.typeCheckIdMap.entries()) {
2034 if (id === diag.typeCheckId) {
2035 const cls = classes.find((c) => makeClassKey(c.className, c.span.start) === classKey);
2036 component = cls?.component ?? undefined;
2037 break;
2038 }
2039 }
2040 }
2041
2042 fileDiagnostics.push(

Callers 1

processFileFunction · 0.85

Calls 12

getOrCreateFileAnalysisFunction · 0.85
buildTcbTargetsFunction · 0.85
prepareTcbTargetsFunction · 0.85
generateTcbCodeFunction · 0.85
combineTcbContentFunction · 0.85
makeClassKeyFunction · 0.85
mapMethod · 0.80
countMethod · 0.65
entriesMethod · 0.45
findMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected