MCPcopy Create free account
hub / github.com/angular/angular / _consumeEntity

Method _consumeEntity

packages/compiler/src/ml_parser/lexer.ts:704–752  ·  view source on GitHub ↗
(textTokenType: TokenType)

Source from the content-addressed store, hash-verified

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

Callers 2

_consumeRawTextMethod · 0.95

Calls 12

_beginTokenMethod · 0.95
_attemptCharCodeMethod · 0.95
_createErrorMethod · 0.95
_endTokenMethod · 0.95
_unknownEntityErrorMsgFunction · 0.85
cloneMethod · 0.65
advanceMethod · 0.65
peekMethod · 0.65
getCharsMethod · 0.65
getSpanMethod · 0.65

Tested by

no test coverage detected