Skip to content

Commit

Permalink
Merge pull request #104 from lightsofapollo/support-put
Browse files Browse the repository at this point in the history
Add support for .put closing issue #103
  • Loading branch information
shepherdwind authored Jun 11, 2018
2 parents 4775b74 + e43b8d3 commit 8733300
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/compile/references.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
12 changes: 12 additions & 0 deletions tests/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 8733300

Please sign in to comment.