Closed yllhwa closed 6 months ago
Note that backslash characters in template literals create escape sequences, so the code
in your example is not what it looks like:
var code = `let pattern = /(\/x\/[\w-_]+\/)/;`;
console.log(code);
// prints "let pattern = /(/x/[w-_]+/)/";
To get the text as it appears inside backticks, you could use String.raw
:
var code = String.raw`let pattern = /(\/x\/[\w-_]+\/)/;`;
Or insert a double backslash (\\
) where there should be one:
var code = `let pattern = /(\\/x\\/[\\w-_]+\\/)/;`;
Thanks a lot. I just made such a silly mistake. Esprima cannot parse this, so I want to try espree. And it works!
reproduction code:
the regular expression looks fine(since I can run the code below)
but an error occurred:
version: 9.6.1