Skip to content

Commit

Permalink
fix dev mode each block validation when using strings (#4451)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conduitry authored Feb 23, 2020
1 parent a972a47 commit 138213c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Svelte changelog

## Unreleased

* Fix dev mode validation of `{#each}` blocks using strings ([#4450](https://github.com/sveltejs/svelte/issues/4450))

## 3.19.0

* Fix indirect bindings involving elements with spreads ([#3680](https://github.com/sveltejs/svelte/issues/3680))
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/internal/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function set_data_dev(text, data) {
}

export function validate_each_argument(arg) {
if (!arg || !('length' in arg)) {
if (typeof arg !== 'string' && !(arg && typeof arg === 'object' && 'length' in arg)) {
let msg = '{#each} only iterates over array-like objects.';
if (typeof Symbol === 'function' && arg && Symbol.iterator in arg) {
msg += ' You can use a spread to convert this iterable into an array.';
Expand Down
10 changes: 10 additions & 0 deletions test/runtime/samples/each-block-string/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
compileOptions: {
dev: true
},
html: `
<div>f</div>
<div>o</div>
<div>o</div>
`
};
3 changes: 3 additions & 0 deletions test/runtime/samples/each-block-string/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{#each 'foo' as c}
<div>{c}</div>
{/each}

0 comments on commit 138213c

Please sign in to comment.