Rich-Harris / magic-string

Manipulate strings like a wizard
MIT License
2.37k stars 113 forks source link

Bug: Incorrect error message on negative start position for `remove` #260

Open rschristian opened 1 year ago

rschristian commented 1 year ago
import MagicString from 'https://esm.sh/magic-string';

const s = new MagicString('problems = 99');

s.remove(-1, 5);

Uncaught Error: end must be greater than start

Lead me on a bit of a wild goose chase before I realized the issue was with the start position, not that the end was somehow less than the start.

sapphi-red commented 1 year ago

It seems it works like String::slice. https://github.com/Rich-Harris/magic-string/blob/8e77538d1d03feefe9b114cdff31fba2ef243b4d/src/MagicString.js#L471-L473