Skip to content

Commit

Permalink
Fix esmodules: true without specified browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Feb 25, 2021
1 parent bb558aa commit be5576e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 1 deletion.
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" || !shouldParseBrowsers)) {
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;

0 comments on commit be5576e

Please sign in to comment.