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