(ts, onRule)
| 2243 | * @returns {Rule[]} top-level rules (empty when `onRule` is given) |
| 2244 | */ |
| 2245 | const consumeAStylesheetsContents = (ts, onRule) => { |
| 2246 | // Let rules be an initially empty list of rules. |
| 2247 | /** @type {Rule[]} */ |
| 2248 | const rules = []; |
| 2249 | |
| 2250 | // Process input |
| 2251 | for (;;) { |
| 2252 | const t = ts.next(); |
| 2253 | // <whitespace-token> / <CDO-token> / <CDC-token> |
| 2254 | // Discard a token from input. |
| 2255 | if (t.type === TT_WHITESPACE || t.type === TT_CDO || t.type === TT_CDC) { |
| 2256 | ts.discard(); |
| 2257 | } |
| 2258 | // <EOF-token> |
| 2259 | // Return rules. |
| 2260 | else if (t.type === TT_EOF) { |
| 2261 | return rules; |
| 2262 | } |
| 2263 | // <at-keyword-token> |
| 2264 | // Consume an at-rule from input. If anything is returned, append it to rules. |
| 2265 | else if (t.type === TT_AT_KEYWORD) { |
| 2266 | const at = consumeAnAtRule(ts); |
| 2267 | if (at) { |
| 2268 | if (onRule) onRule(at); |
| 2269 | else rules.push(at); |
| 2270 | } |
| 2271 | } |
| 2272 | // anything else |
| 2273 | // Consume a qualified rule from input. If a rule is returned, append it to rules. |
| 2274 | else { |
| 2275 | const rule = consumeAQualifiedRule(ts); |
| 2276 | if (rule) { |
| 2277 | if (onRule) onRule(rule); |
| 2278 | else rules.push(rule); |
| 2279 | } |
| 2280 | } |
| 2281 | } |
| 2282 | }; |
| 2283 | |
| 2284 | /** |
| 2285 | * Consume an at-rule, CSS Syntax Level 3 [§5.4.2](https://drafts.csswg.org/css-syntax/#consume-at-rule) — the next token must be an <at-keyword-token> (asserted); consumes the prelude up to `;` / `{` / `}` / EOF; `{` consumes the block (§5.4.4) onto `.block`, `;` / EOF is discarded, a top-level `}` (when not `nested`) is appended via `consumeAComponentValue`. |
no test coverage detected