If you know which specific AST node from Svelte syntax you want to print.
There are 4 categories of AST nodes available and their respective submodules:
CSS - "svelte-ast-print/css"
HTML - "svelte-ast-print/html"
JavaScript & TypeScript - "svelte-ast-print/js"
Svelte template - "svelte-ast-print/template"
Let's take for example SV.SnippetBlock which is a Svelte template-related node.
// How you obtain the node is up to you. // Either by building programmatically or from parsing letnode: AST.SnippetBlock;
conststringified = printSvelteSnippet(node);
Example: General usage
If you don't know which AST node from Svelte syntax you want to print.
It could be either JavaScript/TypeScript (ESTree specification complaint) or Svelte.
Under the hood it uses esrap#print.
Usage
There are two ways to use this package.
Example: Recommended usage
If you know which specific AST node from Svelte syntax you want to print.
There are 4 categories of AST nodes available and their respective submodules:
"svelte-ast-print/css"
"svelte-ast-print/html"
"svelte-ast-print/js"
"svelte-ast-print/template"
Let's take for example SV.SnippetBlock which is a Svelte template-related node.
Example: General usage
If you don't know which AST node from Svelte syntax you want to print. It could be either JavaScript/TypeScript (ESTree specification complaint) or Svelte. Under the hood it uses esrap#print.
Example: General usage - Svelte only
If you don't know which AST node from Svelte syntax you want to print, but you know that it's Svelte.
Options
Every
print*
function accepts a second argument for options. Is optional and has some sensible defaults.See
PrintOptions