@@ -708,7 +708,21 @@ const splitAlternatives = (body) => {
708708} ;
709709
710710/**
711- * Rewrites the first alternation group, word-character class or optional atom
711+ * The part of a group body the match spells: the body itself for a capturing
712+ * group, what follows the `?:` or `?<name>` prefix for the others, and nothing
713+ * for a lookaround, which says what surrounds the match rather than spelling it.
714+ * @param {string } body group body without the enclosing parentheses
715+ * @returns {string | undefined } the spelled part, or `undefined` for a lookaround
716+ */
717+ const groupContent = ( body ) => {
718+ if ( ! body . startsWith ( "?" ) ) return body ;
719+ if ( body . startsWith ( "?:" ) ) return body . slice ( 2 ) ;
720+ const named = / ^ \? < [ ^ = ! ] [ ^ > ] * > / . exec ( body ) ;
721+ return named ? body . slice ( named [ 0 ] . length ) : undefined ;
722+ } ;
723+
724+ /**
725+ * Rewrites the first group, word-character class or optional atom
712726 * in the source into the spellings it can match, leaving the rest as written.
713727 * @param {string } source regexp source
714728 * @returns {string[] | undefined } the rewritten sources, or `undefined` when the source holds no such construct
@@ -717,7 +731,6 @@ const expandFirstConstruct = (source) => {
717731 for ( let i = 0 ; i < source . length ; i ++ ) {
718732 const char = source [ i ] ;
719733 let end = i + 1 ;
720- let resumeInside = false ;
721734 /** @type {string[] | undefined } */
722735 let spellings ;
723736 if ( char === "\\" ) {
@@ -732,15 +745,8 @@ const expandFirstConstruct = (source) => {
732745 } else if ( char === "(" ) {
733746 const close = findGroupEnd ( source , i ) ;
734747 end = close + 1 ;
735- const body = source . slice ( i + 1 , close ) ;
736- // a lookaround says what must surround the match, not what it spells
737- if ( ! body . startsWith ( "?" ) || body . startsWith ( "?:" ) ) {
738- const alternatives = splitAlternatives (
739- body . startsWith ( "?:" ) ? body . slice ( 2 ) : body
740- ) ;
741- if ( alternatives . length > 1 ) spellings = alternatives ;
742- else resumeInside = true ;
743- }
748+ const content = groupContent ( source . slice ( i + 1 , close ) ) ;
749+ if ( content !== undefined ) spellings = splitAlternatives ( content ) ;
744750 }
745751 // `?` makes the atom optional, so its absence is a spelling as well
746752 if ( source [ end ] === "?" ) {
@@ -752,7 +758,7 @@ const expandFirstConstruct = (source) => {
752758 ( spelling ) => source . slice ( 0 , i ) + spelling + source . slice ( end )
753759 ) ;
754760 }
755- if ( ! resumeInside ) i = end - 1 ;
761+ i = end - 1 ;
756762 }
757763} ;
758764
@@ -855,11 +861,11 @@ const globReferencesExtension = (glob, extension) => {
855861 */
856862const conditionReferencesExtension = ( condition , extProbe ) => {
857863 if ( condition instanceof RegExp ) {
858- return someSpellingContains (
859- condition . source ,
860- extProbe ,
861- expandFirstConstruct
862- ) ;
864+ // an `/i` rule spells the extension in any case; the probe is lower case
865+ const source = condition . ignoreCase
866+ ? condition . source . toLowerCase ( )
867+ : condition . source ;
868+ return someSpellingContains ( source , extProbe , expandFirstConstruct ) ;
863869 }
864870 if ( Array . isArray ( condition ) ) {
865871 return condition . some ( ( c ) => conditionReferencesExtension ( c , extProbe ) ) ;
0 commit comments