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

SWC generate wrong sourcemap when have mutibyte character after 1.3.20 #6552

Closed
IWANABETHATGUY opened this issue Nov 30, 2022 · 7 comments · Fixed by #6574
Closed

SWC generate wrong sourcemap when have mutibyte character after 1.3.20 #6552

IWANABETHATGUY opened this issue Nov 30, 2022 · 7 comments · Fixed by #6574
Assignees
Labels
Milestone

Comments

@IWANABETHATGUY
Copy link
Contributor

Describe the bug

Minimal reproduce repo

https://github.com/IWANABETHATGUY/swc-sourcemap-issue

How to reproduce

  1. git clone
  2. pnpm i
  3. node index

@swc/core 1.3.20

image

@swc/core 1.3.21

image

Input code

const xxx = ', something'
console.error(`❌ ${message}`);

const bbb = ''

Config

{
    sourceMaps: true,
    jsc: {
      parser: {
        syntax: "ecmascript",
        jsx: false,
      },
      target: "es5",
      loose: false,
      minify: {
        compress: false,
        mangle: false,
      },
    },
    module: {
      type: "commonjs",
    },
    minify: true,
    isModule: true,
}

Playground link

No response

Expected behavior

Should generate right source map

Actual behavior

No response

Version

@swc/core 1.3.21

Additional context

No response

@kdy1 kdy1 added this to the Planned milestone Nov 30, 2022
@IWANABETHATGUY IWANABETHATGUY changed the title SWC generate wrong position when have mutibyte character after 1.3.20 SWC generate wrong sourcemap when have mutibyte character after 1.3.20 Dec 1, 2022
@kdy1 kdy1 self-assigned this Dec 1, 2022
@kdy1
Copy link
Member

kdy1 commented Dec 2, 2022

So should we revert 47908a4?

@kdy1
Copy link
Member

kdy1 commented Dec 2, 2022

Can you check if it's the cause?

@IWANABETHATGUY
Copy link
Contributor Author

Yeah, I could help

@IWANABETHATGUY
Copy link
Contributor Author

The issue is gone after I revert that pr.

@jridgewell
Copy link
Contributor

This particular issue is caused by bug 2 in #6574.

@IWANABETHATGUY
Copy link
Contributor Author

Thanks

@kdy1 kdy1 closed this as completed in #6574 Dec 4, 2022
kdy1 pushed a commit that referenced this issue Dec 4, 2022
**Description:**

This fixes the BytePos -> CharPos calculation necessary for source maps.
There were a few issues in the old code:

1. UTF-8 maps 1-3 bytes into 1 UTF-16 char, but 4 bytes into 2 UTF-16 chars
2. The starting offset was not recorded when we reached the end of the `multibyte_chars` iteration
3. The `mappings` can be unordered, meaning we need to restart the UTF-16 offset calculation

**Related issue:**

 - Closes #6552.
@kdy1 kdy1 modified the milestones: Planned, v1.3.22 Dec 9, 2022
@swc-bot
Copy link
Collaborator

swc-bot commented Jan 8, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Jan 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

4 participants