Skip to content

Relative paths become absolute paths when using a source map with empty string as the sourceRoot with SourceMapConsumer #123

@Arnavion

Description

@Arnavion

Edit: Fixed title to reflect the underlying issue (empty string as sourceRoot).

The issue is that loading a source map with sourceRoot: "" into a SourceMapConsumer and then querying it via originalPositionFor() returns a source that is an absolute path. For example, if the path in the source map was "foo.ts", then consumer.originalPositionFor(...).source is "/foo.ts"

So there are two things here:

  • Empty string sourceRoot is no longer interpreted the same as it used to be.
  • Empty string sourceRoot causes relative paths to become absolute paths.

Original issue text below:


I start with a sourcemap generated from Typescript that has:

"sources":["utility.ts","web-worker.ts","parts.ts","parser.ts","renderers-clocks.ts","renderers-null.ts","renderers-web.ts","renderers-default.ts","types.ts","libjass.ts"]

I then run the Javascript and this source map through UglifyJS for some transforms. When writing out the source map from UJS, I get this:

"sources":["/utility.ts","/web-worker.ts","/parts.ts","/parser.ts","/renderers-clocks.ts","/renderers-null.ts","/renderers-web.ts","/renderers-default.ts","/types.ts"]

Note the relative paths (i.e., relative to current directory) have become absolute paths. This breaks loading the original JS in browsers because they try to fetch the original source using the absolute path instead of relative to the sourcemap URL.

git bisect reveals this was caused by 0235bb0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions