diff --git a/package.json b/package.json index 4ba3fdf5e..f82003534 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "shopify-liquid", - "version": "1.1.8", + "version": "1.1.9", "description": "A Shopify Liquid Implementation in Node.js", "main": "index.js", "scripts": { diff --git a/src/scope.js b/src/scope.js index 75b43f91c..954e004c3 100644 --- a/src/scope.js +++ b/src/scope.js @@ -4,9 +4,16 @@ const error = require('./error.js'); var scope = { get: function(str) { + var ctx = {}; for (var i = this.scopes.length - 1; i >= 0; i--) { + if(str === undefined){ + _.merge(ctx, this.scopes[i]); + } var v = _.get(this.scopes[i], str); if (v !== undefined) return v; + if(str === undefined){ + return ctx; + } } }, set: function(k, v) { diff --git a/test/scope.js b/test/scope.js index d2a19d3f4..9b5288c05 100644 --- a/test/scope.js +++ b/test/scope.js @@ -5,18 +5,25 @@ var expect = chai.expect; var Scope = require('../src/scope.js'); describe('scope', function() { - var scope; + var scope, ctx; beforeEach(function(){ - scope = Scope.factory({ + ctx = { foo: 'bar', bar: ['a', {b: [1, 2]}] - }); + }; + scope = Scope.factory(ctx); }); it('should get property', function() { scope.get('foo').should.equal('bar'); }); + it('should get all property', function() { + scope.get().should.deep.equal(ctx); + expect(scope.get('')).to.equal(undefined); + expect(scope.get(false)).to.equal(undefined); + }); + it('should set property', function() { scope.set('foo', 'FOO'); scope.get('foo').should.equal('FOO');