Skip to content

Commit

Permalink
Use node type enum in relevant places
Browse files Browse the repository at this point in the history
  • Loading branch information
jahilldev committed Jan 31, 2022
1 parent 01a0e62 commit 05b731d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { h, Fragment } from 'preact';
import { IElement } from './model';
import { IElement, NodeType } from './model';
import { parseHtml, parseString } from './parse';

/* -----------------------------------
Expand Down Expand Up @@ -50,11 +50,11 @@ function parse(htmlValue: string) {
* -------------------------------- */

function convertToVDom(node: IElement | Element): preact.VNode<any> | string {
if (node.nodeType === 3) {
if (node.nodeType === NodeType.Text) {
return parseString(node.textContent);
}

if (node.nodeType !== 1) {
if (node.nodeType !== NodeType.Element) {
return null;
}

Expand Down
8 changes: 4 additions & 4 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ interface IElement {
* -------------------------------- */

enum NodeType {
ELEMENT = 1,
TEXT = 3,
Element = 1,
Text = 3,
}

/* -----------------------------------
Expand Down Expand Up @@ -113,7 +113,7 @@ function createElement(element: IElement): IElement {

let model = {
nodeName: 'BODY',
nodeType: 1,
nodeType: NodeType.Element,
tagName: 'body',
tagRange: [],
attributes: [],
Expand All @@ -139,7 +139,7 @@ function createElement(element: IElement): IElement {

function createText(value: string, tagRange: number[]) {
return createElement({
nodeType: NodeType.TEXT,
nodeType: NodeType.Text,
textContent: value,
nodeName: '#text',
tagName: void 0,
Expand Down

0 comments on commit 05b731d

Please sign in to comment.