Marko v3: Allow <else if(foo)>

This commit is contained in:
Patrick Steele-Idem 2016-02-16 22:24:03 -07:00
parent 7e9e408c2a
commit ef1374097f
4 changed files with 29 additions and 2 deletions

View File

@ -1,5 +1,7 @@
'use strict';
module.exports = function nodeFactory(el, context) {
var attributes = el.attributes;
var elseStatement = context.builder.elseStatement();
var argument = el.argument;
@ -7,8 +9,27 @@ module.exports = function nodeFactory(el, context) {
context.addError(elseStatement, 'Invalid <else> tag. Argument is not allowed');
}
if (attributes.length) {
if (el.hasAttribute('if')) {
let ifAttr = el.getAttribute('if');
el.removeAttribute('if');
if (el.attributes.length) {
context.addError(elseStatement, 'Invalid <else if> tag. Only the "if" attribute is allowed.');
return el;
}
var testExpression = ifAttr.argument;
if (!testExpression) {
context.addError(elseStatement, 'Invalid <else if> tag. Invalid "if" attribute. Expected: <else if(<test>)>');
return el;
}
var elseIfStatement = context.builder.elseIfStatement(testExpression);
return elseIfStatement;
}
if (el.attributes.length) {
context.addError(elseStatement, 'Invalid <else> tag. Attributes not allowed.');
return el;
}
return elseStatement;

View File

@ -0,0 +1 @@
B

View File

@ -0,0 +1,4 @@
if(false)
- A
else if(true)
- B

View File

@ -0,0 +1 @@
exports.templateData = {};