Skip to content

Commit

Permalink
handle triple-quoted JSX attribute values
Browse files Browse the repository at this point in the history
  • Loading branch information
helixbass committed Apr 22, 2021
1 parent 07f644c commit 74c75d2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/coffeescript/nodes.js

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

6 changes: 3 additions & 3 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,7 @@ exports.JSXAttribute = class JSXAttribute extends Base
@value =
if value?
value = value.base
if value instanceof StringLiteral
if value instanceof StringLiteral and not value.shouldGenerateTemplateLiteral()
value
else
new JSXExpressionContainer value
Expand Down Expand Up @@ -5146,13 +5146,13 @@ exports.Parens = class Parens extends Base
#### StringWithInterpolations

exports.StringWithInterpolations = class StringWithInterpolations extends Base
constructor: (@body, {@quote, @startQuote} = {}) ->
constructor: (@body, {@quote, @startQuote, @jsxAttribute} = {}) ->
super()

@fromStringLiteral: (stringLiteral) ->
updatedString = stringLiteral.withoutQuotesInLocationData()
updatedStringValue = new Value(updatedString).withLocationDataFrom updatedString
new StringWithInterpolations Block.wrap([updatedStringValue]), quote: stringLiteral.quote
new StringWithInterpolations Block.wrap([updatedStringValue]), quote: stringLiteral.quote, jsxAttribute: stringLiteral.jsxAttribute
.withLocationDataFrom stringLiteral

children: ['body']
Expand Down
21 changes: 21 additions & 0 deletions test/jsx.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,24 @@ test '“Adjacent” tags on separate lines should still compile', ->
return <b />;
});
'''

test '#5352: triple-quoted non-interpolated attribute values', ->
eqJS '''
<div a="""
b
c
""" />
''', '''
<div a={`b
c`} />;
'''

eqJS """
<div a='''
b
c
''' />
""", '''
<div a={`b
c`} />;
'''

0 comments on commit 74c75d2

Please sign in to comment.