MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / split

Method split

src/Chunk.js:97–132  ·  view source on GitHub ↗
(index)

Source from the content-addressed store, hash-verified

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;

Callers 10

trimEndMethod · 0.95
trimStartMethod · 0.95
generateDecodedMapMethod · 0.45
_splitChunkMethod · 0.45
generateDecodedMapMethod · 0.45
advanceMethod · 0.45
getRelativePathFunction · 0.45
guessIndentFunction · 0.45
getLocatorFunction · 0.45

Calls 2

editMethod · 0.95
sliceMethod · 0.45

Tested by

no test coverage detected