MCPcopy Index your code
hub / github.com/angular/angular / TcbTemplateVariableOp

Class TcbTemplateVariableOp

packages/compiler/src/typecheck/ops/variables.ts:49–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47 * Executing this operation returns a reference to the variable variable (lol).
48 */
49export class TcbTemplateVariableOp extends TcbOp {
50 constructor(
51 private tcb: Context,
52 private scope: Scope,
53 private template: Template,
54 private variable: Variable,
55 ) {
56 super();
57 }
58
59 override get optional() {
60 return false;
61 }
62
63 override execute(): TcbExpr {
64 // Look for a context variable for the template.
65 const ctx = this.scope.resolve(this.template);
66
67 // Allocate an identifier for the Variable, and initialize it to a read of the variable
68 // on the template context.
69 const id = new TcbExpr(this.tcb.allocateId());
70 const initializer = new TcbExpr(`${ctx.print()}.${this.variable.value || '$implicit'}`);
71 id.addParseSpanInfo(this.variable.keySpan);
72
73 // Declare the variable, and return its identifier.
74 if (this.variable.valueSpan !== undefined) {
75 initializer.addParseSpanInfo(this.variable.valueSpan).wrapForTypeChecker();
76 } else {
77 }
78 const variable = new TcbExpr(`var ${id.print()} = ${initializer.print()}`);
79 variable.addParseSpanInfo(this.variable.sourceSpan);
80 this.scope.addStatement(variable);
81 return id;
82 }
83}
84
85/**
86 * A `TcbOp` which renders a variable defined inside of block syntax (e.g. `@if (expr; as var) {}`).

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…