Skip to content

Conversation

@tromey
Copy link
Contributor

@tromey tromey commented Sep 25, 2017

The source-map library has long implemented sourceRoot resolution using
URL resolution. However, the source map specification is reasonably
clear that concatenation is to be used instead.

There is more information in these bugs:
#62
https://bugzilla.mozilla.org/show_bug.cgi?id=977463

This patch changes the resolution to match what Chrome does. This is an
incompatible change; but, I believe, better for interoperability.

This patch also adds an optional sourceMapURL parameter to the
SourceMapConsumer constructor. This allows us to implement the full
source URL resolution algorithm in the source-map library.

Fixes #62

@tromey tromey requested a review from gregtatum September 25, 2017 19:40
@tromey
Copy link
Contributor Author

tromey commented Sep 25, 2017

This allows removing a bunch of code from devtools-source-map as well.

@tromey tromey force-pushed the fix-source-root-prepending branch from c7992c5 to 43f5980 Compare September 26, 2017 14:40
@tromey
Copy link
Contributor Author

tromey commented Sep 26, 2017

Rebased, and avoid startsWith and endsWith

Copy link
Member

@gregtatum gregtatum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic looks good as far as I can tell. I had an optional comment on some more unit tests and on a few more explanatory comments.


if (sourceRoot) {
// This follows what Chrome does.
if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should do what Chrome does here, the spec doesn't seem to define this area very well :-/

sourceURL = sourceRoot + sourceURL;
}

if (sourceMapURL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a few more comments here explaining why you are doing this work, and how it conforms to the spec. It feels a bit mysterious to me.

}

return normalize(sourceURL);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function drives a lot of the internals, and is dependent on behavior both defined from the spec, and implicitly derived from other's implementations. This code gets hit by our existing tests, but I think it warrants having unit tests just for this function that run through the various types of options that can be done here. I took some time to verify my assumptions in the console of how things worked in order to have more confidence in this review. I think some tests could be fairly quick and terse, but would really help in defining the desired behavior here.

assert.equal(
  computeSourceURL("http://correct.com/", "/a/b.js", "http://wrong.com/source.map"),
  "http://correct.com/a/b.js"
)

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great idea.

'sources': ['original.js'],
'names': [],
'mappings': 'AACA',
'sourcesContent': ['yellow warbler']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your birds are starting to compete with fitzgen's hip hop references.

The source-map library has long implemented sourceRoot resolution using
URL resolution.  However, the source map specification is reasonably
clear that concatenation is to be used instead.

There is more information in these bugs:
    mozilla#62
    https://bugzilla.mozilla.org/show_bug.cgi?id=977463

This patch changes the resolution to match what Chrome does.  This is an
incompatible change; but, I believe, better for interoperability.

This patch also adds an optional sourceMapURL parameter to the
SourceMapConsumer constructor.  This allows us to implement the full
source URL resolution algorithm in the source-map library.

Fixes mozilla#62
@tromey tromey force-pushed the fix-source-root-prepending branch from 43f5980 to 54825b8 Compare September 26, 2017 19:33
@tromey tromey merged commit 75131c7 into mozilla:master Sep 26, 2017
@tromey tromey deleted the fix-source-root-prepending branch September 26, 2017 20:37
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

Successfully merging this pull request may close these issues.

2 participants