Skip to content

Commit

Permalink
fix: reuse parsed options
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Apr 6, 2023
1 parent 5cf24b5 commit 7e4e016
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
3 changes: 2 additions & 1 deletion bin/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let rtl = false
let identifier

const semver = require('../')
const parseOptions = require('../internal/parse-options')

let reverse = false

Expand Down Expand Up @@ -88,7 +89,7 @@ const main = () => {
}
}

options = { loose: loose, includePrerelease: includePrerelease, rtl: rtl }
options = parseOptions({ loose, includePrerelease, rtl })

versions = versions.map((v) => {
return coerce ? (semver.coerce(v, options) || { version: v }).version : v
Expand Down
7 changes: 0 additions & 7 deletions classes/comparator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions functions/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const SemVer = require('../classes/semver')

const parseOptions = require('../internal/parse-options')
const parse = (version, options) => {
options = parseOptions(options)

if (version instanceof SemVer) {
return version
}
Expand All @@ -18,6 +16,7 @@ const parse = (version, options) => {
return null
}

options = parseOptions(options)
const r = options.loose ? re[t.LOOSE] : re[t.FULL]
if (!r.test(version)) {
return null
Expand Down

0 comments on commit 7e4e016

Please sign in to comment.