@@ -9957,35 +9957,43 @@ const coerce = (version, options) => {
99579957
99589958 let match = null
99599959 if ( ! options . rtl ) {
9960- match = version . match ( re [ t . COERCE ] )
9960+ match = version . match ( options . includePrerelease ? re [ t . COERCEFULL ] : re [ t . COERCE ] )
99619961 } else {
99629962 // Find the right-most coercible string that does not share
99639963 // a terminus with a more left-ward coercible string.
99649964 // Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
9965+ // With includePrerelease option set, '1.2.3.4-rc' wants to coerce '2.3.4-rc', not '2.3.4'
99659966 //
99669967 // Walk through the string checking with a /g regexp
99679968 // Manually set the index so as to pick up overlapping matches.
99689969 // Stop when we get a match that ends at the string end, since no
99699970 // coercible string can be more right-ward without the same terminus.
9971+ const coerceRtlRegex = options . includePrerelease ? re [ t . COERCERTLFULL ] : re [ t . COERCERTL ]
99709972 let next
9971- while ( ( next = re [ t . COERCERTL ] . exec ( version ) ) &&
9973+ while ( ( next = coerceRtlRegex . exec ( version ) ) &&
99729974 ( ! match || match . index + match [ 0 ] . length !== version . length )
99739975 ) {
99749976 if ( ! match ||
99759977 next . index + next [ 0 ] . length !== match . index + match [ 0 ] . length ) {
99769978 match = next
99779979 }
9978- re [ t . COERCERTL ] . lastIndex = next . index + next [ 1 ] . length + next [ 2 ] . length
9980+ coerceRtlRegex . lastIndex = next . index + next [ 1 ] . length + next [ 2 ] . length
99799981 }
99809982 // leave it in a clean state
9981- re [ t . COERCERTL ] . lastIndex = - 1
9983+ coerceRtlRegex . lastIndex = - 1
99829984 }
99839985
99849986 if ( match === null ) {
99859987 return null
99869988 }
99879989
9988- return parse ( `${ match [ 2 ] } .${ match [ 3 ] || '0' } .${ match [ 4 ] || '0' } ` , options )
9990+ const major = match [ 2 ]
9991+ const minor = match [ 3 ] || '0'
9992+ const patch = match [ 4 ] || '0'
9993+ const prerelease = options . includePrerelease && match [ 5 ] ? `-${ match [ 5 ] } ` : ''
9994+ const build = options . includePrerelease && match [ 6 ] ? `+${ match [ 6 ] } ` : ''
9995+
9996+ return parse ( `${ major } .${ minor } .${ patch } ${ prerelease } ${ build } ` , options )
99899997}
99909998module . exports = coerce
99919999
@@ -10677,12 +10685,17 @@ createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`)
1067710685
1067810686// Coercion.
1067910687// Extract anything that could conceivably be a part of a valid semver
10680- createToken ( 'COERCE ' , `${ '(^|[^\\d])' +
10688+ createToken ( 'COERCEPLAIN ' , `${ '(^|[^\\d])' +
1068110689 '(\\d{1,' } ${ MAX_SAFE_COMPONENT_LENGTH } })` +
1068210690 `(?:\\.(\\d{1,${ MAX_SAFE_COMPONENT_LENGTH } }))?` +
10683- `(?:\\.(\\d{1,${ MAX_SAFE_COMPONENT_LENGTH } }))?` +
10691+ `(?:\\.(\\d{1,${ MAX_SAFE_COMPONENT_LENGTH } }))?` )
10692+ createToken ( 'COERCE' , `${ src [ t . COERCEPLAIN ] } (?:$|[^\\d])` )
10693+ createToken ( 'COERCEFULL' , src [ t . COERCEPLAIN ] +
10694+ `(?:${ src [ t . PRERELEASE ] } )?` +
10695+ `(?:${ src [ t . BUILD ] } )?` +
1068410696 `(?:$|[^\\d])` )
1068510697createToken ( 'COERCERTL' , src [ t . COERCE ] , true )
10698+ createToken ( 'COERCERTLFULL' , src [ t . COERCEFULL ] , true )
1068610699
1068710700// Tilde ranges.
1068810701// Meaning is "reasonably at or greater than"
0 commit comments