1
1
// This is the synchronous version of the optimizer; which the Async one should be based on.
2
2
import { isDeterministic } from './compiler.js'
3
3
import { map } from './async_iterators.js'
4
- import { isSync , Sync } from './constants.js'
4
+ import { isSync , Sync , OriginalImpl } from './constants.js'
5
5
import declareSync from './utilities/declareSync.js'
6
6
import { coerceArray } from './utilities/coerceArray.js'
7
7
@@ -29,6 +29,7 @@ function getMethod (logic, engine, methodName, above) {
29
29
30
30
let args = logic [ methodName ]
31
31
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 ]
32
33
33
34
if ( Array . isArray ( args ) ) {
34
35
const optimizedArgs = args . map ( l => optimize ( l , engine , above ) )
@@ -50,6 +51,11 @@ function getMethod (logic, engine, methodName, above) {
50
51
51
52
if ( isSync ( optimizedArgs ) && ( method . method || method [ Sync ] ) ) {
52
53
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
+
53
59
if ( method . optimizeUnary ) return declareSync ( ( data , abv ) => called ( typeof optimizedArgs === 'function' ? optimizedArgs ( data , abv ) : optimizedArgs , data , abv || above , engine . fallback ) , true )
54
60
return declareSync ( ( data , abv ) => called ( coerceArray ( typeof optimizedArgs === 'function' ? optimizedArgs ( data , abv ) : optimizedArgs ) , data , abv || above , engine ) , true )
55
61
}
0 commit comments