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 20, 2024
1 parent a828744 commit 8ea975c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
10 changes: 8 additions & 2 deletions semver/_parse_comparator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ export function parseComparator(comparator: string): Comparator {
const semver = groups.major
? {
major: parseNumber(groups.major, "Invalid major version"),
minor: parseNumber(groups.minor, "Invalid minor version"),
patch: parseNumber(groups.patch, "Invalid patch version"),
minor: parseNumber(
groups.minor!,
"Invalid minor version",
),
patch: parseNumber(
groups.patch!,
"Invalid patch version",
),
prerelease: prerelease ? parsePrerelease(prerelease) : [],
build: buildmetadata ? parseBuild(buildmetadata) : [],
}
Expand Down
6 changes: 3 additions & 3 deletions semver/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export function parse(version: string): SemVer {
const groups = version.match(FULL_REGEXP)?.groups;
if (!groups) throw new TypeError(`Invalid Version: ${version}`);

const major = parseNumber(groups.major, "Invalid major version");
const minor = parseNumber(groups.minor, "Invalid minor version");
const patch = parseNumber(groups.patch, "Invalid patch version");
const major = parseNumber(groups.major!, "Invalid major version");
const minor = parseNumber(groups.minor!, "Invalid minor version");
const patch = parseNumber(groups.patch!, "Invalid patch version");

const prerelease = groups.prerelease
? parsePrerelease(groups.prerelease)
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 8ea975c

Please sign in to comment.