Skip to content

Commit 64d5e88

Browse files
committed
cleanup code
1 parent 229ab37 commit 64d5e88

File tree

1 file changed

+15
-25
lines changed
  • packages/svelte/src/compiler/phases/3-transform/client

1 file changed

+15
-25
lines changed

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

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/** @import { ClientTransformState, ComponentClientTransformState, ComponentContext } from './types.js' */
44
/** @import { Analysis, ComponentAnalysis } from '../../types.js' */
55
/** @import { Scope } from '../../scope.js' */
6+
/** @import { Visitor } from 'zimmerframe' */
67
import * as b from '#compiler/builders';
78
import { is_simple_expression } from '../../../utils/ast.js';
89
import {
@@ -40,43 +41,30 @@ export function can_be_parallelized(expression, scope, analysis, bindings) {
4041
let should_stop = false;
4142
/** @type {Set<string>} */
4243
const references = new Set();
44+
/** @type {Visitor<Node, null, Node>} */
45+
function stop(_, { stop }) {
46+
should_stop = true;
47+
stop();
48+
}
4349
walk(/** @type {Node} */ (expression), null, {
44-
ArrowFunctionExpression(_, { stop }) {
45-
should_stop = true;
46-
stop();
47-
},
48-
FunctionExpression(_, { stop }) {
49-
should_stop = true;
50-
stop();
51-
},
50+
ArrowFunctionExpression: stop,
51+
FunctionExpression: stop,
52+
MemberExpression: stop,
53+
CallExpression: stop,
54+
NewExpression: stop,
55+
StaticBlock: stop,
5256
Identifier(node, { path }) {
5357
if (is_reference(node, /** @type {Node} */ (path.at(-1)))) {
5458
references.add(node.name);
5559
}
56-
},
57-
MemberExpression(node, { stop }) {
58-
should_stop = true;
59-
stop();
60-
},
61-
CallExpression(node, { stop }) {
62-
should_stop = true;
63-
stop();
64-
},
65-
NewExpression(node, { stop }) {
66-
should_stop = true;
67-
stop();
68-
},
69-
StaticBlock(node, { stop }) {
70-
should_stop = true;
71-
stop();
7260
}
7361
});
7462
if (should_stop) {
7563
return false;
7664
}
7765
for (const reference of references) {
7866
const binding = scope.get(reference);
79-
if (!binding || binding.declaration_kind === 'import') {
67+
if (binding === null || binding.declaration_kind === 'import') {
8068
return false;
8169
}
8270
if (binding.scope !== analysis.module.scope) {
@@ -92,6 +80,8 @@ export function can_be_parallelized(expression, scope, analysis, bindings) {
9280
return false;
9381
}
9482

83+
// we assume that async deriveds will be parallelized here
84+
// TODO can we confirm this instead of relying on assumptions?
9585
if (binding.kind === 'derived') {
9686
const init = /** @type {CallExpression} */ (binding.initial);
9787
if (analysis.async_deriveds.has(init)) {

0 commit comments

Comments
 (0)