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

Class PlainCharacterCursor

packages/compiler/src/ml_parser/lexer.ts:1616–1735  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1614}
1615
1616class PlainCharacterCursor implements CharacterCursor {
1617 protected state: CursorState;
1618 protected file: ParseSourceFile;
1619 protected input: string;
1620 protected end: number;
1621
1622 constructor(fileOrCursor: PlainCharacterCursor);
1623 constructor(fileOrCursor: ParseSourceFile, range: LexerRange);
1624 constructor(fileOrCursor: ParseSourceFile | PlainCharacterCursor, range?: LexerRange) {
1625 if (fileOrCursor instanceof PlainCharacterCursor) {
1626 this.file = fileOrCursor.file;
1627 this.input = fileOrCursor.input;
1628 this.end = fileOrCursor.end;
1629
1630 const state = fileOrCursor.state;
1631 // Note: avoid using `{...fileOrCursor.state}` here as that has a severe performance penalty.
1632 // In ES5 bundles the object spread operator is translated into the `__assign` helper, which
1633 // is not optimized by VMs as efficiently as a raw object literal. Since this constructor is
1634 // called in tight loops, this difference matters.
1635 this.state = {
1636 peek: state.peek,
1637 offset: state.offset,
1638 line: state.line,
1639 column: state.column,
1640 };
1641 } else {
1642 if (!range) {
1643 throw new Error(
1644 'Programming error: the range argument must be provided with a file argument.',
1645 );
1646 }
1647 this.file = fileOrCursor;
1648 this.input = fileOrCursor.content;
1649 this.end = range.endPos;
1650 this.state = {
1651 peek: -1,
1652 offset: range.startPos,
1653 line: range.startLine,
1654 column: range.startCol,
1655 };
1656 }
1657 }
1658
1659 clone(): PlainCharacterCursor {
1660 return new PlainCharacterCursor(this);
1661 }
1662
1663 peek() {
1664 return this.state.peek;
1665 }
1666 charsLeft() {
1667 return this.end - this.state.offset;
1668 }
1669 diff(other: this) {
1670 return this.state.offset - other.state.offset;
1671 }
1672
1673 advance(): void {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected