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

Class MagicString

src/MagicString.ts:51–1348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51export default class MagicString {
52 declare original: string
53 /** @internal */
54 declare outro: string
55 /** @internal */
56 declare intro: string
57 /** @internal */
58 declare filename: string | undefined
59 declare indentExclusionRanges: MagicStringOptions['indentExclusionRanges']
60 /** @internal */
61 declare ignoreList: boolean | undefined
62 declare offset: number
63 /** @internal */
64 declare firstChunk: Chunk
65 /** @internal */
66 declare lastChunk: Chunk
67 /** @internal */
68 declare lastSearchedChunk: Chunk
69 /** @internal */
70 declare byStart: Map<number, Chunk>
71 /** @internal */
72 declare byEnd: Map<number, Chunk>
73 /** @internal */
74 declare sourcemapLocations: BitSet
75 /** @internal */
76 declare storedNames: Record<string, true>
77 /** @internal */
78 declare indentStr: string | null | undefined
79 /** @internal */
80 declare stats: Stats
81 /** @internal */
82 declare hasMovedChunks: boolean
83
84 constructor(string: string, options: MagicStringOptions = {}) {
85 const chunk = new Chunk(0, string.length, string)
86
87 Object.defineProperties(this, {
88 original: { writable: true, value: string },
89 outro: { writable: true, value: '' },
90 intro: { writable: true, value: '' },
91 firstChunk: { writable: true, value: chunk },
92 lastChunk: { writable: true, value: chunk },
93 lastSearchedChunk: { writable: true, value: chunk },
94 byStart: { writable: true, value: new Map<number, Chunk>([[0, chunk]]) },
95 byEnd: { writable: true, value: new Map<number, Chunk>([[string.length, chunk]]) },
96 filename: { writable: true, value: options.filename },
97 indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
98 sourcemapLocations: { writable: true, value: new BitSet() },
99 storedNames: { writable: true, value: {} },
100 indentStr: { writable: true, value: undefined },
101 ignoreList: { writable: true, value: options.ignoreList },
102 offset: { writable: true, value: options.offset || 0 },
103 hasMovedChunks: { writable: true, value: false },
104 })
105
106 if (DEBUG) {
107 Object.defineProperty(this, 'stats', { value: new Stats() })
108 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected