Add getElementById and getElementsByTagName support#620
Draft
andrewiggins wants to merge 14 commits into
Draft
Conversation
Inserting before a child that already had a previous sibling updated the inserted and reference nodes, but left the previous sibling pointing at the reference node. Traversals following NEXT therefore skipped the inserted subtree even though childNodes contained it.\n\nThe Document-getElementById WPT case 'where insertion order and tree order don’t match' exposed this by inserting duplicate-ID elements between existing siblings and expecting lookup to follow tree order.
Implement the NonElementParentNode lookup on Document and DocumentFragment through a shared tree-order traversal. Reflect Element.id, match identifiers literally, preserve string coercion, and reject empty identifiers as required by the WPT coverage.\n\nClassify all Document-getElementById WPT cases, supporting the common mutation and tree-order paths while deferring cases that require adjacent HTML element, NamedNodeMap, or outerHTML support.
Expose tag-name traversal on Document and Element, matching the DOM API hosts without adding the method to DocumentFragment. Share the traversal implementation while preserving case-insensitive HTML matching, case-sensitive non-HTML matching, and wildcard lookups.
Match the DOM mutation contract by returning the child passed to appendChild. Besides enabling normal chaining, the canonical Element.getElementsByTagName WPT uses this return value while constructing its fixture.
Run the canonical Document and Element getElementsByTagName suites. Record seven supported Document cases and eight supported Element cases, while deferring HTMLCollection semantics, HTML qualified-name edge cases, and the wildcard test's adjacent Node constant dependency.\n\nExpand the release note to describe the implemented lookup behavior and its intentionally deferred conformance surface.
querySelector and querySelectorAll now accept a pre-parsed Matcher[] in addition to string selectors. MatcherType, Combinator, Matcher, and Part are exported from selectors.ts. getElementById and getElementsByTagName delegate to the selector engine instead of maintaining independent tree-walk implementations, eliminating duplicate traversal code and fixing CSS-escaping issues for ids with special characters. HTML tag-name matching in the selector engine is now case-insensitive per the CSS spec.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getElementById()lookup onDocumentandDocumentFragment, including reflectedElement.idbehavior and literal identifier matchinggetElementsByTagName()on its standardDocumentandElementhosts for common HTML, non-HTML, and wildcard descendant searchesinsertBefore()sibling links and makeappendChild()return its appended childStacked dependency
This PR is stacked on #617 and its branch starts from that PR's current head,
cb18d72. Because the base branch belongs to a fork, GitHub requires this PR to targetmain; until #617 merges, the displayed diff also includes the runner infrastructure.Related PR #618 independently adds
getElementById(). This implementation incorporates itsDocumentFragmentsurface and shared literal traversal, while additionally handling empty identifiers, reflectingElement.id, fixing WPT-exposed tree ordering, and recording classified WPT coverage.WPT coverage
Document-getElementById.html: 12 supported, 6 deferredDocument-getElementsByTagName.html: 7 supported, 11 deferredElement-getElementsByTagName.html: 8 supported, 11 deferredDeferred cases require concrete HTML element constructors, indexed
NamedNodeMapaccess, anouterHTMLsetter, liveHTMLCollectionsemantics, HTML qualified-name edge cases, or adjacentNodeconstants.Validation
pnpm lintpnpm type-checkpnpm vitest run— 20 files, 208 tests passedpnpm test:wpt— 4/4 files passed with complete capability classification