diff --git a/packages/devtools-source-map/assets.js b/packages/devtools-source-map/assets.js
index 7454b042b0..a911626402 100644
--- a/packages/devtools-source-map/assets.js
+++ b/packages/devtools-source-map/assets.js
@@ -4,5 +4,6 @@
// @flow
module.exports = {
- "dwarf_to_json.wasm": require.resolve("./wasm/dwarf_to_json.wasm")
+ "dwarf_to_json.wasm": require.resolve("./wasm/dwarf_to_json.wasm"),
+ "source-map-mappings.wasm": require.resolve("source-map/lib/mappings.wasm")
};
diff --git a/packages/devtools-source-map/package.json b/packages/devtools-source-map/package.json
index 19c4f1b567..bd1a55df13 100644
--- a/packages/devtools-source-map/package.json
+++ b/packages/devtools-source-map/package.json
@@ -22,6 +22,6 @@
"devtools-utils": "0.0.14",
"md5": "^2.2.1",
"regenerator-runtime": "^0.10.3",
- "source-map": "^0.6.1"
+ "source-map": "^0.7.3"
}
}
diff --git a/packages/devtools-source-map/src/source-map.js b/packages/devtools-source-map/src/source-map.js
index 27dfcd92f4..ea33d388dd 100644
--- a/packages/devtools-source-map/src/source-map.js
+++ b/packages/devtools-source-map/src/source-map.js
@@ -171,17 +171,36 @@ async function getGeneratedLocation(
return location;
}
- const { line, column } = map.generatedPositionFor({
+ const positions = map.allGeneratedPositionsFor({
source: originalSource.url,
line: location.line,
- column: location.column == null ? 0 : location.column,
- bias: SourceMapConsumer.LEAST_UPPER_BOUND
+ column: location.column == null ? 0 : location.column
});
+ // Prior to source-map 0.7, the source-map module returned the earliest
+ // generated location in the file when there were multiple generated
+ // locations. The current comparison fn in 0.7 does not appear to take
+ // generated location into account properly.
+ let match;
+ for (const pos of positions) {
+ if (!match || pos.line < match.line || pos.column < match.column) {
+ match = pos;
+ }
+ }
+
+ if (!match) {
+ match = map.generatedPositionFor({
+ source: originalSource.url,
+ line: location.line,
+ column: location.column == null ? 0 : location.column,
+ bias: SourceMapConsumer.LEAST_UPPER_BOUND
+ });
+ }
+
return {
sourceId: generatedSourceId,
- line,
- column
+ line: match.line,
+ column: match.column
};
}
diff --git a/packages/devtools-source-map/src/utils/wasmAssetBrowser.js b/packages/devtools-source-map/src/utils/wasmAssetBrowser.js
index 21331f3dba..e123c278bd 100644
--- a/packages/devtools-source-map/src/utils/wasmAssetBrowser.js
+++ b/packages/devtools-source-map/src/utils/wasmAssetBrowser.js
@@ -3,10 +3,16 @@
* file, You can obtain one at . */
// @flow
+const { SourceMapConsumer } = require("source-map");
+
let root;
function setAssetRootURL(assetRoot: string): void {
// Remove any trailing slash so we don't generate a double-slash below.
root = assetRoot.replace(/\/$/, "");
+
+ SourceMapConsumer.initialize({
+ "lib/mappings.wasm": `${root}/source-map-mappings.wasm`
+ });
}
async function getDwarfToWasmData(name: string): Promise {
diff --git a/yarn.lock b/yarn.lock
index 783ec94f6d..4ce4b37773 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -11019,6 +11019,10 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
+source-map@^0.7.3:
+ version "0.7.3"
+ resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"
+
space-separated-tokens@^1.0.0:
version "1.1.2"
resolved "https://registry.yarnpkg.com/space-separated-tokens/-/space-separated-tokens-1.1.2.tgz#e95ab9d19ae841e200808cd96bc7bd0adbbb3412"