diff --git a/index.js b/index.js index a74332378..6b4370912 100644 --- a/index.js +++ b/index.js @@ -38,15 +38,7 @@ var _engine = { return this.parser.parse(tokens); }, render: function(tpl, ctx, opts) { - opts = _.assign({ - strict_variables: false, - strict_filters: false, - root: [] - }, opts); - this.renderer.initRegister(opts); - var scope = Scope.factory(ctx, { - strict: opts.strict_variables, - }); + var scope = Scope.factory(ctx, opts); return this.renderer.renderTemplates(tpl, scope); }, parseAndRender: function(html, ctx, opts) { diff --git a/src/render.js b/src/render.js index 1bb9a6df2..bb378e363 100644 --- a/src/render.js +++ b/src/render.js @@ -42,7 +42,7 @@ var render = { if (template.name === 'break') { return Promise.reject(new RenderBreak('break')); } - return template.render(scope, this.register); + return template.render(scope); }, evalOutput: function(template, scope) { @@ -50,7 +50,7 @@ var render = { var val = Syntax.evalExp(template.initial, scope); template.filters.some(filter => { if (filter.error) { - if (this.register.strict_filters) { + if (scope.get('liquid.strict_filters')) { throw filter.error; } else { val = '' @@ -60,16 +60,11 @@ var render = { val = filter.render(val, scope); }); return val; - }, - - initRegister: function(opts) { - return this.register = opts; } }; function factory() { var instance = Object.create(render); - instance.register = {}; return instance; } diff --git a/src/scope.js b/src/scope.js index 49762009b..3da6354dd 100644 --- a/src/scope.js +++ b/src/scope.js @@ -26,7 +26,7 @@ var Scope = { }, get: function(str) { var val = this.safeGet(str); - if (val === undefined && this.opts.strict) { + if (val === undefined && this.opts.strict_variables) { throw new Error(`[strict_variables] undefined variable: ${str}`); } return val; @@ -149,9 +149,12 @@ function matchRightBracket(str, begin) { exports.factory = function(ctx, opts) { opts = _.assign({ - strict: false, - blocks: {} + strict_variables: false, + strict_filters: false, + blocks: {}, + root: [] }, opts); + ctx = _.assign(ctx, { liquid: opts }); diff --git a/src/tag.js b/src/tag.js index 2f47d0b66..227ebc67b 100644 --- a/src/tag.js +++ b/src/tag.js @@ -18,9 +18,9 @@ module.exports = function() { var tagImpls = {}; var _tagInstance = { - render: function(scope, register) { + render: function(scope) { var obj = hash(this.token.args, scope); - return this.tagImpl.render && this.tagImpl.render(scope, obj, register) || Promise.resolve(''); + return this.tagImpl.render && this.tagImpl.render(scope, obj) || Promise.resolve(''); }, parse: function(token, tokens){ this.type = 'tag'; diff --git a/tags/cycle.js b/tags/cycle.js index 02b2989dd..07e779a9e 100644 --- a/tags/cycle.js +++ b/tags/cycle.js @@ -24,9 +24,10 @@ module.exports = function(liquid) { assert(this.candidates.length, `empty candidates: ${tagToken.raw}`); }, - render: function(scope, hash, register) { + render: function(scope, hash) { var group = Liquid.evalValue(this.group, scope); var fingerprint = `cycle:${group}:` + this.candidates.join(','); + var register = scope.get('liquid'); var idx = register[fingerprint]; if(idx === undefined){ diff --git a/tags/include.js b/tags/include.js index 4c6d89301..a02ba8c61 100644 --- a/tags/include.js +++ b/tags/include.js @@ -16,12 +16,12 @@ module.exports = function(liquid) { this.with = match[1]; } }, - render: function(scope, hash, register) { + render: function(scope, hash) { var filepath = Liquid.evalValue(this.value, scope); - var reg = scope.get('liquid'); - var originBlocks = reg.blocks; - reg.blocks = {}; + var register = scope.get('liquid'); + var originBlocks = register.blocks; + register.blocks = {}; if(this.with){ hash[filepath] = Liquid.evalValue(this.with, scope); @@ -33,7 +33,7 @@ module.exports = function(liquid) { }) .then((html) => { scope.pop(); - reg.blocks = originBlocks; + register.blocks = originBlocks; return html; }); } diff --git a/tags/layout.js b/tags/layout.js index 7db0c6a7b..bbf384b69 100644 --- a/tags/layout.js +++ b/tags/layout.js @@ -13,9 +13,9 @@ module.exports = function(liquid) { this.layout = match[0]; this.tpls = liquid.parser.parse(remainTokens); }, - render: function(scope, hash, register) { + render: function(scope, hash) { var layout = Liquid.evalValue(this.layout, scope); - var reg = scope.get('liquid'); + var register = scope.get('liquid'); // render the remaining tokens immediately return liquid.renderer.renderTemplates(this.tpls, scope) diff --git a/test/scope.js b/test/scope.js index 1fe6fdd2b..83913d7db 100644 --- a/test/scope.js +++ b/test/scope.js @@ -73,7 +73,7 @@ describe('scope', function() { it('should throw undefined in strict mode', function() { scope = Scope.factory(ctx, { - strict: true + strict_variables: true }); function fn() {