From 1af0706d4afe5f6b2e6da34d0220c4a104038ee5 Mon Sep 17 00:00:00 2001 From: Logan Bell Date: Tue, 29 Jul 2014 11:34:36 -0700 Subject: [PATCH 1/2] Fixing issue #499 * Prior to version 1.4.1 the output of a macro could be assigned to a variable with "set" - this restores that bahavior. --- lib/tags/macro.js | 3 +-- tests/tags/macro.test.js | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tags/macro.js b/lib/tags/macro.js index 19b80771..44655e15 100644 --- a/lib/tags/macro.js +++ b/lib/tags/macro.js @@ -22,12 +22,11 @@ exports.compile = function (compiler, args, content, parents, options, blockName return '_ctx.' + fnName + ' = function (' + args.join('') + ') {\n' + ' var _output = "";\n' + ' __ctx = _utils.extend({}, _ctx),\n' + - ' _ctx = _utils.extend({}, __ctx);\n' + ' _utils.each(_ctx, function (v, k) {\n' + ' if (["' + args.join('","') + '"].indexOf(k) !== -1) { delete _ctx[k]; }\n' + ' });\n' + compiler(content, parents, options, blockName) + '\n' + - ' _ctx = __ctx;\n' + + ' _ctx = _utils.extend(_ctx, __ctx);\n' + ' return _output;\n' + '};\n' + '_ctx.' + fnName + '.safe = true;\n'; diff --git a/tests/tags/macro.test.js b/tests/tags/macro.test.js index 5f16d2f0..0a3a8537 100644 --- a/tests/tags/macro.test.js +++ b/tests/tags/macro.test.js @@ -31,4 +31,8 @@ describe('Tag: macro', function () { it('gh-457: local context is copied and overwritten within macro context', function () { expect(swig.render('{% set foo = 1 %}{% set baz = 3 %}{% macro bar(foo) %}{{ foo }}{{ baz }}{% endmacro %}{{ bar(2) }}{{ foo }}')).to.equal('231'); }); + + it('a macro can be set to a variable', function () { + expect(swig.render('{% macro burrito() %}burrito{% endmacro %}{% set foo = burrito() %}{{foo}}')).to.equal('burrito'); + }); }); From 7ce80b4b3c2b1f7740b6d2c00484dfa7179538b9 Mon Sep 17 00:00:00 2001 From: Logan Bell Date: Tue, 29 Jul 2014 14:32:06 -0700 Subject: [PATCH 2/2] Prepending the test with the issue number --- tests/tags/macro.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tags/macro.test.js b/tests/tags/macro.test.js index 0a3a8537..1867b78f 100644 --- a/tests/tags/macro.test.js +++ b/tests/tags/macro.test.js @@ -32,7 +32,7 @@ describe('Tag: macro', function () { expect(swig.render('{% set foo = 1 %}{% set baz = 3 %}{% macro bar(foo) %}{{ foo }}{{ baz }}{% endmacro %}{{ bar(2) }}{{ foo }}')).to.equal('231'); }); - it('a macro can be set to a variable', function () { + it('gh-499: a macro can be set to a variable', function () { expect(swig.render('{% macro burrito() %}burrito{% endmacro %}{% set foo = burrito() %}{{foo}}')).to.equal('burrito'); }); });