From 2d6f8320ee3e39a480440ff10843ec22f70c10c3 Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Tue, 29 Nov 2022 06:17:50 +0800 Subject: [PATCH] improve --- .../babel-helper-compilation-targets/src/utils.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/babel-helper-compilation-targets/src/utils.ts b/packages/babel-helper-compilation-targets/src/utils.ts index 4fba5a5c7959..984eba747df1 100644 --- a/packages/babel-helper-compilation-targets/src/utils.ts +++ b/packages/babel-helper-compilation-targets/src/utils.ts @@ -29,11 +29,14 @@ export function semverify(version: number | string): string { `'${version}' is not a valid version`, ); - const split = version.toString().split("."); - while (split.length < 3) { - split.push("0"); + version = version.toString(); + + let pos = 0; + let num = 0; + while ((pos = version.indexOf(".", pos + 1)) > 0) { + num++; } - return split.join("."); + return version + ".0".repeat(2 - num); } export function isUnreleasedVersion(