Skip to content

Commit

Permalink
fix: validate plugin object in assertNoUnwrappedItemOptionPairs
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jan 7, 2020
1 parent f922c1e commit d796628
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/babel-core/src/config/validation/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
type Validator,
type OptionPath,
} from "./option-assertions";
import { validatePluginObject } from "./plugins";

const ROOT_VALIDATORS: ValidatorSet = {
cwd: (assertString: Validator<$PropertyType<ValidatedOptions, "cwd">>),
Expand Down Expand Up @@ -451,7 +452,9 @@ export function assertNoUnwrappedItemOptionPairs(
!Array.isArray(items[1])
) {
try {
validate(type, items[1]);
type === "preset"
? validate(type, items[1])
: validatePluginObject(items[1]);
} catch (e) {
throw new Error(
`.${type}[1] is not a valid ${type}. Maybe you meant to use\n` +
Expand Down
12 changes: 12 additions & 0 deletions packages/babel-core/test/option-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ describe("option-manager", () => {
}).toThrowErrorMatchingSnapshot();
});

it("should not throw when a preset string followed by valid preset object", () => {
const { plugin } = makePlugin("my-plugin");
expect(
loadOptions({
presets: [
"@babel/env",
{ plugins: [[plugin, undefined, "my-plugin"]] },
],
}),
).toBeTruthy();
});

it("should throw if a plugin is repeated, with information about the repeated plugin", () => {
const { calls, plugin } = makePlugin("my-plugin");

Expand Down

0 comments on commit d796628

Please sign in to comment.