-
-
Notifications
You must be signed in to change notification settings - Fork 147
Allow :is() and :where() selectors #789
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
base: main
Are you sure you want to change the base?
Changes from 11 commits
a92102d
7e3300c
8336e48
83383f5
15263f7
18d052e
05b9aa3
23cdd58
74b8138
1e38ea7
effc878
4bce81f
c01cfe5
40f1a68
c30db48
8635c88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -85,6 +85,25 @@ export namespace Selector { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function matches(element: Element, selector: string): boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Private.protoMatchFunc.call(element, selector); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Remove :is() and :where() functional pseudo-classes so that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * commas inside them do not count as top-level selector separators. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function stripIsWhere(selector: string): string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return selector.replace( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /:(is|where)\(([^()]|\([^()]*\))*\)/g, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return selector.replace( | |
| /:(is|where)\(([^()]|\([^()]*\))*\)/g, | |
| '' | |
| ); | |
| let result = ''; | |
| const len = selector.length; | |
| let i = 0; | |
| while (i < len) { | |
| const ch = selector[i]; | |
| if ( | |
| ch === ':' && | |
| (selector.startsWith('is(', i + 1) || | |
| selector.startsWith('where(', i + 1)) | |
| ) { | |
| // Determine which function name we matched. | |
| const isIs = selector.startsWith('is(', i + 1); | |
| const nameLen = isIs ? 2 : 5; // 'is' or 'where' | |
| const openParenIndex = i + 1 + nameLen; | |
| // Sanity check: ensure there is an opening parenthesis. | |
| if (openParenIndex >= len || selector[openParenIndex] !== '(') { | |
| // Fallback: treat ':' as a normal character. | |
| result += ch; | |
| i++; | |
| continue; | |
| } | |
| // Skip over the entire :is(...) or :where(...) construct, | |
| // correctly handling nested parentheses. | |
| let depth = 1; | |
| let j = openParenIndex + 1; | |
| while (j < len && depth > 0) { | |
| const cj = selector[j]; | |
| if (cj === '(') { | |
| depth++; | |
| } else if (cj === ')') { | |
| depth--; | |
| } | |
| j++; | |
| } | |
| // Set i to the position after the closing parenthesis (or end of string). | |
| i = j; | |
| continue; | |
| } | |
| // Normal character, keep it. | |
| result += ch; | |
| i++; | |
| } | |
| return result; |
Copilot
AI
Mar 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasTopLevelComma() now allows selectors like .a:is(.b,.c), but Selector.calculateSpecificity()/Private.calculateSingle() still split the selector at the first comma (selector.split(',', 1)[0]). That will cut commas inside :is()/:where() and produce incorrect specificity values, which affects ordering logic in context menus and keybinding resolution. Please update specificity parsing to ignore commas inside :is()/:where() (or implement their Selectors Level 4 specificity rules) so the new allowed selectors don’t break precedence decisions.
Uh oh!
There was an error while loading. Please reload this page.