(textTokenType: TokenType)
| 687 | } |
| 688 | |
| 689 | private _consumeEntity(textTokenType: TokenType): void { |
| 690 | this._beginToken(TokenType.ENCODED_ENTITY); |
| 691 | const start = this._cursor.clone(); |
| 692 | this._cursor.advance(); |
| 693 | if (this._attemptCharCode(chars.$HASH)) { |
| 694 | const isHex = this._attemptCharCode(chars.$x) || this._attemptCharCode(chars.$X); |
| 695 | const codeStart = this._cursor.clone(); |
| 696 | this._attemptCharCodeUntilFn(isDigitEntityEnd); |
| 697 | if (this._cursor.peek() != chars.$SEMICOLON) { |
| 698 | // Advance cursor to include the peeked character in the string provided to the error |
| 699 | // message. |
| 700 | this._cursor.advance(); |
| 701 | const entityType = isHex ? CharacterReferenceType.HEX : CharacterReferenceType.DEC; |
| 702 | throw this._createError( |
| 703 | _unparsableEntityErrorMsg(entityType, this._cursor.getChars(start)), |
| 704 | this._cursor.getSpan(), |
| 705 | ); |
| 706 | } |
| 707 | const strNum = this._cursor.getChars(codeStart); |
| 708 | this._cursor.advance(); |
| 709 | try { |
| 710 | const charCode = parseInt(strNum, isHex ? 16 : 10); |
| 711 | this._endToken([String.fromCodePoint(charCode), this._cursor.getChars(start)]); |
| 712 | } catch { |
| 713 | throw this._createError( |
| 714 | _unknownEntityErrorMsg(this._cursor.getChars(start)), |
| 715 | this._cursor.getSpan(), |
| 716 | ); |
| 717 | } |
| 718 | } else { |
| 719 | const nameStart = this._cursor.clone(); |
| 720 | this._attemptCharCodeUntilFn(isNamedEntityEnd); |
| 721 | if (this._cursor.peek() != chars.$SEMICOLON) { |
| 722 | // No semicolon was found so abort the encoded entity token that was in progress, and treat |
| 723 | // this as a text token |
| 724 | this._beginToken(textTokenType, start); |
| 725 | this._cursor = nameStart; |
| 726 | this._endToken(['&']); |
| 727 | } else { |
| 728 | const name = this._cursor.getChars(nameStart); |
| 729 | this._cursor.advance(); |
| 730 | const char = NAMED_ENTITIES.hasOwnProperty(name) && NAMED_ENTITIES[name]; |
| 731 | if (!char) { |
| 732 | throw this._createError(_unknownEntityErrorMsg(name), this._cursor.getSpan(start)); |
| 733 | } |
| 734 | this._endToken([char, `&${name};`]); |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | private _consumeRawText(consumeEntities: boolean, endMarkerPredicate: () => boolean): void { |
| 740 | this._beginToken(consumeEntities ? TokenType.ESCAPABLE_RAW_TEXT : TokenType.RAW_TEXT); |
no test coverage detected