Skip to content

Commit e80ab33

Browse files
committed
Merge branch 'parallelize-async-work' of https://github.com/sveltejs/svelte into parallelize-async-work
2 parents cd8969a + f57ec19 commit e80ab33

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ export function is_state_source(binding, analysis) {
3838
*/
3939
export function can_be_parallelized(expression, scope, analysis, bindings) {
4040
let has_closures = false;
41+
let should_stop = false;
4142
/** @type {Set<string>} */
4243
const references = new Set();
43-
walk(expression, null, {
44+
walk(/** @type {Node} */ (expression), null, {
4445
ArrowFunctionExpression(_, { stop }) {
4546
has_closures = true;
4647
stop();
@@ -53,9 +54,25 @@ export function can_be_parallelized(expression, scope, analysis, bindings) {
5354
if (is_reference(node, /** @type {Node} */ (path.at(-1)))) {
5455
references.add(node.name);
5556
}
57+
},
58+
MemberExpression(node, { stop }) {
59+
should_stop = true;
60+
stop();
61+
},
62+
CallExpression(node, { stop }) {
63+
should_stop = true;
64+
stop();
65+
},
66+
NewExpression(node, { stop }) {
67+
should_stop = true;
68+
stop();
69+
},
70+
StaticBlock(node, { stop }) {
71+
has_closures = true;
72+
stop();
5673
}
5774
});
58-
if (has_closures) {
75+
if (has_closures || should_stop) {
5976
return false;
6077
}
6178
for (const reference of references) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export function Program(node, context) {
153153
);
154154
} else {
155155
const pattern = b.array_pattern(chunk.declarators.map(({ id }) => id));
156-
const init = b.call('$.all', b.array(chunk.declarators.map(({ init }) => init)));
156+
const init = b.call('$.all', ...chunk.declarators.map(({ init }) => init));
157157
body.push(b.declaration(chunk.kind, [b.declarator(pattern, b.await(init))]));
158158
}
159159
}

0 commit comments

Comments
 (0)