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

Class InlineTcbOp

packages/compiler-cli/src/ngtsc/typecheck/src/context.ts:720–768  ·  view source on GitHub ↗

* A type check block operation which produces inline type check code for a particular directive.

Source from the content-addressed store, hash-verified

718 * A type check block operation which produces inline type check code for a particular directive.
719 */
720class InlineTcbOp implements Op {
721 constructor(
722 readonly ref: Reference<ClassDeclaration<ts.ClassDeclaration>>,
723 readonly meta: TypeCheckBlockMetadata,
724 readonly config: TypeCheckingConfig,
725 readonly reflector: ReflectionHost,
726 readonly domSchemaChecker: DomSchemaChecker<unknown>,
727 readonly oobRecorder: OutOfBandDiagnosticRecorder<unknown>,
728 ) {}
729
730 /**
731 * Type check blocks are inserted immediately after the end of the directive class.
732 */
733 get splitPoint(): number {
734 return this.ref.node.end;
735 }
736
737 execute(im: ImportManager, tcbSf: ts.SourceFile, refEmitter: ReferenceEmitter): string {
738 const env = new Environment(this.config, im, refEmitter, tcbSf);
739 const originalSf = this.ref.node.getSourceFile();
740 if (tcbSf !== originalSf) {
741 env.copiedSourceOriginPath = absoluteFromSourceFile(originalSf);
742 }
743 const fnName = `${TCB_FUNCTION_PREFIX}_${this.ref.node.pos}`;
744
745 const {tcbMeta, component} = adaptTypeCheckBlockMetadata(
746 this.ref,
747 this.meta,
748 env,
749 this.reflector,
750 TcbGenericContextBehavior.CopyClassNodes,
751 );
752
753 // Inline TCBs should copy any generic type parameter nodes directly, as the TCB code is
754 // inlined into the class in a context where that will always be legal.
755 const fn = generateTypeCheckBlock(
756 env,
757 component,
758 fnName,
759 tcbMeta,
760 this.domSchemaChecker,
761 this.oobRecorder,
762 );
763
764 // A leading newline is required so that the generated TCB isn't accidentally
765 // appended as part of a trailing single-line comment (e.g. `// comment`).
766 return `\n${fn}`;
767 }
768}
769
770/**
771 * A type constructor operation which produces type constructor code for a particular directive.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected