diff --git a/taglibs/core/macro-tag.js b/taglibs/core/macro-tag.js index cb1dc926d..0dc766bb8 100644 --- a/taglibs/core/macro-tag.js +++ b/taglibs/core/macro-tag.js @@ -10,6 +10,12 @@ module.exports = function nodeFactory(elNode, context) { var body = elNode.body; var macroName = defAttr.name; + + if (context.isMacro(macroName)) { + context.addError(elNode, ` tag with duplicate name of "${macroName}" found.`); + return elNode; + } + var argument = defAttr.argument; var params; if (argument) { @@ -23,4 +29,4 @@ module.exports = function nodeFactory(elNode, context) { context.registerMacro(macroName, params); return builder.macro(macroName, params, body); -}; \ No newline at end of file +}; diff --git a/test/autotests/render/error-duplicate-macro/marko.json b/test/autotests/render/error-duplicate-macro/marko.json new file mode 100644 index 000000000..35cf25b45 --- /dev/null +++ b/test/autotests/render/error-duplicate-macro/marko.json @@ -0,0 +1,5 @@ +{ + "": { + "open-tag-only": true + } +} \ No newline at end of file diff --git a/test/autotests/render/error-duplicate-macro/template.marko b/test/autotests/render/error-duplicate-macro/template.marko new file mode 100644 index 000000000..168bd201c --- /dev/null +++ b/test/autotests/render/error-duplicate-macro/template.marko @@ -0,0 +1,10 @@ + + + Hello1 + + + + + Hello2 + + diff --git a/test/autotests/render/error-duplicate-macro/test.js b/test/autotests/render/error-duplicate-macro/test.js new file mode 100644 index 000000000..72c114c4c --- /dev/null +++ b/test/autotests/render/error-duplicate-macro/test.js @@ -0,0 +1,9 @@ +var expect = require('chai').expect; + +exports.templateData = {}; + +exports.checkError = function(e) { + var message = e.toString(); + expect(message).to.contain(' tag with duplicate name of "hello" found'); + expect(message).to.contain('template.marko:7:4'); +};