@@ -115,6 +115,27 @@ function checkIdioms (logic, engine, above) {
115
115
}
116
116
}
117
117
118
+ if ( ( logic . if || logic [ '?:' ] ) && engine . methods . if [ OriginalImpl ] && Array . isArray ( logic . if || logic [ '?:' ] ) && ( logic . if || logic [ '?:' ] ) . length === 3 ) {
119
+ const [ condition , truthy , falsy ] = logic . if || logic [ '?:' ]
120
+ const C = optimize ( condition , engine , above )
121
+ const T = optimize ( truthy , engine , above )
122
+ const F = optimize ( falsy , engine , above )
123
+
124
+ if ( typeof C === 'function' && typeof T === 'function' && typeof F === 'function' ) return ( data , abv ) => engine . truthy ( C ( data , abv ) ) ? T ( data , abv ) : F ( data , abv )
125
+ if ( typeof C === 'function' && typeof T === 'function' ) return ( data , abv ) => engine . truthy ( C ( data , abv ) ) ? T ( data , abv ) : F
126
+ if ( typeof C === 'function' && typeof F === 'function' ) return ( data , abv ) => engine . truthy ( C ( data , abv ) ) ? T : F ( data , abv )
127
+ if ( typeof C === 'function' ) return ( data , abv ) => engine . truthy ( C ( data , abv ) ) ? T : F
128
+
129
+ // Otherwise, C is not a function, and we can just return the result of the evaluation.
130
+ return engine . truthy ( C ) ? T : F
131
+ }
132
+
133
+ if ( logic . filter && engine . methods . filter [ OriginalImpl ] && Array . isArray ( logic . filter ) && logic . filter . length === 2 ) {
134
+ const [ collection , filter ] = logic . filter
135
+ const filterF = optimize ( filter , engine , above )
136
+ if ( typeof filterF !== 'function' ) return engine . truthy ( filterF ) ? optimize ( collection , engine , above ) : [ ]
137
+ }
138
+
118
139
// Hyper-Optimizations for Comparison Operators.
119
140
for ( const comparison in comparisons ) {
120
141
if ( logic [ comparison ] && Array . isArray ( logic [ comparison ] ) && engine . methods [ comparison ] [ OriginalImpl ] ) {
0 commit comments