@@ -43,7 +43,7 @@ function isTrivialAssertion(
4343 }
4444
4545 if ( assertion . kind === "lookahead" || assertion . kind === "lookbehind" ) {
46- if ( isPotentiallyEmpty ( assertion . alternatives ) ) {
46+ if ( isPotentiallyEmpty ( assertion . alternatives , flags ) ) {
4747 // The assertion is guaranteed to trivially accept/reject.
4848 return true
4949 }
@@ -80,6 +80,7 @@ function isTrivialAssertion(
8080function * getNextElements (
8181 start : Element ,
8282 dir : MatchingDirection ,
83+ flags : ReadonlyFlags ,
8384) : Iterable < Element > {
8485 let element = start
8586
@@ -110,7 +111,7 @@ function* getNextElements(
110111 for ( let i = index + inc ; i >= 0 && i < elements . length ; i += inc ) {
111112 const e = elements [ i ]
112113 yield e
113- if ( ! isZeroLength ( e ) ) {
114+ if ( ! isZeroLength ( e , flags ) ) {
114115 return
115116 }
116117 }
@@ -142,6 +143,7 @@ function tryFindContradictionIn(
142143 element : Element ,
143144 dir : MatchingDirection ,
144145 condition : ( e : Element | Alternative ) => boolean ,
146+ flags : ReadonlyFlags ,
145147) : boolean {
146148 if ( condition ( element ) ) {
147149 return true
@@ -151,7 +153,7 @@ function tryFindContradictionIn(
151153 // Go into the alternatives of groups
152154 let some = false
153155 element . alternatives . forEach ( ( a ) => {
154- if ( tryFindContradictionInAlternative ( a , dir , condition ) ) {
156+ if ( tryFindContradictionInAlternative ( a , dir , condition , flags ) ) {
155157 some = true
156158 }
157159 } )
@@ -160,7 +162,7 @@ function tryFindContradictionIn(
160162
161163 if ( element . type === "Quantifier" && element . max === 1 ) {
162164 // Go into the element of quantifiers if their maximum is 1
163- return tryFindContradictionIn ( element . element , dir , condition )
165+ return tryFindContradictionIn ( element . element , dir , condition , flags )
164166 }
165167
166168 if (
@@ -173,7 +175,7 @@ function tryFindContradictionIn(
173175 // Since we don't consume characters, we want to keep going even if we
174176 // find a contradiction inside the lookaround.
175177 element . alternatives . forEach ( ( a ) =>
176- tryFindContradictionInAlternative ( a , dir , condition ) ,
178+ tryFindContradictionInAlternative ( a , dir , condition , flags ) ,
177179 )
178180 }
179181
@@ -188,6 +190,7 @@ function tryFindContradictionInAlternative(
188190 alternative : Alternative ,
189191 dir : MatchingDirection ,
190192 condition : ( e : Element | Alternative ) => boolean ,
193+ flags : ReadonlyFlags ,
191194) : boolean {
192195 if ( condition ( alternative ) ) {
193196 return true
@@ -199,10 +202,10 @@ function tryFindContradictionInAlternative(
199202 const inc = dir === "ltr" ? 1 : - 1
200203 for ( let i = first ; i >= 0 && i < elements . length ; i += inc ) {
201204 const e = elements [ i ]
202- if ( tryFindContradictionIn ( e , dir , condition ) ) {
205+ if ( tryFindContradictionIn ( e , dir , condition , flags ) ) {
203206 return true
204207 }
205- if ( ! isZeroLength ( e ) ) {
208+ if ( ! isZeroLength ( e , flags ) ) {
206209 break
207210 }
208211 }
@@ -271,8 +274,10 @@ export default createRule("no-contradiction-with-assertion", {
271274 getFirstConsumedChar ( assertion , dir , flags ) ,
272275 )
273276
274- for ( const element of getNextElements ( assertion , dir ) ) {
275- if ( tryFindContradictionIn ( element , dir , contradicts ) ) {
277+ for ( const element of getNextElements ( assertion , dir , flags ) ) {
278+ if (
279+ tryFindContradictionIn ( element , dir , contradicts , flags )
280+ ) {
276281 break
277282 }
278283 }
0 commit comments