Skip to content

Commit cf0ec8a

Browse files
committed
Expand test suite
1 parent 2292bf9 commit cf0ec8a

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

defaultMethods.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ const defaultMethods = {
346346
// A unary optimization
347347
if (!Array.isArray(args)) {
348348
if (unFound && !(context && args in context)) return unFound
349+
if (context === null || context === undefined) return null
349350
const result = context[args]
350351
if (typeof result === 'undefined') return null
351352
return result
@@ -405,7 +406,7 @@ const defaultMethods = {
405406
}
406407
if (Array.isArray(data) && data.length === 1) data = data[0]
407408
if (data === null) return wrapNull(buildState.compile`context`)
408-
if (!Array.isArray(data)) return wrapNull(buildState.compile`context[${data}]`)
409+
if (!Array.isArray(data)) return wrapNull(buildState.compile`(context || 0)[${data}]`)
409410
if (Array.isArray(data)) {
410411
let res = buildState.compile`context`
411412
for (let i = 0; i < data.length; i++) {

logic.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class LogicEngine {
7676
// Later on, I could define something to shut this off if var / val are redefined.
7777
if ((func === 'var' || func === 'val') && this.methods[func][OriginalImpl]) {
7878
const input = (!data || typeof data !== 'object') ? data : this.run(data, context, { above })
79-
return this.methods[func].method(input, context, above, this)
79+
return this.methods[func].method(input, context, above, this, null)
8080
}
8181

8282
if (typeof this.methods[func] === 'function') {

suites/val.json

+12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@
4242
"data": { "." : 20 },
4343
"result": 20
4444
},
45+
{
46+
"description": "Fetching a value from null returns null",
47+
"rule": { "val": "hello" },
48+
"data": { "hello" : null },
49+
"result": null
50+
},
51+
{
52+
"description": "Fetching a value from a null fetched value returns null",
53+
"rule": { "val": ["hello", "world"] },
54+
"data": { "hello" : null },
55+
"result": null
56+
},
4557
{
4658
"description": "Fetches the entire context",
4759
"rule": { "val": [] },

0 commit comments

Comments
 (0)