Skip to content

Commit c435ebd

Browse files
authoredJun 12, 2024··
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

+1-1
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

+6
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)
Please sign in to comment.