Skip to content

Commit

Permalink
refactor: Add exhaustive switch for all ElementTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Dec 5, 2020
1 parent f04da51 commit fbb874f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,22 @@ export default function render(
}

function renderNode(node: Node, options: DomSerializerOptions): string {
switch (node.type as string) {
case "root":
switch (node.type) {
case ElementType.Root:
return render((node as NodeWithChildren).children, options);
case ElementType.Directive:
case ElementType.Doctype:
return renderDirective(node as DataNode);
case ElementType.Comment:
return renderComment(node as DataNode);
case ElementType.CDATA:
return renderCdata(node as NodeWithChildren);
default:
return ElementType.isTag(node)
? renderTag(node as Element, options)
: renderText(node as DataNode, options);
case ElementType.Script:
case ElementType.Style:
case ElementType.Tag:
return renderTag(node as Element, options);
case ElementType.Text:
return renderText(node as DataNode, options);
}
}

Expand Down

0 comments on commit fbb874f

Please sign in to comment.