@@ -16,7 +16,7 @@ class MapGenerator {
1616 this . root = root
1717 this . opts = opts
1818 this . css = cssString
19- this . fileUrls = ! this . mapOpts . from && this . mapOpts . absolute
19+ this . usesFileUrls = ! this . mapOpts . from && this . mapOpts . absolute
2020 }
2121
2222 isMap ( ) {
@@ -98,16 +98,9 @@ class MapGenerator {
9898 let from = node . source . input . from
9999 if ( from && ! already [ from ] ) {
100100 already [ from ] = true
101- let fromUrl = this . toUrl ( this . path ( from ) )
102- if ( this . fileUrls ) {
103- if ( pathToFileURL ) {
104- fromUrl = pathToFileURL ( from ) . toString ( )
105- } else {
106- throw new Error (
107- '`map.absolute` option is not available in this PostCSS build'
108- )
109- }
110- }
101+ let fromUrl = this . usesFileUrls
102+ ? this . toFileUrl ( from )
103+ : this . toUrl ( this . path ( from ) )
111104 this . map . setSourceContent ( fromUrl , node . source . input . css )
112105 }
113106 }
@@ -240,17 +233,21 @@ class MapGenerator {
240233 return encodeURI ( path ) . replace ( / [ # ? ] / g, encodeURIComponent )
241234 }
242235
236+ toFileUrl ( path ) {
237+ if ( pathToFileURL ) {
238+ return pathToFileURL ( path ) . toString ( )
239+ } else {
240+ throw new Error (
241+ '`map.absolute` option is not available in this PostCSS build'
242+ )
243+ }
244+ }
245+
243246 sourcePath ( node ) {
244247 if ( this . mapOpts . from ) {
245248 return this . toUrl ( this . mapOpts . from )
246- } else if ( this . fileUrls ) {
247- if ( pathToFileURL ) {
248- return pathToFileURL ( node . source . input . from ) . toString ( )
249- } else {
250- throw new Error (
251- '`map.absolute` option is not available in this PostCSS build'
252- )
253- }
249+ } else if ( this . usesFileUrls ) {
250+ return this . toFileUrl ( node . source . input . from )
254251 } else {
255252 return this . toUrl ( this . path ( node . source . input . from ) )
256253 }
0 commit comments