# What changed in magic-string

> 40 changes in magic-string 1 from its official release notes, upgrade guides and advisories: 4 breaking, 5 new APIs and options. Each one cited. Sources checked 2026-10-17. HTML: https://unstale.sh/npm/magic-string/

To see which of these apply to a repository, run `npx @unstale/cli init` in it.

## magic-string 1

### Breaking changes

- Separators between sources are trimmed, changing how bundled sources are joined. (1.2.3) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.2.3)
- Indices below -length are clamped instead of wrapping repeatedly. (1.2.3) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.2.3)
- An overlapping move now throws instead of corrupting the chunk list. (1.2.1) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.2.1)
- The package is now pure ESM; the CJS, UMD, and IIFE builds have been dropped. (1.0.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.0.0)

### New APIs and options

- Adds an affinity option to move(). (1.4.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.4.0)
- Adds toMagicString() to flatten a Bundle into a MagicString. (1.4.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.4.0)
- includeContent in Bundle now supports a function. (1.3.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.3.0)
- Adds a high-resolution source map mode using range mappings. (1.3.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.3.0)
- Introduces MagicStringError with concise, consistent messages. (1.2.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.2.0)

### Performance

- Looks up removed content without scanning every chunk. (1.4.2) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.4.2)
- Encodes mappings incrementally to reduce peak memory usage. (1.4.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.4.0)
- Avoids split() when locating lines. (1.3.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.3.0)
- Walks unedited chunks line by line when generating mappings. (1.3.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.3.0)
- hasChanged is optimized. (1.2.2) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.2.2)
- A fast path was added for non-exclusion indentation. (1.0.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.0.0)

### Fixes and other changes

- Fixes replacement of matched text when an offset is set. (1.4.3) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.4.3)
- Preserves inserts when update spans several chunks. (1.4.3) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.4.3)
- Keeps the outro when splitting a removed chunk. (1.4.2) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.4.2)
- Skips empty matches inside removed content. (1.4.2) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.4.2)
- Flushes the shared encoder buffer at the end of every drain. (1.4.1) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.4.1)
- Carries trimStart and trimEnd into the intro and outro. (1.3.2) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.3.2)
- Treats moving a range to where it already sits as a no-op. (1.3.2) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.3.2)
- Carries trimStart and trimEnd into the intro and outro. (1.3.2) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.3.2)
- Preserves inserts anchored to the edges of a removed range. (1.3.2) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.3.2)
- Returns an empty slice when the end index resolves to zero. (1.3.2) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.3.2)
- Content added with append or prepend is now indented. (1.3.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.3.0)
- Bundle#length now counts source appends and prepends. (1.3.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.3.0)
- Now counts string-level appends and prepends. (1.3.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.3.0)
- Expands $ substitutions as String.prototype does. (1.3.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.3.0)
- Only passes the groups object when the pattern has named groups. (1.3.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.3.0)
- Indentation in a bundle is guessed from its most common indentation. (1.2.3) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.2.3)
- Empty matches are handled in replace. (1.2.3) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.2.3)
- Empty matches are handled in replaceAll. (1.2.3) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.2.3)
- Cloning now keeps the ignore-list hint and stored names. (1.2.2) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.2.2)
- hasChanged now reports a change when an edit spans a chunk boundary. (1.2.2) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.2.2)
- Bundle#isEmpty now counts separators when determining whether a bundle is empty. (1.2.1) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.2.1)
- Bundle#length counts separators. (1.1.1) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.1.1)
- update() validates its range and includes indices in range errors. (1.1.1) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.1.1)
- Replacements longer than the range they replace are trimmed. (1.1.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.1.0)
- Moving a zero-length range no longer crashes. (1.0.0) — [release notes](https://github.com/Rich-Harris/magic-string/releases/tag/v1.0.0)
