-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix adjacent logical selectors #138
Conversation
Previously, adjacent logical selectors such as `:is(*):is(*)` would crash because the regex would incorrectly match *):is(* Replacing the naive match contents with something that matches balanced parentheses correctly handles these situations.
Per #137, no regressions on the following wpt tests
I don't have the full test setup locally, so that will need to be checked still. Also will need a performance check for tuning depth. A depth of 3 seems pretty good in terms of covering real scenarios, but if it doesn't hurt to go higher, then increasing it to something like 4-5 would be nice. |
This method also does not work for all logical selectors. Sample failing test cases below. It seems like it's related to commas or number of characters between inner parentheses.
This PR will not fix #127 Might be fixable by modifying the regex to allow more characters in between nested parens? |
Funnily enough, |
Oh found it. The problem is that commas are interpreted as different selectors sometimes within the context of logical selectors in the initial parse in https://github.com/dperini/nwsapi/blob/master/src/nwsapi.js#L1534 |
@KindaOK |
@KindaOK
Just a note for when performing the tests. |
There's no special behavior in place to prevent this at the moment neither in the current version of nwsapi nor in my branch. I think it's hard but doable with regex using a balanced parentheses matcher. Something like
My PR doesn't support that, but mangled selector support already has been gone for a bit. It looks like e60b058 was the commit that removed it. I don't think it can be easily thoroughly readded without a parser setup. The simple case for missing end parenthesis could be resolved by replacing the end |
@KindaOK |
Is there a plan for a release that includes this fix? I don't see anything in the wiki about release targets or cadences, but it looks like you've been releasing ~bimonthly recently? For us, this is a blocker for Svelte 5. |
@bmm6o I will do my best to increase the releases frequencies related to the :has() pseudo-class but to be honest Next testing strategy candidate will be using "compareDocumentPosition" Stay tuned, reviews, suggestions and testing are welcome and appreciated. |
Sounds good. And it might be helpful if I add some context. The dependency chain for us is Vite/jsdom/nwsapi, and what surfaced the bug is that Svelte 5 seems to generate more complex css selectors than Svelte 4 did. This is on the same codebase, so it's not selectors that we are intentionally building. I expect others from the Svelte community will run into this soon if they haven't already, which is what I meant by "us" - I hope I didn't sound too rude earlier. We are investigating alternatives, which I think would be to replace jsdom. |
Previously, adjacent logical selectors such as
:is(*):is(*)
would crash because the regex would incorrectly match*):is(*
Replacing the naive match contents with something that matches balanced parentheses correctly handles these situations.
Resolves #137