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:
anchann 2015-07-27 13:57:16 +09:00
parent cee215c081
commit 88dc5544e8
4 changed files with 11 additions and 1 deletions

View File

@ -293,6 +293,8 @@ function convertHtmlToReact(node, context) {
data.scopeMapping[boundParam] = boundParam;
});
_.each(node.attribs[scopeProp].split(';'), function (scopePart) {
if (scopePart.trim().length === 0) return;
var scopeSubParts = scopePart.split(' as ');
if (scopeSubParts.length < 2) {
throw RTCodeError.build("invalid scope part '" + scopePart + "'", context, node);

View 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>

View File

@ -0,0 +1,2 @@
<div><div>35</div><div>good</div></div>

View File

@ -175,7 +175,7 @@ function normalizeHtml(html) {
}
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);
files.forEach(check);