fix: Improve contextual spacing for JSX expression containers when js… #726
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…xExpressionContainer.spaceSurroundingExpression: true
When jsxExpressionContainer.spaceSurroundingExpression is true, make sure the spaces around braces are right based on the context of where the brace lies.
The change is to only add the space if the open brace is not at the end of a line. We do that on the opening brace by adding a Signal::SpaceOrNewLine which allows the system to add the space if it needs to for purposes of word wrap, otherwise ommitting it. For the close brace, we add the space if we're not the first token on the line.
The impetus for this was the case where an opening brace within a JSX element was the last character on a line, or a closing brace was the first. For example:
The above case was getting formatted with extra spaces around the braces for the "inner" attribute.
This fixes this case and similar ones, plus adds additional varied test cases to cover variations of this idea.