Fix #4686: if a CSX interpolation contains comments, not just inner CSX (JSX) tags, it needs to be wrapped in braces (#4689)

This commit is contained in:
Geoffrey Booth 2017-09-16 12:03:33 -07:00 committed by GitHub
parent 4c41831474
commit aecc115c79
3 changed files with 35 additions and 2 deletions

View File

@ -5010,7 +5010,9 @@
fragments.push(this.makeCode('$'));
}
code = element.compileToFragments(o, LEVEL_PAREN);
if (!this.isNestedTag(element)) {
if (!this.isNestedTag(element) || code.some(function(fragment) {
return fragment.comments != null;
})) {
code = this.wrapInBraces(code);
// Flag the `{` and `}` fragments as having been generated by this
// `StringWithInterpolations` node, so that `compileComments` knows

View File

@ -3403,7 +3403,7 @@ exports.StringWithInterpolations = class StringWithInterpolations extends Base
else
fragments.push @makeCode '$' unless @csx
code = element.compileToFragments(o, LEVEL_PAREN)
unless @isNestedTag element
if not @isNestedTag(element) or code.some((fragment) -> fragment.comments?)
code = @wrapInBraces code
# Flag the `{` and `}` fragments as having been generated by this
# `StringWithInterpolations` node, so that `compileComments` knows

View File

@ -711,3 +711,34 @@ test 'unspaced less than after CSX works but is not encouraged', ->
res = 2 < div;
'''
test '#4686: comments inside interpolations that also contain CSX tags', ->
eqJS '''
<div>
{
# comment
<div />
}
</div>
''', '''
<div>
{ // comment
<div />}
</div>;
'''
test '#4686: comments inside interpolations that also contain CSX attributes', ->
eqJS '''
<div>
<div anAttr={
# comment
"value"
} />
</div>
''', '''
<div>
{ // comment
<div anAttr={"value"} />}
</div>;
'''