@@ -20,49 +20,55 @@ function walkUrls(parsed, callback) {
20
20
node . after = '' ;
21
21
/* eslint-enable */
22
22
23
- if ( url . trim ( ) . replace ( / \\ [ \r \n ] / g, '' ) . length !== 0 ) {
24
- callback ( node , url ) ;
25
- }
23
+ callback ( node , url ) ;
26
24
27
25
// Do not traverse inside url
28
26
// eslint-disable-next-line consistent-return
29
27
return false ;
30
28
} ) ;
31
29
}
32
30
33
- function filterUrls ( parsed , filter ) {
34
- const result = [ ] ;
31
+ function filterUrls ( parsed , result , decl , filter ) {
32
+ const urls = [ ] ;
35
33
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 ) ) {
38
44
return ;
39
45
}
40
46
41
- result . push ( content ) ;
47
+ urls . push ( url ) ;
42
48
} ) ;
43
49
44
- return result ;
50
+ return urls ;
45
51
}
46
52
47
- function walkDeclsWithUrl ( css , filter ) {
48
- const result = [ ] ;
53
+ function walkDeclsWithUrl ( css , result , filter ) {
54
+ const items = [ ] ;
49
55
50
56
css . walkDecls ( ( decl ) => {
51
57
if ( ! / u r l \( / i. test ( decl . value ) ) {
52
58
return ;
53
59
}
54
60
55
61
const parsed = valueParser ( decl . value ) ;
56
- const values = filterUrls ( parsed , filter ) ;
62
+ const values = filterUrls ( parsed , result , decl , filter ) ;
57
63
58
64
if ( values . length === 0 ) {
59
65
return ;
60
66
}
61
67
62
- result . push ( { decl, parsed, values } ) ;
68
+ items . push ( { decl, parsed, values } ) ;
63
69
} ) ;
64
70
65
- return result ;
71
+ return items ;
66
72
}
67
73
68
74
function flatten ( array ) {
@@ -92,9 +98,11 @@ function uniq(array) {
92
98
module . exports = postcss . plugin (
93
99
pluginName ,
94
100
( options ) =>
95
- function process ( css ) {
101
+ function process ( css , result ) {
96
102
const urlItems = [ ] ;
97
- const traversed = walkDeclsWithUrl ( css , ( value ) => isUrlRequest ( value ) ) ;
103
+ const traversed = walkDeclsWithUrl ( css , result , ( value ) =>
104
+ isUrlRequest ( value )
105
+ ) ;
98
106
const paths = uniq ( flatten ( traversed . map ( ( item ) => item . values ) ) ) ;
99
107
100
108
if ( paths . length === 0 ) {
0 commit comments