Skip to content

Commit 3a719d5

Browse files
committed
fix: Adjust globalifySelector to not split selectors with parentheses.
1 parent 276037a commit 3a719d5

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
@@ -57,4 +57,10 @@ describe('globalifySelector', () => {
5757
`:global(p:nth-child(n+8):nth-child(-n+15))`,
5858
);
5959
});
60+
61+
it('works with selector with whitespace in parenthesis: :is()', async () => {
62+
expect(globalifySelector('article :is(h1, h2)')).toBe(
63+
`:global(article) :global(:is(h1, h2))`,
64+
);
65+
});
6066
});

0 commit comments

Comments
 (0)