Skip to content

Commit a8c3d77

Browse files
authored
feat: css nesting support (#64)
1 parent 87fa2e8 commit a8c3d77

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ function localizeNode(rule, mode, localAliasMap) {
230230

231231
break;
232232
}
233+
case "nesting": {
234+
if (node.value === "&") {
235+
context.hasLocals = true;
236+
}
237+
}
233238
}
234239

235240
context.lastWasSpacing = false;

test/index.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,30 @@ const tests = [
844844
input: ":global(.a:not(:global .b, :global .c)) {}",
845845
error: /A :global is not allowed inside of a :global/,
846846
},
847+
{
848+
name: "consider & statements as pure",
849+
input: ".foo { &:hover { a_value: some-value; } }",
850+
options: { mode: "pure" },
851+
expected: ":local(.foo) { &:hover { a_value: some-value; } }",
852+
},
853+
{
854+
name: "consider selector & statements as pure",
855+
input: ".foo { html &:hover { a_value: some-value; } }",
856+
options: { mode: "pure" },
857+
expected: ":local(.foo) { html &:hover { a_value: some-value; } }",
858+
},
859+
{
860+
name: "consider selector & statements as pure",
861+
input: ".foo { &:global(.bar) { a_value: some-value; } }",
862+
options: { mode: "pure" },
863+
expected: ":local(.foo) { &.bar { a_value: some-value; } }",
864+
},
865+
{
866+
name: "throw on nested & selectors without a local selector",
867+
input: ":global(.foo) { &:hover { a_value: some-value; } }",
868+
options: { mode: "pure" },
869+
error: /is not pure/,
870+
},
847871
/*
848872
Bug in postcss-selector-parser
849873
{

0 commit comments

Comments
 (0)