This commit is contained in:
parent
708e57586c
commit
fe7554828a
|
@ -671,7 +671,7 @@
|
|||
// A Block node does not return its entire body, rather it
|
||||
// ensures that the final expression is returned.
|
||||
makeReturn(res) {
|
||||
var expr, len;
|
||||
var csxCheckIndex, expr, j, len, ref1;
|
||||
len = this.expressions.length;
|
||||
while (len--) {
|
||||
expr = this.expressions[len];
|
||||
|
@ -679,6 +679,15 @@
|
|||
if (expr instanceof Return && !expr.expression) {
|
||||
this.expressions.splice(len, 1);
|
||||
}
|
||||
// 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 = j = ref1 = len; (ref1 <= 0 ? j <= 0 : j >= 0); csxCheckIndex = ref1 <= 0 ? ++j : --j) {
|
||||
if (this.expressions[csxCheckIndex].unwrapAll().csx) {
|
||||
expr.error('Adjacent JSX elements must be wrapped in an enclosing tag');
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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: ->
|
||||
|
@ -1840,4 +1861,4 @@ test "#3933: prevent implicit calls when cotrol flow is missing `THEN`", ->
|
|||
[stdin]:2:10: error: unexpected ->
|
||||
when a ->
|
||||
^^
|
||||
'''
|
||||
'''
|
||||
|
|
Loading…
Reference in New Issue