Fix semver comparison logic (#773)

Fix `isLessThan` logic between semvers
This commit is contained in:
Daniel Chao
2024-11-03 20:31:04 -08:00
committed by GitHub
parent 9692504b5f
commit 4b4d81ba93
3 changed files with 48 additions and 8 deletions

View File

@@ -133,10 +133,10 @@ class Version {
///
/// Note: `version1.equals(version2)` differs from `version1 == version2` in that it ignores [build].
function equals(other: Version): Boolean =
major == other.major &&
minor == other.minor &&
patch == other.patch &&
preRelease == other.preRelease
major == other.major
&& minor == other.minor
&& patch == other.patch
&& preRelease == other.preRelease
/// Tells whether this version is less than [other] according to semantic versioning rules.
///
@@ -157,10 +157,14 @@ class Version {
/// semver.Version("1.0.0-rc.1").isLessThan(semver.Version("1.0.0"))
/// ```
function isLessThan(other: Version): Boolean =
major < other.major ||
minor < other.minor ||
patch < other.patch ||
isPreReleaseLessThan(other)
major < other.major
|| major == other.major && minor < other.minor
|| major == other.major && minor == other.minor && patch < other.patch
||
major == other.major
&& minor == other.minor
&& patch == other.patch
&& isPreReleaseLessThan(other)
/// Tells whether this version is less than or equal to [other] according to semantic versioning rules.
function isLessThanOrEquals(other: Version): Boolean =