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

Class NgtscProgram

packages/compiler-cli/src/ngtsc/program.ts:38–411  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36 * command-line main() function or the Angular CLI.
37 */
38export class NgtscProgram implements api.Program {
39 readonly compiler: NgCompiler;
40
41 /**
42 * The primary TypeScript program, which is used for analysis and emit.
43 */
44 private tsProgram: ts.Program;
45
46 private host: NgCompilerHost;
47 private incrementalStrategy: TrackedIncrementalBuildStrategy;
48
49 constructor(
50 rootNames: ReadonlyArray<string>,
51 private options: NgCompilerOptions,
52 delegateHost: api.CompilerHost,
53 oldProgram?: NgtscProgram,
54 ) {
55 const perfRecorder = ActivePerfRecorder.zeroedToNow();
56
57 perfRecorder.phase(PerfPhase.Setup);
58
59 // First, check whether the current TS version is supported.
60 if (!options.disableTypeScriptVersionCheck) {
61 verifySupportedTypeScriptVersion();
62 }
63
64 // In local compilation mode there are almost always (many) emit errors due to imports that
65 // cannot be resolved. So we should emit regardless.
66 if (options.compilationMode === 'experimental-local') {
67 options.noEmitOnError = false;
68 }
69
70 const reuseProgram = oldProgram?.compiler.getCurrentProgram();
71 this.host = NgCompilerHost.wrap(delegateHost, rootNames, options, reuseProgram ?? null);
72
73 if (reuseProgram !== undefined) {
74 // Prior to reusing the old program, restore shim tagging for all its `ts.SourceFile`s.
75 // TypeScript checks the `referencedFiles` of `ts.SourceFile`s for changes when evaluating
76 // incremental reuse of data from the old program, so it's important that these match in order
77 // to get the most benefit out of reuse.
78 retagAllTsFiles(reuseProgram);
79 }
80
81 this.tsProgram = perfRecorder.inPhase(PerfPhase.TypeScriptProgramCreate, () =>
82 ts.createProgram(this.host.inputFiles, options, this.host, reuseProgram),
83 );
84
85 perfRecorder.phase(PerfPhase.Unaccounted);
86 perfRecorder.memory(PerfCheckpoint.TypeScriptProgramCreate);
87
88 this.host.postProgramCreationCleanup();
89
90 const programDriver = new TsCreateProgramDriver(
91 this.tsProgram,
92 this.host,
93 this.options,
94 this.host.shimExtensionPrefixes,
95 );

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected