@@ -84,18 +84,18 @@ export class GroupSpecifiersAsES2018 implements GroupSpecifiers {
84
84
}
85
85
86
86
export class GroupSpecifiersAsES2025 implements GroupSpecifiers {
87
- private groupNamesInDisjunction = new Set < string > ( )
88
- private groupNamesInDisjunctionStack : Set < string > [ ] = [ ]
89
- private groupNamesInAlternative = new Set < string > ( )
90
- private groupNamesInAlternativeStack : Set < string > [ ] = [ ]
87
+ private groupNamesAddedInDisjunction = new Set < string > ( )
88
+ private groupNamesAddedInUpperDisjunctionStack : Set < string > [ ] = [ ]
89
+ private groupNamesInScope = new Set < string > ( )
90
+ private groupNamesInUpperScopeStack : Set < string > [ ] = [ ]
91
91
92
92
private groupNamesInPattern = new Set < string > ( )
93
93
94
94
public clear ( ) : void {
95
- this . groupNamesInDisjunction . clear ( )
96
- this . groupNamesInDisjunctionStack . length = 0
97
- this . groupNamesInAlternative . clear ( )
98
- this . groupNamesInAlternativeStack . length = 0
95
+ this . groupNamesAddedInDisjunction . clear ( )
96
+ this . groupNamesAddedInUpperDisjunctionStack . length = 0
97
+ this . groupNamesInScope . clear ( )
98
+ this . groupNamesInUpperScopeStack . length = 0
99
99
this . groupNamesInPattern . clear ( )
100
100
}
101
101
@@ -104,25 +104,31 @@ export class GroupSpecifiersAsES2025 implements GroupSpecifiers {
104
104
}
105
105
106
106
public enterDisjunction ( ) : void {
107
- this . groupNamesInDisjunctionStack . push ( this . groupNamesInDisjunction )
108
- this . groupNamesInDisjunction = new Set ( )
107
+ this . groupNamesAddedInUpperDisjunctionStack . push (
108
+ this . groupNamesAddedInDisjunction ,
109
+ )
110
+ // Clear groupNamesAddedInDisjunction to store the groupName added in this Disjunction.
111
+ this . groupNamesAddedInDisjunction = new Set ( )
109
112
}
110
113
111
114
public enterAlternative ( ) : void {
112
- this . groupNamesInAlternativeStack . push ( this . groupNamesInAlternative )
113
- this . groupNamesInAlternative = new Set ( this . groupNamesInAlternative )
115
+ this . groupNamesInUpperScopeStack . push ( this . groupNamesInScope )
116
+ this . groupNamesInScope = new Set ( this . groupNamesInScope )
114
117
}
115
118
116
119
public leaveAlternative ( ) : void {
117
- this . groupNamesInAlternative = this . groupNamesInAlternativeStack . pop ( ) !
120
+ this . groupNamesInScope = this . groupNamesInUpperScopeStack . pop ( ) !
118
121
}
119
122
120
123
public leaveDisjunction ( ) : void {
121
- const child = this . groupNamesInDisjunction
122
- this . groupNamesInDisjunction = this . groupNamesInDisjunctionStack . pop ( ) !
123
- for ( const groupName of child ) {
124
- this . groupNamesInDisjunction . add ( groupName )
125
- this . groupNamesInAlternative . add ( groupName )
124
+ const groupNamesAddedInDisjunction = this . groupNamesAddedInDisjunction
125
+ this . groupNamesAddedInDisjunction =
126
+ this . groupNamesAddedInUpperDisjunctionStack . pop ( ) !
127
+ for ( const groupName of groupNamesAddedInDisjunction ) {
128
+ // Adds the groupName added in Disjunction to groupNamesInScope.
129
+ this . groupNamesInScope . add ( groupName )
130
+ // Adds the groupName added in Disjunction to the upper Disjunction.
131
+ this . groupNamesAddedInDisjunction . add ( groupName )
126
132
}
127
133
}
128
134
@@ -131,12 +137,12 @@ export class GroupSpecifiersAsES2025 implements GroupSpecifiers {
131
137
}
132
138
133
139
public hasInScope ( name : string ) : boolean {
134
- return this . groupNamesInAlternative . has ( name )
140
+ return this . groupNamesInScope . has ( name )
135
141
}
136
142
137
143
public addToScope ( name : string ) : void {
138
- this . groupNamesInAlternative . add ( name )
139
- this . groupNamesInDisjunction . add ( name )
144
+ this . groupNamesInScope . add ( name )
145
+ this . groupNamesAddedInDisjunction . add ( name )
140
146
this . groupNamesInPattern . add ( name )
141
147
}
142
148
}
0 commit comments