2014-07-13 01:04:16 +02:00
|
|
|
/// <reference path="sys.ts"/>
|
|
|
|
/// <reference path="types.ts"/>
|
|
|
|
/// <reference path="core.ts"/>
|
2015-10-31 02:10:05 +01:00
|
|
|
/// <reference path="diagnosticInformationMap.generated.ts"/>
|
2016-11-14 20:13:06 +01:00
|
|
|
/// <reference path="parser.ts"/>
|
2014-07-13 01:04:16 +02:00
|
|
|
|
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" };
|
2015-03-31 19:52:21 +02:00
|
|
|
/* @internal */
|
2016-06-06 20:29:03 +02:00
|
|
|
export const optionDeclarations: CommandLineOption[] = [
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
|
|
|
name: "charset",
|
|
|
|
type: "string",
|
|
|
|
},
|
2016-08-24 01:11:52 +02:00
|
|
|
compileOnSaveCommandLineOption,
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
|
|
|
name: "declaration",
|
|
|
|
shortName: "d",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Generates_corresponding_d_ts_file,
|
|
|
|
},
|
2016-02-20 19:27:51 +01:00
|
|
|
{
|
|
|
|
name: "declarationDir",
|
|
|
|
type: "string",
|
|
|
|
isFilePath: true,
|
|
|
|
paramType: Diagnostics.DIRECTORY,
|
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
|
|
|
name: "diagnostics",
|
|
|
|
type: "boolean",
|
|
|
|
},
|
2016-07-20 00:10:29 +02:00
|
|
|
{
|
|
|
|
name: "extendedDiagnostics",
|
|
|
|
type: "boolean",
|
2016-08-02 20:45:56 +02:00
|
|
|
experimental: true
|
2016-07-20 00:10:29 +02:00
|
|
|
},
|
2014-08-06 21:55:57 +02:00
|
|
|
{
|
2014-10-26 02:26:24 +02:00
|
|
|
name: "emitBOM",
|
2014-08-06 21:55:57 +02:00
|
|
|
type: "boolean"
|
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
|
|
|
name: "help",
|
|
|
|
shortName: "h",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Print_this_message,
|
|
|
|
},
|
2016-05-24 20:33:23 +02:00
|
|
|
{
|
|
|
|
name: "help",
|
|
|
|
shortName: "?",
|
|
|
|
type: "boolean"
|
|
|
|
},
|
2015-07-27 13:52:57 +02:00
|
|
|
{
|
|
|
|
name: "init",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file,
|
|
|
|
},
|
2015-04-08 09:14:23 +02:00
|
|
|
{
|
|
|
|
name: "inlineSourceMap",
|
|
|
|
type: "boolean",
|
|
|
|
},
|
2015-04-21 05:33:31 +02:00
|
|
|
{
|
|
|
|
name: "inlineSources",
|
|
|
|
type: "boolean",
|
|
|
|
},
|
2015-06-18 23:01:31 +02:00
|
|
|
{
|
|
|
|
name: "jsx",
|
2016-08-16 01:41:32 +02:00
|
|
|
type: createMap({
|
2015-06-18 23:01:31 +02:00
|
|
|
"preserve": JsxEmit.Preserve,
|
|
|
|
"react": JsxEmit.React
|
2016-08-16 01:41:32 +02:00
|
|
|
}),
|
2015-06-18 23:01:31 +02:00
|
|
|
paramType: Diagnostics.KIND,
|
2015-06-26 18:38:21 +02:00
|
|
|
description: Diagnostics.Specify_JSX_code_generation_Colon_preserve_or_react,
|
2015-06-18 23:01:31 +02:00
|
|
|
},
|
2015-12-18 11:56:08 +01:00
|
|
|
{
|
2016-01-07 22:59:25 +01:00
|
|
|
name: "reactNamespace",
|
2015-12-18 11:56:08 +01:00
|
|
|
type: "string",
|
2016-03-14 23:49:29 +01:00
|
|
|
description: Diagnostics.Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit
|
2015-06-18 23:01:31 +02:00
|
|
|
},
|
2016-11-09 21:12:48 +01:00
|
|
|
{
|
|
|
|
name: "jsxFactory",
|
|
|
|
type: "string",
|
|
|
|
description: Diagnostics.Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h
|
|
|
|
},
|
2015-01-15 22:22:23 +01:00
|
|
|
{
|
|
|
|
name: "listFiles",
|
|
|
|
type: "boolean",
|
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
|
|
|
name: "locale",
|
|
|
|
type: "string",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mapRoot",
|
|
|
|
type: "string",
|
2015-01-15 22:22:23 +01:00
|
|
|
isFilePath: true,
|
2016-03-14 23:49:29 +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
|
|
|
paramType: Diagnostics.LOCATION,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "module",
|
|
|
|
shortName: "m",
|
2016-08-16 01:41:32 +02:00
|
|
|
type: createMap({
|
2016-02-11 21:45:52 +01:00
|
|
|
"none": ModuleKind.None,
|
2014-08-02 02:12:29 +02:00
|
|
|
"commonjs": ModuleKind.CommonJS,
|
2015-04-10 21:10:38 +02:00
|
|
|
"amd": ModuleKind.AMD,
|
|
|
|
"system": ModuleKind.System,
|
2015-04-24 05:50:35 +02:00
|
|
|
"umd": ModuleKind.UMD,
|
2016-10-14 10:54:54 +02:00
|
|
|
"es6": ModuleKind.ES2015,
|
2015-10-15 19:50:47 +02:00
|
|
|
"es2015": ModuleKind.ES2015,
|
2016-08-16 01:41:32 +02:00
|
|
|
}),
|
2015-10-22 22:23:12 +02:00
|
|
|
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015,
|
2014-08-02 02:12:29 +02:00
|
|
|
paramType: Diagnostics.KIND,
|
|
|
|
},
|
2015-04-26 17:37:02 +02:00
|
|
|
{
|
|
|
|
name: "newLine",
|
2016-08-16 01:41:32 +02:00
|
|
|
type: createMap({
|
2015-05-04 22:21:39 +02:00
|
|
|
"crlf": NewLineKind.CarriageReturnLineFeed,
|
|
|
|
"lf": NewLineKind.LineFeed
|
2016-08-16 01:41:32 +02:00
|
|
|
}),
|
2016-03-14 23:49:29 +01:00
|
|
|
description: Diagnostics.Specify_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix,
|
2015-04-26 17:37:02 +02:00
|
|
|
paramType: Diagnostics.NEWLINE,
|
|
|
|
},
|
2014-12-17 05:25:19 +01:00
|
|
|
{
|
|
|
|
name: "noEmit",
|
|
|
|
type: "boolean",
|
|
|
|
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
|
|
|
{
|
|
|
|
name: "noEmitHelpers",
|
|
|
|
type: "boolean"
|
|
|
|
},
|
2014-10-27 20:48:46 +01:00
|
|
|
{
|
|
|
|
name: "noEmitOnError",
|
|
|
|
type: "boolean",
|
2015-05-12 23:31:38 +02:00
|
|
|
description: Diagnostics.Do_not_emit_outputs_if_any_errors_were_reported,
|
2014-10-27 20:48:46 +01:00
|
|
|
},
|
2016-08-06 00:10:02 +02:00
|
|
|
{
|
|
|
|
name: "noErrorTruncation",
|
2016-08-17 23:22:01 +02:00
|
|
|
type: "boolean"
|
2016-08-06 00:10:02 +02:00
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
|
|
|
name: "noImplicitAny",
|
|
|
|
type: "boolean",
|
2015-01-11 11:14:06 +01:00
|
|
|
description: Diagnostics.Raise_error_on_expressions_and_declarations_with_an_implied_any_type,
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
2016-03-26 00:37:28 +01:00
|
|
|
{
|
|
|
|
name: "noImplicitThis",
|
|
|
|
type: "boolean",
|
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
|
|
|
},
|
2016-06-25 00:38:39 +02:00
|
|
|
{
|
|
|
|
name: "noUnusedLocals",
|
|
|
|
type: "boolean",
|
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",
|
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
|
|
|
{
|
|
|
|
name: "noLib",
|
|
|
|
type: "boolean",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "noResolve",
|
|
|
|
type: "boolean",
|
|
|
|
},
|
2015-06-04 22:56:33 +02:00
|
|
|
{
|
|
|
|
name: "skipDefaultLibCheck",
|
|
|
|
type: "boolean",
|
|
|
|
},
|
2016-05-22 02:44:37 +02:00
|
|
|
{
|
|
|
|
name: "skipLibCheck",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Skip_type_checking_of_declaration_files,
|
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
|
|
|
name: "out",
|
|
|
|
type: "string",
|
2015-08-21 02:37:56 +02:00
|
|
|
isFilePath: false, // This is intentionally broken to support compatability with existing tsconfig files
|
2016-05-03 23:52:41 +02:00
|
|
|
// for correct behaviour, please use outFile
|
2015-08-21 02:37:56 +02:00
|
|
|
paramType: Diagnostics.FILE,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "outFile",
|
|
|
|
type: "string",
|
2015-06-20 02:34:10 +02:00
|
|
|
isFilePath: true,
|
2014-08-02 02:12:29 +02:00
|
|
|
description: Diagnostics.Concatenate_and_emit_output_to_single_file,
|
|
|
|
paramType: Diagnostics.FILE,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "outDir",
|
|
|
|
type: "string",
|
2015-01-15 22:22:23 +01:00
|
|
|
isFilePath: true,
|
2014-08-02 02:12:29 +02:00
|
|
|
description: Diagnostics.Redirect_output_structure_to_the_directory,
|
|
|
|
paramType: Diagnostics.DIRECTORY,
|
|
|
|
},
|
2014-12-10 21:37:09 +01:00
|
|
|
{
|
|
|
|
name: "preserveConstEnums",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code
|
|
|
|
},
|
2015-11-02 22:20:48 +01:00
|
|
|
{
|
|
|
|
name: "pretty",
|
2015-11-03 01:40:35 +01:00
|
|
|
description: Diagnostics.Stylize_errors_and_messages_using_color_and_context_experimental,
|
2015-11-02 22:20:48 +01:00
|
|
|
type: "boolean"
|
|
|
|
},
|
2015-01-15 22:22:23 +01:00
|
|
|
{
|
|
|
|
name: "project",
|
|
|
|
shortName: "p",
|
|
|
|
type: "string",
|
|
|
|
isFilePath: true,
|
|
|
|
description: Diagnostics.Compile_the_project_in_the_given_directory,
|
|
|
|
paramType: Diagnostics.DIRECTORY
|
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
|
|
|
name: "removeComments",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Do_not_emit_comments_to_output,
|
|
|
|
},
|
2015-04-15 07:11:25 +02:00
|
|
|
{
|
|
|
|
name: "rootDir",
|
|
|
|
type: "string",
|
|
|
|
isFilePath: true,
|
|
|
|
paramType: Diagnostics.LOCATION,
|
2016-03-14 23:49:29 +01:00
|
|
|
description: Diagnostics.Specify_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir,
|
2015-04-15 07:11:25 +02:00
|
|
|
},
|
2015-03-31 04:33:15 +02:00
|
|
|
{
|
2015-05-19 06:49:41 +02:00
|
|
|
name: "isolatedModules",
|
2015-03-31 04:33:15 +02:00
|
|
|
type: "boolean",
|
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
2014-08-10 14:02:49 +02:00
|
|
|
name: "sourceMap",
|
2014-08-02 02:12:29 +02:00
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Generates_corresponding_map_file,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sourceRoot",
|
|
|
|
type: "string",
|
2015-01-15 22:22:23 +01:00
|
|
|
isFilePath: true,
|
2016-03-14 23:49:29 +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
|
|
|
paramType: Diagnostics.LOCATION,
|
|
|
|
},
|
2015-08-27 02:13:53 +02:00
|
|
|
{
|
|
|
|
name: "suppressExcessPropertyErrors",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Suppress_excess_property_checks_for_object_literals,
|
|
|
|
experimental: true
|
|
|
|
},
|
2014-12-10 21:37:09 +01:00
|
|
|
{
|
|
|
|
name: "suppressImplicitAnyIndexErrors",
|
|
|
|
type: "boolean",
|
2014-12-11 02:51:14 +01:00
|
|
|
description: Diagnostics.Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures,
|
2014-12-10 21:37:09 +01:00
|
|
|
},
|
2015-02-03 22:15:28 +01:00
|
|
|
{
|
|
|
|
name: "stripInternal",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Do_not_emit_declarations_for_code_that_has_an_internal_annotation,
|
|
|
|
experimental: true
|
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
|
|
|
name: "target",
|
|
|
|
shortName: "t",
|
2016-08-16 01:41:32 +02:00
|
|
|
type: createMap({
|
2015-10-15 19:50:47 +02:00
|
|
|
"es3": ScriptTarget.ES3,
|
|
|
|
"es5": ScriptTarget.ES5,
|
2016-10-14 10:54:54 +02:00
|
|
|
"es6": ScriptTarget.ES2015,
|
2015-10-15 19:50:47 +02:00
|
|
|
"es2015": ScriptTarget.ES2015,
|
2016-10-12 21:28:11 +02:00
|
|
|
"es2016": ScriptTarget.ES2016,
|
2016-10-05 17:09:58 +02:00
|
|
|
"es2017": ScriptTarget.ES2017,
|
2016-11-07 18:54:48 +01:00
|
|
|
"esnext": ScriptTarget.ESNext,
|
2016-08-16 01:41:32 +02:00
|
|
|
}),
|
2016-03-14 23:49:29 +01:00
|
|
|
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015,
|
2014-08-02 02:12:29 +02:00
|
|
|
paramType: Diagnostics.VERSION,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "version",
|
|
|
|
shortName: "v",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Print_the_compiler_s_version,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "watch",
|
|
|
|
shortName: "w",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Watch_input_files,
|
2015-04-02 02:58:28 +02:00
|
|
|
},
|
2015-06-02 00:01:24 +02:00
|
|
|
{
|
|
|
|
name: "experimentalDecorators",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Enables_experimental_support_for_ES7_decorators
|
|
|
|
},
|
2015-04-02 02:58:28 +02:00
|
|
|
{
|
|
|
|
name: "emitDecoratorMetadata",
|
|
|
|
type: "boolean",
|
2015-06-02 00:01:24 +02:00
|
|
|
experimental: true,
|
|
|
|
description: Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators
|
2015-08-21 01:13:49 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "moduleResolution",
|
2016-08-16 01:41:32 +02:00
|
|
|
type: createMap({
|
2015-08-21 01:13:49 +02:00
|
|
|
"node": ModuleResolutionKind.NodeJs,
|
2015-11-19 06:46:45 +01:00
|
|
|
"classic": ModuleResolutionKind.Classic,
|
2016-08-16 01:41:32 +02:00
|
|
|
}),
|
2016-03-14 23:49:29 +01:00
|
|
|
description: Diagnostics.Specify_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6,
|
2016-09-10 04:37:51 +02:00
|
|
|
paramType: Diagnostics.STRATEGY,
|
2015-10-15 23:43:51 +02:00
|
|
|
},
|
2015-09-03 19:49:39 +02:00
|
|
|
{
|
2015-10-03 09:20:15 +02:00
|
|
|
name: "allowUnusedLabels",
|
2015-09-03 19:49:39 +02:00
|
|
|
type: "boolean",
|
2015-10-03 09:20:15 +02:00
|
|
|
description: Diagnostics.Do_not_report_errors_on_unused_labels
|
2015-09-03 19:49:39 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "noImplicitReturns",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Report_error_when_not_all_code_paths_in_function_return_a_value
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "noFallthroughCasesInSwitch",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Report_errors_for_fallthrough_cases_in_switch_statement
|
|
|
|
},
|
|
|
|
{
|
2015-10-03 09:20:15 +02:00
|
|
|
name: "allowUnreachableCode",
|
2015-09-03 19:49:39 +02:00
|
|
|
type: "boolean",
|
2015-10-03 09:20:15 +02:00
|
|
|
description: Diagnostics.Do_not_report_errors_on_unreachable_code
|
2015-10-29 17:33:27 +01:00
|
|
|
},
|
2015-10-15 23:43:51 +02:00
|
|
|
{
|
|
|
|
name: "forceConsistentCasingInFileNames",
|
|
|
|
type: "boolean",
|
2015-10-27 19:52:57 +01:00
|
|
|
description: Diagnostics.Disallow_inconsistently_cased_references_to_the_same_file
|
2015-11-09 23:24:19 +01:00
|
|
|
},
|
|
|
|
{
|
2015-11-19 06:46:45 +01:00
|
|
|
name: "baseUrl",
|
|
|
|
type: "string",
|
|
|
|
isFilePath: true,
|
2015-11-25 01:41:41 +01:00
|
|
|
description: Diagnostics.Base_directory_to_resolve_non_absolute_module_names
|
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",
|
|
|
|
isTSConfigOnly: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
}
|
2015-11-20 06:11:57 +01:00
|
|
|
},
|
2016-04-06 01:33:11 +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
|
|
|
|
}
|
2016-04-06 01:33:11 +02:00
|
|
|
},
|
2016-04-06 22:49:25 +02:00
|
|
|
{
|
|
|
|
name: "types",
|
|
|
|
type: "list",
|
|
|
|
element: {
|
|
|
|
name: "types",
|
|
|
|
type: "string"
|
|
|
|
},
|
|
|
|
description: Diagnostics.Type_declaration_files_to_be_included_in_compilation
|
|
|
|
},
|
2015-11-20 06:33:33 +01:00
|
|
|
{
|
2016-04-01 21:41:01 +02:00
|
|
|
name: "traceResolution",
|
2015-11-09 23:24:19 +01:00
|
|
|
type: "boolean",
|
2016-04-01 21:41:01 +02:00
|
|
|
description: Diagnostics.Enable_tracing_of_the_name_resolution_process
|
2015-11-20 22:45:25 +01:00
|
|
|
},
|
2015-09-16 22:57:51 +02:00
|
|
|
{
|
2015-10-28 22:02:46 +01:00
|
|
|
name: "allowJs",
|
|
|
|
type: "boolean",
|
2015-11-20 22:45:25 +01:00
|
|
|
description: Diagnostics.Allow_javascript_files_to_be_compiled
|
2015-11-26 06:23:35 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "allowSyntheticDefaultImports",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking
|
2016-02-03 23:16:09 +01:00
|
|
|
},
|
|
|
|
{
|
2016-02-06 01:30:01 +01:00
|
|
|
name: "noImplicitUseStrict",
|
2016-02-03 23:16:09 +01:00
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output
|
2016-02-15 03:41:38 +01:00
|
|
|
},
|
2016-02-13 16:48:25 +01:00
|
|
|
{
|
|
|
|
name: "maxNodeModuleJsDepth",
|
|
|
|
type: "number",
|
|
|
|
description: Diagnostics.The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files
|
2016-05-24 02:00:10 +02:00
|
|
|
},
|
2016-04-06 22:25:29 +02:00
|
|
|
{
|
|
|
|
name: "listEmittedFiles",
|
2016-04-08 01:47:52 +02:00
|
|
|
type: "boolean"
|
2016-04-06 22:25:29 +02:00
|
|
|
},
|
2016-03-28 23:20:29 +02:00
|
|
|
{
|
|
|
|
name: "lib",
|
|
|
|
type: "list",
|
|
|
|
element: {
|
|
|
|
name: "lib",
|
2016-08-16 01:41:32 +02:00
|
|
|
type: createMap({
|
2016-03-28 23:20:29 +02:00
|
|
|
// JavaScript only
|
|
|
|
"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",
|
2016-05-10 23:22:00 +02:00
|
|
|
"es2017": "lib.es2017.d.ts",
|
2016-03-28 23:20:29 +02:00
|
|
|
// Host only
|
|
|
|
"dom": "lib.dom.d.ts",
|
2016-09-21 02:11:39 +02:00
|
|
|
"dom.iterable": "lib.dom.iterable.d.ts",
|
2016-03-28 23:20:29 +02:00
|
|
|
"webworker": "lib.webworker.d.ts",
|
|
|
|
"scripthost": "lib.scripthost.d.ts",
|
|
|
|
// ES2015 Or ESNext By-feature options
|
2016-04-05 07:02:12 +02:00
|
|
|
"es2015.core": "lib.es2015.core.d.ts",
|
2016-03-28 23:20:29 +02:00
|
|
|
"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",
|
2016-05-10 23:22:00 +02:00
|
|
|
"es2016.array.include": "lib.es2016.array.include.d.ts",
|
2016-05-23 17:41:44 +02:00
|
|
|
"es2017.object": "lib.es2017.object.d.ts",
|
2016-11-10 21:43:51 +01:00
|
|
|
"es2017.sharedmemory": "lib.es2017.sharedmemory.d.ts",
|
|
|
|
"es2017.string": "lib.es2017.string.d.ts",
|
2016-08-16 01:41:32 +02:00
|
|
|
}),
|
2016-03-28 23:20:29 +02:00
|
|
|
},
|
|
|
|
description: Diagnostics.Specify_library_files_to_be_included_in_the_compilation_Colon
|
|
|
|
},
|
2016-03-14 22:51:24 +01:00
|
|
|
{
|
2016-06-27 20:46:58 +02:00
|
|
|
name: "disableSizeLimit",
|
2016-03-15 04:14:17 +01:00
|
|
|
type: "boolean"
|
2016-03-24 19:42:18 +01:00
|
|
|
},
|
2016-02-15 03:41:38 +01:00
|
|
|
{
|
|
|
|
name: "strictNullChecks",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Enable_strict_null_checks
|
2016-06-11 09:12:04 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "importHelpers",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Import_emit_helpers_from_tslib
|
2016-10-09 00:49:51 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "alwaysStrict",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Parse_in_strict_mode_and_emit_use_strict_for_each_source_file
|
2015-09-03 19:49:39 +02:00
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
];
|
2015-03-31 19:52:21 +02:00
|
|
|
|
2016-03-10 20:14:29 +01:00
|
|
|
/* @internal */
|
2016-11-19 02:46:06 +01:00
|
|
|
export let 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,
|
|
|
|
noImplicitAny: false,
|
|
|
|
sourceMap: false,
|
|
|
|
};
|
|
|
|
|
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) {
|
2016-11-22 23:47:44 +01:00
|
|
|
const result: TypeAcquisition = {
|
|
|
|
enable: typeAcquisition.enableAutoDiscovery,
|
|
|
|
include: typeAcquisition.include || [],
|
|
|
|
exclude: typeAcquisition.exclude || []
|
|
|
|
};
|
|
|
|
return result;
|
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
|
|
|
}
|
|
|
|
|
2015-08-25 23:34:34 +02:00
|
|
|
/* @internal */
|
2015-07-27 13:52:57 +02:00
|
|
|
export function getOptionNameMap(): OptionNameMap {
|
|
|
|
if (optionNameMapCache) {
|
|
|
|
return optionNameMapCache;
|
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
|
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 => {
|
|
|
|
optionNameMap[option.name.toLowerCase()] = option;
|
|
|
|
if (option.shortName) {
|
|
|
|
shortOptionNames[option.shortName] = option.name;
|
|
|
|
}
|
|
|
|
});
|
2015-07-27 13:52:57 +02:00
|
|
|
|
|
|
|
optionNameMapCache = { optionNameMap, shortOptionNames };
|
|
|
|
return optionNameMapCache;
|
|
|
|
}
|
|
|
|
|
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-10-18 17:09:56 +02:00
|
|
|
const namesOfType = Object.keys(opt.type).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 */
|
|
|
|
export function parseCustomTypeOption(opt: CommandLineOptionOfCustomType, value: string, errors: Diagnostic[]) {
|
2016-05-03 23:52:41 +02:00
|
|
|
const key = trimString((value || "")).toLowerCase();
|
2016-03-28 23:20:29 +02:00
|
|
|
const map = opt.type;
|
2016-08-16 01:41:32 +02:00
|
|
|
if (key in map) {
|
2016-03-28 23:20:29 +02:00
|
|
|
return map[key];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
errors.push(createCompilerDiagnosticForInvalidCustomType(opt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* @internal */
|
2016-06-10 23:14:32 +02:00
|
|
|
export function parseListTypeOption(opt: CommandLineOptionOfListType, value = "", errors: Diagnostic[]): (string | number)[] | undefined {
|
|
|
|
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:
|
|
|
|
return filter(map(values, v => parseCustomTypeOption(<CommandLineOptionOfCustomType>opt.element, v, errors)), v => !!v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* @internal */
|
2015-08-28 03:16:22 +02:00
|
|
|
export function parseCommandLine(commandLine: string[], readFile?: (path: string) => string): ParsedCommandLine {
|
2015-11-04 23:02:33 +01:00
|
|
|
const options: CompilerOptions = {};
|
|
|
|
const fileNames: string[] = [];
|
|
|
|
const errors: Diagnostic[] = [];
|
|
|
|
const { optionNameMap, shortOptionNames } = getOptionNameMap();
|
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
|
|
|
};
|
|
|
|
|
|
|
|
function parseStrings(args: string[]) {
|
2015-06-26 02:36:19 +02:00
|
|
|
let i = 0;
|
2014-07-13 01:04:16 +02:00
|
|
|
while (i < args.length) {
|
2015-12-23 00:45:00 +01:00
|
|
|
let s = args[i];
|
|
|
|
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) {
|
|
|
|
s = s.slice(s.charCodeAt(1) === CharacterCodes.minus ? 2 : 1).toLowerCase();
|
|
|
|
|
|
|
|
// Try to translate short option names to their full equivalents.
|
2016-08-15 21:03:39 +02:00
|
|
|
if (s in shortOptionNames) {
|
2014-07-13 01:04:16 +02:00
|
|
|
s = shortOptionNames[s];
|
|
|
|
}
|
|
|
|
|
2016-08-15 21:03:39 +02:00
|
|
|
if (s in optionNameMap) {
|
2015-11-04 23:02:33 +01:00
|
|
|
const opt = optionNameMap[s];
|
2014-07-13 01:04:16 +02:00
|
|
|
|
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") {
|
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_expects_an_argument, opt.name));
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
let optValue = args[i];
|
|
|
|
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":
|
2016-06-10 23:14:32 +02:00
|
|
|
const result = parseListTypeOption(<CommandLineOptionOfListType>opt, args[i], errors);
|
|
|
|
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 {
|
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.Unknown_compiler_option_0, s));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2015-03-31 19:52:21 +02:00
|
|
|
/**
|
|
|
|
* Read tsconfig.json file
|
|
|
|
* @param fileName The path to the config file
|
|
|
|
*/
|
2016-11-16 21:25:24 +01:00
|
|
|
export function readConfigFile(fileName: string, readFile: (path: string) => string): { config?: any; error?: Diagnostic } {
|
2015-07-24 02:30:31 +02:00
|
|
|
let text = "";
|
2015-01-15 22:22:23 +01:00
|
|
|
try {
|
2015-08-28 01:52:49 +02:00
|
|
|
text = readFile(fileName);
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
|
|
|
catch (e) {
|
2016-11-16 21:25:24 +01:00
|
|
|
return { error: createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) };
|
2015-04-23 03:09:55 +02:00
|
|
|
}
|
2015-10-15 00:10:05 +02:00
|
|
|
return parseConfigFileTextToJson(fileName, text);
|
2015-04-23 03:09:55 +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-11 22:41:43 +01:00
|
|
|
const { node, errors } = parseJsonText(fileName, jsonText);
|
|
|
|
return {
|
|
|
|
config: convertToJson(node, errors),
|
2016-11-16 21:25:24 +01:00
|
|
|
error: errors.length ? errors[0] : undefined
|
2016-11-11 22:41:43 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-11-16 21:25:24 +01:00
|
|
|
/**
|
|
|
|
* Read tsconfig.json file
|
|
|
|
* @param fileName The path to the config file
|
|
|
|
*/
|
|
|
|
export function readConfigFileToJsonNode(fileName: string, readFile: (path: string) => string): ParsedNodeResults<JsonNode> {
|
|
|
|
let text = "";
|
|
|
|
try {
|
|
|
|
text = readFile(fileName);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
return { errors: [createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message)] };
|
|
|
|
}
|
|
|
|
return parseJsonText(fileName, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tsconfigRootOptions: CommandLineOption[] = [
|
|
|
|
{
|
|
|
|
name: "compilerOptions",
|
|
|
|
type: "object",
|
|
|
|
optionDeclarations: optionDeclarations,
|
|
|
|
extraKeyDiagnosticMessage: Diagnostics.Unknown_compiler_option_0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "typingOptions",
|
|
|
|
type: "object",
|
2016-11-23 21:20:55 +01:00
|
|
|
optionDeclarations: typeAcquisitionDeclarations,
|
|
|
|
extraKeyDiagnosticMessage: Diagnostics.Unknown_type_acquisition_option_0
|
2016-11-16 21:25:24 +01:00
|
|
|
},
|
2016-11-23 21:20:55 +01:00
|
|
|
{
|
|
|
|
name: "typeAcquisition",
|
|
|
|
type: "object",
|
|
|
|
optionDeclarations: typeAcquisitionDeclarations,
|
|
|
|
extraKeyDiagnosticMessage: Diagnostics.Unknown_type_acquisition_option_0
|
|
|
|
},
|
2016-11-16 21:25:24 +01:00
|
|
|
{
|
|
|
|
name: "extends",
|
|
|
|
type: "string"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "files",
|
|
|
|
type: "list",
|
|
|
|
element: {
|
|
|
|
name: "files",
|
|
|
|
type: "string"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "include",
|
|
|
|
type: "list",
|
|
|
|
element: {
|
|
|
|
name: "include",
|
|
|
|
type: "string"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "exclude",
|
|
|
|
type: "list",
|
|
|
|
element: {
|
|
|
|
name: "exclude",
|
|
|
|
type: "string"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
compileOnSaveCommandLineOption
|
|
|
|
];
|
|
|
|
|
|
|
|
function commandLineOptionsToMap(options: CommandLineOption[]) {
|
|
|
|
return arrayToMap(options, option => option.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
let _tsconfigRootOptionsMap: Map<CommandLineOption>;
|
|
|
|
function getTsconfigRootOptionsMap() {
|
|
|
|
if (_tsconfigRootOptionsMap === undefined) {
|
|
|
|
_tsconfigRootOptionsMap = commandLineOptionsToMap(tsconfigRootOptions);
|
|
|
|
}
|
|
|
|
return _tsconfigRootOptionsMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface JsonConversionNotifier {
|
|
|
|
/** Notifies options object is being set with the optionKey and optionValue is being set */
|
|
|
|
onSetOptionKeyValue(optionsObject: string, option: CommandLineOption, value: CompilerOptionsValue): void;
|
|
|
|
/** Notify when root key value is being set */
|
|
|
|
onRootKeyValue(key: string, propertyName: PropertyName, value: CompilerOptionsValue, node: Expression): void;
|
|
|
|
}
|
|
|
|
|
2016-11-11 22:41:43 +01:00
|
|
|
/**
|
|
|
|
* Convert the json syntax tree into the json value
|
|
|
|
* @param jsonNode
|
|
|
|
* @param errors
|
|
|
|
*/
|
2016-11-16 21:25:24 +01:00
|
|
|
export function convertToJson(jsonNode: JsonNode, errors: Diagnostic[]): any {
|
|
|
|
return convertToJsonWorker(jsonNode, errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert the json syntax tree into the json value
|
|
|
|
* @param jsonNode
|
|
|
|
* @param errors
|
|
|
|
*/
|
|
|
|
function convertToJsonWorker(jsonNode: JsonNode, errors: Diagnostic[], knownRootOptions?: Map<CommandLineOption>, optionsIterator?: JsonConversionNotifier): any {
|
2016-11-11 22:41:43 +01:00
|
|
|
if (!jsonNode) {
|
|
|
|
return undefined;
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
2016-11-11 22:41:43 +01:00
|
|
|
|
|
|
|
if (jsonNode.kind === SyntaxKind.EndOfFileToken) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const sourceFile = <SourceFile>jsonNode.parent;
|
2016-11-16 21:25:24 +01:00
|
|
|
return convertObjectLiteralExpressionToJson(jsonNode, knownRootOptions);
|
2016-11-11 22:41:43 +01:00
|
|
|
|
2016-11-16 21:25:24 +01:00
|
|
|
function convertObjectLiteralExpressionToJson(node: ObjectLiteralExpression, options?: Map<CommandLineOption>, extraKeyDiagnosticMessage?: DiagnosticMessage, optionsObject?: string): any {
|
2016-11-11 22:41:43 +01:00
|
|
|
const result: any = {};
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
const keyText = getTextOfPropertyName(element.name);
|
|
|
|
const option = options ? options[keyText] : undefined;
|
|
|
|
if (extraKeyDiagnosticMessage && !option) {
|
|
|
|
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, element.name, extraKeyDiagnosticMessage, keyText));
|
|
|
|
}
|
|
|
|
const value = parseValue(element.initializer, option);
|
|
|
|
if (typeof keyText !== undefined && typeof value !== undefined) {
|
|
|
|
result[keyText] = value;
|
|
|
|
// Notify key value set, if user asked for it
|
|
|
|
if (optionsIterator &&
|
|
|
|
(optionsObject || options === knownRootOptions)) {
|
|
|
|
const isValidOptionValue = isCompilerOptionsValue(option, value);
|
|
|
|
if (optionsObject && isValidOptionValue) {
|
|
|
|
optionsIterator.onSetOptionKeyValue(optionsObject, option, value);
|
2016-11-11 22:41:43 +01:00
|
|
|
}
|
2016-11-16 21:25:24 +01:00
|
|
|
if (options === knownRootOptions && (isValidOptionValue || !option)) {
|
|
|
|
optionsIterator.onRootKeyValue(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;
|
|
|
|
}
|
|
|
|
|
2016-11-16 21:25:24 +01:00
|
|
|
function convertArrayLiteralExpressionToJson(elements: NodeArray<Expression>, option?: CommandLineOption): any[] {
|
2016-11-11 22:41:43 +01:00
|
|
|
const result: any[] = [];
|
2016-11-16 21:25:24 +01:00
|
|
|
for (const element of elements) {
|
|
|
|
result.push(parseValue(element, option));
|
2016-11-11 22:41:43 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-16 21:25:24 +01:00
|
|
|
function parseValue(node: Expression, option: CommandLineOption): any {
|
2016-11-11 22:41:43 +01:00
|
|
|
switch (node.kind) {
|
|
|
|
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:
|
2016-11-16 21:25:24 +01:00
|
|
|
reportInvalidOptionValue(!!option);
|
2016-11-11 22:41:43 +01:00
|
|
|
return null; // tslint:disable-line:no-null-keyword
|
|
|
|
|
|
|
|
case SyntaxKind.StringLiteral:
|
|
|
|
if (!isDoubleQuotedString(node)) {
|
|
|
|
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, node, Diagnostics.String_literal_with_double_quotes_expected));
|
|
|
|
}
|
2016-11-16 21:25:24 +01:00
|
|
|
reportInvalidOptionValue(option && (typeof option.type === "string" && option.type !== "string"));
|
|
|
|
const text = (<StringLiteral>node).text;
|
|
|
|
if (option && typeof option.type !== "string") {
|
|
|
|
const customOption = <CommandLineOptionOfCustomType>option;
|
|
|
|
// Validate custom option type
|
|
|
|
if (!(text in customOption.type)) {
|
|
|
|
errors.push(
|
|
|
|
createDiagnosticForInvalidCustomType(
|
|
|
|
customOption,
|
|
|
|
(message, arg0, arg1) => createDiagnosticForNodeInSourceFile(sourceFile, node, message, arg0, arg1)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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");
|
2016-11-11 22:41:43 +01:00
|
|
|
return Number((<NumericLiteral>node).text);
|
|
|
|
|
|
|
|
case SyntaxKind.ObjectLiteralExpression:
|
2016-11-16 21:25:24 +01:00
|
|
|
reportInvalidOptionValue(option && option.type !== "object");
|
|
|
|
const objectOption = <TsConfigOnlyOption>option;
|
|
|
|
const optionDeclarations = option && objectOption.optionDeclarations ? commandLineOptionsToMap(objectOption.optionDeclarations) : undefined;
|
|
|
|
return convertObjectLiteralExpressionToJson(
|
|
|
|
<ObjectLiteralExpression>node,
|
|
|
|
optionDeclarations,
|
|
|
|
option && objectOption.extraKeyDiagnosticMessage,
|
|
|
|
optionDeclarations && option.name
|
|
|
|
);
|
2016-11-11 22:41:43 +01:00
|
|
|
|
|
|
|
case SyntaxKind.ArrayLiteralExpression:
|
2016-11-16 21:25:24 +01:00
|
|
|
reportInvalidOptionValue(option && option.type !== "list");
|
|
|
|
return convertArrayLiteralExpressionToJson((<ArrayLiteralExpression>node).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) {
|
|
|
|
reportInvalidOptionValue(!!option);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, node, Diagnostics.String_number_object_array_true_false_or_null_expected));
|
|
|
|
}
|
|
|
|
|
2016-11-11 22:41:43 +01:00
|
|
|
return undefined;
|
2016-11-16 21:25:24 +01:00
|
|
|
|
|
|
|
function reportInvalidOptionValue(isError: boolean) {
|
|
|
|
if (isError) {
|
|
|
|
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, node, Diagnostics.Compiler_option_0_requires_a_value_of_type_1, option.name, getCompilerOptionValueTypeString(option)));
|
|
|
|
}
|
|
|
|
}
|
2016-11-11 22:41:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function isDoubleQuotedString(node: Node) {
|
|
|
|
return node.kind === SyntaxKind.StringLiteral && getSourceTextOfNodeFromSourceFile(sourceFile, node).charCodeAt(0) === CharacterCodes.doubleQuote;
|
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" :
|
|
|
|
typeof option.type === "string" ? option.type : "string";
|
|
|
|
}
|
|
|
|
|
|
|
|
function isCompilerOptionsValue(option: CommandLineOption, value: any): value is CompilerOptionsValue {
|
|
|
|
if (option) {
|
|
|
|
if (option.type === "list") {
|
|
|
|
return isArray(value);
|
|
|
|
}
|
|
|
|
const expectedType = typeof option.type === "string" ? option.type : "string";
|
|
|
|
return typeof value === expectedType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-18 00:23:28 +02:00
|
|
|
/**
|
|
|
|
* 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: string[]): { compilerOptions: Map<CompilerOptionsValue> } {
|
|
|
|
const compilerOptions = extend(options, defaultInitCompilerOptions);
|
|
|
|
const configurations: any = {
|
|
|
|
compilerOptions: serializeCompilerOptions(compilerOptions)
|
|
|
|
};
|
|
|
|
if (fileNames && fileNames.length) {
|
|
|
|
// only set the files property if we have at least one file
|
|
|
|
configurations.files = fileNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
return configurations;
|
|
|
|
|
|
|
|
function getCustomTypeMapOfCommandLineOption(optionDefinition: CommandLineOption): Map<string | number> | undefined {
|
|
|
|
if (optionDefinition.type === "string" || optionDefinition.type === "number" || optionDefinition.type === "boolean") {
|
|
|
|
// this is of a type CommandLineOptionOfPrimitiveType
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
else if (optionDefinition.type === "list") {
|
|
|
|
return getCustomTypeMapOfCommandLineOption((<CommandLineOptionOfListType>optionDefinition).element);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (<CommandLineOptionOfCustomType>optionDefinition).type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNameOfCompilerOptionValue(value: CompilerOptionsValue, customTypeMap: MapLike<string | number>): string | undefined {
|
|
|
|
// There is a typeMap associated with this command-line option so use it to map value back to its name
|
|
|
|
for (const key in customTypeMap) {
|
|
|
|
if (customTypeMap[key] === value) {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
function serializeCompilerOptions(options: CompilerOptions): Map<CompilerOptionsValue> {
|
|
|
|
const result = createMap<CompilerOptionsValue>();
|
|
|
|
const optionsNameMap = getOptionNameMap().optionNameMap;
|
|
|
|
|
|
|
|
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
|
|
|
|
switch (name) {
|
|
|
|
case "init":
|
|
|
|
case "watch":
|
|
|
|
case "version":
|
|
|
|
case "help":
|
|
|
|
case "project":
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
const value = options[name];
|
|
|
|
let optionDefinition = optionsNameMap[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
|
|
|
|
result[name] = value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (optionDefinition.type === "list") {
|
|
|
|
const convertedValue: string[] = [];
|
|
|
|
for (const element of value as (string | number)[]) {
|
|
|
|
convertedValue.push(getNameOfCompilerOptionValue(element, customTypeMap));
|
|
|
|
}
|
|
|
|
result[name] = convertedValue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// There is a typeMap associated with this command-line option so use it to map value back to its name
|
|
|
|
result[name] = getNameOfCompilerOptionValue(value, customTypeMap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-31 19:52:21 +02:00
|
|
|
/**
|
|
|
|
* Parse the contents of a config file (tsconfig.json).
|
|
|
|
* @param json The contents of the config file to parse
|
2015-10-17 23:35:28 +02:00
|
|
|
* @param host Instance of ParseConfigHost used to enumerate files in folder.
|
2015-03-31 19:52:21 +02:00
|
|
|
* @param basePath A root directory to resolve relative path entries in the config
|
2015-07-09 00:35:49 +02:00
|
|
|
* file to. e.g. outDir
|
2015-03-31 19:52:21 +02:00
|
|
|
*/
|
2016-11-16 21:25:24 +01:00
|
|
|
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[]): ParsedCommandLine {
|
|
|
|
return parseJsonConfigFileContentWorker(json, /*jsonNode*/ undefined, host, basePath, existingOptions, configFileName, resolutionStack);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
export function parseJsonNodeConfigFileContent(jsonNode: JsonNode, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[]): ParsedCommandLine {
|
|
|
|
return parseJsonConfigFileContentWorker(/*json*/ undefined, jsonNode, host, basePath, existingOptions, configFileName, resolutionStack);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
function parseJsonConfigFileContentWorker(json: any, jsonNode: JsonNode, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}, configFileName?: string, resolutionStack: Path[] = []): ParsedCommandLine {
|
|
|
|
Debug.assert((json === undefined && jsonNode !== undefined) || (json !== undefined && jsonNode === undefined));
|
2016-03-10 20:14:29 +01:00
|
|
|
const errors: Diagnostic[] = [];
|
2016-07-25 23:48:41 +02:00
|
|
|
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);
|
|
|
|
const resolvedPath = toPath(configFileName || "", basePath, getCanonicalFileName);
|
|
|
|
if (resolutionStack.indexOf(resolvedPath) >= 0) {
|
|
|
|
return {
|
|
|
|
options: {},
|
|
|
|
fileNames: [],
|
2016-11-19 02:46:06 +01:00
|
|
|
typeAcquisition: {},
|
2016-11-16 21:25:24 +01:00
|
|
|
raw: json || convertToJson(jsonNode, errors),
|
|
|
|
errors: errors.concat(createCompilerDiagnostic(Diagnostics.Circularity_detected_while_resolving_configuration_Colon_0, [...resolutionStack, resolvedPath].join(" -> "))),
|
2016-07-25 23:48:41 +02:00
|
|
|
wildcardDirectories: {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-11-16 21:25:24 +01:00
|
|
|
let options: CompilerOptions;
|
2016-11-23 21:20:55 +01:00
|
|
|
let typeAcquisition: TypeAcquisition;
|
2016-11-16 21:25:24 +01:00
|
|
|
let compileOnSave: boolean;
|
|
|
|
let hasExtendsError: boolean, extendedConfigPath: Path;
|
|
|
|
if (json) {
|
|
|
|
options = convertCompilerOptionsFromJsonWorker(json["compilerOptions"], basePath, errors, configFileName);
|
2016-11-23 21:20:55 +01:00
|
|
|
// typingOptions has been deprecated and is only supported for backward compatibility purposes.
|
|
|
|
// It should be removed in future releases - use typeAcquisition instead.
|
|
|
|
const jsonOptions = json["typeAcquisition"] || json["typingOptions"];
|
|
|
|
typeAcquisition = convertTypeAcquisitionFromJsonWorker(jsonOptions, basePath, errors, configFileName);
|
2016-11-16 21:25:24 +01:00
|
|
|
compileOnSave = convertCompileOnSaveOptionFromJson(json, basePath, errors);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
options = getDefaultCompilerOptions(configFileName);
|
2016-11-23 21:20:55 +01:00
|
|
|
let typingOptionstypeAcquisition: TypeAcquisition;
|
2016-11-16 21:25:24 +01:00
|
|
|
const optionsIterator: JsonConversionNotifier = {
|
|
|
|
onSetOptionKeyValue(optionsObject: string, option: CommandLineOption, value: CompilerOptionsValue) {
|
2016-11-23 21:20:55 +01:00
|
|
|
Debug.assert(optionsObject === "compilerOptions" || optionsObject === "typeAcquisition" || optionsObject === "typingOptions");
|
|
|
|
const currentOption = optionsObject === "compilerOptions" ? options :
|
|
|
|
optionsObject === "typeAcquisition" ? (typeAcquisition || (typeAcquisition = getDefaultTypeAcquisition(configFileName)) ) :
|
|
|
|
(typingOptionstypeAcquisition || (typingOptionstypeAcquisition = getDefaultTypeAcquisition(configFileName)));
|
|
|
|
|
2016-11-16 21:25:24 +01:00
|
|
|
currentOption[option.name] = normalizeOptionValue(option, basePath, value);
|
|
|
|
},
|
|
|
|
onRootKeyValue(key: string, propertyName: PropertyName, value: CompilerOptionsValue, node: Expression) {
|
|
|
|
switch (key) {
|
|
|
|
case "extends":
|
|
|
|
const extendsDiagnostic = getExtendsConfigPath(<string>value, (message, arg0) =>
|
|
|
|
createDiagnosticForNodeInSourceFile(<SourceFile>jsonNode.parent, node, message, arg0));
|
|
|
|
if ((<Diagnostic>extendsDiagnostic).messageText) {
|
|
|
|
errors.push(<Diagnostic>extendsDiagnostic);
|
|
|
|
hasExtendsError = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
extendedConfigPath = <Path>extendsDiagnostic;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case "excludes":
|
|
|
|
errors.push(createDiagnosticForNodeInSourceFile(<SourceFile>jsonNode.parent, propertyName, Diagnostics.Unknown_option_excludes_Did_you_mean_exclude));
|
|
|
|
return;
|
|
|
|
case "files":
|
|
|
|
if ((<string[]>value).length === 0) {
|
|
|
|
errors.push(createDiagnosticForNodeInSourceFile(<SourceFile>jsonNode.parent, node, Diagnostics.The_files_list_in_config_file_0_is_empty, configFileName || "tsconfig.json"));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case "compileOnSave":
|
|
|
|
compileOnSave = <boolean>value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
json = convertToJsonWorker(jsonNode, errors, getTsconfigRootOptionsMap(), optionsIterator);
|
2016-11-23 21:20:55 +01:00
|
|
|
if (!typeAcquisition) {
|
|
|
|
if (typingOptionstypeAcquisition) {
|
|
|
|
typeAcquisition = (typingOptionstypeAcquisition.enableAutoDiscovery !== undefined) ?
|
|
|
|
{
|
|
|
|
enable: typingOptionstypeAcquisition.enableAutoDiscovery,
|
|
|
|
include: typingOptionstypeAcquisition.include,
|
|
|
|
exclude: typingOptionstypeAcquisition.exclude
|
|
|
|
} :
|
|
|
|
typingOptionstypeAcquisition;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
typeAcquisition = getDefaultTypeAcquisition(configFileName);
|
|
|
|
}
|
|
|
|
}
|
2016-11-16 21:25:24 +01:00
|
|
|
}
|
2016-05-04 23:50:58 +02:00
|
|
|
|
2016-07-25 23:48:41 +02:00
|
|
|
if (json["extends"]) {
|
|
|
|
let [include, exclude, files, baseOptions]: [string[], string[], string[], CompilerOptions] = [undefined, undefined, undefined, {}];
|
2016-11-16 21:25:24 +01:00
|
|
|
if (!hasExtendsError && typeof json["extends"] === "string") {
|
|
|
|
[include, exclude, files, baseOptions] = (tryExtendsName(json["extends"], extendedConfigPath) || [include, exclude, files, baseOptions]);
|
2016-07-25 23:48:41 +02:00
|
|
|
}
|
|
|
|
else {
|
2016-11-16 21:25:24 +01:00
|
|
|
createCompilerDiagnosticForJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "extends", "string");
|
2016-07-25 23:48:41 +02:00
|
|
|
}
|
|
|
|
if (include && !json["include"]) {
|
|
|
|
json["include"] = include;
|
|
|
|
}
|
|
|
|
if (exclude && !json["exclude"]) {
|
|
|
|
json["exclude"] = exclude;
|
|
|
|
}
|
|
|
|
if (files && !json["files"]) {
|
|
|
|
json["files"] = files;
|
|
|
|
}
|
|
|
|
options = assign({}, baseOptions, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
options = extend(existingOptions, options);
|
2016-03-23 19:41:34 +01:00
|
|
|
options.configFilePath = configFileName;
|
2016-03-16 00:30:11 +01:00
|
|
|
|
2016-05-26 02:06:50 +02:00
|
|
|
const { fileNames, wildcardDirectories } = getFileNames(errors);
|
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,
|
2016-11-19 02:46:06 +01:00
|
|
|
typeAcquisition,
|
2016-05-06 19:12:12 +02:00
|
|
|
raw: json,
|
2015-12-07 23:58:13 +01:00
|
|
|
errors,
|
2016-08-24 01:11:52 +02:00
|
|
|
wildcardDirectories,
|
|
|
|
compileOnSave
|
2015-01-15 22:22:23 +01:00
|
|
|
};
|
|
|
|
|
2016-11-16 21:25:24 +01:00
|
|
|
function getExtendsConfigPath<T>(extendedConfig: string, createDiagnostic: (message: DiagnosticMessage, arg1?: string) => T): T | Path {
|
2016-07-25 23:48:41 +02:00
|
|
|
// If the path isn't a rooted or relative path, don't try to resolve it (we reserve the right to special case module-id like paths in the future)
|
|
|
|
if (!(isRootedDiskPath(extendedConfig) || startsWith(normalizeSlashes(extendedConfig), "./") || startsWith(normalizeSlashes(extendedConfig), "../"))) {
|
2016-11-16 21:25:24 +01:00
|
|
|
return createDiagnostic(Diagnostics.A_path_in_an_extends_option_must_be_relative_or_rooted_but_0_is_not, extendedConfig);
|
2016-07-25 23:48:41 +02:00
|
|
|
}
|
|
|
|
let extendedConfigPath = toPath(extendedConfig, basePath, getCanonicalFileName);
|
|
|
|
if (!host.fileExists(extendedConfigPath) && !endsWith(extendedConfigPath, ".json")) {
|
|
|
|
extendedConfigPath = `${extendedConfigPath}.json` as Path;
|
|
|
|
if (!host.fileExists(extendedConfigPath)) {
|
2016-11-16 21:25:24 +01:00
|
|
|
return createDiagnostic(Diagnostics.File_0_does_not_exist, extendedConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return extendedConfigPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
function tryExtendsName(extendedConfig: string, extendedConfigPath?: Path): [string[], string[], string[], CompilerOptions] {
|
|
|
|
if (!extendedConfigPath) {
|
|
|
|
const result = getExtendsConfigPath(extendedConfig, (message, arg1) => (createCompilerDiagnosticForJson(message, arg1), true));
|
|
|
|
if (result === true) {
|
2016-07-25 23:48:41 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-11-16 21:25:24 +01:00
|
|
|
extendedConfigPath = <Path>result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!host.fileExists(extendedConfigPath) && !endsWith(extendedConfigPath, ".json")) {
|
|
|
|
extendedConfigPath = `${extendedConfigPath}.json` as Path;
|
2016-07-25 23:48:41 +02:00
|
|
|
}
|
2016-11-16 21:25:24 +01:00
|
|
|
|
|
|
|
const extendedResult = readConfigFileToJsonNode(extendedConfigPath, path => host.readFile(path));
|
2016-11-11 22:41:43 +01:00
|
|
|
if (extendedResult.errors.length) {
|
|
|
|
errors.push(...extendedResult.errors);
|
2016-07-25 23:48:41 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const extendedDirname = getDirectoryPath(extendedConfigPath);
|
|
|
|
const relativeDifference = convertToRelativePath(extendedDirname, basePath, getCanonicalFileName);
|
|
|
|
const updatePath: (path: string) => string = path => isRootedDiskPath(path) ? path : combinePaths(relativeDifference, path);
|
|
|
|
// Merge configs (copy the resolution stack so it is never reused between branches in potential diamond-problem scenarios)
|
2016-11-16 21:25:24 +01:00
|
|
|
const result = parseJsonNodeConfigFileContent(extendedResult.node, host, extendedDirname, /*existingOptions*/undefined, getBaseFileName(extendedConfigPath), resolutionStack.concat([resolvedPath]));
|
2016-07-25 23:48:41 +02:00
|
|
|
errors.push(...result.errors);
|
|
|
|
const [include, exclude, files] = map(["include", "exclude", "files"], key => {
|
2016-11-16 21:25:24 +01:00
|
|
|
if (!json[key] && result.raw[key]) {
|
|
|
|
return map(result.raw[key], updatePath);
|
2016-07-25 23:48:41 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return [include, exclude, files, result.options];
|
|
|
|
}
|
|
|
|
|
2016-05-26 02:06:50 +02:00
|
|
|
function getFileNames(errors: Diagnostic[]): ExpandResult {
|
2015-12-03 19:44:24 +01:00
|
|
|
let fileNames: string[];
|
2015-01-16 02:12:45 +01:00
|
|
|
if (hasProperty(json, "files")) {
|
2015-12-03 19:44:24 +01:00
|
|
|
if (isArray(json["files"])) {
|
|
|
|
fileNames = <string[]>json["files"];
|
2016-10-24 20:00:32 +02:00
|
|
|
if (fileNames.length === 0) {
|
2016-11-16 21:25:24 +01:00
|
|
|
createCompilerDiagnosticForJson(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 {
|
2016-11-16 21:25:24 +01:00
|
|
|
createCompilerDiagnosticForJson(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
|
|
|
|
2015-12-03 19:44:24 +01:00
|
|
|
let includeSpecs: string[];
|
|
|
|
if (hasProperty(json, "include")) {
|
|
|
|
if (isArray(json["include"])) {
|
|
|
|
includeSpecs = <string[]>json["include"];
|
|
|
|
}
|
|
|
|
else {
|
2016-11-16 21:25:24 +01:00
|
|
|
createCompilerDiagnosticForJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "include", "Array");
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let excludeSpecs: string[];
|
|
|
|
if (hasProperty(json, "exclude")) {
|
|
|
|
if (isArray(json["exclude"])) {
|
|
|
|
excludeSpecs = <string[]>json["exclude"];
|
|
|
|
}
|
|
|
|
else {
|
2016-11-16 21:25:24 +01:00
|
|
|
createCompilerDiagnosticForJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "exclude", "Array");
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
2016-05-26 02:08:24 +02:00
|
|
|
else if (hasProperty(json, "excludes")) {
|
2016-11-16 21:25:24 +01:00
|
|
|
createCompilerDiagnosticForJson(Diagnostics.Unknown_option_excludes_Did_you_mean_exclude);
|
2016-05-26 02:08:24 +02:00
|
|
|
}
|
2016-05-26 02:07:36 +02:00
|
|
|
else {
|
2016-11-18 15:55:03 +01:00
|
|
|
// If no includes were specified, exclude common package folders and the outDir
|
|
|
|
excludeSpecs = includeSpecs ? [] : ["node_modules", "bower_components", "jspm_packages"];
|
2016-05-26 02:07:36 +02:00
|
|
|
|
2016-09-01 21:57:23 +02:00
|
|
|
const outDir = json["compilerOptions"] && json["compilerOptions"]["outDir"];
|
|
|
|
if (outDir) {
|
|
|
|
excludeSpecs.push(outDir);
|
|
|
|
}
|
2016-05-26 02:07:36 +02:00
|
|
|
}
|
2015-11-12 22:23:53 +01:00
|
|
|
|
2015-12-03 19:44:24 +01:00
|
|
|
if (fileNames === 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
|
|
|
|
2016-11-16 21:25:24 +01:00
|
|
|
const result = matchFileNames(fileNames, includeSpecs, excludeSpecs, basePath, options, host, errors, jsonNode);
|
2016-10-24 20:00:32 +02:00
|
|
|
|
|
|
|
if (result.fileNames.length === 0 && !hasProperty(json, "files") && resolutionStack.length === 0) {
|
|
|
|
errors.push(
|
|
|
|
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 || [])));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
2016-11-16 21:25:24 +01:00
|
|
|
|
|
|
|
function createCompilerDiagnosticForJson(message: DiagnosticMessage, arg0?: string, arg1?: string) {
|
|
|
|
if (!jsonNode) {
|
|
|
|
errors.push(createCompilerDiagnostic(message, arg0, arg1));
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
2015-10-17 23:35:28 +02:00
|
|
|
|
2016-08-24 01:11:52 +02:00
|
|
|
export function convertCompileOnSaveOptionFromJson(jsonOption: any, basePath: string, errors: Diagnostic[]): boolean {
|
|
|
|
if (!hasProperty(jsonOption, compileOnSaveCommandLineOption.name)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const result = convertJsonOption(compileOnSaveCommandLineOption, jsonOption["compileOnSave"], basePath, errors);
|
|
|
|
if (typeof result === "boolean" && result) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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) {
|
2016-09-22 23:55:58 +02:00
|
|
|
const options: CompilerOptions = getBaseFileName(configFileName) === "jsconfig.json"
|
2016-10-12 04:19:40 +02:00
|
|
|
? { allowJs: true, maxNodeModuleJsDepth: 2, allowSyntheticDefaultImports: true, skipLibCheck: true }
|
2016-09-22 23:55:58 +02:00
|
|
|
: {};
|
2016-11-16 21:25:24 +01:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertCompilerOptionsFromJsonWorker(jsonOptions: any,
|
|
|
|
basePath: string, errors: Diagnostic[], configFileName?: string): CompilerOptions {
|
|
|
|
|
|
|
|
const options = getDefaultCompilerOptions(configFileName);
|
2016-03-20 04:59:32 +01:00
|
|
|
convertOptionsFromJson(optionDeclarations, jsonOptions, basePath, options, Diagnostics.Unknown_compiler_option_0, errors);
|
2016-03-16 00:30:11 +01:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2016-11-23 21:20:55 +01:00
|
|
|
function getDefaultTypeAcquisition(configFileName?: string) {
|
|
|
|
const options: TypeAcquisition = { enable: getBaseFileName(configFileName) === "jsconfig.json", include: [], exclude: [] };
|
2016-11-16 21:25:24 +01:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2016-11-19 02:46:06 +01:00
|
|
|
function convertTypeAcquisitionFromJsonWorker(jsonOptions: any,
|
|
|
|
basePath: string, errors: 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;
|
|
|
|
}
|
|
|
|
|
2016-03-20 04:59:32 +01:00
|
|
|
function convertOptionsFromJson(optionDeclarations: CommandLineOption[], jsonOptions: any, basePath: string,
|
2016-11-19 02:46:06 +01:00
|
|
|
defaultOptions: CompilerOptions | TypeAcquisition, diagnosticMessage: DiagnosticMessage, errors: 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-08-15 21:03:39 +02:00
|
|
|
if (id in optionNameMap) {
|
2015-11-04 23:02:33 +01:00
|
|
|
const opt = optionNameMap[id];
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-17 00:35:51 +01:00
|
|
|
function convertJsonOption(opt: CommandLineOption, value: any, basePath: string, errors: 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
|
|
|
}
|
2016-11-16 21:25:24 +01:00
|
|
|
else if (typeof optType !== "string") {
|
|
|
|
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 {
|
|
|
|
if (option.type === "list") {
|
|
|
|
const listOption = <CommandLineOptionOfListType>option;
|
|
|
|
if (listOption.element.isFilePath || typeof listOption.element.type !== "string") {
|
|
|
|
return <CompilerOptionsValue>filter(map(value, v => normalizeOptionValue(listOption.element, basePath, v)), v => !!v);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
else if (typeof option.type !== "string") {
|
|
|
|
return option.type[value];
|
|
|
|
}
|
|
|
|
return normalizeNonListOptionValue(option, basePath, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
function normalizeNonListOptionValue(option: CommandLineOption, basePath: string, value: any): CompilerOptionsValue {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
function convertJsonOptionOfCustomType(opt: CommandLineOptionOfCustomType, value: string, errors: Diagnostic[]) {
|
|
|
|
const key = value.toLowerCase();
|
2016-08-16 01:41:32 +02:00
|
|
|
if (key in opt.type) {
|
2016-03-10 20:14:29 +01:00
|
|
|
return opt.type[key];
|
|
|
|
}
|
|
|
|
else {
|
2016-03-16 21:49:36 +01:00
|
|
|
errors.push(createCompilerDiagnosticForInvalidCustomType(opt));
|
2016-03-10 20:14:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertJsonOptionOfListType(option: CommandLineOptionOfListType, values: any[], basePath: string, errors: 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
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for a path with multiple recursive directory wildcards.
|
2016-01-04 20:37:25 +01:00
|
|
|
* Matches **\** and **\a\**, 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 a recursive directory wildcard "**" followed by a directory separator.
|
|
|
|
* (.*\/)? # optionally matches any number of characters followed by a directory separator.
|
|
|
|
* \*\* # matches a recursive directory wildcard "**"
|
|
|
|
* ($|\/) # matches either the end of the string or a directory separator.
|
|
|
|
*/
|
2015-12-15 00:21:12 +01:00
|
|
|
const invalidMultipleRecursionPatterns = /(^|\/)\*\*\/(.*\/)?\*\*($|\/)/;
|
2015-12-07 23:58:13 +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.
|
|
|
|
*
|
|
|
|
* @param fileNames The literal file names to include.
|
2015-12-16 22:42:17 +01:00
|
|
|
* @param include The wildcard file specifications to include.
|
|
|
|
* @param exclude 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.
|
|
|
|
*/
|
2016-11-16 21:25:24 +01:00
|
|
|
function matchFileNames(fileNames: string[], include: string[], exclude: string[], basePath: string, options: CompilerOptions, host: ParseConfigHost, errors: Diagnostic[], jsonNode: JsonNode): ExpandResult {
|
2015-12-03 19:44:24 +01:00
|
|
|
basePath = normalizePath(basePath);
|
|
|
|
|
2015-12-07 23:58:13 +01: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.
|
|
|
|
const keyMapper = host.useCaseSensitiveFileNames ? caseSensitiveKeyMapper : caseInsensitiveKeyMapper;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2015-12-16 22:42:17 +01:00
|
|
|
if (include) {
|
2016-11-16 21:25:24 +01:00
|
|
|
include = validateSpecs(include, errors, /*allowTrailingRecursion*/ false, jsonNode, "include");
|
2015-12-16 22:42:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (exclude) {
|
2016-11-16 21:25:24 +01:00
|
|
|
exclude = validateSpecs(exclude, errors, /*allowTrailingRecursion*/ true, jsonNode, "exclude");
|
2015-12-16 22:42:17 +01:00
|
|
|
}
|
|
|
|
|
2015-12-07 23:58:13 +01:00
|
|
|
// 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.
|
2015-12-16 22:42:17 +01:00
|
|
|
const wildcardDirectories: Map<WatchDirectoryFlags> = getWildcardDirectories(include, exclude, basePath, host.useCaseSensitiveFileNames);
|
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.
|
|
|
|
const supportedExtensions = getSupportedExtensions(options);
|
|
|
|
|
|
|
|
// Literal files are always included verbatim. An "include" or "exclude" specification cannot
|
|
|
|
// remove a literal file.
|
2015-12-03 19:44:24 +01:00
|
|
|
if (fileNames) {
|
|
|
|
for (const fileName of fileNames) {
|
2015-12-15 00:21:12 +01:00
|
|
|
const file = combinePaths(basePath, fileName);
|
|
|
|
literalFileMap[keyMapper(file)] = file;
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-16 22:42:17 +01:00
|
|
|
if (include && include.length > 0) {
|
|
|
|
for (const file of host.readDirectory(basePath, supportedExtensions, exclude, include)) {
|
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-08-15 21:03:39 +02:00
|
|
|
if (!(key in literalFileMap) && !(key in wildcardFileMap)) {
|
2015-12-15 00:21:12 +01:00
|
|
|
wildcardFileMap[key] = file;
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-07 23:58:13 +01:00
|
|
|
|
2016-08-16 20:15:15 +02:00
|
|
|
const literalFiles = reduceProperties(literalFileMap, addFileToOutput, []);
|
|
|
|
const wildcardFiles = reduceProperties(wildcardFileMap, addFileToOutput, []);
|
2015-12-15 00:21:12 +01:00
|
|
|
wildcardFiles.sort(host.useCaseSensitiveFileNames ? compareStrings : compareStringsCaseInsensitive);
|
|
|
|
return {
|
|
|
|
fileNames: literalFiles.concat(wildcardFiles),
|
|
|
|
wildcardDirectories
|
|
|
|
};
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
|
|
|
|
2016-11-16 21:25:24 +01:00
|
|
|
function validateSpecs(specs: string[], errors: Diagnostic[], allowTrailingRecursion: boolean, jsonNode: JsonNode, specKey: string) {
|
2015-12-15 00:21:12 +01:00
|
|
|
const validSpecs: string[] = [];
|
|
|
|
for (const spec of specs) {
|
|
|
|
if (!allowTrailingRecursion && invalidTrailingRecursionPattern.test(spec)) {
|
2016-11-16 21:25:24 +01:00
|
|
|
errors.push(createDiagnostic(Diagnostics.File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0, spec));
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
2015-12-15 00:21:12 +01:00
|
|
|
else if (invalidMultipleRecursionPatterns.test(spec)) {
|
2016-11-16 21:25:24 +01:00
|
|
|
errors.push(createDiagnostic(Diagnostics.File_specification_cannot_contain_multiple_recursive_directory_wildcards_Asterisk_Asterisk_Colon_0, spec));
|
2015-12-07 23:58:13 +01:00
|
|
|
}
|
2016-07-01 18:59:07 +02:00
|
|
|
else if (invalidDotDotAfterRecursiveWildcardPattern.test(spec)) {
|
2016-11-16 21:25:24 +01:00
|
|
|
errors.push(createDiagnostic(Diagnostics.File_specification_cannot_contain_a_parent_directory_that_appears_after_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0, spec));
|
2016-07-01 18:59:07 +02:00
|
|
|
}
|
2015-12-15 00:21:12 +01:00
|
|
|
else {
|
|
|
|
validSpecs.push(spec);
|
2015-12-07 23:58:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-15 00:21:12 +01:00
|
|
|
return validSpecs;
|
2016-11-16 21:25:24 +01:00
|
|
|
|
|
|
|
function createDiagnostic(message: DiagnosticMessage, spec: string): Diagnostic {
|
|
|
|
if (jsonNode && jsonNode.kind === SyntaxKind.ObjectLiteralExpression) {
|
|
|
|
for (const property of jsonNode.properties) {
|
|
|
|
if (property.kind === SyntaxKind.PropertyAssignment && getTextOfPropertyName(property.name) === specKey) {
|
|
|
|
const specsNode = <ArrayLiteralExpression>property.initializer;
|
|
|
|
for (const element of specsNode.elements) {
|
|
|
|
if (element.kind === SyntaxKind.StringLiteral && (<StringLiteral>element).text === spec) {
|
|
|
|
return createDiagnosticForNodeInSourceFile(<SourceFile>jsonNode.parent, element, message, spec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return createCompilerDiagnostic(message, spec);
|
|
|
|
}
|
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
|
|
|
*/
|
2016-10-07 18:29:11 +02:00
|
|
|
function getWildcardDirectories(include: string[], exclude: string[], path: string, useCaseSensitiveFileNames: boolean): Map<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");
|
2016-08-11 01:47:06 +02:00
|
|
|
const wildcardDirectories = createMap<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.
|
|
|
|
for (const key in wildcardDirectories) {
|
2016-08-15 21:03:39 +02:00
|
|
|
for (const recursiveKey of recursiveKeys) {
|
|
|
|
if (key !== recursiveKey && containsPath(recursiveKey, key, path, !useCaseSensitiveFileNames)) {
|
|
|
|
delete wildcardDirectories[key];
|
2015-12-15 00:21:12 +01: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.
|
|
|
|
*/
|
2015-12-15 00:21:12 +01:00
|
|
|
function hasFileWithHigherPriorityExtension(file: string, literalFiles: Map<string>, wildcardFiles: Map<string>, extensions: string[], keyMapper: (value: string) => string) {
|
|
|
|
const extensionPriority = getExtensionPriority(file, extensions);
|
2015-12-07 23:58:13 +01:00
|
|
|
const adjustedExtensionPriority = adjustExtensionPriority(extensionPriority);
|
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-08-15 21:03:39 +02:00
|
|
|
if (higherPriorityPath in literalFiles || higherPriorityPath in wildcardFiles) {
|
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.
|
|
|
|
*/
|
2015-12-15 00:21:12 +01:00
|
|
|
function removeWildcardFilesWithLowerPriorityExtension(file: string, wildcardFiles: Map<string>, extensions: string[], keyMapper: (value: string) => string) {
|
|
|
|
const extensionPriority = getExtensionPriority(file, extensions);
|
2015-12-07 23:58:13 +01:00
|
|
|
const nextExtensionPriority = getNextLowestExtensionPriority(extensionPriority);
|
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));
|
|
|
|
delete wildcardFiles[lowerPriorityPath];
|
2015-12-03 19:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a file to an array of files.
|
|
|
|
*
|
|
|
|
* @param output The output array.
|
|
|
|
* @param file The file path.
|
|
|
|
*/
|
|
|
|
function addFileToOutput(output: string[], file: string) {
|
|
|
|
output.push(file);
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a case sensitive key.
|
|
|
|
*
|
|
|
|
* @param key The original key.
|
|
|
|
*/
|
|
|
|
function caseSensitiveKeyMapper(key: string) {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a case insensitive key.
|
|
|
|
*
|
|
|
|
* @param key The original key.
|
|
|
|
*/
|
|
|
|
function caseInsensitiveKeyMapper(key: string) {
|
|
|
|
return key.toLowerCase();
|
|
|
|
}
|
2015-09-10 20:16:16 +02:00
|
|
|
}
|