Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/coffeescript/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,12 @@ exports.Block = class Block extends Base
expr = @expressions[len]
@expressions[len] = expr.makeReturn res
@expressions.splice(len, 1) if expr instanceof Return and not expr.expression
# We also need to check that we’re not returning a CSX tag if there’s an
# adjacent one at the same level; JSX doesn’t allow that.
if expr.unwrapAll().csx
for csxCheckIndex in [len..0]
if @expressions[csxCheckIndex].unwrapAll().csx
expr.error 'Adjacent JSX elements must be wrapped in an enclosing tag'
break
this

Expand Down
23 changes: 22 additions & 1 deletion test/error_messages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,27 @@ test 'CSX error: invalid attributes', ->
^^^^^^^^^^^^^^^^
'''

test '#5034: CSX error: Adjacent JSX elements must be wrapped in an enclosing tag', ->
assertErrorFormat '''
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 = -> (
<Row>a</Row>
<Row>b</Row>
)
''', '''
[stdin]:3:4: error: Adjacent JSX elements must be wrapped in an enclosing tag
<Row>b</Row>
^^^^^^^^^^^
'''

test 'Bound method called as callback before binding throws runtime error', ->
class Base
constructor: ->
Expand Down Expand Up @@ -1840,4 +1861,4 @@ test "#3933: prevent implicit calls when cotrol flow is missing `THEN`", ->
[stdin]:2:10: error: unexpected ->
when a ->
^^
'''
'''