Created
February 9, 2021 08:20
-
-
Save mizchi/d9be0ec969203f32f66e5f6eda9decb9 to your computer and use it in GitHub Desktop.
Generate code from svelte ast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import prettier from "prettier/standalone"; | |
import produce from "immer"; | |
import { parse } from "svelte/compiler"; | |
import type { Ast } from "svelte/types/compiler/interfaces"; | |
// @ts-ignore | |
import * as sveltePlugin from "prettier-plugin-svelte"; | |
function printTemplate(ast: Ast) { | |
const overridePlugin = produce(sveltePlugin, (d: any) => { | |
d.parsers.svelte.parse = () => { | |
return { ...ast, __isRoot: true }; | |
}; | |
}); | |
return prettier.format(" dummy ", { | |
parser: "svelte", | |
plugins: [overridePlugin as any], | |
}); | |
} | |
const code = "<div {id}>text</div>"; | |
const parsed = parse(code); | |
// override ast | |
// @ts-ignore | |
parsed.html.children[0].name = "span"; | |
const out = printTemplate(parsed); | |
console.log(out); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,Do you have Java code to implement Telegram authorization login?