You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{printCode}from'@mizchi/svelte-printer';import{parse}from'svelte/compiler';constcode=`<script>let x = 1</script><button on:click={() => x += 1}>{x}</button>`;constparsed=parse(code);constprinted=printCode(ast);console.log(printed);=>code
I skipped parse and preprocess to input svelte AST. To generate code I use astring because I can not use snip phase. I did not need formatter in this case.
For now there is no clean way to do this simply because this is not something that's built yet. I think for now your idea to reuse this formatting plugin is probably the fastest way to get going.
Svelte compiler has parser but no code printer. I need code printer for ast to svelte template.
related sveltejs/svelte#5972
How to implementation
I created fork of this repo.
https://github.com/mizchi/svelte-printer
mizchi@dc8ddb2
I skipped parse and preprocess to input svelte AST. To generate code I use
astring
because I can not use snip phase. I did not need formatter in this case.davidbonnet/astring: 🌳 Tiny and fast JavaScript code generator from an ESTree-compliant AST.
Why
I'm creating Non Programmer's Form from svelte template. This tool needs bi-directional transform.
or other way
I created fork but is there other clean way?
The text was updated successfully, but these errors were encountered: