Skip to content

fix: Adjust globalifySelector to not split selectors with parentheses. #632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/modules/globalifySelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions test/modules/globalifySelector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))`,
);
});
});