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
Svelte support #151
Comments
What is your plugin for svelte files? Is it |
A little bit of context about what a Svelte file is: A Svelte file follows the "Single File Components"-principle (script/style/html in one file) and mostly looks like regular HTML, with some additional micro syntax on top. The JS/TS code goes into a <script>
/** Hi maybe you want to format me with prettier-plugin-jsdoc */
let foo = 'bar';
</script>
<p>Hello {foo}</p>
<style>
p { color: red; }
</style> I don't know how this plugin works, but maybe you can do a regex-based search for the |
For other languages, this plugin first running original parser and getting an AST object of parsed string, then replacing comment part of them. With formatted comment and in the end returning it to prettier. The main question is: is svelte plugin parser parsing an AST of string? |
The Svelte parser does return a Svelte AST, but before parsing it it blanks the contents of the script and css tags, so the AST only contains the HTML part. This is done because the Svelte parser does not handle languages like TypeScript or SCSS, it would throw an error if it came across them. The original text is inside To summarize: I'm not sure if the approach of using our parser and traversing the AST will work. You would have to do your work before our parser and preprocessor starts doing stuff, and return the output as a string, so that our preprocessor/parser thinks this is how it always looked. I'm not sure if that's possible with the current Prettier plugin API. |
Oops, sorry didn't see this response until now. Thanks for being so on top of things! Yes, that's what I'm using. Unfortunately, I'm not an expert in either the prettier or svelte internals so I can't be of much help here. |
Would it be possible to get this to work in svelte files? I don't know enough about how prettier extensions work to know if this would be as easy as adding a file type or much more complex. Thanks!
The text was updated successfully, but these errors were encountered: