Skip to content

Commit

Permalink
chore: use characterNode.raw instead of characterNode.value
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash-Singh1 committed Dec 3, 2021
1 parent 8d96676 commit 0c7e362
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rules/prefer-regex-literals.js
Expand Up @@ -265,18 +265,23 @@ module.exports = {
function resolveEscapes(character) {
switch (character) {
case "\n":
case "\\\n":
return "\\n";

case "\r":
case "\\\r":
return "\\r";

case "\t":
case "\\\t":
return "\\t";

case "\v":
case "\\\v":
return "\\v";

case "\f":
case "\\\f":
return "\\f";

case "/":
Expand Down Expand Up @@ -345,7 +350,7 @@ module.exports = {
onCharacterEnter(characterNode) {
let changeCharIncrease = 0;
let stringCodePointValue = String.fromCodePoint(characterNode.value);
const escaped = resolveEscapes(stringCodePointValue);
const escaped = resolveEscapes(characterNode.raw);

if (escaped) {
stringCodePointValue = escaped;
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules/prefer-regex-literals.js
Expand Up @@ -2324,6 +2324,20 @@ ruleTester.run("prefer-regex-literals", rule, {
]
}
]
},
{
code: "new RegExp(\"\\u000A\\u000A\");",
errors: [
{
messageId: "unexpectedRegExp",
suggestions: [
{
messageId: "unexpectedRegExp",
output: "/\\n\\n/"
}
]
}
]
}
]
});

0 comments on commit 0c7e362

Please sign in to comment.