Fix handling scoped packages in preset-env include/exclude options (#9219)
This commit is contained in:
parent
3f9a1c08cc
commit
ea1c436ea1
@ -76,7 +76,7 @@ const validBrowserslistTargets = [
|
||||
];
|
||||
|
||||
export const normalizePluginName = (plugin: string): string =>
|
||||
plugin.replace(/^babel-plugin-/, "");
|
||||
plugin.replace(/^(@babel\/|babel-)(plugin-)?/, "");
|
||||
|
||||
export const checkDuplicateIncludeExcludes = (
|
||||
include: Array<string> = [],
|
||||
|
||||
1
packages/babel-preset-env/test/fixtures/preset-options/include-scoped/input.mjs
vendored
Normal file
1
packages/babel-preset-env/test/fixtures/preset-options/include-scoped/input.mjs
vendored
Normal file
@ -0,0 +1 @@
|
||||
class Foo {}
|
||||
14
packages/babel-preset-env/test/fixtures/preset-options/include-scoped/options.json
vendored
Normal file
14
packages/babel-preset-env/test/fixtures/preset-options/include-scoped/options.json
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"presets": [
|
||||
[
|
||||
"../../../../lib",
|
||||
{
|
||||
"targets": {
|
||||
"chrome": 61
|
||||
},
|
||||
"include": ["@babel/plugin-transform-classes"],
|
||||
"modules": false
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
5
packages/babel-preset-env/test/fixtures/preset-options/include-scoped/output.mjs
vendored
Normal file
5
packages/babel-preset-env/test/fixtures/preset-options/include-scoped/output.mjs
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
let Foo = function Foo() {
|
||||
_classCallCheck(this, Foo);
|
||||
};
|
||||
@ -12,11 +12,30 @@ describe("normalize-options", () => {
|
||||
describe("normalizeOptions", () => {
|
||||
it("should return normalized `include` and `exclude`", () => {
|
||||
const normalized = normalizeOptions.default({
|
||||
include: ["babel-plugin-transform-spread", "transform-classes"],
|
||||
include: [
|
||||
"babel-plugin-transform-spread",
|
||||
"transform-classes",
|
||||
"@babel/plugin-transform-unicode-regex",
|
||||
"@babel/transform-block-scoping",
|
||||
],
|
||||
exclude: [
|
||||
"babel-plugin-transform-for-of",
|
||||
"transform-parameters",
|
||||
"@babel/plugin-transform-regenerator",
|
||||
"@babel/transform-new-target",
|
||||
],
|
||||
});
|
||||
expect(normalized.include).toEqual([
|
||||
"transform-spread",
|
||||
"transform-classes",
|
||||
"transform-unicode-regex",
|
||||
"transform-block-scoping",
|
||||
]);
|
||||
expect(normalized.exclude).toEqual([
|
||||
"transform-for-of",
|
||||
"transform-parameters",
|
||||
"transform-regenerator",
|
||||
"transform-new-target",
|
||||
]);
|
||||
});
|
||||
|
||||
@ -25,15 +44,26 @@ describe("normalize-options", () => {
|
||||
expect(normalized).toBe("prefix-babel-plugin-postfix");
|
||||
});
|
||||
|
||||
it("should throw if duplicate names in `include` and `exclude`", () => {
|
||||
const normalizeWithSameIncludes = () => {
|
||||
normalizeOptions.default({
|
||||
include: ["babel-plugin-transform-spread"],
|
||||
exclude: ["transform-spread"],
|
||||
});
|
||||
};
|
||||
expect(normalizeWithSameIncludes).toThrow();
|
||||
});
|
||||
test.each`
|
||||
include | exclude
|
||||
${["babel-plugin-transform-spread"]} | ${["transform-spread"]}
|
||||
${["@babel/plugin-transform-spread"]} | ${["transform-spread"]}
|
||||
${["transform-spread"]} | ${["babel-plugin-transform-spread"]}
|
||||
${["transform-spread"]} | ${["@babel/plugin-transform-spread"]}
|
||||
${["babel-plugin-transform-spread"]} | ${["@babel/plugin-transform-spread"]}
|
||||
${["@babel/plugin-transform-spread"]} | ${["babel-plugin-transform-spread"]}
|
||||
${["@babel/plugin-transform-spread"]} | ${["@babel/transform-spread"]}
|
||||
${["@babel/transform-spread"]} | ${["@babel/plugin-transform-spread"]}
|
||||
${["babel-plugin-transform-spread"]} | ${["@babel/transform-spread"]}
|
||||
${["@babel/transform-spread"]} | ${["babel-plugin-transform-spread"]}
|
||||
`(
|
||||
"should throw if with includes $include and excludes $exclude",
|
||||
({ include, exclude }) => {
|
||||
expect(() =>
|
||||
normalizeOptions.default({ include, exclude }),
|
||||
).toThrowError(/were found in both/);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("Config format validation", () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user