Repository navigation
Conversation
`new Range(comparator, options)` returned from the `instanceof Comparator` branch before assigning `this.options`, `this.loose` and `this.includePrerelease`, so those fields stayed `undefined`. As a result `range.test()` threw a TypeError for any prerelease version (it reads `options.includePrerelease` in `testSet`) and `range.range`/`toString()` failed the same way. `satisfies(version, comparator)` went through the same path and threw as well. Assign the missing fields in that branch. A comparator already carries the options it was parsed with, so they are inherited when the caller does not pass any; explicit options still win. This makes a comparator-built range behave like the equivalent string range. Fixes npm#908
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
new Range(comparator, options)returns from therange instanceof Comparatorbranch beforethis.options,this.looseandthis.includePrereleaseare assigned, so those fields stayedundefinedon a comparator-built range.Range#test()passesthis.optionstotestSet(), which readsoptions.includePrerelease, so testing any prerelease version against such a range threw:Stable versions happened to work because
testSet()short-circuits onversion.prerelease.length.Fixes #908.
Fix
Assign the three fields in the
Comparatorbranch. A comparator already carries the options it was parsed with, so those are inherited when the caller passes no options; explicit options still win:new Range(comparator)uses the comparator's options (includingincludePrerelease).new Range(comparator, { includePrerelease: true })andnew Range(comparator, true)(loose) use what the caller asked for.A comparator-built range now behaves exactly like the equivalent string range for
.test(),.range,looseandincludePrerelease.Tests
Added to
test/classes/range.js:includePrereleaseis inherited from the comparator, and an explicit option overrides it;loose) are still parsed;options/loose/includePrerelease/rangeare populated.Validation
npx tap(full suite, coverage thresholds): pass, 53 test files, no failuresnpx eslint classes/range.js test/classes/range.js: clean