diff --git a/CHANGELOG.md b/CHANGELOG.md index ddb33ea8..7c4edf08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +Version 1.15.4, released 2020-11-27 +----------------------------------- +Minor improvements: +* Fix lost context when calling a macro multiple times ([#727](https://github.com/twigjs/twig.js/pull/727)) by [mihkeleidast ](https://github.com/mihkeleidast) + Version 1.15.3, released 2020-11-05 ----------------------------------- Minor improvements: diff --git a/package-lock.json b/package-lock.json index 87e85038..e5fb24ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "twig", - "version": "1.15.3", + "version": "1.15.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7c510a57..52433ef5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "John Roepke (http://john.sh/)", "name": "twig", "description": "JS port of the Twig templating language.", - "version": "1.15.3", + "version": "1.15.4", "homepage": "https://github.com/twigjs/twig.js", "license": "BSD-2-Clause", "licenses": [ diff --git a/src/twig.logic.js b/src/twig.logic.js index 3b3039e5..0031ac5c 100644 --- a/src/twig.logic.js +++ b/src/twig.logic.js @@ -1006,6 +1006,7 @@ module.exports = function (Twig) { state.macros[token.macroName] = function (...args) { // Pass global context and other macros const macroContext = { + ...context, _self: state.macros }; // Save arguments diff --git a/test/templates/macro-self-twice.twig b/test/templates/macro-self-twice.twig new file mode 100644 index 00000000..375c8992 --- /dev/null +++ b/test/templates/macro-self-twice.twig @@ -0,0 +1,2 @@ +{% macro input(name, value, type, size) %}{% endmacro %} +{% import _self as forms %}

{{ forms.input('username') }}

{{ forms.input('password') }}

diff --git a/test/test.macro.js b/test/test.macro.js index e51e4a03..0e9ef6df 100644 --- a/test/test.macro.js +++ b/test/test.macro.js @@ -34,6 +34,16 @@ describe('Twig.js Macro ->', function () { twig({ref: 'import-macro-self'}).render({ }).trim().should.equal('

'); }); + it('it should run macro with self reference twice', function () { + twig({ + id: 'import-macro-self-twice', + path: 'test/templates/macro-self-twice.twig', + async: false + }); + // Load the template + twig({ref: 'import-macro-self-twice'}).render({ }).trim().should.equal('

'); + }); + it('it should run wrapped macro with self reference', function () { twig({ id: 'import-wrapped-macro-self',