summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/semver/classes/comparator.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/node_modules/semver/classes/comparator.js')
-rw-r--r--tools/node_modules/eslint/node_modules/semver/classes/comparator.js70
1 files changed, 37 insertions, 33 deletions
diff --git a/tools/node_modules/eslint/node_modules/semver/classes/comparator.js b/tools/node_modules/eslint/node_modules/semver/classes/comparator.js
index 62cd204d9b..2146c884bd 100644
--- a/tools/node_modules/eslint/node_modules/semver/classes/comparator.js
+++ b/tools/node_modules/eslint/node_modules/semver/classes/comparator.js
@@ -78,13 +78,6 @@ class Comparator {
throw new TypeError('a Comparator is required')
}
- if (!options || typeof options !== 'object') {
- options = {
- loose: !!options,
- includePrerelease: false,
- }
- }
-
if (this.operator === '') {
if (this.value === '') {
return true
@@ -97,32 +90,43 @@ class Comparator {
return new Range(this.value, options).test(comp.semver)
}
- const sameDirectionIncreasing =
- (this.operator === '>=' || this.operator === '>') &&
- (comp.operator === '>=' || comp.operator === '>')
- const sameDirectionDecreasing =
- (this.operator === '<=' || this.operator === '<') &&
- (comp.operator === '<=' || comp.operator === '<')
- const sameSemVer = this.semver.version === comp.semver.version
- const differentDirectionsInclusive =
- (this.operator === '>=' || this.operator === '<=') &&
- (comp.operator === '>=' || comp.operator === '<=')
- const oppositeDirectionsLessThan =
- cmp(this.semver, '<', comp.semver, options) &&
- (this.operator === '>=' || this.operator === '>') &&
- (comp.operator === '<=' || comp.operator === '<')
- const oppositeDirectionsGreaterThan =
- cmp(this.semver, '>', comp.semver, options) &&
- (this.operator === '<=' || this.operator === '<') &&
- (comp.operator === '>=' || comp.operator === '>')
-
- return (
- sameDirectionIncreasing ||
- sameDirectionDecreasing ||
- (sameSemVer && differentDirectionsInclusive) ||
- oppositeDirectionsLessThan ||
- oppositeDirectionsGreaterThan
- )
+ options = parseOptions(options)
+
+ // Special cases where nothing can possibly be lower
+ if (options.includePrerelease &&
+ (this.value === '<0.0.0-0' || comp.value === '<0.0.0-0')) {
+ return false
+ }
+ if (!options.includePrerelease &&
+ (this.value.startsWith('<0.0.0') || comp.value.startsWith('<0.0.0'))) {
+ return false
+ }
+
+ // Same direction increasing (> or >=)
+ if (this.operator.startsWith('>') && comp.operator.startsWith('>')) {
+ return true
+ }
+ // Same direction decreasing (< or <=)
+ if (this.operator.startsWith('<') && comp.operator.startsWith('<')) {
+ return true
+ }
+ // same SemVer and both sides are inclusive (<= or >=)
+ if (
+ (this.semver.version === comp.semver.version) &&
+ this.operator.includes('=') && comp.operator.includes('=')) {
+ return true
+ }
+ // opposite directions less than
+ if (cmp(this.semver, '<', comp.semver, options) &&
+ this.operator.startsWith('>') && comp.operator.startsWith('<')) {
+ return true
+ }
+ // opposite directions greater than
+ if (cmp(this.semver, '>', comp.semver, options) &&
+ this.operator.startsWith('<') && comp.operator.startsWith('>')) {
+ return true
+ }
+ return false
}
}