From e6cedac68ee9c4c265fb09f076629a561da8f96c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 5 May 2026 22:08:49 -0400 Subject: [PATCH] simplify --- .../src/internal/client/reactivity/async.js | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/packages/svelte/src/internal/client/reactivity/async.js b/packages/svelte/src/internal/client/reactivity/async.js index eb921f6186..69fc68c217 100644 --- a/packages/svelte/src/internal/client/reactivity/async.js +++ b/packages/svelte/src/internal/client/reactivity/async.js @@ -215,9 +215,10 @@ export async function* for_await_track_reactivity_loss(iterable) { /** Whether the completion of the iterator was "normal", meaning it wasn't ended via `break` or a similar method */ let normal_completion = false; - const no_error = {}; // because a madman might throw `null` or `undefined` + /** @type {any} */ - let thrown_error = no_error; + let threw = false; + try { while (true) { const { done, value } = (await track_reactivity_loss(iterator.next()))(); @@ -230,30 +231,19 @@ export async function* for_await_track_reactivity_loss(iterable) { set_reactivity_loss_tracker(prev); } } catch (error) { - thrown_error = error; + threw = true; + throw error; } finally { // If the iterator had an abrupt completion and `return` is defined on the iterator, call it and return the value if (!normal_completion && iterator.return !== undefined) { - try { - // Spec says a non-normal completion is break, return, or throw, in which case iterator.return() should be called... - const result = (await track_reactivity_loss(iterator.return()))(); - - // ... but only in case of break or return the result is returned, otherwise error takes precedence and is (re)thrown - if (thrown_error === no_error) { - // eslint-disable-next-line no-unsafe-finally - return /** @type {TReturn} */ (result.value); - } - } catch (error) { - if (thrown_error === no_error) { - // eslint-disable-next-line no-unsafe-finally - throw error; - } - } - } + // Spec says a non-normal completion is break, return, or throw, in which case iterator.return() should be called... + const result = (await track_reactivity_loss(iterator.return()))(); - if (thrown_error !== no_error) { - // eslint-disable-next-line no-unsafe-finally - throw thrown_error; + // ... but only in case of break or return the result is returned, otherwise error takes precedence + if (!threw) { + // eslint-disable-next-line no-unsafe-finally + return /** @type {TReturn} */ (result.value); + } } } }