MCPcopy
hub / github.com/webpack/webpack / walkSelectorList

Method walkSelectorList

lib/css/CssParser.js:1997–2170  ·  view source on GitHub ↗
(values, localMode, topLevel = true)

Source from the content-addressed store, hash-verified

1995 * @returns {void}
1996 */
1997 const walkSelectorList = (values, localMode, topLevel = true) => {
1998 // At a rule's top level, inherit persistent `modeData` (or the one-shot `suppressNextRulePrelude` → "global"); recursive calls use the passed `localMode`.
1999 let segmentMode = localMode;
2000 if (topLevel) {
2001 if (suppressNextRulePrelude) {
2002 segmentMode = "global";
2003 suppressNextRulePrelude = false;
2004 } else if (modeData) {
2005 segmentMode = modeData;
2006 }
2007 }
2008 for (let i = 0; i < values.length; i++) {
2009 const v = values[i];
2010 switch (A.type(v)) {
2011 case NodeType.Whitespace:
2012 break;
2013 case NodeType.Comma:
2014 if (topLevel) {
2015 // Top-level comma resets the segment + persistent mode and, in pure mode, finalizes the segment's purity.
2016 segmentMode = localMode;
2017 modeData = undefined;
2018 pure.finalizeSelector();
2019 }
2020 break;
2021 case NodeType.Colon: {
2022 // Look ahead for `:local` / `:global` markers; other pseudos fall through.
2023 const next = values[i + 1];
2024 if (!next) break;
2025 const nextType = A.type(next);
2026 if (nextType === NodeType.Ident) {
2027 const raw = A.value(next);
2028 const isLocal = equalsLowerCase(raw, "local");
2029 if (isLocal || equalsLowerCase(raw, "global")) {
2030 const id = isLocal ? "local" : "global";
2031 // Bare `:local` / `:global`: switch the segment (and top-level persistent) mode and strip the marker.
2032 const afterIsWhitespace = stripBareMarker(
2033 v,
2034 next,
2035 values[i + 2]
2036 );
2037 // Bare `:local` / `:global` needs whitespace before the next selector (else `:local.b` is ambiguous) — warn when none follows.
2038 if (!afterIsWhitespace) {
2039 this._emitWarning(
2040 state,
2041 `Missing whitespace after ':${id}' in '${source.slice(
2042 A.start(v),
2043 findLeftCurly(source, A.end(next)) + 1
2044 )}'`,
2045 locConverter,
2046 A.start(v),
2047 A.end(next)
2048 );
2049 }
2050 segmentMode = id;
2051 if (topLevel) modeData = id;
2052 // Skip past the colon + ident.
2053 i += 1;
2054 }

Callers

nothing calls this directly

Calls 15

_emitWarningMethod · 0.95
equalsLowerCaseFunction · 0.85
findLeftCurlyFunction · 0.85
isDashedIdentifierFunction · 0.85
finalizeSelectorMethod · 0.80
sliceMethod · 0.80
unescapedNameMethod · 0.80
typeFlagMethod · 0.80
unescapedMethod · 0.80
markLocalMethod · 0.80
ancestorHadLocalMethod · 0.80
typeMethod · 0.45

Tested by

no test coverage detected