Skip to content

Commit c41900c

Browse files
committed
more
1 parent c17a1e3 commit c41900c

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

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

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ export function VariableDeclaration(node, context) {
5151
init?.type === 'AwaitExpression' &&
5252
context.state.analysis.instance?.scope === context.state.scope
5353
) {
54+
const current_chunk = context.state.current_parallelized_chunk;
5455
const parallelize = can_be_parallelized(
5556
init.argument,
5657
context.state.scope,
5758
context.state.analysis,
58-
[...(context.state.current_parallelized_chunk?.bindings ?? []), ...bindings]
59+
[...(current_chunk?.bindings ?? []), ...bindings]
5960
);
6061
if (parallelize) {
6162
const { id, init: visited_init } = /** @type {VariableDeclarator} */ (
@@ -68,15 +69,10 @@ export function VariableDeclaration(node, context) {
6869
id,
6970
init: /** @type {Expression} */ (visited_init)
7071
};
71-
if (
72-
context.state.current_parallelized_chunk &&
73-
context.state.current_parallelized_chunk.kind === node.kind
74-
) {
75-
context.state.current_parallelized_chunk.declarators.push(_declarator);
76-
context.state.current_parallelized_chunk.bindings.push(...bindings);
77-
context.state.current_parallelized_chunk.position = /** @type {Program} */ (
78-
parent
79-
).body.indexOf(node);
72+
if (current_chunk && current_chunk.kind === node.kind) {
73+
current_chunk.declarators.push(_declarator);
74+
current_chunk.bindings.push(...bindings);
75+
current_chunk.position = /** @type {Program} */ (parent).body.indexOf(node);
8076
} else {
8177
/** @type {ParallelizedChunk} */
8278
const chunk = {
@@ -251,6 +247,7 @@ export function VariableDeclaration(node, context) {
251247
/** @type {CallExpression} */ (init)
252248
);
253249
let parallelize = false;
250+
const current_chunk = context.state.current_parallelized_chunk;
254251
if (
255252
is_async &&
256253
context.state.analysis.instance &&
@@ -259,7 +256,7 @@ export function VariableDeclaration(node, context) {
259256
declarator.id.type === 'Identifier'
260257
) {
261258
parallelize = can_be_parallelized(value, context.state.scope, context.state.analysis, [
262-
...(context.state.current_parallelized_chunk?.bindings ?? []),
259+
...(current_chunk?.bindings ?? []),
263260
...context.state.scope.get_bindings(declarator)
264261
]);
265262
}
@@ -369,18 +366,14 @@ export function VariableDeclaration(node, context) {
369366
if (!parallelize) {
370367
declarations.push(...derived_declarators);
371368
} else if (derived_declarators.length > 0) {
372-
/** @type {ParallelizedChunk['declarators']} */
373369
const declarators = derived_declarators.map(({ id, init }) => ({
374370
id,
375371
init: /** @type {Expression} */ (init)
376372
}));
377-
if (
378-
context.state.current_parallelized_chunk &&
379-
context.state.current_parallelized_chunk.kind === node.kind
380-
) {
381-
context.state.current_parallelized_chunk.declarators.push(...declarators);
382-
context.state.current_parallelized_chunk.bindings.push(...bindings);
383-
context.state.current_parallelized_chunk.position = position;
373+
if (current_chunk && current_chunk.kind === node.kind) {
374+
current_chunk.declarators.push(...declarators);
375+
current_chunk.bindings.push(...bindings);
376+
current_chunk.position = position;
384377
} else {
385378
/** @type {ParallelizedChunk} */
386379
const chunk = {

0 commit comments

Comments
 (0)