| 18 | * Executing this operation returns a reference to the element variable. |
| 19 | */ |
| 20 | export class TcbHostElementOp extends TcbOp { |
| 21 | override readonly optional = true; |
| 22 | |
| 23 | constructor( |
| 24 | private tcb: Context, |
| 25 | private scope: Scope, |
| 26 | private element: HostElement, |
| 27 | ) { |
| 28 | super(); |
| 29 | } |
| 30 | |
| 31 | override execute(): TcbExpr { |
| 32 | const id = this.tcb.allocateId(); |
| 33 | let tagNames: string; |
| 34 | |
| 35 | if (this.element.tagNames.length === 1) { |
| 36 | tagNames = `"${this.element.tagNames[0]}"`; |
| 37 | } else { |
| 38 | tagNames = `null! as ${this.element.tagNames.map((t) => `"${t}"`).join(' | ')}`; |
| 39 | } |
| 40 | |
| 41 | const initializer = new TcbExpr(`document.createElement(${tagNames})`); |
| 42 | initializer.addParseSpanInfo(this.element.sourceSpan); |
| 43 | this.scope.addStatement(new TcbExpr(`var ${id} = ${initializer.print()}`)); |
| 44 | return new TcbExpr(id); |
| 45 | } |
| 46 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…