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

Class MagicString

src/MagicString.ts:140–1612  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138}
139
140export class MagicString {
141 declare original: string
142 /** @internal */
143 declare outro: string
144 /** @internal */
145 declare intro: string
146 /** @internal */
147 declare filename: string | undefined
148 declare indentExclusionRanges: MagicStringOptions['indentExclusionRanges']
149 /** @internal */
150 declare ignoreList: boolean | undefined
151 declare offset: number
152 /** @internal */
153 declare firstChunk: Chunk
154 /** @internal */
155 declare lastChunk: Chunk
156 /** @internal */
157 declare lastSearchedChunk: Chunk
158 /** @internal */
159 declare byStart: Map<number, Chunk>
160 /** @internal */
161 declare byEnd: Map<number, Chunk>
162 /** @internal */
163 declare sourcemapLocations: BitSet
164 /** @internal */
165 declare storedNames: Record<string, true>
166 /** @internal */
167 declare indentStr: string | null | undefined
168 /** @internal */
169 declare stats: Stats
170 /** @internal */
171 declare hasMovedChunks: boolean
172
173 constructor(string: string, options: MagicStringOptions = {}) {
174 const chunk = new Chunk(0, string.length, string)
175
176 Object.defineProperties(this, {
177 original: { writable: true, value: string },
178 outro: { writable: true, value: '' },
179 intro: { writable: true, value: '' },
180 firstChunk: { writable: true, value: chunk },
181 lastChunk: { writable: true, value: chunk },
182 lastSearchedChunk: { writable: true, value: chunk },
183 byStart: { writable: true, value: new Map<number, Chunk>([[0, chunk]]) },
184 byEnd: { writable: true, value: new Map<number, Chunk>([[string.length, chunk]]) },
185 filename: { writable: true, value: options.filename },
186 indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
187 sourcemapLocations: { writable: true, value: new BitSet() },
188 storedNames: { writable: true, value: {} },
189 indentStr: { writable: true, value: undefined },
190 ignoreList: { writable: true, value: options.ignoreList },
191 offset: { writable: true, value: options.offset || 0 },
192 hasMovedChunks: { writable: true, value: false },
193 })
194
195 /* v8 ignore next 3 -- DEBUG is always true in tests */
196 if (DEBUG) {
197 Object.defineProperty(this, 'stats', { value: new Stats() })

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected