UNPKG

@tricoteuses/arbre-de-la-loi

Version:

Generate ASTs from the French bills & laws; manipulate & export them to Markdown, etc.

50 lines (49 loc) 1.65 kB
import { HastType } from "./hast"; import { assertNeverXastNode, XastType } from "./xast"; export default function hastFromXast(xastNode) { switch (xastNode.type) { case XastType.Cdata: case XastType.Comment: case XastType.Instruction: return { data: xastNode.data, position: xastNode.position, type: HastType.Comment, value: xastNode.value, }; case XastType.Doctype: return { data: xastNode.data, name: xastNode.name, position: xastNode.position, public: xastNode.public, system: xastNode.system, type: HastType.Doctype, }; case XastType.Root: return { children: xastNode.children.map(hastFromXast), data: xastNode.data, position: xastNode.position, type: HastType.Root, }; case XastType.Text: return { data: xastNode.data, position: xastNode.position, type: HastType.Text, value: xastNode.value, }; case XastType.Element: return { children: xastNode.children.map(hastFromXast), data: xastNode.data, position: xastNode.position, properties: xastNode.attributes, tagName: xastNode.name, type: HastType.Element, }; default: assertNeverXastNode(xastNode); } }