Skip to content

Commit

Permalink
Fix #4686: if a CSX interpolation contains comments, not just inner C…
Browse files Browse the repository at this point in the history
…SX (JSX) tags, it needs to be wrapped in braces (#4689)
  • Loading branch information
GeoffreyBooth committed Sep 16, 2017
1 parent 4c41831 commit aecc115
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/coffeescript/nodes.js

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

2 changes: 1 addition & 1 deletion src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions test/csx.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
'''

0 comments on commit aecc115

Please sign in to comment.