44import { dev , is_ignored } from '../../../../../state.js' ;
55import { get_attribute_chunks , object } from '../../../../../utils/ast.js' ;
66import * as b from '../../../../../utils/builders.js' ;
7- import { create_derived } from '../../utils.js' ;
87import { build_bind_this , memoize_expression , validate_binding } from '../shared/utils.js' ;
98import { build_attribute_value } from '../shared/element.js' ;
109import { build_event_handler } from './events.js' ;
@@ -134,9 +133,9 @@ export function build_component(node, component_name, context, anchor = context.
134133 custom_css_props . push (
135134 b . init (
136135 attribute . name ,
137- build_attribute_value ( attribute . value , context , ( value ) =>
136+ build_attribute_value ( attribute . value , context , ( value , metadata ) =>
138137 // TODO put the derived in the local block
139- memoize_expression ( context . state , value )
138+ metadata . has_call ? memoize_expression ( context . state , value ) : value
140139 ) . value
141140 )
142141 ) ;
@@ -151,31 +150,29 @@ export function build_component(node, component_name, context, anchor = context.
151150 has_children_prop = true ;
152151 }
153152
154- const { value, has_state } = build_attribute_value ( attribute . value , context , ( value ) =>
155- memoize_expression ( context . state , value )
156- ) ;
157-
158- if ( has_state ) {
159- let arg = value ;
160-
161- // When we have a non-simple computation, anything other than an Identifier or Member expression,
162- // then there's a good chance it needs to be memoized to avoid over-firing when read within the
163- // child component.
164- const should_wrap_in_derived = get_attribute_chunks ( attribute . value ) . some ( ( n ) => {
165- return (
166- n . type === 'ExpressionTag' &&
167- n . expression . type !== 'Identifier' &&
168- n . expression . type !== 'MemberExpression'
169- ) ;
170- } ) ;
153+ const { value, has_state } = build_attribute_value (
154+ attribute . value ,
155+ context ,
156+ ( value , metadata ) => {
157+ if ( ! metadata . has_state ) return value ;
158+
159+ // When we have a non-simple computation, anything other than an Identifier or Member expression,
160+ // then there's a good chance it needs to be memoized to avoid over-firing when read within the
161+ // child component (e.g. `active={i === index}`)
162+ const should_wrap_in_derived = get_attribute_chunks ( attribute . value ) . some ( ( n ) => {
163+ return (
164+ n . type === 'ExpressionTag' &&
165+ n . expression . type !== 'Identifier' &&
166+ n . expression . type !== 'MemberExpression'
167+ ) ;
168+ } ) ;
171169
172- if ( should_wrap_in_derived ) {
173- const id = b . id ( context . state . scope . generate ( attribute . name ) ) ;
174- context . state . init . push ( b . var ( id , create_derived ( context . state , b . thunk ( value ) ) ) ) ;
175- arg = b . call ( '$.get' , id ) ;
170+ return should_wrap_in_derived ? memoize_expression ( context . state , value ) : value ;
176171 }
172+ ) ;
177173
178- push_prop ( b . get ( attribute . name , [ b . return ( arg ) ] ) ) ;
174+ if ( has_state ) {
175+ push_prop ( b . get ( attribute . name , [ b . return ( value ) ] ) ) ;
179176 } else {
180177 push_prop ( b . init ( attribute . name , value ) ) ;
181178 }
0 commit comments