@@ -72,6 +72,8 @@ function hasNativeFlag(flag) {
7272 }
7373 return isSupported ;
7474}
75+ // Check for ES2021 `d` flag support
76+ const hasNativeD = hasNativeFlag ( 'd' ) ;
7577// Check for ES2018 `s` flag support
7678const hasNativeS = hasNativeFlag ( 's' ) ;
7779// Check for ES6 `u` flag support
@@ -80,6 +82,7 @@ const hasNativeU = hasNativeFlag('u');
8082const hasNativeY = hasNativeFlag ( 'y' ) ;
8183// Tracker for known flags, including addon flags
8284const registeredFlags = {
85+ d : hasNativeD ,
8386 g : true ,
8487 i : true ,
8588 m : true ,
@@ -88,7 +91,7 @@ const registeredFlags = {
8891 y : hasNativeY
8992} ;
9093// Flags to remove when passing to native `RegExp` constructor
91- const nonnativeFlags = hasNativeS ? / [ ^ g i m s u y ] + / g : / [ ^ g i m u y ] + / g;
94+ const nonnativeFlags = hasNativeS ? / [ ^ d g i m s u y ] + / g : / [ ^ d g i m u y ] + / g;
9295
9396/**
9497 * Attaches extended data and `XRegExp.prototype` properties to a regex object.
@@ -379,10 +382,10 @@ function prepareFlags(pattern, flags) {
379382 throw new SyntaxError ( `Invalid duplicate regex flag ${ flags } ` ) ;
380383 }
381384
382- // Strip and apply a leading mode modifier with any combination of flags except g or y
385+ // Strip and apply a leading mode modifier with any combination of flags except `dgy`
383386 pattern = pattern . replace ( / ^ \( \? ( [ \w $ ] + ) \) / , ( $0 , $1 ) => {
384- if ( / [ g y ] / . test ( $1 ) ) {
385- throw new SyntaxError ( `Cannot use flag g or y in mode modifier ${ $0 } ` ) ;
387+ if ( / [ d g y ] / . test ( $1 ) ) {
388+ throw new SyntaxError ( `Cannot use flags dgy in mode modifier ${ $0 } ` ) ;
386389 }
387390 // Allow duplicate flags within the mode modifier
388391 flags = clipDuplicates ( flags + $1 ) ;
@@ -519,6 +522,7 @@ function setNamespacing(on) {
519522 * @param {String|RegExp } pattern Regex pattern string, or an existing regex object to copy.
520523 * @param {String } [flags] Any combination of flags.
521524 * Native flags:
525+ * - `d` - indices for groups (ES2021)
522526 * - `g` - global
523527 * - `i` - ignore case
524528 * - `m` - multiline anchors
0 commit comments