Skip to content

Commit 6308afc

Browse files
bomsyjasonLaster
authored andcommitted
fix issue where minified files without js extns do get detected (firefox-devtools#4091)
1 parent e0a9a5a commit 6308afc

4 files changed

Lines changed: 23 additions & 15 deletions

File tree

src/components/Editor/Footer.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,6 @@ class SourceFooter extends PureComponent {
139139
}
140140

141141
renderCommands() {
142-
const { selectedSource } = this.props;
143-
if (!shouldShowPrettyPrint(selectedSource)) {
144-
return null;
145-
}
146-
147142
return (
148143
<div className="commands">
149144
{this.prettyPrintButton()}

src/utils/pretty-print/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@ type PrettyPrintOpts = {
1818
};
1919

2020
export async function prettyPrint({ source, url }: PrettyPrintOpts) {
21-
const contentType = source.contentType;
2221
const indent = 2;
2322

24-
assert(
25-
isJavaScript(source.url, contentType),
26-
"Can't prettify non-javascript files."
27-
);
23+
assert(isJavaScript(source), "Can't prettify non-javascript files.");
2824

2925
return await _prettyPrint({
3026
url,

src/utils/source.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function shouldPrettyPrint(source: any) {
3838
}
3939

4040
const _isPretty = isPretty(source);
41-
const _isJavaScript = isJavaScript(source.url);
41+
const _isJavaScript = isJavaScript(source);
4242
const isOriginal = isOriginalId(source.id);
4343
const hasSourceMap = source.sourceMapURL;
4444

@@ -59,10 +59,10 @@ function shouldPrettyPrint(source: any) {
5959
* @memberof utils/source
6060
* @static
6161
*/
62-
function isJavaScript(url: ?string, contentType: string = ""): boolean {
62+
function isJavaScript(source: Source): boolean {
6363
return (
64-
(url && /\.(jsm|js)?$/.test(trimUrlQuery(url))) ||
65-
contentType.includes("javascript")
64+
(source.url && /\.(jsm|js)?$/.test(trimUrlQuery(source.url))) ||
65+
!!(source.contentType && source.contentType.includes("javascript"))
6666
);
6767
}
6868

src/utils/tests/source.spec.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {
22
getFilename,
33
getMode,
44
getSourceLineCount,
5-
isThirdParty
5+
isThirdParty,
6+
isJavaScript
67
} from "../source.js";
78

89
describe("sources", () => {
@@ -22,6 +23,22 @@ describe("sources", () => {
2223
});
2324
});
2425

26+
describe("isJavaScript", () => {
27+
it("is not JavaScript", () => {
28+
expect(isJavaScript({ url: "foo.html" })).toBe(false);
29+
expect(isJavaScript({ contentType: "text/html" })).toBe(false);
30+
});
31+
32+
it("is JavaScript", () => {
33+
expect(isJavaScript({ url: "foo.js" })).toBe(true);
34+
expect(isJavaScript({ url: "bar.jsm" })).toBe(true);
35+
expect(isJavaScript({ contentType: "text/javascript" })).toBe(true);
36+
expect(isJavaScript({ contentType: "application/javascript" })).toBe(
37+
true
38+
);
39+
});
40+
});
41+
2542
describe("isThirdParty", () => {
2643
it("node_modules", () => {
2744
expect(isThirdParty({ url: "/node_modules/foo.js" })).toBe(true);

0 commit comments

Comments
 (0)