Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rschristian opened this issue Sep 4, 2023 · 1 comment
Open

Comments

@rschristian
Copy link

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
Copy link
Contributor

It seems it works like String::slice.

remove(start, end) {
while (start < 0) start += this.original.length;
while (end < 0) end += this.original.length;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants