From 36f84e4b3c761172272e37a10d7539f84e34068d Mon Sep 17 00:00:00 2001 From: harttle Date: Sat, 21 Jul 2018 17:12:46 +0800 Subject: [PATCH] refactor: pop the same context as the pushed one --- tags/include.js | 2 +- tags/layout.js | 4 +--- tags/tablerow.js | 5 ++--- test/scope.js | 1 + 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tags/include.js b/tags/include.js index 0ed9790e0..3315535f7 100644 --- a/tags/include.js +++ b/tags/include.js @@ -42,7 +42,7 @@ module.exports = function (liquid) { return liquid.renderer.renderTemplates(templates, scope) }) .then((html) => { - scope.pop() + scope.pop(hash) scope.opts.blocks = originBlocks scope.opts.blockMode = originBlockMode return html diff --git a/tags/layout.js b/tags/layout.js index 6689359f5..f8df29e77 100644 --- a/tags/layout.js +++ b/tags/layout.js @@ -38,14 +38,12 @@ module.exports = function (liquid) { return liquid.getTemplate(layout, scope.opts.root) }) .then(templates => { - // push the hash scope.push(hash) scope.opts.blockMode = 'output' return liquid.renderer.renderTemplates(templates, scope) }) - // pop the hash .then(partial => { - scope.pop() + scope.pop(hash) return partial }) } diff --git a/tags/tablerow.js b/tags/tablerow.js index eaa0fb96e..7386fe824 100644 --- a/tags/tablerow.js +++ b/tags/tablerow.js @@ -43,11 +43,10 @@ module.exports = function (liquid) { // build array of arguments to pass to sequential promises... collection = collection.slice(offset, offset + limit) if (!cols) cols = collection.length - var contexts = [] - collection.some((item, i) => { + var contexts = collection.map((item, i) => { var ctx = {} ctx[this.variable] = item - contexts.push(ctx) + return ctx }) return mapSeries(contexts, diff --git a/test/scope.js b/test/scope.js index 2b7b45a85..6ecce7de1 100644 --- a/test/scope.js +++ b/test/scope.js @@ -1,3 +1,4 @@ +'use strict' const chai = require('chai') const expect = chai.expect