diff --git a/internal/core/compileroptions.go b/internal/core/compileroptions.go index 074532d3a6..b6d91351bc 100644 --- a/internal/core/compileroptions.go +++ b/internal/core/compileroptions.go @@ -134,6 +134,8 @@ type CompilerOptions struct { Watch Tristate `json:"watch,omitzero"` ShowConfig Tristate `json:"showConfig,omitzero"` TscBuild Tristate `json:"tscBuild,omitzero"` + Help Tristate `json:"help,omitzero"` + All Tristate `json:"all,omitzero"` } func (options *CompilerOptions) GetEmitScriptTarget() ScriptTarget { diff --git a/internal/execute/outputs.go b/internal/execute/outputs.go index 18e17a2350..c51e70f6f9 100644 --- a/internal/execute/outputs.go +++ b/internal/execute/outputs.go @@ -2,6 +2,7 @@ package execute import ( "fmt" + "slices" "strings" "github.com/microsoft/typescript-go/internal/ast" @@ -9,6 +10,7 @@ import ( "github.com/microsoft/typescript-go/internal/compiler/diagnostics" "github.com/microsoft/typescript-go/internal/core" "github.com/microsoft/typescript-go/internal/diagnosticwriter" + "github.com/microsoft/typescript-go/internal/tsoptions" "github.com/microsoft/typescript-go/internal/tspath" ) @@ -85,3 +87,186 @@ func printVersion(sys System) { fmt.Fprint(sys.Writer(), diagnostics.Version_0.Format(core.Version)+sys.NewLine()) sys.EndWrite() } + +func printHelp(sys System, commandLine *tsoptions.ParsedCommandLine) { + if commandLine.CompilerOptions().All.IsFalseOrUnknown() { + printEasyHelp(sys, getOptionsForHelp(commandLine)) + } else { + // !!! printAllHelp(sys, getOptionsForHelp(commandLine)) + } +} + +func getOptionsForHelp(commandLine *tsoptions.ParsedCommandLine) []*tsoptions.CommandLineOption { + // Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch") + opts := slices.Clone(tsoptions.OptionsDeclarations) + opts = append(opts, &tsoptions.TscBuildOption) + + if commandLine.CompilerOptions().All.IsTrue() { + slices.SortFunc(opts, func(a, b *tsoptions.CommandLineOption) int { + return strings.Compare(strings.ToLower(a.Name), strings.ToLower(b.Name)) + }) + return opts + } else { + return core.Filter(opts, func(opt *tsoptions.CommandLineOption) bool { + return opt.ShowInSimplifiedHelpView + }) + } +} + +func getHeader(sys System, message string) []string { + // !!! const colors = createColors(sys); + var header []string + // !!! terminalWidth := sys.GetWidthOfTerminal?.() ?? 0 + const tsIconLength = 5 + + // const tsIconFirstLine = colors.blueBackground("".padStart(tsIconLength)); + // const tsIconSecondLine = colors.blueBackground(colors.brightWhite("TS ".padStart(tsIconLength))); + // // If we have enough space, print TS icon. + // if (terminalWidth >= message.length + tsIconLength) { + // // right align of the icon is 120 at most. + // const rightAlign = terminalWidth > 120 ? 120 : terminalWidth; + // const leftAlign = rightAlign - tsIconLength; + // header.push(message.padEnd(leftAlign) + tsIconFirstLine + sys.newLine); + // header.push("".padStart(leftAlign) + tsIconSecondLine + sys.newLine); + // } + // else { + header = append(header, message+sys.NewLine(), sys.NewLine()) + // } + return header +} + +func printEasyHelp(sys System, simpleOptions []*tsoptions.CommandLineOption) { + // !!! const colors = createColors(sys); + var output []string + example := func(examples []string, desc *diagnostics.Message) { + for _, example := range examples { + // !!! colors + // output.push(" " + colors.blue(example) + sys.newLine); + output = append(output, " ", example, sys.NewLine()) + } + output = append(output, " ", desc.Format(), sys.NewLine(), sys.NewLine()) + } + + msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Format() + " - " + diagnostics.Version_0.Format(core.Version) + output = append(output, getHeader(sys, msg)...) + + output = append(output /*colors.bold(*/, diagnostics.COMMON_COMMANDS.Format() /*)*/, sys.NewLine(), sys.NewLine()) + + example([]string{"tsc"}, diagnostics.Compiles_the_current_project_tsconfig_json_in_the_working_directory) + example([]string{"tsc app.ts util.ts"}, diagnostics.Ignoring_tsconfig_json_compiles_the_specified_files_with_default_compiler_options) + example([]string{"tsc -b"}, diagnostics.Build_a_composite_project_in_the_working_directory) + example([]string{"tsc --init"}, diagnostics.Creates_a_tsconfig_json_with_the_recommended_settings_in_the_working_directory) + example([]string{"tsc -p ./path/to/tsconfig.json"}, diagnostics.Compiles_the_TypeScript_project_located_at_the_specified_path) + example([]string{"tsc --help --all"}, diagnostics.An_expanded_version_of_this_information_showing_all_possible_compiler_options) + example([]string{"tsc --noEmit", "tsc --target esnext"}, diagnostics.Compiles_the_current_project_with_additional_settings) + + var cliCommands []*tsoptions.CommandLineOption + var configOpts []*tsoptions.CommandLineOption + for _, opt := range simpleOptions { + if opt.IsCommandLineOnly || opt.Category == diagnostics.Command_line_Options { + cliCommands = append(cliCommands, opt) + } else { + configOpts = append(configOpts, opt) + } + } + + output = append(output, generateSectionOptionsOutput(sys, diagnostics.COMMAND_LINE_FLAGS.Format(), cliCommands /*subCategory*/, false /*beforeOptionsDescription*/, nil /*afterOptionsDescription*/, nil)...) + + after := diagnostics.You_can_learn_about_all_of_the_compiler_options_at_0.Format("https://aka.ms/tsc") + output = append(output, generateSectionOptionsOutput(sys, diagnostics.COMMON_COMPILER_OPTIONS.Format(), configOpts /*subCategory*/, false /*beforeOptionsDescription*/, nil, + // !!! locale formatMessage(Diagnostics.You_can_learn_about_all_of_the_compiler_options_at_0, "https://aka.ms/tsc")), + &after)...) + + for _, chunk := range output { + fmt.Fprint(sys.Writer(), chunk) + } + sys.EndWrite() +} + +func generateSectionOptionsOutput( + sys System, + sectionName string, + options []*tsoptions.CommandLineOption, + subCategory bool, + beforeOptionsDescription, + afterOptionsDescription *string, +) (output []string) { + // !!! color + output = append(output /*createColors(sys).bold(*/, sectionName /*)*/, sys.NewLine(), sys.NewLine()) + + if beforeOptionsDescription != nil { + output = append(output, *beforeOptionsDescription, sys.NewLine(), sys.NewLine()) + } + if !subCategory { + output = append(output, generateGroupOptionOutput(sys, options)...) + if afterOptionsDescription != nil { + output = append(output, *afterOptionsDescription, sys.NewLine(), sys.NewLine()) + } + return output + } + categoryMap := make(map[string][]*tsoptions.CommandLineOption) + for _, option := range options { + if option.Category == nil { + continue + } + curCategory := option.Category.Format() + categoryMap[curCategory] = append(categoryMap[curCategory], option) + } + for key, value := range categoryMap { + output = append(output, "### ", key, sys.NewLine(), sys.NewLine()) + output = append(output, generateGroupOptionOutput(sys, value)...) + } + if afterOptionsDescription != nil { + output = append(output, *afterOptionsDescription, sys.NewLine(), sys.NewLine()) + } + + return output +} + +func generateGroupOptionOutput(sys System, optionsList []*tsoptions.CommandLineOption) []string { + var maxLength int + for _, option := range optionsList { + curLenght := len(getDisplayNameTextOfOption(option)) + maxLength = max(curLenght, maxLength) + } + + // left part should be right align, right part should be left align + + // assume 2 space between left margin and left part. + rightAlignOfLeftPart := maxLength + 2 + // assume 2 space between left and right part + leftAlignOfRightPart := rightAlignOfLeftPart + 2 + + var lines []string + for _, option := range optionsList { + tmp := generateOptionOutput(sys, option, rightAlignOfLeftPart, leftAlignOfRightPart) + lines = append(lines, tmp...) + } + + // make sure always a blank line in the end. + // !!! if lines[len(lines)-2] != sys.NewLine() { + // !!! lines = append(lines, sys.NewLine()) + // !!! } + + return lines +} + +func generateOptionOutput( + sys System, + option *tsoptions.CommandLineOption, + rightAlignOfLeftPart, leftAlignOfRightPart int, +) []string { + var text []string + // !!! const colors = createColors(sys); + + // name and description + // !!! name := getDisplayNameTextOfOption(option) + + // !!! + + return text +} + +func getDisplayNameTextOfOption(option *tsoptions.CommandLineOption) string { + return "--" + option.Name + core.IfElse(option.ShortName != "", ", -"+option.ShortName, "") +} diff --git a/internal/execute/tsc.go b/internal/execute/tsc.go index 498f9d2905..78a18ef788 100644 --- a/internal/execute/tsc.go +++ b/internal/execute/tsc.go @@ -34,10 +34,7 @@ func executeCommandLineWorker(sys System, cb cbType, commandLine *tsoptions.Pars return ExitStatusDiagnosticsPresent_OutputsSkipped, nil } - if commandLine.CompilerOptions().Init.IsTrue() || - // commandLine.CompilerOptions().Help != nil || - // commandLine.CompilerOptions().All != nil || - commandLine.CompilerOptions().Watch.IsTrue() && commandLine.CompilerOptions().ListFilesOnly.IsTrue() { + if commandLine.CompilerOptions().Init.IsTrue() { return ExitStatusNotImplemented, nil } @@ -46,6 +43,15 @@ func executeCommandLineWorker(sys System, cb cbType, commandLine *tsoptions.Pars return ExitStatusSuccess, nil } + if commandLine.CompilerOptions().Help.IsTrue() || commandLine.CompilerOptions().All.IsTrue() { + printHelp(sys, commandLine) + return ExitStatusSuccess, nil + } + + if commandLine.CompilerOptions().Watch.IsTrue() && commandLine.CompilerOptions().ListFilesOnly.IsTrue() { + return ExitStatusNotImplemented, nil + } + if commandLine.CompilerOptions().Project != "" { if len(commandLine.FileNames()) != 0 { reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line)) @@ -76,7 +82,7 @@ func executeCommandLineWorker(sys System, cb cbType, commandLine *tsoptions.Pars reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0, tspath.NormalizePath(sys.GetCurrentDirectory()))) } else { printVersion(sys) - // print help + printHelp(sys, commandLine) } return ExitStatusDiagnosticsPresent_OutputsSkipped, nil } diff --git a/internal/tsoptions/commandlineoption.go b/internal/tsoptions/commandlineoption.go index 63173c98ac..ca944646be 100644 --- a/internal/tsoptions/commandlineoption.go +++ b/internal/tsoptions/commandlineoption.go @@ -19,7 +19,7 @@ const ( ) type CommandLineOption struct { - Name, shortName string + Name, ShortName string Kind CommandLineOptionKind // used in parsing @@ -30,7 +30,7 @@ type CommandLineOption struct { // used in output Description *diagnostics.Message DefaultValueDescription any - showInSimplifiedHelpView bool + ShowInSimplifiedHelpView bool // used in output in serializing and generate tsconfig Category *diagnostics.Message diff --git a/internal/tsoptions/declsbuild.go b/internal/tsoptions/declsbuild.go index 5d40a4ae80..3b995d0137 100644 --- a/internal/tsoptions/declsbuild.go +++ b/internal/tsoptions/declsbuild.go @@ -8,21 +8,21 @@ import ( var BuildOpts = slices.Concat(commonOptionsWithBuild, optionsForBuild) -var tscBuildOption = CommandLineOption{ +var TscBuildOption = CommandLineOption{ Name: "build", Kind: "boolean", - shortName: "b", - showInSimplifiedHelpView: true, + ShortName: "b", + ShowInSimplifiedHelpView: true, Category: diagnostics.Command_line_Options, Description: diagnostics.Build_one_or_more_projects_and_their_dependencies_if_out_of_date, DefaultValueDescription: false, } var optionsForBuild = []*CommandLineOption{ - &tscBuildOption, + &TscBuildOption, { Name: "verbose", - shortName: "v", + ShortName: "v", Category: diagnostics.Command_line_Options, Description: diagnostics.Enable_verbose_logging, Kind: "boolean", @@ -30,7 +30,7 @@ var optionsForBuild = []*CommandLineOption{ }, { Name: "dry", - shortName: "d", + ShortName: "d", Category: diagnostics.Command_line_Options, Description: diagnostics.Show_what_would_be_built_or_deleted_if_specified_with_clean, Kind: "boolean", @@ -38,7 +38,7 @@ var optionsForBuild = []*CommandLineOption{ }, { Name: "force", - shortName: "f", + ShortName: "f", Category: diagnostics.Command_line_Options, Description: diagnostics.Build_all_projects_including_those_that_appear_to_be_up_to_date, Kind: "boolean", diff --git a/internal/tsoptions/declscompiler.go b/internal/tsoptions/declscompiler.go index 11a577c237..8881f0f64c 100644 --- a/internal/tsoptions/declscompiler.go +++ b/internal/tsoptions/declscompiler.go @@ -13,9 +13,9 @@ var optionsForCompiler = []*CommandLineOption{ //******* commandOptionsWithoutBuild ******* { Name: "help", - shortName: "h", + ShortName: "h", Kind: CommandLineOptionTypeBoolean, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, IsCommandLineOnly: true, Category: diagnostics.Command_line_Options, Description: diagnostics.Print_this_message, @@ -23,7 +23,7 @@ var optionsForCompiler = []*CommandLineOption{ }, { Name: "help", - shortName: "?", + ShortName: "?", Kind: CommandLineOptionTypeBoolean, IsCommandLineOnly: true, Category: diagnostics.Command_line_Options, @@ -31,9 +31,9 @@ var optionsForCompiler = []*CommandLineOption{ }, { Name: "watch", - shortName: "w", + ShortName: "w", Kind: CommandLineOptionTypeBoolean, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, IsCommandLineOnly: true, Category: diagnostics.Command_line_Options, Description: diagnostics.Watch_input_files, @@ -42,7 +42,7 @@ var optionsForCompiler = []*CommandLineOption{ { Name: "preserveWatchOutput", Kind: CommandLineOptionTypeBoolean, - showInSimplifiedHelpView: false, + ShowInSimplifiedHelpView: false, Category: diagnostics.Output_Formatting, Description: diagnostics.Disable_wiping_the_console_in_watch_mode, DefaultValueDescription: false, @@ -71,7 +71,7 @@ var optionsForCompiler = []*CommandLineOption{ { Name: "pretty", Kind: CommandLineOptionTypeBoolean, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Output_Formatting, Description: diagnostics.Enable_color_and_formatting_in_TypeScript_s_output_to_make_compiler_errors_easier_to_read, DefaultValueDescription: true, @@ -114,7 +114,7 @@ var optionsForCompiler = []*CommandLineOption{ }, { Name: "incremental", - shortName: "i", + ShortName: "i", Kind: CommandLineOptionTypeBoolean, Category: diagnostics.Projects, Description: diagnostics.Save_tsbuildinfo_files_to_allow_for_incremental_compilation_of_projects, @@ -123,11 +123,11 @@ var optionsForCompiler = []*CommandLineOption{ }, { Name: "declaration", - shortName: "d", + ShortName: "d", Kind: CommandLineOptionTypeBoolean, // Not setting affectsEmit because we calculate this flag might not affect full emit AffectsBuildInfo: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Emit, transpileOptionValue: core.TSUnknown, Description: diagnostics.Generate_d_ts_files_from_TypeScript_and_JavaScript_files_in_your_project, @@ -138,7 +138,7 @@ var optionsForCompiler = []*CommandLineOption{ Kind: CommandLineOptionTypeBoolean, // Not setting affectsEmit because we calculate this flag might not affect full emit AffectsBuildInfo: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Emit, DefaultValueDescription: false, Description: diagnostics.Create_sourcemaps_for_d_ts_files, @@ -148,7 +148,7 @@ var optionsForCompiler = []*CommandLineOption{ Kind: CommandLineOptionTypeBoolean, // Not setting affectsEmit because we calculate this flag might not affect full emit AffectsBuildInfo: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Emit, Description: diagnostics.Only_output_d_ts_files_and_not_JavaScript_files, transpileOptionValue: core.TSUnknown, @@ -159,7 +159,7 @@ var optionsForCompiler = []*CommandLineOption{ Kind: CommandLineOptionTypeBoolean, // Not setting affectsEmit because we calculate this flag might not affect full emit AffectsBuildInfo: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Emit, DefaultValueDescription: false, Description: diagnostics.Create_source_map_files_for_emitted_JavaScript_files, @@ -176,7 +176,7 @@ var optionsForCompiler = []*CommandLineOption{ { Name: "noCheck", Kind: CommandLineOptionTypeBoolean, - showInSimplifiedHelpView: false, + ShowInSimplifiedHelpView: false, Category: diagnostics.Compiler_Diagnostics, Description: diagnostics.Disable_full_type_checking_only_critical_parse_and_emit_errors_will_be_reported, transpileOptionValue: core.TSTrue, @@ -186,7 +186,7 @@ var optionsForCompiler = []*CommandLineOption{ { Name: "noEmit", Kind: CommandLineOptionTypeBoolean, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Emit, Description: diagnostics.Disable_emitting_files_from_a_compilation, transpileOptionValue: core.TSUnknown, @@ -219,16 +219,16 @@ var commonOptionsWithBuild = []*CommandLineOption{ { Name: "all", Kind: CommandLineOptionTypeBoolean, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Command_line_Options, Description: diagnostics.Show_all_compiler_options, DefaultValueDescription: false, }, { Name: "version", - shortName: "v", + ShortName: "v", Kind: CommandLineOptionTypeBoolean, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Command_line_Options, Description: diagnostics.Print_the_compiler_s_version, DefaultValueDescription: false, @@ -236,24 +236,24 @@ var commonOptionsWithBuild = []*CommandLineOption{ { Name: "init", Kind: CommandLineOptionTypeBoolean, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Command_line_Options, Description: diagnostics.Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file, DefaultValueDescription: false, }, { Name: "project", - shortName: "p", + ShortName: "p", Kind: CommandLineOptionTypeString, isFilePath: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Command_line_Options, Description: diagnostics.Compile_the_project_given_the_path_to_its_configuration_file_or_to_a_folder_with_a_tsconfig_json, }, { Name: "showConfig", Kind: CommandLineOptionTypeBoolean, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Command_line_Options, IsCommandLineOnly: true, Description: diagnostics.Print_the_final_configuration_instead_of_building, @@ -272,13 +272,13 @@ var commonOptionsWithBuild = []*CommandLineOption{ // targetOptionDeclaration, { Name: "target", - shortName: "t", + ShortName: "t", Kind: CommandLineOptionTypeEnum, // targetOptionMap AffectsSourceFile: true, AffectsModuleResolution: true, AffectsEmit: true, AffectsBuildInfo: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Language_and_Environment, Description: diagnostics.Set_the_JavaScript_language_version_for_emitted_JavaScript_and_include_compatible_library_declarations, DefaultValueDescription: core.ScriptTargetES5, @@ -287,12 +287,12 @@ var commonOptionsWithBuild = []*CommandLineOption{ // moduleOptionDeclaration, { Name: "module", - shortName: "m", + ShortName: "m", Kind: CommandLineOptionTypeEnum, // moduleOptionMap AffectsModuleResolution: true, AffectsEmit: true, AffectsBuildInfo: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Modules, Description: diagnostics.Specify_what_module_code_is_generated, DefaultValueDescription: core.TSUnknown, @@ -306,7 +306,7 @@ var commonOptionsWithBuild = []*CommandLineOption{ // defaultValueDescription: core.TSUnknown, // }, AffectsProgramStructure: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Language_and_Environment, Description: diagnostics.Specify_a_set_of_bundled_library_declaration_files_that_describe_the_target_runtime_environment, transpileOptionValue: core.TSUnknown, @@ -316,7 +316,7 @@ var commonOptionsWithBuild = []*CommandLineOption{ Kind: CommandLineOptionTypeBoolean, allowJsFlag: true, AffectsBuildInfo: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.JavaScript_Support, Description: diagnostics.Allow_JavaScript_files_to_be_a_part_of_your_program_Use_the_checkJS_option_to_get_errors_from_these_files, DefaultValueDescription: false, @@ -327,7 +327,7 @@ var commonOptionsWithBuild = []*CommandLineOption{ AffectsModuleResolution: true, AffectsSemanticDiagnostics: true, AffectsBuildInfo: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.JavaScript_Support, Description: diagnostics.Enable_error_reporting_in_type_checked_JavaScript_files, DefaultValueDescription: false, @@ -343,7 +343,7 @@ var commonOptionsWithBuild = []*CommandLineOption{ // This is effectively a semantic error, so mark this option as affecting semantic diagnostics // so we know to refresh errors when this option is changed. AffectsSemanticDiagnostics: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Language_and_Environment, Description: diagnostics.Specify_what_JSX_code_is_generated, DefaultValueDescription: core.TSUnknown, @@ -355,7 +355,7 @@ var commonOptionsWithBuild = []*CommandLineOption{ AffectsBuildInfo: true, AffectsDeclarationPath: true, isFilePath: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Emit, Description: diagnostics.Specify_a_file_that_bundles_all_outputs_into_one_JavaScript_file_If_declaration_is_true_also_designates_a_file_that_bundles_all_d_ts_output, transpileOptionValue: core.TSUnknown, @@ -367,7 +367,7 @@ var commonOptionsWithBuild = []*CommandLineOption{ AffectsBuildInfo: true, AffectsDeclarationPath: true, isFilePath: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Emit, Description: diagnostics.Specify_an_output_folder_for_all_emitted_files, }, @@ -409,7 +409,7 @@ var commonOptionsWithBuild = []*CommandLineOption{ Kind: CommandLineOptionTypeBoolean, AffectsEmit: true, AffectsBuildInfo: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Emit, DefaultValueDescription: false, Description: diagnostics.Disable_emitting_comments, @@ -470,7 +470,7 @@ var commonOptionsWithBuild = []*CommandLineOption{ // But we need to store `strict` in builf info, even though it won't be examined directly, so that the // flags it controls (e.g. `strictNullChecks`) will be retrieved correctly AffectsBuildInfo: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Type_Checking, Description: diagnostics.Enable_all_strict_type_checking_options, DefaultValueDescription: false, @@ -637,7 +637,7 @@ var commonOptionsWithBuild = []*CommandLineOption{ Kind: CommandLineOptionTypeBoolean, AffectsSemanticDiagnostics: true, AffectsBuildInfo: true, - showInSimplifiedHelpView: false, + ShowInSimplifiedHelpView: false, Category: diagnostics.Type_Checking, Description: diagnostics.Enforces_using_indexed_accessors_for_keys_declared_using_an_indexed_type, DefaultValueDescription: false, @@ -706,7 +706,7 @@ var commonOptionsWithBuild = []*CommandLineOption{ Name: "types", Kind: CommandLineOptionTypeList, AffectsProgramStructure: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Modules, Description: diagnostics.Specify_type_package_names_to_be_included_without_being_referenced_in_a_source_file, transpileOptionValue: core.TSUnknown, @@ -726,7 +726,7 @@ var commonOptionsWithBuild = []*CommandLineOption{ AffectsSemanticDiagnostics: true, AffectsEmit: true, AffectsBuildInfo: true, - showInSimplifiedHelpView: true, + ShowInSimplifiedHelpView: true, Category: diagnostics.Interop_Constraints, Description: diagnostics.Emit_additional_JavaScript_to_ease_support_for_importing_CommonJS_modules_This_enables_allowSyntheticDefaultImports_for_type_compatibility, DefaultValueDescription: false, diff --git a/internal/tsoptions/namemap.go b/internal/tsoptions/namemap.go index 66ae8d231d..e199577f87 100644 --- a/internal/tsoptions/namemap.go +++ b/internal/tsoptions/namemap.go @@ -17,8 +17,8 @@ func GetNameMapFromList(optDecls []*CommandLineOption) *NameMap { shortOptionNames := map[string]string{} for _, option := range optDecls { optionsNames.Set(strings.ToLower(option.Name), option) - if option.shortName != "" { - shortOptionNames[option.shortName] = option.Name + if option.ShortName != "" { + shortOptionNames[option.ShortName] = option.Name } } return &NameMap{ diff --git a/internal/tsoptions/parsinghelpers.go b/internal/tsoptions/parsinghelpers.go index ac1e61f239..d0c69275c5 100644 --- a/internal/tsoptions/parsinghelpers.go +++ b/internal/tsoptions/parsinghelpers.go @@ -371,6 +371,10 @@ func ParseCompilerOptions(key string, value any, allOptions *core.CompilerOption allOptions.VerbatimModuleSyntax = parseTristate(value) case "version": allOptions.Version = parseTristate(value) + case "help": + allOptions.Help = parseTristate(value) + case "all": + allOptions.All = parseTristate(value) case "maxNodeModuleJsDepth": allOptions.MaxNodeModuleJsDepth = parseNumber(value) case "skipLibCheck": diff --git a/testdata/baselines/reference/tsc/commandLine/Parse-watch-interval-option.js b/testdata/baselines/reference/tsc/commandLine/Parse-watch-interval-option.js index 92fa2ab7fd..3af4af905c 100644 --- a/testdata/baselines/reference/tsc/commandLine/Parse-watch-interval-option.js +++ b/testdata/baselines/reference/tsc/commandLine/Parse-watch-interval-option.js @@ -33,3 +33,36 @@ ParsedCommandLine::{ Output:: Version 7.0.0-dev +tsc: The TypeScript Compiler - Version 7.0.0-dev + +COMMON COMMANDS + + tsc + Compiles the current project (tsconfig.json in the working directory.) + + tsc app.ts util.ts + Ignoring tsconfig.json, compiles the specified files with default compiler options. + + tsc -b + Build a composite project in the working directory. + + tsc --init + Creates a tsconfig.json with the recommended settings in the working directory. + + tsc -p ./path/to/tsconfig.json + Compiles the TypeScript project located at the specified path. + + tsc --help --all + An expanded version of this information, showing all possible compiler options + + tsc --noEmit + tsc --target esnext + Compiles the current project, with additional settings. + +COMMAND LINE FLAGS + +COMMON COMPILER OPTIONS + +You can learn about all of the compiler options at https://aka.ms/tsc + + diff --git a/testdata/baselines/reference/tsc/commandLine/does-not-add-color-when-NO_COLOR-is-set.js b/testdata/baselines/reference/tsc/commandLine/does-not-add-color-when-NO_COLOR-is-set.js index 88dbd52083..b6fdb9e2de 100644 --- a/testdata/baselines/reference/tsc/commandLine/does-not-add-color-when-NO_COLOR-is-set.js +++ b/testdata/baselines/reference/tsc/commandLine/does-not-add-color-when-NO_COLOR-is-set.js @@ -28,3 +28,36 @@ ParsedCommandLine::{ Output:: Version 7.0.0-dev +tsc: The TypeScript Compiler - Version 7.0.0-dev + +COMMON COMMANDS + + tsc + Compiles the current project (tsconfig.json in the working directory.) + + tsc app.ts util.ts + Ignoring tsconfig.json, compiles the specified files with default compiler options. + + tsc -b + Build a composite project in the working directory. + + tsc --init + Creates a tsconfig.json with the recommended settings in the working directory. + + tsc -p ./path/to/tsconfig.json + Compiles the TypeScript project located at the specified path. + + tsc --help --all + An expanded version of this information, showing all possible compiler options + + tsc --noEmit + tsc --target esnext + Compiles the current project, with additional settings. + +COMMAND LINE FLAGS + +COMMON COMPILER OPTIONS + +You can learn about all of the compiler options at https://aka.ms/tsc + + diff --git a/testdata/baselines/reference/tsc/commandLine/help-all.js b/testdata/baselines/reference/tsc/commandLine/help-all.js index 0e43c8b742..95cca0f837 100644 --- a/testdata/baselines/reference/tsc/commandLine/help-all.js +++ b/testdata/baselines/reference/tsc/commandLine/help-all.js @@ -3,11 +3,14 @@ currentDirectory::/home/src/workspaces/project useCaseSensitiveFileNames::true Input::--help --all -ExitStatus:: 1 +ExitStatus:: 0 ParsedCommandLine::{ "parsedConfig": { - "compilerOptions": {}, + "compilerOptions": { + "help": true, + "all": true + }, "watchOptions": { "watchInterval": null, "watchFile": 0, @@ -29,5 +32,5 @@ ParsedCommandLine::{ "compileOnSave": null } Output:: -Version 7.0.0-dev +No output diff --git a/testdata/baselines/reference/tsc/commandLine/help.js b/testdata/baselines/reference/tsc/commandLine/help.js index 39db1c7675..13d0d0c142 100644 --- a/testdata/baselines/reference/tsc/commandLine/help.js +++ b/testdata/baselines/reference/tsc/commandLine/help.js @@ -3,11 +3,13 @@ currentDirectory::/home/src/workspaces/project useCaseSensitiveFileNames::true Input::--help -ExitStatus:: 1 +ExitStatus:: 0 ParsedCommandLine::{ "parsedConfig": { - "compilerOptions": {}, + "compilerOptions": { + "help": true + }, "watchOptions": { "watchInterval": null, "watchFile": 0, @@ -28,5 +30,36 @@ ParsedCommandLine::{ "compileOnSave": null } Output:: -Version 7.0.0-dev +tsc: The TypeScript Compiler - Version 7.0.0-dev + +COMMON COMMANDS + + tsc + Compiles the current project (tsconfig.json in the working directory.) + + tsc app.ts util.ts + Ignoring tsconfig.json, compiles the specified files with default compiler options. + + tsc -b + Build a composite project in the working directory. + + tsc --init + Creates a tsconfig.json with the recommended settings in the working directory. + + tsc -p ./path/to/tsconfig.json + Compiles the TypeScript project located at the specified path. + + tsc --help --all + An expanded version of this information, showing all possible compiler options + + tsc --noEmit + tsc --target esnext + Compiles the current project, with additional settings. + +COMMAND LINE FLAGS + +COMMON COMPILER OPTIONS + +You can learn about all of the compiler options at https://aka.ms/tsc + diff --git a/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-cannot-provide-terminal-width.js b/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-cannot-provide-terminal-width.js index 88dbd52083..b6fdb9e2de 100644 --- a/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-cannot-provide-terminal-width.js +++ b/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-cannot-provide-terminal-width.js @@ -28,3 +28,36 @@ ParsedCommandLine::{ Output:: Version 7.0.0-dev +tsc: The TypeScript Compiler - Version 7.0.0-dev + +COMMON COMMANDS + + tsc + Compiles the current project (tsconfig.json in the working directory.) + + tsc app.ts util.ts + Ignoring tsconfig.json, compiles the specified files with default compiler options. + + tsc -b + Build a composite project in the working directory. + + tsc --init + Creates a tsconfig.json with the recommended settings in the working directory. + + tsc -p ./path/to/tsconfig.json + Compiles the TypeScript project located at the specified path. + + tsc --help --all + An expanded version of this information, showing all possible compiler options + + tsc --noEmit + tsc --target esnext + Compiles the current project, with additional settings. + +COMMAND LINE FLAGS + +COMMON COMPILER OPTIONS + +You can learn about all of the compiler options at https://aka.ms/tsc + + diff --git a/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js b/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js index 88dbd52083..b6fdb9e2de 100644 --- a/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js +++ b/testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js @@ -28,3 +28,36 @@ ParsedCommandLine::{ Output:: Version 7.0.0-dev +tsc: The TypeScript Compiler - Version 7.0.0-dev + +COMMON COMMANDS + + tsc + Compiles the current project (tsconfig.json in the working directory.) + + tsc app.ts util.ts + Ignoring tsconfig.json, compiles the specified files with default compiler options. + + tsc -b + Build a composite project in the working directory. + + tsc --init + Creates a tsconfig.json with the recommended settings in the working directory. + + tsc -p ./path/to/tsconfig.json + Compiles the TypeScript project located at the specified path. + + tsc --help --all + An expanded version of this information, showing all possible compiler options + + tsc --noEmit + tsc --target esnext + Compiles the current project, with additional settings. + +COMMAND LINE FLAGS + +COMMON COMPILER OPTIONS + +You can learn about all of the compiler options at https://aka.ms/tsc + +