implement quantifier range check (autofix)
MODIFY
packages/@romejs/codec-js-regexp/index.ts
packages/@romejs/codec-js-regexp/index.ts
@@ -784,17 +784,35 @@ export const createRegExpParser = createParser(
this.nextToken();
+ const start = this.getPosition();
const min = this.parseDigits();
if (min !== undefined) {
const nextToken = this.getToken();
if (nextToken.type === 'Character' && nextToken.value === ',') {
this.nextToken();
+
const max = this.parseDigits();
+ const end = this.getPosition();
const endToken = this.getToken();
if (endToken.type === 'Operator' && endToken.value === '}') {
this.nextToken();
+
+ if (max !== undefined && min > max) {
+ this.addDiagnostic(
+ {
+ description: descriptions.REGEX_PARSER.REVERSED_QUANTIFIER_RANGE,
+ start,
+ end,
+ },
+ );
+ return {
+ max: min,
+ min: max,
+ };
+ }
+
return {
min,
max,

MODIFY
packages/@romejs/diagnostics/descriptions.ts
packages/@romejs/diagnostics/descriptions.ts
@@ -157,6 +157,7 @@ export const descriptions = createMessages(
UNCLOSED_CHAR_SET: 'Unclosed character set',
DUPLICATE_FLAG: 'Duplicate regular expression flag',
INVALID_FLAG: 'Invalid regular expression flag',
+ REVERSED_QUANTIFIER_RANGE: 'Quantifier minimum is greater than maximum',
NO_TARGET_QUANTIFIER: 'Nothing to repeat',
INVALID_NAMED_CAPTURE: 'Invalid named capture referenced',
UNCLOSED_NAMED_CAPTURE: 'Unclosed named capture',

implement quantifier range check (autofix)