(ts, nested = false)
| 2288 | * @returns {AtRule | undefined} the parsed at-rule |
| 2289 | */ |
| 2290 | const consumeAnAtRule = (ts, nested = false) => { |
| 2291 | // Assert (spec): the next token is an <at-keyword-token>. |
| 2292 | // Consume a token from input, and let rule be a new at-rule with its name set to the returned token’s value, its prelude initially set to an empty list, and no declarations or child rules. |
| 2293 | const head = ts.consume(); |
| 2294 | const rule = /** @type {AtRule} */ ( |
| 2295 | _mkContainer(T_AT_RULE, head.start, head.end) |
| 2296 | ); |
| 2297 | _setName( |
| 2298 | rule, |
| 2299 | ts.input.slice(head.start + 1, head.end), |
| 2300 | head.start, |
| 2301 | head.end |
| 2302 | ); |
| 2303 | const prelude = _list(); |
| 2304 | _setPrelude(rule, prelude); |
| 2305 | // declarations / childRules / blockStart (-1) / blockEnd (-1) keep their |
| 2306 | // defaults (no block: the `;` / EOF / nested-`}` at-rule forms). |
| 2307 | |
| 2308 | // Process input |
| 2309 | for (;;) { |
| 2310 | const t = ts.next(); |
| 2311 | |
| 2312 | // <semicolon-token> |
| 2313 | // <EOF-token> |
| 2314 | // Discard a token from input. If rule is valid in the current context, return it; otherwise return nothing. |
| 2315 | if (t.type === TT_SEMICOLON || t.type === TT_EOF) { |
| 2316 | ts.discard(); |
| 2317 | _setEnd(rule, t.start); |
| 2318 | return rule; |
| 2319 | } |
| 2320 | // <}-token> |
| 2321 | // If nested is true: if rule is valid in the current context, return it; otherwise return nothing. |
| 2322 | // Otherwise, consume a token and append the result to rule’s prelude. |
| 2323 | else if (t.type === TT_RIGHT_CURLY_BRACKET) { |
| 2324 | if (nested) { |
| 2325 | _setEnd(rule, t.start); |
| 2326 | return rule; |
| 2327 | } |
| 2328 | prelude.push(consumeATokenAsNode(ts)); |
| 2329 | continue; |
| 2330 | } |
| 2331 | // <{-token> |
| 2332 | // Consume a block from input, and assign the result to rule's declarations and child rules. |
| 2333 | else if (t.type === TT_LEFT_CURLY_BRACKET) { |
| 2334 | const block = consumeABlock(ts); |
| 2335 | _setBody(rule, block.decls, block.rules); |
| 2336 | _setBlock(rule, block.blockStart, block.blockEnd); |
| 2337 | _setEnd(rule, block.blockEnd); |
| 2338 | return rule; |
| 2339 | } |
| 2340 | |
| 2341 | // anything else |
| 2342 | // Consume a component value from input and append the returned value to rule’s prelude. |
| 2343 | prelude.push(consumeAComponentValue(ts, t)); |
| 2344 | } |
| 2345 | }; |
| 2346 | |
| 2347 | /** |
no test coverage detected