From a3c1dc1dfbca2ecf29cf1cceafd32c2b8bffd61e Mon Sep 17 00:00:00 2001 From: Antonino Porcino Date: Thu, 31 Dec 2015 17:47:44 +0100 Subject: [PATCH] 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);