mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
<macro> tag now requires a name as its first attribute, which may or may not be an argument attribute
This commit is contained in:
parent
cd01b0cb5d
commit
6aef4d100f
@ -1,13 +1,10 @@
|
||||
module.exports = function codeGenerator(elNode, codegen) {
|
||||
|
||||
var attributes = elNode.attributes;
|
||||
if (!attributes.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
var defAttr = attributes[0];
|
||||
if (defAttr.argument == null) {
|
||||
return;
|
||||
|
||||
if(!defAttr || defAttr.value !== undefined) {
|
||||
return codegen.addError('The <macro> tag must contain a name as its first attribute, example: <macro greeting()>');
|
||||
}
|
||||
|
||||
var body = elNode.body;
|
||||
|
||||
5
test/autotests/render/error-macro-no-name/marko.json
Normal file
5
test/autotests/render/error-macro-no-name/marko.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"<test-open-tag-only>": {
|
||||
"open-tag-only": true
|
||||
}
|
||||
}
|
||||
7
test/autotests/render/error-macro-no-name/template.marko
Normal file
7
test/autotests/render/error-macro-no-name/template.marko
Normal file
@ -0,0 +1,7 @@
|
||||
<macro>
|
||||
This is bad.
|
||||
</macro>
|
||||
|
||||
<macro test=123>
|
||||
This is also bad.
|
||||
</macro>
|
||||
11
test/autotests/render/error-macro-no-name/test.js
Normal file
11
test/autotests/render/error-macro-no-name/test.js
Normal file
@ -0,0 +1,11 @@
|
||||
var expect = require('chai').expect;
|
||||
|
||||
exports.templateData = {};
|
||||
|
||||
exports.checkError = function(e) {
|
||||
expect(Array.isArray(e.errors)).to.equal(true);
|
||||
expect(e.errors.length).to.equal(2);
|
||||
|
||||
var message = e.toString();
|
||||
expect(message).to.contain('The <macro> tag must contain a name as its first attribute, example: <macro greeting()>');
|
||||
};
|
||||
@ -1 +1 @@
|
||||
Marko is awesomeMarko is awesome
|
||||
Marko is awesomeMarko is awesomeMarko is really awesomeMarko is really awesome
|
||||
@ -2,5 +2,11 @@
|
||||
Marko is awesome
|
||||
</macro>
|
||||
|
||||
<macro greeting2>
|
||||
Marko is really awesome
|
||||
</macro>
|
||||
|
||||
<greeting/>
|
||||
<greeting/>
|
||||
<greeting()/>
|
||||
<greeting2/>
|
||||
<greeting2()/>
|
||||
Loading…
x
Reference in New Issue
Block a user