MCPcopy Index your code
hub / github.com/angular/angular / _consumeEntity

Method _consumeEntity

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

Source from the content-addressed store, hash-verified

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