Skip to content

Commit 06d43df

Browse files
committed
make $.all a stmt if all awaits are stmts
1 parent e2c32f9 commit 06d43df

File tree

1 file changed

+11
-7
lines changed
  • packages/svelte/src/compiler/phases/3-transform/client/visitors

1 file changed

+11
-7
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,18 @@ export function Program(node, context) {
165165
}
166166
} else {
167167
const pattern = b.array_pattern(chunk.declarators.map(({ id }) => id));
168-
const init = b.call('$.all', ...chunk.declarators.map(({ init }) => init));
169-
body.splice(
170-
chunk.position + offset,
171-
0,
172-
b.declaration(chunk.kind ?? 'const', [
173-
b.declarator(pattern, b.call(b.await(b.call('$.save', init))))
174-
])
168+
const init = b.call(
169+
b.await(b.call('$.save', b.call('$.all', ...chunk.declarators.map(({ init }) => init))))
175170
);
171+
if (pattern.elements.every((element) => element === null)) {
172+
body.splice(chunk.position + offset, 0, b.stmt(init));
173+
} else {
174+
body.splice(
175+
chunk.position + offset,
176+
0,
177+
b.declaration(chunk.kind ?? 'const', [b.declarator(pattern, init)])
178+
);
179+
}
176180
}
177181
offset++;
178182
}

0 commit comments

Comments
 (0)