Skip to content

Commit

Permalink
Fix compatibility with old @babel/core (caught by the e2e test)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Apr 8, 2021
1 parent ff6ceee commit 96b0184
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/babel-preset-env/src/available-plugins.js
Expand Up @@ -142,3 +142,7 @@ export default {
"transform-unicode-escapes": () => transformUnicodeEscapes,
"transform-unicode-regex": () => transformUnicodeRegex,
};

export const minVersions = {
"proposal-class-static-block": "7.12.0",
};
15 changes: 15 additions & 0 deletions packages/babel-preset-env/src/filter-items.js
@@ -1,5 +1,10 @@
// @flow

import { lt } from "semver";
import { minVersions } from "./available-plugins";

const has = Function.call.bind(Object.hasOwnProperty);

export function removeUnnecessaryItems(
items: Set<string>,
overlapping: { [name: string]: string[] },
Expand All @@ -8,3 +13,13 @@ export function removeUnnecessaryItems(
overlapping[item]?.forEach(name => items.delete(name));
});
}
export function removeUnsupportedItems(
items: Set<string>,
babelVersion: string,
) {
items.forEach(item => {
if (has(minVersions, item) && lt(babelVersion, minVersions[item])) {
items.delete(item);
}
});
}
3 changes: 2 additions & 1 deletion packages/babel-preset-env/src/index.js
Expand Up @@ -3,7 +3,7 @@
import { SemVer, lt } from "semver";
import { logPlugin } from "./debug";
import getOptionSpecificExcludesFor from "./get-option-specific-excludes";
import { removeUnnecessaryItems } from "./filter-items";
import { removeUnnecessaryItems, removeUnsupportedItems } from "./filter-items";
import moduleTransformations from "./module-transformations";
import normalizeOptions from "./normalize-options";
import { proposalPlugins, pluginSyntaxMap } from "../data/shipped-proposals";
Expand Down Expand Up @@ -374,6 +374,7 @@ option \`forceAllTransforms: true\` instead.
pluginSyntaxMap,
);
removeUnnecessaryItems(pluginNames, overlappingPlugins);
removeUnsupportedItems(pluginNames, api.version);

const polyfillPlugins = getPolyfillPlugins({
useBuiltIns,
Expand Down

0 comments on commit 96b0184

Please sign in to comment.