Skip to content

Commit

Permalink
feat: css nesting support (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
jantimon authored Dec 21, 2023
1 parent 87fa2e8 commit a8c3d77
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ function localizeNode(rule, mode, localAliasMap) {

break;
}
case "nesting": {
if (node.value === "&") {
context.hasLocals = true;
}
}
}

context.lastWasSpacing = false;
Expand Down
24 changes: 24 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,30 @@ const tests = [
input: ":global(.a:not(:global .b, :global .c)) {}",
error: /A :global is not allowed inside of a :global/,
},
{
name: "consider & statements as pure",
input: ".foo { &:hover { a_value: some-value; } }",
options: { mode: "pure" },
expected: ":local(.foo) { &:hover { a_value: some-value; } }",
},
{
name: "consider selector & statements as pure",
input: ".foo { html &:hover { a_value: some-value; } }",
options: { mode: "pure" },
expected: ":local(.foo) { html &:hover { a_value: some-value; } }",
},
{
name: "consider selector & statements as pure",
input: ".foo { &:global(.bar) { a_value: some-value; } }",
options: { mode: "pure" },
expected: ":local(.foo) { &.bar { a_value: some-value; } }",
},
{
name: "throw on nested & selectors without a local selector",
input: ":global(.foo) { &:hover { a_value: some-value; } }",
options: { mode: "pure" },
error: /is not pure/,
},
/*
Bug in postcss-selector-parser
{
Expand Down

0 comments on commit a8c3d77

Please sign in to comment.