Merge pull request #22981 from a-tarasyuk/bug/advanced-options-do-not-work-with---init

Allow using Advanced_Options with --init
This commit is contained in:
Mohamed Hegazy
2018-03-30 09:22:49 -07:00
committed by GitHub
3 changed files with 75 additions and 1 deletions

View File

@@ -1341,12 +1341,21 @@ namespace ts {
return Array(paddingLength + 1).join(" ");
}
function isAllowedOption({ category, name }: CommandLineOption): boolean {
// Skip options which do not have a category or have category `Command_line_Options`
// Exclude all possible `Advanced_Options` in tsconfig.json which were NOT defined in command line
return category !== undefined
&& category !== Diagnostics.Command_line_Options
&& (category !== Diagnostics.Advanced_Options || compilerOptionsMap.has(name));
}
function writeConfigurations() {
// Filter applicable options to place in the file
const categorizedOptions = createMultiMap<CommandLineOption>();
for (const option of optionDeclarations) {
const { category } = option;
if (category !== undefined && category !== Diagnostics.Command_line_Options && category !== Diagnostics.Advanced_Options) {
if (isAllowedOption(option)) {
categorizedOptions.add(getLocaleSpecificMessage(category), option);
}
}

View File

@@ -30,5 +30,7 @@ namespace ts {
initTSConfigCorrectly("Initialized TSConfig with incorrect compiler option", ["--init", "--someNonExistOption"]);
initTSConfigCorrectly("Initialized TSConfig with incorrect compiler option value", ["--init", "--lib", "nonExistLib,es5,es2015.promise"]);
initTSConfigCorrectly("Initialized TSConfig with advanced options", ["--init", "--declaration", "--declarationDir", "lib", "--skipLibCheck", "--noErrorTruncation"]);
});
}