@@ -107,7 +107,7 @@ export class Binding {
107107
108108class Evaluation {
109109 /** @type {Set<any> } */
110- values = new Set ( ) ;
110+ values ;
111111
112112 /**
113113 * True if there is exactly one possible value
@@ -147,8 +147,11 @@ class Evaluation {
147147 *
148148 * @param {Scope } scope
149149 * @param {Expression } expression
150+ * @param {Set<any> } values
150151 */
151- constructor ( scope , expression ) {
152+ constructor ( scope , expression , values = new Set ( ) ) {
153+ this . values = values ;
154+
152155 switch ( expression . type ) {
153156 case 'Literal' : {
154157 this . values . add ( expression . value ) ;
@@ -178,10 +181,7 @@ class Evaluation {
178181 }
179182
180183 if ( ! binding . updated && binding . initial !== null && ! is_prop ) {
181- const evaluation = binding . scope . evaluate ( /** @type {Expression } */ ( binding . initial ) ) ;
182- for ( const value of evaluation . values ) {
183- this . values . add ( value ) ;
184- }
184+ binding . scope . evaluate ( /** @type {Expression } */ ( binding . initial ) , this . values ) ;
185185 break ;
186186 }
187187 } else if ( expression . name === 'undefined' ) {
@@ -353,9 +353,7 @@ class Evaluation {
353353 case '$state.raw' :
354354 case '$derived' :
355355 if ( arg ) {
356- for ( let value of scope . evaluate ( arg ) . values ) {
357- this . values . add ( value ) ;
358- }
356+ scope . evaluate ( arg , this . values ) ;
359357 } else {
360358 this . values . add ( undefined ) ;
361359 }
@@ -372,9 +370,7 @@ class Evaluation {
372370
373371 case '$derived.by' :
374372 if ( arg ?. type === 'ArrowFunctionExpression' && arg . body . type !== 'BlockStatement' ) {
375- for ( let value of scope . evaluate ( arg . body ) . values ) {
376- this . values . add ( value ) ;
377- }
373+ scope . evaluate ( arg . body , this . values ) ;
378374 break ;
379375 }
380376
@@ -629,10 +625,10 @@ export class Scope {
629625 * Only call this once scope has been fully generated in a first pass,
630626 * else this evaluates on incomplete data and may yield wrong results.
631627 * @param {Expression } expression
632- * @param {Set<any> } values
628+ * @param {Set<any> } [ values]
633629 */
634- evaluate ( expression , values = new Set ( ) ) {
635- return new Evaluation ( this , expression ) ;
630+ evaluate ( expression , values ) {
631+ return new Evaluation ( this , expression , values ) ;
636632 }
637633}
638634
0 commit comments