Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smarter rendering of array elements across lines #260

Open
reverofevil opened this issue Sep 30, 2015 · 3 comments · May be fixed by #442
Open

smarter rendering of array elements across lines #260

reverofevil opened this issue Sep 30, 2015 · 3 comments · May be fixed by #442

Comments

@reverofevil
Copy link

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?

@michaelficarra michaelficarra changed the title [1, 2] smarter rendering of array elements across lines Sep 30, 2015
@michaelficarra
Copy link
Member

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.

@deviousasti
Copy link

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

@amahfouz
Copy link

amahfouz commented Oct 9, 2016

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

d-rk added a commit to d-rk/escodegen that referenced this issue Mar 16, 2021
@d-rk d-rk linked a pull request Mar 16, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants