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

Class TcbEnvironmentImpl

packages/compiler-cli/preprocessor/src/tcb.ts:497–583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

495}
496
497export class TcbEnvironmentImpl implements TcbEnvironment {
498 private readonly nextIds = {
499 pipeInst: 1,
500 typeCtor: 1,
501 };
502
503 private readonly typeCtors = new Map<TcbReferenceKey, string>();
504 private readonly typeCtorStatements: TcbExpr[] = [];
505
506 private readonly pipeInsts = new Map<TcbReferenceKey, string>();
507 private readonly pipeInstStatements: TcbExpr[] = [];
508
509 constructor(
510 readonly config: TypeCheckingConfig,
511 private readonly importManager: TcbImportManager,
512 private readonly isInline: boolean = false,
513 ) {}
514
515 referenceTcbValue(ref: TcbReferenceMetadata): TcbExpr {
516 if (ref.unexportedDiagnostic !== null || ref.isLocal || ref.moduleName === null) {
517 if (ref.unexportedDiagnostic !== null) {
518 throw new Error(`Unable to import symbol ${ref.name}: ${ref.unexportedDiagnostic}`);
519 }
520 return new TcbExpr(ref.name);
521 }
522 return this.referenceExternalSymbol(ref.moduleName, ref.name);
523 }
524
525 referenceExternalSymbol(moduleName: string, name: string): TcbExpr {
526 const alias = this.importManager.addImport(moduleName);
527 return new TcbExpr(`${alias}.${name}`);
528 }
529
530 typeCtorFor(dir: TcbDirectiveMetadata): TcbExpr {
531 if (this.typeCtors.has(dir.ref.key)) {
532 return new TcbExpr(this.typeCtors.get(dir.ref.key)!);
533 }
534
535 if (dir.requiresInlineTypeCtor) {
536 const typeCtorExpr = `${this.referenceTcbValue(dir.ref).print()}.ngTypeCtor`;
537 this.typeCtors.set(dir.ref.key, typeCtorExpr);
538 return new TcbExpr(typeCtorExpr);
539 } else {
540 const fnName = `_ctor${this.nextIds.typeCtor++}`;
541 const nodeTypeRef = this.referenceTcbValue(dir.ref);
542 const meta: TypeCtorMetadata = {
543 fnName,
544 body: true,
545 fields: {
546 inputs: dir.inputs,
547 },
548 coercedInputFields: dir.coercedInputFields,
549 };
550
551 const typeParams = dir.typeParameters
552 ? qualifyTypeParameters(dir.typeParameters, this, dir.ref.moduleName)
553 : undefined;
554 const typeCtor = generateTypeCtorDeclarationFn(this, meta, nodeTypeRef, typeParams);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected