@@ -20,49 +20,55 @@ function walkUrls(parsed, callback) {
2020 node . after = '' ;
2121 /* eslint-enable */
2222
23- if ( url . trim ( ) . replace ( / \\ [ \r \n ] / g, '' ) . length !== 0 ) {
24- callback ( node , url ) ;
25- }
23+ callback ( node , url ) ;
2624
2725 // Do not traverse inside url
2826 // eslint-disable-next-line consistent-return
2927 return false ;
3028 } ) ;
3129}
3230
33- function filterUrls ( parsed , filter ) {
34- const result = [ ] ;
31+ function filterUrls ( parsed , result , decl , filter ) {
32+ const urls = [ ] ;
3533
36- walkUrls ( parsed , ( node , content ) => {
37- if ( ! filter ( content ) ) {
34+ walkUrls ( parsed , ( node , url ) => {
35+ if ( url . trim ( ) . replace ( / \\ [ \r \n ] / g, '' ) . length === 0 ) {
36+ result . warn ( `Unable to find uri in '${ decl . toString ( ) } '` , {
37+ node : decl ,
38+ } ) ;
39+
40+ return ;
41+ }
42+
43+ if ( ! filter ( url ) ) {
3844 return ;
3945 }
4046
41- result . push ( content ) ;
47+ urls . push ( url ) ;
4248 } ) ;
4349
44- return result ;
50+ return urls ;
4551}
4652
47- function walkDeclsWithUrl ( css , filter ) {
48- const result = [ ] ;
53+ function walkDeclsWithUrl ( css , result , filter ) {
54+ const items = [ ] ;
4955
5056 css . walkDecls ( ( decl ) => {
5157 if ( ! / u r l \( / i. test ( decl . value ) ) {
5258 return ;
5359 }
5460
5561 const parsed = valueParser ( decl . value ) ;
56- const values = filterUrls ( parsed , filter ) ;
62+ const values = filterUrls ( parsed , result , decl , filter ) ;
5763
5864 if ( values . length === 0 ) {
5965 return ;
6066 }
6167
62- result . push ( { decl, parsed, values } ) ;
68+ items . push ( { decl, parsed, values } ) ;
6369 } ) ;
6470
65- return result ;
71+ return items ;
6672}
6773
6874function flatten ( array ) {
@@ -92,9 +98,11 @@ function uniq(array) {
9298module . exports = postcss . plugin (
9399 pluginName ,
94100 ( options ) =>
95- function process ( css ) {
101+ function process ( css , result ) {
96102 const urlItems = [ ] ;
97- const traversed = walkDeclsWithUrl ( css , ( value ) => isUrlRequest ( value ) ) ;
103+ const traversed = walkDeclsWithUrl ( css , result , ( value ) =>
104+ isUrlRequest ( value )
105+ ) ;
98106 const paths = uniq ( flatten ( traversed . map ( ( item ) => item . values ) ) ) ;
99107
100108 if ( paths . length === 0 ) {
0 commit comments