Skip to content

Commit 6f02147

Browse files
LeaVeroufantasai
andcommitted
[css-nesting-1] Proposal summary, formatting + some more pros and cons
Co-Authored-By: fantasai <[email protected]>
1 parent 501e285 commit 6f02147

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

css-nesting-1/proposals.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ To organize the discussion a bit, the options we're looking at are:
99
1. Just at-rules. This means any nested at-rule, like a nested @media, or the no-op `@nest;` rule we'd introduce.
1010
2. [(link)](https://github.com/w3c/csswg-drafts/issues/7834#issuecomment-1268979633) The above, plus any style rule starting with an `&`. (Rules following the switch can start with whatever.)
1111
3. [(link)](https://github.com/w3c/csswg-drafts/issues/7834#issuecomment-1270665794) The above, plus any style rule starting with a non-ident. (So `.foo`, `:hover`, etc will trigger the switch, but `div` won't.) (Rules following the switch can start with whatever.)
12-
3. [Lea's proposal](https://github.com/w3c/csswg-drafts/issues/7834#issuecomment-1272373216) - No parsing switch, instead every nested rule has to be unambiguous on its own, by starting with anything but an ident. (You can write `& div` or `:is(div)` if you need to start a selector with a type selector.) (This employs the same parsing strat as (2.3) to avoid accidentally parsing invalid properties like `//color: red;` as rules.)
12+
3. [Lea's proposal](https://github.com/w3c/csswg-drafts/issues/7834#issuecomment-1272373216) - No parsing switch, instead every nested rule has to be unambiguous on its own, by starting with anything but an ident. (You can write `& div` or `:is(div)` if you need to start a selector with a type selector.) (This employs the same parsing strat as (2.iii) to avoid accidentally parsing invalid properties like `//color: red;` as rules.)
1313
4. [Post-nesting proposal](https://github.com/w3c/csswg-drafts/issues/7834#issuecomment-1276360012) - Block after main rule containing nested rules, no `&` needed in nested selectors except for disambiguation
1414
1. Could add the rule block with an `@nest` rule
1515
2. Could add the rule block with special ASCII selector like bare `&` or `&&` to indicate association of nested rules with the previous selector
@@ -39,7 +39,7 @@ Arguments for each of the above options:
3939
- More verbose than Sass/etc-style, which many authors are used to. (And is arguably just a good design.)
4040

4141
<tr>
42-
<th>(2.1)
42+
<th>(2.i)
4343
<td>
4444

4545
- After the switch, syntax is the same as other nesting contexts.
@@ -52,25 +52,25 @@ Arguments for each of the above options:
5252
- Can't mix properties and rules - all properties have to come first. (But this matches the data model anyway.)
5353

5454
<tr>
55-
<th>(2.2)
55+
<th>(2.ii)
5656
<td>
5757

58-
- Same as (2.1), but you can avoid using `@nest;` most of the time if you instead start your first rule with `&`.
58+
- Same as (2.i), but you can avoid using `@nest;` most of the time if you instead start your first rule with `&`.
5959

6060

6161
<td>
6262

6363
- Need to pay somewhat more attention to context, and make sure your first rule is written correctly - either preceded by an at-rule, or starting with `&`.
6464

6565
<tr>
66-
<th>(2.3)
66+
<th>(2.iii)
6767
<td>
6868

69-
- Same as (2.2), but you can avoid using `@nest;` in even more cases: unless your first selector starts with a type selector, you can just nest naively.
69+
- Same as (2.ii), but you can avoid using `@nest;` in even more cases: unless your first selector starts with a type selector, you can just nest naively.
7070

7171
<td>
7272

73-
- Still somewhat context-sensitive, just less so than (2.2).
73+
- Still somewhat context-sensitive, just less so than (2.ii).
7474
- Prevents us from ever changing property syntax to start with an ascii glyph. (Like `+transform:...;` for additive properties?) (But these are probably already ruled out anyway, due to people using garbage to "comment out" their properties, like `//color: red;`, or `*color:red;` for an old IE hack.)
7575

7676
<tr>
@@ -86,7 +86,7 @@ Arguments for each of the above options:
8686
<td>
8787

8888
- Rules are invalid if they start with a type selector, requiring them to be rephrased somehow. (Using `:is(div)`, starting with `&`, etc.)
89-
- Like (2.3), prevents us from changing property syntax to start with an ascii glyph in the future. (But similarly, this is probably already lost to us.)
89+
- Like (2.iii), prevents us from changing property syntax to start with an ascii glyph in the future. (But similarly, this is probably already lost to us.)
9090

9191
<tr>
9292
<th>(4)
@@ -96,6 +96,7 @@ Arguments for each of the above options:
9696
- No double-nested indentation
9797
- No `&` for selectors that do not require it
9898
- Full compatibility with `@scope` and root contexts
99+
- No `@nest` in variants (4.ii) and (4.iii)
99100

100101
<td>
101102

@@ -104,5 +105,6 @@ Arguments for each of the above options:
104105
- Requires either noisy `@nest` everywhere or cryptic ASCII syntax
105106
- CSSOM with (arguably) a different structure than the syntax
106107
- Can't mix properties and rules - all properties have to come first. (But this matches the data model anyway.)
108+
- If you are *only* nesting rules, you still need an empty declaration block (`{}`), which looks awkward
107109

108110
table>

0 commit comments

Comments
 (0)