Implement `esccharopen`: Dangling backslash
MODIFY
packages/@romejs/diagnostics/descriptions.ts
packages/@romejs/diagnostics/descriptions.ts
@@ -863,6 +863,7 @@ export const descriptions = createMessages({
INVALID_INT_TOKEN: 'Invalid or unexpected int token',
UNICODE_ESCAPE_IN_REGEX_FLAGS: 'Regular expression flags can\'t contain unicode escapes',
UNTERMINATED_REGEX: 'Unterminated regular expression',
+ DANGLING_BACKSLASH_IN_REGEX: 'Dangling backslash in a regular expression',
EXPECTED_RELATIONAL_OPERATOR: 'Expected relational operator',
UNEXPECTED_SPACE: 'Unexpected space',
EXPECTED_SEMI_OR_LINE_TERMINATOR: 'Expected a semicolon or a line terminator',

MODIFY
packages/@romejs/js-parser/tokenizer/index.ts
packages/@romejs/js-parser/tokenizer/index.ts
@@ -977,6 +977,16 @@ export function readRegexp(parser: JSParser): void {
const ch = parser.input.charAt(getIndex(parser));
if (lineBreak.test(ch)) {
+ if(parser.input.charAt(getIndex(parser) - 2) === String.fromCharCode(charCodes.backslash)
+ || parser.input.charAt(getIndex(parser) - 3) === String.fromCharCode(charCodes.backslash)) {
+ const line = parser.input.slice(0, getIndex(parser));
+ const backslashIndex = line.lastIndexOf(String.fromCharCode(charCodes.backslash));
+ parser.addDiagnostic({
+ end: parser.getPositionFromIndex(coerce0(backslashIndex)),
+ description: descriptions.JS_PARSER.DANGLING_BACKSLASH_IN_REGEX,
+ });
+ break;
+ }
parser.addDiagnostic({
end: parser.getPositionFromIndex(parser.state.index),
description: descriptions.JS_PARSER.UNTERMINATED_REGEX,

Implement `esccharopen`: Dangling backslash