Skip to content

the "source" returned by "originalPositionFor" is different with "sources" of sourceMap file #267

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

Closed
kiwenlau opened this issue Jun 7, 2017 · 6 comments

Comments

@kiwenlau
Copy link

kiwenlau commented Jun 7, 2017

I use "originalPositionFor" to get the original position.

    console.log(JSON.stringify(sourceMap.sources, null, 4));

    var smc = new SourceMap.SourceMapConsumer(sourceMap);
    var result = smc.originalPositionFor(
    {
        line: parseInt(lineNumber),
        column: parseInt(columnNumber)
    });

    console.log(result.source);

I print out the "sources" property of sourceMap and the "source" of "originalPosition" results, but they are different, making it hard for me to locate the exact "sourcesContent" of sourceMap.

sourceMap.sources:

[
    "webpack:///static/js/manifest.b7cf97680f7a50fa150f.js",
    "webpack:///webpack/bootstrap 67e184f9679733298d44"
]

result.source:

webpack:/webpack/bootstrap 67e184f9679733298d44

result.source misses "//", which is quite strange.

Any suggestion? Thx!

@tromey
Copy link
Contributor

tromey commented Jun 8, 2017

Source maps for webpack-built bundles are definitely working in Firefox. For example, this test uses one.

The best thing would be if you could make a (hopefully minimal) example showing the problem.

@kiwenlau
Copy link
Author

kiwenlau commented Jun 9, 2017

Here is the Source Map file:(GitHub only support uploading .txt file...)
test.txt

The sources field of source map:

"sources": ["webpack:///static/js/manifest.b7cf97680f7a50fa150f.js","webpack:///webpack/bootstrap 67e184f9679733298d44"],

Here is the code:

const sourceMap = require('source-map');

const fs = require('fs');
const rawSourceMap = JSON.parse(fs.readFileSync('./test.txt', 'utf8'));

const smc = new sourceMap.SourceMapConsumer(rawSourceMap);

console.log(smc.originalPositionFor({
  line: 1,
  column: 100
}));

Here is the output:

{ source: 'webpack:/webpack/bootstrap 67e184f9679733298d44',
  line: 52,
  column: 0,
  name: 'call' }

You can see that the "source" returned by "originalPositionFor" is different with "sources" of sourceMap file

Thx!

@kiwenlau
Copy link
Author

I found exactly the same problem again! @tromey

here is the sourcemap file: test02.txt

The sources field of source map:

"webpack:///./src/components/ajax/ajax.js"

Here is the code:

const sourceMap = require('source-map');

const fs = require('fs');
const rawSourceMap = JSON.parse(fs.readFileSync('./test02.txt', 'utf8'));

const smc = new sourceMap.SourceMapConsumer(rawSourceMap);

console.log(smc.originalPositionFor({
  line: 1,
  column: 15545
}));

Here is the output:

{ source: 'webpack:///src/components/ajax/ajax.js',
  line: 14,
  column: 23,
  name: 'data' }

@tromey
Copy link
Contributor

tromey commented Sep 22, 2017

I would mildly expect the /// to be transformed to // by source-map's URL normalization; but I definitely am seeing it transform to /, which seems quite wrong.

@tromey
Copy link
Contributor

tromey commented Sep 22, 2017

The built-in URL parser can't parse that URL, which is probably the problem. Would be fixed by using the standard URL, see #275

@tromey
Copy link
Contributor

tromey commented Sep 22, 2017

{ source: 'webpack:///src/components/ajax/ajax.js',

This one isn't really a bug. The source-map library does some normalization.

tromey added a commit to tromey/source-map that referenced this issue Sep 25, 2017
urlRegexp was requiring that there be no spaces in the path component of
the URL.  However, this is overly strict; and in particular webpack
creates URLs with an embedded space.
Fixes mozilla#267
tromey added a commit to tromey/source-map that referenced this issue Sep 25, 2017
urlRegexp was requiring that there be no spaces in the path component of
the URL.  However, this is overly strict; and in particular webpack
creates URLs with an embedded space.
Fixes mozilla#267
tromey added a commit to tromey/source-map that referenced this issue Sep 25, 2017
urlRegexp was requiring that there be no spaces in the path component of
the URL.  However, this is overly strict; and in particular webpack
creates URLs with an embedded space.
Fixes mozilla#267
tromey added a commit to tromey/source-map that referenced this issue Sep 25, 2017
urlRegexp was requiring that there be no spaces in the path component of
the URL.  However, this is overly strict; and in particular webpack
creates URLs with an embedded space.
Fixes mozilla#267
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants