make underline point at first problematic flag instead of regex beginning
MODIFY
packages/@romejs/js-parser-utils/regex.ts
packages/@romejs/js-parser-utils/regex.ts
@@ -12,21 +12,21 @@ const VALID_REGEX_FLAGS: Array<string> = 'gmsiyu'.split('');
// This is used by both rome-json and rome-js-parser to validate regex flags
export function validateRegexFlags(
flags: string,
- onUnexpected: (message: string, index: number) => void,
+ parserIndex: number,
+ onUnexpected: (message: string, index: number, parserIndex: number) => void,
): Set<string> {
const foundFlags: Set<string> = new Set();
-
for (let i = 0; i < flags.length; i++) {
const flag = flags[i];
if (VALID_REGEX_FLAGS.includes(flag)) {
if (foundFlags.has(flag)) {
- onUnexpected(messages.DUPLICATE_REGEX_FLAG(), i);
+ onUnexpected(messages.DUPLICATE_REGEX_FLAG(), i, parserIndex);
} else {
foundFlags.add(flag);
}
} else {
- onUnexpected(messages.INVALID_REGEX_FLAG(), i);
+ onUnexpected(messages.INVALID_REGEX_FLAG(), i, parserIndex);
}
}

MODIFY
packages/@romejs/js-parser/tokenizer/index.ts
packages/@romejs/js-parser/tokenizer/index.ts
@@ -1024,17 +1024,19 @@ export function readRegexp(parser: JSParser): void {
bumpIndex(parser);
const rawMods = readWord1(parser);
-
if (parser.state.escapePosition !== undefined) {
parser.addDiagnostic({
index: parser.state.escapePosition,
message: 'Regular expression flags can\'t contain unicode escapes',
});
}
-
- const mods = validateRegexFlags(rawMods, (msg, index) => {
+ const mods = validateRegexFlags(rawMods, getIndex(parser), (
+ msg,
+ flagPosition,
+ parserIndex,
+ ) => {
parser.addDiagnostic({
- index: add(start, index),
+ index: add(parserIndex - rawMods.length, flagPosition),
message: msg,
});
});

MODIFY
packages/@romejs/ob1/index.ts
packages/@romejs/ob1/index.ts
@@ -29,6 +29,7 @@ export function add(a: number, b: Number0): Number0;
export function add(a: Number1, b: Number0): Number1;
export function add(a: Number0, b: Number1): Number1;
export function add(a: Number0, b: Number0): Number0;
+export function add(a: number, b: number): Number0;
export function add(a: number | AnyNumber, b: number | AnyNumber): AnyNumber {
// @ts-ignore
return a + b;

make underline point at first problematic flag instead of regex beginning