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

Fix issue #260: smarter rendering of array elements across lines #288

Closed
wants to merge 1 commit into from
Closed

Conversation

dnkolegov
Copy link

The fix is based on discussion and suggestion in #260.

@@ -2056,7 +2056,7 @@
if (!expr.elements.length) {
return '[]';
}
multiline = isPattern ? false : expr.elements.length > 1;
multiline = isPattern ? false : expr.elements.length > 10 && expr.elements[0].type !== Syntax.Literal;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!isPattern && expr.elements.length > 10 && expr.elements[0].type !== Syntax.Literal

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean this?

multiline = isPattern ? false : !isPattern && expr.elements.length > 10 && expr.elements[0].type !== Syntax.Literal;

isPattern in this is false and !isPattern is true.

@michaelficarra
Copy link
Member

I don't like this approach. It is a rough approximation which may be very incorrect for certain inputs. The solution I suggested in #260 would actually solve this. 👎

@dnkolegov
Copy link
Author

Hi @michaelficarra. Thanks for suggestion.

this can be done by determining the formatting based on the size/content of the generated source text for each element

Could you make clear what do you mean here? What content should be outputted across lines except Literal elements? And how I can determine size of source?

What about the following:

multiline = isPattern ? false : expr.elements.length > 10 && expr.elements[0].type !== Syntax.Literal && expr.elements[expr.elements.length - 1].type !== Syntax.Literal;

@michaelficarra
Copy link
Member

@dnkolegov The suggestion I had was to split across lines based on the length of the result of calling generateExpression on the array elements. Closing this, as it's not making a decision based on a useful characteristic of the array.

@michaelficarra
Copy link
Member

@healzer Feel free to implement it and send a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants