deno icon indicating copy to clipboard operation
deno copied to clipboard

fmt - Error formatting Svelte 5 snippet

Open lts20050703 opened this issue 1 year ago • 3 comments

Reproduction

{#snippet test()}
<div>Test</div>
{/snippet}

Expected

No errors

Actual

Error formatting: ...
   Syntax error (expected text node) at file:///...

deno --version deno 2.0.0 (stable, release, x86_64-unknown-linux-gnu) v8 12.9.202.13-rusty typescript 5.6.2

lts20050703 avatar Oct 16 '24 19:10 lts20050703

The error I get when I format using prettier:

app.svelte
[error] app.svelte: Expected if, each or await
[error] > 1 | {#snippet test()}
[error]     |  ^
[error]   2 | <div>Test</div>
[error]   3 | {/snippet}
[error]   4 | (1:2)
[error] 1: {#snippet test()}
[error]      ^
[error] 2: <div>Test</div>
[error] 3: {/snippet}

satyarohith avatar Oct 16 '24 19:10 satyarohith

@satyarohith What's the version of prettier and prettier-plugin-svelte are you using? I'm using "prettier": "^3.3.3", "prettier-plugin-svelte": "^3.2.7" and it works fine.

lts20050703 avatar Oct 17 '24 05:10 lts20050703

@satyarohith Svelte 5 just released (https://svelte.dev/blog/svelte-5-is-alive), and a fix to make this work would be greatly appreciated, as snippets is really useful to re-use HTML template code and remove duplication.

lts20050703 avatar Oct 23 '24 11:10 lts20050703

I'm still getting an error in deno 2.0.5 (stable, release, x86_64-pc-windows-msvc)

{#snippet test()}
  <div>Test</div>
{/snippet}
deno fmt --unstable-component
Error formatting: C:\Users\sylva\Documents\Projects\temp\deno-init\test.svelte
   Unexpected token `/`. Expected identifier, string literal, numeric literal or [ for the computed key at file:///C:/Users/sylva/Documents/Projects/temp/deno-init/test.svelte.tsx:2:21

                   <>{/snippet}</>
                      ~
Checked 4 files

sylc avatar Nov 10 '24 01:11 sylc

I just ran into this as well. It looks like the rest of the fix for this is unreleased (maybe in markup_fmt 0.15.2?): https://github.com/g-plane/markup_fmt/pull/73

sureshjoshi avatar Nov 14 '24 18:11 sureshjoshi