Skip to content

Commit fe75548

Browse files
Fix jashkenas#5034: Adjacent JSX elements must be wrapped in an enclosing tag (jashkenas#5046)
1 parent 708e575 commit fe75548

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

lib/coffeescript/nodes.js

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@ exports.Block = class Block extends Base
482482
expr = @expressions[len]
483483
@expressions[len] = expr.makeReturn res
484484
@expressions.splice(len, 1) if expr instanceof Return and not expr.expression
485+
# We also need to check that we’re not returning a CSX tag if there’s an
486+
# adjacent one at the same level; JSX doesn’t allow that.
487+
if expr.unwrapAll().csx
488+
for csxCheckIndex in [len..0]
489+
if @expressions[csxCheckIndex].unwrapAll().csx
490+
expr.error 'Adjacent JSX elements must be wrapped in an enclosing tag'
485491
break
486492
this
487493

test/error_messages.coffee

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,27 @@ test 'CSX error: invalid attributes', ->
16621662
^^^^^^^^^^^^^^^^
16631663
'''
16641664

1665+
test '#5034: CSX error: Adjacent JSX elements must be wrapped in an enclosing tag', ->
1666+
assertErrorFormat '''
1667+
render = ->
1668+
<Row>a</Row>
1669+
<Row>b</Row>
1670+
''', '''
1671+
[stdin]:3:4: error: Adjacent JSX elements must be wrapped in an enclosing tag
1672+
<Row>b</Row>
1673+
^^^^^^^^^^^
1674+
'''
1675+
assertErrorFormat '''
1676+
render = -> (
1677+
<Row>a</Row>
1678+
<Row>b</Row>
1679+
)
1680+
''', '''
1681+
[stdin]:3:4: error: Adjacent JSX elements must be wrapped in an enclosing tag
1682+
<Row>b</Row>
1683+
^^^^^^^^^^^
1684+
'''
1685+
16651686
test 'Bound method called as callback before binding throws runtime error', ->
16661687
class Base
16671688
constructor: ->
@@ -1840,4 +1861,4 @@ test "#3933: prevent implicit calls when cotrol flow is missing `THEN`", ->
18401861
[stdin]:2:10: error: unexpected ->
18411862
when a ->
18421863
^^
1843-
'''
1864+
'''

0 commit comments

Comments
 (0)