You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add support for es2025 duplicate named capturing groups (#18630)
* feat: add support for es2025 to `no-useless-backreference`
* test: add test for es2025 to `no-invalid-regexp`
* update REGEXPP_LATEST_ECMA_VERSION to 2025
* change `no-useless-backreference` to handle disjunctive
* fix comment
Copy file name to clipboardExpand all lines: lib/rules/no-useless-backreference.js
+81-31Lines changed: 81 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -72,11 +72,11 @@ module.exports = {
72
72
schema: [],
73
73
74
74
messages: {
75
-
nested: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}' from within that group.",
76
-
forward: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}' which appears later in the pattern.",
77
-
backward: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}' which appears before in the same lookbehind.",
78
-
disjunctive: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}' which is in another alternative.",
79
-
intoNegativeLookaround: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}' which is in a negative lookaround."
75
+
nested: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}'{{ otherGroups }} from within that group.",
76
+
forward: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}'{{ otherGroups }} which appears later in the pattern.",
77
+
backward: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}'{{ otherGroups }} which appears before in the same lookbehind.",
78
+
disjunctive: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}'{{ otherGroups }} which is in another alternative.",
79
+
intoNegativeLookaround: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}'{{ otherGroups }} which is in a negative lookaround."
80
80
}
81
81
},
82
82
@@ -104,16 +104,21 @@ module.exports = {
104
104
105
105
visitRegExpAST(regExpAST,{
106
106
onBackreferenceEnter(bref){
107
-
constgroup=bref.resolved,
108
-
brefPath=getPathToRoot(bref),
109
-
groupPath=getPathToRoot(group);
110
-
letmessageId=null;
107
+
constgroups=[bref.resolved].flat(),
108
+
brefPath=getPathToRoot(bref);
111
109
112
-
if(brefPath.includes(group)){
110
+
constproblems=groups.map(group=>{
111
+
constgroupPath=getPathToRoot(group);
112
+
113
+
if(brefPath.includes(group)){
114
+
115
+
// group is bref's ancestor => bref is nested ('nested reference') => group hasn't matched yet when bref starts to match.
116
+
return{
117
+
messageId: "nested",
118
+
group
119
+
};
120
+
}
113
121
114
-
// group is bref's ancestor => bref is nested ('nested reference') => group hasn't matched yet when bref starts to match.
115
-
messageId="nested";
116
-
}else{
117
122
118
123
// Start from the root to find the lowest common ancestor.
0 commit comments