Fixed empty lambda expressions

This commit is contained in:
amitk 2014-11-13 00:25:12 +02:00
parent 68606d9681
commit 6839b7506b
6 changed files with 26 additions and 8 deletions

View File

@ -112,7 +112,11 @@ function generateProps(node, context) {
var funcParts = val.split('=>');
var evtParams = funcParts[0].replace('(', '').replace(')', '').trim();
var funcBody = funcParts[1].trim();
var generatedFuncName = generateInjectedFunc(context, key, funcBody,context.boundParams.concat([evtParams]));
var params = context.boundParams;
if (evtParams.trim() !== '') {
params = params.concat([evtParams.trim()]);
}
var generatedFuncName = generateInjectedFunc(context, key, funcBody, params);
props[propKey] = generatedFuncName + ".bind(" + (["this"].concat(context.boundParams)).join(",") + ")";
} else if (key === "style" && !isStringOnlyCode(val)) {
var styleParts = val.trim().split(";");
@ -214,7 +218,6 @@ function convertHtmlToReact(node, context) {
data.repeatBinds = ["this"].concat(_.reject(context.boundParams, function (param) {
return (param === data.item || param === data.item+"Index");
}));
console.log(data.repeatBinds);
data.body = repeatTemplate(data);
}
if (node.attribs[ifProp]) {

6
test/data/lambda.rt Normal file
View File

@ -0,0 +1,6 @@
<!DOCTYPE jsx>
<div rt-scope="{value:'event did not happen because onClick not called'} as data"
onMouseDown="(evt) => data.value = 'event did happen though it should not'"
onClick="() => data.value = 'event did happen though it should not'">
{data.value}
</div>

3
test/data/lambda.rt.html Normal file
View File

@ -0,0 +1,3 @@
<div>
event did not happen because onClick not called
</div>

View File

@ -1,6 +1,8 @@
<!DOCTYPE jsx>
<p>
<div rt-repeat="items in this.props.things">
<span style="width:auto;line-height: 5px;" onClick="(evt)=>this.happend(evt);return false;">Mock</span>
<span style="width:auto;line-height: 5px;"
onClick="(evt)=>this.happend(evt);return false;"
onMouseDown="()=>this.happend();return false;">Mock</span>
</div>
</p>

View File

@ -7,19 +7,24 @@ define([
this.happend(evt);
return false;
}
function repeatItems2(items, itemsIndex) {
function onMouseDown2(items, itemsIndex) {
this.happend();
return false;
}
function repeatItems3(items, itemsIndex) {
return React.DOM.div({}, React.DOM.span({
'style': {
width: 'auto',
lineHeight: '5px'
},
'onClick': onClick1.bind(this, items, itemsIndex)
'onClick': onClick1.bind(this, items, itemsIndex),
'onMouseDown': onMouseDown2.bind(this, items, itemsIndex)
}, 'Mock'));
}
return function () {
return React.DOM.p.apply(this, _.flatten([
{},
_.map(this.props.things, repeatItems2.bind(this))
_.map(this.props.things, repeatItems3.bind(this))
]));
};
});

View File

@ -36,7 +36,7 @@ function normalizeHtml(html) {
}
test('html tests', function (t) {
var files = ['scope.rt'];
var files = ['scope.rt', 'lambda.rt'];
t.plan(files.length);
files.forEach(check);
@ -60,7 +60,6 @@ test('html tests', function (t) {
var actual = React.renderToStaticMarkup(comp());
actual = normalizeHtml(actual);
expected = normalizeHtml(expected);
console.log(actual,expected)
t.equal(actual, expected);
if (actual !== expected) {
fs.writeFileSync(filename + '.actual.html', actual);