taoqf / node-html-parser

A very fast HTML parser, generating a simplified DOM, with basic element query support.
MIT License
1.11k stars 107 forks source link

Chore: Update the return of the closest function #222

Closed MakingStuffs closed 1 year ago

MakingStuffs commented 1 year ago

Update the return of the closest function to ensure that we return either a HTMLElement or null.

As the MDN spec for the .closest function states, the return type is 'The closest ancestor Element or itself, which matches the selectors. If there are no such element, null'

This means it should be an actual Element type and not a node. This solves a wider issue with TS that prevents users from chaining querySelector and calls to closest.

This provides a much more native behaviour akin to what is actually experienced within the browser environment.

MakingStuffs commented 1 year ago

@taoqf any chance of a review?

taoqf commented 1 year ago

@MakingStuffs Thanks