Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(range): inherit options from input range #388

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions classes/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class Range {
options = parseOptions(options)

if (range instanceof Range) {
// inherit options
options = { ...{ loose: range.loose, includePrerelease: range.includePrerelease }, ...range.options, ...options }
bluelovers marked this conversation as resolved.
Show resolved Hide resolved
if (
range.loose === !!options.loose &&
range.includePrerelease === !!options.includePrerelease
Expand Down
3 changes: 2 additions & 1 deletion test/classes/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ test('range as argument to range ctor', t => {
const loose = new Range('1.2.3', { loose: true })
t.equal(new Range(loose, { loose: true }), loose, 'loose option')
t.equal(new Range(loose, true), loose, 'loose boolean')
t.notEqual(new Range(loose), loose, 'created new range if not matched')
t.notEqual(new Range(loose, { loose: false }), loose, 'created new range if not matched')
t.equal(new Range(loose), loose, 'inherit')

const incPre = new Range('1.2.3', {includePrerelease: true})
t.equal(new Range(incPre, {includePrerelease: true}), incPre,
Expand Down