Skip to content

Commit

Permalink
Fix: Allow useless escapes in tagged template literals (fixes #7383) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark authored and gyandeeps committed Oct 17, 2016
1 parent 9106964 commit 7525042
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/rules/no-useless-escape.js
Expand Up @@ -132,6 +132,12 @@ module.exports = {
let nodeEscapes,
match;

if (isTemplateElement && node.parent && node.parent.parent && node.parent.parent.type === "TaggedTemplateExpression") {

// Don't report tagged template literals, because the backslash character is accessible to the tag function.
return;
}

if (typeof node.value === "string" || isTemplateElement) {

/*
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/rules/no-useless-escape.js
Expand Up @@ -75,7 +75,9 @@ ruleTester.run("no-useless-escape", rule, {
{code: "var foo = `\\\``", parserOptions: {ecmaVersion: 6}},
{code: "var foo = `\\\`${foo}\\\``", parserOptions: {ecmaVersion: 6}},
{code: "var foo = `\\${{${foo}`;", parserOptions: {ecmaVersion: 6}},
{code: "var foo = `$\\{{${foo}`;", parserOptions: {ecmaVersion: 6}}
{code: "var foo = `$\\{{${foo}`;", parserOptions: {ecmaVersion: 6}},
{code: "var foo = String.raw`\\.`", parserOptions: {ecmaVersion: 6}},
{code: "var foo = myFunc`\\.`", parserOptions: {ecmaVersion: 6}}
],

invalid: [
Expand Down

0 comments on commit 7525042

Please sign in to comment.