(index: number)
| 113 | } |
| 114 | |
| 115 | split(index: number): Chunk { |
| 116 | const sliceIndex = index - this.start |
| 117 | |
| 118 | const originalBefore = this.original.slice(0, sliceIndex) |
| 119 | const originalAfter = this.original.slice(sliceIndex) |
| 120 | |
| 121 | this.original = originalBefore |
| 122 | |
| 123 | const newChunk = new Chunk(index, this.end, originalAfter) |
| 124 | newChunk.outro = this.outro |
| 125 | this.outro = '' |
| 126 | |
| 127 | this.end = index |
| 128 | |
| 129 | if (this.edited) { |
| 130 | // after split we should save the edit content record into the correct chunk |
| 131 | // to make sure sourcemap correct |
| 132 | // For example: |
| 133 | // ' test'.trim() |
| 134 | // split -> ' ' + 'test' |
| 135 | // ✔️ edit -> '' + 'test' |
| 136 | // ✖️ edit -> 'test' + '' |
| 137 | // TODO is this block necessary?... |
| 138 | newChunk.edit('', false) |
| 139 | this.content = '' |
| 140 | } |
| 141 | else { |
| 142 | this.content = originalBefore |
| 143 | } |
| 144 | |
| 145 | newChunk.next = this.next |
| 146 | if (newChunk.next) |
| 147 | newChunk.next.previous = newChunk |
| 148 | newChunk.previous = this |
| 149 | this.next = newChunk |
| 150 | |
| 151 | return newChunk |
| 152 | } |
| 153 | |
| 154 | toString(): string { |
| 155 | return this.intro + this.content + this.outro |
no test coverage detected