JSPM

  • Created
  • Published
  • Downloads 31892
  • Score
    100M100P100Q149891F
  • License MIT

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

Package Exports

  • svelte-ast-print
  • svelte-ast-print/css
  • svelte-ast-print/css/rule
  • svelte-ast-print/css/selector
  • svelte-ast-print/fragment
  • svelte-ast-print/lib
  • svelte-ast-print/template
  • svelte-ast-print/template/attribute-like
  • svelte-ast-print/template/block
  • svelte-ast-print/template/element-like
  • svelte-ast-print/template/html
  • svelte-ast-print/template/root
  • svelte-ast-print/template/tag

Readme

svelte-ast-print

NPM Version

Print (serialize) Svelte AST nodes into stringified code syntax.
A.k.a. parse() in reverse.

Usage

See documentation.

[!IMPORTANT]

When using parse() from "svelte/compiler"...
please remember about passing modern: true to options (second argument).

This option is only available starting svelte@5.

Example:

import { parse } from "svelte/compiler";

parse(code, { modern: true });
//          👆 Don't forget about this!

You can omit it from Svelte v6 - source.


How does it work under the hood?

  1. It determines whether the provided AST node type is related to Svelte syntax only.
  2. Based on node's type check from above:
    • it uses either this package's printer to print AST node related to Svelte syntax,
    • otherwise it uses esrap to print ESTree specification-complaint AST node.

Author

Mateusz "xeho91" Kadlubowski

Acknowledgements