Correct selector matching - #679
Conversation
e728f56 to
9adce31
Compare
9adce31 to
1204f44
Compare
|
The combinator and relative :has() fixes look right. I reviewed 1. Use CSS whitespace instead of JavaScript trim()selectors.ts:130-137 removes characters that CSS treats as identifier characters: const root = document.createElement('div');
root.appendChild(document.createElement('article'));
root.querySelector('\u1680article');Native/base return Please use CSS whitespace (space, tab, LF, CR, FF) consistently in normalization and tokenizer character classes, rather than A build-only probe correction fixes all eight targeted U+1680/U+FEFF cases without changing other comparison results. No production source was changed. References: CSS whitespace, identifier code points. 2. Reject :has() nested inside :has()The balanced argument parsing now permits forbidden nesting: const root = document.createElement('div');
const article = document.createElement('article');
const section = document.createElement('section');
const active = document.createElement('a');
active.setAttribute('class', 'active');
section.appendChild(active);
article.appendChild(section);
root.appendChild(article);
root.querySelector('article:has(:has(.active))');
root.querySelector('article:has(:not(:has(.active)))');Each native call throws Please track the inside-has context structurally during parsing, before inspecting the DOM. Preserve valid This is the same nested-has issue already raised on #692. That branch inherited the acceptance; #679 identifies where it starts. Implement the structural rejection once here, retaining #692's named-error/integration coverage rather than moving its whole error-contract change forward. Validation: 285 polyfill tests and 59 focused core tests pass, as do the locked-TypeScript polyfill check and locked formatting. The updated selector file on the actual base has 32 failures / 57 passes. Head matches 259/279 standards-mode native comparison cases, including all 180 generated supported combinator chains. Remaining differences cover the above plus known selector-list/error-contract limits. Reported CI is green; full-repository and live Shell/admin validation remain separate gates. No #679 source fix or approval performed. |
1204f44 to
2c920f3
Compare
2c920f3 to
0fbcbae
Compare
|
Fixed both. Selector parsing now uses CSS whitespace explicitly instead of |
0fbcbae to
1c1a644
Compare
1c1a644 to
da43e02
Compare
Problem
The polyfill implements a deliberately limited selector surface, but several supported forms were matched incorrectly.
:has()evaluated its argument against the candidate itself rather than relative descendants; a multi-part selector could restart matching from the original leaf after finding an ancestor or sibling; leading whitespace produced an empty selector part; and unquoted exact attribute equality was not parsed as an equality value.Impact
Important. Calls to the exposed
querySelector()andquerySelectorAll()APIs could silently select the wrong element or no element for supported selectors. In a worker DOM, that can direct application updates at the wrong local node before Remote DOM synchronization.Reproduction
Before this change, the final call returned
null:.activewas tested against thearticleitself, not its descendants. It now returns thearticle. The same regression file demonstrates correct chained-combinator state, leading whitespace, and[class=content]exact attribute matching.Change
:has()as a scoped relative selector, including supported leading child and sibling relations, instead of matching the candidate itself.The implementation remains scoped to the selector forms this polyfill exposes; it does not claim a complete CSS selector grammar.
Tests
Expands selector parsing and matching coverage with positive and negative cases for unquoted and quoted exact attributes, 3+ part child/descendant/sibling chains, descendant and relative
:has(), nested:has()/:not(), balanced quoted function arguments, pseudo-class name casing, and leading/internal whitespace.Stack
respect-default-namespaceThe restacked diff contains only selector implementation, selector tests, and its changeset; the unrelated text-content test fix was moved into #671.
Validation
Fresh GitHub CI on restacked head
1204f44passes: