@@ -167,101 +167,3 @@ export function* findUrls(
167
167
}
168
168
}
169
169
}
170
-
171
- /**
172
- * Scans a CSS or Sass file and locates all valid import/use directive values as defined by the
173
- * syntax specification.
174
- * @param contents A string containing a CSS or Sass file to scan.
175
- * @returns An iterable that yields each CSS directive value found.
176
- */
177
- export function * findImports (
178
- contents : string ,
179
- ) : Iterable < { start : number ; end : number ; specifier : string } > {
180
- yield * find ( contents , '@import ' ) ;
181
- yield * find ( contents , '@use ' ) ;
182
- }
183
-
184
- /**
185
- * Scans a CSS or Sass file and locates all valid function/directive values as defined by the
186
- * syntax specification.
187
- * @param contents A string containing a CSS or Sass file to scan.
188
- * @param prefix The prefix to start a valid segment.
189
- * @returns An iterable that yields each CSS url function value found.
190
- */
191
- function * find (
192
- contents : string ,
193
- prefix : string ,
194
- ) : Iterable < { start : number ; end : number ; specifier : string } > {
195
- let pos = 0 ;
196
- let width = 1 ;
197
- let current = - 1 ;
198
- const next = ( ) => {
199
- pos += width ;
200
- current = contents . codePointAt ( pos ) ?? - 1 ;
201
- width = current > 0xffff ? 2 : 1 ;
202
-
203
- return current ;
204
- } ;
205
-
206
- // Based on https://www.w3.org/TR/css-syntax-3/#consume-ident-like-token
207
- while ( ( pos = contents . indexOf ( prefix , pos ) ) !== - 1 ) {
208
- // Set to position of the last character in prefix
209
- pos += prefix . length - 1 ;
210
- width = 1 ;
211
-
212
- // Consume all leading whitespace
213
- while ( isWhitespace ( next ( ) ) ) {
214
- /* empty */
215
- }
216
-
217
- // Initialize URL state
218
- const url = { start : pos , end : - 1 , specifier : '' } ;
219
- let complete = false ;
220
-
221
- // If " or ', then consume the value as a string
222
- if ( current === 0x0022 || current === 0x0027 ) {
223
- const ending = current ;
224
- // Based on https://www.w3.org/TR/css-syntax-3/#consume-string-token
225
- while ( ! complete ) {
226
- switch ( next ( ) ) {
227
- case - 1 : // EOF
228
- return ;
229
- case 0x000a : // line feed
230
- case 0x000c : // form feed
231
- case 0x000d : // carriage return
232
- // Invalid
233
- complete = true ;
234
- break ;
235
- case 0x005c : // \ -- character escape
236
- // If not EOF or newline, add the character after the escape
237
- switch ( next ( ) ) {
238
- case - 1 :
239
- return ;
240
- case 0x000a : // line feed
241
- case 0x000c : // form feed
242
- case 0x000d : // carriage return
243
- // Skip when inside a string
244
- break ;
245
- default :
246
- // TODO: Handle hex escape codes
247
- url . specifier += String . fromCodePoint ( current ) ;
248
- break ;
249
- }
250
- break ;
251
- case ending :
252
- // Full string position should include the quotes for replacement
253
- url . end = pos + 1 ;
254
- complete = true ;
255
- yield url ;
256
- break ;
257
- default :
258
- url . specifier += String . fromCodePoint ( current ) ;
259
- break ;
260
- }
261
- }
262
-
263
- next ( ) ;
264
- continue ;
265
- }
266
- }
267
- }
0 commit comments