b-fuze / deno-dom

Browser DOM & HTML parser in Deno
https://jsr.io/@b-fuze/deno-dom
MIT License
423 stars 47 forks source link

Fix #99 by adding Element.prototype.closest #137

Closed farsightsoftware closed 1 year ago

farsightsoftware commented 1 year ago

Went back and forth about whether to use el.matches(selectorString) or go straight to this.ownerDocument!._nwapi.match, but if you run this code on a browser, you don't see closest calling matches:

<div>
  <span>
    <em id="target"></em>
  </span>
</div>
<script>
const t = document.getElementById("target");
const m = t.matches;
t.matches = function (str) {
  console.log("***************");
  return m.call(this, str);
};
console.log("closest");
console.log(t.closest(".x"));
console.log("matches");
console.log(t.matches("#target"));
</script>

So went with _nwapi.match.

b-fuze commented 1 year ago

Looks good, the only thing that comes to mind is if someone is using the Sizzle engine selector (which was required at one point for Deno Deploy, but afaik isn't required anymore—though it can be explicitly enabled by the user)

b-fuze commented 1 year ago

Nvm, Sizzle also has match. This is good to go