Skip to content

Commit c197e74

Browse files
committed
Add a simple optimization to inline chained val logic.
1 parent 95adac6 commit c197e74

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

defaultMethods.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,11 @@ const defaultMethods = {
319319
if (!buildState.engine.allowFunctions) buildState.methods.preventFunctions = a => typeof a === 'function' ? null : a
320320
else buildState.methods.preventFunctions = a => a
321321

322-
if (typeof data === 'object' && !Array.isArray(data)) return false
322+
if (typeof data === 'object' && !Array.isArray(data)) {
323+
// If the input for this function can be inlined, we will do so right here.
324+
if (isSyncDeep(data, buildState.engine, buildState) && isDeterministic(data, buildState.engine, buildState) && !buildState.disableInline) data = (buildState.engine.fallback || buildState.engine).run(data, buildState.context, { above: buildState.above })
325+
else return false
326+
}
323327
if (Array.isArray(data) && Array.isArray(data[0])) {
324328
// A very, very specific optimization.
325329
if (buildState.iteratorCompile && Math.abs(data[0][0] || 0) === 1 && data[1] === 'index') return buildState.compile`index`

suites/additional.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,11 @@
7070
"start_with": 59
7171
},
7272
69
73-
]
73+
],
74+
{
75+
"description": "Simple Inlineable Val Chained",
76+
"rule": { "val": { "cat": ["te", "st"] } },
77+
"data": { "test": 1 },
78+
"result": 1
79+
}
7480
]

0 commit comments

Comments
 (0)