(index)
| 95 | } |
| 96 | |
| 97 | split(index) { |
| 98 | const sliceIndex = index - this.start; |
| 99 | |
| 100 | const originalBefore = this.original.slice(0, sliceIndex); |
| 101 | const originalAfter = this.original.slice(sliceIndex); |
| 102 | |
| 103 | this.original = originalBefore; |
| 104 | |
| 105 | const newChunk = new Chunk(index, this.end, originalAfter); |
| 106 | newChunk.outro = this.outro; |
| 107 | this.outro = ''; |
| 108 | |
| 109 | this.end = index; |
| 110 | |
| 111 | if (this.edited) { |
| 112 | // after split we should save the edit content record into the correct chunk |
| 113 | // to make sure sourcemap correct |
| 114 | // For example: |
| 115 | // ' test'.trim() |
| 116 | // split -> ' ' + 'test' |
| 117 | // ✔️ edit -> '' + 'test' |
| 118 | // ✖️ edit -> 'test' + '' |
| 119 | // TODO is this block necessary?... |
| 120 | newChunk.edit('', false); |
| 121 | this.content = ''; |
| 122 | } else { |
| 123 | this.content = originalBefore; |
| 124 | } |
| 125 | |
| 126 | newChunk.next = this.next; |
| 127 | if (newChunk.next) newChunk.next.previous = newChunk; |
| 128 | newChunk.previous = this; |
| 129 | this.next = newChunk; |
| 130 | |
| 131 | return newChunk; |
| 132 | } |
| 133 | |
| 134 | toString() { |
| 135 | return this.intro + this.content + this.outro; |
no test coverage detected