MCPcopy Index your code
hub / github.com/angular/angular / makeProgram

Function makeProgram

packages/compiler-cli/src/ngtsc/testing/src/utils.ts:19–60  ·  view source on GitHub ↗
(
  files: {name: AbsoluteFsPath; contents: string; isRoot?: boolean}[],
  options?: ts.CompilerOptions,
  host?: ts.CompilerHost,
  checkForErrors: boolean = true,
)

Source from the content-addressed store, hash-verified

17import {NgtscTestCompilerHost} from './compiler_host';
18
19export function makeProgram(
20 files: {name: AbsoluteFsPath; contents: string; isRoot?: boolean}[],
21 options?: ts.CompilerOptions,
22 host?: ts.CompilerHost,
23 checkForErrors: boolean = true,
24): {program: ts.Program; host: ts.CompilerHost; options: ts.CompilerOptions} {
25 const fs = getFileSystem();
26 files.forEach((file) => {
27 fs.ensureDir(dirname(file.name));
28 fs.writeFile(file.name, file.contents);
29 });
30
31 const compilerOptions = {
32 noLib: true,
33 experimentalDecorators: true,
34 strict: false,
35 moduleResolution: ts.ModuleResolutionKind.Bundler,
36 ...options,
37 };
38 const compilerHost = new NgtscTestCompilerHost(fs, compilerOptions);
39 const rootNames = files
40 .filter((file) => file.isRoot !== false)
41 .map((file) => compilerHost.getCanonicalFileName(file.name));
42 const program = ts.createProgram(rootNames, compilerOptions, compilerHost);
43 if (checkForErrors) {
44 const diags = [...program.getSyntacticDiagnostics(), ...program.getSemanticDiagnostics()];
45 if (diags.length > 0) {
46 const errors = diags.map((diagnostic) => {
47 let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
48 if (diagnostic.file) {
49 const {line, character} = diagnostic.file.getLineAndCharacterOfPosition(
50 diagnostic.start!,
51 );
52 message = `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`;
53 }
54 return `Error: ${message}`;
55 });
56 throw new Error(`Typescript diagnostics failed! ${errors.join(', ')}`);
57 }
58 }
59 return {program, host: compilerHost, options: compilerOptions};
60}
61
62/**
63 * Search the file specified by `fileName` in the given `program` for a declaration that has the

Callers 15

makeProgramFromGraphFunction · 0.90
adapter_spec.tsFile · 0.90
ts_host_spec.tsFile · 0.90
getComponentDeclarationFunction · 0.90
makeStrategyFunction · 0.90
emitter_spec.tsFile · 0.90
default_spec.tsFile · 0.90
makeTestEnvFunction · 0.90
evaluator_spec.tsFile · 0.90
traceExpressionFunction · 0.90

Calls 11

getFileSystemFunction · 0.90
dirnameFunction · 0.90
mapMethod · 0.80
ensureDirMethod · 0.65
writeFileMethod · 0.65
joinMethod · 0.65
forEachMethod · 0.45
filterMethod · 0.45
getCanonicalFileNameMethod · 0.45
createProgramMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…