@@ -14,13 +14,14 @@ export class Evaluator<T = any> implements IValue<T> {
14
14
15
15
readonly isConstantLiteral : boolean ;
16
16
readonly usedColumns = new Set < IValue > ( ) ;
17
+ readonly forceNotConstant : boolean ;
17
18
18
19
get index ( ) {
19
20
return this . origin ?. getIndex ( this ) ;
20
21
}
21
22
22
23
get isConstant ( ) : boolean {
23
- return ! this . usedColumns . size ;
24
+ return ! this . usedColumns . size && ! this . forceNotConstant ;
24
25
}
25
26
26
27
get isConstantReal ( ) : boolean {
@@ -42,16 +43,22 @@ export class Evaluator<T = any> implements IValue<T> {
42
43
, private opts ?: {
43
44
isAny ?: boolean ;
44
45
isColumnOf ?: _ISelection ;
46
+ forceNotConstant ?: boolean ;
45
47
unpure ?: boolean ;
46
48
} ) {
47
49
this . isConstantLiteral = typeof val !== 'function' ;
50
+ if ( opts ?. forceNotConstant ) {
51
+ this . forceNotConstant = true ;
52
+ }
48
53
49
54
// fetch columns to depend on
50
55
let depArray : IValue [ ] ;
56
+ let hasNotConstant = false ;
51
57
if ( dependencies ) {
52
58
if ( ! Array . isArray ( dependencies ) ) {
53
59
depArray = [ dependencies ] ;
54
60
this . usedColumns = dependencies . usedColumns as Set < IValue > ;
61
+ hasNotConstant = ! dependencies . isConstant ;
55
62
this . origin = dependencies . origin ;
56
63
} else {
57
64
this . usedColumns = new Set ( ) ;
@@ -62,6 +69,9 @@ export class Evaluator<T = any> implements IValue<T> {
62
69
}
63
70
this . origin = d . origin ;
64
71
}
72
+ if ( ! d . isConstant ) {
73
+ hasNotConstant = true ;
74
+ }
65
75
for ( const u of d . usedColumns ) {
66
76
this . usedColumns . add ( u ) ;
67
77
}
@@ -74,10 +84,14 @@ export class Evaluator<T = any> implements IValue<T> {
74
84
this . origin = opts . isColumnOf ;
75
85
delete opts . isColumnOf ;
76
86
}
87
+ if ( hasNotConstant && ! this . usedColumns . size ) {
88
+ this . forceNotConstant = true ;
89
+ }
77
90
78
91
if ( ! this . usedColumns . size // no used columns
79
92
&& ! this . origin
80
93
&& ! this . opts ?. unpure
94
+ && ! this . forceNotConstant
81
95
&& ! depArray ?. some ( x => ! x . isConstantReal ) // all real constant dependencies
82
96
) {
83
97
// no dependency => this is a real constant => evaluate it.
0 commit comments