@@ -29,9 +29,9 @@ class Range {
2929 // First, split based on boolean or ||
3030 this . raw = range
3131 this . set = range
32- . split ( / \s * \| \| \s * / )
32+ . split ( '||' )
3333 // map the range to a 2d array of comparators
34- . map ( range => this . parseRange ( range . trim ( ) ) )
34+ . map ( r => this . parseRange ( r . trim ( ) ) )
3535 // throw out any comparator lists that are empty
3636 // this generally means that it was not a valid range, which is allowed
3737 // in loose mode, but will still throw if the WHOLE range is invalid.
@@ -46,9 +46,9 @@ class Range {
4646 // keep the first one, in case they're all null sets
4747 const first = this . set [ 0 ]
4848 this . set = this . set . filter ( c => ! isNullSet ( c [ 0 ] ) )
49- if ( this . set . length === 0 )
49+ if ( this . set . length === 0 ) {
5050 this . set = [ first ]
51- else if ( this . set . length > 1 ) {
51+ } else if ( this . set . length > 1 ) {
5252 // if we have any that are *, then the range is just *
5353 for ( const c of this . set ) {
5454 if ( c . length === 1 && isAny ( c [ 0 ] ) ) {
@@ -84,8 +84,9 @@ class Range {
8484 const memoOpts = Object . keys ( this . options ) . join ( ',' )
8585 const memoKey = `parseRange:${ memoOpts } :${ range } `
8686 const cached = cache . get ( memoKey )
87- if ( cached )
87+ if ( cached ) {
8888 return cached
89+ }
8990
9091 const loose = this . options . loose
9192 // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
@@ -94,7 +95,7 @@ class Range {
9495 debug ( 'hyphen replace' , range )
9596 // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
9697 range = range . replace ( re [ t . COMPARATORTRIM ] , comparatorTrimReplace )
97- debug ( 'comparator trim' , range , re [ t . COMPARATORTRIM ] )
98+ debug ( 'comparator trim' , range )
9899
99100 // `~ 1.2.3` => `~1.2.3`
100101 range = range . replace ( re [ t . TILDETRIM ] , tildeTrimReplace )
@@ -108,30 +109,37 @@ class Range {
108109 // At this point, the range is completely trimmed and
109110 // ready to be split into comparators.
110111
111- const compRe = loose ? re [ t . COMPARATORLOOSE ] : re [ t . COMPARATOR ]
112- const rangeList = range
112+ let rangeList = range
113113 . split ( ' ' )
114114 . map ( comp => parseComparator ( comp , this . options ) )
115115 . join ( ' ' )
116116 . split ( / \s + / )
117117 // >=0.0.0 is equivalent to *
118118 . map ( comp => replaceGTE0 ( comp , this . options ) )
119+
120+ if ( loose ) {
119121 // in loose mode, throw out any that are not valid comparators
120- . filter ( this . options . loose ? comp => ! ! comp . match ( compRe ) : ( ) => true )
121- . map ( comp => new Comparator ( comp , this . options ) )
122+ rangeList = rangeList . filter ( comp => {
123+ debug ( 'loose invalid filter' , comp , this . options )
124+ return ! ! comp . match ( re [ t . COMPARATORLOOSE ] )
125+ } )
126+ }
127+ debug ( 'range list' , rangeList )
122128
123129 // if any comparators are the null set, then replace with JUST null set
124130 // if more than one comparator, remove any * comparators
125131 // also, don't include the same comparator more than once
126- const l = rangeList . length
127132 const rangeMap = new Map ( )
128- for ( const comp of rangeList ) {
129- if ( isNullSet ( comp ) )
133+ const comparators = rangeList . map ( comp => new Comparator ( comp , this . options ) )
134+ for ( const comp of comparators ) {
135+ if ( isNullSet ( comp ) ) {
130136 return [ comp ]
137+ }
131138 rangeMap . set ( comp . value , comp )
132139 }
133- if ( rangeMap . size > 1 && rangeMap . has ( '' ) )
140+ if ( rangeMap . size > 1 && rangeMap . has ( '' ) ) {
134141 rangeMap . delete ( '' )
142+ }
135143
136144 const result = [ ...rangeMap . values ( ) ]
137145 cache . set ( memoKey , result )
@@ -196,7 +204,7 @@ const {
196204 t,
197205 comparatorTrimReplace,
198206 tildeTrimReplace,
199- caretTrimReplace
207+ caretTrimReplace,
200208} = require ( '../internal/re' )
201209
202210const isNullSet = c => c . value === '<0.0.0-0'
@@ -245,8 +253,8 @@ const isX = id => !id || id.toLowerCase() === 'x' || id === '*'
245253// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
246254// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
247255const replaceTildes = ( comp , options ) =>
248- comp . trim ( ) . split ( / \s + / ) . map ( ( comp ) => {
249- return replaceTilde ( comp , options )
256+ comp . trim ( ) . split ( / \s + / ) . map ( ( c ) => {
257+ return replaceTilde ( c , options )
250258 } ) . join ( ' ' )
251259
252260const replaceTilde = ( comp , options ) => {
@@ -284,8 +292,8 @@ const replaceTilde = (comp, options) => {
284292// ^1.2.3 --> >=1.2.3 <2.0.0-0
285293// ^1.2.0 --> >=1.2.0 <2.0.0-0
286294const replaceCarets = ( comp , options ) =>
287- comp . trim ( ) . split ( / \s + / ) . map ( ( comp ) => {
288- return replaceCaret ( comp , options )
295+ comp . trim ( ) . split ( / \s + / ) . map ( ( c ) => {
296+ return replaceCaret ( c , options )
289297 } ) . join ( ' ' )
290298
291299const replaceCaret = ( comp , options ) => {
@@ -343,8 +351,8 @@ const replaceCaret = (comp, options) => {
343351
344352const replaceXRanges = ( comp , options ) => {
345353 debug ( 'replaceXRanges' , comp , options )
346- return comp . split ( / \s + / ) . map ( ( comp ) => {
347- return replaceXRange ( comp , options )
354+ return comp . split ( / \s + / ) . map ( ( c ) => {
355+ return replaceXRange ( c , options )
348356 } ) . join ( ' ' )
349357}
350358
@@ -405,8 +413,9 @@ const replaceXRange = (comp, options) => {
405413 }
406414 }
407415
408- if ( gtlt === '<' )
416+ if ( gtlt === '<' ) {
409417 pr = '-0'
418+ }
410419
411420 ret = `${ gtlt + M } .${ m } .${ p } ${ pr } `
412421 } else if ( xm ) {
0 commit comments