escodegen
escodegen copied to clipboard
smarter rendering of array elements across lines
get rewritten into
[
1,
2
]
which is not what one would expect rewriting the code. That's a small, innocent literal array. And yet I see no way to make escodegen
output such lists as [1, 2]
. Could you add it as a default behaviour and an option, please?
Yes, this can be done by determining the formatting based on the size/content of the generated source text for each element. Should be pretty easy. PRs welcome.
+1
In the ArrayExpression case,
changing from
multiline = expr.elements.length > 1;
to
multiline = expr.elements.length > 10 && expr.elements[0].type !== Syntax.Literal;
should make literals a bit prettier. Literal arrays are much more likely to be homogeneous than arrays of reference types; if the first element is a literal, the rest are likely to follow. The 10
is completely arbitrary though; could be an option.
This is quite minor though. Should I open a PR?
+1 I need this fix. Has it not been merged yet? I am using 1.8.1 and I am getting the line breaks.