Skip to content

Commit c435ebd

Browse files
authored
fix: adjust globalifySelector to not split selectors with parentheses. (#632)
Fixes #501
1 parent 133472c commit c435ebd

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/modules/globalifySelector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* escaped combinators like `\~`.
77
*/
88
// TODO: maybe replace this ugly pattern with an actual selector parser? (https://github.com/leaverou/parsel, 2kb)
9-
const combinatorPattern = /(?<!\\)(?:\\\\)*([ >+~,]\s*)(?![^[]+\]|\d)/g;
9+
const combinatorPattern = /(?<!\\)(?:\\\\)*([ >+~,]\s*)(?![^(]*\))(?![^[]+\]|\d)/g;
1010

1111
export function globalifySelector(selector: string) {
1212
const parts = selector.trim().split(combinatorPattern);

test/modules/globalifySelector.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,10 @@ describe('globalifySelector', () => {
5858
`:global(p:nth-child(n+8):nth-child(-n+15))`,
5959
);
6060
});
61+
62+
it('works with selector with whitespace in parenthesis: :is()', async () => {
63+
expect(globalifySelector('article :is(h1, h2)')).toBe(
64+
`:global(article) :global(:is(h1, h2))`,
65+
);
66+
});
6167
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy