Created
February 18, 2016 09:13
-
-
Save RSO/f484cd8935c2adaacb0f to your computer and use it in GitHub Desktop.
Ugly hacking in Recast printer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case "JSXElement": | |
var openingLines = path.call(print, "openingElement"); | |
if (n.openingElement.selfClosing) { | |
assert.ok(!n.closingElement); | |
return openingLines; | |
} | |
var childs = []; | |
var childs2 = []; | |
path.each(function(childPath, index) { | |
var child = childPath.getValue(); | |
if (namedTypes.Literal.check(child) && | |
typeof child.value === "string") { | |
if (child.value === " ") { | |
childs[index] = "{' '}"; | |
} else { | |
childs[index] = child.value.replace(/(^[ ]|[ ]$)/g, "{' '}"); | |
} | |
} else { | |
childs[index] = print(childPath); | |
} | |
}, "children"); | |
childs.forEach(function(child, index) { | |
var previous = index > 0 && childs[index - 1]; | |
if (child instanceof linesModule.Lines && previous && previous instanceof linesModule.Lines) { | |
childs2.push("\n"); | |
} | |
childs2.push(child); | |
}); | |
var childLines = concat(childs2).indent(options.tabWidth); | |
var closingLines = path.call(print, "closingElement"); | |
return concat([ | |
openingLines, | |
"\n", | |
childLines, | |
"\n", | |
closingLines | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment