Skip to content

Commit 887a617

Browse files
Handle triple-quoted JSX attribute values (#5353)
Co-authored-by: Geoffrey Booth <[email protected]>
1 parent ed6733d commit 887a617

File tree

9 files changed

+57
-13
lines changed

9 files changed

+57
-13
lines changed

docs/v2/annotated-source/nodes.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,7 +3414,7 @@ <h3 id="jsx">JSX</h3>
34143414
@value =
34153415
<span class="hljs-keyword">if</span> value?
34163416
value = value.base
3417-
<span class="hljs-keyword">if</span> value <span class="hljs-keyword">instanceof</span> StringLiteral
3417+
<span class="hljs-keyword">if</span> value <span class="hljs-keyword">instanceof</span> StringLiteral <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> value.shouldGenerateTemplateLiteral()
34183418
value
34193419
<span class="hljs-keyword">else</span>
34203420
<span class="hljs-keyword">new</span> JSXExpressionContainer value
@@ -9327,13 +9327,13 @@ <h3 id="stringwithinterpolations">StringWithInterpolations</h3>
93279327

93289328
<div class="content"><div class='highlight'><pre>
93299329
<span class="hljs-built_in">exports</span>.StringWithInterpolations = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">StringWithInterpolations</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
9330-
constructor: <span class="hljs-function"><span class="hljs-params">(@body, {@quote, @startQuote} = {})</span> -&gt;</span>
9330+
constructor: <span class="hljs-function"><span class="hljs-params">(@body, {@quote, @startQuote, @jsxAttribute} = {})</span> -&gt;</span>
93319331
super()
93329332

93339333
@fromStringLiteral: <span class="hljs-function"><span class="hljs-params">(stringLiteral)</span> -&gt;</span>
93349334
updatedString = stringLiteral.withoutQuotesInLocationData()
93359335
updatedStringValue = <span class="hljs-keyword">new</span> Value(updatedString).withLocationDataFrom updatedString
9336-
<span class="hljs-keyword">new</span> StringWithInterpolations Block.wrap([updatedStringValue]), quote: stringLiteral.quote
9336+
<span class="hljs-keyword">new</span> StringWithInterpolations Block.wrap([updatedStringValue]), quote: stringLiteral.quote, jsxAttribute: stringLiteral.jsxAttribute
93379337
.withLocationDataFrom stringLiteral
93389338

93399339
children: [<span class="hljs-string">&#x27;body&#x27;</span>]</pre></div></div>

docs/v2/browser-compiler-legacy/coffeescript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/v2/browser-compiler-modern/coffeescript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/v2/test.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27004,6 +27004,27 @@ <h2>Another heading</h2>
2700427004
});
2700527005
'''
2700627006

27007+
test '#5352: triple-quoted non-interpolated attribute values', ->
27008+
eqJS '''
27009+
<div a="""
27010+
b
27011+
c
27012+
""" />
27013+
''', '''
27014+
<div a={`b
27015+
c`} />;
27016+
'''
27017+
27018+
eqJS """
27019+
<div a='''
27020+
b
27021+
c
27022+
''' />
27023+
""", '''
27024+
<div a={`b
27025+
c`} />;
27026+
'''
27027+
2700727028
</script>
2700827029
<script type="text/x-literate-coffeescript" class="test" id="literate">
2700927030
# Literate CoffeeScript Test

lib/coffeescript-browser-compiler-legacy/coffeescript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffeescript-browser-compiler-modern/coffeescript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffeescript/nodes.js

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ exports.JSXAttribute = class JSXAttribute extends Base
17121712
@value =
17131713
if value?
17141714
value = value.base
1715-
if value instanceof StringLiteral
1715+
if value instanceof StringLiteral and not value.shouldGenerateTemplateLiteral()
17161716
value
17171717
else
17181718
new JSXExpressionContainer value
@@ -5150,13 +5150,13 @@ exports.Parens = class Parens extends Base
51505150
#### StringWithInterpolations
51515151

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

51565156
@fromStringLiteral: (stringLiteral) ->
51575157
updatedString = stringLiteral.withoutQuotesInLocationData()
51585158
updatedStringValue = new Value(updatedString).withLocationDataFrom updatedString
5159-
new StringWithInterpolations Block.wrap([updatedStringValue]), quote: stringLiteral.quote
5159+
new StringWithInterpolations Block.wrap([updatedStringValue]), quote: stringLiteral.quote, jsxAttribute: stringLiteral.jsxAttribute
51605160
.withLocationDataFrom stringLiteral
51615161

51625162
children: ['body']

test/jsx.coffee

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,3 +946,24 @@ test '“Adjacent” tags on separate lines should still compile', ->
946946
return <b />;
947947
});
948948
'''
949+
950+
test '#5352: triple-quoted non-interpolated attribute values', ->
951+
eqJS '''
952+
<div a="""
953+
b
954+
c
955+
""" />
956+
''', '''
957+
<div a={`b
958+
c`} />;
959+
'''
960+
961+
eqJS """
962+
<div a='''
963+
b
964+
c
965+
''' />
966+
""", '''
967+
<div a={`b
968+
c`} />;
969+
'''

0 commit comments

Comments
 (0)