MCPcopy
hub / github.com/webpack/webpack / parseARule

Function parseARule

lib/css/syntax.js:2118–2139  ·  view source on GitHub ↗
(input, pos, comment)

Source from the content-addressed store, hash-verified

2116 * @returns {Rule | undefined} the parsed rule
2117 */
2118const parseARule = (input, pos, comment) => {
2119 // 1. Normalize input, and set input to the result.
2120 const ts = normalizeIntoTokenStream(input, pos, comment);
2121 useObjectBackend(ts.locConverter);
2122 // 2. Discard whitespace from input.
2123 while (ts.next().type === TT_WHITESPACE) ts.discard();
2124 // 3. If the next token from input is an <EOF-token>, return a syntax error.
2125 // Otherwise, if the next token from input is an <at-keyword-token>, consume an at-rule from input, and let rule be the return value.
2126 // Otherwise, consume a qualified rule from input and let rule be the return value.
2127 // If nothing or an invalid rule error was returned, return a syntax error.
2128 const head = ts.next();
2129 if (head.type === TT_EOF) return undefined;
2130 const rule =
2131 head.type === TT_AT_KEYWORD
2132 ? consumeAnAtRule(ts)
2133 : consumeAQualifiedRule(ts);
2134 if (!rule) return undefined;
2135 // 4. Discard whitespace from input.
2136 while (ts.next().type === TT_WHITESPACE) ts.discard();
2137 // 5. If the next token from input is an <EOF-token>, return rule. Otherwise, return a syntax error.
2138 return ts.next().type === TT_EOF ? rule : undefined;
2139};
2140
2141/**
2142 * Parse a declaration, CSS Syntax Level 3

Callers 1

Calls 6

normalizeIntoTokenStreamFunction · 0.85
useObjectBackendFunction · 0.85
consumeAnAtRuleFunction · 0.85
consumeAQualifiedRuleFunction · 0.85
discardMethod · 0.80
nextMethod · 0.45

Tested by

no test coverage detected