#1021·snabbdom

Why not use Node.nodeType for checking nodeType equality in htmldomapi.ts ?

Author: FujihaiCreated May 20, 2022Updated Feb 1, 2024

In snabbdom\src\htmldomapi.ts,I think use Node.nodeType for checking nodeType equality is better.

Browser compatibility

https://caniuse.com/?search=node.nodeType

Usage

before:

javascript
function isElement(node: Node): node is Element {
  return node.nodeType === 1;
}

function isText(node: Node): node is Text {
  return node.nodeType === 3;
}

function isComment(node: Node): node is Comment {
  return node.nodeType === 8;
}

function isDocumentFragment(node: Node): node is DocumentFragment {
  return node.nodeType === 11;
}

after:

javascript
function isElement(node: Node): node is Element {
  return node.nodeType === Node.ELEMENT_NODE;
}

function isText(node: Node): node is Text {
  return node.nodeType === Node.TEXT_NODE;
}

function isComment(node: Node): node is Comment {
  return node.nodeType === Node.COMMENT_NODE;
}

function isDocumentFragment(node: Node): node is DocumentFragment {
  return node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
}