Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop core-js 2 support #11751

Merged
merged 11 commits into from Jul 1, 2020
16 changes: 0 additions & 16 deletions packages/babel-plugin-transform-runtime/scripts/build-dist.js
Expand Up @@ -10,33 +10,17 @@ const t = require("@babel/types");
const transformRuntime = require("../");

const runtimeVersion = require("@babel/runtime/package.json").version;
const corejs2Definitions = require("../lib/runtime-corejs2-definitions").default();
const corejs3Definitions = require("../lib/runtime-corejs3-definitions").default();
const outputFileSync = function (filePath, data) {
fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, data);
};

writeHelpers("@babel/runtime");
writeHelpers("@babel/runtime-corejs2", { corejs: 2 });
writeHelpers("@babel/runtime-corejs3", {
corejs: { version: 3, proposals: true },
});

writeCoreJS({
corejs: 2,
proposals: true,
definitions: corejs2Definitions,
paths: [
"is-iterable",
"get-iterator",
// This was previously in definitions, but was removed to work around
// zloirock/core-js#262. We need to keep it in @babel/runtime-corejs2 to
// avoid a breaking change there.
"symbol/async-iterator",
],
corejsRoot: "core-js/library/fn",
});
writeCoreJS({
corejs: 3,
proposals: false,
Expand Down
35 changes: 17 additions & 18 deletions packages/babel-plugin-transform-runtime/src/index.js
Expand Up @@ -2,7 +2,6 @@ import { declare } from "@babel/helper-plugin-utils";
import { addDefault, isModule } from "@babel/helper-module-imports";
import { types as t } from "@babel/core";

import getCoreJS2Definitions from "./runtime-corejs2-definitions";
import getCoreJS3Definitions from "./runtime-corejs3-definitions";
import { typeAnnotationToString } from "./helpers";
import getRuntimePath from "./get-runtime-path";
Expand Down Expand Up @@ -35,15 +34,21 @@ export default declare((api, options, dirname) => {

const corejsVersion = rawVersion ? Number(rawVersion) : false;

if (![false, 2, 3].includes(corejsVersion)) {
if (corejsVersion === 2) {
throw new Error(
`The \`core-js\` version must be false, 2 or 3, but got ${JSON.stringify(
"Since Babel 8, the core-js 2 support has been dropped. Please use 'corejs: 3'.",
JLHwung marked this conversation as resolved.
Show resolved Hide resolved
);
}

if (![false, 3].includes(corejsVersion)) {
throw new Error(
`The \`core-js\` version must be false or 3, but got ${JSON.stringify(
rawVersion,
)}.`,
);
}

if (proposals && (!corejsVersion || corejsVersion < 3)) {
if (proposals && !corejsVersion) {
throw new Error(
"The 'proposals' option is only supported when using 'corejs: 3'",
JLHwung marked this conversation as resolved.
Show resolved Hide resolved
);
Expand Down Expand Up @@ -158,21 +163,17 @@ export default declare((api, options, dirname) => {
const esModules =
useESModules === "auto" ? api.caller(supportsStaticESM) : useESModules;

const injectCoreJS2 = corejsVersion === 2;
const injectCoreJS3 = corejsVersion === 3;
const injectCoreJS = corejsVersion !== false;

const moduleName = injectCoreJS3
? "@babel/runtime-corejs3"
: injectCoreJS2
? "@babel/runtime-corejs2"
: "@babel/runtime";
const moduleName = injectCoreJS ? "@babel/runtime-corejs3" : "@babel/runtime";

const corejsRoot = injectCoreJS3 && !proposals ? "core-js-stable" : "core-js";
const corejsRoot = injectCoreJS && !proposals ? "core-js-stable" : "core-js";

const { BuiltIns, StaticProperties, InstanceProperties } = (injectCoreJS2
? getCoreJS2Definitions
: getCoreJS3Definitions)(runtimeVersion);
const {
BuiltIns,
StaticProperties,
InstanceProperties,
} = getCoreJS3Definitions(runtimeVersion);

const HEADER_HELPERS = ["interopRequireWildcard", "interopRequireDefault"];

Expand Down Expand Up @@ -286,7 +287,7 @@ export default declare((api, options, dirname) => {
);

// transform calling instance methods like `something.includes()`
if (injectCoreJS3 && !hasStaticMapping(object.name, propertyName)) {
if (injectCoreJS && !hasStaticMapping(object.name, propertyName)) {
if (
hasMapping(InstanceProperties, propertyName) &&
maybeNeedsPolyfill(
Expand Down Expand Up @@ -368,7 +369,6 @@ export default declare((api, options, dirname) => {

// transform `something[Symbol.iterator]` to calling `getIteratorMethod(something)` helper
if (
!injectCoreJS2 &&
node.computed &&
path.get("property").matchesPattern("Symbol.iterator")
) {
Expand Down Expand Up @@ -396,7 +396,6 @@ export default declare((api, options, dirname) => {
) {
// transform getting of instance methods like `method = something.includes`
if (
injectCoreJS3 &&
hasMapping(InstanceProperties, propertyName) &&
maybeNeedsPolyfill(path, InstanceProperties, propertyName)
) {
Expand Down

This file was deleted.