Improve tests and comments

This commit is contained in:
Geoffrey Booth
2016-12-03 10:16:41 -08:00
parent d8abfae457
commit d45d780869
2 changed files with 8 additions and 5 deletions

View File

@@ -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}"

View File

@@ -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} ` ${"