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

Class PlainCharacterCursor

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected