| 97 | } |
| 98 | |
| 99 | build(): void { |
| 100 | while (this._peek.type !== TokenType.EOF) { |
| 101 | if ( |
| 102 | this._peek.type === TokenType.TAG_OPEN_START || |
| 103 | this._peek.type === TokenType.INCOMPLETE_TAG_OPEN |
| 104 | ) { |
| 105 | this._consumeElementStartTag(this._advance()); |
| 106 | } else if (this._peek.type === TokenType.TAG_CLOSE) { |
| 107 | this._consumeElementEndTag(this._advance()); |
| 108 | } else if (this._peek.type === TokenType.CDATA_START) { |
| 109 | this._closeVoidElement(); |
| 110 | this._consumeCdata(this._advance()); |
| 111 | } else if (this._peek.type === TokenType.COMMENT_START) { |
| 112 | this._closeVoidElement(); |
| 113 | this._consumeComment(this._advance()); |
| 114 | } else if ( |
| 115 | this._peek.type === TokenType.TEXT || |
| 116 | this._peek.type === TokenType.RAW_TEXT || |
| 117 | this._peek.type === TokenType.ESCAPABLE_RAW_TEXT |
| 118 | ) { |
| 119 | this._closeVoidElement(); |
| 120 | this._consumeText(this._advance()); |
| 121 | } else if (this._peek.type === TokenType.EXPANSION_FORM_START) { |
| 122 | this._consumeExpansion(this._advance()); |
| 123 | } else if (this._peek.type === TokenType.BLOCK_OPEN_START) { |
| 124 | this._closeVoidElement(); |
| 125 | this._consumeBlockOpen(this._advance()); |
| 126 | } else if (this._peek.type === TokenType.BLOCK_CLOSE) { |
| 127 | this._closeVoidElement(); |
| 128 | this._consumeBlockClose(this._advance()); |
| 129 | } else if (this._peek.type === TokenType.INCOMPLETE_BLOCK_OPEN) { |
| 130 | this._closeVoidElement(); |
| 131 | this._consumeIncompleteBlock(this._advance()); |
| 132 | } else if (this._peek.type === TokenType.LET_START) { |
| 133 | this._closeVoidElement(); |
| 134 | this._consumeLet(this._advance()); |
| 135 | } else if (this._peek.type === TokenType.INCOMPLETE_LET) { |
| 136 | this._closeVoidElement(); |
| 137 | this._consumeIncompleteLet(this._advance()); |
| 138 | } else { |
| 139 | // Skip all other tokens... |
| 140 | this._advance(); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | for (const leftoverContainer of this._containerStack) { |
| 145 | // Unlike HTML elements, blocks aren't closed implicitly by the end of the file. |
| 146 | if (leftoverContainer instanceof html.Block) { |
| 147 | this.errors.push( |
| 148 | TreeError.create( |
| 149 | leftoverContainer.name, |
| 150 | leftoverContainer.sourceSpan, |
| 151 | `Unclosed block "${leftoverContainer.name}"`, |
| 152 | ), |
| 153 | ); |
| 154 | } |
| 155 | } |
| 156 | } |