diff --git a/semver/_shared.ts b/semver/_shared.ts index f31f5366e9d53..d6fe6b1108140 100644 --- a/semver/_shared.ts +++ b/semver/_shared.ts @@ -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; diff --git a/semver/parse_range.ts b/semver/parse_range.ts index 94c88d5c0c0b1..c429d1a027607 100644 --- a/semver/parse_range.ts +++ b/semver/parse_range.ts @@ -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 === "*"; } @@ -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}`; diff --git a/semver/range_intersects.ts b/semver/range_intersects.ts index 9dc802c40f701..471ef54d42b32 100644 --- a/semver/range_intersects.ts +++ b/semver/range_intersects.ts @@ -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;