mirror of
https://github.com/bobwen-dev/react-templates
synced 2025-04-12 00:56:39 +02:00
Merge branch 'gh-pages' of github.com:wix/react-templates into gh-pages
This commit is contained in:
commit
12578a06a2
@ -32,8 +32,8 @@
|
||||
"chalk": "^1.1.1",
|
||||
"cheerio": "^0.19.0",
|
||||
"css": "^2.2.1",
|
||||
"escodegen": "1.7.1",
|
||||
"esprima-fb": "^15001.1001.0-dev-harmony-fb",
|
||||
"escodegen": "^1.8.0",
|
||||
"esprima": "^2.7.1",
|
||||
"lodash": "^3.10.1",
|
||||
"optionator": "^0.8.0",
|
||||
"text-table": "^0.2.0"
|
||||
|
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
var cheerio = require('cheerio');
|
||||
var _ = require('lodash');
|
||||
var esprima = require('esprima-fb');
|
||||
var esprima = require('esprima');
|
||||
var escodegen = require('escodegen');
|
||||
var reactDOMSupport = require('./reactDOMSupport');
|
||||
var reactNativeSupport = require('./reactNativeSupport');
|
||||
@ -51,6 +51,7 @@ var classAttr = 'class';
|
||||
var scopeAttr = 'rt-scope';
|
||||
var propsAttr = 'rt-props';
|
||||
var templateNode = 'rt-template';
|
||||
var virtualNode = 'rt-virtual';
|
||||
|
||||
/**
|
||||
* @param {Options} options
|
||||
@ -346,7 +347,7 @@ function convertHtmlToReact(node, context) {
|
||||
data.item = arr[0].trim();
|
||||
data.collection = arr[1].trim();
|
||||
validateJS(data.item, node, context);
|
||||
validateJS(data.collection, node, context);
|
||||
validateJS("(" + data.collection + ")", node, context);
|
||||
stringUtils.addIfMissing(context.boundParams, data.item);
|
||||
stringUtils.addIfMissing(context.boundParams, `${data.item}Index`);
|
||||
}
|
||||
@ -374,13 +375,20 @@ function convertHtmlToReact(node, context) {
|
||||
}
|
||||
}
|
||||
|
||||
data.children = utils.concatChildren(_.map(node.children, function (child) {
|
||||
var children = _.map(node.children, function (child) {
|
||||
var code = convertHtmlToReact(child, context);
|
||||
validateJS(code, child, context);
|
||||
return code;
|
||||
}));
|
||||
});
|
||||
|
||||
data.children = utils.concatChildren(children);
|
||||
|
||||
if (node.name === virtualNode) { //eslint-disable-line wix-editor/prefer-ternary
|
||||
data.body = "[" + _.compact(children).join(',') + "]"
|
||||
}
|
||||
else {
|
||||
data.body = _.template(getTagTemplateString(!hasNonSimpleChildren(node), reactSupport.shouldUseCreateElement(context)))(data);
|
||||
}
|
||||
|
||||
if (node.attribs[scopeAttr]) {
|
||||
var functionBody = _.values(data.innerScope.innerMapping).join('\n') + `return ${data.body}`;
|
||||
@ -522,6 +530,8 @@ function convertRT(html, reportContext, options) {
|
||||
});
|
||||
if (firstTag === null) {
|
||||
throw RTCodeError.build(context, rootNode.root()[0], 'Document should have a single root element');
|
||||
} else if (firstTag.name === virtualNode) {
|
||||
throw RTCodeError.build(context, firstTag, `Document should not have <${virtualNode}> as root element`);
|
||||
}
|
||||
var body = convertHtmlToReact(firstTag, context);
|
||||
var requirePaths = _(defines)
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
var _ = require('lodash');
|
||||
var esprima = require('esprima-fb');
|
||||
var esprima = require('esprima');
|
||||
var rtError = require('./RTCodeError');
|
||||
var RTCodeError = rtError.RTCodeError;
|
||||
|
||||
|
@ -2,4 +2,4 @@ import React from 'react/addons';
|
||||
import _ from 'lodash';
|
||||
export default function () {
|
||||
return React.createElement('div', {});
|
||||
};
|
||||
}
|
3
test/data/invalid-virtual.rt
Normal file
3
test/data/invalid-virtual.rt
Normal file
@ -0,0 +1,3 @@
|
||||
<rt-virtual>
|
||||
<div>This is not allowed</div>
|
||||
</rt-virtual>
|
5
test/data/repeat-literal-collection.rt
Normal file
5
test/data/repeat-literal-collection.rt
Normal file
@ -0,0 +1,5 @@
|
||||
<div>
|
||||
<div rt-repeat="items in {a:1, b:2}">
|
||||
{items}
|
||||
</div>
|
||||
</div>
|
1
test/data/repeat-literal-collection.rt.html
Normal file
1
test/data/repeat-literal-collection.rt.html
Normal file
@ -0,0 +1 @@
|
||||
<div><div>1</div><div>2</div></div>
|
14
test/data/virtual.rt
Normal file
14
test/data/virtual.rt
Normal file
@ -0,0 +1,14 @@
|
||||
<div>
|
||||
<rt-virtual rt-scope="'rendered' as verb">
|
||||
<rt-virtual rt-if="1<0">
|
||||
<div>this is not {verb}</div>
|
||||
</rt-virtual>
|
||||
<rt-virtual rt-if="1>0">
|
||||
<div>this is {verb}</div>
|
||||
</rt-virtual>
|
||||
<rt-virtual rt-repeat="n in [1,2]">
|
||||
<div>{verb} {n}-a</div>
|
||||
<div>{verb} {n}-b</div>
|
||||
</rt-virtual>
|
||||
</rt-virtual>
|
||||
</div>
|
1
test/data/virtual.rt.html
Normal file
1
test/data/virtual.rt.html
Normal file
@ -0,0 +1 @@
|
||||
<div><div>this is rendered</div><div>rendered 1-a</div><div>rendered 1-b</div><div>rendered 2-a</div><div>rendered 2-b</div></div>
|
@ -26,7 +26,8 @@ var invalidFiles = [
|
||||
{file: 'invalid-repeat.rt', issue: new RTCodeError('rt-repeat invalid \'in\' expression \'a in b in c\'', 0, 35, 1, 1)},
|
||||
{file: 'invalid-rt-require.rt', issue: new RTCodeError("rt-require needs 'dependency' and 'as' attributes", 0, 14, 1, 1)},
|
||||
{file: 'invalid-brace.rt', issue: new RTCodeError('Unexpected end of input', 128, 163, 5, 11)},
|
||||
{file: 'invalid-style.rt', issue: new RTCodeError('Unexpected token ILLEGAL', 10, 39, 2, 5)}
|
||||
{file: 'invalid-style.rt', issue: new RTCodeError('Unexpected token ILLEGAL', 10, 39, 2, 5)},
|
||||
{file: 'invalid-virtual.rt', issue: new RTCodeError('Document should not have <rt-virtual> as root element', 0, 60, 1, 1)}
|
||||
];
|
||||
|
||||
test('invalid tests', function (t) {
|
||||
@ -182,9 +183,27 @@ test('convert jsrt and test source results', function (t) {
|
||||
});
|
||||
|
||||
test('html tests', function (t) {
|
||||
var files = ['scope.rt', 'scope-trailing-semicolon.rt', 'scope-variable-references.rt', 'lambda.rt', 'eval.rt', 'props.rt', 'custom-element.rt', 'style.rt', 'concat.rt',
|
||||
'js-in-attr.rt', 'props-class.rt', 'rt-class.rt', 'className.rt', 'svg.rt',
|
||||
'scope-evaluated-after-repeat.rt', 'scope-evaluated-after-repeat2.rt', 'scope-evaluated-after-if.rt', 'scope-obj.rt'
|
||||
var files = [
|
||||
"scope.rt",
|
||||
"scope-trailing-semicolon.rt",
|
||||
"scope-variable-references.rt",
|
||||
"lambda.rt",
|
||||
"eval.rt",
|
||||
"props.rt",
|
||||
"custom-element.rt",
|
||||
"style.rt",
|
||||
"concat.rt",
|
||||
"js-in-attr.rt",
|
||||
"props-class.rt",
|
||||
"rt-class.rt",
|
||||
"className.rt",
|
||||
"svg.rt",
|
||||
"virtual.rt",
|
||||
"scope-evaluated-after-repeat.rt",
|
||||
"scope-evaluated-after-repeat2.rt",
|
||||
"scope-evaluated-after-if.rt",
|
||||
"scope-obj.rt",
|
||||
"repeat-literal-collection.rt"
|
||||
];
|
||||
t.plan(files.length);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user