From 89da7bfc53c35b40cee05fb8d0fb41b34d94ab6d Mon Sep 17 00:00:00 2001 From: Nguyen Tran <88808276+ngtr6788@users.noreply.github.com> Date: Fri, 22 Dec 2023 14:40:47 +0000 Subject: [PATCH] Deal with patterns to check for async --- .../phases/3-transform/client/utils.js | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/svelte/src/compiler/phases/3-transform/client/utils.js b/packages/svelte/src/compiler/phases/3-transform/client/utils.js index f6b1a0626b..c248bafd61 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/utils.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/utils.js @@ -104,11 +104,20 @@ export function serialize_get_binding(node, state) { } /** - * @param {import('estree').Expression} expression + * @param {import('estree').Expression | import('estree').Pattern} expression * @returns {boolean} */ function is_async(expression) { switch (expression.type) { + case 'ArrayPattern': { + for (const element of expression.elements) { + if (element && is_async(element)) { + return true; + } + } + + return false; + } case 'ArrayExpression': { for (const element of expression.elements) { if (!element) { @@ -130,6 +139,10 @@ function is_async(expression) { case 'FunctionExpression': { return expression.async ?? false; } + case 'AssignmentPattern': + case 'AssignmentExpression': { + return is_async(expression.left) || is_async(expression.right); + } case 'AwaitExpression': { return true; } @@ -201,22 +214,21 @@ function is_async(expression) { case 'MetaProperty': { return false; } + case 'ObjectPattern': case 'ObjectExpression': { for (const property of expression.properties) { if (property.type === 'SpreadElement') { if (is_async(property.argument)) { return true; } - } else { + } else if (property.type === 'Property') { const key_is_async = property.key.type === 'PrivateIdentifier' ? false : is_async(property.key); if (key_is_async) { return true; } - const value_is_async = is_async( - /** @type {import('estree').Expression} */ (property.value) - ); + const value_is_async = is_async(property.value); if (value_is_async) { return true; } @@ -225,6 +237,9 @@ function is_async(expression) { return false; } + case 'RestElement': { + return is_async(expression.argument); + } case 'SequenceExpression': { for (const subexpression of expression.expressions) { if (is_async(subexpression)) {