diff --git a/src/compile/references.js b/src/compile/references.js index 0f75cfb..4425058 100644 --- a/src/compile/references.js +++ b/src/compile/references.js @@ -265,7 +265,8 @@ module.exports = function(Velocity, utils) { } else if (id === 'size') { return getSize(baseRef); - + } else if (id === 'put') { + return baseRef[this.getLiteral(property.args[0])] = this.getLiteral(property.args[1]); } else { ret = baseRef[id]; diff --git a/tests/compile.js b/tests/compile.js index ce9b652..61ebecb 100644 --- a/tests/compile.js +++ b/tests/compile.js @@ -694,6 +694,18 @@ describe('Compile', function() { }); }); + describe('assignment via .put', function () { + it('should set a key to an object', function() { + var vm = ` + #set($foo = {}) + #set($test = $foo.put('foo', 'bar')) + $foo["foo"] + `; + var expected = 'bar'; + assert.equal(render(vm).trim(), expected) + }); + }); + describe('Object|Array#toString', function() { it('simple object', function() { var vm = '$data';