Skip to content

Commit

Permalink
fix: Restrict :has, :not, :is, and :where to selector arguments
Browse files Browse the repository at this point in the history
(fixes #45)
  • Loading branch information
savetheclocktower authored and amaanq committed Aug 17, 2024
1 parent f6be52c commit 31584d6
Show file tree
Hide file tree
Showing 4 changed files with 5,953 additions and 5,458 deletions.
24 changes: 22 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,22 @@ 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 specific pseudo-class that can only accept a selector…
seq(
alias(
choice('has', 'not', 'is', 'where'),
$.class_name,
),
alias($.pseudo_class_with_selector_arguments, $.arguments),
),
// …or any other pseudo-class (for which we'll allow 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 @@ -217,6 +231,12 @@ module.exports = grammar({
')',
),

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

pseudo_element_arguments: $ => seq(
token.immediate('('),
sep(',', choice($._selector, repeat1($._value))),
Expand Down
133 changes: 116 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 31584d6

Please sign in to comment.