2015-06-12 18:01:48 +02:00
|
|
|
namespace ts {
|
2016-08-24 01:11:52 +02:00
|
|
|
/* @internal */
|
|
|
|
export const compileOnSaveCommandLineOption: CommandLineOption = { name: "compileOnSave", type: "boolean" };
|
2018-05-03 00:47:48 +02:00
|
|
|
|
2018-05-31 18:50:51 +02:00
|
|
|
// NOTE: The order here is important to default lib ordering as entries will have the same
|
|
|
|
// order in the generated program (see `getDefaultLibPriority` in program.ts). This
|
|
|
|
// order also affects overload resolution when a type declared in one lib is
|
|
|
|
// augmented in another lib.
|
|
|
|
const libEntries: [string, string][] = [
|
2018-05-03 00:47:48 +02:00
|
|
|
// JavaScript only
|
2018-05-05 02:23:56 +02:00
|
|
|
["es5", "lib.es5.d.ts"],
|
|
|
|
["es6", "lib.es2015.d.ts"],
|
|
|
|
["es2015", "lib.es2015.d.ts"],
|
|
|
|
["es7", "lib.es2016.d.ts"],
|
|
|
|
["es2016", "lib.es2016.d.ts"],
|
|
|
|
["es2017", "lib.es2017.d.ts"],
|
|
|
|
["es2018", "lib.es2018.d.ts"],
|
|
|
|
["esnext", "lib.esnext.d.ts"],
|
2018-05-03 00:47:48 +02:00
|
|
|
// Host only
|
2018-05-05 02:23:56 +02:00
|
|
|
["dom", "lib.dom.d.ts"],
|
|
|
|
["dom.iterable", "lib.dom.iterable.d.ts"],
|
|
|
|
["webworker", "lib.webworker.d.ts"],
|
2018-05-31 18:50:51 +02:00
|
|
|
["webworker.importscripts", "lib.webworker.importscripts.d.ts"],
|
2018-05-05 02:23:56 +02:00
|
|
|
["scripthost", "lib.scripthost.d.ts"],
|
2018-05-03 00:47:48 +02:00
|
|
|
// ES2015 Or ESNext By-feature options
|
2018-05-05 02:23:56 +02:00
|
|
|
["es2015.core", "lib.es2015.core.d.ts"],
|
|
|
|
["es2015.collection", "lib.es2015.collection.d.ts"],
|
|
|
|
["es2015.generator", "lib.es2015.generator.d.ts"],
|
|
|
|
["es2015.iterable", "lib.es2015.iterable.d.ts"],
|
|
|
|
["es2015.promise", "lib.es2015.promise.d.ts"],
|
|
|
|
["es2015.proxy", "lib.es2015.proxy.d.ts"],
|
|
|
|
["es2015.reflect", "lib.es2015.reflect.d.ts"],
|
|
|
|
["es2015.symbol", "lib.es2015.symbol.d.ts"],
|
|
|
|
["es2015.symbol.wellknown", "lib.es2015.symbol.wellknown.d.ts"],
|
|
|
|
["es2016.array.include", "lib.es2016.array.include.d.ts"],
|
|
|
|
["es2017.object", "lib.es2017.object.d.ts"],
|
|
|
|
["es2017.sharedmemory", "lib.es2017.sharedmemory.d.ts"],
|
|
|
|
["es2017.string", "lib.es2017.string.d.ts"],
|
|
|
|
["es2017.intl", "lib.es2017.intl.d.ts"],
|
|
|
|
["es2017.typedarrays", "lib.es2017.typedarrays.d.ts"],
|
|
|
|
["es2018.intl", "lib.es2018.intl.d.ts"],
|
|
|
|
["es2018.promise", "lib.es2018.promise.d.ts"],
|
|
|
|
["es2018.regexp", "lib.es2018.regexp.d.ts"],
|
|
|
|
["esnext.array", "lib.esnext.array.d.ts"],
|
2018-06-04 23:38:56 +02:00
|
|
|
["esnext.symbol", "lib.esnext.symbol.d.ts"],
|
2018-05-05 02:23:56 +02:00
|
|
|
["esnext.asynciterable", "lib.esnext.asynciterable.d.ts"],
|
2018-09-29 21:01:42 +02:00
|
|
|
["esnext.intl", "lib.esnext.intl.d.ts"],
|
|
|
|
["esnext.bigint", "lib.esnext.bigint.d.ts"]
|
2018-05-31 18:50:51 +02:00
|
|
|
];
|
2018-05-03 00:47:48 +02:00
|
|
|
|
2018-05-31 18:50:51 +02:00
|
|
|
/**
|
|
|
|
* An array of supported "lib" reference file names used to determine the order for inclusion
|
|
|
|
* when referenced, as well as for spelling suggestions. This ensures the correct ordering for
|
|
|
|
* overload resolution when a type declared in one lib is extended by another.
|
|
|
|
*/
|
2018-05-03 00:47:48 +02:00
|
|
|
/* @internal */
|
2018-05-31 18:50:51 +02:00
|
|
|
export const libs = libEntries.map(entry => entry[0]);
|
2018-05-03 00:47:48 +02:00
|
|
|
|
2018-05-31 18:50:51 +02:00
|
|
|
/**
|
|
|
|
* A map of lib names to lib files. This map is used both for parsing the "lib" command line
|
|
|
|
* option as well as for resolving lib reference directives.
|
|
|
|
*/
|
2018-05-03 00:47:48 +02:00
|
|
|
/* @internal */
|
2018-05-31 18:50:51 +02:00
|
|
|
export const libMap = createMapFromEntries(libEntries);
|
2018-05-03 00:47:48 +02:00
|
|
|
|
2018-09-13 18:54:35 +02:00
|
|
|
/* @internal */
|
|
|
|
export const commonOptionsWithBuild: CommandLineOption[] = [
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
|
|
|
name: "help",
|
|
|
|
shortName: "h",
|
|
|
|
type: "boolean",
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-03-22 20:01:08 +01:00
|
|
|
category: Diagnostics.Command_line_Options,
|
2014-08-02 02:12:29 +02:00
|
|
|
description: Diagnostics.Print_this_message,
|
|
|
|
},
|
|
|
|
{
|
2016-05-24 20:33:23 +02:00
|
|
|
name: "help",
|
|
|
|
shortName: "?",
|
|
|
|
type: "boolean"
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
2018-09-17 22:01:58 +02:00
|
|
|
{
|
|
|
|
name: "watch",
|
|
|
|
shortName: "w",
|
|
|
|
type: "boolean",
|
|
|
|
showInSimplifiedHelpView: true,
|
|
|
|
category: Diagnostics.Command_line_Options,
|
|
|
|
description: Diagnostics.Watch_input_files,
|
|
|
|
},
|
2018-08-29 21:23:52 +02:00
|
|
|
{
|
|
|
|
name: "preserveWatchOutput",
|
|
|
|
type: "boolean",
|
|
|
|
showInSimplifiedHelpView: false,
|
|
|
|
category: Diagnostics.Command_line_Options,
|
|
|
|
description: Diagnostics.Whether_to_keep_outdated_console_output_in_watch_mode_instead_of_clearing_the_screen,
|
|
|
|
},
|
|
|
|
{
|
2018-09-13 20:17:03 +02:00
|
|
|
name: "listFiles",
|
2018-08-29 21:23:52 +02:00
|
|
|
type: "boolean",
|
2018-09-13 20:17:03 +02:00
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Print_names_of_files_part_of_the_compilation
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "listEmittedFiles",
|
|
|
|
type: "boolean",
|
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Print_names_of_generated_files_part_of_the_compilation
|
|
|
|
},
|
2018-11-01 18:12:46 +01:00
|
|
|
{
|
|
|
|
name: "pretty",
|
|
|
|
type: "boolean",
|
|
|
|
showInSimplifiedHelpView: true,
|
|
|
|
category: Diagnostics.Command_line_Options,
|
|
|
|
description: Diagnostics.Stylize_errors_and_messages_using_color_and_context_experimental
|
|
|
|
},
|
2018-09-17 22:01:58 +02:00
|
|
|
|
2018-08-29 21:23:52 +02:00
|
|
|
{
|
2018-09-17 22:01:58 +02:00
|
|
|
name: "traceResolution",
|
2018-08-29 21:23:52 +02:00
|
|
|
type: "boolean",
|
2018-09-17 22:01:58 +02:00
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Enable_tracing_of_the_name_resolution_process
|
2018-08-29 21:23:52 +02:00
|
|
|
},
|
2018-11-19 20:15:48 +01:00
|
|
|
{
|
|
|
|
name: "diagnostics",
|
|
|
|
type: "boolean",
|
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Show_diagnostic_information
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "extendedDiagnostics",
|
|
|
|
type: "boolean",
|
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Show_verbose_diagnostic_information
|
|
|
|
},
|
2018-08-29 21:23:52 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
/* @internal */
|
|
|
|
export const optionDeclarations: CommandLineOption[] = [
|
|
|
|
// CommandLine only options
|
|
|
|
...commonOptionsWithBuild,
|
2016-02-20 19:27:51 +01:00
|
|
|
{
|
2017-02-08 21:14:43 +01:00
|
|
|
name: "all",
|
2015-07-27 13:52:57 +02:00
|
|
|
type: "boolean",
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-03-22 20:01:08 +01:00
|
|
|
category: Diagnostics.Command_line_Options,
|
2017-02-08 21:14:43 +01:00
|
|
|
description: Diagnostics.Show_all_compiler_options,
|
2016-02-20 19:27:51 +01:00
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "version",
|
|
|
|
shortName: "v",
|
2014-08-02 02:12:29 +02:00
|
|
|
type: "boolean",
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-03-22 20:01:08 +01:00
|
|
|
category: Diagnostics.Command_line_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Print_the_compiler_s_version,
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
2016-07-20 00:10:29 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "init",
|
2016-07-20 00:10:29 +02:00
|
|
|
type: "boolean",
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-03-22 20:01:08 +01:00
|
|
|
category: Diagnostics.Command_line_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file,
|
2016-07-20 00:10:29 +02:00
|
|
|
},
|
2014-08-06 21:55:57 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "project",
|
|
|
|
shortName: "p",
|
2016-11-09 21:12:48 +01:00
|
|
|
type: "string",
|
2017-02-08 08:10:43 +01:00
|
|
|
isFilePath: true,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-03-22 20:01:08 +01:00
|
|
|
category: Diagnostics.Command_line_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
paramType: Diagnostics.FILE_OR_DIRECTORY,
|
|
|
|
description: Diagnostics.Compile_the_project_given_the_path_to_its_configuration_file_or_to_a_folder_with_a_tsconfig_json,
|
2014-08-06 21:55:57 +02:00
|
|
|
},
|
2018-05-30 19:00:35 +02:00
|
|
|
{
|
|
|
|
name: "build",
|
|
|
|
type: "boolean",
|
|
|
|
shortName: "b",
|
|
|
|
showInSimplifiedHelpView: true,
|
|
|
|
category: Diagnostics.Command_line_Options,
|
|
|
|
description: Diagnostics.Build_one_or_more_projects_and_their_dependencies_if_out_of_date
|
|
|
|
},
|
2018-10-31 23:57:09 +01:00
|
|
|
{
|
|
|
|
name: "showConfig",
|
|
|
|
type: "boolean",
|
|
|
|
category: Diagnostics.Command_line_Options,
|
|
|
|
isCommandLineOnly: true,
|
|
|
|
description: Diagnostics.Print_the_final_configuration_instead_of_building
|
|
|
|
},
|
2017-02-08 21:14:43 +01:00
|
|
|
|
|
|
|
// Basic
|
2015-07-27 13:52:57 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "target",
|
|
|
|
shortName: "t",
|
|
|
|
type: createMapFromTemplate({
|
2017-11-07 03:13:20 +01:00
|
|
|
es3: ScriptTarget.ES3,
|
|
|
|
es5: ScriptTarget.ES5,
|
|
|
|
es6: ScriptTarget.ES2015,
|
|
|
|
es2015: ScriptTarget.ES2015,
|
|
|
|
es2016: ScriptTarget.ES2016,
|
|
|
|
es2017: ScriptTarget.ES2017,
|
2017-12-02 20:16:59 +01:00
|
|
|
es2018: ScriptTarget.ES2018,
|
2017-11-07 03:13:20 +01:00
|
|
|
esnext: ScriptTarget.ESNext,
|
2017-02-08 08:10:43 +01:00
|
|
|
}),
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsSourceFile: true,
|
|
|
|
affectsModuleResolution: true,
|
2017-02-08 08:10:43 +01:00
|
|
|
paramType: Diagnostics.VERSION,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2017-12-02 20:16:59 +01:00
|
|
|
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_ES2015_ES2016_ES2017_ES2018_or_ESNEXT,
|
2015-07-27 13:52:57 +02:00
|
|
|
},
|
2015-04-08 09:14:23 +02:00
|
|
|
{
|
2014-08-02 02:12:29 +02:00
|
|
|
name: "module",
|
|
|
|
shortName: "m",
|
2017-01-11 18:52:50 +01:00
|
|
|
type: createMapFromTemplate({
|
2017-11-07 03:13:20 +01:00
|
|
|
none: ModuleKind.None,
|
|
|
|
commonjs: ModuleKind.CommonJS,
|
|
|
|
amd: ModuleKind.AMD,
|
|
|
|
system: ModuleKind.System,
|
|
|
|
umd: ModuleKind.UMD,
|
|
|
|
es6: ModuleKind.ES2015,
|
|
|
|
es2015: ModuleKind.ES2015,
|
|
|
|
esnext: ModuleKind.ESNext
|
2016-08-16 01:41:32 +02:00
|
|
|
}),
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsModuleResolution: true,
|
2014-08-02 02:12:29 +02:00
|
|
|
paramType: Diagnostics.KIND,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2017-07-06 13:27:27 +02:00
|
|
|
description: Diagnostics.Specify_module_code_generation_Colon_none_commonjs_amd_system_umd_es2015_or_ESNext,
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
2015-04-26 17:37:02 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "lib",
|
|
|
|
type: "list",
|
|
|
|
element: {
|
|
|
|
name: "lib",
|
2018-05-31 18:50:51 +02:00
|
|
|
type: libMap
|
2017-02-08 08:10:43 +01:00
|
|
|
},
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsModuleResolution: true,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2018-01-17 18:42:40 +01:00
|
|
|
description: Diagnostics.Specify_library_files_to_be_included_in_the_compilation
|
2015-04-08 09:14:23 +02:00
|
|
|
},
|
2015-04-21 05:33:31 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "allowJs",
|
2015-04-08 09:14:23 +02:00
|
|
|
type: "boolean",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsModuleResolution: true,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Allow_javascript_files_to_be_compiled
|
2015-04-08 09:14:23 +02:00
|
|
|
},
|
2015-04-21 05:33:31 +02:00
|
|
|
{
|
2017-03-22 23:45:27 +01:00
|
|
|
name: "checkJs",
|
2015-04-21 05:33:31 +02:00
|
|
|
type: "boolean",
|
2017-03-22 23:45:27 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
|
|
|
description: Diagnostics.Report_errors_in_js_files
|
2015-04-21 05:33:31 +02:00
|
|
|
},
|
2015-06-18 23:01:31 +02:00
|
|
|
{
|
|
|
|
name: "jsx",
|
2017-01-11 18:52:50 +01:00
|
|
|
type: createMapFromTemplate({
|
2015-06-18 23:01:31 +02:00
|
|
|
"preserve": JsxEmit.Preserve,
|
2017-01-23 21:42:39 +01:00
|
|
|
"react-native": JsxEmit.ReactNative,
|
2015-06-18 23:01:31 +02:00
|
|
|
"react": JsxEmit.React
|
2016-08-16 01:41:32 +02:00
|
|
|
}),
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsSourceFile: true,
|
2015-06-18 23:01:31 +02:00
|
|
|
paramType: Diagnostics.KIND,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2017-01-23 21:42:39 +01:00
|
|
|
description: Diagnostics.Specify_JSX_code_generation_Colon_preserve_react_native_or_react,
|
2015-06-18 23:01:31 +02:00
|
|
|
},
|
2016-11-09 21:12:48 +01:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "declaration",
|
|
|
|
shortName: "d",
|
2014-12-17 05:25:19 +01:00
|
|
|
type: "boolean",
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Generates_corresponding_d_ts_file,
|
2016-11-09 21:12:48 +01:00
|
|
|
},
|
2018-03-26 21:15:34 +02:00
|
|
|
{
|
|
|
|
name: "declarationMap",
|
|
|
|
type: "boolean",
|
|
|
|
showInSimplifiedHelpView: true,
|
|
|
|
category: Diagnostics.Basic_Options,
|
|
|
|
description: Diagnostics.Generates_a_sourcemap_for_each_corresponding_d_ts_file,
|
|
|
|
},
|
2018-01-26 00:35:18 +01:00
|
|
|
{
|
2018-02-05 23:48:50 +01:00
|
|
|
name: "emitDeclarationOnly",
|
2018-01-26 00:35:18 +01:00
|
|
|
type: "boolean",
|
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Only_emit_d_ts_declaration_files,
|
|
|
|
},
|
2015-01-15 22:22:23 +01:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "sourceMap",
|
2015-01-15 22:22:23 +01:00
|
|
|
type: "boolean",
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Generates_corresponding_map_file,
|
2015-01-15 22:22:23 +01:00
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "outFile",
|
2014-08-02 02:12:29 +02:00
|
|
|
type: "string",
|
2017-02-08 08:10:43 +01:00
|
|
|
isFilePath: true,
|
|
|
|
paramType: Diagnostics.FILE,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Concatenate_and_emit_output_to_single_file,
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "outDir",
|
2014-08-02 02:12:29 +02:00
|
|
|
type: "string",
|
2015-01-15 22:22:23 +01:00
|
|
|
isFilePath: true,
|
2017-02-08 08:10:43 +01:00
|
|
|
paramType: Diagnostics.DIRECTORY,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Redirect_output_structure_to_the_directory,
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "rootDir",
|
2014-08-02 02:12:29 +02:00
|
|
|
type: "string",
|
2015-01-15 22:22:23 +01:00
|
|
|
isFilePath: true,
|
2014-08-02 02:12:29 +02:00
|
|
|
paramType: Diagnostics.LOCATION,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Specify_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir,
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
2018-05-08 00:12:50 +02:00
|
|
|
{
|
|
|
|
name: "composite",
|
|
|
|
type: "boolean",
|
|
|
|
isTSConfigOnly: true,
|
|
|
|
category: Diagnostics.Basic_Options,
|
|
|
|
description: Diagnostics.Enable_project_compilation,
|
|
|
|
},
|
2015-04-26 17:37:02 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "removeComments",
|
2016-03-26 00:37:28 +01:00
|
|
|
type: "boolean",
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Do_not_emit_comments_to_output,
|
2015-04-26 17:37:02 +02:00
|
|
|
},
|
2014-12-17 05:25:19 +01:00
|
|
|
{
|
|
|
|
name: "noEmit",
|
|
|
|
type: "boolean",
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2014-12-17 05:25:19 +01:00
|
|
|
description: Diagnostics.Do_not_emit_outputs,
|
|
|
|
},
|
Add support for --noEmitHelpers flag
This PR is a Work In Progress that addresses multiple `__extends`
being output as described in #1350: Multiple `__extends` being output
when `--module amd` is set.
The issue still exists as of `v1.5.0 - f53e6a8`.
Apparently a fix was created for this in #1356 but according to #2009, a
[comment](https://github.com/Microsoft/TypeScript/issues/2009#issuecomment-74136291)
later indicated that this was never merged in.
Further conversation continued in #2487 but did not yield any result. I
refer to my earlier recommendation in #1350.
> My question is this, would the TypeScript team be open to a flag that
> can be passed to tsc that will generate something like the following
> ```ts
> define(["require", "exports", "__extends", './mammal'], function (require, exports, __extends, Mammal) {
> var Human = (function (_super) {
> __extends(Human, _super);
> function Human() {
> _super.apply(this, arguments);
> }
> return Human;
> })(Mammal);
> return Human;
> });
> ```
To continue with the naming convention I have chosen the flag
`--noEmitHelpers`.
2015-04-24 04:16:11 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "importHelpers",
|
2016-06-25 00:38:39 +02:00
|
|
|
type: "boolean",
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Import_emit_helpers_from_tslib
|
Add support for --noEmitHelpers flag
This PR is a Work In Progress that addresses multiple `__extends`
being output as described in #1350: Multiple `__extends` being output
when `--module amd` is set.
The issue still exists as of `v1.5.0 - f53e6a8`.
Apparently a fix was created for this in #1356 but according to #2009, a
[comment](https://github.com/Microsoft/TypeScript/issues/2009#issuecomment-74136291)
later indicated that this was never merged in.
Further conversation continued in #2487 but did not yield any result. I
refer to my earlier recommendation in #1350.
> My question is this, would the TypeScript team be open to a flag that
> can be passed to tsc that will generate something like the following
> ```ts
> define(["require", "exports", "__extends", './mammal'], function (require, exports, __extends, Mammal) {
> var Human = (function (_super) {
> __extends(Human, _super);
> function Human() {
> _super.apply(this, arguments);
> }
> return Human;
> })(Mammal);
> return Human;
> });
> ```
To continue with the naming convention I have chosen the flag
`--noEmitHelpers`.
2015-04-24 04:16:11 +02:00
|
|
|
},
|
2014-10-27 20:48:46 +01:00
|
|
|
{
|
2017-03-15 23:38:55 +01:00
|
|
|
name: "downlevelIteration",
|
2014-10-27 20:48:46 +01:00
|
|
|
type: "boolean",
|
2017-03-15 23:38:55 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2017-03-22 20:01:08 +01:00
|
|
|
description: Diagnostics.Provide_full_support_for_iterables_in_for_of_spread_and_destructuring_when_targeting_ES5_or_ES3
|
2014-10-27 20:48:46 +01:00
|
|
|
},
|
2016-08-06 00:10:02 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "isolatedModules",
|
2014-08-02 02:12:29 +02:00
|
|
|
type: "boolean",
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Basic_Options,
|
2017-03-22 20:01:08 +01:00
|
|
|
description: Diagnostics.Transpile_each_file_as_a_separate_module_similar_to_ts_transpileModule
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
2017-02-08 08:10:43 +01:00
|
|
|
|
2017-03-16 00:15:59 +01:00
|
|
|
// Strict Type Checks
|
2015-06-04 22:56:33 +02:00
|
|
|
{
|
2017-03-15 23:38:55 +01:00
|
|
|
name: "strict",
|
2015-06-04 22:56:33 +02:00
|
|
|
type: "boolean",
|
2017-03-15 23:38:55 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-03-22 20:01:08 +01:00
|
|
|
category: Diagnostics.Strict_Type_Checking_Options,
|
|
|
|
description: Diagnostics.Enable_all_strict_type_checking_options
|
2016-08-06 00:10:02 +02:00
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
|
|
|
name: "noImplicitAny",
|
|
|
|
type: "boolean",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2018-08-06 23:54:57 +02:00
|
|
|
strictFlag: true,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-03-22 20:01:08 +01:00
|
|
|
category: Diagnostics.Strict_Type_Checking_Options,
|
2018-08-06 23:54:57 +02:00
|
|
|
description: Diagnostics.Raise_error_on_expressions_and_declarations_with_an_implied_any_type
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "strictNullChecks",
|
2015-06-04 22:56:33 +02:00
|
|
|
type: "boolean",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2018-08-06 23:54:57 +02:00
|
|
|
strictFlag: true,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-03-22 20:01:08 +01:00
|
|
|
category: Diagnostics.Strict_Type_Checking_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Enable_strict_null_checks
|
2015-08-21 02:37:56 +02:00
|
|
|
},
|
2017-09-18 15:33:47 +02:00
|
|
|
{
|
|
|
|
name: "strictFunctionTypes",
|
|
|
|
type: "boolean",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2018-08-06 23:54:57 +02:00
|
|
|
strictFlag: true,
|
2017-09-18 15:33:47 +02:00
|
|
|
showInSimplifiedHelpView: true,
|
|
|
|
category: Diagnostics.Strict_Type_Checking_Options,
|
|
|
|
description: Diagnostics.Enable_strict_checking_of_function_types
|
|
|
|
},
|
2018-09-11 00:12:16 +02:00
|
|
|
{
|
|
|
|
name: "strictBindCallApply",
|
|
|
|
type: "boolean",
|
|
|
|
strictFlag: true,
|
|
|
|
showInSimplifiedHelpView: true,
|
|
|
|
category: Diagnostics.Strict_Type_Checking_Options,
|
|
|
|
description: Diagnostics.Enable_strict_bind_call_and_apply_methods_on_functions
|
|
|
|
},
|
2017-11-16 19:58:00 +01:00
|
|
|
{
|
|
|
|
name: "strictPropertyInitialization",
|
|
|
|
type: "boolean",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2018-08-06 23:54:57 +02:00
|
|
|
strictFlag: true,
|
2017-11-16 19:58:00 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
|
|
|
category: Diagnostics.Strict_Type_Checking_Options,
|
|
|
|
description: Diagnostics.Enable_strict_checking_of_property_initialization_in_classes
|
|
|
|
},
|
2016-03-26 00:37:28 +01:00
|
|
|
{
|
|
|
|
name: "noImplicitThis",
|
|
|
|
type: "boolean",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2018-08-06 23:54:57 +02:00
|
|
|
strictFlag: true,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-03-22 20:01:08 +01:00
|
|
|
category: Diagnostics.Strict_Type_Checking_Options,
|
2016-03-31 00:01:16 +02:00
|
|
|
description: Diagnostics.Raise_error_on_this_expressions_with_an_implied_any_type,
|
2016-03-26 00:37:28 +01:00
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
2017-03-16 00:15:59 +01:00
|
|
|
name: "alwaysStrict",
|
2014-12-10 21:37:09 +01:00
|
|
|
type: "boolean",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsSourceFile: true,
|
2018-08-06 23:54:57 +02:00
|
|
|
strictFlag: true,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-03-22 20:01:08 +01:00
|
|
|
category: Diagnostics.Strict_Type_Checking_Options,
|
2017-03-16 00:15:59 +01:00
|
|
|
description: Diagnostics.Parse_in_strict_mode_and_emit_use_strict_for_each_source_file
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
2017-03-16 00:15:59 +01:00
|
|
|
|
|
|
|
// Additional Checks
|
2016-06-25 00:38:39 +02:00
|
|
|
{
|
|
|
|
name: "noUnusedLocals",
|
|
|
|
type: "boolean",
|
2018-08-06 23:54:57 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-03-16 00:15:59 +01:00
|
|
|
category: Diagnostics.Additional_Checks,
|
2016-07-26 19:28:49 +02:00
|
|
|
description: Diagnostics.Report_errors_on_unused_locals,
|
2016-06-25 00:38:39 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "noUnusedParameters",
|
|
|
|
type: "boolean",
|
2018-08-06 23:54:57 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-03-16 00:15:59 +01:00
|
|
|
category: Diagnostics.Additional_Checks,
|
2016-07-26 19:28:49 +02:00
|
|
|
description: Diagnostics.Report_errors_on_unused_parameters,
|
2016-06-25 00:38:39 +02:00
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "noImplicitReturns",
|
2014-08-02 02:12:29 +02:00
|
|
|
type: "boolean",
|
2018-08-06 23:54:57 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-03-16 00:15:59 +01:00
|
|
|
category: Diagnostics.Additional_Checks,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Report_error_when_not_all_code_paths_in_function_return_a_value
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "noFallthroughCasesInSwitch",
|
2014-08-02 02:12:29 +02:00
|
|
|
type: "boolean",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsBindDiagnostics: true,
|
2018-08-06 23:54:57 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-03-16 00:15:59 +01:00
|
|
|
category: Diagnostics.Additional_Checks,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Report_errors_for_fallthrough_cases_in_switch_statement
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
2017-02-08 08:10:43 +01:00
|
|
|
|
|
|
|
// Module Resolution
|
2015-06-04 22:56:33 +02:00
|
|
|
{
|
2015-08-21 01:13:49 +02:00
|
|
|
name: "moduleResolution",
|
2017-01-11 18:52:50 +01:00
|
|
|
type: createMapFromTemplate({
|
2017-11-07 03:13:20 +01:00
|
|
|
node: ModuleResolutionKind.NodeJs,
|
|
|
|
classic: ModuleResolutionKind.Classic,
|
2016-08-16 01:41:32 +02:00
|
|
|
}),
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsModuleResolution: true,
|
2016-09-10 04:37:51 +02:00
|
|
|
paramType: Diagnostics.STRATEGY,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Module_Resolution_Options,
|
2017-02-08 06:54:56 +01:00
|
|
|
description: Diagnostics.Specify_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6,
|
2015-06-04 22:56:33 +02:00
|
|
|
},
|
2016-05-22 02:44:37 +02:00
|
|
|
{
|
2015-11-19 06:46:45 +01:00
|
|
|
name: "baseUrl",
|
2015-04-15 07:11:25 +02:00
|
|
|
type: "string",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsModuleResolution: true,
|
2015-04-15 07:11:25 +02:00
|
|
|
isFilePath: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Module_Resolution_Options,
|
2015-11-25 01:41:41 +01:00
|
|
|
description: Diagnostics.Base_directory_to_resolve_non_absolute_module_names
|
2016-05-22 02:44:37 +02:00
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
2015-11-19 06:46:45 +01:00
|
|
|
// this option can only be specified in tsconfig.json
|
|
|
|
// use type = object to copy the value as-is
|
|
|
|
name: "paths",
|
|
|
|
type: "object",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsModuleResolution: true,
|
2017-02-08 06:54:56 +01:00
|
|
|
isTSConfigOnly: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Module_Resolution_Options,
|
2017-03-22 20:01:08 +01:00
|
|
|
description: Diagnostics.A_series_of_entries_which_re_map_imports_to_lookup_locations_relative_to_the_baseUrl
|
2015-08-21 02:37:56 +02:00
|
|
|
},
|
|
|
|
{
|
2015-11-19 06:46:45 +01:00
|
|
|
// this option can only be specified in tsconfig.json
|
|
|
|
// use type = object to copy the value as-is
|
|
|
|
name: "rootDirs",
|
2016-03-10 20:14:29 +01:00
|
|
|
type: "list",
|
2015-11-26 01:41:09 +01:00
|
|
|
isTSConfigOnly: true,
|
2016-03-10 20:14:29 +01:00
|
|
|
element: {
|
|
|
|
name: "rootDirs",
|
|
|
|
type: "string",
|
|
|
|
isFilePath: true
|
2017-02-08 06:54:56 +01:00
|
|
|
},
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsModuleResolution: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Module_Resolution_Options,
|
2017-03-22 20:01:08 +01:00
|
|
|
description: Diagnostics.List_of_root_folders_whose_combined_content_represents_the_structure_of_the_project_at_runtime
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
|
|
|
{
|
2016-06-11 00:44:11 +02:00
|
|
|
name: "typeRoots",
|
|
|
|
type: "list",
|
|
|
|
element: {
|
|
|
|
name: "typeRoots",
|
2016-06-13 18:33:49 +02:00
|
|
|
type: "string",
|
|
|
|
isFilePath: true
|
2017-02-08 06:54:56 +01:00
|
|
|
},
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsModuleResolution: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Module_Resolution_Options,
|
2017-02-08 06:54:56 +01:00
|
|
|
description: Diagnostics.List_of_folders_to_include_type_definitions_from
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
2015-08-27 02:13:53 +02:00
|
|
|
{
|
2016-04-06 22:49:25 +02:00
|
|
|
name: "types",
|
|
|
|
type: "list",
|
|
|
|
element: {
|
|
|
|
name: "types",
|
|
|
|
type: "string"
|
|
|
|
},
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsModuleResolution: true,
|
2017-02-08 21:14:43 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Module_Resolution_Options,
|
2016-04-06 22:49:25 +02:00
|
|
|
description: Diagnostics.Type_declaration_files_to_be_included_in_compilation
|
2015-08-27 02:13:53 +02:00
|
|
|
},
|
2014-12-10 21:37:09 +01:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "allowSyntheticDefaultImports",
|
2014-12-10 21:37:09 +01:00
|
|
|
type: "boolean",
|
2018-08-10 23:44:44 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Module_Resolution_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking
|
2014-12-10 21:37:09 +01:00
|
|
|
},
|
2018-01-09 01:36:23 +01:00
|
|
|
{
|
|
|
|
name: "esModuleInterop",
|
|
|
|
type: "boolean",
|
2018-08-10 23:44:44 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2018-01-09 01:36:23 +01:00
|
|
|
showInSimplifiedHelpView: true,
|
|
|
|
category: Diagnostics.Module_Resolution_Options,
|
|
|
|
description: Diagnostics.Enables_emit_interoperability_between_CommonJS_and_ES_Modules_via_creation_of_namespace_objects_for_all_imports_Implies_allowSyntheticDefaultImports
|
|
|
|
},
|
2017-08-11 19:03:21 +02:00
|
|
|
{
|
|
|
|
name: "preserveSymlinks",
|
|
|
|
type: "boolean",
|
|
|
|
category: Diagnostics.Module_Resolution_Options,
|
|
|
|
description: Diagnostics.Do_not_resolve_the_real_path_of_symlinks,
|
|
|
|
},
|
2017-02-08 08:10:43 +01:00
|
|
|
|
2017-02-08 21:14:43 +01:00
|
|
|
// Source Maps
|
|
|
|
{
|
|
|
|
name: "sourceRoot",
|
2015-08-21 02:37:56 +02:00
|
|
|
type: "string",
|
2017-02-08 21:14:43 +01:00
|
|
|
paramType: Diagnostics.LOCATION,
|
2017-03-22 20:01:08 +01:00
|
|
|
category: Diagnostics.Source_Map_Options,
|
2017-02-08 21:14:43 +01:00
|
|
|
description: Diagnostics.Specify_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
|
|
|
{
|
2017-02-08 21:14:43 +01:00
|
|
|
name: "mapRoot",
|
2014-08-02 02:12:29 +02:00
|
|
|
type: "string",
|
2017-02-08 21:14:43 +01:00
|
|
|
paramType: Diagnostics.LOCATION,
|
2017-03-22 20:01:08 +01:00
|
|
|
category: Diagnostics.Source_Map_Options,
|
2017-02-08 21:14:43 +01:00
|
|
|
description: Diagnostics.Specify_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations,
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
2014-12-10 21:37:09 +01:00
|
|
|
{
|
2017-02-08 21:14:43 +01:00
|
|
|
name: "inlineSourceMap",
|
2014-12-10 21:37:09 +01:00
|
|
|
type: "boolean",
|
2017-03-22 20:01:08 +01:00
|
|
|
category: Diagnostics.Source_Map_Options,
|
2017-02-08 21:14:43 +01:00
|
|
|
description: Diagnostics.Emit_a_single_file_with_source_maps_instead_of_having_a_separate_file
|
2014-12-10 21:37:09 +01:00
|
|
|
},
|
2015-11-02 22:20:48 +01:00
|
|
|
{
|
2017-02-08 21:14:43 +01:00
|
|
|
name: "inlineSources",
|
2014-08-02 02:12:29 +02:00
|
|
|
type: "boolean",
|
2017-03-22 20:01:08 +01:00
|
|
|
category: Diagnostics.Source_Map_Options,
|
2017-02-14 07:21:34 +01:00
|
|
|
description: Diagnostics.Emit_the_source_alongside_the_sourcemaps_within_a_single_file_requires_inlineSourceMap_or_sourceMap_to_be_set
|
2015-11-02 22:20:48 +01:00
|
|
|
},
|
2017-02-08 21:14:43 +01:00
|
|
|
|
2017-02-08 08:10:43 +01:00
|
|
|
// Experimental
|
2015-01-15 22:22:23 +01:00
|
|
|
{
|
2015-06-02 00:01:24 +02:00
|
|
|
name: "experimentalDecorators",
|
|
|
|
type: "boolean",
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Experimental_Options,
|
2015-06-02 00:01:24 +02:00
|
|
|
description: Diagnostics.Enables_experimental_support_for_ES7_decorators
|
|
|
|
},
|
2015-04-02 02:58:28 +02:00
|
|
|
{
|
|
|
|
name: "emitDecoratorMetadata",
|
|
|
|
type: "boolean",
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Experimental_Options,
|
2015-06-02 00:01:24 +02:00
|
|
|
description: Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators
|
2015-08-21 01:13:49 +02:00
|
|
|
},
|
2017-02-08 08:10:43 +01:00
|
|
|
|
2017-02-08 21:14:43 +01:00
|
|
|
// Advanced
|
2015-08-21 01:13:49 +02:00
|
|
|
{
|
2017-03-16 00:15:59 +01:00
|
|
|
name: "jsxFactory",
|
2015-01-15 22:22:23 +01:00
|
|
|
type: "string",
|
2017-03-16 00:15:59 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h
|
2015-10-15 23:43:51 +02:00
|
|
|
},
|
2018-04-06 00:27:44 +02:00
|
|
|
{
|
|
|
|
name: "resolveJsonModule",
|
|
|
|
type: "boolean",
|
|
|
|
category: Diagnostics.Advanced_Options,
|
2018-05-04 20:14:39 +02:00
|
|
|
description: Diagnostics.Include_modules_imported_with_json_extension
|
2018-04-06 00:27:44 +02:00
|
|
|
},
|
2017-02-08 08:10:43 +01:00
|
|
|
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
2017-02-08 21:14:43 +01:00
|
|
|
name: "out",
|
2014-08-02 02:12:29 +02:00
|
|
|
type: "string",
|
2017-02-08 21:14:43 +01:00
|
|
|
isFilePath: false, // This is intentionally broken to support compatability with existing tsconfig files
|
|
|
|
// for correct behaviour, please use outFile
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-02-08 21:14:43 +01:00
|
|
|
paramType: Diagnostics.FILE,
|
2017-02-08 21:25:38 +01:00
|
|
|
description: Diagnostics.Deprecated_Use_outFile_instead_Concatenate_and_emit_output_to_single_file,
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
2015-08-27 02:13:53 +02:00
|
|
|
{
|
2017-02-08 21:14:43 +01:00
|
|
|
name: "reactNamespace",
|
|
|
|
type: "string",
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-02-08 21:25:38 +01:00
|
|
|
description: Diagnostics.Deprecated_Use_jsxFactory_instead_Specify_the_object_invoked_for_createElement_when_targeting_react_JSX_emit
|
2015-08-27 02:13:53 +02:00
|
|
|
},
|
2014-12-10 21:37:09 +01:00
|
|
|
{
|
2017-02-08 21:14:43 +01:00
|
|
|
name: "skipDefaultLibCheck",
|
2014-12-10 21:37:09 +01:00
|
|
|
type: "boolean",
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-02-08 21:25:38 +01:00
|
|
|
description: Diagnostics.Deprecated_Use_skipLibCheck_instead_Skip_type_checking_of_default_library_declaration_files
|
2014-12-10 21:37:09 +01:00
|
|
|
},
|
2015-02-03 22:15:28 +01:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "charset",
|
2015-11-19 06:46:45 +01:00
|
|
|
type: "string",
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.The_character_set_of_the_input_files
|
2015-11-19 06:46:45 +01:00
|
|
|
},
|
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "emitBOM",
|
2015-02-03 22:15:28 +01:00
|
|
|
type: "boolean",
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-02-14 07:21:34 +01:00
|
|
|
description: Diagnostics.Emit_a_UTF_8_Byte_Order_Mark_BOM_in_the_beginning_of_output_files
|
2015-02-03 22:15:28 +01:00
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "locale",
|
|
|
|
type: "string",
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-03-22 20:01:08 +01:00
|
|
|
description: Diagnostics.The_locale_used_when_displaying_messages_to_the_user_e_g_en_us
|
2015-11-20 06:11:57 +01:00
|
|
|
},
|
2016-04-06 01:33:11 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "newLine",
|
2017-01-11 18:52:50 +01:00
|
|
|
type: createMapFromTemplate({
|
2017-11-07 03:13:20 +01:00
|
|
|
crlf: NewLineKind.CarriageReturnLineFeed,
|
|
|
|
lf: NewLineKind.LineFeed
|
2016-08-16 01:41:32 +02:00
|
|
|
}),
|
2017-02-08 08:10:43 +01:00
|
|
|
paramType: Diagnostics.NEWLINE,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Specify_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix,
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "noErrorTruncation",
|
2014-08-02 02:12:29 +02:00
|
|
|
type: "boolean",
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-03-22 20:01:08 +01:00
|
|
|
description: Diagnostics.Do_not_truncate_error_messages
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "noLib",
|
2014-08-02 02:12:29 +02:00
|
|
|
type: "boolean",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsModuleResolution: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Do_not_include_the_default_library_file_lib_d_ts
|
2015-04-02 02:58:28 +02:00
|
|
|
},
|
2015-06-02 00:01:24 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "noResolve",
|
2015-06-02 00:01:24 +02:00
|
|
|
type: "boolean",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsModuleResolution: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-03-22 20:01:08 +01:00
|
|
|
description: Diagnostics.Do_not_add_triple_slash_references_or_imported_modules_to_the_list_of_compiled_files
|
2015-06-02 00:01:24 +02:00
|
|
|
},
|
2015-04-02 02:58:28 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "stripInternal",
|
2015-04-02 02:58:28 +02:00
|
|
|
type: "boolean",
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-02-08 08:10:43 +01:00
|
|
|
description: Diagnostics.Do_not_emit_declarations_for_code_that_has_an_internal_annotation,
|
2015-10-15 23:43:51 +02:00
|
|
|
},
|
2015-09-03 19:49:39 +02:00
|
|
|
{
|
2017-02-08 08:10:43 +01:00
|
|
|
name: "disableSizeLimit",
|
2015-09-03 19:49:39 +02:00
|
|
|
type: "boolean",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsSourceFile: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-03-22 20:01:08 +01:00
|
|
|
description: Diagnostics.Disable_size_limitations_on_JavaScript_projects
|
2015-09-03 19:49:39 +02:00
|
|
|
},
|
|
|
|
{
|
2016-02-06 01:30:01 +01:00
|
|
|
name: "noImplicitUseStrict",
|
2015-09-03 19:49:39 +02:00
|
|
|
type: "boolean",
|
2018-08-06 23:54:57 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2016-02-03 23:16:09 +01:00
|
|
|
description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output
|
2015-09-03 19:49:39 +02:00
|
|
|
},
|
|
|
|
{
|
2017-02-08 21:14:43 +01:00
|
|
|
name: "noEmitHelpers",
|
2015-09-03 19:49:39 +02:00
|
|
|
type: "boolean",
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-02-08 21:14:43 +01:00
|
|
|
description: Diagnostics.Do_not_generate_custom_helper_functions_like_extends_in_compiled_output
|
2015-09-03 19:49:39 +02:00
|
|
|
},
|
|
|
|
{
|
2017-02-08 21:14:43 +01:00
|
|
|
name: "noEmitOnError",
|
2015-09-03 19:49:39 +02:00
|
|
|
type: "boolean",
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-02-08 21:14:43 +01:00
|
|
|
description: Diagnostics.Do_not_emit_outputs_if_any_errors_were_reported,
|
2015-10-29 17:33:27 +01:00
|
|
|
},
|
2015-10-15 23:43:51 +02:00
|
|
|
{
|
2017-02-08 21:14:43 +01:00
|
|
|
name: "preserveConstEnums",
|
2015-10-15 23:43:51 +02:00
|
|
|
type: "boolean",
|
2017-02-09 04:25:08 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2017-02-08 21:14:43 +01:00
|
|
|
description: Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code
|
2015-11-09 23:24:19 +01:00
|
|
|
},
|
|
|
|
{
|
2017-02-09 04:32:27 +01:00
|
|
|
name: "declarationDir",
|
2015-11-19 06:46:45 +01:00
|
|
|
type: "string",
|
|
|
|
isFilePath: true,
|
2017-02-09 04:32:27 +01:00
|
|
|
paramType: Diagnostics.DIRECTORY,
|
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Output_directory_for_generated_declaration_files
|
2015-11-20 06:11:57 +01:00
|
|
|
},
|
2016-04-06 01:33:11 +02:00
|
|
|
{
|
2017-02-09 04:32:27 +01:00
|
|
|
name: "skipLibCheck",
|
2016-02-15 03:41:38 +01:00
|
|
|
type: "boolean",
|
2017-02-09 04:32:27 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Skip_type_checking_of_declaration_files,
|
2016-04-06 01:33:11 +02:00
|
|
|
},
|
2016-04-06 22:49:25 +02:00
|
|
|
{
|
2017-02-09 04:32:27 +01:00
|
|
|
name: "allowUnusedLabels",
|
2016-06-11 09:12:04 +02:00
|
|
|
type: "boolean",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsBindDiagnostics: true,
|
2018-08-06 23:54:57 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2017-02-09 04:32:27 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Do_not_report_errors_on_unused_labels
|
2016-04-06 22:49:25 +02:00
|
|
|
},
|
2015-11-20 06:33:33 +01:00
|
|
|
{
|
2017-02-09 04:32:27 +01:00
|
|
|
name: "allowUnreachableCode",
|
2015-11-09 23:24:19 +01:00
|
|
|
type: "boolean",
|
2018-09-17 19:53:48 +02:00
|
|
|
affectsBindDiagnostics: true,
|
2018-08-06 23:54:57 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2017-02-09 04:32:27 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Do_not_report_errors_on_unreachable_code
|
2015-11-20 22:45:25 +01:00
|
|
|
},
|
2015-09-16 22:57:51 +02:00
|
|
|
{
|
2017-02-09 04:32:27 +01:00
|
|
|
name: "suppressExcessPropertyErrors",
|
2015-10-28 22:02:46 +01:00
|
|
|
type: "boolean",
|
2018-08-06 23:54:57 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2017-02-09 04:32:27 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Suppress_excess_property_checks_for_object_literals,
|
2015-11-26 06:23:35 +01:00
|
|
|
},
|
|
|
|
{
|
2017-02-09 04:32:27 +01:00
|
|
|
name: "suppressImplicitAnyIndexErrors",
|
2015-11-26 06:23:35 +01:00
|
|
|
type: "boolean",
|
2018-08-06 23:54:57 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2017-02-09 04:32:27 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures,
|
2016-02-03 23:16:09 +01:00
|
|
|
},
|
|
|
|
{
|
2017-02-09 04:32:27 +01:00
|
|
|
name: "forceConsistentCasingInFileNames",
|
2016-02-03 23:16:09 +01:00
|
|
|
type: "boolean",
|
2017-02-09 04:32:27 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Disallow_inconsistently_cased_references_to_the_same_file
|
2016-02-15 03:41:38 +01:00
|
|
|
},
|
2016-02-13 16:48:25 +01:00
|
|
|
{
|
|
|
|
name: "maxNodeModuleJsDepth",
|
|
|
|
type: "number",
|
2018-11-09 19:48:28 +01:00
|
|
|
affectsModuleResolution: true,
|
2017-02-09 04:32:27 +01:00
|
|
|
category: Diagnostics.Advanced_Options,
|
2016-02-13 16:48:25 +01:00
|
|
|
description: Diagnostics.The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files
|
2016-05-24 02:00:10 +02:00
|
|
|
},
|
2017-06-12 22:09:01 +02:00
|
|
|
{
|
|
|
|
name: "noStrictGenericChecks",
|
|
|
|
type: "boolean",
|
2018-08-06 23:54:57 +02:00
|
|
|
affectsSemanticDiagnostics: true,
|
2017-06-12 22:09:01 +02:00
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Disable_strict_checking_of_generic_signatures_in_function_types,
|
|
|
|
},
|
2018-04-09 19:45:13 +02:00
|
|
|
{
|
|
|
|
name: "keyofStringsOnly",
|
|
|
|
type: "boolean",
|
|
|
|
category: Diagnostics.Advanced_Options,
|
|
|
|
description: Diagnostics.Resolve_keyof_to_string_valued_property_names_only_no_numbers_or_symbols,
|
|
|
|
},
|
2016-04-06 22:25:29 +02:00
|
|
|
{
|
2017-02-14 22:35:16 +01:00
|
|
|
// A list of plugins to load in the language service
|
|
|
|
name: "plugins",
|
2016-03-28 23:20:29 +02:00
|
|
|
type: "list",
|
2017-02-14 22:35:16 +01:00
|
|
|
isTSConfigOnly: true,
|
2016-03-28 23:20:29 +02:00
|
|
|
element: {
|
2017-02-14 22:35:16 +01:00
|
|
|
name: "plugin",
|
|
|
|
type: "object"
|
2016-03-28 23:20:29 +02:00
|
|
|
},
|
2017-03-22 20:01:08 +01:00
|
|
|
description: Diagnostics.List_of_language_service_plugins
|
2015-09-03 19:49:39 +02:00
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
];
|
2015-03-31 19:52:21 +02:00
|
|
|
|
2018-09-17 19:53:48 +02:00
|
|
|
/* @internal */
|
|
|
|
export const semanticDiagnosticsOptionDeclarations: ReadonlyArray<CommandLineOption> =
|
|
|
|
optionDeclarations.filter(option => !!option.affectsSemanticDiagnostics);
|
|
|
|
|
|
|
|
/* @internal */
|
|
|
|
export const moduleResolutionOptionDeclarations: ReadonlyArray<CommandLineOption> =
|
|
|
|
optionDeclarations.filter(option => !!option.affectsModuleResolution);
|
|
|
|
|
|
|
|
/* @internal */
|
|
|
|
export const sourceFileAffectingCompilerOptions: ReadonlyArray<CommandLineOption> = optionDeclarations.filter(option =>
|
|
|
|
!!option.affectsSourceFile || !!option.affectsModuleResolution || !!option.affectsBindDiagnostics);
|
|
|
|
|
2018-08-29 21:23:52 +02:00
|
|
|
/* @internal */
|
|
|
|
export const buildOpts: CommandLineOption[] = [
|
|
|
|
...commonOptionsWithBuild,
|
|
|
|
{
|
|
|
|
name: "verbose",
|
|
|
|
shortName: "v",
|
|
|
|
category: Diagnostics.Command_line_Options,
|
|
|
|
description: Diagnostics.Enable_verbose_logging,
|
|
|
|
type: "boolean"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "dry",
|
|
|
|
shortName: "d",
|
|
|
|
category: Diagnostics.Command_line_Options,
|
|
|
|
description: Diagnostics.Show_what_would_be_built_or_deleted_if_specified_with_clean,
|
|
|
|
type: "boolean"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "force",
|
|
|
|
shortName: "f",
|
|
|
|
category: Diagnostics.Command_line_Options,
|
|
|
|
description: Diagnostics.Build_all_projects_including_those_that_appear_to_be_up_to_date,
|
|
|
|
type: "boolean"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "clean",
|
|
|
|
category: Diagnostics.Command_line_Options,
|
|
|
|
description: Diagnostics.Delete_the_outputs_of_all_projects,
|
|
|
|
type: "boolean"
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2016-03-10 20:14:29 +01:00
|
|
|
/* @internal */
|
2016-11-24 01:09:34 +01:00
|
|
|
export const typeAcquisitionDeclarations: CommandLineOption[] = [
|
2016-03-10 20:14:29 +01:00
|
|
|
{
|
2016-11-21 22:42:42 +01:00
|
|
|
/* @deprecated typingOptions.enableAutoDiscovery
|
|
|
|
* Use typeAcquisition.enable instead.
|
|
|
|
*/
|
2016-03-10 20:14:29 +01:00
|
|
|
name: "enableAutoDiscovery",
|
|
|
|
type: "boolean",
|
|
|
|
},
|
|
|
|
{
|
2016-11-19 02:46:06 +01:00
|
|
|
name: "enable",
|
2016-03-10 20:14:29 +01:00
|
|
|
type: "boolean",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "include",
|
|
|
|
type: "list",
|
|
|
|
element: {
|
|
|
|
name: "include",
|
|
|
|
type: "string"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "exclude",
|
|
|
|
type: "list",
|
|
|
|
element: {
|
2016-03-16 22:08:49 +01:00
|
|
|
name: "exclude",
|
2016-03-10 20:14:29 +01:00
|
|
|
type: "string"
|
|
|
|
}
|
2015-09-03 19:49:39 +02:00
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
];
|
2015-03-31 19:52:21 +02:00
|
|
|
|
2015-08-25 23:34:34 +02:00
|
|
|
/* @internal */
|
2015-07-27 13:52:57 +02:00
|
|
|
export interface OptionNameMap {
|
|
|
|
optionNameMap: Map<CommandLineOption>;
|
|
|
|
shortOptionNames: Map<string>;
|
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
|
2016-08-18 00:23:28 +02:00
|
|
|
/* @internal */
|
|
|
|
export const defaultInitCompilerOptions: CompilerOptions = {
|
|
|
|
module: ModuleKind.CommonJS,
|
|
|
|
target: ScriptTarget.ES5,
|
2018-01-09 01:36:23 +01:00
|
|
|
strict: true,
|
|
|
|
esModuleInterop: true
|
2016-08-18 00:23:28 +02:00
|
|
|
};
|
|
|
|
|
2015-07-27 13:52:57 +02:00
|
|
|
let optionNameMapCache: OptionNameMap;
|
2016-03-28 23:20:29 +02:00
|
|
|
|
2016-11-21 22:42:42 +01:00
|
|
|
/* @internal */
|
2016-11-22 23:47:44 +01:00
|
|
|
export function convertEnableAutoDiscoveryToEnable(typeAcquisition: TypeAcquisition): TypeAcquisition {
|
|
|
|
// Convert deprecated typingOptions.enableAutoDiscovery to typeAcquisition.enable
|
2016-11-21 22:42:42 +01:00
|
|
|
if (typeAcquisition && typeAcquisition.enableAutoDiscovery !== undefined && typeAcquisition.enable === undefined) {
|
2017-12-04 22:36:01 +01:00
|
|
|
return {
|
2016-11-22 23:47:44 +01:00
|
|
|
enable: typeAcquisition.enableAutoDiscovery,
|
|
|
|
include: typeAcquisition.include || [],
|
|
|
|
exclude: typeAcquisition.exclude || []
|
|
|
|
};
|
2016-11-21 22:42:42 +01:00
|
|
|
}
|
2016-11-22 23:47:44 +01:00
|
|
|
return typeAcquisition;
|
2016-11-21 22:42:42 +01:00
|
|
|
}
|
|
|
|
|
2017-05-25 22:30:27 +02:00
|
|
|
function getOptionNameMap(): OptionNameMap {
|
2018-08-18 02:22:08 +02:00
|
|
|
return optionNameMapCache || (optionNameMapCache = createOptionNameMap(optionDeclarations));
|
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
|
2018-08-18 02:22:08 +02:00
|
|
|
/*@internal*/
|
|
|
|
export function createOptionNameMap(optionDeclarations: ReadonlyArray<CommandLineOption>): OptionNameMap {
|
2016-08-11 01:47:06 +02:00
|
|
|
const optionNameMap = createMap<CommandLineOption>();
|
|
|
|
const shortOptionNames = createMap<string>();
|
2015-01-15 22:22:23 +01:00
|
|
|
forEach(optionDeclarations, option => {
|
2016-12-05 23:13:32 +01:00
|
|
|
optionNameMap.set(option.name.toLowerCase(), option);
|
2015-01-15 22:22:23 +01:00
|
|
|
if (option.shortName) {
|
2016-12-05 23:13:32 +01:00
|
|
|
shortOptionNames.set(option.shortName, option.name);
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
|
|
|
});
|
2015-07-27 13:52:57 +02:00
|
|
|
|
2018-08-18 02:22:08 +02:00
|
|
|
return { optionNameMap, shortOptionNames };
|
2015-07-27 13:52:57 +02:00
|
|
|
}
|
|
|
|
|
2016-03-14 23:53:42 +01:00
|
|
|
/* @internal */
|
2016-03-16 21:49:36 +01:00
|
|
|
export function createCompilerDiagnosticForInvalidCustomType(opt: CommandLineOptionOfCustomType): Diagnostic {
|
2016-11-16 21:25:24 +01:00
|
|
|
return createDiagnosticForInvalidCustomType(opt, createCompilerDiagnostic);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createDiagnosticForInvalidCustomType(opt: CommandLineOptionOfCustomType, createDiagnostic: (message: DiagnosticMessage, arg0: string, arg1: string) => Diagnostic): Diagnostic {
|
2016-12-28 18:05:52 +01:00
|
|
|
const namesOfType = arrayFrom(opt.type.keys()).map(key => `'${key}'`).join(", ");
|
2016-11-16 21:25:24 +01:00
|
|
|
return createDiagnostic(Diagnostics.Argument_for_0_option_must_be_Colon_1, `--${opt.name}`, namesOfType);
|
2016-03-14 23:53:42 +01:00
|
|
|
}
|
|
|
|
|
2016-03-28 23:20:29 +02:00
|
|
|
/* @internal */
|
2017-07-21 16:16:22 +02:00
|
|
|
export function parseCustomTypeOption(opt: CommandLineOptionOfCustomType, value: string, errors: Push<Diagnostic>) {
|
2016-12-07 17:19:47 +01:00
|
|
|
return convertJsonOptionOfCustomType(opt, trimString(value || ""), errors);
|
2016-03-28 23:20:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* @internal */
|
2017-07-21 16:16:22 +02:00
|
|
|
export function parseListTypeOption(opt: CommandLineOptionOfListType, value = "", errors: Push<Diagnostic>): (string | number)[] | undefined {
|
2016-06-10 23:14:32 +02:00
|
|
|
value = trimString(value);
|
|
|
|
if (startsWith(value, "-")) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2016-06-10 23:35:13 +02:00
|
|
|
if (value === "") {
|
2016-06-10 23:14:32 +02:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
const values = value.split(",");
|
2016-03-28 23:20:29 +02:00
|
|
|
switch (opt.element.type) {
|
|
|
|
case "number":
|
2016-06-10 23:14:32 +02:00
|
|
|
return map(values, parseInt);
|
2016-03-28 23:20:29 +02:00
|
|
|
case "string":
|
2016-06-10 23:14:32 +02:00
|
|
|
return map(values, v => v || "");
|
2016-03-28 23:20:29 +02:00
|
|
|
default:
|
2018-05-22 23:46:57 +02:00
|
|
|
return mapDefined(values, v => parseCustomTypeOption(<CommandLineOptionOfCustomType>opt.element, v, errors));
|
2016-03-28 23:20:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-13 18:54:35 +02:00
|
|
|
/* @internal */
|
|
|
|
export interface OptionsBase {
|
|
|
|
[option: string]: CompilerOptionsValue | undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Tuple with error messages for 'unknown compiler option', 'option requires type' */
|
|
|
|
type ParseCommandLineWorkerDiagnostics = [DiagnosticMessage, DiagnosticMessage];
|
|
|
|
|
2018-09-14 19:02:42 +02:00
|
|
|
function parseCommandLineWorker(
|
2018-09-13 18:54:35 +02:00
|
|
|
getOptionNameMap: () => OptionNameMap,
|
|
|
|
[unknownOptionDiagnostic, optionTypeMismatchDiagnostic]: ParseCommandLineWorkerDiagnostics,
|
|
|
|
commandLine: ReadonlyArray<string>,
|
|
|
|
readFile?: (path: string) => string | undefined) {
|
2018-09-14 19:02:42 +02:00
|
|
|
const options = {} as OptionsBase;
|
2015-11-04 23:02:33 +01:00
|
|
|
const fileNames: string[] = [];
|
|
|
|
const errors: Diagnostic[] = [];
|
2015-07-27 13:52:57 +02:00
|
|
|
|
2014-07-13 01:04:16 +02:00
|
|
|
parseStrings(commandLine);
|
|
|
|
return {
|
2014-11-18 21:05:40 +01:00
|
|
|
options,
|
2015-02-04 01:08:46 +01:00
|
|
|
fileNames,
|
2014-11-18 21:05:40 +01:00
|
|
|
errors
|
2014-07-13 01:04:16 +02:00
|
|
|
};
|
|
|
|
|
2017-07-21 16:16:22 +02:00
|
|
|
function parseStrings(args: ReadonlyArray<string>) {
|
2015-06-26 02:36:19 +02:00
|
|
|
let i = 0;
|
2014-07-13 01:04:16 +02:00
|
|
|
while (i < args.length) {
|
2017-05-25 22:30:27 +02:00
|
|
|
const s = args[i];
|
2015-12-23 00:45:00 +01:00
|
|
|
i++;
|
2014-07-13 01:04:16 +02:00
|
|
|
if (s.charCodeAt(0) === CharacterCodes.at) {
|
|
|
|
parseResponseFile(s.slice(1));
|
|
|
|
}
|
|
|
|
else if (s.charCodeAt(0) === CharacterCodes.minus) {
|
2018-09-13 18:54:35 +02:00
|
|
|
const opt = getOptionDeclarationFromName(getOptionNameMap, s.slice(s.charCodeAt(1) === CharacterCodes.minus ? 2 : 1), /*allowShort*/ true);
|
2016-12-05 23:13:32 +01:00
|
|
|
if (opt) {
|
2016-03-10 20:14:29 +01:00
|
|
|
if (opt.isTSConfigOnly) {
|
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.Option_0_can_only_be_specified_in_tsconfig_json_file, opt.name));
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
2016-03-10 20:14:29 +01:00
|
|
|
else {
|
|
|
|
// Check to see if no argument was provided (e.g. "--locale" is the last command-line argument).
|
|
|
|
if (!args[i] && opt.type !== "boolean") {
|
2018-09-13 18:54:35 +02:00
|
|
|
errors.push(createCompilerDiagnostic(optionTypeMismatchDiagnostic, opt.name));
|
2016-03-10 20:14:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (opt.type) {
|
|
|
|
case "number":
|
|
|
|
options[opt.name] = parseInt(args[i]);
|
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
case "boolean":
|
2016-10-24 19:45:07 +02:00
|
|
|
// boolean flag has optional value true, false, others
|
2016-12-18 07:44:54 +01:00
|
|
|
const optValue = args[i];
|
2016-10-24 19:45:07 +02:00
|
|
|
options[opt.name] = optValue !== "false";
|
|
|
|
// consume next argument as boolean flag value
|
|
|
|
if (optValue === "false" || optValue === "true") {
|
|
|
|
i++;
|
|
|
|
}
|
2016-03-10 20:14:29 +01:00
|
|
|
break;
|
|
|
|
case "string":
|
|
|
|
options[opt.name] = args[i] || "";
|
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
case "list":
|
2018-10-18 00:17:21 +02:00
|
|
|
const result = parseListTypeOption(opt, args[i], errors);
|
2016-06-10 23:14:32 +02:00
|
|
|
options[opt.name] = result || [];
|
|
|
|
if (result) {
|
|
|
|
i++;
|
|
|
|
}
|
2016-03-10 20:14:29 +01:00
|
|
|
break;
|
|
|
|
// If not a primitive, the possible types are specified in what is effectively a map of options.
|
|
|
|
default:
|
2016-03-28 23:20:29 +02:00
|
|
|
options[opt.name] = parseCustomTypeOption(<CommandLineOptionOfCustomType>opt, args[i], errors);
|
2016-03-10 20:14:29 +01:00
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2018-09-13 18:54:35 +02:00
|
|
|
errors.push(createCompilerDiagnostic(unknownOptionDiagnostic, s));
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-02-04 01:08:46 +01:00
|
|
|
fileNames.push(s);
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-04 01:08:46 +01:00
|
|
|
function parseResponseFile(fileName: string) {
|
2015-11-04 23:02:33 +01:00
|
|
|
const text = readFile ? readFile(fileName) : sys.readFile(fileName);
|
2014-07-13 01:04:16 +02:00
|
|
|
|
|
|
|
if (!text) {
|
2015-02-04 01:08:46 +01:00
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.File_0_not_found, fileName));
|
2014-07-13 01:04:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-04 23:02:33 +01:00
|
|
|
const args: string[] = [];
|
2015-06-26 02:36:19 +02:00
|
|
|
let pos = 0;
|
2014-07-13 01:04:16 +02:00
|
|
|
while (true) {
|
|
|
|
while (pos < text.length && text.charCodeAt(pos) <= CharacterCodes.space) pos++;
|
|
|
|
if (pos >= text.length) break;
|
2015-11-04 23:02:33 +01:00
|
|
|
const start = pos;
|
2014-07-13 01:04:16 +02:00
|
|
|
if (text.charCodeAt(start) === CharacterCodes.doubleQuote) {
|
|
|
|
pos++;
|
|
|
|
while (pos < text.length && text.charCodeAt(pos) !== CharacterCodes.doubleQuote) pos++;
|
|
|
|
if (pos < text.length) {
|
|
|
|
args.push(text.substring(start + 1, pos));
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
else {
|
2015-02-04 01:08:46 +01:00
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.Unterminated_quoted_string_in_response_file_0, fileName));
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (text.charCodeAt(pos) > CharacterCodes.space) pos++;
|
|
|
|
args.push(text.substring(start, pos));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parseStrings(args);
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 22:22:23 +01:00
|
|
|
|
2018-09-13 18:54:35 +02:00
|
|
|
export function parseCommandLine(commandLine: ReadonlyArray<string>, readFile?: (path: string) => string | undefined): ParsedCommandLine {
|
|
|
|
return parseCommandLineWorker(getOptionNameMap, [
|
|
|
|
Diagnostics.Unknown_compiler_option_0,
|
|
|
|
Diagnostics.Compiler_option_0_expects_an_argument
|
|
|
|
], commandLine, readFile);
|
|
|
|
}
|
|
|
|
|
2018-06-01 17:23:37 +02:00
|
|
|
/** @internal */
|
2018-08-18 02:22:08 +02:00
|
|
|
export function getOptionFromName(optionName: string, allowShort?: boolean): CommandLineOption | undefined {
|
|
|
|
return getOptionDeclarationFromName(getOptionNameMap, optionName, allowShort);
|
|
|
|
}
|
|
|
|
|
2018-09-13 18:54:35 +02:00
|
|
|
function getOptionDeclarationFromName(getOptionNameMap: () => OptionNameMap, optionName: string, allowShort = false): CommandLineOption | undefined {
|
2017-05-25 22:30:27 +02:00
|
|
|
optionName = optionName.toLowerCase();
|
|
|
|
const { optionNameMap, shortOptionNames } = getOptionNameMap();
|
|
|
|
// Try to translate short option names to their full equivalents.
|
|
|
|
if (allowShort) {
|
|
|
|
const short = shortOptionNames.get(optionName);
|
|
|
|
if (short !== undefined) {
|
|
|
|
optionName = short;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return optionNameMap.get(optionName);
|
|
|
|
}
|
|
|
|
|
2018-08-29 21:23:52 +02:00
|
|
|
/*@internal*/
|
|
|
|
export interface ParsedBuildCommand {
|
|
|
|
buildOptions: BuildOptions;
|
|
|
|
projects: string[];
|
|
|
|
errors: ReadonlyArray<Diagnostic>;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*@internal*/
|
|
|
|
export function parseBuildCommand(args: string[]): ParsedBuildCommand {
|
|
|
|
let buildOptionNameMap: OptionNameMap | undefined;
|
|
|
|
const returnBuildOptionNameMap = () => (buildOptionNameMap || (buildOptionNameMap = createOptionNameMap(buildOpts)));
|
2018-09-14 19:02:42 +02:00
|
|
|
const { options, fileNames: projects, errors } = parseCommandLineWorker(returnBuildOptionNameMap, [
|
2018-09-13 18:54:35 +02:00
|
|
|
Diagnostics.Unknown_build_option_0,
|
|
|
|
Diagnostics.Build_option_0_requires_a_value_of_type_1
|
|
|
|
], args);
|
2018-09-14 19:02:42 +02:00
|
|
|
const buildOptions = options as BuildOptions;
|
2018-08-29 21:23:52 +02:00
|
|
|
|
|
|
|
if (projects.length === 0) {
|
|
|
|
// tsc -b invoked with no extra arguments; act as if invoked with "tsc -b ."
|
|
|
|
projects.push(".");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nonsensical combinations
|
|
|
|
if (buildOptions.clean && buildOptions.force) {
|
2018-09-13 18:54:35 +02:00
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "force"));
|
2018-08-29 21:23:52 +02:00
|
|
|
}
|
|
|
|
if (buildOptions.clean && buildOptions.verbose) {
|
2018-09-13 18:54:35 +02:00
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "verbose"));
|
2018-08-29 21:23:52 +02:00
|
|
|
}
|
|
|
|
if (buildOptions.clean && buildOptions.watch) {
|
2018-09-13 18:54:35 +02:00
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "watch"));
|
2018-08-29 21:23:52 +02:00
|
|
|
}
|
|
|
|
if (buildOptions.watch && buildOptions.dry) {
|
2018-09-13 18:54:35 +02:00
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.Options_0_and_1_cannot_be_combined, "watch", "dry"));
|
2018-08-29 21:23:52 +02:00
|
|
|
}
|
|
|
|
|
2018-09-13 18:54:35 +02:00
|
|
|
return { buildOptions, projects, errors };
|
2018-08-29 21:23:52 +02:00
|
|
|
}
|
2018-05-08 00:12:50 +02:00
|
|
|
|
2018-05-30 19:00:35 +02:00
|
|
|
function getDiagnosticText(_message: DiagnosticMessage, ..._args: any[]): string {
|
|
|
|
const diagnostic = createCompilerDiagnostic.apply(undefined, arguments);
|
|
|
|
return <string>diagnostic.messageText;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* @internal */
|
|
|
|
export function printVersion() {
|
|
|
|
sys.write(getDiagnosticText(Diagnostics.Version_0, version) + sys.newLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* @internal */
|
2018-10-30 16:41:31 +01:00
|
|
|
export function printHelp(optionsList: ReadonlyArray<CommandLineOption>, syntaxPrefix = "") {
|
2018-05-30 19:00:35 +02:00
|
|
|
const output: string[] = [];
|
|
|
|
|
|
|
|
// We want to align our "syntax" and "examples" commands to a certain margin.
|
|
|
|
const syntaxLength = getDiagnosticText(Diagnostics.Syntax_Colon_0, "").length;
|
|
|
|
const examplesLength = getDiagnosticText(Diagnostics.Examples_Colon_0, "").length;
|
|
|
|
let marginLength = Math.max(syntaxLength, examplesLength);
|
|
|
|
|
|
|
|
// Build up the syntactic skeleton.
|
|
|
|
let syntax = makePadding(marginLength - syntaxLength);
|
|
|
|
syntax += `tsc ${syntaxPrefix}[${getDiagnosticText(Diagnostics.options)}] [${getDiagnosticText(Diagnostics.file)}...]`;
|
|
|
|
|
|
|
|
output.push(getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax));
|
|
|
|
output.push(sys.newLine + sys.newLine);
|
|
|
|
|
|
|
|
// Build up the list of examples.
|
|
|
|
const padding = makePadding(marginLength);
|
|
|
|
output.push(getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine);
|
|
|
|
output.push(padding + "tsc --outFile file.js file.ts" + sys.newLine);
|
|
|
|
output.push(padding + "tsc @args.txt" + sys.newLine);
|
|
|
|
output.push(padding + "tsc --build tsconfig.json" + sys.newLine);
|
|
|
|
output.push(sys.newLine);
|
|
|
|
|
|
|
|
output.push(getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine);
|
|
|
|
|
|
|
|
// We want our descriptions to align at the same column in our output,
|
|
|
|
// so we keep track of the longest option usage string.
|
|
|
|
marginLength = 0;
|
|
|
|
const usageColumn: string[] = []; // Things like "-d, --declaration" go in here.
|
|
|
|
const descriptionColumn: string[] = [];
|
|
|
|
|
|
|
|
const optionsDescriptionMap = createMap<string[]>(); // Map between option.description and list of option.type if it is a kind
|
|
|
|
|
|
|
|
for (const option of optionsList) {
|
|
|
|
// If an option lacks a description,
|
|
|
|
// it is not officially supported.
|
|
|
|
if (!option.description) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let usageText = " ";
|
|
|
|
if (option.shortName) {
|
|
|
|
usageText += "-" + option.shortName;
|
|
|
|
usageText += getParamType(option);
|
|
|
|
usageText += ", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
usageText += "--" + option.name;
|
|
|
|
usageText += getParamType(option);
|
|
|
|
|
|
|
|
usageColumn.push(usageText);
|
|
|
|
let description: string;
|
|
|
|
|
|
|
|
if (option.name === "lib") {
|
|
|
|
description = getDiagnosticText(option.description);
|
|
|
|
const element = (<CommandLineOptionOfListType>option).element;
|
|
|
|
const typeMap = <Map<number | string>>element.type;
|
|
|
|
optionsDescriptionMap.set(description, arrayFrom(typeMap.keys()).map(key => `'${key}'`));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
description = getDiagnosticText(option.description);
|
|
|
|
}
|
|
|
|
|
|
|
|
descriptionColumn.push(description);
|
|
|
|
|
|
|
|
// Set the new margin for the description column if necessary.
|
|
|
|
marginLength = Math.max(usageText.length, marginLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special case that can't fit in the loop.
|
|
|
|
const usageText = " @<" + getDiagnosticText(Diagnostics.file) + ">";
|
|
|
|
usageColumn.push(usageText);
|
|
|
|
descriptionColumn.push(getDiagnosticText(Diagnostics.Insert_command_line_options_and_files_from_a_file));
|
|
|
|
marginLength = Math.max(usageText.length, marginLength);
|
|
|
|
|
|
|
|
// Print out each row, aligning all the descriptions on the same column.
|
|
|
|
for (let i = 0; i < usageColumn.length; i++) {
|
|
|
|
const usage = usageColumn[i];
|
|
|
|
const description = descriptionColumn[i];
|
|
|
|
const kindsList = optionsDescriptionMap.get(description);
|
|
|
|
output.push(usage + makePadding(marginLength - usage.length + 2) + description + sys.newLine);
|
|
|
|
|
|
|
|
if (kindsList) {
|
|
|
|
output.push(makePadding(marginLength + 4));
|
|
|
|
for (const kind of kindsList) {
|
|
|
|
output.push(kind + " ");
|
|
|
|
}
|
|
|
|
output.push(sys.newLine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const line of output) {
|
|
|
|
sys.write(line);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
function getParamType(option: CommandLineOption) {
|
|
|
|
if (option.paramType !== undefined) {
|
|
|
|
return " " + getDiagnosticText(option.paramType);
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
function makePadding(paddingLength: number): string {
|
|
|
|
return Array(paddingLength + 1).join(" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-08 00:12:50 +02:00
|
|
|
export type DiagnosticReporter = (diagnostic: Diagnostic) => void;
|
|
|
|
/**
|
|
|
|
* Reports config file diagnostics
|
|
|
|
*/
|
|
|
|
export interface ConfigFileDiagnosticsReporter {
|
|
|
|
/**
|
|
|
|
* Reports unrecoverable error when parsing config file
|
|
|
|
*/
|
|
|
|
onUnRecoverableConfigFileDiagnostic: DiagnosticReporter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface extending ParseConfigHost to support ParseConfigFile that reads config file and reports errors
|
|
|
|
*/
|
|
|
|
export interface ParseConfigFileHost extends ParseConfigHost, ConfigFileDiagnosticsReporter {
|
|
|
|
getCurrentDirectory(): string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads the config file, reports errors if any and exits if the config file cannot be found
|
|
|
|
*/
|
|
|
|
export function getParsedCommandLineOfConfigFile(configFileName: string, optionsToExtend: CompilerOptions, host: ParseConfigFileHost): ParsedCommandLine | undefined {
|
2018-05-22 23:46:57 +02:00
|
|
|
let configFileText: string | undefined;
|
2018-05-08 00:12:50 +02:00
|
|
|
try {
|
|
|
|
configFileText = host.readFile(configFileName);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
const error = createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, configFileName, e.message);
|
|
|
|
host.onUnRecoverableConfigFileDiagnostic(error);
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
if (!configFileText) {
|
|
|
|
const error = createCompilerDiagnostic(Diagnostics.File_0_not_found, configFileName);
|
|
|
|
host.onUnRecoverableConfigFileDiagnostic(error);
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const result = parseJsonText(configFileName, configFileText);
|
|
|
|
const cwd = host.getCurrentDirectory();
|
2018-09-19 01:21:05 +02:00
|
|
|
result.path = toPath(configFileName, cwd, createGetCanonicalFileName(host.useCaseSensitiveFileNames));
|
2018-10-02 23:10:19 +02:00
|
|
|
result.resolvedPath = result.path;
|
|
|
|
result.originalFileName = result.fileName;
|
2018-05-08 00:12:50 +02:00
|
|
|
return parseJsonSourceFileConfigFileContent(result, host, getNormalizedAbsolutePath(getDirectoryPath(configFileName), cwd), optionsToExtend, getNormalizedAbsolutePath(configFileName, cwd));
|
|
|
|
}
|
|
|
|
|
2015-03-31 19:52:21 +02:00
|
|
|
/**
|
2017-04-03 18:32:39 +02:00
|
|
|
* Read tsconfig.json file
|
|
|
|
* @param fileName The path to the config file
|
|
|
|
*/
|
2017-07-14 23:26:13 +02:00
|
|
|
export function readConfigFile(fileName: string, readFile: (path: string) => string | undefined): { config?: any; error?: Diagnostic } {
|
|
|
|
const textOrDiagnostic = tryReadFile(fileName, readFile);
|
2017-07-19 22:07:55 +02:00
|
|
|
return isString(textOrDiagnostic) ? parseConfigFileTextToJson(fileName, textOrDiagnostic) : { config: {}, error: textOrDiagnostic };
|
2015-04-23 03:09:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-03 18:32:39 +02:00
|
|
|
* Parse the text of the tsconfig.json file
|
|
|
|
* @param fileName The path to the config file
|
|
|
|
* @param jsonText The text of the config file
|
|
|
|
*/
|
2016-11-16 21:25:24 +01:00
|
|
|
export function parseConfigFileTextToJson(fileName: string, jsonText: string): { config?: any; error?: Diagnostic } {
|
2016-11-24 01:09:34 +01:00
|
|
|
const jsonSourceFile = parseJsonText(fileName, jsonText);
|
2016-11-11 22:41:43 +01:00
|
|
|
return {
|
2017-02-08 20:45:03 +01:00
|
|
|
config: convertToObject(jsonSourceFile, jsonSourceFile.parseDiagnostics),
|
2016-11-24 01:09:34 +01:00
|
|
|
error: jsonSourceFile.parseDiagnostics.length ? jsonSourceFile.parseDiagnostics[0] : undefined
|
2016-11-11 22:41:43 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-11-16 21:25:24 +01:00
|
|
|
/**
|
2017-04-17 22:40:49 +02:00
|
|
|
* Read tsconfig.json file
|
|
|
|
* @param fileName The path to the config file
|
|
|
|
*/
|
2018-01-30 19:53:54 +01:00
|
|
|
export function readJsonConfigFile(fileName: string, readFile: (path: string) => string | undefined): TsConfigSourceFile {
|
2017-07-14 23:26:13 +02:00
|
|
|
const textOrDiagnostic = tryReadFile(fileName, readFile);
|
2018-01-30 19:53:54 +01:00
|
|
|
return isString(textOrDiagnostic) ? parseJsonText(fileName, textOrDiagnostic) : <TsConfigSourceFile>{ parseDiagnostics: [textOrDiagnostic] };
|
2017-07-14 23:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function tryReadFile(fileName: string, readFile: (path: string) => string | undefined): string | Diagnostic {
|
|
|
|
let text: string | undefined;
|
2016-11-16 21:25:24 +01:00
|
|
|
try {
|
|
|
|
text = readFile(fileName);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2017-07-14 23:26:13 +02:00
|
|
|
return createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message);
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
2017-07-17 21:38:11 +02:00
|
|
|
return text === undefined ? createCompilerDiagnostic(Diagnostics.The_specified_path_does_not_exist_Colon_0, fileName) : text;
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
|
|
|
|
2017-07-21 16:16:22 +02:00
|
|
|
function commandLineOptionsToMap(options: ReadonlyArray<CommandLineOption>) {
|
2016-11-16 21:25:24 +01:00
|
|
|
return arrayToMap(options, option => option.name);
|
|
|
|
}
|
|
|
|
|
2018-01-30 19:53:54 +01:00
|
|
|
let _tsconfigRootOptions: TsConfigOnlyOption;
|
2016-11-16 21:25:24 +01:00
|
|
|
function getTsconfigRootOptionsMap() {
|
2017-02-08 20:45:03 +01:00
|
|
|
if (_tsconfigRootOptions === undefined) {
|
2018-01-30 19:53:54 +01:00
|
|
|
_tsconfigRootOptions = {
|
2018-05-22 23:46:57 +02:00
|
|
|
name: undefined!, // should never be needed since this is root
|
2018-01-30 19:53:54 +01:00
|
|
|
type: "object",
|
|
|
|
elementOptions: commandLineOptionsToMap([
|
|
|
|
{
|
|
|
|
name: "compilerOptions",
|
|
|
|
type: "object",
|
|
|
|
elementOptions: commandLineOptionsToMap(optionDeclarations),
|
|
|
|
extraKeyDiagnosticMessage: Diagnostics.Unknown_compiler_option_0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "typingOptions",
|
|
|
|
type: "object",
|
|
|
|
elementOptions: commandLineOptionsToMap(typeAcquisitionDeclarations),
|
|
|
|
extraKeyDiagnosticMessage: Diagnostics.Unknown_type_acquisition_option_0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "typeAcquisition",
|
|
|
|
type: "object",
|
|
|
|
elementOptions: commandLineOptionsToMap(typeAcquisitionDeclarations),
|
|
|
|
extraKeyDiagnosticMessage: Diagnostics.Unknown_type_acquisition_option_0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "extends",
|
2017-02-08 20:45:03 +01:00
|
|
|
type: "string"
|
2018-01-30 19:53:54 +01:00
|
|
|
},
|
2018-05-08 00:12:50 +02:00
|
|
|
{
|
|
|
|
name: "references",
|
|
|
|
type: "list",
|
|
|
|
element: {
|
|
|
|
name: "references",
|
|
|
|
type: "object"
|
|
|
|
}
|
|
|
|
},
|
2018-01-30 19:53:54 +01:00
|
|
|
{
|
|
|
|
name: "files",
|
|
|
|
type: "list",
|
|
|
|
element: {
|
|
|
|
name: "files",
|
|
|
|
type: "string"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2017-02-08 20:45:03 +01:00
|
|
|
name: "include",
|
2018-01-30 19:53:54 +01:00
|
|
|
type: "list",
|
|
|
|
element: {
|
|
|
|
name: "include",
|
|
|
|
type: "string"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2017-02-08 20:45:03 +01:00
|
|
|
name: "exclude",
|
2018-01-30 19:53:54 +01:00
|
|
|
type: "list",
|
|
|
|
element: {
|
|
|
|
name: "exclude",
|
|
|
|
type: "string"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
compileOnSaveCommandLineOption
|
|
|
|
])
|
|
|
|
};
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
2017-02-08 20:45:03 +01:00
|
|
|
return _tsconfigRootOptions;
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
interface JsonConversionNotifier {
|
2017-05-11 18:06:01 +02:00
|
|
|
/**
|
|
|
|
* Notifies parent option object is being set with the optionKey and a valid optionValue
|
|
|
|
* Currently it notifies only if there is element with type object (parentOption) and
|
|
|
|
* has element's option declarations map associated with it
|
|
|
|
* @param parentOption parent option name in which the option and value are being set
|
|
|
|
* @param option option declaration which is being set with the value
|
|
|
|
* @param value value of the option
|
|
|
|
*/
|
|
|
|
onSetValidOptionKeyValueInParent(parentOption: string, option: CommandLineOption, value: CompilerOptionsValue): void;
|
|
|
|
/**
|
|
|
|
* Notify when valid root key value option is being set
|
|
|
|
* @param key option key
|
|
|
|
* @param keyNode node corresponding to node in the source file
|
|
|
|
* @param value computed value of the key
|
|
|
|
* @param ValueNode node corresponding to value in the source file
|
|
|
|
*/
|
|
|
|
onSetValidOptionKeyValueInRoot(key: string, keyNode: PropertyName, value: CompilerOptionsValue, valueNode: Expression): void;
|
|
|
|
/**
|
|
|
|
* Notify when unknown root key value option is being set
|
|
|
|
* @param key option key
|
|
|
|
* @param keyNode node corresponding to node in the source file
|
|
|
|
* @param value computed value of the key
|
|
|
|
* @param ValueNode node corresponding to value in the source file
|
|
|
|
*/
|
|
|
|
onSetUnknownOptionKeyValueInRoot(key: string, keyNode: PropertyName, value: CompilerOptionsValue, valueNode: Expression): void;
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
|
|
|
|
2016-11-11 22:41:43 +01:00
|
|
|
/**
|
|
|
|
* Convert the json syntax tree into the json value
|
|
|
|
*/
|
2017-07-21 16:16:22 +02:00
|
|
|
export function convertToObject(sourceFile: JsonSourceFile, errors: Push<Diagnostic>): any {
|
2018-02-24 03:06:27 +01:00
|
|
|
return convertToObjectWorker(sourceFile, errors, /*returnValue*/ true, /*knownRootOptions*/ undefined, /*jsonConversionNotifier*/ undefined);
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-24 03:06:27 +01:00
|
|
|
* Convert the json syntax tree into the json value and report errors
|
2018-05-04 19:45:46 +02:00
|
|
|
* This returns the json value (apart from checking errors) only if returnValue provided is true.
|
|
|
|
* Otherwise it just checks the errors and returns undefined
|
2016-11-16 21:25:24 +01:00
|
|
|
*/
|
2018-02-24 03:06:27 +01:00
|
|
|
/*@internal*/
|
|
|
|
export function convertToObjectWorker(
|
2017-05-11 18:06:01 +02:00
|
|
|
sourceFile: JsonSourceFile,
|
2017-07-21 16:16:22 +02:00
|
|
|
errors: Push<Diagnostic>,
|
2018-02-24 03:06:27 +01:00
|
|
|
returnValue: boolean,
|
2018-01-30 19:53:54 +01:00
|
|
|
knownRootOptions: CommandLineOption | undefined,
|
2017-05-11 18:06:01 +02:00
|
|
|
jsonConversionNotifier: JsonConversionNotifier | undefined): any {
|
2018-01-26 23:06:22 +01:00
|
|
|
if (!sourceFile.statements.length) {
|
2018-02-24 03:06:27 +01:00
|
|
|
return returnValue ? {} : undefined;
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
2016-11-11 22:41:43 +01:00
|
|
|
|
2018-01-30 19:53:54 +01:00
|
|
|
return convertPropertyValueToJson(sourceFile.statements[0].expression, knownRootOptions);
|
|
|
|
|
|
|
|
function isRootOptionMap(knownOptions: Map<CommandLineOption> | undefined) {
|
|
|
|
return knownRootOptions && (knownRootOptions as TsConfigOnlyOption).elementOptions === knownOptions;
|
|
|
|
}
|
2016-11-11 22:41:43 +01:00
|
|
|
|
2017-05-11 18:06:01 +02:00
|
|
|
function convertObjectLiteralExpressionToJson(
|
|
|
|
node: ObjectLiteralExpression,
|
|
|
|
knownOptions: Map<CommandLineOption> | undefined,
|
|
|
|
extraKeyDiagnosticMessage: DiagnosticMessage | undefined,
|
|
|
|
parentOption: string | undefined
|
|
|
|
): any {
|
2018-02-24 03:06:27 +01:00
|
|
|
const result: any = returnValue ? {} : undefined;
|
2016-11-11 22:41:43 +01:00
|
|
|
for (const element of node.properties) {
|
2016-11-16 21:25:24 +01:00
|
|
|
if (element.kind !== SyntaxKind.PropertyAssignment) {
|
|
|
|
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, element, Diagnostics.Property_assignment_expected));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (element.questionToken) {
|
|
|
|
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, element.questionToken, Diagnostics._0_can_only_be_used_in_a_ts_file, "?"));
|
|
|
|
}
|
|
|
|
if (!isDoubleQuotedString(element.name)) {
|
|
|
|
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, element.name, Diagnostics.String_literal_with_double_quotes_expected));
|
|
|
|
}
|
|
|
|
|
2018-08-01 01:39:50 +02:00
|
|
|
const textOfKey = getTextOfPropertyName(element.name);
|
|
|
|
const keyText = textOfKey && unescapeLeadingUnderscores(textOfKey);
|
|
|
|
const option = keyText && knownOptions ? knownOptions.get(keyText) : undefined;
|
|
|
|
if (keyText && extraKeyDiagnosticMessage && !option) {
|
2016-11-16 21:25:24 +01:00
|
|
|
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, element.name, extraKeyDiagnosticMessage, keyText));
|
|
|
|
}
|
2017-02-08 20:45:03 +01:00
|
|
|
const value = convertPropertyValueToJson(element.initializer, option);
|
2017-09-07 07:08:42 +02:00
|
|
|
if (typeof keyText !== "undefined") {
|
2018-02-24 03:06:27 +01:00
|
|
|
if (returnValue) {
|
|
|
|
result[keyText] = value;
|
|
|
|
}
|
2016-11-16 21:25:24 +01:00
|
|
|
// Notify key value set, if user asked for it
|
2017-05-11 18:06:01 +02:00
|
|
|
if (jsonConversionNotifier &&
|
|
|
|
// Current callbacks are only on known parent option or if we are setting values in the root
|
2018-01-30 19:53:54 +01:00
|
|
|
(parentOption || isRootOptionMap(knownOptions))) {
|
2016-11-16 21:25:24 +01:00
|
|
|
const isValidOptionValue = isCompilerOptionsValue(option, value);
|
2017-05-11 18:06:01 +02:00
|
|
|
if (parentOption) {
|
|
|
|
if (isValidOptionValue) {
|
|
|
|
// Notify option set in the parent if its a valid option value
|
2018-05-22 23:46:57 +02:00
|
|
|
jsonConversionNotifier.onSetValidOptionKeyValueInParent(parentOption, option!, value);
|
2017-05-11 18:06:01 +02:00
|
|
|
}
|
2016-11-11 22:41:43 +01:00
|
|
|
}
|
2018-01-30 19:53:54 +01:00
|
|
|
else if (isRootOptionMap(knownOptions)) {
|
2017-05-11 18:06:01 +02:00
|
|
|
if (isValidOptionValue) {
|
|
|
|
// Notify about the valid root key value being set
|
|
|
|
jsonConversionNotifier.onSetValidOptionKeyValueInRoot(keyText, element.name, value, element.initializer);
|
|
|
|
}
|
|
|
|
else if (!option) {
|
|
|
|
// Notify about the unknown root key value being set
|
|
|
|
jsonConversionNotifier.onSetUnknownOptionKeyValueInRoot(keyText, element.name, value, element.initializer);
|
|
|
|
}
|
2016-11-11 22:41:43 +01:00
|
|
|
}
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
2016-11-11 22:41:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-05-11 18:06:01 +02:00
|
|
|
function convertArrayLiteralExpressionToJson(
|
|
|
|
elements: NodeArray<Expression>,
|
|
|
|
elementOption: CommandLineOption | undefined
|
2018-02-24 03:06:27 +01:00
|
|
|
): any[] | void {
|
2018-09-28 22:49:00 +02:00
|
|
|
if (!returnValue) {
|
|
|
|
return elements.forEach(element => convertPropertyValueToJson(element, elementOption));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter out invalid values
|
|
|
|
return filter(elements.map(element => convertPropertyValueToJson(element, elementOption)), v => v !== undefined);
|
2016-11-11 22:41:43 +01:00
|
|
|
}
|
|
|
|
|
2018-05-22 23:46:57 +02:00
|
|
|
function convertPropertyValueToJson(valueExpression: Expression, option: CommandLineOption | undefined): any {
|
2017-05-11 18:06:01 +02:00
|
|
|
switch (valueExpression.kind) {
|
2016-11-11 22:41:43 +01:00
|
|
|
case SyntaxKind.TrueKeyword:
|
2016-11-16 21:25:24 +01:00
|
|
|
reportInvalidOptionValue(option && option.type !== "boolean");
|
2016-11-11 22:41:43 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case SyntaxKind.FalseKeyword:
|
2016-11-16 21:25:24 +01:00
|
|
|
reportInvalidOptionValue(option && option.type !== "boolean");
|
2016-11-11 22:41:43 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case SyntaxKind.NullKeyword:
|
2017-09-07 07:08:42 +02:00
|
|
|
reportInvalidOptionValue(option && option.name === "extends"); // "extends" is the only option we don't allow null/undefined for
|
2016-11-11 22:41:43 +01:00
|
|
|
return null; // tslint:disable-line:no-null-keyword
|
|
|
|
|
|
|
|
case SyntaxKind.StringLiteral:
|
2017-05-11 18:06:01 +02:00
|
|
|
if (!isDoubleQuotedString(valueExpression)) {
|
|
|
|
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, valueExpression, Diagnostics.String_literal_with_double_quotes_expected));
|
2016-11-11 22:41:43 +01:00
|
|
|
}
|
2017-07-19 22:07:55 +02:00
|
|
|
reportInvalidOptionValue(option && (isString(option.type) && option.type !== "string"));
|
2017-05-11 18:06:01 +02:00
|
|
|
const text = (<StringLiteral>valueExpression).text;
|
2017-07-19 22:07:55 +02:00
|
|
|
if (option && !isString(option.type)) {
|
2016-11-16 21:25:24 +01:00
|
|
|
const customOption = <CommandLineOptionOfCustomType>option;
|
|
|
|
// Validate custom option type
|
2017-08-12 04:59:43 +02:00
|
|
|
if (!customOption.type.has(text.toLowerCase())) {
|
2016-11-16 21:25:24 +01:00
|
|
|
errors.push(
|
|
|
|
createDiagnosticForInvalidCustomType(
|
|
|
|
customOption,
|
2017-05-11 18:06:01 +02:00
|
|
|
(message, arg0, arg1) => createDiagnosticForNodeInSourceFile(sourceFile, valueExpression, message, arg0, arg1)
|
2016-11-16 21:25:24 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return text;
|
2016-11-11 22:41:43 +01:00
|
|
|
|
|
|
|
case SyntaxKind.NumericLiteral:
|
2016-11-16 21:25:24 +01:00
|
|
|
reportInvalidOptionValue(option && option.type !== "number");
|
2017-05-11 18:06:01 +02:00
|
|
|
return Number((<NumericLiteral>valueExpression).text);
|
2016-11-11 22:41:43 +01:00
|
|
|
|
2017-10-28 20:06:33 +02:00
|
|
|
case SyntaxKind.PrefixUnaryExpression:
|
|
|
|
if ((<PrefixUnaryExpression>valueExpression).operator !== SyntaxKind.MinusToken || (<PrefixUnaryExpression>valueExpression).operand.kind !== SyntaxKind.NumericLiteral) {
|
|
|
|
break; // not valid JSON syntax
|
|
|
|
}
|
|
|
|
reportInvalidOptionValue(option && option.type !== "number");
|
|
|
|
return -Number((<NumericLiteral>(<PrefixUnaryExpression>valueExpression).operand).text);
|
|
|
|
|
2016-11-11 22:41:43 +01:00
|
|
|
case SyntaxKind.ObjectLiteralExpression:
|
2016-11-16 21:25:24 +01:00
|
|
|
reportInvalidOptionValue(option && option.type !== "object");
|
2017-05-11 18:06:01 +02:00
|
|
|
const objectLiteralExpression = <ObjectLiteralExpression>valueExpression;
|
|
|
|
|
|
|
|
// Currently having element option declaration in the tsconfig with type "object"
|
|
|
|
// determines if it needs onSetValidOptionKeyValueInParent callback or not
|
|
|
|
// At moment there are only "compilerOptions", "typeAcquisition" and "typingOptions"
|
|
|
|
// that satifies it and need it to modify options set in them (for normalizing file paths)
|
|
|
|
// vs what we set in the json
|
|
|
|
// If need arises, we can modify this interface and callbacks as needed
|
|
|
|
if (option) {
|
|
|
|
const { elementOptions, extraKeyDiagnosticMessage, name: optionName } = <TsConfigOnlyOption>option;
|
|
|
|
return convertObjectLiteralExpressionToJson(objectLiteralExpression,
|
|
|
|
elementOptions, extraKeyDiagnosticMessage, optionName);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return convertObjectLiteralExpressionToJson(
|
|
|
|
objectLiteralExpression, /* knownOptions*/ undefined,
|
|
|
|
/*extraKeyDiagnosticMessage */ undefined, /*parentOption*/ undefined);
|
|
|
|
}
|
2016-11-11 22:41:43 +01:00
|
|
|
|
|
|
|
case SyntaxKind.ArrayLiteralExpression:
|
2016-11-16 21:25:24 +01:00
|
|
|
reportInvalidOptionValue(option && option.type !== "list");
|
2017-05-11 18:06:01 +02:00
|
|
|
return convertArrayLiteralExpressionToJson(
|
|
|
|
(<ArrayLiteralExpression>valueExpression).elements,
|
|
|
|
option && (<CommandLineOptionOfListType>option).element);
|
2016-11-11 22:41:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Not in expected format
|
2016-11-16 21:25:24 +01:00
|
|
|
if (option) {
|
2017-02-08 20:45:03 +01:00
|
|
|
reportInvalidOptionValue(/*isError*/ true);
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-05-11 18:06:01 +02:00
|
|
|
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, valueExpression, Diagnostics.Property_value_can_only_be_string_literal_numeric_literal_true_false_null_object_literal_or_array_literal));
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
|
|
|
|
2016-11-11 22:41:43 +01:00
|
|
|
return undefined;
|
2016-11-16 21:25:24 +01:00
|
|
|
|
2018-05-22 23:46:57 +02:00
|
|
|
function reportInvalidOptionValue(isError: boolean | undefined) {
|
2016-11-16 21:25:24 +01:00
|
|
|
if (isError) {
|
2018-05-22 23:46:57 +02:00
|
|
|
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, valueExpression, Diagnostics.Compiler_option_0_requires_a_value_of_type_1, option!.name, getCompilerOptionValueTypeString(option!)));
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-11 22:41:43 +01:00
|
|
|
}
|
|
|
|
|
Add exported members of all project files in the global completion list (#19069)
* checker.ts: Remove null check on symbols
* tsserverProjectSystem.ts: add two tests
* client.ts, completions.ts, types.ts: Add codeActions member to CompletionEntryDetails
* protocol.ts, session.ts: Add codeActions member to CompletionEntryDetails protocol
* protocol.ts, session.ts, types.ts: add hasAction to CompletionEntry
* session.ts, services.ts, types.ts: Add formattingOptions parameter to getCompletionEntryDetails
* completions.ts: define SymbolOriginInfo type
* completions.ts, services.ts: Add allSourceFiles parameter to getCompletionsAtPosition
* completions.ts, services.ts: Plumb allSourceFiles into new function getSymbolsFromOtherSourceFileExports inside getCompletionData
* completions.ts: add symbolToOriginInfoMap parameter to getCompletionEntriesFromSymbols and to return value of getCompletionData
* utilities.ts: Add getOtherModuleSymbols, getUniqueSymbolIdAsString, getUniqueSymbolId
* completions.ts: Set CompletionEntry.hasAction when symbol is found in symbolToOriginInfoMap (meaning there's an import action)
* completions.ts: Populate list with possible exports (implement getSymbolsFromOtherSourceFileExports)
* completions.ts, services.ts: Plumb host and rulesProvider into getCompletionEntryDetails
* completions.ts: Add TODO comment
* importFixes.ts: Add types ImportDeclarationMap and ImportCodeFixContext
* Move getImportDeclarations into getCodeActionForImport, immediately after the implementation
* importFixes.ts: Move createChangeTracker into getCodeActionForImport, immediately after getImportDeclarations
* importFixes.ts: Add convertToImportCodeFixContext function and reference it from the getCodeActions lambda
* importFixes.ts: Add context: ImportCodeFixContext parameter to getCodeActionForImport, update call sites, destructure it, use compilerOptions in getModuleSpecifierForNewImport
* importFixes.ts: Remove moduleSymbol parameter from getImportDeclarations and use the ambient one
* importFixes.ts: Use cachedImportDeclarations from context in getCodeActionForImport
* importFixes.ts: Move createCodeAction out, immediately above convertToImportCodeFixContext
* Move the declaration for lastImportDeclaration out of the getCodeActions lambda into getCodeActionForImport
* importFixes.ts: Use symbolToken in getCodeActionForImport
* importFixes.ts: Remove useCaseSensitiveFileNames altogether from getCodeActions lambda
* importFixes.ts: Remove local getUniqueSymbolId function and add checker parameter to calls to it
* importFixes.ts: Move getCodeActionForImport out into an export, immediately below convertToImportCodeFixContext
* completions.ts: In getCompletionEntryDetails, if there's symbolOriginInfo, call getCodeActionForImport
* importFixes.ts: Create and use importFixContext within getCodeActions lambda
* importFixes.ts: Use local newLineCharacter instead of context.newLineCharacter in getCodeActionForImport
* importFixes.ts: Use local host instead of context.host in getCodeActionForImport
* importFixes.ts: Remove dummy getCanonicalFileName line
* Filter symbols after gathering exports instead of before
* Lint
* Test, fix bugs, refactor
* Suggestions from code review
* Update api baseline
* Fix bug if previousToken is not an Identifier
* Replace `startsWith` with `stringContainsCharactersInOrder`
2017-10-17 19:20:11 +02:00
|
|
|
function isDoubleQuotedString(node: Node): boolean {
|
|
|
|
return isStringLiteral(node) && isStringDoubleQuoted(node, sourceFile);
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 21:25:24 +01:00
|
|
|
function getCompilerOptionValueTypeString(option: CommandLineOption) {
|
|
|
|
return option.type === "list" ?
|
|
|
|
"Array" :
|
2017-07-19 22:07:55 +02:00
|
|
|
isString(option.type) ? option.type : "string";
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
|
|
|
|
2018-05-22 23:46:57 +02:00
|
|
|
function isCompilerOptionsValue(option: CommandLineOption | undefined, value: any): value is CompilerOptionsValue {
|
2016-11-16 21:25:24 +01:00
|
|
|
if (option) {
|
2017-09-07 07:08:42 +02:00
|
|
|
if (isNullOrUndefined(value)) return true; // All options are undefinable/nullable
|
2016-11-16 21:25:24 +01:00
|
|
|
if (option.type === "list") {
|
|
|
|
return isArray(value);
|
|
|
|
}
|
2017-07-19 22:07:55 +02:00
|
|
|
const expectedType = isString(option.type) ? option.type : "string";
|
2016-11-16 21:25:24 +01:00
|
|
|
return typeof value === expectedType;
|
|
|
|
}
|
2018-05-22 23:46:57 +02:00
|
|
|
return false;
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
|
|
|
|
2016-08-18 00:23:28 +02:00
|
|
|
/**
|
2018-10-31 23:57:09 +01:00
|
|
|
* Generate an uncommented, complete tsconfig for use with "--showConfig"
|
|
|
|
* @param configParseResult options to be generated into tsconfig.json
|
|
|
|
* @param configFileName name of the parsed config file - output paths will be generated relative to this
|
|
|
|
* @param host provides current directory and case sensitivity services
|
2016-08-18 00:23:28 +02:00
|
|
|
*/
|
2018-10-31 23:57:09 +01:00
|
|
|
/** @internal */
|
|
|
|
export function convertToTSConfig(configParseResult: ParsedCommandLine, configFileName: string, host: { getCurrentDirectory(): string, useCaseSensitiveFileNames: boolean }): object {
|
|
|
|
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);
|
|
|
|
const files = map(
|
|
|
|
filter(
|
|
|
|
configParseResult.fileNames,
|
2018-11-28 23:01:02 +01:00
|
|
|
(!configParseResult.configFileSpecs || !configParseResult.configFileSpecs.validatedIncludeSpecs) ? _ => true : matchesSpecs(
|
2018-10-31 23:57:09 +01:00
|
|
|
configFileName,
|
|
|
|
configParseResult.configFileSpecs.validatedIncludeSpecs,
|
|
|
|
configParseResult.configFileSpecs.validatedExcludeSpecs
|
|
|
|
)
|
|
|
|
),
|
2018-11-28 23:01:02 +01:00
|
|
|
f => getRelativePathFromFile(getNormalizedAbsolutePath(configFileName, host.getCurrentDirectory()), getNormalizedAbsolutePath(f, host.getCurrentDirectory()), getCanonicalFileName)
|
2018-10-31 23:57:09 +01:00
|
|
|
);
|
|
|
|
const optionMap = serializeCompilerOptions(configParseResult.options, { configFilePath: getNormalizedAbsolutePath(configFileName, host.getCurrentDirectory()), useCaseSensitiveFileNames: host.useCaseSensitiveFileNames });
|
|
|
|
const config = {
|
|
|
|
compilerOptions: {
|
|
|
|
...arrayFrom(optionMap.entries()).reduce((prev, cur) => ({ ...prev, [cur[0]]: cur[1] }), {}),
|
|
|
|
showConfig: undefined,
|
|
|
|
configFile: undefined,
|
|
|
|
configFilePath: undefined,
|
|
|
|
help: undefined,
|
|
|
|
init: undefined,
|
|
|
|
listFiles: undefined,
|
|
|
|
listEmittedFiles: undefined,
|
|
|
|
project: undefined,
|
2018-12-05 01:24:25 +01:00
|
|
|
build: undefined,
|
|
|
|
version: undefined,
|
2018-10-31 23:57:09 +01:00
|
|
|
},
|
|
|
|
references: map(configParseResult.projectReferences, r => ({ ...r, path: r.originalPath, originalPath: undefined })),
|
|
|
|
files: length(files) ? files : undefined,
|
|
|
|
...(configParseResult.configFileSpecs ? {
|
|
|
|
include: filterSameAsDefaultInclude(configParseResult.configFileSpecs.validatedIncludeSpecs),
|
|
|
|
exclude: configParseResult.configFileSpecs.validatedExcludeSpecs
|
|
|
|
} : {}),
|
|
|
|
compilerOnSave: !!configParseResult.compileOnSave ? true : undefined
|
|
|
|
};
|
|
|
|
return config;
|
|
|
|
}
|
2016-08-18 00:23:28 +02:00
|
|
|
|
2018-10-31 23:57:09 +01:00
|
|
|
function filterSameAsDefaultInclude(specs: ReadonlyArray<string> | undefined) {
|
|
|
|
if (!length(specs)) return undefined;
|
|
|
|
if (length(specs) !== 1) return specs;
|
|
|
|
if (specs![0] === "**/*") return undefined;
|
|
|
|
return specs;
|
|
|
|
}
|
|
|
|
|
|
|
|
function matchesSpecs(path: string, includeSpecs: ReadonlyArray<string> | undefined, excludeSpecs: ReadonlyArray<string> | undefined): (path: string) => boolean {
|
2018-11-28 23:01:02 +01:00
|
|
|
if (!includeSpecs) return _ => true;
|
2018-10-31 23:57:09 +01:00
|
|
|
const patterns = getFileMatcherPatterns(path, excludeSpecs, includeSpecs, sys.useCaseSensitiveFileNames, sys.getCurrentDirectory());
|
|
|
|
const excludeRe = patterns.excludePattern && getRegexFromPattern(patterns.excludePattern, sys.useCaseSensitiveFileNames);
|
|
|
|
const includeRe = patterns.includeFilePattern && getRegexFromPattern(patterns.includeFilePattern, sys.useCaseSensitiveFileNames);
|
|
|
|
if (includeRe) {
|
|
|
|
if (excludeRe) {
|
2018-11-28 23:01:02 +01:00
|
|
|
return path => !(includeRe.test(path) && !excludeRe.test(path));
|
2016-08-18 00:23:28 +02:00
|
|
|
}
|
2018-11-28 23:01:02 +01:00
|
|
|
return path => !includeRe.test(path);
|
2016-08-18 00:23:28 +02:00
|
|
|
}
|
2018-10-31 23:57:09 +01:00
|
|
|
if (excludeRe) {
|
2018-11-28 23:01:02 +01:00
|
|
|
return path => excludeRe.test(path);
|
2018-10-31 23:57:09 +01:00
|
|
|
}
|
2018-11-28 23:01:02 +01:00
|
|
|
return _ => true;
|
2018-10-31 23:57:09 +01:00
|
|
|
}
|
2016-08-18 00:23:28 +02:00
|
|
|
|
2018-10-31 23:57:09 +01:00
|
|
|
function getCustomTypeMapOfCommandLineOption(optionDefinition: CommandLineOption): Map<string | number> | undefined {
|
2018-12-05 01:24:25 +01:00
|
|
|
if (optionDefinition.type === "string" || optionDefinition.type === "number" || optionDefinition.type === "boolean" || optionDefinition.type === "object") {
|
2018-10-31 23:57:09 +01:00
|
|
|
// this is of a type CommandLineOptionOfPrimitiveType
|
|
|
|
return undefined;
|
2016-08-18 00:23:28 +02:00
|
|
|
}
|
2018-10-31 23:57:09 +01:00
|
|
|
else if (optionDefinition.type === "list") {
|
|
|
|
return getCustomTypeMapOfCommandLineOption(optionDefinition.element);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (<CommandLineOptionOfCustomType>optionDefinition).type;
|
|
|
|
}
|
|
|
|
}
|
2016-08-18 00:23:28 +02:00
|
|
|
|
2018-10-31 23:57:09 +01:00
|
|
|
function getNameOfCompilerOptionValue(value: CompilerOptionsValue, customTypeMap: Map<string | number>): string | undefined {
|
|
|
|
// There is a typeMap associated with this command-line option so use it to map value back to its name
|
|
|
|
return forEachEntry(customTypeMap, (mapValue, key) => {
|
|
|
|
if (mapValue === value) {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-08-18 00:23:28 +02:00
|
|
|
|
2018-10-31 23:57:09 +01:00
|
|
|
function serializeCompilerOptions(options: CompilerOptions, pathOptions?: { configFilePath: string, useCaseSensitiveFileNames: boolean }): Map<CompilerOptionsValue> {
|
|
|
|
const result = createMap<CompilerOptionsValue>();
|
|
|
|
const optionsNameMap = getOptionNameMap().optionNameMap;
|
|
|
|
const getCanonicalFileName = pathOptions && createGetCanonicalFileName(pathOptions.useCaseSensitiveFileNames);
|
|
|
|
|
|
|
|
for (const name in options) {
|
|
|
|
if (hasProperty(options, name)) {
|
|
|
|
// tsconfig only options cannot be specified via command line,
|
|
|
|
// so we can assume that only types that can appear here string | number | boolean
|
|
|
|
if (optionsNameMap.has(name) && optionsNameMap.get(name)!.category === Diagnostics.Command_line_Options) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const value = <CompilerOptionsValue>options[name];
|
|
|
|
const optionDefinition = optionsNameMap.get(name.toLowerCase());
|
|
|
|
if (optionDefinition) {
|
|
|
|
const customTypeMap = getCustomTypeMapOfCommandLineOption(optionDefinition);
|
|
|
|
if (!customTypeMap) {
|
|
|
|
// There is no map associated with this compiler option then use the value as-is
|
|
|
|
// This is the case if the value is expect to be string, number, boolean or list of string
|
|
|
|
if (pathOptions && optionDefinition.isFilePath) {
|
|
|
|
result.set(name, getRelativePathFromFile(pathOptions.configFilePath, getNormalizedAbsolutePath(value as string, getDirectoryPath(pathOptions.configFilePath)), getCanonicalFileName!));
|
|
|
|
}
|
|
|
|
else {
|
2017-07-25 23:19:17 +02:00
|
|
|
result.set(name, value);
|
2017-02-08 21:35:31 +01:00
|
|
|
}
|
2018-10-31 23:57:09 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (optionDefinition.type === "list") {
|
|
|
|
result.set(name, (value as ReadonlyArray<string | number>).map(element => getNameOfCompilerOptionValue(element, customTypeMap)!)); // TODO: GH#18217
|
|
|
|
}
|
2017-02-08 21:35:31 +01:00
|
|
|
else {
|
2018-10-31 23:57:09 +01:00
|
|
|
// There is a typeMap associated with this command-line option so use it to map value back to its name
|
|
|
|
result.set(name, getNameOfCompilerOptionValue(value, customTypeMap));
|
2017-02-08 21:35:31 +01:00
|
|
|
}
|
2016-08-18 00:23:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-31 23:57:09 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate tsconfig configuration when running command line "--init"
|
|
|
|
* @param options commandlineOptions to be generated into tsconfig.json
|
|
|
|
* @param fileNames array of filenames to be generated into tsconfig.json
|
|
|
|
*/
|
|
|
|
/* @internal */
|
|
|
|
export function generateTSConfig(options: CompilerOptions, fileNames: ReadonlyArray<string>, newLine: string): string {
|
|
|
|
const compilerOptions = extend(options, defaultInitCompilerOptions);
|
|
|
|
const compilerOptionsMap = serializeCompilerOptions(compilerOptions);
|
|
|
|
return writeConfigurations();
|
2017-02-09 04:07:15 +01:00
|
|
|
|
|
|
|
function getDefaultValueForOption(option: CommandLineOption) {
|
|
|
|
switch (option.type) {
|
|
|
|
case "number":
|
|
|
|
return 1;
|
|
|
|
case "boolean":
|
|
|
|
return true;
|
|
|
|
case "string":
|
|
|
|
return option.isFilePath ? "./" : "";
|
|
|
|
case "list":
|
|
|
|
return [];
|
|
|
|
case "object":
|
|
|
|
return {};
|
|
|
|
default:
|
2018-10-18 00:17:21 +02:00
|
|
|
return option.type.keys().next().value;
|
2017-02-09 04:07:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:08:32 +01:00
|
|
|
function makePadding(paddingLength: number): string {
|
|
|
|
return Array(paddingLength + 1).join(" ");
|
|
|
|
}
|
|
|
|
|
2018-03-29 11:18:33 +02:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2017-02-09 04:07:15 +01:00
|
|
|
function writeConfigurations() {
|
2017-03-16 00:08:32 +01:00
|
|
|
// Filter applicable options to place in the file
|
2017-07-25 23:19:17 +02:00
|
|
|
const categorizedOptions = createMultiMap<CommandLineOption>();
|
|
|
|
for (const option of optionDeclarations) {
|
|
|
|
const { category } = option;
|
2018-03-29 11:18:33 +02:00
|
|
|
|
|
|
|
if (isAllowedOption(option)) {
|
2018-05-22 23:46:57 +02:00
|
|
|
categorizedOptions.add(getLocaleSpecificMessage(category!), option);
|
2017-07-25 23:19:17 +02:00
|
|
|
}
|
|
|
|
}
|
2017-02-09 04:07:15 +01:00
|
|
|
|
2017-07-25 23:19:17 +02:00
|
|
|
// Serialize all options and their descriptions
|
2017-03-16 00:08:32 +01:00
|
|
|
let marginLength = 0;
|
2017-02-09 04:07:15 +01:00
|
|
|
let seenKnownKeys = 0;
|
2017-03-16 00:08:32 +01:00
|
|
|
const nameColumn: string[] = [];
|
|
|
|
const descriptionColumn: string[] = [];
|
2017-07-25 23:19:17 +02:00
|
|
|
categorizedOptions.forEach((options, category) => {
|
2017-03-16 00:08:32 +01:00
|
|
|
if (nameColumn.length !== 0) {
|
|
|
|
nameColumn.push("");
|
|
|
|
descriptionColumn.push("");
|
|
|
|
}
|
|
|
|
nameColumn.push(`/* ${category} */`);
|
|
|
|
descriptionColumn.push("");
|
2017-07-25 23:19:17 +02:00
|
|
|
for (const option of options) {
|
2017-03-16 00:08:32 +01:00
|
|
|
let optionName;
|
2017-07-25 23:19:17 +02:00
|
|
|
if (compilerOptionsMap.has(option.name)) {
|
|
|
|
optionName = `"${option.name}": ${JSON.stringify(compilerOptionsMap.get(option.name))}${(seenKnownKeys += 1) === compilerOptionsMap.size ? "" : ","}`;
|
2017-02-09 04:07:15 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-03-16 00:08:32 +01:00
|
|
|
optionName = `// "${option.name}": ${JSON.stringify(getDefaultValueForOption(option))},`;
|
2017-02-09 04:07:15 +01:00
|
|
|
}
|
2017-03-16 00:08:32 +01:00
|
|
|
nameColumn.push(optionName);
|
|
|
|
descriptionColumn.push(`/* ${option.description && getLocaleSpecificMessage(option.description) || option.name} */`);
|
|
|
|
marginLength = Math.max(optionName.length, marginLength);
|
2017-02-09 04:07:15 +01:00
|
|
|
}
|
2017-07-25 23:19:17 +02:00
|
|
|
});
|
2017-03-16 00:08:32 +01:00
|
|
|
|
|
|
|
// Write the output
|
|
|
|
const tab = makePadding(2);
|
|
|
|
const result: string[] = [];
|
|
|
|
result.push(`{`);
|
|
|
|
result.push(`${tab}"compilerOptions": {`);
|
|
|
|
// Print out each row, aligning all the descriptions on the same column.
|
|
|
|
for (let i = 0; i < nameColumn.length; i++) {
|
|
|
|
const optionName = nameColumn[i];
|
|
|
|
const description = descriptionColumn[i];
|
2018-05-08 00:12:50 +02:00
|
|
|
result.push(optionName && `${tab}${tab}${optionName}${description && (makePadding(marginLength - optionName.length + 2) + description)}`);
|
2017-02-09 04:07:15 +01:00
|
|
|
}
|
2017-07-25 22:30:48 +02:00
|
|
|
if (fileNames.length) {
|
2017-03-16 00:08:32 +01:00
|
|
|
result.push(`${tab}},`);
|
|
|
|
result.push(`${tab}"files": [`);
|
2017-07-25 22:30:48 +02:00
|
|
|
for (let i = 0; i < fileNames.length; i++) {
|
|
|
|
result.push(`${tab}${tab}${JSON.stringify(fileNames[i])}${i === fileNames.length - 1 ? "" : ","}`);
|
2017-02-09 04:07:15 +01:00
|
|
|
}
|
2017-03-16 00:08:32 +01:00
|
|
|
result.push(`${tab}]`);
|
2017-02-09 04:07:15 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-03-16 00:08:32 +01:00
|
|
|
result.push(`${tab}}`);
|
2017-02-09 04:07:15 +01:00
|
|
|
}
|
2017-03-16 00:08:32 +01:00
|
|
|
result.push(`}`);
|
2017-02-09 04:07:15 +01:00
|
|
|
|
2018-11-30 14:26:21 +01:00
|
|
|
return result.join(newLine) + newLine;
|
2017-02-09 04:07:15 +01:00
|
|
|
}
|
2016-08-18 00:23:28 +02:00
|
|
|
}
|
|
|
|
|
2015-03-31 19:52:21 +02:00
|
|
|
/**
|
2017-04-17 22:40:49 +02:00
|
|
|
* Parse the contents of a config file (tsconfig.json).
|
|
|
|
* @param json The contents of the config file to parse
|
|
|
|
* @param host Instance of ParseConfigHost used to enumerate files in folder.
|
|
|
|
* @param basePath A root directory to resolve relative path entries in the config
|
|
|
|
* file to. e.g. outDir
|
2015-10-29 12:56:13 +01:00
|
|
|
*/
|
2018-04-06 02:30:04 +02:00
|
|
|
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: ReadonlyArray<FileExtensionInfo>): ParsedCommandLine {
|
2016-12-15 20:45:40 +01:00
|
|
|
return parseJsonConfigFileContentWorker(json, /*sourceFile*/ undefined, host, basePath, existingOptions, configFileName, resolutionStack, extraFileExtensions);
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-17 22:40:49 +02:00
|
|
|
* Parse the contents of a config file (tsconfig.json).
|
|
|
|
* @param jsonNode The contents of the config file to parse
|
|
|
|
* @param host Instance of ParseConfigHost used to enumerate files in folder.
|
|
|
|
* @param basePath A root directory to resolve relative path entries in the config
|
|
|
|
* file to. e.g. outDir
|
|
|
|
*/
|
2018-05-04 00:35:54 +02:00
|
|
|
export function parseJsonSourceFileConfigFileContent(sourceFile: TsConfigSourceFile, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: ReadonlyArray<FileExtensionInfo>): ParsedCommandLine {
|
2016-12-15 20:45:40 +01:00
|
|
|
return parseJsonConfigFileContentWorker(/*json*/ undefined, sourceFile, host, basePath, existingOptions, configFileName, resolutionStack, extraFileExtensions);
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
|
|
|
|
2017-05-27 02:06:15 +02:00
|
|
|
/*@internal*/
|
2018-05-22 23:46:57 +02:00
|
|
|
export function setConfigFileInOptions(options: CompilerOptions, configFile: TsConfigSourceFile | undefined) {
|
2017-05-27 02:06:15 +02:00
|
|
|
if (configFile) {
|
|
|
|
Object.defineProperty(options, "configFile", { enumerable: false, writable: false, value: configFile });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-07 07:08:42 +02:00
|
|
|
function isNullOrUndefined(x: any): x is null | undefined {
|
|
|
|
// tslint:disable-next-line:no-null-keyword
|
|
|
|
return x === undefined || x === null;
|
|
|
|
}
|
|
|
|
|
2017-09-08 00:54:24 +02:00
|
|
|
function directoryOfCombinedPath(fileName: string, basePath: string) {
|
2018-01-30 23:16:44 +01:00
|
|
|
// Use the `getNormalizedAbsolutePath` function to avoid canonicalizing the path, as it must remain noncanonical
|
2017-09-08 00:54:24 +02:00
|
|
|
// until consistient casing errors are reported
|
2018-01-30 23:16:44 +01:00
|
|
|
return getDirectoryPath(getNormalizedAbsolutePath(fileName, basePath));
|
2017-09-08 00:54:24 +02:00
|
|
|
}
|
|
|
|
|
2016-11-16 21:25:24 +01:00
|
|
|
/**
|
2017-05-11 18:06:01 +02:00
|
|
|
* Parse the contents of a config file from json or json source file (tsconfig.json).
|
2017-04-03 18:32:39 +02:00
|
|
|
* @param json The contents of the config file to parse
|
2017-05-11 18:06:01 +02:00
|
|
|
* @param sourceFile sourceFile corresponding to the Json
|
2017-04-03 18:32:39 +02:00
|
|
|
* @param host Instance of ParseConfigHost used to enumerate files in folder.
|
|
|
|
* @param basePath A root directory to resolve relative path entries in the config
|
|
|
|
* file to. e.g. outDir
|
2017-04-11 22:57:21 +02:00
|
|
|
* @param resolutionStack Only present for backwards-compatibility. Should be empty.
|
2017-04-03 18:32:39 +02:00
|
|
|
*/
|
2017-05-11 18:06:01 +02:00
|
|
|
function parseJsonConfigFileContentWorker(
|
|
|
|
json: any,
|
2018-05-22 23:46:57 +02:00
|
|
|
sourceFile: TsConfigSourceFile | undefined,
|
2017-05-11 18:06:01 +02:00
|
|
|
host: ParseConfigHost,
|
|
|
|
basePath: string,
|
|
|
|
existingOptions: CompilerOptions = {},
|
|
|
|
configFileName?: string,
|
|
|
|
resolutionStack: Path[] = [],
|
2018-04-06 02:30:04 +02:00
|
|
|
extraFileExtensions: ReadonlyArray<FileExtensionInfo> = [],
|
2017-05-11 18:06:01 +02:00
|
|
|
): ParsedCommandLine {
|
2016-11-24 01:09:34 +01:00
|
|
|
Debug.assert((json === undefined && sourceFile !== undefined) || (json !== undefined && sourceFile === undefined));
|
2016-03-10 20:14:29 +01:00
|
|
|
const errors: Diagnostic[] = [];
|
2016-07-25 23:48:41 +02:00
|
|
|
|
2018-01-30 23:16:44 +01:00
|
|
|
const parsedConfig = parseConfig(json, sourceFile, host, basePath, configFileName, resolutionStack, errors);
|
2017-05-11 18:06:01 +02:00
|
|
|
const { raw } = parsedConfig;
|
|
|
|
const options = extend(existingOptions, parsedConfig.options || {});
|
2018-05-08 00:12:50 +02:00
|
|
|
options.configFilePath = configFileName && normalizeSlashes(configFileName);
|
2017-05-27 02:06:15 +02:00
|
|
|
setConfigFileInOptions(options, sourceFile);
|
2018-09-07 01:03:34 +02:00
|
|
|
let projectReferences: ProjectReference[] | undefined;
|
|
|
|
const { fileNames, wildcardDirectories, spec } = getFileNames();
|
2015-01-15 22:22:23 +01:00
|
|
|
return {
|
2015-10-17 23:35:28 +02:00
|
|
|
options,
|
2015-12-07 23:58:13 +01:00
|
|
|
fileNames,
|
2018-05-08 00:12:50 +02:00
|
|
|
projectReferences,
|
2017-05-11 18:06:01 +02:00
|
|
|
typeAcquisition: parsedConfig.typeAcquisition || getDefaultTypeAcquisition(),
|
|
|
|
raw,
|
2015-12-07 23:58:13 +01:00
|
|
|
errors,
|
2016-08-24 01:11:52 +02:00
|
|
|
wildcardDirectories,
|
2017-07-11 22:38:12 +02:00
|
|
|
compileOnSave: !!raw.compileOnSave,
|
|
|
|
configFileSpecs: spec
|
2015-01-15 22:22:23 +01:00
|
|
|
};
|
|
|
|
|
2017-04-11 22:57:21 +02:00
|
|
|
function getFileNames(): ExpandResult {
|
2018-05-22 23:46:57 +02:00
|
|
|
let filesSpecs: ReadonlyArray<string> | undefined;
|
2017-10-19 17:15:48 +02:00
|
|
|
if (hasProperty(raw, "files") && !isNullOrUndefined(raw.files)) {
|
|
|
|
if (isArray(raw.files)) {
|
|
|
|
filesSpecs = <ReadonlyArray<string>>raw.files;
|
2018-09-04 04:57:26 +02:00
|
|
|
const hasReferences = hasProperty(raw, "references") && !isNullOrUndefined(raw.references);
|
|
|
|
const hasZeroOrNoReferences = !hasReferences || raw.references.length === 0;
|
2018-09-27 21:40:29 +02:00
|
|
|
const hasExtends = hasProperty(raw, "extends");
|
|
|
|
if (filesSpecs.length === 0 && hasZeroOrNoReferences && !hasExtends) {
|
2018-09-07 02:40:02 +02:00
|
|
|
if (sourceFile) {
|
2018-09-08 06:06:07 +02:00
|
|
|
const fileName = configFileName || "tsconfig.json";
|
|
|
|
const diagnosticMessage = Diagnostics.The_files_list_in_config_file_0_is_empty;
|
2018-09-07 02:40:02 +02:00
|
|
|
const nodeValue = firstDefined(getTsConfigPropArray(sourceFile, "files"), property => property.initializer);
|
2018-09-08 06:06:07 +02:00
|
|
|
const error = nodeValue
|
|
|
|
? createDiagnosticForNodeInSourceFile(sourceFile, nodeValue, diagnosticMessage, fileName)
|
|
|
|
: createCompilerDiagnostic(diagnosticMessage, fileName);
|
2018-09-07 02:40:02 +02:00
|
|
|
errors.push(error);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
createCompilerDiagnosticOnlyIfJson(Diagnostics.The_files_list_in_config_file_0_is_empty, configFileName || "tsconfig.json");
|
|
|
|
}
|
2016-10-24 20:00:32 +02:00
|
|
|
}
|
2015-01-16 02:12:45 +01:00
|
|
|
}
|
2015-07-29 02:59:17 +02:00
|
|
|
else {
|
2017-05-11 18:06:01 +02:00
|
|
|
createCompilerDiagnosticOnlyIfJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "files", "Array");
|
2015-07-29 02:59:17 +02:00
|
|
|
}
|
2015-01-16 02:12:45 +01:00
|
|
|
}
|
2015-09-22 00:39:53 +02:00
|
|
|
|
2018-05-22 23:46:57 +02:00
|
|
|
let includeSpecs: ReadonlyArray<string> | undefined;
|
2017-10-19 17:15:48 +02:00
|
|
|
if (hasProperty(raw, "include") && !isNullOrUndefined(raw.include)) {
|
|
|
|
if (isArray(raw.include)) {
|
|
|
|
includeSpecs = <ReadonlyArray<string>>raw.include;
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-05-11 18:06:01 +02:00
|
|
|
createCompilerDiagnosticOnlyIfJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "include", "Array");
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-22 23:46:57 +02:00
|
|
|
let excludeSpecs: ReadonlyArray<string> | undefined;
|
2017-10-19 17:15:48 +02:00
|
|
|
if (hasProperty(raw, "exclude") && !isNullOrUndefined(raw.exclude)) {
|
|
|
|
if (isArray(raw.exclude)) {
|
|
|
|
excludeSpecs = <ReadonlyArray<string>>raw.exclude;
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-05-11 18:06:01 +02:00
|
|
|
createCompilerDiagnosticOnlyIfJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "exclude", "Array");
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
2018-05-11 12:47:44 +02:00
|
|
|
else if (raw.compilerOptions) {
|
|
|
|
const outDir = raw.compilerOptions.outDir;
|
|
|
|
const declarationDir = raw.compilerOptions.declarationDir;
|
|
|
|
|
2018-05-11 20:27:40 +02:00
|
|
|
if (outDir || declarationDir) {
|
|
|
|
excludeSpecs = [outDir, declarationDir].filter(d => !!d);
|
2016-09-01 21:57:23 +02:00
|
|
|
}
|
2016-05-26 02:07:36 +02:00
|
|
|
}
|
2015-11-12 22:23:53 +01:00
|
|
|
|
2017-07-11 22:38:12 +02:00
|
|
|
if (filesSpecs === undefined && includeSpecs === undefined) {
|
2015-12-07 23:58:13 +01:00
|
|
|
includeSpecs = ["**/*"];
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
2015-12-03 19:44:24 +01:00
|
|
|
|
2017-09-11 22:40:00 +02:00
|
|
|
const result = matchFileNames(filesSpecs, includeSpecs, excludeSpecs, configFileName ? directoryOfCombinedPath(configFileName, basePath) : basePath, options, host, errors, extraFileExtensions, sourceFile);
|
2018-09-27 19:04:49 +02:00
|
|
|
if (shouldReportNoInputFiles(result, canJsonReportNoInutFiles(raw), resolutionStack)) {
|
2017-07-11 22:38:12 +02:00
|
|
|
errors.push(getErrorForNoInputFiles(result.spec, configFileName));
|
2016-10-24 20:00:32 +02:00
|
|
|
}
|
|
|
|
|
2018-05-08 00:12:50 +02:00
|
|
|
if (hasProperty(raw, "references") && !isNullOrUndefined(raw.references)) {
|
|
|
|
if (isArray(raw.references)) {
|
|
|
|
for (const ref of raw.references) {
|
|
|
|
if (typeof ref.path !== "string") {
|
|
|
|
createCompilerDiagnosticOnlyIfJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "reference.path", "string");
|
|
|
|
}
|
|
|
|
else {
|
2018-09-07 01:03:34 +02:00
|
|
|
(projectReferences || (projectReferences = [])).push({
|
2018-05-08 00:12:50 +02:00
|
|
|
path: getNormalizedAbsolutePath(ref.path, basePath),
|
|
|
|
originalPath: ref.path,
|
|
|
|
prepend: ref.prepend,
|
|
|
|
circular: ref.circular
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
createCompilerDiagnosticOnlyIfJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "references", "Array");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-24 20:00:32 +02:00
|
|
|
return result;
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
2016-11-16 21:25:24 +01:00
|
|
|
|
2017-05-11 18:06:01 +02:00
|
|
|
function createCompilerDiagnosticOnlyIfJson(message: DiagnosticMessage, arg0?: string, arg1?: string) {
|
2016-11-24 01:09:34 +01:00
|
|
|
if (!sourceFile) {
|
2016-11-16 21:25:24 +01:00
|
|
|
errors.push(createCompilerDiagnostic(message, arg0, arg1));
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
2015-10-17 23:35:28 +02:00
|
|
|
|
2018-09-27 19:04:49 +02:00
|
|
|
function isErrorNoInputFiles(error: Diagnostic) {
|
2017-08-07 23:47:32 +02:00
|
|
|
return error.code === Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2.code;
|
|
|
|
}
|
|
|
|
|
2018-09-27 19:04:49 +02:00
|
|
|
function getErrorForNoInputFiles({ includeSpecs, excludeSpecs }: ConfigFileSpecs, configFileName: string | undefined) {
|
2017-07-11 22:38:12 +02:00
|
|
|
return createCompilerDiagnostic(
|
|
|
|
Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2,
|
|
|
|
configFileName || "tsconfig.json",
|
|
|
|
JSON.stringify(includeSpecs || []),
|
|
|
|
JSON.stringify(excludeSpecs || []));
|
|
|
|
}
|
|
|
|
|
2018-09-27 19:04:49 +02:00
|
|
|
function shouldReportNoInputFiles(result: ExpandResult, canJsonReportNoInutFiles: boolean, resolutionStack?: Path[]) {
|
|
|
|
return result.fileNames.length === 0 && canJsonReportNoInutFiles && (!resolutionStack || resolutionStack.length === 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*@internal*/
|
|
|
|
export function canJsonReportNoInutFiles(raw: any) {
|
|
|
|
return !hasProperty(raw, "files") && !hasProperty(raw, "references");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*@internal*/
|
|
|
|
export function updateErrorForNoInputFiles(result: ExpandResult, configFileName: string, configFileSpecs: ConfigFileSpecs, configParseDiagnostics: Diagnostic[], canJsonReportNoInutFiles: boolean) {
|
|
|
|
const existingErrors = configParseDiagnostics.length;
|
|
|
|
if (shouldReportNoInputFiles(result, canJsonReportNoInutFiles)) {
|
|
|
|
configParseDiagnostics.push(getErrorForNoInputFiles(configFileSpecs, configFileName));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
filterMutate(configParseDiagnostics, error => !isErrorNoInputFiles(error));
|
|
|
|
}
|
|
|
|
return existingErrors !== configParseDiagnostics.length;
|
|
|
|
}
|
|
|
|
|
2017-05-08 20:00:58 +02:00
|
|
|
interface ParsedTsconfig {
|
2017-05-11 18:06:01 +02:00
|
|
|
raw: any;
|
|
|
|
options?: CompilerOptions;
|
|
|
|
typeAcquisition?: TypeAcquisition;
|
2018-01-30 23:16:44 +01:00
|
|
|
/**
|
|
|
|
* Note that the case of the config path has not yet been normalized, as no files have been imported into the project yet
|
|
|
|
*/
|
|
|
|
extendedConfigPath?: string;
|
2017-05-11 18:06:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function isSuccessfulParsedTsconfig(value: ParsedTsconfig) {
|
|
|
|
return !!value.options;
|
2017-05-08 20:00:58 +02:00
|
|
|
}
|
2017-04-11 22:57:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This *just* extracts options/include/exclude/files out of a config file.
|
|
|
|
* It does *not* resolve the included files.
|
|
|
|
*/
|
|
|
|
function parseConfig(
|
|
|
|
json: any,
|
2018-05-22 23:46:57 +02:00
|
|
|
sourceFile: TsConfigSourceFile | undefined,
|
2017-04-11 22:57:21 +02:00
|
|
|
host: ParseConfigHost,
|
|
|
|
basePath: string,
|
2018-05-22 23:46:57 +02:00
|
|
|
configFileName: string | undefined,
|
2018-01-30 23:16:44 +01:00
|
|
|
resolutionStack: string[],
|
2017-07-21 16:16:22 +02:00
|
|
|
errors: Push<Diagnostic>,
|
2017-05-11 18:06:01 +02:00
|
|
|
): ParsedTsconfig {
|
2017-04-11 22:57:21 +02:00
|
|
|
basePath = normalizeSlashes(basePath);
|
2018-01-30 23:16:44 +01:00
|
|
|
const resolvedPath = getNormalizedAbsolutePath(configFileName || "", basePath);
|
2017-04-11 22:57:21 +02:00
|
|
|
|
|
|
|
if (resolutionStack.indexOf(resolvedPath) >= 0) {
|
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.Circularity_detected_while_resolving_configuration_Colon_0, [...resolutionStack, resolvedPath].join(" -> ")));
|
2018-05-22 23:46:57 +02:00
|
|
|
return { raw: json || convertToObject(sourceFile!, errors) };
|
2017-04-11 22:57:21 +02:00
|
|
|
}
|
|
|
|
|
2017-05-11 18:06:01 +02:00
|
|
|
const ownConfig = json ?
|
2018-01-30 23:16:44 +01:00
|
|
|
parseOwnConfigOfJson(json, host, basePath, configFileName, errors) :
|
2018-05-22 23:46:57 +02:00
|
|
|
parseOwnConfigOfJsonSourceFile(sourceFile!, host, basePath, configFileName, errors);
|
2017-05-11 18:06:01 +02:00
|
|
|
|
|
|
|
if (ownConfig.extendedConfigPath) {
|
|
|
|
// copy the resolution stack so it is never reused between branches in potential diamond-problem scenarios.
|
|
|
|
resolutionStack = resolutionStack.concat([resolvedPath]);
|
2018-09-17 14:41:48 +02:00
|
|
|
const extendedConfig = getExtendedConfig(sourceFile, ownConfig.extendedConfigPath, host, basePath, resolutionStack, errors);
|
2017-05-11 18:06:01 +02:00
|
|
|
if (extendedConfig && isSuccessfulParsedTsconfig(extendedConfig)) {
|
|
|
|
const baseRaw = extendedConfig.raw;
|
|
|
|
const raw = ownConfig.raw;
|
|
|
|
const setPropertyInRawIfNotUndefined = (propertyName: string) => {
|
|
|
|
const value = raw[propertyName] || baseRaw[propertyName];
|
|
|
|
if (value) {
|
|
|
|
raw[propertyName] = value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
setPropertyInRawIfNotUndefined("include");
|
|
|
|
setPropertyInRawIfNotUndefined("exclude");
|
|
|
|
setPropertyInRawIfNotUndefined("files");
|
|
|
|
if (raw.compileOnSave === undefined) {
|
|
|
|
raw.compileOnSave = baseRaw.compileOnSave;
|
|
|
|
}
|
|
|
|
ownConfig.options = assign({}, extendedConfig.options, ownConfig.options);
|
|
|
|
// TODO extend type typeAcquisition
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ownConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseOwnConfigOfJson(
|
|
|
|
json: any,
|
|
|
|
host: ParseConfigHost,
|
|
|
|
basePath: string,
|
2017-09-07 07:08:42 +02:00
|
|
|
configFileName: string | undefined,
|
2017-07-21 16:16:22 +02:00
|
|
|
errors: Push<Diagnostic>
|
2017-05-11 18:06:01 +02:00
|
|
|
): ParsedTsconfig {
|
2017-04-11 22:57:21 +02:00
|
|
|
if (hasProperty(json, "excludes")) {
|
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.Unknown_option_excludes_Did_you_mean_exclude));
|
|
|
|
}
|
|
|
|
|
2017-05-11 18:06:01 +02:00
|
|
|
const options = convertCompilerOptionsFromJsonWorker(json.compilerOptions, basePath, errors, configFileName);
|
|
|
|
// typingOptions has been deprecated and is only supported for backward compatibility purposes.
|
|
|
|
// It should be removed in future releases - use typeAcquisition instead.
|
2017-10-19 17:15:48 +02:00
|
|
|
const typeAcquisition = convertTypeAcquisitionFromJsonWorker(json.typeAcquisition || json.typingOptions, basePath, errors, configFileName);
|
2017-05-11 18:06:01 +02:00
|
|
|
json.compileOnSave = convertCompileOnSaveOptionFromJson(json, basePath, errors);
|
2018-05-22 23:46:57 +02:00
|
|
|
let extendedConfigPath: string | undefined;
|
2017-04-11 22:57:21 +02:00
|
|
|
|
|
|
|
if (json.extends) {
|
2017-07-19 22:07:55 +02:00
|
|
|
if (!isString(json.extends)) {
|
2017-05-11 18:06:01 +02:00
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "extends", "string"));
|
|
|
|
}
|
|
|
|
else {
|
2017-09-08 00:54:24 +02:00
|
|
|
const newBase = configFileName ? directoryOfCombinedPath(configFileName, basePath) : basePath;
|
2018-01-30 23:16:44 +01:00
|
|
|
extendedConfigPath = getExtendsConfigPath(json.extends, host, newBase, errors, createCompilerDiagnostic);
|
2017-04-11 22:57:21 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-11 18:06:01 +02:00
|
|
|
return { raw: json, options, typeAcquisition, extendedConfigPath };
|
2017-04-11 22:57:21 +02:00
|
|
|
}
|
|
|
|
|
2017-05-11 18:06:01 +02:00
|
|
|
function parseOwnConfigOfJsonSourceFile(
|
2018-01-30 19:53:54 +01:00
|
|
|
sourceFile: TsConfigSourceFile,
|
2017-05-11 18:06:01 +02:00
|
|
|
host: ParseConfigHost,
|
|
|
|
basePath: string,
|
2017-09-07 07:08:42 +02:00
|
|
|
configFileName: string | undefined,
|
2017-07-21 16:16:22 +02:00
|
|
|
errors: Push<Diagnostic>
|
2017-05-11 18:06:01 +02:00
|
|
|
): ParsedTsconfig {
|
|
|
|
const options = getDefaultCompilerOptions(configFileName);
|
2018-05-22 23:46:57 +02:00
|
|
|
let typeAcquisition: TypeAcquisition | undefined, typingOptionstypeAcquisition: TypeAcquisition | undefined;
|
|
|
|
let extendedConfigPath: string | undefined;
|
2017-05-11 18:06:01 +02:00
|
|
|
|
|
|
|
const optionsIterator: JsonConversionNotifier = {
|
2017-05-11 18:06:01 +02:00
|
|
|
onSetValidOptionKeyValueInParent(parentOption: string, option: CommandLineOption, value: CompilerOptionsValue) {
|
|
|
|
Debug.assert(parentOption === "compilerOptions" || parentOption === "typeAcquisition" || parentOption === "typingOptions");
|
|
|
|
const currentOption = parentOption === "compilerOptions" ?
|
|
|
|
options :
|
|
|
|
parentOption === "typeAcquisition" ?
|
|
|
|
(typeAcquisition || (typeAcquisition = getDefaultTypeAcquisition(configFileName))) :
|
2017-05-11 18:06:01 +02:00
|
|
|
(typingOptionstypeAcquisition || (typingOptionstypeAcquisition = getDefaultTypeAcquisition(configFileName)));
|
|
|
|
|
|
|
|
currentOption[option.name] = normalizeOptionValue(option, basePath, value);
|
|
|
|
},
|
2017-05-11 18:06:01 +02:00
|
|
|
onSetValidOptionKeyValueInRoot(key: string, _keyNode: PropertyName, value: CompilerOptionsValue, valueNode: Expression) {
|
2017-05-11 18:06:01 +02:00
|
|
|
switch (key) {
|
|
|
|
case "extends":
|
2017-09-08 00:54:24 +02:00
|
|
|
const newBase = configFileName ? directoryOfCombinedPath(configFileName, basePath) : basePath;
|
2017-05-11 18:06:01 +02:00
|
|
|
extendedConfigPath = getExtendsConfigPath(
|
|
|
|
<string>value,
|
|
|
|
host,
|
2017-09-07 07:08:42 +02:00
|
|
|
newBase,
|
2017-05-11 18:06:01 +02:00
|
|
|
errors,
|
|
|
|
(message, arg0) =>
|
2017-05-11 18:06:01 +02:00
|
|
|
createDiagnosticForNodeInSourceFile(sourceFile, valueNode, message, arg0)
|
2017-05-11 18:06:01 +02:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2017-05-11 18:06:01 +02:00
|
|
|
},
|
|
|
|
onSetUnknownOptionKeyValueInRoot(key: string, keyNode: PropertyName, _value: CompilerOptionsValue, _valueNode: Expression) {
|
|
|
|
if (key === "excludes") {
|
|
|
|
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, keyNode, Diagnostics.Unknown_option_excludes_Did_you_mean_exclude));
|
|
|
|
}
|
2017-05-11 18:06:01 +02:00
|
|
|
}
|
|
|
|
};
|
2018-02-24 03:06:27 +01:00
|
|
|
const json = convertToObjectWorker(sourceFile, errors, /*returnValue*/ true, getTsconfigRootOptionsMap(), optionsIterator);
|
2018-09-04 04:57:26 +02:00
|
|
|
|
2017-05-11 18:06:01 +02:00
|
|
|
if (!typeAcquisition) {
|
|
|
|
if (typingOptionstypeAcquisition) {
|
|
|
|
typeAcquisition = (typingOptionstypeAcquisition.enableAutoDiscovery !== undefined) ?
|
|
|
|
{
|
|
|
|
enable: typingOptionstypeAcquisition.enableAutoDiscovery,
|
|
|
|
include: typingOptionstypeAcquisition.include,
|
|
|
|
exclude: typingOptionstypeAcquisition.exclude
|
|
|
|
} :
|
|
|
|
typingOptionstypeAcquisition;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
typeAcquisition = getDefaultTypeAcquisition(configFileName);
|
|
|
|
}
|
2017-04-11 22:57:21 +02:00
|
|
|
}
|
|
|
|
|
2017-05-11 18:06:01 +02:00
|
|
|
return { raw: json, options, typeAcquisition, extendedConfigPath };
|
|
|
|
}
|
2017-04-13 00:11:16 +02:00
|
|
|
|
2017-05-11 18:06:01 +02:00
|
|
|
function getExtendsConfigPath(
|
|
|
|
extendedConfig: string,
|
|
|
|
host: ParseConfigHost,
|
|
|
|
basePath: string,
|
2017-07-21 16:16:22 +02:00
|
|
|
errors: Push<Diagnostic>,
|
2017-05-11 18:06:01 +02:00
|
|
|
createDiagnostic: (message: DiagnosticMessage, arg1?: string) => Diagnostic) {
|
|
|
|
extendedConfig = normalizeSlashes(extendedConfig);
|
2018-10-25 19:19:57 +02:00
|
|
|
if (isRootedDiskPath(extendedConfig) || startsWith(extendedConfig, "./") || startsWith(extendedConfig, "../")) {
|
|
|
|
let extendedConfigPath = getNormalizedAbsolutePath(extendedConfig, basePath);
|
|
|
|
if (!host.fileExists(extendedConfigPath) && !endsWith(extendedConfigPath, Extension.Json)) {
|
|
|
|
extendedConfigPath = `${extendedConfigPath}.json`;
|
|
|
|
if (!host.fileExists(extendedConfigPath)) {
|
|
|
|
errors.push(createDiagnostic(Diagnostics.File_0_does_not_exist, extendedConfig));
|
|
|
|
return undefined;
|
|
|
|
}
|
2017-04-11 22:57:21 +02:00
|
|
|
}
|
2018-10-25 19:19:57 +02:00
|
|
|
return extendedConfigPath;
|
|
|
|
}
|
|
|
|
// If the path isn't a rooted or relative path, resolve like a module
|
|
|
|
const resolved = nodeModuleNameResolver(extendedConfig, combinePaths(basePath, "tsconfig.json"), { moduleResolution: ModuleResolutionKind.NodeJs }, host, /*cache*/ undefined, /*projectRefs*/ undefined, /*lookupConfig*/ true);
|
|
|
|
if (resolved.resolvedModule) {
|
|
|
|
return resolved.resolvedModule.resolvedFileName;
|
2017-04-11 22:57:21 +02:00
|
|
|
}
|
2018-10-25 19:19:57 +02:00
|
|
|
errors.push(createDiagnostic(Diagnostics.File_0_does_not_exist, extendedConfig));
|
|
|
|
return undefined;
|
2017-05-11 18:06:01 +02:00
|
|
|
}
|
2017-04-11 22:57:21 +02:00
|
|
|
|
2017-05-11 18:06:01 +02:00
|
|
|
function getExtendedConfig(
|
2018-09-17 14:41:48 +02:00
|
|
|
sourceFile: TsConfigSourceFile | undefined,
|
2018-01-30 23:16:44 +01:00
|
|
|
extendedConfigPath: string,
|
2018-03-01 23:20:18 +01:00
|
|
|
host: ParseConfigHost,
|
2017-05-11 18:06:01 +02:00
|
|
|
basePath: string,
|
2018-01-30 23:16:44 +01:00
|
|
|
resolutionStack: string[],
|
2017-07-21 16:16:22 +02:00
|
|
|
errors: Push<Diagnostic>,
|
2017-05-11 18:06:01 +02:00
|
|
|
): ParsedTsconfig | undefined {
|
|
|
|
const extendedResult = readJsonConfigFile(extendedConfigPath, path => host.readFile(path));
|
2017-05-15 22:13:00 +02:00
|
|
|
if (sourceFile) {
|
2018-09-17 21:24:26 +02:00
|
|
|
sourceFile.extendedSourceFiles = [extendedResult.fileName];
|
2017-05-15 22:13:00 +02:00
|
|
|
}
|
2017-05-11 18:06:01 +02:00
|
|
|
if (extendedResult.parseDiagnostics.length) {
|
|
|
|
errors.push(...extendedResult.parseDiagnostics);
|
2017-04-11 22:57:21 +02:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const extendedDirname = getDirectoryPath(extendedConfigPath);
|
2017-05-11 18:06:01 +02:00
|
|
|
const extendedConfig = parseConfig(/*json*/ undefined, extendedResult, host, extendedDirname,
|
2018-01-30 23:16:44 +01:00
|
|
|
getBaseFileName(extendedConfigPath), resolutionStack, errors);
|
2018-09-17 14:41:48 +02:00
|
|
|
if (sourceFile && extendedResult.extendedSourceFiles) {
|
2018-09-17 21:24:26 +02:00
|
|
|
sourceFile.extendedSourceFiles!.push(...extendedResult.extendedSourceFiles);
|
2017-05-15 22:13:00 +02:00
|
|
|
}
|
2017-05-11 18:06:01 +02:00
|
|
|
|
|
|
|
if (isSuccessfulParsedTsconfig(extendedConfig)) {
|
|
|
|
// Update the paths to reflect base path
|
2018-01-30 23:16:44 +01:00
|
|
|
const relativeDifference = convertToRelativePath(extendedDirname, basePath, identity);
|
2017-05-11 18:06:01 +02:00
|
|
|
const updatePath = (path: string) => isRootedDiskPath(path) ? path : combinePaths(relativeDifference, path);
|
|
|
|
const mapPropertiesInRawIfNotUndefined = (propertyName: string) => {
|
|
|
|
if (raw[propertyName]) {
|
|
|
|
raw[propertyName] = map(raw[propertyName], updatePath);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const { raw } = extendedConfig;
|
|
|
|
mapPropertiesInRawIfNotUndefined("include");
|
|
|
|
mapPropertiesInRawIfNotUndefined("exclude");
|
|
|
|
mapPropertiesInRawIfNotUndefined("files");
|
|
|
|
}
|
|
|
|
|
|
|
|
return extendedConfig;
|
2017-04-11 22:57:21 +02:00
|
|
|
}
|
|
|
|
|
2017-07-21 16:16:22 +02:00
|
|
|
function convertCompileOnSaveOptionFromJson(jsonOption: any, basePath: string, errors: Push<Diagnostic>): boolean {
|
2016-08-24 01:11:52 +02:00
|
|
|
if (!hasProperty(jsonOption, compileOnSaveCommandLineOption.name)) {
|
2018-05-22 23:46:57 +02:00
|
|
|
return false;
|
2016-08-24 01:11:52 +02:00
|
|
|
}
|
2017-10-19 17:15:48 +02:00
|
|
|
const result = convertJsonOption(compileOnSaveCommandLineOption, jsonOption.compileOnSave, basePath, errors);
|
2018-05-22 23:46:57 +02:00
|
|
|
return typeof result === "boolean" && result;
|
2016-08-24 01:11:52 +02:00
|
|
|
}
|
|
|
|
|
2016-03-20 04:59:32 +01:00
|
|
|
export function convertCompilerOptionsFromJson(jsonOptions: any, basePath: string, configFileName?: string): { options: CompilerOptions, errors: Diagnostic[] } {
|
2015-11-04 23:02:33 +01:00
|
|
|
const errors: Diagnostic[] = [];
|
2016-03-20 04:59:32 +01:00
|
|
|
const options = convertCompilerOptionsFromJsonWorker(jsonOptions, basePath, errors, configFileName);
|
|
|
|
return { options, errors };
|
|
|
|
}
|
|
|
|
|
2016-11-19 02:46:06 +01:00
|
|
|
export function convertTypeAcquisitionFromJson(jsonOptions: any, basePath: string, configFileName?: string): { options: TypeAcquisition, errors: Diagnostic[] } {
|
2016-03-20 04:59:32 +01:00
|
|
|
const errors: Diagnostic[] = [];
|
2016-11-19 02:46:06 +01:00
|
|
|
const options = convertTypeAcquisitionFromJsonWorker(jsonOptions, basePath, errors, configFileName);
|
2016-03-20 04:59:32 +01:00
|
|
|
return { options, errors };
|
|
|
|
}
|
|
|
|
|
2016-11-16 21:25:24 +01:00
|
|
|
function getDefaultCompilerOptions(configFileName?: string) {
|
2018-04-30 06:31:33 +02:00
|
|
|
const options: CompilerOptions = configFileName && getBaseFileName(configFileName) === "jsconfig.json"
|
2018-01-25 23:06:11 +01:00
|
|
|
? { allowJs: true, maxNodeModuleJsDepth: 2, allowSyntheticDefaultImports: true, skipLibCheck: true, noEmit: true }
|
2016-09-22 23:55:58 +02:00
|
|
|
: {};
|
2016-11-16 21:25:24 +01:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertCompilerOptionsFromJsonWorker(jsonOptions: any,
|
2017-07-21 16:16:22 +02:00
|
|
|
basePath: string, errors: Push<Diagnostic>, configFileName?: string): CompilerOptions {
|
2016-11-16 21:25:24 +01:00
|
|
|
|
|
|
|
const options = getDefaultCompilerOptions(configFileName);
|
2016-03-20 04:59:32 +01:00
|
|
|
convertOptionsFromJson(optionDeclarations, jsonOptions, basePath, options, Diagnostics.Unknown_compiler_option_0, errors);
|
2018-05-08 00:12:50 +02:00
|
|
|
if (configFileName) {
|
|
|
|
options.configFilePath = normalizeSlashes(configFileName);
|
|
|
|
}
|
2016-03-16 00:30:11 +01:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2017-12-04 22:36:01 +01:00
|
|
|
function getDefaultTypeAcquisition(configFileName?: string): TypeAcquisition {
|
2018-05-22 23:46:57 +02:00
|
|
|
return { enable: !!configFileName && getBaseFileName(configFileName) === "jsconfig.json", include: [], exclude: [] };
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
|
|
|
|
2016-11-19 02:46:06 +01:00
|
|
|
function convertTypeAcquisitionFromJsonWorker(jsonOptions: any,
|
2017-07-21 16:16:22 +02:00
|
|
|
basePath: string, errors: Push<Diagnostic>, configFileName?: string): TypeAcquisition {
|
2016-03-16 00:30:11 +01:00
|
|
|
|
2016-11-23 21:20:55 +01:00
|
|
|
const options = getDefaultTypeAcquisition(configFileName);
|
2016-11-22 23:47:44 +01:00
|
|
|
const typeAcquisition = convertEnableAutoDiscoveryToEnable(jsonOptions);
|
|
|
|
convertOptionsFromJson(typeAcquisitionDeclarations, typeAcquisition, basePath, options, Diagnostics.Unknown_type_acquisition_option_0, errors);
|
2016-03-16 00:30:11 +01:00
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2017-07-21 16:16:22 +02:00
|
|
|
function convertOptionsFromJson(optionDeclarations: ReadonlyArray<CommandLineOption>, jsonOptions: any, basePath: string,
|
|
|
|
defaultOptions: CompilerOptions | TypeAcquisition, diagnosticMessage: DiagnosticMessage, errors: Push<Diagnostic>) {
|
2015-10-17 23:35:28 +02:00
|
|
|
|
|
|
|
if (!jsonOptions) {
|
2016-05-03 23:52:41 +02:00
|
|
|
return;
|
2015-10-17 23:35:28 +02:00
|
|
|
}
|
|
|
|
|
2016-11-16 21:25:24 +01:00
|
|
|
const optionNameMap = commandLineOptionsToMap(optionDeclarations);
|
2015-10-17 23:35:28 +02:00
|
|
|
|
2015-11-04 23:02:33 +01:00
|
|
|
for (const id in jsonOptions) {
|
2016-12-05 23:13:32 +01:00
|
|
|
const opt = optionNameMap.get(id);
|
|
|
|
if (opt) {
|
2016-03-16 00:30:11 +01:00
|
|
|
defaultOptions[opt.name] = convertJsonOption(opt, jsonOptions[id], basePath, errors);
|
2015-10-17 23:35:28 +02:00
|
|
|
}
|
|
|
|
else {
|
2016-03-16 00:30:11 +01:00
|
|
|
errors.push(createCompilerDiagnostic(diagnosticMessage, id));
|
2015-10-17 23:35:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-21 16:16:22 +02:00
|
|
|
function convertJsonOption(opt: CommandLineOption, value: any, basePath: string, errors: Push<Diagnostic>): CompilerOptionsValue {
|
2016-11-16 21:25:24 +01:00
|
|
|
if (isCompilerOptionsValue(opt, value)) {
|
|
|
|
const optType = opt.type;
|
|
|
|
if (optType === "list" && isArray(value)) {
|
|
|
|
return convertJsonOptionOfListType(<CommandLineOptionOfListType>opt, value, basePath, errors);
|
2016-03-10 20:14:29 +01:00
|
|
|
}
|
2017-07-19 22:07:55 +02:00
|
|
|
else if (!isString(optType)) {
|
2016-11-16 21:25:24 +01:00
|
|
|
return convertJsonOptionOfCustomType(<CommandLineOptionOfCustomType>opt, <string>value, errors);
|
2016-02-23 04:00:06 +01:00
|
|
|
}
|
2016-11-16 21:25:24 +01:00
|
|
|
return normalizeNonListOptionValue(opt, basePath, value);
|
2016-02-23 04:00:06 +01:00
|
|
|
}
|
2016-03-10 20:14:29 +01:00
|
|
|
else {
|
2016-11-16 21:25:24 +01:00
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, opt.name, getCompilerOptionValueTypeString(opt)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function normalizeOptionValue(option: CommandLineOption, basePath: string, value: any): CompilerOptionsValue {
|
2017-09-07 07:08:42 +02:00
|
|
|
if (isNullOrUndefined(value)) return undefined;
|
2016-11-16 21:25:24 +01:00
|
|
|
if (option.type === "list") {
|
2018-10-18 00:17:21 +02:00
|
|
|
const listOption = option;
|
2017-07-19 22:07:55 +02:00
|
|
|
if (listOption.element.isFilePath || !isString(listOption.element.type)) {
|
2016-11-16 21:25:24 +01:00
|
|
|
return <CompilerOptionsValue>filter(map(value, v => normalizeOptionValue(listOption.element, basePath, v)), v => !!v);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
2017-07-19 22:07:55 +02:00
|
|
|
else if (!isString(option.type)) {
|
2017-08-18 22:38:24 +02:00
|
|
|
return option.type.get(isString(value) ? value.toLowerCase() : value);
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
|
|
|
return normalizeNonListOptionValue(option, basePath, value);
|
|
|
|
}
|
|
|
|
|
2018-01-08 17:52:13 +01:00
|
|
|
function normalizeNonListOptionValue(option: CommandLineOption, basePath: string, value: any): CompilerOptionsValue {
|
2016-11-16 21:25:24 +01:00
|
|
|
if (option.isFilePath) {
|
|
|
|
value = normalizePath(combinePaths(basePath, value));
|
|
|
|
if (value === "") {
|
|
|
|
value = ".";
|
|
|
|
}
|
2016-02-23 04:00:06 +01:00
|
|
|
}
|
2016-11-16 21:25:24 +01:00
|
|
|
return value;
|
2016-03-10 20:14:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-21 16:16:22 +02:00
|
|
|
function convertJsonOptionOfCustomType(opt: CommandLineOptionOfCustomType, value: string, errors: Push<Diagnostic>) {
|
2017-09-07 07:08:42 +02:00
|
|
|
if (isNullOrUndefined(value)) return undefined;
|
2016-03-10 20:14:29 +01:00
|
|
|
const key = value.toLowerCase();
|
2016-12-05 23:13:32 +01:00
|
|
|
const val = opt.type.get(key);
|
|
|
|
if (val !== undefined) {
|
|
|
|
return val;
|
2016-03-10 20:14:29 +01:00
|
|
|
}
|
|
|
|
else {
|
2016-03-16 21:49:36 +01:00
|
|
|
errors.push(createCompilerDiagnosticForInvalidCustomType(opt));
|
2016-03-10 20:14:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-21 16:16:22 +02:00
|
|
|
function convertJsonOptionOfListType(option: CommandLineOptionOfListType, values: ReadonlyArray<any>, basePath: string, errors: Push<Diagnostic>): any[] {
|
2016-03-16 23:29:13 +01:00
|
|
|
return filter(map(values, v => convertJsonOption(option.element, v, basePath, errors)), v => !!v);
|
2016-02-23 04:00:06 +01:00
|
|
|
}
|
2016-05-03 23:52:41 +02:00
|
|
|
|
|
|
|
function trimString(s: string) {
|
|
|
|
return typeof s.trim === "function" ? s.trim() : s.replace(/^[\s]+|[\s]+$/g, "");
|
2015-10-17 23:35:28 +02:00
|
|
|
}
|
2015-12-03 19:44:24 +01:00
|
|
|
|
2015-12-17 00:49:31 +01:00
|
|
|
/**
|
|
|
|
* Tests for a path that ends in a recursive directory wildcard.
|
2016-01-04 20:37:25 +01:00
|
|
|
* Matches **, \**, **\, and \**\, but not a**b.
|
2015-12-17 00:49:31 +01:00
|
|
|
*
|
2016-01-04 20:37:25 +01:00
|
|
|
* NOTE: used \ in place of / above to avoid issues with multiline comments.
|
2015-12-17 00:49:31 +01:00
|
|
|
*
|
|
|
|
* Breakdown:
|
|
|
|
* (^|\/) # matches either the beginning of the string or a directory separator.
|
|
|
|
* \*\* # matches the recursive directory wildcard "**".
|
|
|
|
* \/?$ # matches an optional trailing directory separator at the end of the string.
|
|
|
|
*/
|
2015-12-15 00:21:12 +01:00
|
|
|
const invalidTrailingRecursionPattern = /(^|\/)\*\*\/?$/;
|
2015-12-17 00:49:31 +01:00
|
|
|
|
2016-07-01 18:59:07 +02:00
|
|
|
/**
|
|
|
|
* Tests for a path where .. appears after a recursive directory wildcard.
|
|
|
|
* Matches **\..\*, **\a\..\*, and **\.., but not ..\**\*
|
|
|
|
*
|
|
|
|
* NOTE: used \ in place of / above to avoid issues with multiline comments.
|
|
|
|
*
|
|
|
|
* Breakdown:
|
|
|
|
* (^|\/) # matches either the beginning of the string or a directory separator.
|
|
|
|
* \*\*\/ # matches a recursive directory wildcard "**" followed by a directory separator.
|
|
|
|
* (.*\/)? # optionally matches any number of characters followed by a directory separator.
|
|
|
|
* \.\. # matches a parent directory path component ".."
|
|
|
|
* ($|\/) # matches either the end of the string or a directory separator.
|
|
|
|
*/
|
|
|
|
const invalidDotDotAfterRecursiveWildcardPattern = /(^|\/)\*\*\/(.*\/)?\.\.($|\/)/;
|
|
|
|
|
2015-12-17 00:49:31 +01:00
|
|
|
/**
|
|
|
|
* Tests for a path containing a wildcard character in a directory component of the path.
|
2016-01-04 20:37:25 +01:00
|
|
|
* Matches \*\, \?\, and \a*b\, but not \a\ or \a\*.
|
2015-12-17 00:49:31 +01:00
|
|
|
*
|
2016-01-04 20:37:25 +01:00
|
|
|
* NOTE: used \ in place of / above to avoid issues with multiline comments.
|
2015-12-17 00:49:31 +01:00
|
|
|
*
|
|
|
|
* Breakdown:
|
|
|
|
* \/ # matches a directory separator.
|
|
|
|
* [^/]*? # matches any number of characters excluding directory separators (non-greedy).
|
|
|
|
* [*?] # matches either a wildcard character (* or ?)
|
|
|
|
* [^/]* # matches any number of characters excluding directory separators (greedy).
|
|
|
|
* \/ # matches a directory separator.
|
|
|
|
*/
|
|
|
|
const watchRecursivePattern = /\/[^/]*?[*?][^/]*\//;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Matches the portion of a wildcard path that does not contain wildcards.
|
2016-01-04 20:37:25 +01:00
|
|
|
* Matches \a of \a\*, or \a\b\c of \a\b\c\?\d.
|
|
|
|
*
|
|
|
|
* NOTE: used \ in place of / above to avoid issues with multiline comments.
|
2015-12-17 00:49:31 +01:00
|
|
|
*
|
|
|
|
* Breakdown:
|
|
|
|
* ^ # matches the beginning of the string
|
|
|
|
* [^*?]* # matches any number of non-wildcard characters
|
|
|
|
* (?=\/[^/]*[*?]) # lookahead that matches a directory separator followed by
|
|
|
|
* # a path component that contains at least one wildcard character (* or ?).
|
|
|
|
*/
|
|
|
|
const wildcardDirectoryPattern = /^[^*?]*(?=\/[^/]*[*?])/;
|
|
|
|
|
2015-12-03 19:44:24 +01:00
|
|
|
/**
|
|
|
|
* Expands an array of file specifications.
|
|
|
|
*
|
2017-08-12 01:37:47 +02:00
|
|
|
* @param filesSpecs The literal file names to include.
|
|
|
|
* @param includeSpecs The wildcard file specifications to include.
|
|
|
|
* @param excludeSpecs The wildcard file specifications to exclude.
|
2015-12-03 19:44:24 +01:00
|
|
|
* @param basePath The base path for any relative file specifications.
|
|
|
|
* @param options Compiler options.
|
|
|
|
* @param host The host used to resolve files and directories.
|
|
|
|
* @param errors An array for diagnostic reporting.
|
|
|
|
*/
|
2017-07-21 16:16:22 +02:00
|
|
|
function matchFileNames(
|
2018-05-22 23:46:57 +02:00
|
|
|
filesSpecs: ReadonlyArray<string> | undefined,
|
|
|
|
includeSpecs: ReadonlyArray<string> | undefined,
|
|
|
|
excludeSpecs: ReadonlyArray<string> | undefined,
|
2017-07-21 16:16:22 +02:00
|
|
|
basePath: string,
|
|
|
|
options: CompilerOptions,
|
|
|
|
host: ParseConfigHost,
|
|
|
|
errors: Push<Diagnostic>,
|
2018-04-06 02:30:04 +02:00
|
|
|
extraFileExtensions: ReadonlyArray<FileExtensionInfo>,
|
2018-05-22 23:46:57 +02:00
|
|
|
jsonSourceFile: TsConfigSourceFile | undefined
|
2017-08-07 20:04:11 +02:00
|
|
|
): ExpandResult {
|
2017-07-11 22:38:12 +02:00
|
|
|
basePath = normalizePath(basePath);
|
2018-05-22 23:46:57 +02:00
|
|
|
let validatedIncludeSpecs: ReadonlyArray<string> | undefined, validatedExcludeSpecs: ReadonlyArray<string> | undefined;
|
2017-07-11 22:38:12 +02:00
|
|
|
|
2017-07-14 00:04:49 +02:00
|
|
|
// The exclude spec list is converted into a regular expression, which allows us to quickly
|
|
|
|
// test whether a file or directory should be excluded before recursively traversing the
|
|
|
|
// file system.
|
|
|
|
|
2017-07-11 22:38:12 +02:00
|
|
|
if (includeSpecs) {
|
|
|
|
validatedIncludeSpecs = validateSpecs(includeSpecs, errors, /*allowTrailingRecursion*/ false, jsonSourceFile, "include");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (excludeSpecs) {
|
|
|
|
validatedExcludeSpecs = validateSpecs(excludeSpecs, errors, /*allowTrailingRecursion*/ true, jsonSourceFile, "exclude");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wildcard directories (provided as part of a wildcard path) are stored in a
|
|
|
|
// file map that marks whether it was a regular wildcard match (with a `*` or `?` token),
|
|
|
|
// or a recursive directory. This information is used by filesystem watchers to monitor for
|
|
|
|
// new entries in these paths.
|
|
|
|
const wildcardDirectories = getWildcardDirectories(validatedIncludeSpecs, validatedExcludeSpecs, basePath, host.useCaseSensitiveFileNames);
|
|
|
|
|
2018-09-07 01:03:34 +02:00
|
|
|
const spec: ConfigFileSpecs = { filesSpecs, includeSpecs, excludeSpecs, validatedIncludeSpecs, validatedExcludeSpecs, wildcardDirectories };
|
2017-07-11 22:38:12 +02:00
|
|
|
return getFileNamesFromConfigSpecs(spec, basePath, options, host, extraFileExtensions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-14 21:52:29 +02:00
|
|
|
* Gets the file names from the provided config file specs that contain, files, include, exclude and
|
|
|
|
* other properties needed to resolve the file names
|
|
|
|
* @param spec The config file specs extracted with file names to include, wildcards to include/exclude and other details
|
2017-07-11 22:38:12 +02:00
|
|
|
* @param basePath The base path for any relative file specifications.
|
|
|
|
* @param options Compiler options.
|
|
|
|
* @param host The host used to resolve files and directories.
|
2017-08-14 21:52:29 +02:00
|
|
|
* @param extraFileExtensions optionaly file extra file extension information from host
|
2017-07-11 22:38:12 +02:00
|
|
|
*/
|
2017-10-03 04:08:13 +02:00
|
|
|
/* @internal */
|
2018-04-06 02:30:04 +02:00
|
|
|
export function getFileNamesFromConfigSpecs(spec: ConfigFileSpecs, basePath: string, options: CompilerOptions, host: ParseConfigHost, extraFileExtensions: ReadonlyArray<FileExtensionInfo> = []): ExpandResult {
|
2015-12-03 19:44:24 +01:00
|
|
|
basePath = normalizePath(basePath);
|
|
|
|
|
2017-11-21 03:03:18 +01:00
|
|
|
const keyMapper = host.useCaseSensitiveFileNames ? identity : toLowerCase;
|
2015-12-07 23:58:13 +01:00
|
|
|
|
|
|
|
// Literal file names (provided via the "files" array in tsconfig.json) are stored in a
|
2015-12-08 19:54:23 +01:00
|
|
|
// file map with a possibly case insensitive key. We use this map later when when including
|
2015-12-07 23:58:13 +01:00
|
|
|
// wildcard paths.
|
2016-08-11 01:47:06 +02:00
|
|
|
const literalFileMap = createMap<string>();
|
2015-12-07 23:58:13 +01:00
|
|
|
|
2015-12-08 19:54:23 +01:00
|
|
|
// Wildcard paths (provided via the "includes" array in tsconfig.json) are stored in a
|
|
|
|
// file map with a possibly case insensitive key. We use this map to store paths matched
|
2015-12-07 23:58:13 +01:00
|
|
|
// via wildcard, and to handle extension priority.
|
2016-08-11 01:47:06 +02:00
|
|
|
const wildcardFileMap = createMap<string>();
|
2015-12-07 23:58:13 +01:00
|
|
|
|
2018-10-11 23:19:32 +02:00
|
|
|
// Wildcard paths of json files (provided via the "includes" array in tsconfig.json) are stored in a
|
|
|
|
// file map with a possibly case insensitive key. We use this map to store paths matched
|
|
|
|
// via wildcard of *.json kind
|
|
|
|
const wildCardJsonFileMap = createMap<string>();
|
2017-07-11 22:38:12 +02:00
|
|
|
const { filesSpecs, validatedIncludeSpecs, validatedExcludeSpecs, wildcardDirectories } = spec;
|
2015-12-07 23:58:13 +01:00
|
|
|
|
2015-12-08 19:54:23 +01:00
|
|
|
// Rather than requery this for each file and filespec, we query the supported extensions
|
2015-12-07 23:58:13 +01:00
|
|
|
// once and store it on the expansion context.
|
2018-02-24 00:08:18 +01:00
|
|
|
const supportedExtensions = getSupportedExtensions(options, extraFileExtensions);
|
2018-10-11 23:19:32 +02:00
|
|
|
const supportedExtensionsWithJsonIfResolveJsonModule = getSuppoertedExtensionsWithJsonIfResolveJsonModule(options, supportedExtensions);
|
2015-12-07 23:58:13 +01:00
|
|
|
|
|
|
|
// Literal files are always included verbatim. An "include" or "exclude" specification cannot
|
|
|
|
// remove a literal file.
|
2017-07-11 22:38:12 +02:00
|
|
|
if (filesSpecs) {
|
|
|
|
for (const fileName of filesSpecs) {
|
2017-09-07 07:08:42 +02:00
|
|
|
const file = getNormalizedAbsolutePath(fileName, basePath);
|
2016-12-05 23:13:32 +01:00
|
|
|
literalFileMap.set(keyMapper(file), file);
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 23:19:32 +02:00
|
|
|
let jsonOnlyIncludeRegexes: ReadonlyArray<RegExp> | undefined;
|
2017-07-11 22:38:12 +02:00
|
|
|
if (validatedIncludeSpecs && validatedIncludeSpecs.length > 0) {
|
2018-10-11 23:19:32 +02:00
|
|
|
for (const file of host.readDirectory(basePath, supportedExtensionsWithJsonIfResolveJsonModule, validatedExcludeSpecs, validatedIncludeSpecs, /*depth*/ undefined)) {
|
|
|
|
if (fileExtensionIs(file, Extension.Json)) {
|
|
|
|
// Valid only if *.json specified
|
|
|
|
if (!jsonOnlyIncludeRegexes) {
|
|
|
|
const includes = validatedIncludeSpecs.filter(s => endsWith(s, Extension.Json));
|
|
|
|
const includeFilePatterns = map(getRegularExpressionsForWildcards(includes, basePath, "files"), pattern => `^${pattern}$`);
|
|
|
|
jsonOnlyIncludeRegexes = includeFilePatterns ? includeFilePatterns.map(pattern => getRegexFromPattern(pattern, host.useCaseSensitiveFileNames)) : emptyArray;
|
|
|
|
}
|
|
|
|
const includeIndex = findIndex(jsonOnlyIncludeRegexes, re => re.test(file));
|
|
|
|
if (includeIndex !== -1) {
|
|
|
|
const key = keyMapper(file);
|
|
|
|
if (!literalFileMap.has(key) && !wildCardJsonFileMap.has(key)) {
|
|
|
|
wildCardJsonFileMap.set(key, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2015-12-15 00:21:12 +01:00
|
|
|
// If we have already included a literal or wildcard path with a
|
|
|
|
// higher priority extension, we should skip this file.
|
|
|
|
//
|
|
|
|
// This handles cases where we may encounter both <file>.ts and
|
|
|
|
// <file>.d.ts (or <file>.js if "allowJs" is enabled) in the same
|
|
|
|
// directory when they are compilation outputs.
|
|
|
|
if (hasFileWithHigherPriorityExtension(file, literalFileMap, wildcardFileMap, supportedExtensions, keyMapper)) {
|
2015-12-07 23:58:13 +01:00
|
|
|
continue;
|
|
|
|
}
|
2015-12-03 19:44:24 +01:00
|
|
|
|
2015-12-15 00:21:12 +01:00
|
|
|
// We may have included a wildcard path with a lower priority
|
|
|
|
// extension due to the user-defined order of entries in the
|
|
|
|
// "include" array. If there is a lower priority extension in the
|
|
|
|
// same directory, we should remove it.
|
|
|
|
removeWildcardFilesWithLowerPriorityExtension(file, wildcardFileMap, supportedExtensions, keyMapper);
|
2015-12-03 19:44:24 +01:00
|
|
|
|
2015-12-15 00:21:12 +01:00
|
|
|
const key = keyMapper(file);
|
2016-12-05 23:13:32 +01:00
|
|
|
if (!literalFileMap.has(key) && !wildcardFileMap.has(key)) {
|
|
|
|
wildcardFileMap.set(key, file);
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-07 23:58:13 +01:00
|
|
|
|
2016-12-28 18:05:52 +01:00
|
|
|
const literalFiles = arrayFrom(literalFileMap.values());
|
|
|
|
const wildcardFiles = arrayFrom(wildcardFileMap.values());
|
2018-05-08 00:12:50 +02:00
|
|
|
|
2015-12-15 00:21:12 +01:00
|
|
|
return {
|
2018-10-11 23:19:32 +02:00
|
|
|
fileNames: literalFiles.concat(wildcardFiles, arrayFrom(wildCardJsonFileMap.values())),
|
2017-07-11 22:38:12 +02:00
|
|
|
wildcardDirectories,
|
|
|
|
spec
|
2015-12-15 00:21:12 +01:00
|
|
|
};
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
|
|
|
|
2018-05-22 23:46:57 +02:00
|
|
|
function validateSpecs(specs: ReadonlyArray<string>, errors: Push<Diagnostic>, allowTrailingRecursion: boolean, jsonSourceFile: TsConfigSourceFile | undefined, specKey: string): ReadonlyArray<string> {
|
2017-08-08 20:38:41 +02:00
|
|
|
return specs.filter(spec => {
|
|
|
|
const diag = specToDiagnostic(spec, allowTrailingRecursion);
|
|
|
|
if (diag !== undefined) {
|
|
|
|
errors.push(createDiagnostic(diag, spec));
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
2017-08-08 20:38:41 +02:00
|
|
|
return diag === undefined;
|
|
|
|
});
|
2016-11-16 21:25:24 +01:00
|
|
|
|
|
|
|
function createDiagnostic(message: DiagnosticMessage, spec: string): Diagnostic {
|
2018-04-30 20:44:09 +02:00
|
|
|
const element = getTsConfigPropArrayElementValue(jsonSourceFile, specKey, spec);
|
|
|
|
return element ?
|
2018-05-22 23:46:57 +02:00
|
|
|
createDiagnosticForNodeInSourceFile(jsonSourceFile!, element, message, spec) :
|
2018-04-30 20:44:09 +02:00
|
|
|
createCompilerDiagnostic(message, spec);
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
2015-12-07 23:58:13 +01:00
|
|
|
}
|
|
|
|
|
2018-03-01 23:20:18 +01:00
|
|
|
function specToDiagnostic(spec: string, allowTrailingRecursion: boolean): DiagnosticMessage | undefined {
|
2017-08-08 20:38:41 +02:00
|
|
|
if (!allowTrailingRecursion && invalidTrailingRecursionPattern.test(spec)) {
|
|
|
|
return Diagnostics.File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0;
|
|
|
|
}
|
|
|
|
else if (invalidDotDotAfterRecursiveWildcardPattern.test(spec)) {
|
|
|
|
return Diagnostics.File_specification_cannot_contain_a_parent_directory_that_appears_after_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-07 23:58:13 +01:00
|
|
|
/**
|
2015-12-15 00:21:12 +01:00
|
|
|
* Gets directories in a set of include patterns that should be watched for changes.
|
2015-12-07 23:58:13 +01:00
|
|
|
*/
|
2018-05-22 23:46:57 +02:00
|
|
|
function getWildcardDirectories(include: ReadonlyArray<string> | undefined, exclude: ReadonlyArray<string> | undefined, path: string, useCaseSensitiveFileNames: boolean): MapLike<WatchDirectoryFlags> {
|
2015-12-15 00:21:12 +01:00
|
|
|
// We watch a directory recursively if it contains a wildcard anywhere in a directory segment
|
|
|
|
// of the pattern:
|
|
|
|
//
|
|
|
|
// /a/b/**/d - Watch /a/b recursively to catch changes to any d in any subfolder recursively
|
|
|
|
// /a/b/*/d - Watch /a/b recursively to catch any d in any immediate subfolder, even if a new subfolder is added
|
2016-10-07 18:29:11 +02:00
|
|
|
// /a/b - Watch /a/b recursively to catch changes to anything in any recursive subfoler
|
2015-12-15 00:21:12 +01:00
|
|
|
//
|
|
|
|
// We watch a directory without recursion if it contains a wildcard in the file segment of
|
|
|
|
// the pattern:
|
|
|
|
//
|
|
|
|
// /a/b/* - Watch /a/b directly to catch any new file
|
|
|
|
// /a/b/a?z - Watch /a/b directly to catch any new file matching a?z
|
2016-05-31 19:11:04 +02:00
|
|
|
const rawExcludeRegex = getRegularExpressionForWildcard(exclude, path, "exclude");
|
|
|
|
const excludeRegex = rawExcludeRegex && new RegExp(rawExcludeRegex, useCaseSensitiveFileNames ? "" : "i");
|
2018-03-01 23:20:18 +01:00
|
|
|
const wildcardDirectories: MapLike<WatchDirectoryFlags> = {};
|
2015-12-16 22:42:17 +01:00
|
|
|
if (include !== undefined) {
|
2015-12-15 00:21:12 +01:00
|
|
|
const recursiveKeys: string[] = [];
|
2015-12-16 22:42:17 +01:00
|
|
|
for (const file of include) {
|
2016-10-07 18:29:11 +02:00
|
|
|
const spec = normalizePath(combinePaths(path, file));
|
|
|
|
if (excludeRegex && excludeRegex.test(spec)) {
|
2015-12-16 22:42:17 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-10-07 18:29:11 +02:00
|
|
|
const match = getWildcardDirectoryFromSpec(spec, useCaseSensitiveFileNames);
|
2015-12-15 00:21:12 +01:00
|
|
|
if (match) {
|
2016-10-07 18:29:11 +02:00
|
|
|
const { key, flags } = match;
|
2016-08-15 21:03:39 +02:00
|
|
|
const existingFlags = wildcardDirectories[key];
|
2015-12-15 00:21:12 +01:00
|
|
|
if (existingFlags === undefined || existingFlags < flags) {
|
|
|
|
wildcardDirectories[key] = flags;
|
|
|
|
if (flags === WatchDirectoryFlags.Recursive) {
|
|
|
|
recursiveKeys.push(key);
|
|
|
|
}
|
|
|
|
}
|
2015-12-07 23:58:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-15 00:21:12 +01:00
|
|
|
// Remove any subpaths under an existing recursively watched directory.
|
2017-06-07 20:58:25 +02:00
|
|
|
for (const key in wildcardDirectories) {
|
|
|
|
if (hasProperty(wildcardDirectories, key)) {
|
|
|
|
for (const recursiveKey of recursiveKeys) {
|
|
|
|
if (key !== recursiveKey && containsPath(recursiveKey, key, path, !useCaseSensitiveFileNames)) {
|
|
|
|
delete wildcardDirectories[key];
|
|
|
|
}
|
2015-12-15 00:21:12 +01:00
|
|
|
}
|
|
|
|
}
|
2017-04-05 07:34:51 +02:00
|
|
|
}
|
2015-12-07 23:58:13 +01:00
|
|
|
}
|
|
|
|
|
2015-12-15 00:21:12 +01:00
|
|
|
return wildcardDirectories;
|
2015-12-07 23:58:13 +01:00
|
|
|
}
|
2015-12-03 19:44:24 +01:00
|
|
|
|
2016-10-07 18:29:11 +02:00
|
|
|
function getWildcardDirectoryFromSpec(spec: string, useCaseSensitiveFileNames: boolean): { key: string, flags: WatchDirectoryFlags } | undefined {
|
|
|
|
const match = wildcardDirectoryPattern.exec(spec);
|
2016-10-12 19:08:43 +02:00
|
|
|
if (match) {
|
|
|
|
return {
|
2016-10-07 18:29:11 +02:00
|
|
|
key: useCaseSensitiveFileNames ? match[0] : match[0].toLowerCase(),
|
|
|
|
flags: watchRecursivePattern.test(spec) ? WatchDirectoryFlags.Recursive : WatchDirectoryFlags.None
|
2016-10-12 19:08:43 +02:00
|
|
|
};
|
|
|
|
}
|
2016-10-24 15:48:05 +02:00
|
|
|
if (isImplicitGlob(spec)) {
|
2016-10-12 19:08:43 +02:00
|
|
|
return { key: spec, flags: WatchDirectoryFlags.Recursive };
|
|
|
|
}
|
2016-10-24 15:48:05 +02:00
|
|
|
return undefined;
|
2016-10-07 18:29:11 +02:00
|
|
|
}
|
|
|
|
|
2015-12-07 23:58:13 +01:00
|
|
|
/**
|
|
|
|
* Determines whether a literal or wildcard file has already been included that has a higher
|
|
|
|
* extension priority.
|
|
|
|
*
|
|
|
|
* @param file The path to the file.
|
|
|
|
* @param extensionPriority The priority of the extension.
|
|
|
|
* @param context The expansion context.
|
|
|
|
*/
|
2017-07-12 02:39:33 +02:00
|
|
|
function hasFileWithHigherPriorityExtension(file: string, literalFiles: Map<string>, wildcardFiles: Map<string>, extensions: ReadonlyArray<string>, keyMapper: (value: string) => string) {
|
2015-12-15 00:21:12 +01:00
|
|
|
const extensionPriority = getExtensionPriority(file, extensions);
|
2017-02-13 21:19:33 +01:00
|
|
|
const adjustedExtensionPriority = adjustExtensionPriority(extensionPriority, extensions);
|
2016-01-05 19:11:44 +01:00
|
|
|
for (let i = ExtensionPriority.Highest; i < adjustedExtensionPriority; i++) {
|
2015-12-15 00:21:12 +01:00
|
|
|
const higherPriorityExtension = extensions[i];
|
|
|
|
const higherPriorityPath = keyMapper(changeExtension(file, higherPriorityExtension));
|
2016-12-05 23:13:32 +01:00
|
|
|
if (literalFiles.has(higherPriorityPath) || wildcardFiles.has(higherPriorityPath)) {
|
2015-12-07 23:58:13 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes files included via wildcard expansion with a lower extension priority that have
|
|
|
|
* already been included.
|
|
|
|
*
|
|
|
|
* @param file The path to the file.
|
|
|
|
* @param extensionPriority The priority of the extension.
|
|
|
|
* @param context The expansion context.
|
|
|
|
*/
|
2017-07-12 02:39:33 +02:00
|
|
|
function removeWildcardFilesWithLowerPriorityExtension(file: string, wildcardFiles: Map<string>, extensions: ReadonlyArray<string>, keyMapper: (value: string) => string) {
|
2015-12-15 00:21:12 +01:00
|
|
|
const extensionPriority = getExtensionPriority(file, extensions);
|
2017-02-13 21:19:33 +01:00
|
|
|
const nextExtensionPriority = getNextLowestExtensionPriority(extensionPriority, extensions);
|
2016-01-05 19:11:44 +01:00
|
|
|
for (let i = nextExtensionPriority; i < extensions.length; i++) {
|
2015-12-15 00:21:12 +01:00
|
|
|
const lowerPriorityExtension = extensions[i];
|
|
|
|
const lowerPriorityPath = keyMapper(changeExtension(file, lowerPriorityExtension));
|
2016-12-05 23:13:32 +01:00
|
|
|
wildcardFiles.delete(lowerPriorityPath);
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-25 22:30:27 +02:00
|
|
|
/**
|
2018-11-12 04:03:46 +01:00
|
|
|
* Produces a cleaned version of compiler options with personally identifying info (aka, paths) removed.
|
2017-05-25 22:30:27 +02:00
|
|
|
* Also converts enum values back to strings.
|
|
|
|
*/
|
|
|
|
/* @internal */
|
2018-03-01 23:20:18 +01:00
|
|
|
export function convertCompilerOptionsForTelemetry(opts: CompilerOptions): CompilerOptions {
|
|
|
|
const out: CompilerOptions = {};
|
2017-06-07 20:58:25 +02:00
|
|
|
for (const key in opts) {
|
|
|
|
if (opts.hasOwnProperty(key)) {
|
|
|
|
const type = getOptionFromName(key);
|
|
|
|
if (type !== undefined) { // Ignore unknown options
|
|
|
|
out[key] = getOptionValueWithEmptyStrings(opts[key], type);
|
|
|
|
}
|
2017-05-25 22:30:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getOptionValueWithEmptyStrings(value: any, option: CommandLineOption): {} {
|
|
|
|
switch (option.type) {
|
|
|
|
case "object": // "paths". Can't get any useful information from the value since we blank out strings, so just return "".
|
|
|
|
return "";
|
|
|
|
case "string": // Could be any arbitrary string -- use empty string instead.
|
|
|
|
return "";
|
|
|
|
case "number": // Allow numbers, but be sure to check it's actually a number.
|
|
|
|
return typeof value === "number" ? value : "";
|
|
|
|
case "boolean":
|
|
|
|
return typeof value === "boolean" ? value : "";
|
|
|
|
case "list":
|
2018-10-18 00:17:21 +02:00
|
|
|
const elementType = option.element;
|
2018-03-01 23:20:18 +01:00
|
|
|
return isArray(value) ? value.map(v => getOptionValueWithEmptyStrings(v, elementType)) : "";
|
2017-05-25 22:30:27 +02:00
|
|
|
default:
|
2018-03-01 23:20:18 +01:00
|
|
|
return forEachEntry(option.type, (optionEnumValue, optionStringValue) => {
|
2017-05-25 22:30:27 +02:00
|
|
|
if (optionEnumValue === value) {
|
|
|
|
return optionStringValue;
|
|
|
|
}
|
2018-05-22 23:46:57 +02:00
|
|
|
})!; // TODO: GH#18217
|
2017-05-25 22:30:27 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-11 18:06:01 +02:00
|
|
|
}
|