Skip to content

Commit

Permalink
Fixed null error in plugin opts and added a test for it (#9945)
Browse files Browse the repository at this point in the history
* Fixed null error in plugin opts and added a test for it

* Remove !opts and add opts === null check to avoid confusion with false and undefined cases

Co-Authored-By: divbhasin <divbest99@gmail.com>
  • Loading branch information
divbhasin authored and nicolo-ribaudo committed May 7, 2019
1 parent 354666a commit 7942dc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Expand Up @@ -337,7 +337,7 @@ function assertPluginItem(loc: GeneralPath, value: mixed): PluginItem {
if (
opts !== undefined &&
opts !== false &&
(typeof opts !== "object" || Array.isArray(opts))
(typeof opts !== "object" || Array.isArray(opts) || opts === null)
) {
throw new Error(
`${msg(access(loc, 1))} must be an object, false, or undefined`,
Expand Down
12 changes: 11 additions & 1 deletion packages/babel-core/test/option-manager.js
Expand Up @@ -38,6 +38,17 @@ describe("option-manager", () => {
expect(calls).toEqual([]);
});

it("throws for null options", () => {
const { calls, plugin } = makePlugin();
expect(() => {
loadOptions({
plugins: [[plugin, null]],
}).toThrow(/.plugins[0][1] must be an object, false, or undefined/);
});

expect(calls).toEqual([]);
});

it("should not throw if a repeated plugin has a different name", () => {
const { calls: calls1, plugin: plugin1 } = makePlugin();
const { calls: calls2, plugin: plugin2 } = makePlugin();
Expand Down Expand Up @@ -87,7 +98,6 @@ describe("option-manager", () => {
expect(calls1).toEqual([{ arg: 1 }]);
expect(calls2).toEqual([{ arg: 2 }]);
});

it("should merge .env[] presets with parent presets", () => {
const { calls: calls1, plugin: preset1 } = makePlugin();
const { calls: calls2, plugin: preset2 } = makePlugin();
Expand Down

0 comments on commit 7942dc0

Please sign in to comment.