3
3
/** @import { ClientTransformState, ComponentClientTransformState, ComponentContext } from './types.js' */
4
4
/** @import { Analysis, ComponentAnalysis } from '../../types.js' */
5
5
/** @import { Scope } from '../../scope.js' */
6
+ /** @import { Visitor } from 'zimmerframe' */
6
7
import * as b from '#compiler/builders' ;
7
8
import { is_simple_expression } from '../../../utils/ast.js' ;
8
9
import {
@@ -40,43 +41,30 @@ export function can_be_parallelized(expression, scope, analysis, bindings) {
40
41
let should_stop = false ;
41
42
/** @type {Set<string> } */
42
43
const references = new Set ( ) ;
44
+ /** @type {Visitor<Node, null, Node> } */
45
+ function stop ( _ , { stop } ) {
46
+ should_stop = true ;
47
+ stop ( ) ;
48
+ }
43
49
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 ,
52
56
Identifier ( node , { path } ) {
53
57
if ( is_reference ( node , /** @type {Node } */ ( path . at ( - 1 ) ) ) ) {
54
58
references . add ( node . name ) ;
55
59
}
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 ( ) ;
72
60
}
73
61
} ) ;
74
62
if ( should_stop ) {
75
63
return false ;
76
64
}
77
65
for ( const reference of references ) {
78
66
const binding = scope . get ( reference ) ;
79
- if ( ! binding || binding . declaration_kind === 'import' ) {
67
+ if ( binding === null || binding . declaration_kind === 'import' ) {
80
68
return false ;
81
69
}
82
70
if ( binding . scope !== analysis . module . scope ) {
@@ -92,6 +80,8 @@ export function can_be_parallelized(expression, scope, analysis, bindings) {
92
80
return false ;
93
81
}
94
82
83
+ // we assume that async deriveds will be parallelized here
84
+ // TODO can we confirm this instead of relying on assumptions?
95
85
if ( binding . kind === 'derived' ) {
96
86
const init = /** @type {CallExpression } */ ( binding . initial ) ;
97
87
if ( analysis . async_deriveds . has ( init ) ) {
0 commit comments