Forbid rt-repeat in root nodes (fix #171)

This commit is contained in:
Antonino Porcino 2016-07-08 12:19:35 +02:00
parent 9b8d15a530
commit d80de30f62
5 changed files with 8 additions and 2 deletions

View File

@ -584,6 +584,8 @@ function parseAndConvertHtmlToReact(html, context) {
throw RTCodeError.build(context, rootNode.root()[0], 'Document should have a single root element');
} else if (firstTag.name === virtualNode) {
throw RTCodeError.build(context, firstTag, `Document should not have <${virtualNode}> as root element`);
} else if (_.includes(_.keys(firstTag.attribs), repeatAttr)) {
throw RTCodeError.build(context, firstTag, "root element may not have a 'rt-repeat' attribute");
}
return convertHtmlToReact(firstTag, context);
}

View File

@ -0,0 +1,3 @@
<div>
<div rt-repeat="a in b in c"></div>
<div>

View File

@ -0,0 +1 @@
<div rt-repeat="a in [1,2,3]">{a}</div>

View File

@ -1 +0,0 @@
<div rt-repeat="a in b in c"></div>

View File

@ -22,7 +22,8 @@ module.exports = {
{file: 'invalid-lambda.rt', issue: new RTCodeError("when using 'on' events, use lambda '(p1,p2)=>body' notation or use {} to return a callback function. error: [onClick='']", 0, 23, 1, 1)},
{file: 'invalid-js.rt', issue: new RTCodeError('Unexpected token ILLEGAL', 0, 32, 1, 1)},
{file: 'invalid-single-root.rt', issue: new RTCodeError('Document should have no more than a single root element', 12, 23, 2, 1)},
{file: 'invalid-repeat.rt', issue: new RTCodeError('rt-repeat invalid \'in\' expression \'a in b in c\'', 0, 35, 1, 1)},
{file: 'invalid-repeat-1.rt', issue: new RTCodeError("rt-repeat invalid 'in' expression 'a in b in c'", 9, 44, 2, 4)},
{file: 'invalid-repeat-2.rt', issue: new RTCodeError("root element may not have a 'rt-repeat' attribute", 0, 39, 1, 1)},
{file: 'invalid-rt-require-1.rt', issue: new RTCodeError("'rt-require' needs 'dependency' and 'as' attributes", 0, 14, 1, 1)},
{file: 'invalid-rt-require-2.rt', issue: new RTCodeError("'rt-require' may have no children", 0, 32, 1, 1)},
{file: 'invalid-rt-import-1.rt', issue: new RTCodeError("'*' imports must have an 'as' attribute", 0, 36, 1, 1)},