(token: InterpolatedTextToken)
| 335 | } |
| 336 | |
| 337 | private _consumeText(token: InterpolatedTextToken) { |
| 338 | const tokens = [token]; |
| 339 | const startSpan = token.sourceSpan; |
| 340 | let text = token.parts[0]; |
| 341 | if (text.length > 0 && text[0] === '\n') { |
| 342 | const parent = this._getContainer(); |
| 343 | |
| 344 | if ( |
| 345 | parent != null && |
| 346 | parent.children.length === 0 && |
| 347 | this._getTagDefinition(parent)?.ignoreFirstLf |
| 348 | ) { |
| 349 | text = text.substring(1); |
| 350 | tokens[0] = {type: token.type, sourceSpan: token.sourceSpan, parts: [text]} as typeof token; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | while ( |
| 355 | this._peek.type === TokenType.INTERPOLATION || |
| 356 | this._peek.type === TokenType.TEXT || |
| 357 | this._peek.type === TokenType.ENCODED_ENTITY |
| 358 | ) { |
| 359 | token = this._advance(); |
| 360 | tokens.push(token); |
| 361 | if (token.type === TokenType.INTERPOLATION) { |
| 362 | // For backward compatibility we decode HTML entities that appear in interpolation |
| 363 | // expressions. This is arguably a bug, but it could be a considerable breaking change to |
| 364 | // fix it. It should be addressed in a larger project to refactor the entire parser/lexer |
| 365 | // chain after View Engine has been removed. |
| 366 | text += token.parts.join('').replace(/&([^;]+);/g, decodeEntity); |
| 367 | } else if (token.type === TokenType.ENCODED_ENTITY) { |
| 368 | text += token.parts[0]; |
| 369 | } else { |
| 370 | text += token.parts.join(''); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | if (text.length > 0) { |
| 375 | const endSpan = token.sourceSpan; |
| 376 | this._addToParent( |
| 377 | new html.Text( |
| 378 | text, |
| 379 | new ParseSourceSpan(startSpan.start, endSpan.end, startSpan.fullStart, startSpan.details), |
| 380 | tokens, |
| 381 | ), |
| 382 | ); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | private _closeVoidElement(): void { |
| 387 | const el = this._getContainer(); |
no test coverage detected