Skip to content

Commit

Permalink
Merge pull request #144 from babel/use-eslint-plugin-regexp
Browse files Browse the repository at this point in the history
Use eslint-plugin-regexp
  • Loading branch information
jviereck authored Oct 1, 2024
2 parents 668eca6 + b0201ff commit ccc838b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import globals from "globals";
import js from "@eslint/js";
import * as regexpPlugin from "eslint-plugin-regexp"

export default [
{
files: ["**/*.js", "**/*.mjs"],
},
js.configs.recommended,
regexpPlugin.configs["flat/recommended"],
{
languageOptions: {
globals: {
Expand Down Expand Up @@ -34,6 +36,7 @@ export default [
"no-useless-escape": ["off"],
"no-empty": ["off"],
"no-unused-vars": ["error", { "caughtErrors": "none" }],
"regexp/use-ignore-case": ["off"],
},
},
];
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
"jsesc": "~3.0.2"
},
"devDependencies": {
"@unicode/unicode-16.0.0": "^1.6.0",
"eslint": "^9.10.0",
"eslint-plugin-regexp": "^2.6.0",
"globals": "^15.9.0",
"npm-run-all": "^4.1.5",
"regenerate": "~1.0.1",
"typescript": "^4.5.2",
"@unicode/unicode-16.0.0": "^1.6.0"
"typescript": "^4.5.2"
}
}
16 changes: 8 additions & 8 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@
// If no unicode flag, then try to parse ExtendedAtom -> ExtendedPatternCharacter.
// ExtendedPatternCharacter
var res;
if (!isUnicodeMode && (res = matchReg(/^{/))) {
if (!isUnicodeMode && (res = matchReg(/^\{/))) {
atom = createCharacter(res);
} else {
bail('Expected atom');
Expand Down Expand Up @@ -704,15 +704,15 @@
else if (match('?')) {
quantifier = createQuantifier(0, 1, undefined, undefined, "?");
}
else if (res = matchReg(/^\{([0-9]+)\}/)) {
else if (res = matchReg(/^\{(\d+)\}/)) {
min = parseInt(res[1], 10);
quantifier = createQuantifier(min, min, res.range[0], res.range[1]);
}
else if (res = matchReg(/^\{([0-9]+),\}/)) {
else if (res = matchReg(/^\{(\d+),\}/)) {
min = parseInt(res[1], 10);
quantifier = createQuantifier(min, undefined, res.range[0], res.range[1]);
}
else if (res = matchReg(/^\{([0-9]+),([0-9]+)\}/)) {
else if (res = matchReg(/^\{(\d+),(\d+)\}/)) {
min = parseInt(res[1], 10);
max = parseInt(res[2], 10);
if (min > max) {
Expand Down Expand Up @@ -762,7 +762,7 @@
// PatternCharacter
return createCharacter(res);
}
else if (!isUnicodeMode && (res = matchReg(/^(?:]|})/))) {
else if (!isUnicodeMode && (res = matchReg(/^(?:\]|\})/))) {
// ExtendedPatternCharacter, first part. See parseTerm.
return createCharacter(res);
}
Expand Down Expand Up @@ -906,7 +906,7 @@
return createEscaped('singleEscape', 0x0008, '\\b');
} else if (match('B')) {
bail('\\B not possible inside of CharacterClass', '', from);
} else if (!isUnicodeMode && (res = matchReg(/^c([0-9])/))) {
} else if (!isUnicodeMode && (res = matchReg(/^c(\d)/))) {
// B.1.4
// c ClassControlLetter, ClassControlLetter = DecimalDigit
return createEscaped('controlLetter', res[1] + 16, res[1], 2);
Expand Down Expand Up @@ -1010,7 +1010,7 @@
var res;
if (res = matchReg(/^[dDsSwW]/)) {
return createCharacterClassEscape(res[0]);
} else if (features.unicodePropertyEscape && isUnicodeMode && (res = matchReg(/^([pP])\{([^\}]+)\}/))) {
} else if (features.unicodePropertyEscape && isUnicodeMode && (res = matchReg(/^([pP])\{([^}]+)\}/))) {
// https://github.com/jviereck/regjsparser/issues/77
return addRaw({
type: 'unicodePropertyEscape',
Expand Down Expand Up @@ -1184,7 +1184,7 @@
var tmp;
var l = lookahead();
if (
(isUnicodeMode && /[\^\$\.\*\+\?\(\)\\\[\]\{\}\|\/]/.test(l)) ||
(isUnicodeMode && /[\^$.*+?()\\[\]{}|/]/.test(l)) ||
(!isUnicodeMode && l !== "c")
) {
if (l === "k" && features.lookbehind) {
Expand Down

0 comments on commit ccc838b

Please sign in to comment.