mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Marko v3: Allow <else if(foo)>
This commit is contained in:
parent
7e9e408c2a
commit
ef1374097f
@ -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;
|
||||
|
||||
1
test/fixtures/render/autotest/if-else-if-concise/expected.html
vendored
Normal file
1
test/fixtures/render/autotest/if-else-if-concise/expected.html
vendored
Normal file
@ -0,0 +1 @@
|
||||
B
|
||||
4
test/fixtures/render/autotest/if-else-if-concise/template.marko
vendored
Normal file
4
test/fixtures/render/autotest/if-else-if-concise/template.marko
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
if(false)
|
||||
- A
|
||||
else if(true)
|
||||
- B
|
||||
1
test/fixtures/render/autotest/if-else-if-concise/test.js
vendored
Normal file
1
test/fixtures/render/autotest/if-else-if-concise/test.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.templateData = {};
|
||||
Loading…
x
Reference in New Issue
Block a user