From fb75588163f7ef867ecc7398fb1b1845ebe5543b Mon Sep 17 00:00:00 2001 From: Conduitry Date: Tue, 18 Feb 2020 04:11:34 -0500 Subject: [PATCH] update validation logic and messages - handle falsy {#each} arg - only mention spread if this is an iterable --- src/runtime/internal/dev.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/runtime/internal/dev.ts b/src/runtime/internal/dev.ts index e00b9edfed..7f4b52eb3b 100644 --- a/src/runtime/internal/dev.ts +++ b/src/runtime/internal/dev.ts @@ -80,15 +80,12 @@ export function set_data_dev(text, data) { } export function validate_each_argument(arg) { - if (arg instanceof Set || arg instanceof Map) { - throw new Error( - `Svelte does not allow Sets or Maps in an {#each} block. Use [...arg.values()] or [...arg.entries()] instead.` - ); - } - if (arg.length === undefined) { - throw new Error( - `Svelte needs an array-like value for the {#each} block. You can spread your iterable into an array instead, e.g. [...iterable]` - ); + if (!arg || !('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.'; + } + throw new Error(msg); } }