Skip to content

Commit 01267bc

Browse files
committed
Merge branch 'master' into LSAPICleanup
Conflicts: src/services/services.ts
2 parents 000206f + 8d5b65a commit 01267bc

120 files changed

Lines changed: 3506 additions & 160 deletions

File tree

Some content is hidden

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

src/compiler/checker.ts

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,6 +3337,8 @@ module ts {
33373337
case SyntaxKind.MethodDeclaration:
33383338
case SyntaxKind.MethodSignature:
33393339
return isContextSensitiveFunctionLikeDeclaration(<MethodDeclaration>node);
3340+
case SyntaxKind.ParenthesizedExpression:
3341+
return isContextSensitive((<ParenthesizedExpression>node).expression);
33403342
}
33413343

33423344
return false;
@@ -4709,13 +4711,21 @@ module ts {
47094711
if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
47104712
return type;
47114713
}
4714+
// Target type is type of prototype property
47124715
var prototypeProperty = getPropertyOfType(rightType, "prototype");
47134716
if (!prototypeProperty) {
47144717
return type;
47154718
}
4716-
var prototypeType = getTypeOfSymbol(prototypeProperty);
4717-
// Narrow to type of prototype property if it is a subtype of current type
4718-
return isTypeSubtypeOf(prototypeType, type) ? prototypeType : type;
4719+
var targetType = getTypeOfSymbol(prototypeProperty);
4720+
// Narrow to target type if it is a subtype of current type
4721+
if (isTypeSubtypeOf(targetType, type)) {
4722+
return targetType;
4723+
}
4724+
// If current type is a union type, remove all constituents that aren't subtypes of target type
4725+
if (type.flags & TypeFlags.Union) {
4726+
return getUnionType(filter((<UnionType>type).types, t => isTypeSubtypeOf(t, targetType)));
4727+
}
4728+
return type;
47194729
}
47204730

47214731
// Narrow the given type based on the given expression having the assumed boolean value
@@ -5221,6 +5231,8 @@ module ts {
52215231
case SyntaxKind.TemplateSpan:
52225232
Debug.assert(parent.parent.kind === SyntaxKind.TemplateExpression);
52235233
return getContextualTypeForSubstitutionExpression(<TemplateExpression>parent.parent, node);
5234+
case SyntaxKind.ParenthesizedExpression:
5235+
return getContextualType(<ParenthesizedExpression>parent);
52245236
}
52255237
return undefined;
52265238
}
@@ -5605,8 +5617,11 @@ module ts {
56055617
return unknownType;
56065618
}
56075619

5608-
if (isConstEnumObjectType(objectType) && node.argumentExpression && node.argumentExpression.kind !== SyntaxKind.StringLiteral) {
5609-
error(node.argumentExpression, Diagnostics.Index_expression_arguments_in_const_enums_must_be_of_type_string);
5620+
var isConstEnum = isConstEnumObjectType(objectType);
5621+
if (isConstEnum &&
5622+
(!node.argumentExpression || node.argumentExpression.kind !== SyntaxKind.StringLiteral)) {
5623+
error(node.argumentExpression, Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal);
5624+
return unknownType;
56105625
}
56115626

56125627
// TypeScript 1.0 spec (April 2014): 4.10 Property Access
@@ -5627,6 +5642,10 @@ module ts {
56275642
getNodeLinks(node).resolvedSymbol = prop;
56285643
return getTypeOfSymbol(prop);
56295644
}
5645+
else if (isConstEnum) {
5646+
error(node.argumentExpression, Diagnostics.Property_0_does_not_exist_on_const_enum_1, name, symbolToString(objectType.symbol));
5647+
return unknownType;
5648+
}
56305649
}
56315650
}
56325651

@@ -6115,34 +6134,47 @@ module ts {
61156134
var result = candidates;
61166135
var lastParent: Node;
61176136
var lastSymbol: Symbol;
6118-
var cutoffPos: number = 0;
6119-
var pos: number;
6137+
var cutoffIndex: number = 0;
6138+
var index: number;
6139+
var specializedIndex: number = -1;
6140+
var spliceIndex: number;
61206141
Debug.assert(!result.length);
61216142
for (var i = 0; i < signatures.length; i++) {
61226143
var signature = signatures[i];
61236144
var symbol = signature.declaration && getSymbolOfNode(signature.declaration);
61246145
var parent = signature.declaration && signature.declaration.parent;
61256146
if (!lastSymbol || symbol === lastSymbol) {
61266147
if (lastParent && parent === lastParent) {
6127-
pos++;
6148+
index++;
61286149
}
61296150
else {
61306151
lastParent = parent;
6131-
pos = cutoffPos;
6152+
index = cutoffIndex;
61326153
}
61336154
}
61346155
else {
61356156
// current declaration belongs to a different symbol
6136-
// set cutoffPos so re-orderings in the future won't change result set from 0 to cutoffPos
6137-
pos = cutoffPos = result.length;
6157+
// set cutoffIndex so re-orderings in the future won't change result set from 0 to cutoffIndex
6158+
index = cutoffIndex = result.length;
61386159
lastParent = parent;
61396160
}
61406161
lastSymbol = symbol;
61416162

6142-
for (var j = result.length; j > pos; j--) {
6143-
result[j] = result[j - 1];
6163+
// specialized signatures always need to be placed before non-specialized signatures regardless
6164+
// of the cutoff position; see GH#1133
6165+
if (signature.hasStringLiterals) {
6166+
specializedIndex++;
6167+
spliceIndex = specializedIndex;
6168+
// The cutoff index always needs to be greater than or equal to the specialized signature index
6169+
// in order to prevent non-specialized signatures from being added before a specialized
6170+
// signature.
6171+
cutoffIndex++;
61446172
}
6145-
result[pos] = signature;
6173+
else {
6174+
spliceIndex = index;
6175+
}
6176+
6177+
result.splice(spliceIndex, 0, signature);
61466178
}
61476179
}
61486180
}
@@ -7174,12 +7206,15 @@ module ts {
71747206

71757207
checkVariableLikeDeclaration(node);
71767208
var func = getContainingFunction(node);
7177-
if (node.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)) {
7209+
if (node.flags & NodeFlags.AccessibilityModifier) {
71787210
func = getContainingFunction(node);
71797211
if (!(func.kind === SyntaxKind.Constructor && nodeIsPresent(func.body))) {
71807212
error(node, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
71817213
}
71827214
}
7215+
if (node.questionToken && isBindingPattern(node.name) && func.body) {
7216+
error(node, Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature);
7217+
}
71837218
if (node.dotDotDotToken) {
71847219
if (!isArrayType(getTypeOfSymbol(node.symbol))) {
71857220
error(node, Diagnostics.A_rest_parameter_must_be_of_an_array_type);
@@ -7193,17 +7228,20 @@ module ts {
71937228
checkGrammarIndexSignature(<SignatureDeclaration>node);
71947229
}
71957230
// TODO (yuisu): Remove this check in else-if when SyntaxKind.Construct is moved and ambient context is handled
7196-
else if (node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.ConstructorType ||
7231+
else if (node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.ConstructorType ||
71977232
node.kind === SyntaxKind.CallSignature || node.kind === SyntaxKind.Constructor ||
71987233
node.kind === SyntaxKind.ConstructSignature){
71997234
checkGrammarFunctionLikeDeclaration(<FunctionLikeDeclaration>node);
72007235
}
72017236

72027237
checkTypeParameters(node.typeParameters);
7238+
72037239
forEach(node.parameters, checkParameter);
7240+
72047241
if (node.type) {
72057242
checkSourceElement(node.type);
72067243
}
7244+
72077245
if (produceDiagnostics) {
72087246
checkCollisionWithArgumentsInGeneratedCode(node);
72097247
if (compilerOptions.noImplicitAny && !node.type) {
@@ -10154,6 +10192,9 @@ module ts {
1015410192
else if (node.kind === SyntaxKind.InterfaceDeclaration && flags & NodeFlags.Ambient) {
1015510193
return grammarErrorOnNode(lastDeclare, Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare");
1015610194
}
10195+
else if (node.kind === SyntaxKind.Parameter && (flags & NodeFlags.AccessibilityModifier) && isBindingPattern((<ParameterDeclaration>node).name)) {
10196+
return grammarErrorOnNode(node, Diagnostics.A_parameter_property_may_not_be_a_binding_pattern);
10197+
}
1015710198
}
1015810199

1015910200
function checkGrammarForDisallowedTrailingComma(list: NodeArray<Node>): boolean {

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ module ts {
146146
Modifiers_cannot_appear_here: { code: 1184, category: DiagnosticCategory.Error, key: "Modifiers cannot appear here." },
147147
Merge_conflict_marker_encountered: { code: 1185, category: DiagnosticCategory.Error, key: "Merge conflict marker encountered." },
148148
A_rest_element_cannot_have_an_initializer: { code: 1186, category: DiagnosticCategory.Error, key: "A rest element cannot have an initializer." },
149+
A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: DiagnosticCategory.Error, key: "A parameter property may not be a binding pattern." },
149150
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
150151
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
151152
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
@@ -297,6 +298,7 @@ module ts {
297298
Type_0_has_no_property_1: { code: 2460, category: DiagnosticCategory.Error, key: "Type '{0}' has no property '{1}'." },
298299
Type_0_is_not_an_array_type: { code: 2461, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type." },
299300
A_rest_element_must_be_last_in_an_array_destructuring_pattern: { code: 2462, category: DiagnosticCategory.Error, key: "A rest element must be last in an array destructuring pattern" },
301+
A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature: { code: 2463, category: DiagnosticCategory.Error, key: "A binding pattern parameter cannot be optional in an implementation signature." },
300302
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
301303
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
302304
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
@@ -369,9 +371,10 @@ module ts {
369371
Enum_declarations_must_all_be_const_or_non_const: { code: 4082, category: DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." },
370372
In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 4083, category: DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression.", isEarly: true },
371373
const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 4084, category: DiagnosticCategory.Error, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." },
372-
Index_expression_arguments_in_const_enums_must_be_of_type_string: { code: 4085, category: DiagnosticCategory.Error, key: "Index expression arguments in 'const' enums must be of type 'string'." },
374+
A_const_enum_member_can_only_be_accessed_using_a_string_literal: { code: 4085, category: DiagnosticCategory.Error, key: "A const enum member can only be accessed using a string literal.", isEarly: true },
373375
const_enum_member_initializer_was_evaluated_to_a_non_finite_value: { code: 4086, category: DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to a non-finite value." },
374376
const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN: { code: 4087, category: DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to disallowed value 'NaN'." },
377+
Property_0_does_not_exist_on_const_enum_1: { code: 4088, category: DiagnosticCategory.Error, key: "Property '{0}' does not exist on 'const' enum '{1}'.", isEarly: true },
375378
The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." },
376379
Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." },
377380
Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" },
@@ -419,7 +422,7 @@ module ts {
419422
Unsupported_locale_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." },
420423
Unable_to_open_file_0: { code: 6050, category: DiagnosticCategory.Error, key: "Unable to open file '{0}'." },
421424
Corrupted_locale_file_0: { code: 6051, category: DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
422-
Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: DiagnosticCategory.Message, key: "Warn on expressions and declarations with an implied 'any' type." },
425+
Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." },
423426
File_0_not_found: { code: 6053, category: DiagnosticCategory.Error, key: "File '{0}' not found." },
424427
File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' must have extension '.ts' or '.d.ts'." },
425428
Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." },

src/compiler/diagnosticMessages.json

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
"A 'declare' modifier cannot be used with an import declaration.": {
225225
"category": "Error",
226226
"code": 1079,
227-
"isEarly": true
227+
"isEarly": true
228228
},
229229
"Invalid 'reference' directive syntax.": {
230230
"category": "Error",
@@ -659,7 +659,7 @@
659659
"An implementation cannot be declared in ambient contexts.": {
660660
"category": "Error",
661661
"code": 1184,
662-
"isEarly": true
662+
"isEarly": true
663663
},
664664
"Modifiers cannot appear here.": {
665665
"category": "Error",
@@ -673,6 +673,10 @@
673673
"category": "Error",
674674
"code": 1186
675675
},
676+
"A parameter property may not be a binding pattern.": {
677+
"category": "Error",
678+
"code": 1187
679+
},
676680

677681
"Duplicate identifier '{0}'.": {
678682
"category": "Error",
@@ -1282,6 +1286,10 @@
12821286
"category": "Error",
12831287
"code": 2462
12841288
},
1289+
"A binding pattern parameter cannot be optional in an implementation signature.": {
1290+
"category": "Error",
1291+
"code": 2463
1292+
},
12851293

12861294
"Import declaration '{0}' is using private name '{1}'.": {
12871295
"category": "Error",
@@ -1572,9 +1580,10 @@
15721580
"category": "Error",
15731581
"code": 4084
15741582
},
1575-
"Index expression arguments in 'const' enums must be of type 'string'.": {
1583+
"A const enum member can only be accessed using a string literal.": {
15761584
"category": "Error",
1577-
"code": 4085
1585+
"code": 4085,
1586+
"isEarly": true
15781587
},
15791588
"'const' enum member initializer was evaluated to a non-finite value.": {
15801589
"category": "Error",
@@ -1584,6 +1593,11 @@
15841593
"category": "Error",
15851594
"code": 4087
15861595
},
1596+
"Property '{0}' does not exist on 'const' enum '{1}'.": {
1597+
"category": "Error",
1598+
"code": 4088,
1599+
"isEarly": true
1600+
},
15871601
"The current host does not support the '{0}' option.": {
15881602
"category": "Error",
15891603
"code": 5001

src/compiler/parser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,10 @@ module ts {
13951395
}
13961396

13971397
function canFollowModifier(): boolean {
1398-
return token === SyntaxKind.OpenBracketToken || token === SyntaxKind.AsteriskToken || isLiteralPropertyName();
1398+
return token === SyntaxKind.OpenBracketToken
1399+
|| token === SyntaxKind.OpenBraceToken
1400+
|| token === SyntaxKind.AsteriskToken
1401+
|| isLiteralPropertyName();
13991402
}
14001403

14011404
// True if positioned at the start of a list element

src/compiler/scanner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ module ts {
10391039
value = 0;
10401040
}
10411041
tokenValue = "" + value;
1042-
return SyntaxKind.NumericLiteral;
1042+
return token = SyntaxKind.NumericLiteral;
10431043
}
10441044
else if (pos + 2 < len && (text.charCodeAt(pos + 1) === CharacterCodes.O || text.charCodeAt(pos + 1) === CharacterCodes.o)) {
10451045
pos += 2;
@@ -1049,7 +1049,7 @@ module ts {
10491049
value = 0;
10501050
}
10511051
tokenValue = "" + value;
1052-
return SyntaxKind.NumericLiteral;
1052+
return token = SyntaxKind.NumericLiteral;
10531053
}
10541054
// Try to parse as an octal
10551055
if (pos + 1 < len && isOctalDigit(text.charCodeAt(pos + 1))) {

0 commit comments

Comments
 (0)