From eaf8e83f1ae677240d19a730e288162293fcf5e0 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Wed, 16 Nov 2022 14:40:04 +0200 Subject: [PATCH] enable Debug in semver --- src/compiler/semver.ts | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/compiler/semver.ts b/src/compiler/semver.ts index 7013569e801d0..3714a41a9ac65 100644 --- a/src/compiler/semver.ts +++ b/src/compiler/semver.ts @@ -1,6 +1,6 @@ -import { compareStringsCaseSensitive, compareValues, emptyArray, /* every, */ isArray, map, some, trimString } from "./core"; +import { compareStringsCaseSensitive, compareValues, emptyArray, every, isArray, map, some, trimString } from "./core"; import { Comparison } from "./corePublic"; -// import { Debug } from "./debug"; +import { Debug } from "./debug"; // https://semver.org/#spec-item-2 // > A normal version number MUST take the form X.Y.Z where X, Y, and Z are non-negative @@ -17,14 +17,14 @@ const versionRegExp = /^(0|[1-9]\d*)(?:\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*)(?:\-([a-z // > alphanumerics and hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty. Numeric identifiers // > MUST NOT include leading zeroes. const prereleaseRegExp = /^(?:0|[1-9]\d*|[a-z-][a-z0-9-]*)(?:\.(?:0|[1-9]\d*|[a-z-][a-z0-9-]*))*$/i; -// const prereleasePartRegExp = /^(?:0|[1-9]\d*|[a-z-][a-z0-9-]*)$/i; +const prereleasePartRegExp = /^(?:0|[1-9]\d*|[a-z-][a-z0-9-]*)$/i; // https://semver.org/#spec-item-10 // > Build metadata MAY be denoted by appending a plus sign and a series of dot separated // > identifiers immediately following the patch or pre-release version. Identifiers MUST // > comprise only ASCII alphanumerics and hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty. const buildRegExp = /^[a-z0-9-]+(?:\.[a-z0-9-]+)*$/i; -// const buildPartRegExp = /^[a-z0-9-]+$/i; +const buildPartRegExp = /^[a-z0-9-]+$/i; // https://semver.org/#spec-item-9 // > Numeric identifiers MUST NOT include leading zeroes. @@ -48,23 +48,19 @@ export class Version { constructor(major: number, minor?: number, patch?: number, prerelease?: string | readonly string[], build?: string | readonly string[]); constructor(major: number | string, minor = 0, patch = 0, prerelease: string | readonly string[] = "", build: string | readonly string[] = "") { if (typeof major === "string") { - // const result = Debug.checkDefined(tryParseComponents(major), "Invalid version"); - const result = tryParseComponents(major); - if (result === undefined) { - throw "Invalid version"; // eslint-disable-line no-throw-literal - } + const result = Debug.checkDefined(tryParseComponents(major), "Invalid version"); ({ major, minor, patch, prerelease, build } = result); } - // Debug.assert(major >= 0, "Invalid argument: major"); - // Debug.assert(minor >= 0, "Invalid argument: minor"); - // Debug.assert(patch >= 0, "Invalid argument: patch"); + Debug.assert(major >= 0, "Invalid argument: major"); + Debug.assert(minor >= 0, "Invalid argument: minor"); + Debug.assert(patch >= 0, "Invalid argument: patch"); const prereleaseArray = prerelease ? isArray(prerelease) ? prerelease : prerelease.split(".") : emptyArray; const buildArray = build ? isArray(build) ? build : build.split(".") : emptyArray; - // Debug.assert(every(prereleaseArray, s => prereleasePartRegExp.test(s)), "Invalid argument: prerelease"); - // Debug.assert(every(buildArray, s => buildPartRegExp.test(s)), "Invalid argument: build"); + Debug.assert(every(prereleaseArray, s => prereleasePartRegExp.test(s)), "Invalid argument: prerelease"); + Debug.assert(every(buildArray, s => buildPartRegExp.test(s)), "Invalid argument: build"); this.major = major; this.minor = minor; @@ -107,8 +103,7 @@ export class Version { case "major": return new Version(this.major + 1, 0, 0); case "minor": return new Version(this.major, this.minor + 1, 0); case "patch": return new Version(this.major, this.minor, this.patch + 1); - // default: return Debug.assertNever(field); - default: throw field; + default: return Debug.assertNever(field); } } @@ -200,8 +195,7 @@ export class VersionRange { private _alternatives: readonly (readonly Comparator[])[]; constructor(spec: string) { - // this._alternatives = spec ? Debug.checkDefined(parseRange(spec), "Invalid range spec.") : emptyArray; - this._alternatives = spec ? parseRange(spec) || emptyArray : emptyArray; + this._alternatives = spec ? Debug.checkDefined(parseRange(spec), "Invalid range spec.") : emptyArray; } static tryParse(text: string) { @@ -410,8 +404,7 @@ function testComparator(version: Version, operator: Comparator["operator"], oper case ">": return cmp > 0; case ">=": return cmp >= 0; case "=": return cmp === 0; - // default: return Debug.assertNever(operator); - default: throw operator; + default: return Debug.assertNever(operator); } }