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

Fix esmodules: true without specified browsers #12908

Merged
merged 2 commits into from Mar 2, 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
3 changes: 3 additions & 0 deletions config.js
@@ -0,0 +1,3 @@
module.exports = {
targets: { esmodules: true },
};
2 changes: 1 addition & 1 deletion packages/babel-helper-compilation-targets/src/index.js
Expand Up @@ -205,7 +205,7 @@ export default function getTargets(

// `esmodules` as a target indicates the specific set of browsers supporting ES Modules.
// These values OVERRIDE the `browsers` field.
if (esmodules && (esmodules !== "intersect" || !browsers)) {
if (esmodules && (esmodules !== "intersect" || !browsers?.length)) {
browsers = Object.keys(ESM_SUPPORT)
.map(browser => `${browser} >= ${ESM_SUPPORT[browser]}`)
.join(", ");
Expand Down
Expand Up @@ -267,6 +267,12 @@ describe("getTargets", () => {
});

it("'intersect' behaves like 'true' if no browsers are specified", () => {
expect(getTargets({ esmodules: "intersect" })).toEqual(
getTargets({ esmodules: true }, { ignoreBrowserslistConfig: true }),
);
});

it("'intersect' behaves like 'true' if no browsers are specified and the browserslist config is ignored", () => {
expect(
getTargets(
{ esmodules: "intersect" },
Expand Down
@@ -0,0 +1 @@
a ** b;
@@ -0,0 +1,4 @@
{
"targets": { "esmodules": true },
"presets": ["env"]
}
@@ -0,0 +1 @@
a ** b;