mirror of
https://github.com/harttle/liquidjs.git
synced 2026-10-03 09:05:14 -07:00
fix #75
This commit is contained in:
+11
-9
@@ -56,15 +56,17 @@ var Scope = {
|
|||||||
}
|
}
|
||||||
var key = paths.shift()
|
var key = paths.shift()
|
||||||
var value = getValueFromScopes(key, scopes)
|
var value = getValueFromScopes(key, scopes)
|
||||||
return paths.reduce(
|
if (_.isNil(value)) {
|
||||||
(value, key) => {
|
throw new TypeError('undefined variable: ' + key)
|
||||||
if (_.isNil(value)) {
|
}
|
||||||
throw new TypeError('undefined variable: ' + key)
|
while (paths.length) {
|
||||||
}
|
key = paths.shift()
|
||||||
return getValueFromParent(key, value)
|
value = getValueFromParent(key, value)
|
||||||
},
|
if (_.isNil(value)) {
|
||||||
value
|
throw new TypeError('undefined variable: ' + key)
|
||||||
)
|
}
|
||||||
|
}
|
||||||
|
return value
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+9
-3
@@ -151,12 +151,18 @@ describe('scope', function () {
|
|||||||
}
|
}
|
||||||
expect(fn).to.throw(/undefined variable: notdefined/)
|
expect(fn).to.throw(/undefined variable: notdefined/)
|
||||||
})
|
})
|
||||||
it('should throw when deep variable not exist', function () {
|
it('should throw when parent not defined', function () {
|
||||||
scope.set('foo', 'bar')
|
|
||||||
function fn () {
|
function fn () {
|
||||||
scope.get('foo.bar.not.defined')
|
scope.get('foo.bar.not.defined')
|
||||||
}
|
}
|
||||||
expect(fn).to.throw(/undefined variable: not/)
|
expect(fn).to.throw(/undefined variable: bar/)
|
||||||
|
})
|
||||||
|
it('should throw when itself not defined', function () {
|
||||||
|
scope.set('foo', 'bar')
|
||||||
|
function fn () {
|
||||||
|
scope.get('foo.BAR')
|
||||||
|
}
|
||||||
|
expect(fn).to.throw(/undefined variable: BAR/)
|
||||||
})
|
})
|
||||||
it('should find variable in parent scope', function () {
|
it('should find variable in parent scope', function () {
|
||||||
scope.set('foo', 'foo')
|
scope.set('foo', 'foo')
|
||||||
|
|||||||
Reference in New Issue
Block a user