more reliable jsx literal whitespace

This commit is contained in:
Sebastian McKenzie
2014-11-11 15:34:29 +11:00
parent c5bfbf37f0
commit 35b28cf722
3 changed files with 16 additions and 9 deletions

View File

@@ -80,10 +80,17 @@ exports.XJSElement = {
var callExpr = node.openingElement;
var children = node.children;
_.each(children, function (child) {
if (t.isLiteral(child) && _.isString(child.value)) {
child.value = child.value.trim().replace(/\n(\s+)/g, " ");
if (!child.value) return;
_.each(children, function (child, i) {
var val = child.value;
if (t.isLiteral(child) && _.isString(val)) {
val = val.replace(/\n(\s+)/g, " ");
i = +i;
if (i === 0) val = val.trimLeft();
if (i === children.length - 1) val = val.trimRight();
if (!val) return;
child.value = val;
}
callExpr.arguments.push(child);

View File

@@ -3,5 +3,5 @@
X({
"data-prop": x ? Y({
prop: 2
}) : Z(null, "\n")
}) : Z(null)
});

View File

@@ -1,9 +1,9 @@
"use strict";
(X(null, " "));
(X(null));
(X(null, "\n"));
(X(null));
(X(null, "\n string\n"));
(X(null, "string"));
(X(null, "\n string\n string\n "));
(X(null, "string string"));