@@ -12,51 +12,48 @@ import { build_getter } from '../../utils.js';
12
12
13
13
export class Memoizer {
14
14
/** @type {Array<{ id: Identifier, expression: Expression }> } */
15
- sync = [ ] ;
15
+ # sync = [ ] ;
16
16
17
17
/** @type {Array<{ id: Identifier, expression: Expression }> } */
18
- async = [ ] ;
18
+ # async = [ ] ;
19
19
20
20
/**
21
21
* @param {Expression } expression
22
22
* @param {boolean } has_await
23
23
*/
24
24
add ( expression , has_await ) {
25
- const id = b . id ( `#` ) ; // filled in later
25
+ const id = b . id ( '#' ) ; // filled in later
26
26
27
- ( has_await ? this . async : this . sync ) . push ( { id, expression } ) ;
27
+ ( has_await ? this . # async : this . # sync) . push ( { id, expression } ) ;
28
28
29
29
return id ;
30
30
}
31
31
32
32
apply ( ) {
33
- const all = [ ...this . async , ...this . sync ] ;
34
-
35
- all . forEach ( ( memo , i ) => {
33
+ return [ ...this . #async, ...this . #sync] . map ( ( memo , i ) => {
36
34
memo . id . name = `$${ i } ` ;
35
+ return memo . id ;
37
36
} ) ;
38
-
39
- return all ;
40
37
}
41
38
42
39
deriveds ( runes = true ) {
43
- return this . sync . map ( ( memo ) =>
40
+ return this . # sync. map ( ( memo ) =>
44
41
b . let ( memo . id , b . call ( runes ? '$.derived' : '$.derived_safe_equal' , b . thunk ( memo . expression ) ) )
45
42
) ;
46
43
}
47
44
48
45
async_ids ( ) {
49
- return this . async . map ( ( memo ) => memo . id ) ;
46
+ return this . # async. map ( ( memo ) => memo . id ) ;
50
47
}
51
48
52
49
async_values ( ) {
53
- if ( this . async . length === 0 ) return ;
54
- return b . array ( this . async . map ( ( memo ) => b . thunk ( memo . expression , true ) ) ) ;
50
+ if ( this . # async. length === 0 ) return ;
51
+ return b . array ( this . # async. map ( ( memo ) => b . thunk ( memo . expression , true ) ) ) ;
55
52
}
56
53
57
54
sync_values ( ) {
58
- if ( this . sync . length === 0 ) return ;
59
- return b . array ( this . sync . map ( ( memo ) => b . thunk ( memo . expression ) ) ) ;
55
+ if ( this . # sync. length === 0 ) return ;
56
+ return b . array ( this . # sync. map ( ( memo ) => b . thunk ( memo . expression ) ) ) ;
60
57
}
61
58
}
62
59
@@ -163,13 +160,13 @@ export function build_template_chunk(
163
160
export function build_render_statement ( state ) {
164
161
const { memoizer } = state ;
165
162
166
- const all = state . memoizer . apply ( ) ;
163
+ const ids = state . memoizer . apply ( ) ;
167
164
168
165
return b . stmt (
169
166
b . call (
170
167
'$.template_effect' ,
171
168
b . arrow (
172
- all . map ( ( { id } ) => id ) ,
169
+ ids ,
173
170
state . update . length === 1 && state . update [ 0 ] . type === 'ExpressionStatement'
174
171
? state . update [ 0 ] . expression
175
172
: b . block ( state . update )
0 commit comments