GULPF / nimquery

Nim library for querying HTML using CSS-selectors (like JavaScripts document.querySelector)
MIT License
134 stars 8 forks source link

`,` combinator behaves differently than in other DOM implementations #11

Closed SirNickolas closed 2 years ago

SirNickolas commented 3 years ago

Consider this snippet:

<div class="key">A</div><div class="value">x</div>
<div class="key">B</div><div class="value">y</div>

If you run document.querySelectorAll(".key, .value") in, e.g., JavaScript, it will return A, x, B, y, but nimquery returns A, B, x, y for it. It is rather hard to emulate the former behaviour for a user of the library (I had to resort to querying all divs and checking their class manually—I was lucky to have so simple query this approach worked without much pain). On the other hand, emulating the latter in JavaScript is no problem: just run two queries and concatenate the results.

I checked the source for some explanatory comment and haven’t find one. exec just does what it does:

https://github.com/GULPF/nimquery/blob/de705e409e5b67ce8f8af6a6ecb648b8b688b596/nimquery.nim#L847-L848

Could you change the behaviour to match other engines, please? Alternatively, to preserve backward compatibility, a new operator may be introduced.

GULPF commented 3 years ago

I agree that the behavior should match the browser implementations, I'll change it.