File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ( ) }
Original file line number Diff line number Diff line change @@ -18,13 +18,9 @@ type PrettyPrintOpts = {
1818} ;
1919
2020export 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,
Original file line number Diff line number Diff 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 && / \. ( j s m | j s ) ? $ / . test ( trimUrlQuery ( url ) ) ) ||
65- contentType . includes ( "javascript" )
64+ ( source . url && / \. ( j s m | j s ) ? $ / . test ( trimUrlQuery ( source . url ) ) ) ||
65+ ! ! ( source . contentType && source . contentType . includes ( "javascript" ) )
6666 ) ;
6767}
6868
Original file line number Diff line number Diff line change 22 getFilename ,
33 getMode ,
44 getSourceLineCount ,
5- isThirdParty
5+ isThirdParty ,
6+ isJavaScript
67} from "../source.js" ;
78
89describe ( "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 ) ;
You can’t perform that action at this time.
0 commit comments