@@ -118,15 +118,54 @@ function parseNode(atRule, key) {
118
118
throw error ;
119
119
}
120
120
121
- const mediaNodes = paramsNodes . slice ( 1 ) ;
121
+ const additionalNodes = paramsNodes . slice ( 1 ) ;
122
+
123
+ let supports ;
124
+ let layer ;
122
125
let media ;
123
126
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
+ }
126
165
}
127
166
128
167
// eslint-disable-next-line consistent-return
129
- return { atRule, prefix, url, media, isRequestable } ;
168
+ return { atRule, prefix, url, layer , supports , media, isRequestable } ;
130
169
}
131
170
132
171
const plugin = ( options = { } ) => {
@@ -160,11 +199,24 @@ const plugin = (options = {}) => {
160
199
161
200
const resolvedAtRules = await Promise . all (
162
201
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 ;
165
211
166
212
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
+ ) ;
168
220
169
221
if ( ! needKeep ) {
170
222
return ;
@@ -192,13 +244,20 @@ const plugin = (options = {}) => {
192
244
atRule . remove ( ) ;
193
245
194
246
// 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
+ } ;
196
255
}
197
256
198
257
atRule . remove ( ) ;
199
258
200
259
// eslint-disable-next-line consistent-return
201
- return { url, media, prefix, isRequestable } ;
260
+ return { url, layer , supports , media, prefix, isRequestable } ;
202
261
} )
203
262
) ;
204
263
@@ -212,10 +271,11 @@ const plugin = (options = {}) => {
212
271
continue ;
213
272
}
214
273
215
- const { url, isRequestable, media } = resolvedAtRule ;
274
+ const { url, isRequestable, layer, supports, media } =
275
+ resolvedAtRule ;
216
276
217
277
if ( ! isRequestable ) {
218
- options . api . push ( { url, media, index } ) ;
278
+ options . api . push ( { url, layer , supports , media, index } ) ;
219
279
220
280
// eslint-disable-next-line no-continue
221
281
continue ;
@@ -237,7 +297,7 @@ const plugin = (options = {}) => {
237
297
} ) ;
238
298
}
239
299
240
- options . api . push ( { importName, media, index } ) ;
300
+ options . api . push ( { importName, layer , supports , media, index } ) ;
241
301
}
242
302
} ,
243
303
} ;
0 commit comments