npm / magic-string
magic-string
What changed in magic-string 1, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-30.
5 breaking5 new APIs and options8 performance30 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initmagic-string 148 changes
Breaking changes 5
Non-integer and out-of-range indices are now rejected consistently.
Separators between sources are trimmed, changing how bundled sources are joined.
Indices below -length are clamped instead of wrapping repeatedly.
An overlapping move now throws instead of corrupting the chunk list.
The package is now pure ESM; the CJS, UMD, and IIFE builds have been dropped.
New APIs and options 5
Adds an affinity option to move().
Adds toMagicString() to flatten a Bundle into a MagicString.
includeContent in Bundle now supports a function.
Adds a high-resolution source map mode using range mappings.
Introduces MagicStringError with concise, consistent messages.
Performance 8
The slice start chunk is found without scanning the list.
These paths use fewer allocations and avoid quadratic lookups.
Looks up removed content without scanning every chunk.
Encodes mappings incrementally to reduce peak memory usage.
Avoids split() when locating lines.
Walks unedited chunks line by line when generating mappings.
hasChanged is optimized.
A fast path was added for non-exclusion indentation.
Fixes and other changes 30
The method now shifts replacesUntil and replacedFrom correctly.
Indent exclusions are respected on moved edits and CRLF bundle intros.
The stored name is preserved when an overwritten range is split.
Empty matches at a chunk boundary inside removed content are skipped.
snip now respects the offset.
Content is kept when update throws across a split point.
Fixes replacement of matched text when an offset is set.
Preserves inserts when update spans several chunks.
Keeps the outro when splitting a removed chunk.
Skips empty matches inside removed content.
Flushes the shared encoder buffer at the end of every drain.
Carries trimStart and trimEnd into the intro and outro.
Treats moving a range to where it already sits as a no-op.
Preserves inserts anchored to the edges of a removed range.
Returns an empty slice when the end index resolves to zero.
Content added with append or prepend is now indented.
Bundle#length now counts source appends and prepends.
Now counts string-level appends and prepends.
Expands $ substitutions as String.prototype does.
Only passes the groups object when the pattern has named groups.
Indentation in a bundle is guessed from its most common indentation.
Empty matches are handled in replace.
Empty matches are handled in replaceAll.
Cloning now keeps the ignore-list hint and stored names.
hasChanged now reports a change when an edit spans a chunk boundary.
Bundle#isEmpty now counts separators when determining whether a bundle is empty.
Bundle#length counts separators.
update() validates its range and includes indices in range errors.
Replacements longer than the range they replace are trimmed.
Moving a zero-length range no longer crashes.