Fix: JSXText node trims whitespace too often #328
Merged
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.
Closes #325 , see that issue for motivation details
I continued to uphold the request in #221 to not generate 'extra' 'jsx_text' nodes, this is not what babel or acorn do so I feel a bit iffy about this.
but completely-whitespace lines are nodes that are stripped by react's jsx_text emitter, so I think it could be OK for there to not be a syntax node here.
(See discussion facebook/react#480 (comment))
I also updated some tests, ie
<Bar> <Foo /> </Bar>
is meant to generate
So it makes sense that two jsx_text nodes are generated.
Side note: i got rid of the right branch of the
choice
that said/\/\/[^\n]*/
which seemed to be trying to address would-be-comments. This is not effective ieshould treat
// hi
as a jsx_node, but it does not before or after PR (its an ERROR), this seems to be a separate issueContinues to work before and after this PR, but the inner jsx_text node spans 2 lines instead of one. I think this is preferred for tooling to consume because the emitted javascript includes trailing spaces after
hi
iff theres no newline before the</div>
(See discussion facebook/react#480 (comment))