| 539 | * that can be auto-generated based on the provided target configuration. |
| 540 | */ |
| 541 | export function setup( |
| 542 | targets: TypeCheckingTarget[], |
| 543 | overrides: { |
| 544 | config?: Partial<TypeCheckingConfig>; |
| 545 | options?: ts.CompilerOptions; |
| 546 | inlining?: boolean; |
| 547 | inliningMode?: InliningMode; |
| 548 | parseOptions?: ParseTemplateOptions; |
| 549 | referenceEmitter?: ReferenceEmitter; |
| 550 | } = {}, |
| 551 | load: { |
| 552 | forms?: boolean; |
| 553 | } = {}, |
| 554 | ): { |
| 555 | templateTypeChecker: TemplateTypeChecker; |
| 556 | program: ts.Program; |
| 557 | programStrategy: TsCreateProgramDriver; |
| 558 | } { |
| 559 | const files = [ |
| 560 | typescriptLibDts(), |
| 561 | ...angularCoreDtsFiles(), |
| 562 | angularAnimationsDts(), |
| 563 | ...(load.forms ? angularFormsDtsFiles() : []), |
| 564 | ]; |
| 565 | const fakeMetadataRegistry = new Map(); |
| 566 | const shims = new Map<AbsoluteFsPath, AbsoluteFsPath>(); |
| 567 | |
| 568 | for (const target of targets) { |
| 569 | let contents: string; |
| 570 | if (target.source !== undefined) { |
| 571 | contents = target.source; |
| 572 | } else { |
| 573 | contents = `// generated from templates\n\nexport const MODULE = true;\n\n`; |
| 574 | if (target.templates) { |
| 575 | for (const className of Object.keys(target.templates)) { |
| 576 | contents += `export class ${className} {}\n`; |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | files.push({name: target.fileName, contents}); |
| 582 | |
| 583 | if (!target.fileName.endsWith('.d.ts')) { |
| 584 | const shimName = TypeCheckShimGenerator.shimFor(target.fileName); |
| 585 | shims.set(target.fileName, shimName); |
| 586 | files.push({name: shimName, contents: 'export const MODULE = true;'}); |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | const opts = overrides.options ?? {}; |
| 591 | const config = overrides.config ?? {}; |
| 592 | |
| 593 | const {program, host, options} = makeProgram( |
| 594 | files, |
| 595 | {strictNullChecks: true, skipLibCheck: true, noImplicitAny: true, ...opts}, |
| 596 | /* host */ undefined, |
| 597 | /* checkForErrors */ false, |
| 598 | ); |