syntax-tree / hast-util-from-dom

utility to transform a DOM tree to hast

Home Page:https://unifiedjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

wooorm opened this issue · comments

commented

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

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

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'

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.

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!

commented

@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!

commented

Closed by febe057.