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

Method _consumeEntity

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

Source from the content-addressed store, hash-verified

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

Callers 2

_consumeRawTextMethod · 0.95

Calls 13

_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