| 19 | * Executing this operation returns a reference to the element variable. |
| 20 | */ |
| 21 | export class TcbElementOp extends TcbOp { |
| 22 | constructor( |
| 23 | private tcb: Context, |
| 24 | private scope: Scope, |
| 25 | private element: Element, |
| 26 | ) { |
| 27 | super(); |
| 28 | } |
| 29 | |
| 30 | override get optional() { |
| 31 | // The statement generated by this operation is only used for type-inference of the DOM |
| 32 | // element's type and won't report diagnostics by itself, so the operation is marked as optional |
| 33 | // to avoid generating statements for DOM elements that are never referenced. |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | override execute(): TcbExpr { |
| 38 | const id = this.tcb.allocateId(); |
| 39 | const idNode = new TcbExpr(id); |
| 40 | idNode.addParseSpanInfo(this.element.startSourceSpan || this.element.sourceSpan); |
| 41 | |
| 42 | // Add the declaration of the element using document.createElement. |
| 43 | const initializer = new TcbExpr(`document.createElement("${this.element.name}")`); |
| 44 | initializer.addParseSpanInfo(this.element.startSourceSpan || this.element.sourceSpan); |
| 45 | const stmt = new TcbExpr(`var ${idNode.print()} = ${initializer.print()}`); |
| 46 | stmt.addParseSpanInfo(this.element.startSourceSpan || this.element.sourceSpan); |
| 47 | this.scope.addStatement(stmt); |
| 48 | return idNode; |
| 49 | } |
| 50 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…