diff --git a/src/modules/globalifySelector.ts b/src/modules/globalifySelector.ts index 652cc77f..a60b43bf 100644 --- a/src/modules/globalifySelector.ts +++ b/src/modules/globalifySelector.ts @@ -6,7 +6,7 @@ * escaped combinators like `\~`. */ // TODO: maybe replace this ugly pattern with an actual selector parser? (https://github.com/leaverou/parsel, 2kb) -const combinatorPattern = /(?+~,]\s*)(?![^[]+\]|\d)/g; +const combinatorPattern = /(?+~,]\s*)(?![^(]*\))(?![^[]+\]|\d)/g; export function globalifySelector(selector: string) { const parts = selector.trim().split(combinatorPattern); diff --git a/test/modules/globalifySelector.test.ts b/test/modules/globalifySelector.test.ts index cddbe7f8..dc86e4f7 100644 --- a/test/modules/globalifySelector.test.ts +++ b/test/modules/globalifySelector.test.ts @@ -57,4 +57,10 @@ describe('globalifySelector', () => { `:global(p:nth-child(n+8):nth-child(-n+15))`, ); }); + + it('works with selector with whitespace in parenthesis: :is()', async () => { + expect(globalifySelector('article :is(h1, h2)')).toBe( + `:global(article) :global(:is(h1, h2))`, + ); + }); });