Skip to content

Commit

Permalink
fix: Restrict :has and :not to selector arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
savetheclocktower committed Jan 26, 2024
1 parent 98c7b3d commit 861b51d
Show file tree
Hide file tree
Showing 5 changed files with 5,908 additions and 5,444 deletions.
21 changes: 19 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,19 @@ module.exports = grammar({
pseudo_class_selector: $ => seq(
optional($._selector),
alias($._pseudo_class_selector_colon, ':'),
alias($.identifier, $.class_name),
optional(alias($.pseudo_class_arguments, $.arguments)),
choice(
// Either a `:has` or `:not` (which take only selectors)…
seq(
alias(choice('has', 'not'), $.class_name),
alias($.pseudo_class_has_or_not_arguments, $.arguments),
),
// …or another pseudo-class (which can take a more diverse set of
// arguments).
seq(
alias($.identifier, $.class_name),
optional(alias($.pseudo_class_arguments, $.arguments)),
),
),
),

pseudo_element_selector: $ => seq(
Expand Down Expand Up @@ -220,6 +231,12 @@ module.exports = grammar({
')',
),

pseudo_class_has_or_not_arguments: $ => seq(
token.immediate('('),
sep(',', $._selector),
')',
),

pseudo_element_arguments: $ => seq(
token.immediate('('),
sep(',', choice($._selector, repeat1($._value))),
Expand Down
125 changes: 108 additions & 17 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 861b51d

Please sign in to comment.