Bug 1541633 - Part 1: Move original ID generation into the source-map worker. r=jlast

Differential Revision: https://phabricator.services.mozilla.com/D42933

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Logan Smyth 2019-08-21 20:18:18 +00:00
Родитель 0d08551fbd
Коммит 5332de6417
9 изменённых файлов: 57 добавлений и 28 удалений

Просмотреть файл

@ -15,7 +15,6 @@ import type {
Source,
SourceId,
} from "../../../src/types";
import type { SourceMapConsumer } from "source-map";
import type { LocationOptions } from "./source-map";
export const dispatcher = new WorkerDispatcher();
@ -40,7 +39,7 @@ export const setAssetRootURL = async (assetRoot: string): Promise<void> =>
export const getOriginalURLs = async (
generatedSource: Source
): Promise<SourceMapConsumer> =>
): Promise<?Array<{| id: SourceId, url: string |}>> =>
dispatcher.invoke("getOriginalURLs", generatedSource);
export const hasOriginalURL = async (url: string): Promise<boolean> =>

Просмотреть файл

@ -52,9 +52,16 @@ export type LocationOptions = {
async function getOriginalURLs(
generatedSource: Source
): Promise<SourceMapConsumer> {
): Promise<?Array<{| id: SourceId, url: string |}>> {
const map = await fetchSourceMap(generatedSource);
return map && map.sources;
if (!map || !map.sources) {
return null;
}
return map.sources.map(url => ({
id: generatedToOriginalId(generatedSource.id, url),
url,
}));
}
const COMPUTED_SPANS = new WeakSet();

Просмотреть файл

@ -35,7 +35,9 @@ async function setupBundleFixture(name) {
return { content };
});
return getOriginalURLs(source);
const data = await getOriginalURLs(source);
return data.map(item => item.url);
}
module.exports = {

Просмотреть файл

@ -110,7 +110,12 @@ describe("wasm source maps", () => {
const { getOriginalURLs, getOriginalLocation } = require("../source-map");
const urls = await getOriginalURLs(source);
expect(urls).toEqual(["http://example.com/whatever/one.js"]);
expect(urls).toEqual([
{
id: "min.js/originalSource-2133f6ef6d6c464acad221082f398cf0",
url: "http://example.com/whatever/one.js",
},
]);
const { line, column } = await getOriginalLocation({
sourceId: source.id,

Просмотреть файл

@ -9,7 +9,6 @@
* @module actions/sources
*/
import { generatedToOriginalId } from "devtools-source-map";
import { flatten } from "lodash";
import {
@ -101,7 +100,7 @@ function loadSourceMap(cx: Context, sourceId: SourceId) {
dispatch,
getState,
sourceMaps,
}: ThunkArgs): Promise<Source[]> {
}: ThunkArgs): Promise<OriginalSourceData[]> {
const source = getSource(getState(), sourceId);
if (
@ -113,7 +112,7 @@ function loadSourceMap(cx: Context, sourceId: SourceId) {
return [];
}
let urls = null;
let data = null;
try {
// Unable to correctly type the result of a spread on a union type.
// See https://github.com/facebook/flow/pull/7298
@ -126,12 +125,12 @@ function loadSourceMap(cx: Context, sourceId: SourceId) {
// however, so use that for resolving any source maps in the source.
(urlInfo: any).url = urlInfo.introductionUrl;
}
urls = await sourceMaps.getOriginalURLs(urlInfo);
data = await sourceMaps.getOriginalURLs(urlInfo);
} catch (e) {
console.error(e);
}
if (!urls) {
if (!data) {
// If this source doesn't have a sourcemap, enable it for pretty printing
dispatch(
({
@ -144,10 +143,7 @@ function loadSourceMap(cx: Context, sourceId: SourceId) {
}
validateNavigateContext(getState(), cx);
return urls.map(url => ({
id: generatedToOriginalId(source.id, url),
url,
}));
return data;
};
}

Просмотреть файл

@ -19,6 +19,7 @@ const {
getSourceByURL,
} = selectors;
import sourceQueue from "../../../utils/source-queue";
import { generatedToOriginalId } from "devtools-source-map";
import { mockCommandClient } from "../../tests/helpers/mockCommandClient";
@ -63,7 +64,12 @@ describe("sources - new sources", () => {
mockCommandClient,
{},
{
getOriginalURLs: async () => ["magic.js"],
getOriginalURLs: async source => [
{
id: generatedToOriginalId(source.id, "magic.js"),
url: "magic.js",
},
],
getOriginalLocations: async items => items,
}
);
@ -124,8 +130,13 @@ describe("sources - new sources", () => {
// simulate a hang loading foo.js.map
return new Promise(_ => {});
}
return [source.id.replace(".js", ".cljs")];
const url = source.id.replace(".js", ".cljs");
return [
{
id: generatedToOriginalId(source.id, url),
url: url,
},
];
},
getOriginalLocations: async items => items,
getGeneratedLocation: location => location,

Просмотреть файл

@ -11,7 +11,7 @@ import {
} from "./helpers/breakpoints.js";
import { mockCommandClient } from "./helpers/mockCommandClient";
import { generatedToOriginalId } from "devtools-source-map";
import { asyncStore } from "../../utils/prefs";
function loadInitialState(opts = {}) {
@ -376,7 +376,12 @@ describe("adding sources", () => {
it("corresponding breakpoints are added to the original source", async () => {
const sourceURL = makeSourceURL("bar.js");
const store = createStore(mockClient({ "5": [2] }), loadInitialState(), {
getOriginalURLs: async () => [sourceURL],
getOriginalURLs: async source => [
{
id: generatedToOriginalId(source.id, sourceURL),
url: sourceURL,
},
],
getOriginalSourceText: async () => ({ source: "" }),
getGeneratedLocation: async (location, _source) => ({
line: location.line,

Просмотреть файл

@ -1432,7 +1432,15 @@ const {
async function getOriginalURLs(generatedSource) {
const map = await fetchSourceMap(generatedSource);
return map && map.sources;
if (!map || !map.sources) {
return null;
}
return map.sources.map(url => ({
id: generatedToOriginalId(generatedSource.id, url),
url
}));
}
const COMPUTED_SPANS = new WeakSet();

Просмотреть файл

@ -366,14 +366,10 @@ StyleEditorUI.prototype = {
this._removeStyleSheetEditor(editor);
editor = null;
for (const source of sources) {
const generatedId = sourceMapService.generatedToOriginalId(
id,
source
);
for (const { id: originalId, url: originalURL } of sources) {
const original = new OriginalSource(
source,
generatedId,
originalURL,
originalId,
sourceMapService
);