@@ -29,9 +29,9 @@ class Range {
29
29
// First, split based on boolean or ||
30
30
this . raw = range
31
31
this . set = range
32
- . split ( / \s * \| \| \s * / )
32
+ . split ( '||' )
33
33
// map the range to a 2d array of comparators
34
- . map ( range => this . parseRange ( range . trim ( ) ) )
34
+ . map ( r => this . parseRange ( r . trim ( ) ) )
35
35
// throw out any comparator lists that are empty
36
36
// this generally means that it was not a valid range, which is allowed
37
37
// in loose mode, but will still throw if the WHOLE range is invalid.
@@ -46,9 +46,9 @@ class Range {
46
46
// keep the first one, in case they're all null sets
47
47
const first = this . set [ 0 ]
48
48
this . set = this . set . filter ( c => ! isNullSet ( c [ 0 ] ) )
49
- if ( this . set . length === 0 )
49
+ if ( this . set . length === 0 ) {
50
50
this . set = [ first ]
51
- else if ( this . set . length > 1 ) {
51
+ } else if ( this . set . length > 1 ) {
52
52
// if we have any that are *, then the range is just *
53
53
for ( const c of this . set ) {
54
54
if ( c . length === 1 && isAny ( c [ 0 ] ) ) {
@@ -84,8 +84,9 @@ class Range {
84
84
const memoOpts = Object . keys ( this . options ) . join ( ',' )
85
85
const memoKey = `parseRange:${ memoOpts } :${ range } `
86
86
const cached = cache . get ( memoKey )
87
- if ( cached )
87
+ if ( cached ) {
88
88
return cached
89
+ }
89
90
90
91
const loose = this . options . loose
91
92
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
@@ -94,7 +95,7 @@ class Range {
94
95
debug ( 'hyphen replace' , range )
95
96
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
96
97
range = range . replace ( re [ t . COMPARATORTRIM ] , comparatorTrimReplace )
97
- debug ( 'comparator trim' , range , re [ t . COMPARATORTRIM ] )
98
+ debug ( 'comparator trim' , range )
98
99
99
100
// `~ 1.2.3` => `~1.2.3`
100
101
range = range . replace ( re [ t . TILDETRIM ] , tildeTrimReplace )
@@ -108,30 +109,37 @@ class Range {
108
109
// At this point, the range is completely trimmed and
109
110
// ready to be split into comparators.
110
111
111
- const compRe = loose ? re [ t . COMPARATORLOOSE ] : re [ t . COMPARATOR ]
112
- const rangeList = range
112
+ let rangeList = range
113
113
. split ( ' ' )
114
114
. map ( comp => parseComparator ( comp , this . options ) )
115
115
. join ( ' ' )
116
116
. split ( / \s + / )
117
117
// >=0.0.0 is equivalent to *
118
118
. map ( comp => replaceGTE0 ( comp , this . options ) )
119
+
120
+ if ( loose ) {
119
121
// 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 )
122
128
123
129
// if any comparators are the null set, then replace with JUST null set
124
130
// if more than one comparator, remove any * comparators
125
131
// also, don't include the same comparator more than once
126
- const l = rangeList . length
127
132
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 ) ) {
130
136
return [ comp ]
137
+ }
131
138
rangeMap . set ( comp . value , comp )
132
139
}
133
- if ( rangeMap . size > 1 && rangeMap . has ( '' ) )
140
+ if ( rangeMap . size > 1 && rangeMap . has ( '' ) ) {
134
141
rangeMap . delete ( '' )
142
+ }
135
143
136
144
const result = [ ...rangeMap . values ( ) ]
137
145
cache . set ( memoKey , result )
@@ -196,7 +204,7 @@ const {
196
204
t,
197
205
comparatorTrimReplace,
198
206
tildeTrimReplace,
199
- caretTrimReplace
207
+ caretTrimReplace,
200
208
} = require ( '../internal/re' )
201
209
202
210
const isNullSet = c => c . value === '<0.0.0-0'
@@ -245,8 +253,8 @@ const isX = id => !id || id.toLowerCase() === 'x' || id === '*'
245
253
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
246
254
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
247
255
const 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 )
250
258
} ) . join ( ' ' )
251
259
252
260
const replaceTilde = ( comp , options ) => {
@@ -284,8 +292,8 @@ const replaceTilde = (comp, options) => {
284
292
// ^1.2.3 --> >=1.2.3 <2.0.0-0
285
293
// ^1.2.0 --> >=1.2.0 <2.0.0-0
286
294
const 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 )
289
297
} ) . join ( ' ' )
290
298
291
299
const replaceCaret = ( comp , options ) => {
@@ -343,8 +351,8 @@ const replaceCaret = (comp, options) => {
343
351
344
352
const replaceXRanges = ( comp , options ) => {
345
353
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 )
348
356
} ) . join ( ' ' )
349
357
}
350
358
@@ -405,8 +413,9 @@ const replaceXRange = (comp, options) => {
405
413
}
406
414
}
407
415
408
- if ( gtlt === '<' )
416
+ if ( gtlt === '<' ) {
409
417
pr = '-0'
418
+ }
410
419
411
420
ret = `${ gtlt + M } .${ m } .${ p } ${ pr } `
412
421
} else if ( xm ) {
0 commit comments