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

fix: pass optionLoc when validating plugin object #10402

Merged
merged 1 commit into from Sep 11, 2019
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
3 changes: 2 additions & 1 deletion packages/babel-core/src/config/validation/options.js
Expand Up @@ -272,7 +272,8 @@ export type OptionsSource =
| "configfile"
| "babelrcfile"
| "extendsfile"
| "preset";
| "preset"
| "plugin";

type RootPath = $ReadOnly<{
type: "root",
Expand Down
11 changes: 10 additions & 1 deletion packages/babel-core/src/config/validation/plugins.js
Expand Up @@ -84,10 +84,19 @@ export type PluginObject = {
};

export function validatePluginObject(obj: {}): PluginObject {
const rootPath: RootPath = {
type: "root",
source: "plugin",
};
Object.keys(obj).forEach(key => {
const validator = VALIDATORS[key];
const optLoc = {
type: "option",
name: key,
parent: rootPath,
};

if (validator) validator(key, obj[key]);
if (validator) validator(optLoc, obj[key]);
else throw new Error(`.${key} is not a valid Plugin property`);
});

Expand Down
15 changes: 15 additions & 0 deletions packages/babel-core/test/config-loading.js
Expand Up @@ -322,6 +322,21 @@ describe("@babel/core config loading", () => {
}
}
});

it("should thrown when plugin is not valid", () => {
const fooPlugin = {
inherits: "inhertis-should-not-be-string",
};
const opts = {
cwd: path.dirname(FILEPATH),
filename: FILEPATH,
plugins: [fooPlugin],
};

expect(() => loadConfig(opts)).toThrow(
/\.inherits must be a function, or undefined/,
);
});
});

describe("caller metadata", () => {
Expand Down