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

Put back ESM helpers in a folder where we can use .js #12919

Merged
merged 2 commits into from Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 8 additions & 14 deletions .gitignore
Expand Up @@ -26,24 +26,20 @@ package-lock.json
/packages/babel-compat-data/build

/packages/babel-runtime/helpers/*.js
/packages/babel-runtime/helpers/*/*.js
/packages/babel-runtime/helpers/*/*.mjs
!/packages/babel-runtime/helpers/toArray/*
!/packages/babel-runtime/helpers/iterableToArray/*
!/packages/babel-runtime/helpers/temporalRef/*
!/packages/babel-runtime/helpers/typeof/*
!/packages/babel-runtime/helpers/toArray.js
!/packages/babel-runtime/helpers/iterableToArray.js
!/packages/babel-runtime/helpers/temporalRef.js
!/packages/babel-runtime/helpers/typeof.js
/packages/babel-runtime/helpers/esm/*.js
!/packages/babel-runtime/helpers/esm/toArray.js
!/packages/babel-runtime/helpers/esm/iterableToArray.js
!/packages/babel-runtime/helpers/esm/temporalRef.js

/packages/babel-runtime-corejs2/helpers/*.js
/packages/babel-runtime-corejs2/helpers/*/*.js
/packages/babel-runtime-corejs2/helpers/*/*.mjs
!/packages/babel-runtime-corejs2/helpers/toArray/*
!/packages/babel-runtime-corejs2/helpers/iterableToArray/*
!/packages/babel-runtime-corejs2/helpers/temporalRef/*
!/packages/babel-runtime-corejs2/helpers/typeof/*
!/packages/babel-runtime-corejs2/helpers/toArray.js
!/packages/babel-runtime-corejs2/helpers/iterableToArray.js
!/packages/babel-runtime-corejs2/helpers/temporalRef.js
!/packages/babel-runtime-corejs2/helpers/typeof.js
/packages/babel-runtime-corejs2/helpers/esm/*.js
!/packages/babel-runtime-corejs2/helpers/esm/toArray.js
!/packages/babel-runtime-corejs2/helpers/esm/iterableToArray.js
Expand All @@ -52,8 +48,6 @@ package-lock.json
!/packages/babel-runtime-corejs2/core-js/map.js

/packages/babel-runtime-corejs3/helpers/*.js
/packages/babel-runtime-corejs3/helpers/*/*.js
/packages/babel-runtime-corejs3/helpers/*/*.mjs
/packages/babel-runtime-corejs3/helpers/esm/*.js
/packages/babel-runtime-corejs3/core-js/**/*.js
/packages/babel-runtime-corejs3/core-js-stable/**/*.js
Expand Down
31 changes: 5 additions & 26 deletions packages/babel-plugin-transform-runtime/scripts/build-dist.js
Expand Up @@ -116,7 +116,10 @@ function writeHelperFile(
helperName,
{ esm, corejs }
) {
const filePath = path.join(helperPath, esm ? "_index.mjs" : "index.js");
const fileName = `${helperName}.js`;
const filePath = esm
? path.join("helpers", "esm", fileName)
: path.join("helpers", fileName);
const fullPath = path.join(pkgDirname, filePath);

outputFile(
Expand All @@ -127,12 +130,6 @@ function writeHelperFile(
return `./${filePath}`;
}

function writeHelperLegacyESMFile(pkgDirname, helperName) {
const fullPath = path.join(pkgDirname, "helpers", "esm", `${helperName}.js`);

outputFile(fullPath, `export { default } from "../${helperName}/_index.mjs"`);
}

function writeHelpers(runtimeName, { corejs } = {}) {
const pkgDirname = getRuntimeRoot(runtimeName);
const helperSubExports = {};
Expand Down Expand Up @@ -173,8 +170,6 @@ function writeHelpers(runtimeName, { corejs } = {}) {
];
// For backward compatibility. We can remove this in Babel 8.
helperSubExports[`./${path.join("helpers", "esm", helperName)}`] = esm;

writeHelperLegacyESMFile(pkgDirname, helperName);
}

writeHelperExports(runtimeName, helperSubExports);
Expand Down Expand Up @@ -251,7 +246,6 @@ function buildHelper(
[transformRuntime, { corejs, version: runtimeVersion }],
buildRuntimeRewritePlugin(runtimeName, helperName),
esm ? null : addDefaultCJSExport,
esm ? useRelativeImports : null,
].filter(Boolean),
overrides: [
{
Expand All @@ -272,7 +266,7 @@ function buildRuntimeRewritePlugin(runtimeName, helperName) {
*/
function adjustImportPath(node) {
if (helpers.list.includes(node.value)) {
node.value = `${runtimeName}/helpers/${node.value}`;
node.value = `./${node.value}.js`;
}
}

Expand Down Expand Up @@ -322,18 +316,3 @@ function addDefaultCJSExport({ template }) {
},
};
}

function useRelativeImports() {
const RE = /^@babel\/runtime(?:-corejs[23])?\/helpers\/(?<name>.+)$/;

return {
visitor: {
ImportDeclaration(path) {
path.node.source.value = path.node.source.value.replace(
RE,
"../$<name>/_index.mjs"
);
},
},
};
}
@@ -1 +1,6 @@
export { default } from "../iterableToArray/_index.mjs"
import _Symbol from "@babel/runtime-corejs2/core-js/symbol";
import _isIterable from "@babel/runtime-corejs2/core-js/is-iterable";
import _Array$from from "@babel/runtime-corejs2/core-js/array/from";
export default function _iterableToArray(iter) {
if (typeof _Symbol !== "undefined" && _isIterable(Object(iter))) return _Array$from(iter);
}
6 changes: 5 additions & 1 deletion packages/babel-runtime-corejs2/helpers/esm/temporalRef.js
@@ -1 +1,5 @@
export { default } from "../temporalRef/_index.mjs"
import undef from "./temporalUndefined.js";
import err from "./tdz.js";
export default function _temporalRef(val, name) {
return val === undef ? err(name) : val;
}
8 changes: 7 additions & 1 deletion packages/babel-runtime-corejs2/helpers/esm/toArray.js
@@ -1 +1,7 @@
export { default } from "../toArray/_index.mjs"
import arrayWithHoles from "./arrayWithHoles.js";
import iterableToArray from "./iterableToArray.js";
import unsupportedIterableToArray from "./unsupportedIterableToArray.js";
import nonIterableRest from "./nonIterableRest.js";
export default function _toArray(arr) {
return arrayWithHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableRest();
}

This file was deleted.

@@ -1,6 +1,6 @@
var temporalUndefined = require("@babel/runtime/helpers/temporalUndefined");
var temporalUndefined = require("./temporalUndefined.js");

var tdz = require("@babel/runtime/helpers/tdz");
var tdz = require("./tdz.js");

function _temporalRef(val, name) {
return val === temporalUndefined ? tdz(name) : val;
Expand Down
5 changes: 0 additions & 5 deletions packages/babel-runtime-corejs2/helpers/temporalRef/_index.mjs

This file was deleted.

14 changes: 14 additions & 0 deletions packages/babel-runtime-corejs2/helpers/toArray.js
@@ -0,0 +1,14 @@
var arrayWithHoles = require("./arrayWithHoles.js");

var iterableToArray = require("./iterableToArray.js");

var unsupportedIterableToArray = require("./unsupportedIterableToArray.js");

var nonIterableRest = require("./nonIterableRest.js");

function _toArray(arr) {
return arrayWithHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableRest();
}

module.exports = _toArray;
module.exports["default"] = module.exports, module.exports.__esModule = true;
7 changes: 0 additions & 7 deletions packages/babel-runtime-corejs2/helpers/toArray/_index.mjs

This file was deleted.

14 changes: 0 additions & 14 deletions packages/babel-runtime-corejs2/helpers/toArray/index.js

This file was deleted.

17 changes: 0 additions & 17 deletions packages/babel-runtime-corejs2/helpers/typeof/_index.mjs

This file was deleted.