mirror of
https://github.com/bobwen-dev/react-templates
synced 2025-04-12 00:56:39 +02:00
Allow trailing semicolon in rt-scope
Rationale: it is natural for many developers to place a trailing semicolon after the last scope alias pair, just as they do after every preceding pair in the list. Since it is possible to save them time (and perhaps frustration) at no cost in terms of semantics and safety, we should do so. On tests. Wasn't sure if this should be broken out into a separate test, or bundled together with the existing one.
This commit is contained in:
parent
cee215c081
commit
88dc5544e8
@ -293,6 +293,8 @@ function convertHtmlToReact(node, context) {
|
|||||||
data.scopeMapping[boundParam] = boundParam;
|
data.scopeMapping[boundParam] = boundParam;
|
||||||
});
|
});
|
||||||
_.each(node.attribs[scopeProp].split(';'), function (scopePart) {
|
_.each(node.attribs[scopeProp].split(';'), function (scopePart) {
|
||||||
|
if (scopePart.trim().length === 0) return;
|
||||||
|
|
||||||
var scopeSubParts = scopePart.split(' as ');
|
var scopeSubParts = scopePart.split(' as ');
|
||||||
if (scopeSubParts.length < 2) {
|
if (scopeSubParts.length < 2) {
|
||||||
throw RTCodeError.build("invalid scope part '" + scopePart + "'", context, node);
|
throw RTCodeError.build("invalid scope part '" + scopePart + "'", context, node);
|
||||||
|
6
test/data/scope-trailing-semicolon.rt
Normal file
6
test/data/scope-trailing-semicolon.rt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<div>
|
||||||
|
<div rt-scope="15 as a; 20 as b;">
|
||||||
|
{a + b}
|
||||||
|
</div>
|
||||||
|
<div rt-if="typeof a === 'undefined'">good</div>
|
||||||
|
</div>
|
2
test/data/scope-trailing-semicolon.rt.html
Normal file
2
test/data/scope-trailing-semicolon.rt.html
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<div><div>35</div><div>good</div></div>
|
||||||
|
|
@ -175,7 +175,7 @@ function normalizeHtml(html) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test('html tests', function (t) {
|
test('html tests', function (t) {
|
||||||
var files = ['scope.rt', 'lambda.rt', 'eval.rt', 'props.rt', 'custom-element.rt', 'style.rt', 'concat.rt', 'js-in-attr.rt', 'props-class.rt', 'rt-class.rt'];
|
var files = ['scope.rt', 'scope-trailing-semicolon.rt', 'lambda.rt', 'eval.rt', 'props.rt', 'custom-element.rt', 'style.rt', 'concat.rt', 'js-in-attr.rt', 'props-class.rt', 'rt-class.rt'];
|
||||||
t.plan(files.length);
|
t.plan(files.length);
|
||||||
|
|
||||||
files.forEach(check);
|
files.forEach(check);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user