Skip to content

Commit

Permalink
chore: more changes following code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash-Singh1 committed Dec 11, 2021
1 parent b4355d1 commit e292a77
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/rules/prefer-regex-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const { canTokensBeAdjacent } = require("./utils/ast-utils");
// Helpers
//------------------------------------------------------------------------------

const REGEXPP_LATEST_ECMA_VERSION = 2022;

/**
* Determines whether the given node is a string literal.
* @param {ASTNode} node Node to check.
Expand Down Expand Up @@ -342,19 +344,17 @@ module.exports = {
if (sourceCode.getCommentsInside(node).length > 0) {
noFix = true;
}

if (regexContent && !noFix) {
let charIncrease = 0;

const ast = new RegExpParser({ ecmaVersion: regexppEcmaVersion }).parsePattern(regexContent, 0, regexContent.length, flags ? flags.includes("u") : false);

visitRegExpAST(ast, {
onCharacterEnter(characterNode) {
let stringCodePointValue = String.fromCodePoint(characterNode.value);
const escaped = resolveEscapes(characterNode.raw);

if (escaped) {
stringCodePointValue = escaped;
regexContent =
regexContent.slice(0, characterNode.start + charIncrease) +
escaped +
Expand Down

0 comments on commit e292a77

Please sign in to comment.