Skip to content

createSourceMapper incorrectly uses .toString() to pass maps to SourceMapConsumer #981

@fabbarix

Description

@fabbarix

Describe the bug
Parsing of source maps fails, this shows up in VSCode as a warning - Unexpected token o in JSON at position 1svelte -
on the first line of Svelte typescript files.

To Reproduce
Setup a project with Svelte and Typescript; open project in VS Code.

Expected behavior
There should be no error.

Screenshots

image

System (please complete the following information):

  • OS: Windows
  • IDE: VSCode
  • Plugin/Package: svelte-language-server

** Observations **

The issue is in this line of code:

await new SourceMapConsumer(processedSingle.map.toString()),

It uses .toString() to pass the value into the constructor of SourceMapConsumer. This is not needed, and it actually breaks the case where the source map is passed as an object - since the map becomes the string value '[object Object]'.

The source map should be passed as is, since SourceMapConsumer is able to handle both cases - see the _factory method here:

https://github.com/mozilla/source-map/blob/58819f09018d56ef84dc41ba9c93f554e0645169/lib/source-map-consumer.js#L1053

I propose to drop the .toString() - should I create a PR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedFixed in master branch. Pending production release.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions