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..1867b78f 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('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'); + }); });