Handle triple-quoted JSX attribute values (#5353)
Co-authored-by: Geoffrey Booth <webadmin@geoffreybooth.com>
This commit is contained in:
parent
ed6733d177
commit
887a6174e9
|
@ -3414,7 +3414,7 @@ a child <code>Value</code> node assigned to the <code>object</code> property.</p
|
|||
@value =
|
||||
<span class="hljs-keyword">if</span> value?
|
||||
value = value.base
|
||||
<span class="hljs-keyword">if</span> value <span class="hljs-keyword">instanceof</span> StringLiteral
|
||||
<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()
|
||||
value
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-keyword">new</span> JSXExpressionContainer value
|
||||
|
@ -9327,13 +9327,13 @@ by comment-based type annotations from JavaScript labels.</p>
|
|||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
<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>
|
||||
constructor: <span class="hljs-function"><span class="hljs-params">(@body, {@quote, @startQuote} = {})</span> -></span>
|
||||
constructor: <span class="hljs-function"><span class="hljs-params">(@body, {@quote, @startQuote, @jsxAttribute} = {})</span> -></span>
|
||||
super()
|
||||
|
||||
@fromStringLiteral: <span class="hljs-function"><span class="hljs-params">(stringLiteral)</span> -></span>
|
||||
updatedString = stringLiteral.withoutQuotesInLocationData()
|
||||
updatedStringValue = <span class="hljs-keyword">new</span> Value(updatedString).withLocationDataFrom updatedString
|
||||
<span class="hljs-keyword">new</span> StringWithInterpolations Block.wrap([updatedStringValue]), quote: stringLiteral.quote
|
||||
<span class="hljs-keyword">new</span> StringWithInterpolations Block.wrap([updatedStringValue]), quote: stringLiteral.quote, jsxAttribute: stringLiteral.jsxAttribute
|
||||
.withLocationDataFrom stringLiteral
|
||||
|
||||
children: [<span class="hljs-string">'body'</span>]</pre></div></div>
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -27004,6 +27004,27 @@ test '“Adjacent” tags on separate lines should still compile', ->
|
|||
});
|
||||
'''
|
||||
|
||||
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`} />;
|
||||
'''
|
||||
|
||||
</script>
|
||||
<script type="text/x-literate-coffeescript" class="test" id="literate">
|
||||
# Literate CoffeeScript Test
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -2545,7 +2545,7 @@
|
|||
var ref1;
|
||||
super();
|
||||
this.name = name1;
|
||||
this.value = value != null ? (value = value.base, value instanceof StringLiteral ? value : new JSXExpressionContainer(value)) : null;
|
||||
this.value = value != null ? (value = value.base, value instanceof StringLiteral && !value.shouldGenerateTemplateLiteral() ? value : new JSXExpressionContainer(value)) : null;
|
||||
if ((ref1 = this.value) != null) {
|
||||
ref1.comments = value.comments;
|
||||
}
|
||||
|
@ -7726,11 +7726,12 @@
|
|||
//### StringWithInterpolations
|
||||
exports.StringWithInterpolations = StringWithInterpolations = (function() {
|
||||
class StringWithInterpolations extends Base {
|
||||
constructor(body1, {quote, startQuote} = {}) {
|
||||
constructor(body1, {quote, startQuote, jsxAttribute} = {}) {
|
||||
super();
|
||||
this.body = body1;
|
||||
this.quote = quote;
|
||||
this.startQuote = startQuote;
|
||||
this.jsxAttribute = jsxAttribute;
|
||||
}
|
||||
|
||||
static fromStringLiteral(stringLiteral) {
|
||||
|
@ -7738,7 +7739,8 @@
|
|||
updatedString = stringLiteral.withoutQuotesInLocationData();
|
||||
updatedStringValue = new Value(updatedString).withLocationDataFrom(updatedString);
|
||||
return new StringWithInterpolations(Block.wrap([updatedStringValue]), {
|
||||
quote: stringLiteral.quote
|
||||
quote: stringLiteral.quote,
|
||||
jsxAttribute: stringLiteral.jsxAttribute
|
||||
}).withLocationDataFrom(stringLiteral);
|
||||
}
|
||||
|
||||
|
|
|
@ -1712,7 +1712,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
|
||||
|
@ -5150,13 +5150,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']
|
||||
|
|
|
@ -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`} />;
|
||||
'''
|
||||
|
|
Loading…
Reference in New Issue