Skip to content

Conversation

@achedges
Copy link
Contributor

@achedges achedges commented Dec 31, 2025

This change refactors a handful of internal functionality to remove unreachable code, and adds a couple of new tests to bring up line coverage.

Comments added inline, I hope this helps!

@achedges achedges requested a review from kt3k as a code owner December 31, 2025 17:34
return cmp < 0;
case "!=":
return false;
return cmp >= 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll admit this one had me scratching my head a bit. It seems that, in the context of this internal utility function, simply inverting the outcome for the != operator (compared to the = operator) should suffice for producing the intended effect.

return cmp > 0;
case "!=":
return false;
return cmp <= 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments on greater_than_range.ts


if (!groups) return null;

const { operator, prerelease, buildmetadata } =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm missing something here, if the regex match succeeds at all, the resulting groups will contain elements for each semver component. This code was attempting to manually parse what this regex was already doing.

@codecov
Copy link

codecov bot commented Dec 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.27%. Comparing base (13e5527) to head (55e9326).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6924      +/-   ##
==========================================
+ Coverage   94.17%   94.27%   +0.09%     
==========================================
  Files         584      584              
  Lines       43087    43131      +44     
  Branches     6875     6903      +28     
==========================================
+ Hits        40578    40660      +82     
+ Misses       2457     2420      -37     
+ Partials       52       51       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

const prerelease = parsePrerelease(groups.prerelease ?? "");
const build = parseBuild(groups.build ?? "");
return [{ operator: undefined, major, minor, patch, prerelease, build }];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the = string if we have it, the net-effect is the same.

throw new Error(
`Cannot parse version range: '${groups.operator}' is not a valid operator`,
);
return handleEqualOperator(groups);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing default case should not be possible, so we can use the equals/empty operator to exercise a switch default.

}]];
// FIXME(kt3k): This demonstrates a bug. This should be false
assertEquals(greaterThanRange(version, range), true);
assertEquals(greaterThanRange(version, range), false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, thanks for fixing this!

}]];
// FIXME(kt3k): This demonstrates a bug. This should be false
assertEquals(lessThanRange(version, range), true);
assertEquals(lessThanRange(version, range), false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

[{ operator: "<", major: 1, minor: 0, patch: 0 }],
]);
assertEquals(parseRange("<=1.*.2"), [
[{ operator: "<", major: 1, minor: NaN, patch: 0 }],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be [{ operator: "<", major: 2, minor: 0, patch: 0 }] (though it's the existing behavior)

npm:semver works like the below:

import * as semver from "npm:semver";

console.log(semver.satisfies("1.9.9", '<=1.*.2')) // => prints true
console.log(semver.satisfies("2.0.0", '<=1.*.2')) // => prints false

I'm adding FIXME comment above for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! I'll take a look, thanks for the pointer.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this! LGTM

@kt3k kt3k merged commit 37e5ec1 into denoland:main Jan 7, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants