1
0
mirror of https://github.com/bobwen-dev/react-templates synced 2025-04-12 00:56:39 +02:00

change string concat to separate children in the function call, so you don't get [Object object]

This commit is contained in:
avim 2015-02-08 17:26:29 +02:00
parent 5a43e9f28a
commit 0af424dd7e
5 changed files with 9 additions and 7 deletions

View File

@ -94,7 +94,7 @@ function convertText(node, context, txt) {
var start = txt.indexOf('{');
var pre = txt.substr(0, start);
if (pre) {
res += (first ? '' : '+') + JSON.stringify(pre);
res += (first ? '' : ',') + JSON.stringify(pre);
first = false;
}
var curlyCounter = 1;
@ -106,13 +106,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 ? '' : ',') + (needsParens ? '(' : '') + txt.substr(start + 1, end - start - 2) + (needsParens ? ')' : '');
first = false;
txt = txt.substr(end);
}
}
if (txt) {
res += (first ? '' : '+') + JSON.stringify(txt);
res += (first ? '' : ',') + JSON.stringify(txt);
}
if (res === '') {
res = 'true';

1
test/data/concat.rt Normal file
View File

@ -0,0 +1 @@
<div>Hello RT!{React.DOM.span({},'test')}</div>

1
test/data/concat.rt.html Normal file
View File

@ -0,0 +1 @@
<div>Hello RT!<span>test</span></div>

View File

@ -6,6 +6,6 @@ define([
], function (React, _, myComp, utils) {
'use strict';
return function () {
return React.createElement(myComp, {}, '\n' + utils.translate('Hello', 'es') + '\n');
return React.createElement(myComp, {}, '\n', utils.translate('Hello', 'es'), '\n');
};
});

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'];
var files = ['scope.rt', 'lambda.rt', 'eval.rt', 'props.rt', 'custom-element.rt', 'style.rt', 'concat.rt'];
t.plan(files.length);
files.forEach(check);
@ -231,7 +231,7 @@ test('test shell', function (t) {
test('test convertText', function (t) {
var texts = [
{input: '{}', expected: '()'},
{input: "a {'b'}", expected: '"a "+(\'b\')'}
{input: "a {'b'}", expected: '"a ",(\'b\')'}
];
t.plan(texts.length);
texts.forEach(check);
@ -244,7 +244,7 @@ test('test convertText', function (t) {
test('test convertText errors', function (t) {
var texts = [
{input: '{}', expected: '()'},
{input: "a {'b'}", expected: '"a "+(\'b\')'}
{input: "a {'b'}", expected: '"a ",(\'b\')'}
];
t.plan(texts.length);
texts.forEach(check);