Skip to content

Incorrect sourcemap generated for code with indented multiline template literals #2900

@airhorns

Description

@airhorns

Describe the bug

In the process of trying to debug why jest is not able to update inline sourcemaps for my project, I think I have found an swc bug where some given input code gets an incorrectly generated source map. See below!

Input code

export {};

describe("whatever", () => {
  test("it can find inline snapshots", () => {
    expect([1, 2]).toMatchInlineSnapshot(`
      Array [
        1,
        2,
      ]
    `);
  });

  test("it can find two inline snapshots", () => {
    expect([3, 4]).toMatchInlineSnapshot();
  });
});

Config

{ "sourceMaps": "inline", "jsc": { "target": "es2020", "externalHelpers": true } }

Playground link

https://play.swc.rs/?version=1.2.113&code=H4sIAAAAAAAAA42OQQuCQBCF7%2F6Kh6cVlkDrJgUdO3TqKILbOuFC7MrukIb43xMxISjoMPPewHvMR33rPGMY8yiqKWhvriTirlFMD%2FKxhEiwP2CIAKbAIjYMrSxuxtYw9m4sIVjVhsZx%2BIgD1LekWRSpRFYmG3Znxbo5zaXL0hHVHAWO3qsniuUCUrna7G3LWaskn3Sc9lco7ty%2FYFuJ3U%2Bw9cs0L6waQO0mAQAA&config=H4sIAAAAAAAAA0WNSQ6DMAxF7%2BI1i5Yld%2BAQUWpQUCb5J1IjlLvXoFTs%2FKfnkw5YWk7KRsByXWixmC8tVFpmWHG50EQFam3Gg7sKIzsXrTDm1%2FzW2KcEHoWJgotuaxfMppCFgScycff%2FZldWSJ96Gef9T5k6CSkeoP6AxthhHe0iVTVSFcuryconF72LTP0HIni%2FHNMAAAA%3D

Expected behavior

The sourcemap matches the input content, and doesn't have ranges in the output content with no source mapping at all. I find this is easiest to see with https://evanw.github.io/source-map-visualization/, here's a screenshot of the output file:

CleanShot 2021-11-27 at 21 45 23@2x

That shows how many of the lines in the output are mapped incorrectly unless I am missing something!

Version

1.2.112

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions