@@ -89,7 +89,9 @@ exports.versionLt = versionLt;
8989 */
9090exports . parseRange = str => {
9191 const splitAndConvert = str => {
92- return str . split ( "." ) . map ( item => ( `${ + item } ` === item ? + item : item ) ) ;
92+ return str
93+ . split ( "." )
94+ . map ( item => ( item !== "NaN" && `${ + item } ` === item ? + item : item ) ) ;
9395 } ;
9496 // see https://docs.npmjs.com/misc/semver#range-grammar for grammar
9597 const parsePartial = str => {
@@ -131,13 +133,15 @@ exports.parseRange = str => {
131133 return [ - range [ 0 ] - 1 , ...range . slice ( 1 ) ] ;
132134 } ;
133135 const parseSimple = str => {
134- // simple ::= primitive | partial | tilde | caret
135- // primitive ::= ( '<' | '>' | '>=' | '<=' | '=' ) partial
136- // tilde ::= '~' partial
137- // caret ::= '^' partial
136+ // simple ::= primitive | partial | tilde | caret
137+ // primitive ::= ( '<' | '>' | '>=' | '<=' | '=' | '!' ) ( ' ' ) * partial
138+ // tilde ::= '~' ( ' ' ) * partial
139+ // caret ::= '^' ( ' ' ) * partial
138140 const match = / ^ ( \^ | ~ | < = | < | > = | > | = | v | ! ) / . exec ( str ) ;
139141 const start = match ? match [ 0 ] : "" ;
140- const remainder = parsePartial ( str . slice ( start . length ) ) ;
142+ const remainder = parsePartial (
143+ start . length ? str . slice ( start . length ) . trim ( ) : str . trim ( )
144+ ) ;
141145 switch ( start ) {
142146 case "^" :
143147 if ( remainder . length > 1 && remainder [ 1 ] === 0 ) {
@@ -191,11 +195,14 @@ exports.parseRange = str => {
191195 return [ , ...arr , ...items . slice ( 1 ) . map ( ( ) => fn ) ] ;
192196 } ;
193197 const parseRange = str => {
194- // range ::= hyphen | simple ( ' ' simple ) * | ''
195- // hyphen ::= partial ' - ' partial
196- const items = str . split ( " - " ) ;
198+ // range ::= hyphen | simple ( ' ' ( ' ' ) * simple ) * | ''
199+ // hyphen ::= partial ( ' ' ) * ' - ' ( ' ' ) * partial
200+ const items = str . split ( / \s + - \s + / ) ;
197201 if ( items . length === 1 ) {
198- const items = str . trim ( ) . split ( / \s + / g) . map ( parseSimple ) ;
202+ const items = str
203+ . trim ( )
204+ . split ( / (?< = [ - 0 - 9 A - Z a - z ] ) \s + / g)
205+ . map ( parseSimple ) ;
199206 return combine ( items , 2 ) ;
200207 }
201208 const a = parsePartial ( items [ 0 ] ) ;
0 commit comments