| 1580 | } |
| 1581 | |
| 1582 | class PlainCharacterCursor implements CharacterCursor { |
| 1583 | protected state: CursorState; |
| 1584 | protected file: ParseSourceFile; |
| 1585 | protected input: string; |
| 1586 | protected end: number; |
| 1587 | |
| 1588 | constructor(fileOrCursor: PlainCharacterCursor); |
| 1589 | constructor(fileOrCursor: ParseSourceFile, range: LexerRange); |
| 1590 | constructor(fileOrCursor: ParseSourceFile | PlainCharacterCursor, range?: LexerRange) { |
| 1591 | if (fileOrCursor instanceof PlainCharacterCursor) { |
| 1592 | this.file = fileOrCursor.file; |
| 1593 | this.input = fileOrCursor.input; |
| 1594 | this.end = fileOrCursor.end; |
| 1595 | |
| 1596 | const state = fileOrCursor.state; |
| 1597 | // Note: avoid using `{...fileOrCursor.state}` here as that has a severe performance penalty. |
| 1598 | // In ES5 bundles the object spread operator is translated into the `__assign` helper, which |
| 1599 | // is not optimized by VMs as efficiently as a raw object literal. Since this constructor is |
| 1600 | // called in tight loops, this difference matters. |
| 1601 | this.state = { |
| 1602 | peek: state.peek, |
| 1603 | offset: state.offset, |
| 1604 | line: state.line, |
| 1605 | column: state.column, |
| 1606 | }; |
| 1607 | } else { |
| 1608 | if (!range) { |
| 1609 | throw new Error( |
| 1610 | 'Programming error: the range argument must be provided with a file argument.', |
| 1611 | ); |
| 1612 | } |
| 1613 | this.file = fileOrCursor; |
| 1614 | this.input = fileOrCursor.content; |
| 1615 | this.end = range.endPos; |
| 1616 | this.state = { |
| 1617 | peek: -1, |
| 1618 | offset: range.startPos, |
| 1619 | line: range.startLine, |
| 1620 | column: range.startCol, |
| 1621 | }; |
| 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | clone(): PlainCharacterCursor { |
| 1626 | return new PlainCharacterCursor(this); |
| 1627 | } |
| 1628 | |
| 1629 | peek() { |
| 1630 | return this.state.peek; |
| 1631 | } |
| 1632 | charsLeft() { |
| 1633 | return this.end - this.state.offset; |
| 1634 | } |
| 1635 | diff(other: this) { |
| 1636 | return this.state.offset - other.state.offset; |
| 1637 | } |
| 1638 | |
| 1639 | advance(): void { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…