From fff28fd4b3bdba73172ac8cf8f8280a028829a68 Mon Sep 17 00:00:00 2001 From: Antonino Porcino Date: Thu, 31 Dec 2015 15:47:09 +0100 Subject: [PATCH 1/7] Support for tag --- src/reactTemplates.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/reactTemplates.js b/src/reactTemplates.js index fea65f4..b254a12 100644 --- a/src/reactTemplates.js +++ b/src/reactTemplates.js @@ -374,13 +374,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.body = _.template(getTagTemplateString(!hasNonSimpleChildren(node), reactSupport.shouldUseCreateElement(context)))(data); + data.children = utils.concatChildren(children); + + if (node.name === 'virtual') { + data.body = "[" + _.compact(children).join(',') + "]" + console.log(data.body) + } + 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}`; From e8baaaec018aa3254081dc5ff4dde82c05b432ed Mon Sep 17 00:00:00 2001 From: Antonino Porcino Date: Thu, 31 Dec 2015 15:49:12 +0100 Subject: [PATCH 2/7] Fix typo --- src/reactTemplates.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/reactTemplates.js b/src/reactTemplates.js index b254a12..2ed8001 100644 --- a/src/reactTemplates.js +++ b/src/reactTemplates.js @@ -378,6 +378,7 @@ function convertHtmlToReact(node, context) { var code = convertHtmlToReact(child, context); validateJS(code, child, context); return code; + }); data.children = utils.concatChildren(children); From a3c1dc1dfbca2ecf29cf1cceafd32c2b8bffd61e Mon Sep 17 00:00:00 2001 From: Antonino Porcino Date: Thu, 31 Dec 2015 17:47:44 +0100 Subject: [PATCH 3/7] Changed to rt-virtual, added tests --- src/reactTemplates.js | 8 +++++--- test/data/invalid-virtual.rt | 3 +++ test/data/virtual.rt | 14 ++++++++++++++ test/data/virtual.rt.html | 1 + test/src/test.js | 5 +++-- 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 test/data/invalid-virtual.rt create mode 100644 test/data/virtual.rt create mode 100644 test/data/virtual.rt.html diff --git a/src/reactTemplates.js b/src/reactTemplates.js index 2ed8001..496bd41 100644 --- a/src/reactTemplates.js +++ b/src/reactTemplates.js @@ -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 @@ -378,13 +379,12 @@ function convertHtmlToReact(node, context) { var code = convertHtmlToReact(child, context); validateJS(code, child, context); return code; - }); + }); data.children = utils.concatChildren(children); - if (node.name === 'virtual') { + if (node.name === virtualNode) { //eslint-disable-line wix-editor/prefer-ternary data.body = "[" + _.compact(children).join(',') + "]" - console.log(data.body) } else { data.body = _.template(getTagTemplateString(!hasNonSimpleChildren(node), reactSupport.shouldUseCreateElement(context)))(data); @@ -530,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) diff --git a/test/data/invalid-virtual.rt b/test/data/invalid-virtual.rt new file mode 100644 index 0000000..e8498bc --- /dev/null +++ b/test/data/invalid-virtual.rt @@ -0,0 +1,3 @@ + +
This is not allowed
+
\ No newline at end of file diff --git a/test/data/virtual.rt b/test/data/virtual.rt new file mode 100644 index 0000000..9e26676 --- /dev/null +++ b/test/data/virtual.rt @@ -0,0 +1,14 @@ +
+ + +
this is not {verb}
+
+ +
this is {verb}
+
+ +
{verb} {n}-a
+
{verb} {n}-b
+
+
+
\ No newline at end of file diff --git a/test/data/virtual.rt.html b/test/data/virtual.rt.html new file mode 100644 index 0000000..7b35812 --- /dev/null +++ b/test/data/virtual.rt.html @@ -0,0 +1 @@ +
this is rendered
rendered 1-a
rendered 1-b
rendered 2-a
rendered 2-b
\ No newline at end of file diff --git a/test/src/test.js b/test/src/test.js index fb412d6..66c092c 100644 --- a/test/src/test.js +++ b/test/src/test.js @@ -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 as root element', 0, 60, 1, 1)} ]; test('invalid tests', function (t) { @@ -183,7 +184,7 @@ 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', + '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' ]; t.plan(files.length); From 27ad9e1cc038e780a72678aae0999850cace685d Mon Sep 17 00:00:00 2001 From: Antonino Porcino Date: Fri, 1 Jan 2016 18:20:35 +0100 Subject: [PATCH 4/7] Deprecated esprima-fb, back to upstream esprima --- package.json | 2 +- src/reactTemplates.js | 2 +- src/utils.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e0eeb20..ff26d62 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "cheerio": "^0.19.0", "css": "^2.2.1", "escodegen": "1.7.1", - "esprima-fb": "^15001.1001.0-dev-harmony-fb", + "esprima": "^2.7.1", "lodash": "^3.10.1", "optionator": "^0.8.0", "text-table": "^0.2.0" diff --git a/src/reactTemplates.js b/src/reactTemplates.js index fea65f4..2447018 100644 --- a/src/reactTemplates.js +++ b/src/reactTemplates.js @@ -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'); diff --git a/src/utils.js b/src/utils.js index 087f313..cd2f872 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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; From f35bb9312a9d1ab0c218a788d55729413b93cc93 Mon Sep 17 00:00:00 2001 From: Antonino Porcino Date: Fri, 1 Jan 2016 19:05:23 +0100 Subject: [PATCH 5/7] Fixed rt-repeat collection JS parsing --- src/reactTemplates.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reactTemplates.js b/src/reactTemplates.js index fea65f4..a4e1108 100644 --- a/src/reactTemplates.js +++ b/src/reactTemplates.js @@ -346,7 +346,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`); } From 9375b8e2d146d24c6ed6d4302e5549507395c585 Mon Sep 17 00:00:00 2001 From: Antonino Porcino Date: Fri, 1 Jan 2016 19:22:35 +0100 Subject: [PATCH 6/7] Added test for rt-repeat over object literal collection --- test/data/repeat-literal-collection.rt | 5 +++++ test/data/repeat-literal-collection.rt.html | 1 + test/src/test.js | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 test/data/repeat-literal-collection.rt create mode 100644 test/data/repeat-literal-collection.rt.html diff --git a/test/data/repeat-literal-collection.rt b/test/data/repeat-literal-collection.rt new file mode 100644 index 0000000..ebc5fb6 --- /dev/null +++ b/test/data/repeat-literal-collection.rt @@ -0,0 +1,5 @@ +
+
+ {items} +
+
\ No newline at end of file diff --git a/test/data/repeat-literal-collection.rt.html b/test/data/repeat-literal-collection.rt.html new file mode 100644 index 0000000..0364ab2 --- /dev/null +++ b/test/data/repeat-literal-collection.rt.html @@ -0,0 +1 @@ +
1
2
\ No newline at end of file diff --git a/test/src/test.js b/test/src/test.js index fb412d6..ee25747 100644 --- a/test/src/test.js +++ b/test/src/test.js @@ -184,7 +184,7 @@ 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' + 'repeat-literal-collection.rt', 'scope-evaluated-after-repeat.rt', 'scope-evaluated-after-repeat2.rt', 'scope-evaluated-after-if.rt', 'scope-obj.rt' ]; t.plan(files.length); From 510d394e2b1d8ce3dded83c508e19cc8cbd21742 Mon Sep 17 00:00:00 2001 From: Antonino Porcino Date: Sun, 3 Jan 2016 10:59:35 +0100 Subject: [PATCH 7/7] Updated escodegen, fixed es6 test --- package.json | 2 +- test/data/div.rt.es6.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ff26d62..e2fd205 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "chalk": "^1.1.1", "cheerio": "^0.19.0", "css": "^2.2.1", - "escodegen": "1.7.1", + "escodegen": "^1.8.0", "esprima": "^2.7.1", "lodash": "^3.10.1", "optionator": "^0.8.0", diff --git a/test/data/div.rt.es6.js b/test/data/div.rt.es6.js index 4f40316..9c4e38c 100644 --- a/test/data/div.rt.es6.js +++ b/test/data/div.rt.es6.js @@ -2,4 +2,4 @@ import React from 'react/addons'; import _ from 'lodash'; export default function () { return React.createElement('div', {}); -}; \ No newline at end of file +} \ No newline at end of file