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

Class PlainCharacterCursor

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

Source from the content-addressed store, hash-verified

1431}
1432
1433class PlainCharacterCursor implements CharacterCursor {
1434 protected state: CursorState;
1435 protected file: ParseSourceFile;
1436 protected input: string;
1437 protected end: number;
1438
1439 constructor(fileOrCursor: PlainCharacterCursor);
1440 constructor(fileOrCursor: ParseSourceFile, range: LexerRange);
1441 constructor(fileOrCursor: ParseSourceFile | PlainCharacterCursor, range?: LexerRange) {
1442 if (fileOrCursor instanceof PlainCharacterCursor) {
1443 this.file = fileOrCursor.file;
1444 this.input = fileOrCursor.input;
1445 this.end = fileOrCursor.end;
1446
1447 const state = fileOrCursor.state;
1448 // Note: avoid using `{...fileOrCursor.state}` here as that has a severe performance penalty.
1449 // In ES5 bundles the object spread operator is translated into the `__assign` helper, which
1450 // is not optimized by VMs as efficiently as a raw object literal. Since this constructor is
1451 // called in tight loops, this difference matters.
1452 this.state = {
1453 peek: state.peek,
1454 offset: state.offset,
1455 line: state.line,
1456 column: state.column,
1457 };
1458 } else {
1459 if (!range) {
1460 throw new Error(
1461 'Programming error: the range argument must be provided with a file argument.',
1462 );
1463 }
1464 this.file = fileOrCursor;
1465 this.input = fileOrCursor.content;
1466 this.end = range.endPos;
1467 this.state = {
1468 peek: -1,
1469 offset: range.startPos,
1470 line: range.startLine,
1471 column: range.startCol,
1472 };
1473 }
1474 }
1475
1476 clone(): PlainCharacterCursor {
1477 return new PlainCharacterCursor(this);
1478 }
1479
1480 peek() {
1481 return this.state.peek;
1482 }
1483 charsLeft() {
1484 return this.end - this.state.offset;
1485 }
1486 diff(other: this) {
1487 return this.state.offset - other.state.offset;
1488 }
1489
1490 advance(): void {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected