Better error messaging when preset options are given without a corresponding preset (#4685)
This commit is contained in:
committed by
Daniel Tschinder
parent
760bbd6014
commit
27ee74ea14
@@ -178,12 +178,13 @@ export default class OptionManager {
|
||||
|
||||
// check for an unknown option
|
||||
if (!option && this.log) {
|
||||
let pluginOptsInfo = "Check out http://babeljs.io/docs/usage/options/ for more info";
|
||||
|
||||
if (removed[key]) {
|
||||
this.log.error(`Using removed Babel 5 option: ${alias}.${key} - ${removed[key].message}`, ReferenceError);
|
||||
} else {
|
||||
this.log.error(`Unknown option: ${alias}.${key}. ${pluginOptsInfo}`, ReferenceError);
|
||||
let unknownOptErr = `Unknown option: ${alias}.${key}. Check out http://babeljs.io/docs/usage/options/ for more information about options.`;
|
||||
let presetConfigErr = `A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:\n\nInvalid:\n \`{ presets: [{option: value}] }\`\nValid:\n \`{ presets: ['pluginName', {option: value}] }\`\n\nFor more detailed information on preset configuration, please see http://babeljs.io/docs/plugins/#pluginpresets-options.`;
|
||||
|
||||
this.log.error(`${unknownOptErr}\n\n${presetConfigErr}`, ReferenceError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,18 @@ suite("option-manager", function () {
|
||||
/While processing preset: .*option-manager(?:\/|\\\\)not-a-preset\.js/
|
||||
);
|
||||
});
|
||||
|
||||
test("throws for invalid preset configuration", function() {
|
||||
return assert.throws(
|
||||
function () {
|
||||
var opt = new OptionManager(new Logger(null, "unknown"));
|
||||
opt.init({
|
||||
'presets': [{ option: "value" }]
|
||||
});
|
||||
},
|
||||
/Unknown option: foreign.option\.(?:.|\n)+A common cause of this error is the presence of a configuration options object without the corresponding preset name/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
suite("presets", function () {
|
||||
|
||||
Reference in New Issue
Block a user