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

Function setup

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

Source from the content-addressed store, hash-verified

524 * that can be auto-generated based on the provided target configuration.
525 */
526export function setup(
527 targets: TypeCheckingTarget[],
528 overrides: {
529 config?: Partial<TypeCheckingConfig>;
530 options?: ts.CompilerOptions;
531 inlining?: boolean;
532 inliningMode?: InliningMode;
533 parseOptions?: ParseTemplateOptions;
534 referenceEmitter?: ReferenceEmitter;
535 } = {},
536): {
537 templateTypeChecker: TemplateTypeChecker;
538 program: ts.Program;
539 programStrategy: TsCreateProgramDriver;
540} {
541 const files = [typescriptLibDts(), ...angularCoreDtsFiles(), angularAnimationsDts()];
542 const fakeMetadataRegistry = new Map();
543 const shims = new Map<AbsoluteFsPath, AbsoluteFsPath>();
544
545 for (const target of targets) {
546 let contents: string;
547 if (target.source !== undefined) {
548 contents = target.source;
549 } else {
550 contents = `// generated from templates\n\nexport const MODULE = true;\n\n`;
551 if (target.templates) {
552 for (const className of Object.keys(target.templates)) {
553 contents += `export class ${className} {}\n`;
554 }
555 }
556 }
557
558 files.push({name: target.fileName, contents});
559
560 if (!target.fileName.endsWith('.d.ts')) {
561 const shimName = TypeCheckShimGenerator.shimFor(target.fileName);
562 shims.set(target.fileName, shimName);
563 files.push({name: shimName, contents: 'export const MODULE = true;'});
564 }
565 }
566
567 const opts = overrides.options ?? {};
568 const config = overrides.config ?? {};
569
570 const {program, host, options} = makeProgram(
571 files,
572 {strictNullChecks: true, skipLibCheck: true, noImplicitAny: true, ...opts},
573 /* host */ undefined,
574 /* checkForErrors */ false,
575 );
576 const checker = program.getTypeChecker();
577 const logicalFs = new LogicalFileSystem(getRootDirs(host, options), host);
578 const reflectionHost = new TypeScriptReflectionHost(checker);
579 const moduleResolver = new ModuleResolver(
580 program,
581 options,
582 host,
583 /* moduleResolutionCache */ null,

Calls 15

makeProgramFunction · 0.90
getRootDirsFunction · 0.90
getSourceFileOrErrorFunction · 0.90
sfExtensionDataFunction · 0.90
parseTemplateFunction · 0.90
typescriptLibDtsFunction · 0.85
angularCoreDtsFilesFunction · 0.85
angularAnimationsDtsFunction · 0.85
makeScopeFunction · 0.85
createTypeCheckAdapterFunction · 0.85
prepareDeclarationsFunction · 0.85
getFakeMetadataReaderFunction · 0.85

Tested by 1

diagnoseTestComponentFunction · 0.72