mirror of
https://github.com/bobwen-dev/react-templates
synced 2025-04-12 00:56:39 +02:00
Forbid rt-repeat in root nodes (fix #171)
This commit is contained in:
parent
9b8d15a530
commit
d80de30f62
@ -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);
|
||||
}
|
||||
|
3
test/data/invalid/invalid-repeat-1.rt
Normal file
3
test/data/invalid/invalid-repeat-1.rt
Normal file
@ -0,0 +1,3 @@
|
||||
<div>
|
||||
<div rt-repeat="a in b in c"></div>
|
||||
<div>
|
1
test/data/invalid/invalid-repeat-2.rt
Normal file
1
test/data/invalid/invalid-repeat-2.rt
Normal file
@ -0,0 +1 @@
|
||||
<div rt-repeat="a in [1,2,3]">{a}</div>
|
@ -1 +0,0 @@
|
||||
<div rt-repeat="a in b in c"></div>
|
@ -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)},
|
||||
|
Loading…
x
Reference in New Issue
Block a user