MCPcopy
hub / github.com/webpack/webpack / consumeAnAtRule

Function consumeAnAtRule

lib/css/syntax.js:2290–2345  ·  view source on GitHub ↗
(ts, nested = false)

Source from the content-addressed store, hash-verified

2288 * @returns {AtRule | undefined} the parsed at-rule
2289 */
2290const 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/**

Callers 3

parseARuleFunction · 0.85
consumeABlocksContentsFunction · 0.85

Calls 9

_listFunction · 0.85
consumeATokenAsNodeFunction · 0.85
consumeABlockFunction · 0.85
consumeAComponentValueFunction · 0.85
consumeMethod · 0.80
sliceMethod · 0.80
discardMethod · 0.80
nextMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected