Empty :is() and :where() pseudoselectors are valid (and return nothing)

This commit is contained in:
Karl Seguin
2026-03-09 16:39:44 +08:00
parent b47004bb7c
commit 71c4fce87f
3 changed files with 13 additions and 4 deletions

View File

@@ -81,6 +81,17 @@
}
</script>
<script id="is_empty">
{
// Empty :is() and :where() are valid per spec and match nothing
const isEmptyResult = document.querySelectorAll(':is()');
testing.expectEqual(0, isEmptyResult.length);
const whereEmptyResult = document.querySelectorAll(':where()');
testing.expectEqual(0, whereEmptyResult.length);
}
</script>
<div id=escaped class=":popover-open"></div>
<script id="escaped">
{

View File

@@ -12,8 +12,6 @@
// Empty functional pseudo-classes should error
testing.expectError("Error: InvalidPseudoClass", () => container.querySelector(':has()'));
testing.expectError("Error: InvalidPseudoClass", () => container.querySelector(':not()'));
testing.expectError("Error: InvalidPseudoClass", () => container.querySelector(':is()'));
testing.expectError("Error: InvalidPseudoClass", () => container.querySelector(':where()'));
testing.expectError("Error: InvalidPseudoClass", () => container.querySelector(':lang()'));
}
</script>

View File

@@ -487,7 +487,7 @@ fn pseudoClass(self: *Parser, arena: Allocator, page: *Page) !Selector.PseudoCla
if (self.peek() != ')') return error.InvalidPseudoClass;
self.input = self.input[1..];
if (selectors.items.len == 0) return error.InvalidPseudoClass;
// Empty :is() is valid per spec - matches nothing
return .{ .is = selectors.items };
}
@@ -514,7 +514,7 @@ fn pseudoClass(self: *Parser, arena: Allocator, page: *Page) !Selector.PseudoCla
if (self.peek() != ')') return error.InvalidPseudoClass;
self.input = self.input[1..];
if (selectors.items.len == 0) return error.InvalidPseudoClass;
// Empty :where() is valid per spec - matches nothing
return .{ .where = selectors.items };
}