2014-07-13 01:04:16 +02:00
|
|
|
/// <reference path="sys.ts"/>
|
|
|
|
/// <reference path="types.ts"/>
|
|
|
|
/// <reference path="core.ts"/>
|
|
|
|
/// <reference path="scanner.ts"/>
|
|
|
|
|
2015-06-12 18:01:48 +02:00
|
|
|
namespace ts {
|
2015-03-31 19:52:21 +02:00
|
|
|
/* @internal */
|
2015-06-26 02:36:19 +02:00
|
|
|
export let optionDeclarations: CommandLineOption[] = [
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
|
|
|
name: "charset",
|
|
|
|
type: "string",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "declaration",
|
|
|
|
shortName: "d",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Generates_corresponding_d_ts_file,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "diagnostics",
|
|
|
|
type: "boolean",
|
|
|
|
},
|
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,
|
|
|
|
},
|
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",
|
|
|
|
type: {
|
|
|
|
"preserve": JsxEmit.Preserve,
|
|
|
|
"react": JsxEmit.React
|
|
|
|
},
|
|
|
|
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
|
|
|
error: Diagnostics.Argument_for_jsx_must_be_preserve_or_react
|
|
|
|
},
|
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,
|
2014-08-02 02:12:29 +02:00
|
|
|
description: Diagnostics.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations,
|
|
|
|
paramType: Diagnostics.LOCATION,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "module",
|
|
|
|
shortName: "m",
|
|
|
|
type: {
|
|
|
|
"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,
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
2015-04-24 05:50:35 +02:00
|
|
|
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_or_umd,
|
2014-08-02 02:12:29 +02:00
|
|
|
paramType: Diagnostics.KIND,
|
2015-04-24 05:50:35 +02:00
|
|
|
error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
2015-04-26 17:37:02 +02:00
|
|
|
{
|
|
|
|
name: "newLine",
|
2015-05-04 22:21:39 +02:00
|
|
|
type: {
|
|
|
|
"crlf": NewLineKind.CarriageReturnLineFeed,
|
|
|
|
"lf": NewLineKind.LineFeed
|
|
|
|
},
|
|
|
|
description: Diagnostics.Specifies_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,
|
2015-04-26 18:19:16 +02:00
|
|
|
error: Diagnostics.Argument_for_newLine_option_must_be_CRLF_or_LF
|
2015-04-26 17:37:02 +02:00
|
|
|
},
|
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
|
|
|
},
|
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
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "noLib",
|
|
|
|
type: "boolean",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "noResolve",
|
|
|
|
type: "boolean",
|
|
|
|
},
|
2015-06-04 22:56:33 +02:00
|
|
|
{
|
|
|
|
name: "skipDefaultLibCheck",
|
|
|
|
type: "boolean",
|
|
|
|
},
|
2014-08-02 02:12:29 +02:00
|
|
|
{
|
|
|
|
name: "out",
|
|
|
|
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-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,
|
|
|
|
description: Diagnostics.Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir,
|
|
|
|
paramType: Diagnostics.LOCATION,
|
|
|
|
},
|
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,
|
2014-08-02 02:12:29 +02:00
|
|
|
description: Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
|
|
|
|
paramType: Diagnostics.LOCATION,
|
|
|
|
},
|
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",
|
2014-10-26 02:26:24 +02:00
|
|
|
type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5, "es6": ScriptTarget.ES6 },
|
2014-10-11 21:52:42 +02:00
|
|
|
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental,
|
2014-08-02 02:12:29 +02:00
|
|
|
paramType: Diagnostics.VERSION,
|
2015-04-23 19:53:19 +02:00
|
|
|
error: Diagnostics.Argument_for_target_option_must_be_ES3_ES5_or_ES6
|
2014-08-02 02:12:29 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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-20 03:05:43 +02:00
|
|
|
{
|
|
|
|
name: "experimentalAsyncFunctions",
|
|
|
|
type: "boolean",
|
|
|
|
description: Diagnostics.Enables_experimental_support_for_ES7_async_functions
|
|
|
|
},
|
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
|
2014-12-12 02:47:29 +01:00
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
];
|
2015-03-31 19:52:21 +02:00
|
|
|
|
2014-07-13 01:04:16 +02:00
|
|
|
export function parseCommandLine(commandLine: string[]): ParsedCommandLine {
|
2015-06-26 02:36:19 +02:00
|
|
|
let options: CompilerOptions = {};
|
|
|
|
let fileNames: string[] = [];
|
|
|
|
let errors: Diagnostic[] = [];
|
|
|
|
let shortOptionNames: Map<string> = {};
|
|
|
|
let optionNameMap: Map<CommandLineOption> = {};
|
2014-07-13 01:04:16 +02:00
|
|
|
|
2015-01-15 22:22:23 +01:00
|
|
|
forEach(optionDeclarations, option => {
|
|
|
|
optionNameMap[option.name.toLowerCase()] = option;
|
|
|
|
if (option.shortName) {
|
|
|
|
shortOptionNames[option.shortName] = option.name;
|
|
|
|
}
|
|
|
|
});
|
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-06-26 02:36:19 +02:00
|
|
|
let s = args[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.
|
|
|
|
if (hasProperty(shortOptionNames, s)) {
|
|
|
|
s = shortOptionNames[s];
|
|
|
|
}
|
|
|
|
|
2014-08-02 02:12:29 +02:00
|
|
|
if (hasProperty(optionNameMap, s)) {
|
2015-06-26 02:36:19 +02:00
|
|
|
let opt = optionNameMap[s];
|
2014-07-13 01:04:16 +02:00
|
|
|
|
|
|
|
// 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++]);
|
|
|
|
break;
|
|
|
|
case "boolean":
|
|
|
|
options[opt.name] = true;
|
|
|
|
break;
|
|
|
|
case "string":
|
|
|
|
options[opt.name] = args[i++] || "";
|
|
|
|
break;
|
|
|
|
// If not a primitive, the possible types are specified in what is effectively a map of options.
|
|
|
|
default:
|
2015-06-26 02:36:19 +02:00
|
|
|
let map = <Map<number>>opt.type;
|
|
|
|
let key = (args[i++] || "").toLowerCase();
|
2014-10-28 19:40:54 +01:00
|
|
|
if (hasProperty(map, key)) {
|
|
|
|
options[opt.name] = map[key];
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
errors.push(createCompilerDiagnostic(opt.error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-06-26 02:36:19 +02:00
|
|
|
let text = 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-06-26 02:36:19 +02:00
|
|
|
let args: string[] = [];
|
|
|
|
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-06-26 02:36:19 +02:00
|
|
|
let 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
|
|
|
|
*/
|
2015-04-23 03:09:55 +02:00
|
|
|
export function readConfigFile(fileName: 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-06-26 03:23:28 +02:00
|
|
|
text = sys.readFile(fileName);
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
|
|
|
catch (e) {
|
2015-04-23 03:09:55 +02:00
|
|
|
return { error: createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) };
|
|
|
|
}
|
2015-04-23 22:36:54 +02:00
|
|
|
return parseConfigFileText(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
|
|
|
|
*/
|
|
|
|
export function parseConfigFileText(fileName: string, jsonText: string): { config?: any; error?: Diagnostic } {
|
|
|
|
try {
|
|
|
|
return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} };
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
|
|
|
catch (e) {
|
2015-04-23 03:00:09 +02:00
|
|
|
return { error: createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) };
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
* @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
|
|
|
*/
|
2015-04-23 00:58:04 +02:00
|
|
|
export function parseConfigFile(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine {
|
2015-06-26 02:36:19 +02:00
|
|
|
let errors: Diagnostic[] = [];
|
2015-01-15 22:22:23 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
options: getCompilerOptions(),
|
2015-05-16 20:38:28 +02:00
|
|
|
fileNames: getFileNames(),
|
2015-01-15 22:22:23 +01:00
|
|
|
errors
|
|
|
|
};
|
|
|
|
|
|
|
|
function getCompilerOptions(): CompilerOptions {
|
2015-06-26 02:36:19 +02:00
|
|
|
let options: CompilerOptions = {};
|
|
|
|
let optionNameMap: Map<CommandLineOption> = {};
|
2015-01-15 22:22:23 +01:00
|
|
|
forEach(optionDeclarations, option => {
|
|
|
|
optionNameMap[option.name] = option;
|
|
|
|
});
|
2015-06-26 02:36:19 +02:00
|
|
|
let jsonOptions = json["compilerOptions"];
|
2015-01-15 22:22:23 +01:00
|
|
|
if (jsonOptions) {
|
2015-06-26 02:36:19 +02:00
|
|
|
for (let id in jsonOptions) {
|
2015-01-15 22:22:23 +01:00
|
|
|
if (hasProperty(optionNameMap, id)) {
|
2015-06-26 02:36:19 +02:00
|
|
|
let opt = optionNameMap[id];
|
|
|
|
let optType = opt.type;
|
|
|
|
let value = jsonOptions[id];
|
|
|
|
let expectedType = typeof optType === "string" ? optType : "string";
|
2015-01-15 22:22:23 +01:00
|
|
|
if (typeof value === expectedType) {
|
|
|
|
if (typeof optType !== "string") {
|
2015-06-26 02:36:19 +02:00
|
|
|
let key = value.toLowerCase();
|
2015-01-15 22:22:23 +01:00
|
|
|
if (hasProperty(optType, key)) {
|
|
|
|
value = optType[key];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
errors.push(createCompilerDiagnostic(opt.error));
|
|
|
|
value = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (opt.isFilePath) {
|
|
|
|
value = normalizePath(combinePaths(basePath, value));
|
|
|
|
}
|
|
|
|
options[opt.name] = value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, id, expectedType));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
errors.push(createCompilerDiagnostic(Diagnostics.Unknown_compiler_option_0, id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2015-05-16 20:38:28 +02:00
|
|
|
function getFileNames(): string[] {
|
2015-06-26 02:36:19 +02:00
|
|
|
let fileNames: string[] = [];
|
2015-01-16 02:12:45 +01:00
|
|
|
if (hasProperty(json, "files")) {
|
|
|
|
if (json["files"] instanceof Array) {
|
2015-05-16 20:38:28 +02:00
|
|
|
fileNames = map(<string[]>json["files"], s => combinePaths(basePath, s));
|
2015-01-16 02:12:45 +01:00
|
|
|
}
|
2015-07-29 02:59:17 +02:00
|
|
|
else {
|
2015-08-04 22:38:00 +02:00
|
|
|
errors.push(createCompilerDiagnostic(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
|
|
|
}
|
|
|
|
else {
|
2015-06-26 02:36:19 +02:00
|
|
|
let exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
|
2015-07-29 02:59:17 +02:00
|
|
|
let sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude));
|
2015-06-26 02:36:19 +02:00
|
|
|
for (let i = 0; i < sysFiles.length; i++) {
|
|
|
|
let name = sysFiles[i];
|
2015-06-18 23:01:31 +02:00
|
|
|
if (fileExtensionIs(name, ".d.ts")) {
|
|
|
|
let baseName = name.substr(0, name.length - ".d.ts".length);
|
|
|
|
if (!contains(sysFiles, baseName + ".tsx") && !contains(sysFiles, baseName + ".ts")) {
|
|
|
|
fileNames.push(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fileExtensionIs(name, ".ts")) {
|
|
|
|
if (!contains(sysFiles, name + "x")) {
|
2015-07-09 02:42:26 +02:00
|
|
|
fileNames.push(name);
|
2015-06-18 23:01:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-05-16 20:38:28 +02:00
|
|
|
fileNames.push(name);
|
2015-01-16 02:12:45 +01:00
|
|
|
}
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-16 20:38:28 +02:00
|
|
|
return fileNames;
|
2015-01-15 22:22:23 +01:00
|
|
|
}
|
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|