mirror of
https://github.com/hanzoai/esbuild.git
synced 2026-09-24 16:58:50 +00:00
@@ -252,8 +252,11 @@ const (
|
||||
func analyzeLeadingAmpersand(sel css_ast.ComplexSelector, isDeclarationContext bool) leadingAmpersand {
|
||||
if len(sel.Selectors) > 1 {
|
||||
if first := sel.Selectors[0]; first.IsSingleAmpersand() {
|
||||
if second := sel.Selectors[1]; second.Combinator.Byte == 0 && len(second.NestingSelectorLocs) > 0 {
|
||||
second := sel.Selectors[1]
|
||||
rest := css_ast.ComplexSelector{Selectors: sel.Selectors[1:]}
|
||||
if second.Combinator.Byte == 0 && rest.ContainsNestingCombinator() {
|
||||
// ".foo { & &.bar {} }" => ".foo { & &.bar {} }"
|
||||
// ".foo { & .bar:not(& .baz) {} }" => ".foo { & .bar:not(& .baz) {} }"
|
||||
} else if second.Combinator.Byte != 0 || second.TypeSelector == nil || !isDeclarationContext {
|
||||
// "& + div {}" => "+ div {}"
|
||||
// "& div {}" => "div {}"
|
||||
|
||||
@@ -1137,6 +1137,9 @@ func TestNestedSelector(t *testing.T) {
|
||||
expectPrintedMangle(t, "a { @media screen { & div { color: red } } }", "a {\n @media screen {\n & div {\n color: red;\n }\n }\n}\n", "")
|
||||
expectPrintedMangle(t, "a { :has(& b) { color: red } }", "a {\n :has(& b) {\n color: red;\n }\n}\n", "")
|
||||
expectPrintedMangle(t, "a { :has(& + b) { color: red } }", "a {\n :has(& + b) {\n color: red;\n }\n}\n", "")
|
||||
expectPrintedMangle(t, "a { & .b:not(& .c) { color: red } }", "a {\n & .b:not(& .c) {\n color: red;\n }\n}\n", "")
|
||||
expectPrintedMangle(t, "a { & .b:is(.c &) { color: red } }", "a {\n & .b:is(.c &) {\n color: red;\n }\n}\n", "")
|
||||
expectPrintedMangle(t, "a { & + .b:not(& .c) { color: red } }", "a {\n + .b:not(& .c) {\n color: red;\n }\n}\n", "")
|
||||
|
||||
// Reorder selectors to enable removing "&"
|
||||
expectPrintedMangle(t, "reorder { & first, .second { color: red } }", "reorder {\n .second,\n first {\n color: red;\n }\n}\n", "")
|
||||
|
||||
Reference in New Issue
Block a user