(start?: Pos, end?: Pos)
| 504 | } |
| 505 | |
| 506 | slice(start?: Pos, end?: Pos) { |
| 507 | if (!end) { |
| 508 | if (!start) { |
| 509 | // The client seems to want a copy of this Lines object, but |
| 510 | // Lines objects are immutable, so it's perfectly adequate to |
| 511 | // return the same object. |
| 512 | return this; |
| 513 | } |
| 514 | |
| 515 | // Slice to the end if no end position was provided. |
| 516 | end = this.lastPos(); |
| 517 | } |
| 518 | |
| 519 | if (!start) { |
| 520 | throw new Error("cannot slice with end but not start"); |
| 521 | } |
| 522 | |
| 523 | const sliced = this.infos.slice(start.line - 1, end.line); |
| 524 | |
| 525 | if (start.line === end.line) { |
| 526 | sliced[0] = sliceInfo(sliced[0], start.column, end.column); |
| 527 | } else { |
| 528 | assert.ok(start.line < end.line); |
| 529 | sliced[0] = sliceInfo(sliced[0], start.column); |
| 530 | sliced.push(sliceInfo(sliced.pop(), 0, end.column)); |
| 531 | } |
| 532 | |
| 533 | const lines = new Lines(sliced); |
| 534 | |
| 535 | if (this.mappings.length > 0) { |
| 536 | const newMappings = lines.mappings; |
| 537 | assert.strictEqual(newMappings.length, 0); |
| 538 | this.mappings.forEach(function (this: any, mapping: any) { |
| 539 | const sliced = mapping.slice(this, start, end); |
| 540 | if (sliced) { |
| 541 | newMappings.push(sliced); |
| 542 | } |
| 543 | }, this); |
| 544 | } |
| 545 | |
| 546 | return lines; |
| 547 | } |
| 548 | |
| 549 | bootstrapSliceString(start: Pos, end: Pos, options?: Options) { |
| 550 | return this.slice(start, end).toString(options); |
no test coverage detected