Skip to content

Commit 1368a7a

Browse files
Sync svelte docs (#908)
sync svelte docs Co-authored-by: Rich-Harris <1162160+Rich-Harris@users.noreply.github.com>
1 parent a865f37 commit 1368a7a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

apps/svelte.dev/content/docs/svelte/03-template-syntax/03-each.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,30 @@ You can freely use destructuring and rest patterns in each blocks.
7474
{/each}
7575
```
7676

77+
## Each blocks without an item
78+
79+
```svelte
80+
<!--- copy: false --->
81+
{#each expression}...{/each}
82+
```
83+
84+
```svelte
85+
<!--- copy: false --->
86+
{#each expression, index}...{/each}
87+
```
88+
89+
In case you just want to render something `n` times, you can omit the `as` part ([demo](/playground/untitled#H4sIAAAAAAAAE3WR0W7CMAxFf8XKNAk0WsSeUEaRpn3Guoc0MbQiJFHiMlDVf18SOrZJ48259_jaVgZmxBEZZ28thgCNFV6xBdt1GgPj7wOji0t2EqI-wa_OleGEmpLWiID_6dIaQkMxhm1UdwKpRQhVzWSaVORJNdvWpqbhAYVsYQCNZk8thzWMC_DCHMZk3wPSThNQ088I3mghD9UwSwHwlLE5PMIzVFUFq3G7WUZ2OyUvU3JOuZU332wCXTRmtPy1NgzXZtUFp8WFw9536uWqpbIgPEaDsJBW90cTOHh0KGi2XsBq5-cT6-3nPauxXqHnsHJnCFZ3CvJVkyuCQ0mFF9TZyCQ162WGvteLKfG197Y3iv_pz_fmS68Hxt8iPBPj5HscP8YvCNX7uhYCAAA=)):
90+
91+
```svelte
92+
<div class="chess-board">
93+
{#each { length: 8 }, rank}
94+
{#each { length: 8 }, file}
95+
<div class:black={(rank + file) % 2 === 1}></div>
96+
{/each}
97+
{/each}
98+
</div>
99+
```
100+
77101
## Else blocks
78102

79103
```svelte

apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-compiler.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ namespace AST {
475475
export interface EachBlock extends BaseNode {
476476
type: 'EachBlock';
477477
expression: Expression;
478-
context: Pattern;
478+
/** The `entry` in `{#each item as entry}`. `null` if `as` part is omitted */
479+
context: Pattern | null;
479480
body: Fragment;
480481
fallback?: Fragment;
481482
index?: string;

0 commit comments

Comments
 (0)