Skip to content

Commit

Permalink
fix: adjust globalifySelector to not split selectors with parentheses. (
Browse files Browse the repository at this point in the history
#632)

Fixes #501
  • Loading branch information
gregschmit committed Jun 12, 2024
1 parent 133472c commit c435ebd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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;

Check failure on line 9 in src/modules/globalifySelector.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎·`

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 @@ -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))`,
);
});
});

0 comments on commit c435ebd

Please sign in to comment.