Skip to content

Commit

Permalink
Merge branch 'master' into unionTypeOperations
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Jan 21, 2015
2 parents efd9f60 + 8f36090 commit 1ce32d9
Show file tree
Hide file tree
Showing 38 changed files with 625 additions and 276 deletions.
18 changes: 10 additions & 8 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module ts {
var emptySymbols: SymbolTable = {};

var compilerOptions = host.getCompilerOptions();
var languageVersion = compilerOptions.target || ScriptTarget.ES3;

var emitResolver = createResolver();

var checker: TypeChecker = {
Expand Down Expand Up @@ -6358,7 +6360,7 @@ module ts {

function checkTaggedTemplateExpression(node: TaggedTemplateExpression): Type {
// Grammar checking
if (compilerOptions.target < ScriptTarget.ES6) {
if (languageVersion < ScriptTarget.ES6) {
grammarErrorOnFirstToken(node.template, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher);
}

Expand Down Expand Up @@ -10056,7 +10058,7 @@ module ts {
globalRegExpType = getGlobalType("RegExp");
// If we're in ES6 mode, load the TemplateStringsArray.
// Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios.
globalTemplateStringsArrayType = compilerOptions.target >= ScriptTarget.ES6
globalTemplateStringsArrayType = languageVersion >= ScriptTarget.ES6
? getGlobalType("TemplateStringsArray")
: unknownType;
anyArrayType = createArrayType(anyType);
Expand Down Expand Up @@ -10429,7 +10431,7 @@ module ts {
return;

var computedPropertyName = <ComputedPropertyName>node;
if (compilerOptions.target < ScriptTarget.ES6) {
if (languageVersion < ScriptTarget.ES6) {
grammarErrorOnNode(node, Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher);
}
else if (computedPropertyName.expression.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>computedPropertyName.expression).operator === SyntaxKind.CommaToken) {
Expand Down Expand Up @@ -10529,7 +10531,7 @@ module ts {

function checkGrammarAccessor(accessor: MethodDeclaration): boolean {
var kind = accessor.kind;
if (compilerOptions.target < ScriptTarget.ES5) {
if (languageVersion < ScriptTarget.ES5) {
return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
}
else if (isInAmbientContext(accessor)) {
Expand Down Expand Up @@ -10734,7 +10736,7 @@ module ts {
return grammarErrorAtPos(getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, Diagnostics.Variable_declaration_list_cannot_be_empty);
}

if (compilerOptions.target < ScriptTarget.ES6) {
if (languageVersion < ScriptTarget.ES6) {
if (isLet(declarationList)) {
return grammarErrorOnFirstToken(declarationList, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
}
Expand Down Expand Up @@ -10836,7 +10838,7 @@ module ts {
function grammarErrorOnFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
var sourceFile = getSourceFileOfNode(node);
if (!hasParseDiagnostics(sourceFile)) {
var scanner = createScanner(compilerOptions.target, /*skipTrivia*/ true, sourceFile.text);
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text);
var start = scanToken(scanner, node.pos);
diagnostics.push(createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2));
return true;
Expand Down Expand Up @@ -10978,7 +10980,7 @@ module ts {
if (node.parserContextFlags & ParserContextFlags.StrictMode) {
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode);
}
else if (compilerOptions.target >= ScriptTarget.ES5) {
else if (languageVersion >= ScriptTarget.ES5) {
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
}
}
Expand All @@ -10987,7 +10989,7 @@ module ts {
function grammarErrorAfterFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
var sourceFile = getSourceFileOfNode(node);
if (!hasParseDiagnostics(sourceFile)) {
var scanner = createScanner(compilerOptions.target, /*skipTrivia*/ true, sourceFile.text);
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text);
scanToken(scanner, node.pos);
diagnostics.push(createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2));
return true;
Expand Down
120 changes: 104 additions & 16 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@ module ts {
type: "boolean",
description: Diagnostics.Print_this_message,
},
{
name: "listFiles",
type: "boolean",
},
{
name: "locale",
type: "string",
},
{
name: "mapRoot",
type: "string",
isFilePath: true,
description: Diagnostics.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations,
paramType: Diagnostics.LOCATION,
},
Expand Down Expand Up @@ -90,6 +95,7 @@ module ts {
{
name: "outDir",
type: "string",
isFilePath: true,
description: Diagnostics.Redirect_output_structure_to_the_directory,
paramType: Diagnostics.DIRECTORY,
},
Expand All @@ -98,6 +104,14 @@ module ts {
type: "boolean",
description: Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code
},
{
name: "project",
shortName: "p",
type: "string",
isFilePath: true,
description: Diagnostics.Compile_the_project_in_the_given_directory,
paramType: Diagnostics.DIRECTORY
},
{
name: "removeComments",
type: "boolean",
Expand All @@ -111,6 +125,7 @@ module ts {
{
name: "sourceRoot",
type: "string",
isFilePath: true,
description: Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
paramType: Diagnostics.LOCATION,
},
Expand Down Expand Up @@ -141,26 +156,19 @@ module ts {
}
];

var shortOptionNames: Map<string> = {};
var optionNameMap: Map<CommandLineOption> = {};

forEach(optionDeclarations, option => {
optionNameMap[option.name.toLowerCase()] = option;

if (option.shortName) {
shortOptionNames[option.shortName] = option.name;
}
});

export function parseCommandLine(commandLine: string[]): ParsedCommandLine {
// Set default compiler option values
var options: CompilerOptions = {
target: ScriptTarget.ES3,
module: ModuleKind.None
};
var options: CompilerOptions = {};
var filenames: string[] = [];
var errors: Diagnostic[] = [];
var shortOptionNames: Map<string> = {};
var optionNameMap: Map<CommandLineOption> = {};

forEach(optionDeclarations, option => {
optionNameMap[option.name.toLowerCase()] = option;
if (option.shortName) {
shortOptionNames[option.shortName] = option.name;
}
});
parseStrings(commandLine);
return {
options,
Expand Down Expand Up @@ -256,4 +264,84 @@ module ts {
parseStrings(args);
}
}

export function readConfigFile(filename: string): any {
try {
var text = sys.readFile(filename);
return /\S/.test(text) ? JSON.parse(text) : {};
}
catch (e) {
}
}

export function parseConfigFile(json: any, basePath?: string): ParsedCommandLine {
var errors: Diagnostic[] = [];

return {
options: getCompilerOptions(),
filenames: getFiles(),
errors
};

function getCompilerOptions(): CompilerOptions {
var options: CompilerOptions = {};
var optionNameMap: Map<CommandLineOption> = {};
forEach(optionDeclarations, option => {
optionNameMap[option.name] = option;
});
var jsonOptions = json["compilerOptions"];
if (jsonOptions) {
for (var id in jsonOptions) {
if (hasProperty(optionNameMap, id)) {
var opt = optionNameMap[id];
var optType = opt.type;
var value = jsonOptions[id];
var expectedType = typeof optType === "string" ? optType : "string";
if (typeof value === expectedType) {
if (typeof optType !== "string") {
var key = value.toLowerCase();
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;
}

function getFiles(): string[] {
var files: string[] = [];
if (hasProperty(json, "files")) {
if (json["files"] instanceof Array) {
var files = map(<string[]>json["files"], s => combinePaths(basePath, s));
}
}
else {
var sysFiles = sys.readDirectory(basePath, ".ts");
for (var i = 0; i < sysFiles.length; i++) {
var name = sysFiles[i];
if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) {
files.push(name);
}
}
}
return files;
}
}
}
15 changes: 14 additions & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@ module ts {
return <T>result;
}

export function extend<T>(first: Map<T>, second: Map<T>): Map<T> {
var result: Map<T> = {};
for (var id in first) {
result[id] = first[id];
}
for (var id in second) {
if (!hasProperty(result, id)) {
result[id] = second[id];
}
}
return result;
}

export function forEachValue<T, U>(map: Map<T>, callback: (value: T) => U): U {
var result: U;
for (var id in map) {
Expand Down Expand Up @@ -568,7 +581,7 @@ module ts {
export function combinePaths(path1: string, path2: string) {
if (!(path1 && path1.length)) return path2;
if (!(path2 && path2.length)) return path1;
if (path2.charAt(0) === directorySeparator) return path2;
if (getRootLength(path2) !== 0) return path2;
if (path1.charAt(path1.length - 1) === directorySeparator) return path1 + path2;
return path1 + directorySeparator + path2;
}
Expand Down
13 changes: 8 additions & 5 deletions src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,13 @@ module ts {
Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" },
Unsupported_file_encoding: { code: 5013, category: DiagnosticCategory.Error, key: "Unsupported file encoding." },
Unknown_compiler_option_0: { code: 5023, category: DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." },
Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." },
Could_not_write_file_0_Colon_1: { code: 5033, category: DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option mapRoot cannot be specified without specifying sourcemap option." },
Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option sourceRoot cannot be specified without specifying sourcemap option." },
Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: DiagnosticCategory.Error, key: "Option noEmit cannot be specified with option out or outDir." },
Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: DiagnosticCategory.Error, key: "Option noEmit cannot be specified with option declaration." },
Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourcemap' option." },
Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option." },
Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." },
Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." },
Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." },
Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." },
Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." },
Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." },
Expand All @@ -399,14 +401,15 @@ module ts {
Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" },
Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." },
Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." },
Compile_the_project_in_the_given_directory: { code: 6020, category: DiagnosticCategory.Message, key: "Compile the project in the given directory." },
Syntax_Colon_0: { code: 6023, category: DiagnosticCategory.Message, key: "Syntax: {0}" },
options: { code: 6024, category: DiagnosticCategory.Message, key: "options" },
file: { code: 6025, category: DiagnosticCategory.Message, key: "file" },
Examples_Colon_0: { code: 6026, category: DiagnosticCategory.Message, key: "Examples: {0}" },
Options_Colon: { code: 6027, category: DiagnosticCategory.Message, key: "Options:" },
Version_0: { code: 6029, category: DiagnosticCategory.Message, key: "Version {0}" },
Insert_command_line_options_and_files_from_a_file: { code: 6030, category: DiagnosticCategory.Message, key: "Insert command line options and files from a file." },
File_change_detected_Compiling: { code: 6032, category: DiagnosticCategory.Message, key: "File change detected. Compiling..." },
File_change_detected_Starting_incremental_compilation: { code: 6032, category: DiagnosticCategory.Message, key: "File change detected. Starting incremental compilation..." },
KIND: { code: 6034, category: DiagnosticCategory.Message, key: "KIND" },
FILE: { code: 6035, category: DiagnosticCategory.Message, key: "FILE" },
VERSION: { code: 6036, category: DiagnosticCategory.Message, key: "VERSION" },
Expand Down
22 changes: 17 additions & 5 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1618,26 +1618,34 @@
"category": "Error",
"code": 5023
},
"Compiler option '{0}' requires a value of type {1}.": {
"category": "Error",
"code": 5024
},
"Could not write file '{0}': {1}": {
"category": "Error",
"code": 5033
},
"Option mapRoot cannot be specified without specifying sourcemap option.": {
"Option 'mapRoot' cannot be specified without specifying 'sourcemap' option.": {
"category": "Error",
"code": 5038
},
"Option sourceRoot cannot be specified without specifying sourcemap option.": {
"Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option.": {
"category": "Error",
"code": 5039
},
"Option noEmit cannot be specified with option out or outDir.": {
"Option 'noEmit' cannot be specified with option 'out' or 'outDir'.": {
"category": "Error",
"code": 5040
},
"Option noEmit cannot be specified with option declaration.": {
"Option 'noEmit' cannot be specified with option 'declaration'.": {
"category": "Error",
"code": 5041
},
"Option 'project' cannot be mixed with source files on a command line.": {
"category": "Error",
"code": 5042
},
"Concatenate and emit output to single file.": {
"category": "Message",
"code": 6001
Expand Down Expand Up @@ -1694,6 +1702,10 @@
"category": "Message",
"code": 6019
},
"Compile the project in the given directory.": {
"category": "Message",
"code": 6020
},
"Syntax: {0}": {
"category": "Message",
"code": 6023
Expand Down Expand Up @@ -1722,7 +1734,7 @@
"category": "Message",
"code": 6030
},
"File change detected. Compiling...": {
"File change detected. Starting incremental compilation...": {
"category": "Message",
"code": 6032
},
Expand Down
Loading

0 comments on commit 1ce32d9

Please sign in to comment.