fix: pass optionLoc when validating plugin object (#10402)
This commit is contained in:
parent
98b14843ba
commit
af04f40ee0
@ -272,7 +272,8 @@ export type OptionsSource =
|
||||
| "configfile"
|
||||
| "babelrcfile"
|
||||
| "extendsfile"
|
||||
| "preset";
|
||||
| "preset"
|
||||
| "plugin";
|
||||
|
||||
type RootPath = $ReadOnly<{
|
||||
type: "root",
|
||||
|
||||
@ -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`);
|
||||
});
|
||||
|
||||
|
||||
@ -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", () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user