Skip to content

Commit 8b885fd

Browse files
committed
fix #3046: missing combinator bug with nested css
1 parent e9413cc commit 8b885fd

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

CHANGELOG.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
* Fix CSS nesting transform for triple-nested rules that start with a combinator ([#3046](https://github.com/evanw/esbuild/issues/3046))
6+
7+
This release fixes a bug with esbuild where triple-nested CSS rules that start with a combinator were not transformed correctly for older browsers. Here's an example of such a case before and after this bug fix:
8+
9+
```css
10+
/* Original input */
11+
.a {
12+
color: red;
13+
> .b {
14+
color: green;
15+
> .c {
16+
color: blue;
17+
}
18+
}
19+
}
20+
21+
/* Old output (with --target=chrome90) */
22+
.a {
23+
color: red;
24+
}
25+
.a > .b {
26+
color: green;
27+
}
28+
.a .b > .c {
29+
color: blue;
30+
}
31+
32+
/* New output (with --target=chrome90) */
33+
.a {
34+
color: red;
35+
}
36+
.a > .b {
37+
color: green;
38+
}
39+
.a > .b > .c {
40+
color: blue;
41+
}
42+
```
43+
344
## 0.17.15
445

546
* Allow keywords as type parameter names in mapped types ([#3033](https://github.com/evanw/esbuild/issues/3033))

internal/css_parser/css_nesting.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ func substituteAmpersandsInCompoundSelector(sel css_ast.CompoundSelector, replac
212212

213213
var subclassSelectorPrefix []css_ast.SS
214214

215+
// Copy over the combinator, if any
216+
sel.Combinator = single.Combinator
217+
215218
// Insert the type selector
216219
if single.TypeSelector != nil {
217220
if sel.TypeSelector != nil {

internal/css_parser/css_parser_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,8 @@ func TestNestedSelector(t *testing.T) {
883883
expectPrintedLower(t, ".foo { & .bar { color: red } color: blue }", ".foo {\n color: blue;\n}\n.foo .bar {\n color: red;\n}\n")
884884
expectPrintedLower(t, ".foo { color: blue; & .bar { color: red } zoom: 2 }", ".foo {\n color: blue;\n zoom: 2;\n}\n.foo .bar {\n color: red;\n}\n")
885885
expectPrintedLower(t, ".a, .b { .c, .d { color: red } }", ":is(.a, .b) :is(.c, .d) {\n color: red;\n}\n")
886+
expectPrintedLower(t, ".a { color: red; > .b { color: green; > .c { color: blue } } }", ".a {\n color: red;\n}\n.a > .b {\n color: green;\n}\n.a > .b > .c {\n color: blue;\n}\n")
887+
expectPrintedLower(t, "> .a { color: red; > .b { color: green; > .c { color: blue } } }", "> .a {\n color: red;\n}\n> .a > .b {\n color: green;\n}\n> .a > .b > .c {\n color: blue;\n}\n")
886888
expectPrintedLower(t, ".foo, .bar, .foo:before, .bar:after { &:hover { color: red } }", ":is(.foo, .bar):hover {\n color: red;\n}\n")
887889
expectPrintedLower(t, ".foo, .bar:before { &:hover { color: red } }", ".foo:hover {\n color: red;\n}\n")
888890
expectPrintedLower(t, ".foo, .bar:before { :hover & { color: red } }", ":hover .foo {\n color: red;\n}\n")

0 commit comments

Comments
 (0)