Fix esmodules: true without specified browsers (#12908)
* Fix `esmodules: true` without specified browsers * fix
This commit is contained in:
parent
82e089c7dd
commit
0d9ad433b4
3
config.js
Normal file
3
config.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
targets: { esmodules: true },
|
||||||
|
};
|
||||||
@ -205,7 +205,7 @@ export default function getTargets(
|
|||||||
|
|
||||||
// `esmodules` as a target indicates the specific set of browsers supporting ES Modules.
|
// `esmodules` as a target indicates the specific set of browsers supporting ES Modules.
|
||||||
// These values OVERRIDE the `browsers` field.
|
// These values OVERRIDE the `browsers` field.
|
||||||
if (esmodules && (esmodules !== "intersect" || !browsers)) {
|
if (esmodules && (esmodules !== "intersect" || !browsers?.length)) {
|
||||||
browsers = Object.keys(ESM_SUPPORT)
|
browsers = Object.keys(ESM_SUPPORT)
|
||||||
.map(browser => `${browser} >= ${ESM_SUPPORT[browser]}`)
|
.map(browser => `${browser} >= ${ESM_SUPPORT[browser]}`)
|
||||||
.join(", ");
|
.join(", ");
|
||||||
|
|||||||
@ -267,6 +267,12 @@ describe("getTargets", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("'intersect' behaves like 'true' if no browsers are specified", () => {
|
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(
|
expect(
|
||||||
getTargets(
|
getTargets(
|
||||||
{ esmodules: "intersect" },
|
{ esmodules: "intersect" },
|
||||||
|
|||||||
1
packages/babel-preset-env/test/fixtures/sanity/top-level-targets-esmodules/input.js
vendored
Normal file
1
packages/babel-preset-env/test/fixtures/sanity/top-level-targets-esmodules/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
a ** b;
|
||||||
4
packages/babel-preset-env/test/fixtures/sanity/top-level-targets-esmodules/options.json
vendored
Normal file
4
packages/babel-preset-env/test/fixtures/sanity/top-level-targets-esmodules/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"targets": { "esmodules": true },
|
||||||
|
"presets": ["env"]
|
||||||
|
}
|
||||||
1
packages/babel-preset-env/test/fixtures/sanity/top-level-targets-esmodules/output.js
vendored
Normal file
1
packages/babel-preset-env/test/fixtures/sanity/top-level-targets-esmodules/output.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
a ** b;
|
||||||
Loading…
x
Reference in New Issue
Block a user