Skip to content

Commit 138213c

Browse files
authored
fix dev mode each block validation when using strings (#4451)
1 parent a972a47 commit 138213c

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Svelte changelog
22

3+
## Unreleased
4+
5+
* Fix dev mode validation of `{#each}` blocks using strings ([#4450](https://github.com/sveltejs/svelte/issues/4450))
6+
37
## 3.19.0
48

59
* Fix indirect bindings involving elements with spreads ([#3680](https://github.com/sveltejs/svelte/issues/3680))

src/runtime/internal/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function set_data_dev(text, data) {
8080
}
8181

8282
export function validate_each_argument(arg) {
83-
if (!arg || !('length' in arg)) {
83+
if (typeof arg !== 'string' && !(arg && typeof arg === 'object' && 'length' in arg)) {
8484
let msg = '{#each} only iterates over array-like objects.';
8585
if (typeof Symbol === 'function' && arg && Symbol.iterator in arg) {
8686
msg += ' You can use a spread to convert this iterable into an array.';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
compileOptions: {
3+
dev: true
4+
},
5+
html: `
6+
<div>f</div>
7+
<div>o</div>
8+
<div>o</div>
9+
`
10+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{#each 'foo' as c}
2+
<div>{c}</div>
3+
{/each}

0 commit comments

Comments
 (0)