Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] AST to svelte template #211

Open
mizchi opened this issue Feb 22, 2021 · 1 comment
Open

[feature request] AST to svelte template #211

mizchi opened this issue Feb 22, 2021 · 1 comment
Labels
question Further information is requested

Comments

@mizchi
Copy link

mizchi commented Feb 22, 2021

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

import { printCode } from '@mizchi/svelte-printer';
import { parse } from 'svelte/compiler';

const code = `<script>let x = 1</script>
<button on:click={() => x += 1}>{x}</button>
`;

const parsed = parse(code);
const printed = printCode(ast);
console.log(printed); => code

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?

@mizchi mizchi changed the title [feature request or question] AST to svelte template [feature request] AST to svelte template Feb 22, 2021
@dummdidumm dummdidumm added the question Further information is requested label Feb 22, 2021
@dummdidumm
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants