1
1
/** @import { Expression, Identifier, ObjectExpression } from 'estree' */
2
- /** @import { AST } from '#compiler' */
2
+ /** @import { AST, ExpressionMetadata } from '#compiler' */
3
3
/** @import { ComponentClientTransformState, ComponentContext } from '../../types' */
4
4
import { normalize_attribute } from '../../../../../../utils.js' ;
5
5
import { is_ignored } from '../../../../../state.js' ;
6
6
import { is_event_attribute } from '../../../../../utils/ast.js' ;
7
7
import * as b from '../../../../../utils/builders.js' ;
8
- import { build_getter , create_derived } from '../../utils.js' ;
8
+ import { build_getter } from '../../utils.js' ;
9
9
import { build_template_chunk , get_expression_id } from './utils.js' ;
10
10
11
11
/**
@@ -35,8 +35,10 @@ export function build_set_attributes(
35
35
36
36
for ( const attribute of attributes ) {
37
37
if ( attribute . type === 'Attribute' ) {
38
- const { value, has_state } = build_attribute_value ( attribute . value , context , ( value ) =>
39
- get_expression_id ( context . state , value )
38
+ const { value, has_state } = build_attribute_value (
39
+ attribute . value ,
40
+ context ,
41
+ ( value , metadata ) => ( metadata . has_call ? get_expression_id ( context . state , value ) : value )
40
42
) ;
41
43
42
44
if (
@@ -59,10 +61,9 @@ export function build_set_attributes(
59
61
let value = /** @type {Expression } */ ( context . visit ( attribute ) ) ;
60
62
61
63
if ( attribute . metadata . expression . has_call ) {
62
- const id = b . id ( state . scope . generate ( 'spread_with_call' ) ) ;
63
- state . init . push ( b . const ( id , create_derived ( state , b . thunk ( value ) ) ) ) ;
64
- value = b . call ( '$.get' , id ) ;
64
+ value = get_expression_id ( context . state , value ) ;
65
65
}
66
+
66
67
values . push ( b . spread ( value ) ) ;
67
68
}
68
69
}
@@ -111,8 +112,8 @@ export function build_style_directives(
111
112
let value =
112
113
directive . value === true
113
114
? build_getter ( { name : directive . name , type : 'Identifier' } , context . state )
114
- : build_attribute_value ( directive . value , context , ( value ) =>
115
- get_expression_id ( context . state , value )
115
+ : build_attribute_value ( directive . value , context , ( value , metadata ) =>
116
+ metadata . has_call ? get_expression_id ( context . state , value ) : value
116
117
) . value ;
117
118
118
119
const update = b . stmt (
@@ -169,7 +170,7 @@ export function build_class_directives(
169
170
/**
170
171
* @param {AST.Attribute['value'] } value
171
172
* @param {ComponentContext } context
172
- * @param {(value: Expression) => Expression } memoize
173
+ * @param {(value: Expression, metadata: ExpressionMetadata ) => Expression } memoize
173
174
* @returns {{ value: Expression, has_state: boolean } }
174
175
*/
175
176
export function build_attribute_value ( value , context , memoize = ( value ) => value ) {
@@ -187,7 +188,7 @@ export function build_attribute_value(value, context, memoize = (value) => value
187
188
let expression = /** @type {Expression } */ ( context . visit ( chunk . expression ) ) ;
188
189
189
190
return {
190
- value : chunk . metadata . expression . has_call ? memoize ( expression ) : expression ,
191
+ value : memoize ( expression , chunk . metadata . expression ) ,
191
192
has_state : chunk . metadata . expression . has_state
192
193
} ;
193
194
}
0 commit comments