( filePath: string, preparedData: PreparedTcbData, config: NgpTypeCheckingConfig, namespaceAliasConflicts?: ReadonlyArray<string>, )
| 660 | } |
| 661 | |
| 662 | export function generateTcbCode( |
| 663 | filePath: string, |
| 664 | preparedData: PreparedTcbData, |
| 665 | config: NgpTypeCheckingConfig, |
| 666 | namespaceAliasConflicts?: ReadonlyArray<string>, |
| 667 | ): TcbResult | null { |
| 668 | const {targets, requiresInline} = preparedData; |
| 669 | if (targets.length === 0) return null; |
| 670 | |
| 671 | // Inline TCBs share file scope with the copied source content, so generated imports must avoid |
| 672 | // any alias-shaped bindings in the file (`AnalysisResult.namespaceAliasConflicts`). |
| 673 | const importManager = new TcbImportManager( |
| 674 | requiresInline && namespaceAliasConflicts ? new Set(namespaceAliasConflicts) : undefined, |
| 675 | ); |
| 676 | const oobRecorder = new OutOfBandDiagnosticRecorderImpl(); |
| 677 | const domSchemaChecker = new RegistryDomSchemaChecker(); |
| 678 | const semanticsDiagnostics: Diagnostic[] = []; |
| 679 | const extendedDiagnostics: Diagnostic[] = []; |
| 680 | |
| 681 | let code = ''; |
| 682 | let functionStrings = ''; |
| 683 | const tcbMap = new Map<string, string>(); |
| 684 | const templateSources: Record<string, TcbTemplateSource> = {}; |
| 685 | |
| 686 | const sharedEnv = !requiresInline ? new TcbEnvironmentImpl(config, importManager, false) : null; |
| 687 | |
| 688 | for (const target of targets) { |
| 689 | const {comp, typeCheckId, tcbMeta, targetMeta} = target; |
| 690 | const env = sharedEnv || new TcbEnvironmentImpl(config, importManager, true); |
| 691 | |
| 692 | const targetTypeParams = targetMeta.typeParameters |
| 693 | ? (qualifyTypeParameters(targetMeta.typeParameters, env, targetMeta.ref.moduleName) ?? null) |
| 694 | : null; |
| 695 | const qualifiedTargetMeta = targetTypeParams |
| 696 | ? {...targetMeta, typeParameters: targetTypeParams} |
| 697 | : targetMeta; |
| 698 | |
| 699 | let tcbString = ''; |
| 700 | try { |
| 701 | tcbString = generateTypeCheckBlock( |
| 702 | env, |
| 703 | qualifiedTargetMeta, |
| 704 | `_${typeCheckId}`, |
| 705 | tcbMeta, |
| 706 | domSchemaChecker, |
| 707 | oobRecorder, |
| 708 | ); |
| 709 | } catch (e: any) { |
| 710 | oobRecorder.error( |
| 711 | typeCheckId, |
| 712 | `Error generating TCB for ${comp.className}: ${e?.message || e}`, |
| 713 | {start: comp.classMeta.span.start, end: comp.classMeta.span.end}, |
| 714 | ); |
| 715 | continue; |
| 716 | } |
| 717 | |
| 718 | if (!config.disabledExtendedDiagnostics) { |
| 719 | semanticsDiagnostics.push( |
no test coverage detected