Skip to content

Count positional selectors across the document in is(), as jQuery does - #152

Open
gravitypdf-bot wants to merge 4 commits into
mainfrom
fix/issue-140
Open

gravitypdf-bot wants to merge 4 commits into
mainfrom
fix/issue-140

Conversation

@gravitypdf-bot

Copy link
Copy Markdown
Contributor

Fixes #140. Behaviour change.

is() now counts a positional pseudo-class (:first, :eq(), :last, …) across the whole document, as jQuery's .is() does, rather than within the match set. So qp($xml, '#c')->is(':first') is now false. filter() still counts within the set, which agrees with jQuery's .filter().

The check lives in a new NodeMatcher::matchesAnyInDocument(). A selector with no positional pseudo-class still takes the single pass over the set that it took before. DOMNode and SplObjectStorage arguments are unchanged.

Tests

tests/Issues/Issue140Test.php covers the issue's table against jQuery 3.7.1, plus non-positional selectors, non-element nodes and the filter() contrast.

Every PR in this set adds its CHANGELOG line at the end of # Unreleased changes, so each one after the first needs a one-line conflict resolved there.

🤖 Generated with Claude Code

gravitypdf-bot and others added 4 commits October 26, 2026 17:18
jQuery's .is() evaluates a positional selector against the document and
tests membership, so is(':first') asks whether the set holds the
document's first element. is() counted within the match set instead,
as filter() does. It now uses NodeMatcher::matchesInDocument().

Fixes #140.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.25%. Comparing base (6ae6acf) to head (563cbd3).
⚠️ Report is 19 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #152      +/-   ##
============================================
+ Coverage     90.69%   91.25%   +0.55%     
- Complexity     1424     1445      +21     
============================================
  Files            25       26       +1     
  Lines          3170     3190      +20     
============================================
+ Hits           2875     2911      +36     
+ Misses          295      279      -16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

is() counts positional pseudo-classes within the match set, where jQuery's .is() counts across the document

1 participant