-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix #5046: Adjacent JSX #5049
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 #5046: Adjacent JSX #5049
Changes from all commits
ba01407
09465f7
e33f032
89405a1
22cd4e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1664,25 +1664,26 @@ test 'CSX error: invalid attributes', -> | |
|
||
test '#5034: CSX error: Adjacent JSX elements must be wrapped in an enclosing tag', -> | ||
assertErrorFormat ''' | ||
render = -> | ||
render = -> ( | ||
<Row>a</Row> | ||
<Row>b</Row> | ||
) | ||
''', ''' | ||
[stdin]:3:4: error: Adjacent JSX elements must be wrapped in an enclosing tag | ||
<Row>b</Row> | ||
^^^^^^^^^^^ | ||
''' | ||
assertErrorFormat ''' | ||
render = -> ( | ||
a = "foo" | ||
<Row>a</Row> | ||
<Row>b</Row> | ||
) | ||
''', ''' | ||
[stdin]:3:4: error: Adjacent JSX elements must be wrapped in an enclosing tag | ||
[stdin]:4:4: error: Adjacent JSX elements must be wrapped in an enclosing tag | ||
<Row>b</Row> | ||
^^^^^^^^^^^ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zdenko We should also add a test for the non-error case: ->
<a />
<b /> That would be a good place to put a comment with a link to this PR, and an explanation for why this shouldn’t error. |
||
''' | ||
|
||
test 'Bound method called as callback before binding throws runtime error', -> | ||
class Base | ||
constructor: -> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should test that it errors out both with and without parens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the without-parens version is valid JSX:
I agree it’s likely a mistake on the user’s part, but catching “most of the time this is wrong” errors is the job of a linter, not the compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I talked about this a bit earlier.
You could say that, but you could also say that
really is
just like
is
instead of
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think you could say that parentheses are implied. JSX tags on subsequent lines aren’t assumed to be part of a unified construct the way an object is. They don’t compile into a single entity, for one thing, even with parentheses:
That’s not the way objects behave. The separate keys of an object are unified by virtue of being all part of the same block, as defined by indentation. Adjacent JSX tags are just that, adjacent JSX tags, unless they’re enclosed by a parent tag or fragment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I also want to point out that this:
Could very well apply to the original warning. Babel could compile it to two createElement doing nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could, but the JSX spec tells it not to. I think that's the distinction.