finish jsx generator

This commit is contained in:
Sebastian McKenzie 2014-11-01 19:28:42 +11:00
parent 6e41309ede
commit 9475dc681f

View File

@ -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("</" + node.name + ">");
exports.XJSClosingElement = function (node, print) {
this.push("</");
print(node.name);
this.push(">");
};
exports.XJSEmptyExpression = function () {