MCPcopy
hub / github.com/webpack/webpack / consumeABlock

Function consumeABlock

lib/css/syntax.js:2454–2466  ·  view source on GitHub ↗
(ts)

Source from the content-addressed store, hash-verified

2452 * @returns {{ decls: Declaration[], rules: Rule[], blockStart: number, blockEnd: number }} block decls + rules and the `{` start / `}` end offsets
2453 */
2454const consumeABlock = (ts) => {
2455 // Capture the opening `{`'s start before advancing — the stream reuses one
2456 // token instance, so `consumeABlocksContents` below would overwrite it.
2457 const blockStart = ts.next().start;
2458 // Assert (spec): the next token is <{-token>.
2459 // Discard a token from input. Consume a block's contents from input and let result be the result. Discard a token from input.
2460 ts.discard();
2461 const { decls, rules } = consumeABlocksContents(ts);
2462 const close = ts.next();
2463 const end = close.type === TT_RIGHT_CURLY_BRACKET ? close.end : close.start;
2464 ts.discard();
2465 return { decls, rules, blockStart, blockEnd: end };
2466};
2467
2468/**
2469 * 2-token lookahead: is the next non-whitespace pair `<ident> <colon>` (the prerequisite for consume-a-declaration steps 1 + 3)? Used by `consumeABlocksContents` to skip a declaration attempt that would otherwise call consume-the-remnants-of-a-bad-declaration and be undone by `restoreMark`. A webpack fast-path, not a spec algorithm — so the implementation is free to peek cheaply. It scans raw code points after the cached ident for the next significant one (skipping whitespace + comments) rather than tokenizing them, and never advances the stream: the ident stays cached in `_next` for `consumeADeclaration` to reuse instead of re-tokenizing the property name. Comments skipped here fire `onComment` later, when the chosen consume algorithm tokenizes past them (once, in source order, as before).

Callers 2

consumeAnAtRuleFunction · 0.85
consumeAQualifiedRuleFunction · 0.85

Calls 3

consumeABlocksContentsFunction · 0.85
discardMethod · 0.80
nextMethod · 0.45

Tested by

no test coverage detected