mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fixes #636 - Add error when macro with duplicate name is found
This commit is contained in:
parent
97904837b7
commit
4dd12b202c
@ -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, `<macro> 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);
|
||||
};
|
||||
};
|
||||
|
||||
5
test/autotests/render/error-duplicate-macro/marko.json
Normal file
5
test/autotests/render/error-duplicate-macro/marko.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"<test-open-tag-only>": {
|
||||
"open-tag-only": true
|
||||
}
|
||||
}
|
||||
10
test/autotests/render/error-duplicate-macro/template.marko
Normal file
10
test/autotests/render/error-duplicate-macro/template.marko
Normal file
@ -0,0 +1,10 @@
|
||||
<if(true)>
|
||||
<macro hello()>
|
||||
Hello1
|
||||
</macro>
|
||||
</if>
|
||||
<else>
|
||||
<macro hello()>
|
||||
Hello2
|
||||
</macro>
|
||||
</else>
|
||||
9
test/autotests/render/error-duplicate-macro/test.js
Normal file
9
test/autotests/render/error-duplicate-macro/test.js
Normal file
@ -0,0 +1,9 @@
|
||||
var expect = require('chai').expect;
|
||||
|
||||
exports.templateData = {};
|
||||
|
||||
exports.checkError = function(e) {
|
||||
var message = e.toString();
|
||||
expect(message).to.contain('<macro> tag with duplicate name of "hello" found');
|
||||
expect(message).to.contain('template.marko:7:4');
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user