diff --git a/lib/6to5/generators/jsx.js b/lib/6to5/generators/jsx.js index 196a4780e4..fb0aadf93f 100644 --- a/lib/6to5/generators/jsx.js +++ b/lib/6to5/generators/jsx.js @@ -1,3 +1,5 @@ +var _ = require("lodash"); + exports.XJSAttribute = function (node, print) { print(node.name); if (node.value) { @@ -34,22 +36,44 @@ exports.XJSExpressionContainer = function (node, print) { this.push("}"); }; -exports.XJSElement = function () { - throw new Error("XJSElement"); +exports.XJSElement = function (node, print) { + var self = this; + + var open = node.openingElement; + print(open); + if (open.selfClosing) return; + + this.indent(); + _.each(node.children, function (child) { + if (child.type === "Literal" && typeof child.value === "string") { + if (/\S/.test(child.value)) { + return self.push(child.value.replace(/^\s+|\s+$/g, "")); + } else if (/\n/.test(child.value)) { + return self.newline(); + } + } + + print(child); + }); + this.dedent(); + + print(node.closingElement); }; exports.XJSOpeningElement = function (node, print) { this.push("<"); print(node.name); - if (node.attributes.length < 0) { + if (node.attributes.length > 0) { this.push(" "); this.printJoin(print, node.attributes, " "); } this.push(node.selfClosing ? " />" : ">");; }; -exports.XJSClosingElement = function (node) { - this.push(""); +exports.XJSClosingElement = function (node, print) { + this.push(""); }; exports.XJSEmptyExpression = function () {