mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
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:
parent
4c41831474
commit
aecc115c79
3 changed files with 35 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>;
|
||||
'''
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue