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 =>
|
export const normalizePluginName = (plugin: string): string =>
|
||||||
plugin.replace(/^babel-plugin-/, "");
|
plugin.replace(/^(@babel\/|babel-)(plugin-)?/, "");
|
||||||
|
|
||||||
export const checkDuplicateIncludeExcludes = (
|
export const checkDuplicateIncludeExcludes = (
|
||||||
include: Array<string> = [],
|
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", () => {
|
describe("normalizeOptions", () => {
|
||||||
it("should return normalized `include` and `exclude`", () => {
|
it("should return normalized `include` and `exclude`", () => {
|
||||||
const normalized = normalizeOptions.default({
|
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([
|
expect(normalized.include).toEqual([
|
||||||
"transform-spread",
|
"transform-spread",
|
||||||
"transform-classes",
|
"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");
|
expect(normalized).toBe("prefix-babel-plugin-postfix");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw if duplicate names in `include` and `exclude`", () => {
|
test.each`
|
||||||
const normalizeWithSameIncludes = () => {
|
include | exclude
|
||||||
normalizeOptions.default({
|
${["babel-plugin-transform-spread"]} | ${["transform-spread"]}
|
||||||
include: ["babel-plugin-transform-spread"],
|
${["@babel/plugin-transform-spread"]} | ${["transform-spread"]}
|
||||||
exclude: ["transform-spread"],
|
${["transform-spread"]} | ${["babel-plugin-transform-spread"]}
|
||||||
});
|
${["transform-spread"]} | ${["@babel/plugin-transform-spread"]}
|
||||||
};
|
${["babel-plugin-transform-spread"]} | ${["@babel/plugin-transform-spread"]}
|
||||||
expect(normalizeWithSameIncludes).toThrow();
|
${["@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", () => {
|
describe("Config format validation", () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user