Skip to content

Commit fbb874f

Browse files
committed
refactor: Add exhaustive switch for all ElementTypes
1 parent f04da51 commit fbb874f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/index.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,22 @@ export default function render(
110110
}
111111

112112
function renderNode(node: Node, options: DomSerializerOptions): string {
113-
switch (node.type as string) {
114-
case "root":
113+
switch (node.type) {
114+
case ElementType.Root:
115115
return render((node as NodeWithChildren).children, options);
116116
case ElementType.Directive:
117+
case ElementType.Doctype:
117118
return renderDirective(node as DataNode);
118119
case ElementType.Comment:
119120
return renderComment(node as DataNode);
120121
case ElementType.CDATA:
121122
return renderCdata(node as NodeWithChildren);
122-
default:
123-
return ElementType.isTag(node)
124-
? renderTag(node as Element, options)
125-
: renderText(node as DataNode, options);
123+
case ElementType.Script:
124+
case ElementType.Style:
125+
case ElementType.Tag:
126+
return renderTag(node as Element, options);
127+
case ElementType.Text:
128+
return renderText(node as DataNode, options);
126129
}
127130
}
128131

0 commit comments

Comments
 (0)