Skip to content

Commit eca27e1

Browse files
fix: allow :host, :host-context, :nth-child, and :nth-last-child to take selectors
1 parent 85ed32a commit eca27e1

File tree

5 files changed

+6299
-5367
lines changed

5 files changed

+6299
-5367
lines changed

grammar.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,15 @@ module.exports = grammar({
177177
// Either a specific pseudo-class that can only accept a selector…
178178
seq(
179179
alias(
180-
choice('has', 'not', 'is', 'where'),
180+
choice('has', 'not', 'is', 'where', 'host', 'host-context'),
181181
$.class_name,
182182
),
183183
alias($.pseudo_class_with_selector_arguments, $.arguments),
184184
),
185+
// …or an `nth-child` or `nth-last-child` selector (which can
186+
// optionally accept a selector)…
187+
$._nth_child_pseudo_class_selector,
188+
185189
// …or any other pseudo-class (for which we'll allow a more diverse set
186190
// of arguments).
187191
seq(
@@ -191,6 +195,16 @@ module.exports = grammar({
191195
),
192196
),
193197

198+
// Only `nth-child`/`nth-last-child`, not `nth-of-type`/`nth-last-of-type`,
199+
// allows an optional filtering selector as a parameter.
200+
_nth_child_pseudo_class_selector: $ => seq(
201+
alias(
202+
choice('nth-child', 'nth-last-child'),
203+
$.class_name,
204+
),
205+
alias($.pseudo_class_nth_child_arguments, $.arguments),
206+
),
207+
194208
pseudo_element_selector: $ => seq(
195209
optional($._selector),
196210
'::',
@@ -237,6 +251,26 @@ module.exports = grammar({
237251
')',
238252
),
239253

254+
pseudo_class_nth_child_arguments: $ => prec(-1, seq(
255+
token.immediate('('),
256+
choice(
257+
alias('even', $.plain_value),
258+
alias('odd', $.plain_value),
259+
$.integer_value,
260+
alias($._nth_functional_notation, $.plain_value),
261+
),
262+
optional(
263+
seq(
264+
'of',
265+
$._selector,
266+
),
267+
),
268+
')',
269+
)),
270+
271+
// An+B notation for `nth-child`/`nth-last-child`.
272+
_nth_functional_notation: _ => /-?(\d)*n\s*(\+\s*\d+)?/,
273+
240274
pseudo_element_arguments: $ => seq(
241275
token.immediate('('),
242276
sep(',', choice($._selector, repeat1($._value))),

src/grammar.json

Lines changed: 125 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node-types.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)