Skip to content

[css-nesting] Allow more direct nesting delimiters #5746

@jonathantneal

Description

@jonathantneal

CSS Nesting avoids unbounded lookahead to tell whether a given bit of text is a declaration or the start of a style rule by requiring a single token of lookahead in its parsing. These tokens are either the <delim-token> or <at-keyword-token>. More specifically, the <delim-token> must have a value of &, and the <at-keyword-token> must have a value of nest.

May we expand the allowable value of the <delim-token> to include non-& values for descendant nesting?

Before this proposed change, here is a sample of allowable CSS (from CSS Nesting: Example 4):

.foo {
  color: blue;
  & > .bar { color: red; }
}

.foo, .bar {
  color: blue;
  & + .baz, &.qux { color: red; }
}

.foo {
  color: blue;
  & .bar, & .baz, & .qux { color: red; }
}

After this proposed change, here is an updated sample of allowable CSS:

.foo {
  color: blue;
  > .bar { color: red; }
}

.foo, .bar {
  color: blue;
  + .baz, &.qux { color: red; }
}

.foo {
  color: blue;
  .bar, .baz, .qux { color: red; }
}

This would further align syntactically-allowable CSS nesting with existing user-land CSS nesting (e.g. Stylis, Sass).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions