Skip to content

Commit 65f9714

Browse files
committed
Fixes deterministic check on undefined
1 parent f5de662 commit 65f9714

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

compiler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function isDeterministic (method, engine, buildState) {
8585
const lower = method[func]
8686

8787
if (engine.isData(method, func)) return true
88-
if (lower === undefined) return true
88+
if (func === undefined) return true
8989

9090
// eslint-disable-next-line no-throw-literal
9191
if (!engine.methods[func]) throw { type: 'Unknown Operator', key: func }

general.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,22 @@ describe('Various Test Cases', () => {
153153
for (const engine of [...normalEngines, ...permissiveEngines]) await testEngine(engine, { max: 5 }, {}, 5)
154154
})
155155

156+
it('calls the function the correct amount of times', async () => {
157+
for (const engine of [...normalEngines, ...permissiveEngines]) {
158+
let called = 0
159+
engine.addMethod('inc', () => {
160+
called++
161+
return 1
162+
}, { optimizeUnary: true })
163+
164+
const f = await engine.build({ inc: undefined })
165+
await f()
166+
await f()
167+
await f()
168+
if (called !== 3) throw new Error('Should have called the function 3 times')
169+
}
170+
})
171+
156172
it('sees empty structures as false', async () => {
157173
for (const engine of [...normalEngines, ...permissiveEngines]) await testEngine(engine, { if: [{ var: 'x' }, true, false] }, { x: {} }, false)
158174
for (const engine of [...normalEngines, ...permissiveEngines]) await testEngine(engine, { if: [{ var: 'x' }, true, false] }, { x: [] }, false)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-logic-engine",
3-
"version": "5.0.0-6",
3+
"version": "5.0.0-7",
44
"description": "Construct complex rules with JSON & process them.",
55
"main": "./dist/cjs/index.js",
66
"module": "./dist/esm/index.js",

0 commit comments

Comments
 (0)