Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomhodgins/d7e3e90829abd38f4f86236987fb0f1e to your computer and use it in GitHub Desktop.
Save tomhodgins/d7e3e90829abd38f4f86236987fb0f1e to your computer and use it in GitHub Desktop.

The part where there are questions right now are you can have a rule list inside a rule, like:

@--custom {
  a {}
  b {}
  c {}
}

And you'd use "Parse a List of Rules" to parse the contents, the list of rules inside: https://drafts.csswg.org/css-syntax-3/#parse-list-of-rules You'd end up with a CSSRuleList object with the rules inside.

Or you can have a declaration list inside a rule, like

@--custom {
  a: ;
  b: ;
  c: ;
}

And you'd use "Parse a list of Declarations" to parse the contents, https://drafts.csswg.org/css-syntax-3/#parse-list-of-declarations which allows for properties and at-rules, but doesn't presently allow rules, and you'd end up with a CSSStyleDeclaration object with the properties inside.

What we don't know right now is how CSS syntax and these parsing algorithms will be changed to allow CSSStyleRule inside other rules, alongside property declarations, what does this parse into?

a {
  b: ;
  c {
    d: ;
  }
}

^ That hasn't been specified yet. It will probably mean a change to the CSS syntax spec, and also to CSSOM. Does this mean CSSStyleRule objects will contain CSS rules of their own? Will they be separate from the properties, or intermixed with them (does order matter?)

It's also possible, though I'm hoping not the case, that it could be a parser-only thing, and 'nested rules' never make it to CSSOM and are 'flattened' at parse time. This would be far less dynamic and useful since you lose the nested relationship in the stylesheet, and wouldn't be able to go in and dynamically change selectors and have it all update correctly. I really hope we get rules-inside-rule in CSSOM, 'melting' selector nesting is just a shadow of what rules-in-rules could be client-side if the browser understands the relationship.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment