File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,15 +14,34 @@ class CSS extends EventEmitter {
1414 return this . recast ( str , options , 'source' ) ;
1515 }
1616 recast ( str , options , type ) {
17+ const regex =
18+ / ( @ i m p o r t \s + (? ! u r l \( ) ) ? \s * u r l \( \s * ( [ ' " ] ? ) ( [ ^ ' " ) ] + ) \2\s * \) | @ i m p o r t \s + ( [ ' " ] ) ( [ ^ ' " ] + ) \4/ g
19+
1720 if ( ! str ) return str ;
1821 str = new String ( str ) . toString ( ) ;
19- str = str . replace ( / (?< = u r l \( " ? ' ? ) [ ^ " ' ] [ \S ] * [ ^ " ' ] (? = " ? ' ? \) ; ? ) / gm, ( match ) => {
20- return type === "rewrite" ? this . ctx . rewriteUrl ( match ) : this . ctx . sourceUrl ( match ) ;
21- } ) ;
22- str = str . replace ( / @ i m p o r t \s + ( [ ' " ] ) ? ( [ ^ ' " \) ; ] + ) \1? \s * (?: ; | $ ) / gm, ( match , quote , url ) => {
23- return `@import ${ quote || "" } ${ type === "rewrite" ? this . ctx . rewriteUrl ( url ) : this . ctx . sourceUrl ( url ) } ${ quote || "" } ;` ;
22+ return str . replace (
23+ regex ,
24+ (
25+ match ,
26+ importStatement ,
27+ urlQuote ,
28+ urlContent ,
29+ importQuote ,
30+ importContent
31+ ) => {
32+ const url = urlContent || importContent
33+ const encodedUrl = type === "rewrite" ? this . ctx . rewriteUrl ( url ) : this . ctx . sourceUrl ( url ) ;
34+
35+ if ( importStatement ) {
36+ return `@import url(${ urlQuote } ${ encodedUrl } ${ urlQuote } )`
37+ }
38+
39+ if ( importQuote ) {
40+ return `@import ${ importQuote } ${ encodedUrl } ${ importQuote } `
41+ }
42+
43+ return `url(${ urlQuote } ${ encodedUrl } ${ urlQuote } )`
2444 } ) ;
25- return str ;
2645 }
2746}
2847
You can’t perform that action at this time.
0 commit comments