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

Sourcemap shifting with multiline template strings in jest #2185

Closed
hjkcai opened this issue Aug 30, 2021 · 2 comments · Fixed by #3003
Closed

Sourcemap shifting with multiline template strings in jest #2185

hjkcai opened this issue Aug 30, 2021 · 2 comments · Fixed by #3003
Labels
Milestone

Comments

@hjkcai
Copy link

hjkcai commented Aug 30, 2021

Describe the bug
The sourcemap has shifting when testing in jest with multiline template strings. This problem will disappear after removing target option in swcrc.

See the screenshot below:

image

However, I cannot reproduce if I use swc cli directly. Everything seems be fine when I upload the source and the sourcemap to source-map-visualization. I have no idea whether this issue is related to jest or swc.

image

Input code

https://github.com/hjkcai/jest-swc-source-map-shifting

describe("foo", () => {
  it("test1", () => {
    expect(false).toBe(true);
  });

  it("test2", () => {
    const str = `
      bar
    `;

    expect(false).toBe(true);
  });

  it("test3", () => {
    expect(false).toBe(true);
  });
});

Config

{
  "sourceMaps": true,
  "jsc": {
    "target": "es2015"
  }
}

Expected behavior
The sourcemap correctly maps back to the source.

Version
The version of @swc/core: latest (1.2.83)

@hjkcai hjkcai added the C-bug label Aug 30, 2021
@kdy1 kdy1 modified the milestones: v1.2.92, v1.2.93, v1.2.94 Sep 27, 2021
@kdy1 kdy1 modified the milestones: v1.2.94, v1.2.95, v1.2.96, v1.2.97 Oct 8, 2021
@kdy1 kdy1 modified the milestones: v1.2.103, v1.2.104, v1.2.105, v1.2.106 Oct 25, 2021
@kdy1 kdy1 modified the milestones: v1.2.110, v1.2.111, v1.2.112 Nov 17, 2021
@kdy1 kdy1 modified the milestones: v1.2.112, v1.2.113 Nov 24, 2021
@ihm-tswow
Copy link

Looks like this is indeed an issue with swc, it also messes up sourcemaps for source-map-support with TypeScript.

The same thing also happens with multi-line comments:

/**
 * This is a
 * long
 * license
 * header
 */
console.log(new Error().stack)

Some findings:

  • Single-line template strings (`string`) or multiline comments (/** comment */) are unaffected and work fine
  • The issue more precisely seems to be that multiline comment / template string lines counts as two lines, for every new line i add to them, two are added to the output sourcemap.
@swc/cli: 0.1.52
@swc/core: 1.2.112
{
    "module": {
        "type":"commonjs"
    },
    "exclude":[".*.js$",".*\\.d.ts$"],
    "jsc": {
        "parser": {
            "syntax": "typescript",
            "tsx": false,
            "decorators": true,
            "dynamicImport": true
        },
        "target":"es2016",
    },
    "sourceMaps": true
}

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 20, 2022

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 Oct 20, 2022
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