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

Fixed useBuiltIns and modules validation when using 'false' as option #11373

Merged
merged 2 commits into from Apr 3, 2020
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
5 changes: 2 additions & 3 deletions packages/babel-preset-env/src/normalize-options.js
Expand Up @@ -167,8 +167,7 @@ export const validateModulesOption = (
modulesOpt: ModuleOption = ModulesOption.auto,
) => {
invariant(
ModulesOption[modulesOpt.toString()] ||
ModulesOption[modulesOpt.toString()] === ModulesOption.false,
ModulesOption[modulesOpt.toString()] || modulesOpt === ModulesOption.false,
`Invalid Option: The 'modules' option must be one of \n` +
` - 'false' to indicate no module processing\n` +
` - a specific module type: 'commonjs', 'amd', 'umd', 'systemjs'` +
Expand All @@ -184,7 +183,7 @@ export const validateUseBuiltInsOption = (
) => {
invariant(
UseBuiltInsOption[builtInsOpt.toString()] ||
UseBuiltInsOption[builtInsOpt.toString()] === UseBuiltInsOption.false,
builtInsOpt === UseBuiltInsOption.false,
`Invalid Option: The 'useBuiltIns' option must be either
'false' (default) to indicate no polyfill,
'"entry"' to indicate replacing the entry polyfill, or
Expand Down
27 changes: 27 additions & 0 deletions packages/babel-preset-env/test/normalize-options.spec.js
Expand Up @@ -6,6 +6,7 @@ const {
checkDuplicateIncludeExcludes,
validateBoolOption,
validateModulesOption,
validateUseBuiltInsOption,
normalizePluginName,
} = normalizeOptions;
describe("normalize-options", () => {
Expand Down Expand Up @@ -242,10 +243,36 @@ describe("normalize-options", () => {
}).toThrow();
});

it("`'false'` option is invalid", () => {
expect(() => {
validateModulesOption("false");
}).toThrow();
});

it("array option is invalid", () => {
expect(() => {
validateModulesOption([]);
}).toThrow();
});
});

describe("validateUseBuiltInsOptions", () => {
it("usage option is valid", () => {
expect(validateUseBuiltInsOption("usage")).toBe("usage");
});

it("entry option is valid", () => {
expect(validateUseBuiltInsOption("entry")).toBe("entry");
});

it("`false` option returns false", () => {
expect(validateUseBuiltInsOption(false)).toBe(false);
});

it("`'false'` option is invalid", () => {
expect(() => {
validateUseBuiltInsOption("false");
}).toThrow();
});
});
});