Skip to content

Commit

Permalink
refactor(semver): prepare for noUncheckedIndexedAccess
Browse files Browse the repository at this point in the history
  • Loading branch information
javihernant committed Feb 19, 2024
1 parent a828744 commit 56f193f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion semver/_shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ export function parseBuild(buildmetadata: string) {
return buildmetadata.split(".").filter(Boolean);
}

export function parseNumber(input: string, errorMessage: string) {
export function parseNumber(input: string | undefined, errorMessage: string) {
if (input === undefined) {
return 0;
}
const number = Number(input);
if (!isValidNumber(number)) throw new TypeError(errorMessage);
return number;
Expand Down
6 changes: 3 additions & 3 deletions semver/parse_range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { OPERATOR_XRANGE_REGEXP, XRANGE } from "./_shared.ts";
import { parseComparator } from "./_parse_comparator.ts";
import { parseBuild, parsePrerelease } from "./_shared.ts";

function isWildcard(id: string): boolean {
function isWildcard(id?: string): boolean {
return !id || id.toLowerCase() === "x" || id === "*";
}

Expand Down Expand Up @@ -50,9 +50,9 @@ function parseHyphenRange(range: string) {
if (isWildcard(rightGroups.major)) {
to = "";
} else if (isWildcard(rightGroups.minor)) {
to = `<${+rightGroups.major + 1}.0.0`;
to = `<${+rightGroups.major! + 1}.0.0`;
} else if (isWildcard(rightGroups.patch)) {
to = `<${rightGroups.major}.${+rightGroups.minor + 1}.0`;
to = `<${rightGroups.major}.${+rightGroups.minor! + 1}.0`;
} else if (rightGroups.prerelease) {
to =
`<=${rightGroups.major}.${rightGroups.minor}.${rightGroups.patch}-${rightGroups.prerelease}`;
Expand Down
2 changes: 1 addition & 1 deletion semver/range_intersects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function rangesSatisfiable(ranges: Range[]): boolean {
function comparatorsSatisfiable(comparators: Comparator[]): boolean {
// Comparators are satisfiable if they all intersect with each other
for (let i = 0; i < comparators.length - 1; i++) {
const c0 = comparators[i];
const c0 = comparators[i]!;
for (const c1 of comparators.slice(i + 1)) {
if (!comparatorIntersects(c0, c1)) {
return false;
Expand Down

0 comments on commit 56f193f

Please sign in to comment.