Skip to content

Commit

Permalink
Fix backward compat for semver checks in class&regexp feat plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed May 2, 2023
1 parent 93d7808 commit 6e65320
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -96,6 +96,15 @@ export function createClassFeaturePlugin({
pre(file) {
enableFeature(file, feature, loose);

if (process.env.BABEL_8_BREAKING) {
// Until 7.21.4, we used to encode the version as a number.
// If file.get(versionKey) is a number, it has thus been
// set by an older version of this plugin.
if (typeof file.get(versionKey) === "number") {
file.set(versionKey, PACKAGE_JSON.version);
return;
}
}
if (
!file.get(versionKey) ||
semver.lt(file.get(versionKey), PACKAGE_JSON.version)
Expand Down
11 changes: 10 additions & 1 deletion packages/babel-helper-create-regexp-features-plugin/src/index.ts
Expand Up @@ -82,8 +82,17 @@ export function createRegExpFeaturePlugin({
}
}

if (process.env.BABEL_8_BREAKING) {
// Until 7.21.4, we used to encode the version as a number.
// If file.get(versionKey) is a number, it has thus been
// set by an older version of this plugin.
if (typeof file.get(versionKey) === "number") {
file.set(versionKey, PACKAGE_JSON.version);
return;
}
}
if (
!file.has(versionKey) ||
!file.get(versionKey) ||
semver.lt(file.get(versionKey), PACKAGE_JSON.version)
) {
file.set(versionKey, PACKAGE_JSON.version);
Expand Down

0 comments on commit 6e65320

Please sign in to comment.