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

Function setup

packages/compiler-cli/src/ngtsc/typecheck/testing/index.ts:243–485  ·  view source on GitHub ↗
(
  targets: TypeCheckingTarget[],
  overrides: {
    config?: Partial<TypeCheckingConfig>;
    options?: ts.CompilerOptions;
    inlining?: boolean;
    inliningMode?: InliningMode;
    parseOptions?: ParseTemplateOptions;
    referenceEmitter?: ReferenceEmitter;
  } = {},
  load: {
    forms?: boolean;
  } = {},
)

Source from the content-addressed store, hash-verified

241 * that can be auto-generated based on the provided target configuration.
242 */
243export function setup(
244 targets: TypeCheckingTarget[],
245 overrides: {
246 config?: Partial<TypeCheckingConfig>;
247 options?: ts.CompilerOptions;
248 inlining?: boolean;
249 inliningMode?: InliningMode;
250 parseOptions?: ParseTemplateOptions;
251 referenceEmitter?: ReferenceEmitter;
252 } = {},
253 load: {
254 forms?: boolean;
255 } = {},
256): {
257 templateTypeChecker: TemplateTypeChecker;
258 program: ts.Program;
259 programStrategy: TsCreateProgramDriver;
260} {
261 const files = [
262 typescriptLibDts(),
263 ...angularCoreDtsFiles(),
264 angularAnimationsDts(),
265 ...(load.forms ? angularFormsDtsFiles() : []),
266 ];
267 const fakeMetadataRegistry = new Map();
268 const shims = new Map<AbsoluteFsPath, AbsoluteFsPath>();
269
270 for (const target of targets) {
271 let contents: string;
272 if (target.source !== undefined) {
273 contents = target.source;
274 } else {
275 contents = `// generated from templates\n\nexport const MODULE = true;\n\n`;
276 if (target.templates) {
277 for (const className of Object.keys(target.templates)) {
278 contents += `export class ${className} {}\n`;
279 }
280 }
281 }
282
283 files.push({name: target.fileName, contents});
284
285 if (!target.fileName.endsWith('.d.ts')) {
286 const shimName = TypeCheckShimGenerator.shimFor(target.fileName);
287 shims.set(target.fileName, shimName);
288 files.push({name: shimName, contents: 'export const MODULE = true;'});
289 }
290 }
291
292 const opts = overrides.options ?? {};
293 const config = overrides.config ?? {};
294
295 const {program, host, options} = makeProgram(
296 files,
297 {strictNullChecks: true, skipLibCheck: true, noImplicitAny: true, ...opts},
298 /* host */ undefined,
299 /* checkForErrors */ false,
300 );

Calls 15

typescriptLibDtsFunction · 0.90
angularCoreDtsFilesFunction · 0.90
angularAnimationsDtsFunction · 0.90
angularFormsDtsFilesFunction · 0.90
makeProgramFunction · 0.90
getRootDirsFunction · 0.90
getSourceFileOrErrorFunction · 0.90
sfExtensionDataFunction · 0.90
parseTemplateFunction · 0.90
isNgpTestModeFunction · 0.90
makeScopeFunction · 0.85

Tested by

no test coverage detected