syntax-tree/hast-util-from-dom

Is the duplication of `nodeType` and `nodeName` needed?

wooorm opened this issue · 4 comments

I was checking out the code and was wondering why you added both switch statements!

...als also, why nodeName == 'html' mapped to a doctype 🤔

kmck commented

i forget exactly whether it was necessary or if i was just being extra defensive, but i included the nodeName as a backup in case nodeType was missing or unrecognized. it might be safe to use element as the default and remove the second switch statement.

as for nodeName === 'html', that's because document.doctype.nodeName === 'html', whereas document.documentElement.nodeName === 'HTML'

i forget exactly whether it was necessary or if i was just being extra defensive, but i included the nodeName as a backup in case nodeType was missing or unrecognized. it might be safe to use element as the default and remove the second switch statement.

I don‘t think it is. From what I gather it’s supported everywhere!

as for nodeName === 'html', that's because document.doctype.nodeName === 'html', whereas document.documentElement.nodeName === 'HTML'

Interesting!! I didn’t know, thanks!

@kmck Seems nodeName’s been specced since 2000, and nodeType since 1998. Though I still prefer while loops over ES5 functions, I’m sure it’s fine to drop one!

Anyway, feel free to close this if you’d like to keep both!

Closed by febe057.