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

Class MagicString

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected