Rich-Harris/magic-string

[Feature request] Add method to restore previously removed range

aleclarson opened this issue · 3 comments

const string = new MagicString("abcd")

string.remove(0, 3)
string.toString() // => "d"

// ...later on...
string.restore(2, 3)
string.toString() // => "cd"

Why not just insert the removed range with existing methods?
Because then I wouldn't be able to insert new content into the restored range.

👉 Example: https://stackblitz.com/edit/node-1gmfpo?file=index.js (backup gist)

antfu commented

That makes sense to me. PR welcome :)