fixed js execution context outside of string nodes needs to concat as string

This commit is contained in:
avim 2015-02-09 10:43:55 +02:00
parent 0af424dd7e
commit d1e6d41740
4 changed files with 7 additions and 4 deletions

View File

@ -90,11 +90,12 @@ var curlyMap = {'{': 1, '}': -1};
function convertText(node, context, txt) {
var res = '';
var first = true;
var concatChar = node.type === 'text' ? ',' : '+';
while (txt.indexOf('{') !== -1) {
var start = txt.indexOf('{');
var pre = txt.substr(0, start);
if (pre) {
res += (first ? '' : ',') + JSON.stringify(pre);
res += (first ? '' : concatChar) + JSON.stringify(pre);
first = false;
}
var curlyCounter = 1;
@ -106,13 +107,13 @@ function convertText(node, context, txt) {
throw RTCodeError.build("Failed to parse text '" + txt + "'", context, node);
} else {
var needsParens = start !== 0 || end !== txt.length - 1;
res += (first ? '' : ',') + (needsParens ? '(' : '') + txt.substr(start + 1, end - start - 2) + (needsParens ? ')' : '');
res += (first ? '' : concatChar) + (needsParens ? '(' : '') + txt.substr(start + 1, end - start - 2) + (needsParens ? ')' : '');
first = false;
txt = txt.substr(end);
}
}
if (txt) {
res += (first ? '' : ',') + JSON.stringify(txt);
res += (first ? '' : concatChar) + JSON.stringify(txt);
}
if (res === '') {
res = 'true';

1
test/data/js-in-attr.rt Normal file
View File

@ -0,0 +1 @@
<div class="test{true?'A':'B'}">Hello RT!</div>

View File

@ -0,0 +1 @@
<div class="testA">Hello RT!</div>

View File

@ -158,7 +158,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'];
var files = ['scope.rt', 'lambda.rt', 'eval.rt', 'props.rt', 'custom-element.rt', 'style.rt', 'concat.rt', 'js-in-attr.rt'];
t.plan(files.length);
files.forEach(check);