@@ -118,15 +118,54 @@ function parseNode(atRule, key) {
118118 throw error ;
119119 }
120120
121- const mediaNodes = paramsNodes . slice ( 1 ) ;
121+ const additionalNodes = paramsNodes . slice ( 1 ) ;
122+
123+ let supports ;
124+ let layer ;
122125 let media ;
123126
124- if ( mediaNodes . length > 0 ) {
125- media = valueParser . stringify ( mediaNodes ) . trim ( ) . toLowerCase ( ) ;
127+ if ( additionalNodes . length > 0 ) {
128+ let nodes = [ ] ;
129+
130+ for ( const node of additionalNodes ) {
131+ nodes . push ( node ) ;
132+
133+ const isLayerFunction =
134+ node . type === "function" && node . value . toLowerCase ( ) === "layer" ;
135+ const isLayerWord =
136+ node . type === "word" && node . value . toLowerCase ( ) === "layer" ;
137+
138+ if ( isLayerFunction || isLayerWord ) {
139+ if ( isLayerFunction ) {
140+ nodes . splice ( nodes . length - 1 , 1 , ...node . nodes ) ;
141+ } else {
142+ nodes . splice ( nodes . length - 1 , 1 , {
143+ type : "string" ,
144+ value : "" ,
145+ unclosed : false ,
146+ } ) ;
147+ }
148+
149+ layer = valueParser . stringify ( nodes ) . trim ( ) . toLowerCase ( ) ;
150+ nodes = [ ] ;
151+ } else if (
152+ node . type === "function" &&
153+ node . value . toLowerCase ( ) === "supports"
154+ ) {
155+ nodes . splice ( nodes . length - 1 , 1 , ...node . nodes ) ;
156+
157+ supports = valueParser . stringify ( nodes ) . trim ( ) . toLowerCase ( ) ;
158+ nodes = [ ] ;
159+ }
160+ }
161+
162+ if ( nodes . length > 0 ) {
163+ media = valueParser . stringify ( nodes ) . trim ( ) . toLowerCase ( ) ;
164+ }
126165 }
127166
128167 // eslint-disable-next-line consistent-return
129- return { atRule, prefix, url, media, isRequestable } ;
168+ return { atRule, prefix, url, layer , supports , media, isRequestable } ;
130169}
131170
132171const plugin = ( options = { } ) => {
@@ -160,11 +199,24 @@ const plugin = (options = {}) => {
160199
161200 const resolvedAtRules = await Promise . all (
162201 parsedAtRules . map ( async ( parsedAtRule ) => {
163- const { atRule, isRequestable, prefix, url, media } =
164- parsedAtRule ;
202+ const {
203+ atRule,
204+ isRequestable,
205+ prefix,
206+ url,
207+ layer,
208+ supports,
209+ media,
210+ } = parsedAtRule ;
165211
166212 if ( options . filter ) {
167- const needKeep = await options . filter ( url , media ) ;
213+ const needKeep = await options . filter (
214+ url ,
215+ media ,
216+ options . resourcePath ,
217+ supports ,
218+ layer
219+ ) ;
168220
169221 if ( ! needKeep ) {
170222 return ;
@@ -192,13 +244,20 @@ const plugin = (options = {}) => {
192244 atRule . remove ( ) ;
193245
194246 // eslint-disable-next-line consistent-return
195- return { url : resolvedUrl , media, prefix, isRequestable } ;
247+ return {
248+ url : resolvedUrl ,
249+ layer,
250+ supports,
251+ media,
252+ prefix,
253+ isRequestable,
254+ } ;
196255 }
197256
198257 atRule . remove ( ) ;
199258
200259 // eslint-disable-next-line consistent-return
201- return { url, media, prefix, isRequestable } ;
260+ return { url, layer , supports , media, prefix, isRequestable } ;
202261 } )
203262 ) ;
204263
@@ -212,10 +271,11 @@ const plugin = (options = {}) => {
212271 continue ;
213272 }
214273
215- const { url, isRequestable, media } = resolvedAtRule ;
274+ const { url, isRequestable, layer, supports, media } =
275+ resolvedAtRule ;
216276
217277 if ( ! isRequestable ) {
218- options . api . push ( { url, media, index } ) ;
278+ options . api . push ( { url, layer , supports , media, index } ) ;
219279
220280 // eslint-disable-next-line no-continue
221281 continue ;
@@ -237,7 +297,7 @@ const plugin = (options = {}) => {
237297 } ) ;
238298 }
239299
240- options . api . push ( { importName, media, index } ) ;
300+ options . api . push ( { importName, layer , supports , media, index } ) ;
241301 }
242302 } ,
243303 } ;
0 commit comments