mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
fix read/write variable in parent's scope, fix #39
This commit is contained in:
+12
-1
@@ -20,7 +20,8 @@ var Scope = {
|
||||
}
|
||||
},
|
||||
set: function (k, v) {
|
||||
setPropertyByPath(this.scopes[this.scopes.length - 1], k, v)
|
||||
var scope = this.findScopeFor(k)
|
||||
setPropertyByPath(scope, k, v)
|
||||
return this
|
||||
},
|
||||
push: function (ctx) {
|
||||
@@ -30,6 +31,16 @@ var Scope = {
|
||||
pop: function () {
|
||||
return this.scopes.pop()
|
||||
},
|
||||
findScopeFor: function (key) {
|
||||
var i = this.scopes.length - 1
|
||||
while (i >= 0 && !(key in this.scopes[i])) {
|
||||
i--
|
||||
}
|
||||
if (i < 0) {
|
||||
i = this.scopes.length - 1
|
||||
}
|
||||
return this.scopes[i]
|
||||
},
|
||||
unshift: function (ctx) {
|
||||
assert(ctx, `trying to push ${ctx} into scopes`)
|
||||
return this.scopes.unshift(ctx)
|
||||
|
||||
Reference in New Issue
Block a user