11// This is the synchronous version of the optimizer; which the Async one should be based on.
22import { isDeterministic } from './compiler.js'
33import { map } from './async_iterators.js'
4- import { isSync , Sync } from './constants.js'
4+ import { isSync , Sync , OriginalImpl } from './constants.js'
55import declareSync from './utilities/declareSync.js'
66import { coerceArray } from './utilities/coerceArray.js'
77
@@ -29,6 +29,7 @@ function getMethod (logic, engine, methodName, above) {
2929
3030 let args = logic [ methodName ]
3131 if ( ( ! args || typeof args !== 'object' ) && ! method . optimizeUnary ) args = [ args ]
32+ if ( Array . isArray ( args ) && args . length === 1 && method . optimizeUnary && ! Array . isArray ( args [ 0 ] ) ) args = args [ 0 ]
3233
3334 if ( Array . isArray ( args ) ) {
3435 const optimizedArgs = args . map ( l => optimize ( l , engine , above ) )
@@ -50,6 +51,11 @@ function getMethod (logic, engine, methodName, above) {
5051
5152 if ( isSync ( optimizedArgs ) && ( method . method || method [ Sync ] ) ) {
5253 const called = method . method ? method . method : method
54+ if ( ( methodName === 'var' || methodName === 'val' ) && engine . methods [ methodName ] [ OriginalImpl ] && ( ( typeof optimizedArgs === 'string' && ! optimizedArgs . includes ( '.' ) && ! optimizedArgs . includes ( '\\' ) ) || ! optimizedArgs || typeof optimizedArgs === 'number' ) ) {
55+ if ( ! optimizedArgs && methodName !== 'val' ) return declareSync ( ( data ) => ! data || typeof data === 'undefined' || ( typeof data === 'function' && ! engine . allowFunctions ) ? null : data )
56+ return declareSync ( ( data ) => ! data || typeof data [ optimizedArgs ] === 'undefined' || ( typeof data [ optimizedArgs ] === 'function' && ! engine . allowFunctions ) ? null : data [ optimizedArgs ] )
57+ }
58+
5359 if ( method . optimizeUnary ) return declareSync ( ( data , abv ) => called ( typeof optimizedArgs === 'function' ? optimizedArgs ( data , abv ) : optimizedArgs , data , abv || above , engine . fallback ) , true )
5460 return declareSync ( ( data , abv ) => called ( coerceArray ( typeof optimizedArgs === 'function' ? optimizedArgs ( data , abv ) : optimizedArgs ) , data , abv || above , engine ) , true )
5561 }
0 commit comments