mirror of
https://github.com/bobwen-dev/react-templates
synced 2025-04-12 00:56:39 +02:00
Fix code generation for rt-template siblings. (#164)
* Clean up the list of propTemplates fixtures. * Subtract the child index of a rt-template tag by the number of rt-template tags seen. Fixes wix/react-templates#163.
This commit is contained in:
parent
fb3afc9a5b
commit
4a403dffbf
@ -116,6 +116,7 @@ function generateInjectedFunc(context, namePrefix, body, params) {
|
||||
}
|
||||
|
||||
function generateTemplateProps(node, context) {
|
||||
let templatePropCount = 0;
|
||||
const propTemplateDefinition = context.options.propTemplates[node.name];
|
||||
const propertiesTemplates = _(node.children)
|
||||
.map((child, index) => {
|
||||
@ -141,7 +142,7 @@ function generateTemplateProps(node, context) {
|
||||
}
|
||||
|
||||
if (templateProp) {
|
||||
_.assign(templateProp, {childIndex: index, content: _.find(child.children, {type: 'tag'})});
|
||||
_.assign(templateProp, {childIndex: index - templatePropCount++, content: _.find(child.children, {type: 'tag'})});
|
||||
}
|
||||
|
||||
return templateProp;
|
||||
|
12
test/data/propTemplates/siblingTemplates.rt
Normal file
12
test/data/propTemplates/siblingTemplates.rt
Normal file
@ -0,0 +1,12 @@
|
||||
<div>
|
||||
<rt-template prop="templateProp1" arguments="brother">
|
||||
<div>Brother: {brother}</div>
|
||||
</rt-template>
|
||||
<rt-template prop="templateProp2" arguments="sister">
|
||||
<div>Sister: {sister}</div>
|
||||
</rt-template>
|
||||
<div>Separator</div>
|
||||
<rt-template prop="templateProp3" arguments="other">
|
||||
<div>Other: {other}</div>
|
||||
</rt-template>
|
||||
</div>
|
22
test/data/propTemplates/siblingTemplates.rt.js
Normal file
22
test/data/propTemplates/siblingTemplates.rt.js
Normal file
@ -0,0 +1,22 @@
|
||||
define([
|
||||
'react',
|
||||
'lodash'
|
||||
], function (React, _) {
|
||||
'use strict';
|
||||
function templateProp11(brother) {
|
||||
return React.createElement('div', {}, 'Brother: ', brother);
|
||||
}
|
||||
function templateProp22(sister) {
|
||||
return React.createElement('div', {}, 'Sister: ', sister);
|
||||
}
|
||||
function templateProp33(other) {
|
||||
return React.createElement('div', {}, 'Other: ', other);
|
||||
}
|
||||
return function () {
|
||||
return React.createElement('div', {
|
||||
'templateProp1': templateProp11.bind(this),
|
||||
'templateProp2': templateProp22.bind(this),
|
||||
'templateProp3': templateProp33.bind(this)
|
||||
}, React.createElement('div', {}, 'Separator'));
|
||||
};
|
||||
});
|
@ -49,7 +49,13 @@ module.exports = {
|
||||
},
|
||||
modules: 'amd'
|
||||
};
|
||||
const files = ['propTemplates/simpleTemplate.rt', 'propTemplates/templateInScope.rt', 'propTemplates/implicitTemplate.rt', 'propTemplates/twoTemplates.rt'];
|
||||
const files = [
|
||||
'simpleTemplate.rt',
|
||||
'templateInScope.rt',
|
||||
'implicitTemplate.rt',
|
||||
'twoTemplates.rt',
|
||||
'siblingTemplates.rt'
|
||||
].map(file => path.join('propTemplates', file));
|
||||
testFiles(t, files, options);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user