mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Improve tests and comments
This commit is contained in:
@@ -2274,8 +2274,8 @@ exports.StringWithInterpolations = class StringWithInterpolations extends Parens
|
||||
fragments.push @makeCode '`'
|
||||
for element in elements
|
||||
if element instanceof StringLiteral
|
||||
value = element.value.slice(1, -1)
|
||||
# Backticks or `${` inside template literals must be escaped
|
||||
value = element.value[1...-1]
|
||||
# Backticks and `${` inside template literals must be escaped.
|
||||
value = value.replace /(\\*)(`|\$\{)/g, (match, backslashes, toBeEscaped) ->
|
||||
if backslashes.length % 2 is 0
|
||||
"#{backslashes}\\#{toBeEscaped}"
|
||||
|
||||
@@ -146,7 +146,7 @@ test "tagged template literal with escaped backticks", ->
|
||||
eq 'text: [ES template literals look like this: \\`foo bar\\`] expressions: []',
|
||||
func"ES template literals look like this: \\`foo bar\\`"
|
||||
|
||||
test "tagged template literal with invalidly escaped backticks", ->
|
||||
test "tagged template literal with unnecessarily escaped backticks", ->
|
||||
eq 'text: [ES template literals look like this: `foo bar`] expressions: []',
|
||||
func"ES template literals look like this: \`foo bar\`"
|
||||
|
||||
@@ -162,7 +162,10 @@ test "tagged template literal with escaped ES interpolation", ->
|
||||
eq 'text: [ES template literals also look like this: `3 + 5 = \\${3+5}`] expressions: []',
|
||||
func"ES template literals also look like this: `3 + 5 = \\${3+5}`"
|
||||
|
||||
test "tagged template literal with invalidly escaped ES interpolation", ->
|
||||
eq 'text: [ES template literals also look like this: `3 + 5 = \${3+5}`] expressions: []',
|
||||
test "tagged template literal with unnecessarily escaped ES interpolation", ->
|
||||
eq 'text: [ES template literals also look like this: `3 + 5 = ${3+5}`] expressions: []',
|
||||
func"ES template literals also look like this: `3 + 5 = \${3+5}`"
|
||||
|
||||
test "tagged template literal special escaping", ->
|
||||
eq 'text: [` ` \\` \\` \\\\` $ { ${ ${ \\${ \\${ \\\\${ | ` ${] expressions: [1]',
|
||||
func"` \` \\` \\\` \\\\` $ { ${ \${ \\${ \\\${ \\\\${ #{1} ` ${"
|
||||
|
||||
Reference in New Issue
Block a user