escodegen icon indicating copy to clipboard operation
escodegen copied to clipboard

smarter rendering of array elements across lines

Open reverofevil opened this issue 8 years ago • 3 comments

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?

reverofevil avatar Sep 30 '15 19:09 reverofevil

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.

michaelficarra avatar Sep 30 '15 19:09 michaelficarra

+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?

deviousasti avatar Oct 22 '15 08:10 deviousasti

+1 I need this fix. Has it not been merged yet? I am using 1.8.1 and I am getting the line breaks.

amahfouz avatar Oct 09 '16 05:10 amahfouz