Repository: shepherdwind/velocity.js (ts)

Issue:
Template does not support adding items to array
Here is my template 
```
#set($foo = [])
#set($ignore = $foo.add('bar'))
$foo
``` 

The expected output is `[bar]` but it is not so. The engine ignores the add method and prints an empty array `[]`

Pull request description:
fixes issue#113 support for add method on arrays
Added support for the add method on arrays.  Fixes #113 

Patch:
diff --git a/src/compile/references.js b/src/compile/references.js
index ce3aa65..4a96870 100644
--- a/src/compile/references.js
+++ b/src/compile/references.js
@@ -267,6 +267,8 @@ module.exports = function(Velocity, utils) {
         return getSize(baseRef);
       } else if (id === 'put' && !baseRef[id]) {
         return baseRef[this.getLiteral(property.args[0])] = this.getLiteral(property.args[1]);
+      } else if (id === 'add' && !baseRef[id]) {
+        return baseRef.push(this.getLiteral(property.args[0]));
       } else {
 
         ret = baseRef[id];


Test patch:
diff --git a/tests/compile.js b/tests/compile.js
index c3f1f41..12c5050 100644
--- a/tests/compile.js
+++ b/tests/compile.js
@@ -738,6 +738,29 @@ describe('Compile', function() {
     });
   });
 
+  describe('Add into empty array', function () {
+    it('should add item to array', function() {
+      var vm = `
+        #set($foo = [])
+        #set($ignore = $foo.add('foo'))
+        $foo
+      `;
+      var expected = '[foo]';
+      assert.equal(render(vm).trim(), expected)
+    });
+
+    it('should add object to array', function() {
+      var vm = `
+        #set($foo = [])
+        #set($ignore = $foo.add({'foo':'bar'}))
+        $foo
+      `;
+      var expected = '[{foo=bar}]';
+      assert.equal(render(vm).trim(), expected)
+    });
+
+  });
+
   describe('Object|Array#toString', function() {
     it('simple object', function() {
       var vm = '$data';