MCPcopy Create free account
hub / github.com/chakra-ui/panda / parseSelectors

Function parseSelectors

packages/core/src/stringify.ts:147–187  ·  view source on GitHub ↗
(selector: string)

Source from the content-addressed store, hash-verified

145 * parseSelectors('&:is(:disabled, [disabled], [data-disabled]), .another') // [':is(:disabled, [disabled], [data-disabled])', '.another']
146 */
147export function parseSelectors(selector: string): string[] {
148 const result = [] as string[]
149 let parenCount = 0
150 let currentSelector = ''
151 let inEscape = false
152
153 for (let i = 0; i < selector.length; i++) {
154 const char = selector[i]
155
156 if (char === '\\' && !inEscape) {
157 inEscape = true
158 currentSelector += char
159 continue
160 }
161
162 if (inEscape) {
163 inEscape = false
164 currentSelector += char
165 continue
166 }
167
168 if (char === '(') {
169 parenCount++
170 } else if (char === ')') {
171 parenCount--
172 }
173
174 if (char === ',' && parenCount === 0) {
175 result.push(currentSelector.trim())
176 currentSelector = ''
177 } else {
178 currentSelector += char
179 }
180 }
181
182 if (currentSelector) {
183 result.push(currentSelector.trim())
184 }
185
186 return result
187}
188
189const parentSelectorRegex = /&/g
190const descendantSelectorRegex = /[ +>|~]/g

Callers 2

serializeStylesFunction · 0.90
parseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected