JSX attributes with unbraced indented values, code children with >
#1381
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.
This PR makes two major advances toward #561, in two commits:
1. JSX attributes with unbraces indented values
#561 discussed a few possibilities for a symbol to indicate that the value of an attribute should be an indented block. I realized that we don't need any symbol here; we can just have an indented block (outside
coffeeJSX
mode which maintains full JSX compatibility without respecting indentation). Example:This seems like a clear (uncontroversial) win. It matches our support for indented content in various contexts, most recently condition of an
if
(#1364).2. JSX child code blocks with
>
I implemented my proposal from #561 (comment) to allow for a JSX code child to be prefixed with
>
instead of wrapping it in braces.Examples where the content is on the same line as the
>
seem pretty straightforward and nice:I also added support for indented blocks, with an indentation after the
>
:These get wrapped automatically in
do
, which lets you do the multiple lines of code and local declarations (which are intuitively local given the indentation). This aspect is maybe a little more controversial. It's related to facebook/jsx#39 which we've discussed implementing but haven't: making all JSX braced blocks (probably including attribute values and code blocks) implicitly wrapped indo
. It's less necessary in Civet where most statements are expressions. But it's relevant exactly when you want to do multiple lines of code.Alternatively, I could remove the indented block feature, and we could spell this as follows:
On the other hand, maybe
>
is a nice place to introduce divergent behavior like this: a single-line expression (not wrapped indo
), or a multi-line block implicitly wrapped indo
. Arguably we should do the same for indented attribute blocks (Part 1 of this PR), if they want to be multiple lines as well?So potentially a bit of discussion before this should get merged. Let me know your thoughts in particular on whether indented
>
blocks and/or indented attribute values should be wrapped indo
. (Currently the former is, but the latter isn't.)And to be clear, this is also meant as a step toward a flag like
"civet jsxCode"
where the>
s aren't necessary, and instead content needs to be quoted like a string. That would complete #561.(Also deleted an old
jsx.md
file which seems to have been fully incorporated intoreference.md
long ago.)