diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bc5f0f..c3973e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - (feat) Svelte 5: support upcoming `` - (feat) Svelte 5: support upcoming `` +- (feat) Svelte 5: support upcoming `#each` without `as` ## 3.2.8 diff --git a/src/print/index.ts b/src/print/index.ts index 9f3cab0..3e25ab5 100644 --- a/src/print/index.ts +++ b/src/print/index.ts @@ -499,12 +499,11 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D return ['{:else}', printSvelteBlockChildren(path, print, options)]; } case 'EachBlock': { - const def: Doc[] = [ - '{#each ', - printJS(path, print, 'expression'), - ' as', - expandNode(node.context, options.originalText), - ]; + const def: Doc[] = ['{#each ', printJS(path, print, 'expression')]; + + if (node.context) { + def.push(' as', expandNode(node.context, options.originalText)); + } if (node.index) { def.push(', ', node.index); diff --git a/test/printer/samples/each-block-without-as.html.skip b/test/printer/samples/each-block-without-as.html.skip new file mode 100644 index 0000000..28ca782 --- /dev/null +++ b/test/printer/samples/each-block-without-as.html.skip @@ -0,0 +1,7 @@ +{#each [1, 2, 3]} +

hi

+{/each} + +{#each [1, 2, 3], i} +

{i}

+{/each}