feature: variable lookup respects to to_liquid, #81

This commit is contained in:
harttle
2018-08-14 00:11:50 +08:00
committed by Jun Yang
parent ea38a9e1f5
commit 5b43520d78
4 changed files with 35 additions and 22 deletions
+9 -4
View File
@@ -58,12 +58,17 @@ var Scope = {
},
readProperty: function (obj, key) {
let val
if (key === 'size' && (_.isArray(obj) || _.isString(obj))) {
val = obj.length
} else if (_.isNil(obj)) {
if (_.isNil(obj)) {
val = undefined
} else {
val = obj[key]
if (typeof obj.to_liquid === 'function') {
obj = obj.to_liquid()
}
if (key === 'size' && (_.isArray(obj) || _.isString(obj))) {
val = obj.length
} else {
val = obj[key]
}
}
if (_.isNil(val) && this.opts.strict_variables) {
throw new TypeError(`undefined variable: ${key}`)