<macro> tag now requires a name as its first attribute, which may or may not be an argument attribute

This commit is contained in:
Michael Rawlings 2016-06-02 16:04:46 -07:00
parent cd01b0cb5d
commit 6aef4d100f
6 changed files with 34 additions and 8 deletions

View File

@ -1,13 +1,10 @@
module.exports = function codeGenerator(elNode, codegen) { module.exports = function codeGenerator(elNode, codegen) {
var attributes = elNode.attributes; var attributes = elNode.attributes;
if (!attributes.length) {
return;
}
var defAttr = attributes[0]; 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; var body = elNode.body;

View File

@ -0,0 +1,5 @@
{
"<test-open-tag-only>": {
"open-tag-only": true
}
}

View File

@ -0,0 +1,7 @@
<macro>
This is bad.
</macro>
<macro test=123>
This is also bad.
</macro>

View 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()>');
};

View File

@ -1 +1 @@
Marko is awesomeMarko is awesome Marko is awesomeMarko is awesomeMarko is really awesomeMarko is really awesome

View File

@ -2,5 +2,11 @@
Marko is awesome Marko is awesome
</macro> </macro>
<macro greeting2>
Marko is really awesome
</macro>
<greeting/> <greeting/>
<greeting/> <greeting()/>
<greeting2/>
<greeting2()/>