The Wayback Machine - https://web.archive.org/web/20220529175116/https://github.com/purescript/purescript/issues/4034
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 generated with negative lines/columns #4034

Closed
RedGlow opened this issue Mar 21, 2021 · 4 comments · Fixed by #4343
Closed

Sourcemap generated with negative lines/columns #4034

RedGlow opened this issue Mar 21, 2021 · 4 comments · Fixed by #4343

Comments

@RedGlow
Copy link

@RedGlow RedGlow commented Mar 21, 2021

Description

I think there is some problem with sourcemaps generation, in that it produces lines/columns with negative indexes. I'm not 100% sure because I'm not an expert in the sourcemaps format, but I've got errors from webpack+purs-loader and using the source-map npm package, which makes me believe they are indeed incorrect.

To Reproduce

I'll give the steps I've used under Windows 10, but there shouldn't be any difference in other environments

  • install purescript and spago globally
  • create a new directory
  • run "spago init"
  • run "spago build"
  • run "npm init -y"
  • install source-map package: "npm install source-map --save"
  • save a script in the project root with this content:
const s = require("source-map");
const fs = require("fs");
const path = require("path");
const content = fs.readFileSync(path.join(__dirname, "output", "Effect.Console", "index.js.map"), {encoding: "utf-8"});
s.SourceMapConsumer.with(
  JSON.parse(content),
  null,
  (consumer) => {
    console.log("sources:");
    console.log(consumer.sources);

    console.log("mappings:");
    consumer.eachMapping(function (m) {
      console.log(JSON.stringify(m));
    });
  }
)
  .then(() => console.log("all done"))
  .catch(console.error);
  • run the script

Expected behavior

It should print a list of mappings between Effect.Console's purescript sources and generated javascript sources. Instead, it fails with an error:

sources:
[ '..\\..\\.spago\\console\\v5.0.0\\src\\Effect\\Console.purs' ]
mappings:
Error: Error parsing mappings (code 1): the mappings contained a negative line, column, source index, or name index
    at BasicSourceMapConsumer._parseMappings (E:\Documents\projects\smbug\node_modules\source-map\lib\source-map-consumer.js:360:13)
    at BasicSourceMapConsumer._getMappingsPtr (E:\Documents\projects\smbug\node_modules\source-map\lib\source-map-consumer.js:315:12)
    at E:\Documents\projects\smbug\node_modules\source-map\lib\source-map-consumer.js:387:57
    at Object.withMappingCallback (E:\Documents\projects\smbug\node_modules\source-map\lib\wasm.js:95:11)
    at BasicSourceMapConsumer.eachMapping (E:\Documents\projects\smbug\node_modules\source-map\lib\source-map-consumer.js:371:16)
    at E:\Documents\projects\smbug\test.js:13:14
    at E:\Documents\projects\smbug\node_modules\source-map\lib\source-map-consumer.js:78:16

Additional context

Spago version: 0.19.1
source-map package version: 0.7.3
psc: psc-0.14.0-20210318

PureScript version

0.14.0

@nwolverson
Copy link
Contributor

@nwolverson nwolverson commented Mar 25, 2021

If there's an issue in generated source maps, it should be apparent either in the source maps in output/, or the result of purs bundle; unfortunately source map generation is a chain of flaky tools, or it was the last time I saw it, the chaining of maps in multiple build steps was problematic

@jterbraak
Copy link

@jterbraak jterbraak commented May 14, 2021

In this case purs emits faulty maps. For example for Data.Lens.Internal.Re purs 0.13.8 emits this mapping:
;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,SAAA;WAAA;;AAIA,mBAAA;0CAAA;eAAA;mBAAA;gBACqB,gCAlBtB,gBAkBG,GAAA

Which translates to

([1,0](#0)=>[2,0])
([1,0](#0)=>[3,0])
([1,0](#0)=>[4,0])
([1,0](#0)=>[5,0])
([1,0](#0)=>[6,0])
([1,0](#0)=>[7,0])
([12,0](#0)=>[8,0]) | ([12,0](#0)=>[8,9])
([12,0](#0)=>[9,11])
([16,0](#0)=>[11,0]) | ([16,0](#0)=>[11,19])
([16,0](#0)=>[12,42])
([16,0](#0)=>[13,15])
([16,0](#0)=>[14,19])
([17,21](#0)=>[15,16]) | ([-1,-1](#0)=>[15,48]) | ([17,2](#0)=>[15,64]) | ([17,2](#0)=>[15,67])

So in the last line it emits a negative column and line. Maybe some invalid source span gets passed to the source map generator.

@i-am-the-slime
Copy link
Contributor

@i-am-the-slime i-am-the-slime commented Jun 6, 2021

@kevinbarabash Had improved the correctness of sourcemaps and was only missing tests by the end.
Here's the work in progress and the issue is here

@klarkc
Copy link

@klarkc klarkc commented Sep 21, 2021

It happened with me when tried to debug the source code with VSCode: spago build --purs-args "-g sourcemaps --json-errors"

j-nava added a commit to j-nava/purescript that referenced this issue Mar 21, 2022
j-nava added a commit to j-nava/purescript that referenced this issue Mar 21, 2022
j-nava added a commit to j-nava/purescript that referenced this issue Mar 21, 2022
j-nava added a commit to j-nava/purescript that referenced this issue Mar 22, 2022
j-nava added a commit to j-nava/purescript that referenced this issue Mar 22, 2022
* Improve mappings for expressions and binders (purescript#3851)

* Add mapping for module imports

* Fix null mapping issue (purescript#4034)

* Add tests
j-nava added a commit to j-nava/purescript that referenced this issue Mar 22, 2022
* Improve mappings for expressions and binders (purescript#3851)

* Add mapping for module imports

* Fix null mapping issue (purescript#4034)

* Clean up JS.hs

* Add tests
JordanMartinez added a commit that referenced this issue May 28, 2022
* Fix null mapping issue (#4034)

* Verify that each source map test produces a valid source map file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants