| 47 | * Executing this operation returns a reference to the variable variable (lol). |
| 48 | */ |
| 49 | export 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) {}`). |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…