From c435ebd633b9b5d461e8256b748a9f6b28680965 Mon Sep 17 00:00:00 2001 From: Greg Schmit <14255284+gregschmit@users.noreply.github.com> Date: Wed, 12 Jun 2024 06:16:31 -0500 Subject: [PATCH] fix: adjust globalifySelector to not split selectors with parentheses. (#632) Fixes #501 --- src/modules/globalifySelector.ts | 2 +- test/modules/globalifySelector.test.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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 cb198eae..6d964dd7 100644 --- a/test/modules/globalifySelector.test.ts +++ b/test/modules/globalifySelector.test.ts @@ -58,4 +58,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))`, + ); + }); });