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

fix(swc_ecma_codegen): fix LineCol calculation of printed files #6763

Merged
merged 1 commit into from
Jan 8, 2023

Conversation

jridgewell
Copy link
Contributor

Description:

There were several issues with the way we updated the current LineCol position during the printing of the generated file:

  • We used chars and char_indices (UTF-32) instead of encode_utf16 (UTF-16) chars.
    • JS uses UCS-2 (basically UTF-16) for its strings, and sourcemaps default to that implicitly.
  • \r was incorrectly handled
    • it didn't add a line_start, only \n did
  • \r\n was incorrectly handled
    • It was trying to let \n path handle the line_start, but it called chars.next() which ate the \n char.

I also took the opportunity to avoid the Vec allocations and reduced some code duplication.

See the before and after

BREAKING CHANGE:

Related issue (if exists):

Fixes #6694

There were several issues with the way we updated the current `LineCol` position during the printing of the generated file:

- We used `chars` and `char_indices` (UTF-32) instead of `encode_utf16` (UTF-16) chars.
  - JS uses UCS-2 (basically UTF-16) for its strings, and sourcemaps default to that implicitly.
- `\r` was incorrectly handled
  - it didn't add a `line_start`, only `\n` did
- `\r\n` was incorrectly handled
  - It was trying to let `\n` path handle the `line_start`, but it called `chars.next()` which ate the `\n` char.

I also took the opportunity to avoid the `Vec` allocations and reduced some code duplication.
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!


swc-bump:

  • swc_common

@kdy1 kdy1 merged commit 2b503c1 into swc-project:main Jan 8, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.26 Jan 8, 2023
@swc-project swc-project locked as resolved and limited conversation to collaborators Feb 10, 2023
@jridgewell jridgewell deleted the fix-sourcemap-gen branch February 10, 2023 17:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Windows line endings break source maps
2 participants