Skip to content

Commit 89da7bf

Browse files
committed
Deal with patterns to check for async
1 parent ddc5e5a commit 89da7bf

File tree

1 file changed

+20
-5
lines changed
  • packages/svelte/src/compiler/phases/3-transform/client

1 file changed

+20
-5
lines changed

packages/svelte/src/compiler/phases/3-transform/client/utils.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,20 @@ export function serialize_get_binding(node, state) {
104104
}
105105

106106
/**
107-
* @param {import('estree').Expression} expression
107+
* @param {import('estree').Expression | import('estree').Pattern} expression
108108
* @returns {boolean}
109109
*/
110110
function is_async(expression) {
111111
switch (expression.type) {
112+
case 'ArrayPattern': {
113+
for (const element of expression.elements) {
114+
if (element && is_async(element)) {
115+
return true;
116+
}
117+
}
118+
119+
return false;
120+
}
112121
case 'ArrayExpression': {
113122
for (const element of expression.elements) {
114123
if (!element) {
@@ -130,6 +139,10 @@ function is_async(expression) {
130139
case 'FunctionExpression': {
131140
return expression.async ?? false;
132141
}
142+
case 'AssignmentPattern':
143+
case 'AssignmentExpression': {
144+
return is_async(expression.left) || is_async(expression.right);
145+
}
133146
case 'AwaitExpression': {
134147
return true;
135148
}
@@ -201,22 +214,21 @@ function is_async(expression) {
201214
case 'MetaProperty': {
202215
return false;
203216
}
217+
case 'ObjectPattern':
204218
case 'ObjectExpression': {
205219
for (const property of expression.properties) {
206220
if (property.type === 'SpreadElement') {
207221
if (is_async(property.argument)) {
208222
return true;
209223
}
210-
} else {
224+
} else if (property.type === 'Property') {
211225
const key_is_async =
212226
property.key.type === 'PrivateIdentifier' ? false : is_async(property.key);
213227
if (key_is_async) {
214228
return true;
215229
}
216230

217-
const value_is_async = is_async(
218-
/** @type {import('estree').Expression} */ (property.value)
219-
);
231+
const value_is_async = is_async(property.value);
220232
if (value_is_async) {
221233
return true;
222234
}
@@ -225,6 +237,9 @@ function is_async(expression) {
225237

226238
return false;
227239
}
240+
case 'RestElement': {
241+
return is_async(expression.argument);
242+
}
228243
case 'SequenceExpression': {
229244
for (const subexpression of expression.expressions) {
230245
if (is_async(subexpression)) {

0 commit comments

Comments
 (0)