Better error messaging when preset options are given without a corresponding preset (#4685)

This commit is contained in:
Kai Cataldo
2016-10-11 10:56:53 -04:00
committed by Daniel Tschinder
parent 760bbd6014
commit 27ee74ea14
2 changed files with 16 additions and 3 deletions

View File

@@ -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);
}
}
}

View File

@@ -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 () {