({
selector,
scopeSelector,
hostSelector,
isParentSelector = false,
}: {
selector: string;
scopeSelector: string;
hostSelector: string;
isParentSelector?: boolean;
})
| 648 | // for example `selector = 'a:where(.one)'` could be the parent, while recursive call |
| 649 | // would have `selector = '.one'`. |
| 650 | private _scopeSelector({ |
| 651 | selector, |
| 652 | scopeSelector, |
| 653 | hostSelector, |
| 654 | isParentSelector = false, |
| 655 | }: { |
| 656 | selector: string; |
| 657 | scopeSelector: string; |
| 658 | hostSelector: string; |
| 659 | isParentSelector?: boolean; |
| 660 | }): string { |
| 661 | // Split the selector into independent parts by `,` (comma) unless |
| 662 | // comma is within parenthesis, for example `:is(.one, two)`. |
| 663 | // Negative lookup after comma allows not splitting inside nested parenthesis, |
| 664 | // up to three levels (((,))). |
| 665 | const selectorSplitRe = |
| 666 | / ?,(?!(?:[^)(]*(?:\([^)(]*(?:\([^)(]*(?:\([^)(]*\)[^)(]*)*\)[^)(]*)*\)[^)(]*)*\))) ?/; |
| 667 | |
| 668 | return selector |
| 669 | .split(selectorSplitRe) |
| 670 | .map((part) => part.split(_shadowDeepSelectors)) |
| 671 | .map((deepParts) => { |
| 672 | const [shallowPart, ...otherParts] = deepParts; |
| 673 | const applyScope = (shallowPart: string) => { |
| 674 | if (this._selectorNeedsScoping(shallowPart, scopeSelector)) { |
| 675 | return this._applySelectorScope({ |
| 676 | selector: shallowPart, |
| 677 | scopeSelector, |
| 678 | hostSelector, |
| 679 | isParentSelector, |
| 680 | }); |
| 681 | } else { |
| 682 | return shallowPart; |
| 683 | } |
| 684 | }; |
| 685 | return [applyScope(shallowPart), ...otherParts].join(' '); |
| 686 | }) |
| 687 | .join(', '); |
| 688 | } |
| 689 | |
| 690 | private _selectorNeedsScoping(selector: string, scopeSelector: string): boolean { |
| 691 | const re = this._makeScopeMatcher(scopeSelector); |
no test coverage detected