Skip to content

Commit

Permalink
fix: allow :host, :host-context, :nth-child, and `:nth-last-chi…
Browse files Browse the repository at this point in the history
…ld` to take selectors
  • Loading branch information
savetheclocktower authored Nov 11, 2024
1 parent 85ed32a commit eca27e1
Show file tree
Hide file tree
Showing 5 changed files with 6,299 additions and 5,367 deletions.
36 changes: 35 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,15 @@ module.exports = grammar({
// Either a specific pseudo-class that can only accept a selector…
seq(
alias(
choice('has', 'not', 'is', 'where'),
choice('has', 'not', 'is', 'where', 'host', 'host-context'),
$.class_name,
),
alias($.pseudo_class_with_selector_arguments, $.arguments),
),
// …or an `nth-child` or `nth-last-child` selector (which can
// optionally accept a selector)…
$._nth_child_pseudo_class_selector,

// …or any other pseudo-class (for which we'll allow a more diverse set
// of arguments).
seq(
Expand All @@ -191,6 +195,16 @@ module.exports = grammar({
),
),

// Only `nth-child`/`nth-last-child`, not `nth-of-type`/`nth-last-of-type`,
// allows an optional filtering selector as a parameter.
_nth_child_pseudo_class_selector: $ => seq(
alias(
choice('nth-child', 'nth-last-child'),
$.class_name,
),
alias($.pseudo_class_nth_child_arguments, $.arguments),
),

pseudo_element_selector: $ => seq(
optional($._selector),
'::',
Expand Down Expand Up @@ -237,6 +251,26 @@ module.exports = grammar({
')',
),

pseudo_class_nth_child_arguments: $ => prec(-1, seq(
token.immediate('('),
choice(
alias('even', $.plain_value),
alias('odd', $.plain_value),
$.integer_value,
alias($._nth_functional_notation, $.plain_value),
),
optional(
seq(
'of',
$._selector,
),
),
')',
)),

// An+B notation for `nth-child`/`nth-last-child`.
_nth_functional_notation: _ => /-?(\d)*n\s*(\+\s*\d+)?/,

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

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

4 changes: 4 additions & 0 deletions src/node-types.json

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

Loading

0 comments on commit eca27e1

Please sign in to comment.