UNPKG

svelte-ast-print

Version:

Serialize Svelte AST nodes into stringified syntax. A.k.a parse in reverse.

52 lines 1.19 kB
/** * Printers related to Svelte **HTML**-related AST nodes only. * @module svelte-ast-print/template/html */ import { HTMLComment } from "../_internal/html.js"; import { State } from "../_internal/shared.js"; /** * @since 1.0.0 * @__NO_SIDE_EFFECTS__ */ export function printHTMLNode(n, opts) { // biome-ignore format: Prettier // prettier-ignore switch (n.type) { case "Comment": return printComment(n, opts); case "Text": return printText(n, opts); } } /** * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Comment} * * @example pattern * ```html * <!--data--> * ``` * * @since 1.0.0 * @__NO_SIDE_EFFECTS__ */ export function printComment(n, opts = {}) { const st = State.get(n, opts); // TODO: Convert it to breakable st.add(new HTMLComment("inline", n.data)); return st.result; } /** * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Text} * * @example pattern * ```html * <!--data--> * ``` * * @since 1.0.0 * @__NO_SIDE_EFFECTS__ */ export function printText(n, opts = {}) { const st = State.get(n, opts); st.add(n.raw); return st.result; } //# sourceMappingURL=html.js.map