Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

WIP - Update source-map to 0.7.2 (#5598) #995

Closed
wants to merge 2 commits into from
Closed

WIP - Update source-map to 0.7.2 (#5598) #995

wants to merge 2 commits into from

Conversation

otowncaleb
Copy link

This PR addresses firefox-devtools/debugger#5598 for updating source-map to 0.7.2. The new version uses WebAssembly to encode/decode mappings. 馃挜

This PR is marked as WIP for a couple reasons:

  • One of the source mapping Jest tests gives a surprising failure:
    image

    • I don't see how this could be correct. Hoping someone from the source-map team can shed some light on this.
  • WebAssembly is loaded differently in Node as opposed to the web. (Jest tests run in a Node-like environment.) The way I handled that is almost certainly not how we want to do it. See my comments below for more details.

Some breaking changes that needed to be addressed:

- new SourceMapConsumer now returns a Promise that needs to be awaited on
- WebAssembly for encoding/decoding mappings needs to be loaded

source-map loads wasm differently in web and Node contexts. Jest tests
run in a Node environment so both need to be accounted for here.
@@ -0,0 +1,5 @@
// TODO: Remove this file after upgrading to Jest 22.4.1+
// More info: https://github.com/facebook/jest/issues/687
console.debug = console.log
Copy link
Author

Choose a reason for hiding this comment

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

In server environments, source-map calls console.debug, which does not exist in the version of Jest that this repo is currently running. Some other problems prevented me from simply upgrading Jest. I didn't think it was the right time to be going down that rabbithole.

@@ -11,6 +11,9 @@

const { networkRequest } = require("devtools-utils");
const { SourceMapConsumer, SourceMapGenerator } = require("source-map");
SourceMapConsumer.initialize({
"lib/mappings.wasm": "https://unpkg.com/source-map@0.7.2/lib/mappings.wasm"
Copy link
Author

Choose a reason for hiding this comment

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

It does work, I must say! The relevant documentation is here. The relevant code is here.

I'm not sure what is the ideal way to do the wasm init in the context of a Webpack app. Would it work just to use the Node way of loading wasm? @fitzgen would love to get your input on this :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know the answer here either, but this is going to need to be configurable so that this can also work in Mozilla Central. There, we'll want to ship the wasm in Firefox and we'll need to use a resource URL or something.

Copy link
Contributor

Choose a reason for hiding this comment

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

yep, we'll need to provide something when we start the worker...

@jasonLaster
Copy link
Contributor

jasonLaster commented Mar 14, 2018

CC @tromey could you take a look at this?

@tromey
Copy link
Contributor

tromey commented Mar 14, 2018

I looked at the test failure a bit. I am not sure this is a valid test.

The issue is that the source map contains two mappings for the O[5,4] location mentioned in the test case. One does map to G[8,0] -- but another maps to G[8,114].

I tend to think that the source map implementation has some freedom to decide which result it returns in this case. (Or perhaps it should return both.)

I'm not 100% sure though, so CC @fitzgen on this as well.

@tromey
Copy link
Contributor

tromey commented Mar 14, 2018

I forgot to mention - I read this patch and, aside from the URL configurability thing, it is pretty much what I thought this patch should look like. So assuming the webpack and test case issues are worked out, r+ from me. Thank you for doing this!

@jasonLaster
Copy link
Contributor

Thanks @tromey

Lets sort out the symmetry thing. I'm good with anything as long as I understand what is going on.

I'm happy to fix this up so we can get the mappings.wasm in m-c and pulled in in the launchpad.

@otowncaleb
Copy link
Author

otowncaleb commented Mar 19, 2018

I tend to think that the source map implementation has some freedom to decide which result it returns in this case.

If this is truly the case and debugger.html doesn't make any assumptions to the contrary, it should be OK to work around the failing tests like so: 1ed76bb

@loganfsmyth
Copy link
Contributor

I've posted an updated version of this in firefox-devtools/debugger#7071, so going to close this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants