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

Wrong mappings when update or overwrite end with new line #273

Closed
dummdidumm opened this issue Feb 28, 2024 · 0 comments · Fixed by #274
Closed

Wrong mappings when update or overwrite end with new line #273

dummdidumm opened this issue Feb 28, 2024 · 0 comments · Fixed by #274

Comments

@dummdidumm
Copy link
Contributor

const s = new MagicString('foobar');
s.update(2, 3, 'od\n');
s.update(4, 5, 'a\nnd\n');

does produce wrong mappings. When the string passed to update or overwrite ends with a new line, the mappings will contain two entries for column zero. This happens because in #261 the loop does not bail if the last line is empty, filling two lines with the same mapping.
This is currently blocking Svelte language tools from bumping magic-string to the latest version.

dummdidumm added a commit to dummdidumm/magic-string that referenced this issue Feb 28, 2024
When the string passed to update or overwrite ends with a new line, the mappings will contain two entries for column zero. This happens because the loop does not bail if the last line is empty, filling two lines with the same mapping. This commit fixes that.
Fixes Rich-Harris#273
@antfu antfu closed this as completed in #274 Mar 3, 2024
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

Successfully merging a pull request may close this issue.

1 participant