Skip to content

Commit ad42afc

Browse files
committed
resolve merge conflicts
2 parents e15f934 + 2052ac3 commit ad42afc

File tree

53 files changed

+2265
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2265
-364
lines changed

src/compiler/binder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ module ts {
99

1010
export function getModuleInstanceState(node: Node): ModuleInstanceState {
1111
// A module is uninstantiated if it contains only
12-
// 1. interface declarations
13-
if (node.kind === SyntaxKind.InterfaceDeclaration) {
12+
// 1. interface declarations, type alias declarations
13+
if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.TypeAliasDeclaration) {
1414
return ModuleInstanceState.NonInstantiated;
1515
}
1616
// 2. const enum declarations don't make module instantiated

src/compiler/checker.ts

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module ts {
1616
var emptySymbols: SymbolTable = {};
1717

1818
var compilerOptions = host.getCompilerOptions();
19+
var languageVersion = compilerOptions.target || ScriptTarget.ES3;
20+
1921
var emitResolver = createResolver();
2022

2123
var checker: TypeChecker = {
@@ -5618,7 +5620,7 @@ module ts {
56185620
}
56195621

56205622
var isConstEnum = isConstEnumObjectType(objectType);
5621-
if (isConstEnum &&
5623+
if (isConstEnum &&
56225624
(!node.argumentExpression || node.argumentExpression.kind !== SyntaxKind.StringLiteral)) {
56235625
error(node.argumentExpression, Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal);
56245626
return unknownType;
@@ -5650,10 +5652,10 @@ module ts {
56505652
}
56515653

56525654
// Check for compatible indexer types.
5653-
if (indexType.flags & (TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike)) {
5655+
if (isTypeOfKind(indexType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike)) {
56545656

56555657
// Try to use a number indexer.
5656-
if (indexType.flags & (TypeFlags.Any | TypeFlags.NumberLike)) {
5658+
if (isTypeOfKind(indexType, TypeFlags.Any | TypeFlags.NumberLike)) {
56575659
var numberIndexType = getIndexTypeOfType(objectType, IndexKind.Number);
56585660
if (numberIndexType) {
56595661
return numberIndexType;
@@ -6357,7 +6359,7 @@ module ts {
63576359

63586360
function checkTaggedTemplateExpression(node: TaggedTemplateExpression): Type {
63596361
// Grammar checking
6360-
if (compilerOptions.target < ScriptTarget.ES6) {
6362+
if (languageVersion < ScriptTarget.ES6) {
63616363
grammarErrorOnFirstToken(node.template, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher);
63626364
}
63636365

@@ -6554,7 +6556,7 @@ module ts {
65546556
}
65556557

65566558
function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage): boolean {
6557-
if (!(type.flags & (TypeFlags.Any | TypeFlags.NumberLike))) {
6559+
if (!isTypeOfKind(type, TypeFlags.Any | TypeFlags.NumberLike)) {
65586560
error(operand, diagnostic);
65596561
return false;
65606562
}
@@ -6705,12 +6707,21 @@ module ts {
67056707
return numberType;
67066708
}
67076709

6708-
// Return true if type an object type, a type parameter, or a union type composed of only those kinds of types
6709-
function isStructuredType(type: Type): boolean {
6710+
// Return true if type has the given flags, or is a union type composed of types that all have those flags
6711+
function isTypeOfKind(type: Type, kind: TypeFlags): boolean {
6712+
if (type.flags & kind) {
6713+
return true;
6714+
}
67106715
if (type.flags & TypeFlags.Union) {
6711-
return !forEach((<UnionType>type).types, t => !isStructuredType(t));
6716+
var types = (<UnionType>type).types;
6717+
for (var i = 0; i < types.length; i++) {
6718+
if (!(types[i].flags & kind)) {
6719+
return false;
6720+
}
6721+
}
6722+
return true;
67126723
}
6713-
return (type.flags & (TypeFlags.ObjectType | TypeFlags.TypeParameter)) !== 0;
6724+
return false;
67146725
}
67156726

67166727
function isConstEnumObjectType(type: Type): boolean {
@@ -6727,7 +6738,7 @@ module ts {
67276738
// and the right operand to be of type Any or a subtype of the 'Function' interface type.
67286739
// The result is always of the Boolean primitive type.
67296740
// NOTE: do not raise error if leftType is unknown as related error was already reported
6730-
if (!(leftType.flags & TypeFlags.Any || isStructuredType(leftType))) {
6741+
if (!isTypeOfKind(leftType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) {
67316742
error(node.left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
67326743
}
67336744
// NOTE: do not raise error if right is unknown as related error was already reported
@@ -6742,10 +6753,10 @@ module ts {
67426753
// The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type,
67436754
// and the right operand to be of type Any, an object type, or a type parameter type.
67446755
// The result is always of the Boolean primitive type.
6745-
if (leftType !== anyType && leftType !== stringType && leftType !== numberType) {
6756+
if (!isTypeOfKind(leftType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike)) {
67466757
error(node.left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number);
67476758
}
6748-
if (!(rightType.flags & TypeFlags.Any || isStructuredType(rightType))) {
6759+
if (!isTypeOfKind(rightType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) {
67496760
error(node.right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
67506761
}
67516762
return booleanType;
@@ -6906,16 +6917,16 @@ module ts {
69066917
if (rightType.flags & (TypeFlags.Undefined | TypeFlags.Null)) rightType = leftType;
69076918

69086919
var resultType: Type;
6909-
if (leftType.flags & TypeFlags.NumberLike && rightType.flags & TypeFlags.NumberLike) {
6920+
if (isTypeOfKind(leftType, TypeFlags.NumberLike) && isTypeOfKind(rightType, TypeFlags.NumberLike)) {
69106921
// Operands of an enum type are treated as having the primitive type Number.
69116922
// If both operands are of the Number primitive type, the result is of the Number primitive type.
69126923
resultType = numberType;
69136924
}
6914-
else if (leftType.flags & TypeFlags.StringLike || rightType.flags & TypeFlags.StringLike) {
6925+
else if (isTypeOfKind(leftType, TypeFlags.StringLike) || isTypeOfKind(rightType, TypeFlags.StringLike)) {
69156926
// If one or both operands are of the String primitive type, the result is of the String primitive type.
69166927
resultType = stringType;
69176928
}
6918-
else if (leftType.flags & TypeFlags.Any || leftType === unknownType || rightType.flags & TypeFlags.Any || rightType === unknownType) {
6929+
else if (leftType.flags & TypeFlags.Any || rightType.flags & TypeFlags.Any) {
69196930
// Otherwise, the result is of type Any.
69206931
// NOTE: unknown type here denotes error type. Old compiler treated this case as any type so do we.
69216932
resultType = anyType;
@@ -8271,7 +8282,7 @@ module ts {
82718282
var exprType = checkExpression(node.expression);
82728283
// unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved
82738284
// in this case error about missing name is already reported - do not report extra one
8274-
if (!(exprType.flags & TypeFlags.Any || isStructuredType(exprType))) {
8285+
if (!isTypeOfKind(exprType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) {
82758286
error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter);
82768287
}
82778288

@@ -10055,7 +10066,7 @@ module ts {
1005510066
globalRegExpType = getGlobalType("RegExp");
1005610067
// If we're in ES6 mode, load the TemplateStringsArray.
1005710068
// Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios.
10058-
globalTemplateStringsArrayType = compilerOptions.target >= ScriptTarget.ES6
10069+
globalTemplateStringsArrayType = languageVersion >= ScriptTarget.ES6
1005910070
? getGlobalType("TemplateStringsArray")
1006010071
: unknownType;
1006110072
anyArrayType = createArrayType(anyType);
@@ -10427,7 +10438,7 @@ module ts {
1042710438
return;
1042810439

1042910440
var computedPropertyName = <ComputedPropertyName>node;
10430-
if (compilerOptions.target < ScriptTarget.ES6) {
10441+
if (languageVersion < ScriptTarget.ES6) {
1043110442
grammarErrorOnNode(node, Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher);
1043210443
}
1043310444
else if (computedPropertyName.expression.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>computedPropertyName.expression).operator === SyntaxKind.CommaToken) {
@@ -10527,7 +10538,7 @@ module ts {
1052710538

1052810539
function checkGrammarAccessor(accessor: MethodDeclaration): boolean {
1052910540
var kind = accessor.kind;
10530-
if (compilerOptions.target < ScriptTarget.ES5) {
10541+
if (languageVersion < ScriptTarget.ES5) {
1053110542
return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
1053210543
}
1053310544
else if (isInAmbientContext(accessor)) {
@@ -10732,7 +10743,7 @@ module ts {
1073210743
return grammarErrorAtPos(getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, Diagnostics.Variable_declaration_list_cannot_be_empty);
1073310744
}
1073410745

10735-
if (compilerOptions.target < ScriptTarget.ES6) {
10746+
if (languageVersion < ScriptTarget.ES6) {
1073610747
if (isLet(declarationList)) {
1073710748
return grammarErrorOnFirstToken(declarationList, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
1073810749
}
@@ -10834,7 +10845,7 @@ module ts {
1083410845
function grammarErrorOnFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
1083510846
var sourceFile = getSourceFileOfNode(node);
1083610847
if (!hasParseDiagnostics(sourceFile)) {
10837-
var scanner = createScanner(compilerOptions.target, /*skipTrivia*/ true, sourceFile.text);
10848+
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text);
1083810849
var start = scanToken(scanner, node.pos);
1083910850
diagnostics.push(createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2));
1084010851
return true;
@@ -10976,7 +10987,7 @@ module ts {
1097610987
if (node.parserContextFlags & ParserContextFlags.StrictMode) {
1097710988
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode);
1097810989
}
10979-
else if (compilerOptions.target >= ScriptTarget.ES5) {
10990+
else if (languageVersion >= ScriptTarget.ES5) {
1098010991
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
1098110992
}
1098210993
}
@@ -10985,7 +10996,7 @@ module ts {
1098510996
function grammarErrorAfterFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
1098610997
var sourceFile = getSourceFileOfNode(node);
1098710998
if (!hasParseDiagnostics(sourceFile)) {
10988-
var scanner = createScanner(compilerOptions.target, /*skipTrivia*/ true, sourceFile.text);
10999+
var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceFile.text);
1098911000
scanToken(scanner, node.pos);
1099011001
diagnostics.push(createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2));
1099111002
return true;

src/compiler/commandLineParser.ts

Lines changed: 104 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@ module ts {
3333
type: "boolean",
3434
description: Diagnostics.Print_this_message,
3535
},
36+
{
37+
name: "listFiles",
38+
type: "boolean",
39+
},
3640
{
3741
name: "locale",
3842
type: "string",
3943
},
4044
{
4145
name: "mapRoot",
4246
type: "string",
47+
isFilePath: true,
4348
description: Diagnostics.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations,
4449
paramType: Diagnostics.LOCATION,
4550
},
@@ -90,6 +95,7 @@ module ts {
9095
{
9196
name: "outDir",
9297
type: "string",
98+
isFilePath: true,
9399
description: Diagnostics.Redirect_output_structure_to_the_directory,
94100
paramType: Diagnostics.DIRECTORY,
95101
},
@@ -98,6 +104,14 @@ module ts {
98104
type: "boolean",
99105
description: Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code
100106
},
107+
{
108+
name: "project",
109+
shortName: "p",
110+
type: "string",
111+
isFilePath: true,
112+
description: Diagnostics.Compile_the_project_in_the_given_directory,
113+
paramType: Diagnostics.DIRECTORY
114+
},
101115
{
102116
name: "removeComments",
103117
type: "boolean",
@@ -111,6 +125,7 @@ module ts {
111125
{
112126
name: "sourceRoot",
113127
type: "string",
128+
isFilePath: true,
114129
description: Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
115130
paramType: Diagnostics.LOCATION,
116131
},
@@ -141,26 +156,19 @@ module ts {
141156
}
142157
];
143158

144-
var shortOptionNames: Map<string> = {};
145-
var optionNameMap: Map<CommandLineOption> = {};
146-
147-
forEach(optionDeclarations, option => {
148-
optionNameMap[option.name.toLowerCase()] = option;
149-
150-
if (option.shortName) {
151-
shortOptionNames[option.shortName] = option.name;
152-
}
153-
});
154-
155159
export function parseCommandLine(commandLine: string[]): ParsedCommandLine {
156-
// Set default compiler option values
157-
var options: CompilerOptions = {
158-
target: ScriptTarget.ES3,
159-
module: ModuleKind.None
160-
};
160+
var options: CompilerOptions = {};
161161
var filenames: string[] = [];
162162
var errors: Diagnostic[] = [];
163+
var shortOptionNames: Map<string> = {};
164+
var optionNameMap: Map<CommandLineOption> = {};
163165

166+
forEach(optionDeclarations, option => {
167+
optionNameMap[option.name.toLowerCase()] = option;
168+
if (option.shortName) {
169+
shortOptionNames[option.shortName] = option.name;
170+
}
171+
});
164172
parseStrings(commandLine);
165173
return {
166174
options,
@@ -256,4 +264,84 @@ module ts {
256264
parseStrings(args);
257265
}
258266
}
267+
268+
export function readConfigFile(filename: string): any {
269+
try {
270+
var text = sys.readFile(filename);
271+
return /\S/.test(text) ? JSON.parse(text) : {};
272+
}
273+
catch (e) {
274+
}
275+
}
276+
277+
export function parseConfigFile(json: any, basePath?: string): ParsedCommandLine {
278+
var errors: Diagnostic[] = [];
279+
280+
return {
281+
options: getCompilerOptions(),
282+
filenames: getFiles(),
283+
errors
284+
};
285+
286+
function getCompilerOptions(): CompilerOptions {
287+
var options: CompilerOptions = {};
288+
var optionNameMap: Map<CommandLineOption> = {};
289+
forEach(optionDeclarations, option => {
290+
optionNameMap[option.name] = option;
291+
});
292+
var jsonOptions = json["compilerOptions"];
293+
if (jsonOptions) {
294+
for (var id in jsonOptions) {
295+
if (hasProperty(optionNameMap, id)) {
296+
var opt = optionNameMap[id];
297+
var optType = opt.type;
298+
var value = jsonOptions[id];
299+
var expectedType = typeof optType === "string" ? optType : "string";
300+
if (typeof value === expectedType) {
301+
if (typeof optType !== "string") {
302+
var key = value.toLowerCase();
303+
if (hasProperty(optType, key)) {
304+
value = optType[key];
305+
}
306+
else {
307+
errors.push(createCompilerDiagnostic(opt.error));
308+
value = 0;
309+
}
310+
}
311+
if (opt.isFilePath) {
312+
value = normalizePath(combinePaths(basePath, value));
313+
}
314+
options[opt.name] = value;
315+
}
316+
else {
317+
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, id, expectedType));
318+
}
319+
}
320+
else {
321+
errors.push(createCompilerDiagnostic(Diagnostics.Unknown_compiler_option_0, id));
322+
}
323+
}
324+
}
325+
return options;
326+
}
327+
328+
function getFiles(): string[] {
329+
var files: string[] = [];
330+
if (hasProperty(json, "files")) {
331+
if (json["files"] instanceof Array) {
332+
var files = map(<string[]>json["files"], s => combinePaths(basePath, s));
333+
}
334+
}
335+
else {
336+
var sysFiles = sys.readDirectory(basePath, ".ts");
337+
for (var i = 0; i < sysFiles.length; i++) {
338+
var name = sysFiles[i];
339+
if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) {
340+
files.push(name);
341+
}
342+
}
343+
}
344+
return files;
345+
}
346+
}
259347
}

src/compiler/core.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,19 @@ module ts {
178178
return <T>result;
179179
}
180180

181+
export function extend<T>(first: Map<T>, second: Map<T>): Map<T> {
182+
var result: Map<T> = {};
183+
for (var id in first) {
184+
result[id] = first[id];
185+
}
186+
for (var id in second) {
187+
if (!hasProperty(result, id)) {
188+
result[id] = second[id];
189+
}
190+
}
191+
return result;
192+
}
193+
181194
export function forEachValue<T, U>(map: Map<T>, callback: (value: T) => U): U {
182195
var result: U;
183196
for (var id in map) {
@@ -568,7 +581,7 @@ module ts {
568581
export function combinePaths(path1: string, path2: string) {
569582
if (!(path1 && path1.length)) return path2;
570583
if (!(path2 && path2.length)) return path1;
571-
if (path2.charAt(0) === directorySeparator) return path2;
584+
if (getRootLength(path2) !== 0) return path2;
572585
if (path1.charAt(path1.length - 1) === directorySeparator) return path1 + path2;
573586
return path1 + directorySeparator + path2;
574587
}

0 commit comments

Comments
 (0)