dperini / nwsapi

Fast CSS Selectors API Engine
MIT License
105 stars 36 forks source link

Exception occurs when using element.matches #48

Closed toasted-nutbread closed 1 year ago

toasted-nutbread commented 3 years ago

element.matches can throw an unexpected error for certain selectors.

Here is an example to reproduce the issue in the browser (assuming nwsapi.js is included in a <script> tag):

const div = document.createElement('div');
div.innerHTML = '<div class="b"><div class="c"></div></div>';
//document.documentElement.appendChild(div); // Doesn't matter if this is executed or not
const c = div.querySelector('.c');
const selector = '.a:nth-last-of-type(1) .b .c';
console.log(c.matches(selector)); // Okay with native DOM
console.log(NW.Dom.match(selector, c)); // Throws
Uncaught TypeError: Cannot read property 'parentElement' of null
    at Array.Resolver (eval at compile (nwsapi.js:768), <anonymous>:3:129)
    at match_assert (nwsapi.js:1351)
    at Object._matches [as match] (nwsapi.js:1415)
dperini commented 1 year ago

@toasted-nutbread the bug has been fixed in release 2.2.3. It does not throw error any more. Closing the issue.