Skip to content

Commit 4fb0660

Browse files
JibersonjasonLaster
authored andcommitted
[releases] Use native URL class (firefox-devtools#6678)
1 parent 122f653 commit 4fb0660

9 files changed

Lines changed: 48 additions & 14 deletions

File tree

.babel/transform-mc.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ const VENDORS = [
3333
"react-aria-components/src/tabs",
3434
"react-transition-group/Transition",
3535
"reselect",
36-
"Svg",
37-
"url"
36+
"Svg"
3837
];
3938

4039
/*

src/test/mochitest/browser_dbg-sources-named-eval.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ add_task(async function() {
3131
});
3232

3333
await waitForSourceCount(dbg, 3);
34-
3534
is(getLabel(dbg, 3), "evaled.js", "evaled exists");
3635
});

src/test/tests-setup.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ global.L10N.setBundle(
4444
global.jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
4545
global.performance = { now: () => 0 };
4646

47+
const { URL } = require("url");
48+
global.URL = URL;
49+
4750
Enzyme.configure({ adapter: new Adapter() });
4851

4952
function formatException(reason, p) {

src/utils/source.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
*/
1111

1212
import { isOriginalId } from "devtools-source-map";
13+
import { getUnicodeUrl } from "devtools-modules";
14+
1315
import { endTruncateStr } from "./utils";
1416
import { truncateMiddleText } from "../utils/text";
15-
16-
import { parse as parseURL } from "url";
17-
import { getUnicodeUrl } from "devtools-modules";
17+
import { parse as parseURL } from "../utils/url";
1818
export { isMinified } from "./isMinified";
1919
import { getURL, getFileExtension } from "./sources-tree";
2020
import { prefs } from "./prefs";
@@ -155,7 +155,6 @@ export function getFilename(source: Source) {
155155
}
156156

157157
const { filename } = getURL(source);
158-
159158
return getRawSourceURL(filename);
160159
}
161160

src/utils/sources-tree/getURL.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// @flow
66

7-
import { parse } from "url";
7+
import { parse } from "../../utils/url";
88
import { getUnicodeHostname, getUnicodeUrlPath } from "devtools-modules";
99

1010
import type { Source } from "../../types";
@@ -80,7 +80,7 @@ function _getURL(source: Source, defaultDomain: string): ParsedURL {
8080
filename: url
8181
};
8282

83-
case null:
83+
case "":
8484
if (pathname && pathname.startsWith("/")) {
8585
// use file protocol for a URL like "/foo/bar.js"
8686
return {
@@ -89,7 +89,7 @@ function _getURL(source: Source, defaultDomain: string): ParsedURL {
8989
filename,
9090
group: "file://"
9191
};
92-
} else if (host === null) {
92+
} else if (!host) {
9393
return {
9494
...def,
9595
path: url,

src/utils/sources-tree/tests/getUrl.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { getURL } from "../getURL";
88
import { createSource } from "../../../reducers/sources";
9-
import Url from "url";
9+
import * as Url from "../../url";
1010

1111
let spy;
1212

@@ -121,7 +121,6 @@ describe("getUrl", () => {
121121
url: "http://example.com/foo/bar/baz.js"
122122
});
123123

124-
spy = jest.spyOn(Url, "parse");
125124
getURL(source);
126125
const url = getURL(source2);
127126
expect(spy).toHaveBeenCalledTimes(2);

src/utils/sources-tree/treeOrder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// @flow
66

7-
import { parse } from "url";
7+
import { parse } from "../url";
88

99
import { nodeHasChildren } from "./utils";
1010

src/utils/sources-tree/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// @flow
66

7-
import { parse } from "url";
7+
import { parse } from "../../utils/url";
88

99
import type { TreeNode, TreeSource, TreeDirectory, ParentMap } from "./types";
1010
import type { Source } from "../../types";

src/utils/url.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
4+
5+
const defaultUrl = {
6+
hash: "",
7+
host: "",
8+
hostname: "",
9+
href: "",
10+
origin: "null",
11+
password: "",
12+
path: "",
13+
pathname: "",
14+
port: "",
15+
protocol: "",
16+
search: "",
17+
// This should be a "URLSearchParams" object
18+
searchParams: {},
19+
username: ""
20+
};
21+
22+
export function parse(url: string): URL | object {
23+
try {
24+
const urlObj = new URL(url);
25+
urlObj.path = urlObj.pathname + urlObj.search;
26+
return urlObj;
27+
} catch (err) {
28+
// If we're given simply a filename...
29+
if (url) {
30+
return { ...defaultUrl, path: url, pathname: url };
31+
}
32+
33+
return defaultUrl;
34+
}
35+
}

0 commit comments

Comments
 (0)