@@ -77,30 +77,55 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
7777exports [ exportName ] = replaceImportsInString ( exports [ exportName ] ) ;
7878} ) ;
7979
80+ function processNode ( item , isValue ) {
81+ switch ( item . type ) {
82+ case "value" :
83+ item . nodes . forEach ( function ( node ) {
84+ processNode ( node , true ) ;
85+ } ) ;
86+ break ;
87+ case "nested-item" :
88+ item . nodes . forEach ( function ( node ) {
89+ processNode ( node ) ;
90+ } ) ;
91+ break ;
92+ case "item" :
93+ var importIndex = imports [ "$" + item . name ] ;
94+ if ( typeof importIndex === "number" ) {
95+ item . name = "___CSS_LOADER_IMPORT___" + importIndex + "___" ;
96+ }
97+ break ;
98+ case "url" :
99+ if ( ! / ^ # / . test ( item . url ) && loaderUtils . isUrlRequest ( item . url , options . root ) ) {
100+ item . stringType = "" ;
101+ delete item . innerSpacingBefore ;
102+ delete item . innerSpacingAfter ;
103+ var url ;
104+
105+ if ( isValue ) {
106+ if ( loaderUtils . isUrlRequest ( url , options . root ) && options . mode === "global" ) {
107+ url = loaderUtils . urlToRequest ( item . url , options . root ) ;
108+ } else {
109+ url = item . url ;
110+ }
111+ } else {
112+ url = item . url ;
113+ }
114+
115+ item . url = "___CSS_LOADER_URL___" + urlItems . length + "___" ;
116+ urlItems . push ( {
117+ url : url
118+ } ) ;
119+ }
120+ break ;
121+ }
122+ }
123+
80124css . walkDecls ( function ( decl ) {
81125var values = Tokenizer . parseValues ( decl . value ) ;
82126values . nodes . forEach ( function ( value ) {
83- value . nodes . forEach ( function ( item ) {
84- switch ( item . type ) {
85- case "item" :
86- var importIndex = imports [ "$" + item . name ] ;
87- if ( typeof importIndex === "number" ) {
88- item . name = "___CSS_LOADER_IMPORT___" + importIndex + "___" ;
89- }
90- break ;
91- case "url" :
92- if ( ! / ^ # / . test ( item . url ) && loaderUtils . isUrlRequest ( item . url , options . root ) ) {
93- item . stringType = "" ;
94- delete item . innerSpacingBefore ;
95- delete item . innerSpacingAfter ;
96- var url = item . url ;
97- item . url = "___CSS_LOADER_URL___" + urlItems . length + "___" ;
98- urlItems . push ( {
99- url : url
100- } ) ;
101- }
102- break ;
103- }
127+ value . nodes . forEach ( function ( node ) {
128+ processNode ( node ) ;
104129} ) ;
105130} ) ;
106131decl . value = Tokenizer . stringifyValues ( values ) ;
0 commit comments