Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/__tests__/leaf-pseudo-depth.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import test from "./util/runner.mjs";
import parser from "../../dist/index.js";

test("a zero nesting limit permits nonfunctional pseudo selectors", (t) => {
const input = "a:hover::before";
t.is(parser().processSync(input, { maxNestingDepth: 0 }), input);
t.is(parser().astSync(input).toString({ maxNestingDepth: 0 }), input);
});

test("leaf pseudo selectors do not add nesting inside a functional pseudo", (t) => {
const input = ":is(a:hover, b::before)";
t.is(parser().processSync(input, { maxNestingDepth: 1 }), input);
t.is(parser().astSync(input).toString({ maxNestingDepth: 1 }), input);
});

test("functional pseudos still enforce the serialization nesting limit", (t) => {
const root = parser().astSync(":is(:not(a))");
t.throws(() => root.toString({ maxNestingDepth: 1 }), { message: /nesting depth/ });
t.throws(() => parser().astSync(":is(a)").toString({ maxNestingDepth: 0 }), /nesting depth/);
});
2 changes: 1 addition & 1 deletion src/selectors/pseudo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class Pseudo extends Container {
}

_stringify(options, depth, max) {
if (depth >= max) {
if (this.length && depth >= max) {
throw new Error(`Cannot serialize selector: nesting depth exceeds the maximum of ${max}.`);
}
let params = this.length
Expand Down
Loading