Skip to content
This repository has been archived by the owner on May 13, 2019. It is now read-only.

Commit

Permalink
Remove extra brackets from render in particular cases.
Browse files Browse the repository at this point in the history
For HH syntax, even if node has single text child,
it should be wrapped in bracked due to ohanhi/hyperscript-helpers#6 (comment)

For HH syntax, hovewer it is not required.

Brackets around single commend child are not required in both syntaxes.
  • Loading branch information
ivan-kleshnin committed Dec 31, 2015
1 parent f9fb178 commit a9bb8ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion specs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("htmlToHs()", function () {
});

it("should convert comments", function () {
assert.equal(convert('<div><!-- c1 --></div>'), 'div([/* c1 */])');
assert.equal(convert('<div><!-- c1 --></div>'), 'div(/* c1 */)');
assert.equal(convert('<div>t1<span>t2</span><!-- c1 --><!-- c2 --></div>'), 'div([\n `t1`,\n span([`t2`])\n /* c1 */\n /* c2 */\n])');
assert.equal(convert('<div><!-- c1 --><!-- c2 -->t1<span>t2</span></div>'), 'div([\n /* c1 */\n /* c2 */\n `t1`,\n span([`t2`])\n])');
assert.equal(convert('<!-- c1 --><!-- c2 -->'), '[\n /* c1 */\n /* c2 */\n]');
Expand Down Expand Up @@ -99,6 +99,9 @@ describe("htmlToHs()", function () {

let html3 = `<div class="foo"><span></span></div>`;
assert.equal(htmlToHs({syntax: "h"}, html3), 'h("div.foo", [\n h("span")\n])');

let html4 = `<div>test</div>`;
assert.equal(htmlToHs({syntax: "h"}, html4), 'h("div", `test`)');
});
});
});
Expand Down
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ let htmlToHs2 = curry((opts, html) => {

let renderNodes = curry((depth, nodes) => {
if (nodes.length == 1 && isComment(nodes[0])) {
return "[" + renderCommentNode(0, nodes[0], 0) + "]";
return renderCommentNode(0, nodes[0], 0);
} else if (nodes.length == 1 && isText(nodes[0])) {
return "[" + renderTextNode(0, nodes[0], 0) + "]";
if (opts.syntax == "hh") {
return "[" + renderTextNode(0, nodes[0], 0) + "]";
} else {
return renderTextNode(0, nodes[0], 0);
}
} else {
let space = makeSpace(depth);
return "[\n" + joinNodes(depth + 1, nodes) + "\n" + space + "]";
Expand Down

0 comments on commit a9bb8ea

Please sign in to comment.