(
element: Element,
className: string,
globalOperators: Set<string>,
)
| 316 | } |
| 317 | |
| 318 | private normalizeGlobalOperatorSelectors( |
| 319 | element: Element, |
| 320 | className: string, |
| 321 | globalOperators: Set<string>, |
| 322 | ): boolean { |
| 323 | if (Array.isArray(element.children)) { |
| 324 | const children = element.children; |
| 325 | |
| 326 | for (let index = 0; index < children.length; ) { |
| 327 | if ( |
| 328 | this.normalizeGlobalOperatorSelectors( |
| 329 | children[index], |
| 330 | className, |
| 331 | globalOperators, |
| 332 | ) |
| 333 | ) { |
| 334 | index += 1; |
| 335 | } else { |
| 336 | children.splice(index, 1); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | element.length = children.length; |
| 341 | } |
| 342 | |
| 343 | if (element.type !== "rule") { |
| 344 | return true; |
| 345 | } |
| 346 | |
| 347 | const { selectors, touched } = this.normalizeSelectorList( |
| 348 | element.props, |
| 349 | className, |
| 350 | globalOperators, |
| 351 | ); |
| 352 | |
| 353 | if (!touched) { |
| 354 | return true; |
| 355 | } |
| 356 | |
| 357 | if (selectors.length === 0) { |
| 358 | return false; |
| 359 | } |
| 360 | |
| 361 | element.props = selectors; |
| 362 | |
| 363 | if (typeof element.value === "string") { |
| 364 | element.value = |
| 365 | unwrapGlobalOperator(element.value).trim() || |
| 366 | (selectors[0] ?? element.value); |
| 367 | } |
| 368 | |
| 369 | return true; |
| 370 | } |
| 371 | |
| 372 | private normalizeSelectorList( |
| 373 | props: Element["props"], |
no test coverage detected