Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
svelte-ast-print
Advanced tools
svelte-ast-print
Print Svelte AST nodes as a string.
A.k.a. parse
in reverse.
This is what you need to create codemods - e.g. for migration between Svelte versions syntaxes.
https://xeho91.github.io/svelte-ast-print
This package depends on:
esrap
for printing ESTree specification-compliant AST nodeszimmerframe
for walking on the AST nodes[!WARNING] TypeScript isn't supported, yet.
At the moment Svelte parser skips TypeScript related syntax. Also,esrap
doesn't recognize TypeScript related AST nodes.
[!IMPORTANT] It ignores any previous formatting. The current focus is to be able to write codemods as soon as possible - because right now, there are no alternatives.
If you need to format modified and stringified Svelte AST, use available formatters for Svelte:
- Biome - ⚠️ has partial support
- Prettier with
prettier-plugin-svelte
[!NOTE] Is not optimized for performance, yet.
See Roadmap
Use the package manager of your choice to install this package:
npm install svelte-ast-print
yarn add svelte-ast-print
pnpm add svelte-ast-print
bun add svelte-ast-print
Incorporate it into your project, for example using Node.js and with the Svelte parse
method:
import fs from "node:fs";
import { print } from "svelte-ast-print";
import { parse } from "svelte/compiler";
const originalSvelteCode = fs.readFileSync("src/App.svelte", "utf-8");
let svelteAST = parse(originalSvelteCode, { modern: true });
// 👆 For now, only modern is supported.
// By default is 'false'.
// Is it planned to be 'true' from Svelte v6+
// ...
// Do some modifications on this AST...
// e.g. transform `<slot />` to `{@render children()}`
// ...
const output = print(svelteAST); // AST is now a stringified code output! 🎉
fs.writeFileSync("src/App.svelte", output, { encoding: " utf-8" });
Take a look at contributing guide.
This project follows the all-contributors specification. Contributions of any kind are welcome!
💌 to these people:
Mateusz Kadlubowski 💻 🚧 📖 🚇 ⚠️ |
If you don't have time, but you need this project to work, or resolve an existing issue, consider sponsorship.
Mateusz "xeho91" Kadlubowski
This project is licensed under the MIT License.
FAQs
Print Svelte AST nodes as a string. Aka parse in reverse.
We found that svelte-ast-print demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.