Merge branch 'master' into returnExitCode

This commit is contained in:
Yui T
2014-09-22 14:05:55 -07:00
158 changed files with 2475 additions and 533 deletions

View File

@@ -226,7 +226,7 @@ module ts {
function bindConstructorDeclaration(node: ConstructorDeclaration) {
bindDeclaration(node, SymbolFlags.Constructor, 0);
forEach(node.parameters, p => {
if (p.flags & (NodeFlags.Public | NodeFlags.Private)) {
if (p.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)) {
bindDeclaration(p, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
}
});

View File

@@ -1282,8 +1282,8 @@ module ts {
case SyntaxKind.Property:
case SyntaxKind.Method:
if (node.flags & NodeFlags.Private) {
// Private properties/methods are not visible
if (node.flags & (NodeFlags.Private | NodeFlags.Protected)) {
// Private/protected properties/methods are not visible
return false;
}
// Public properties/methods are visible if its parents are visible, so let it fall into next case statement
@@ -2708,22 +2708,19 @@ module ts {
}
function isPropertyIdenticalToRecursive(sourceProp: Symbol, targetProp: Symbol, reportErrors: boolean, relate: (source: Type, target: Type, reportErrors: boolean) => boolean): boolean {
Debug.assert(sourceProp);
if (!targetProp) {
return false;
}
// Two members are considered identical when
// - they are public properties with identical names, optionality, and types,
// - they are private properties originating in the same declaration and having identical types
var sourcePropIsPrivate = getDeclarationFlagsFromSymbol(sourceProp) & NodeFlags.Private;
var targetPropIsPrivate = getDeclarationFlagsFromSymbol(targetProp) & NodeFlags.Private;
if (sourcePropIsPrivate !== targetPropIsPrivate) {
// - they are private or protected properties originating in the same declaration and having identical types
if (sourceProp === targetProp) {
return true;
}
var sourcePropAccessibility = getDeclarationFlagsFromSymbol(sourceProp) & (NodeFlags.Private | NodeFlags.Protected);
var targetPropAccessibility = getDeclarationFlagsFromSymbol(targetProp) & (NodeFlags.Private | NodeFlags.Protected);
if (sourcePropAccessibility !== targetPropAccessibility) {
return false;
}
if (sourcePropIsPrivate) {
return (getTargetSymbol(sourceProp).parent === getTargetSymbol(targetProp).parent) && relate(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
if (sourcePropAccessibility) {
return getTargetSymbol(sourceProp) === getTargetSymbol(targetProp) && relate(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
}
else {
return isOptionalProperty(sourceProp) === isOptionalProperty(targetProp) && relate(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
@@ -2749,8 +2746,8 @@ module ts {
}
return result;
function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string): void {
errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1);
function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void {
errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2);
}
function isRelatedTo(source: Type, target: Type, reportErrors: boolean): boolean {
@@ -2922,25 +2919,18 @@ module ts {
}
function propertiesAreIdenticalTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean {
if (source === target) {
return true;
}
var sourceProperties = getPropertiesOfType(source);
var targetProperties = getPropertiesOfType(target);
if (sourceProperties.length !== targetProperties.length) {
return false;
}
for (var i = 0, len = sourceProperties.length; i < len; ++i) {
var sourceProp = sourceProperties[i];
var targetProp = getPropertyOfType(target, sourceProp.name);
if (!isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) {
if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) {
return false;
}
}
return true;
}
@@ -2949,50 +2939,72 @@ module ts {
for (var i = 0; i < properties.length; i++) {
var targetProp = properties[i];
var sourceProp = getPropertyOfApparentType(source, targetProp.name);
if (sourceProp === targetProp) {
continue;
}
var targetPropIsOptional = isOptionalProperty(targetProp);
if (!sourceProp) {
if (!targetPropIsOptional) {
if (reportErrors) {
reportError(Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source));
}
return false;
}
}
else if (sourceProp !== targetProp) {
if (targetProp.flags & SymbolFlags.Prototype) {
continue;
}
if (getDeclarationFlagsFromSymbol(sourceProp) & NodeFlags.Private || getDeclarationFlagsFromSymbol(targetProp) & NodeFlags.Private) {
if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) {
if (sourceProp !== targetProp) {
if (!sourceProp) {
if (!isOptionalProperty(targetProp)) {
if (reportErrors) {
reportError(Diagnostics.Private_property_0_cannot_be_reimplemented, symbolToString(targetProp));
reportError(Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source));
}
return false;
}
}
if (!isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors)) {
if (reportErrors) {
reportError(Diagnostics.Types_of_property_0_are_incompatible_Colon, symbolToString(targetProp));
else if (!(targetProp.flags & SymbolFlags.Prototype)) {
var sourceFlags = getDeclarationFlagsFromSymbol(sourceProp);
var targetFlags = getDeclarationFlagsFromSymbol(targetProp);
if (sourceFlags & NodeFlags.Private || targetFlags & NodeFlags.Private) {
if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) {
if (reportErrors) {
if (sourceFlags & NodeFlags.Private && targetFlags & NodeFlags.Private) {
reportError(Diagnostics.Types_have_separate_declarations_of_a_private_property_0, symbolToString(targetProp));
}
else {
reportError(Diagnostics.Property_0_is_private_in_type_1_but_not_in_type_2, symbolToString(targetProp),
typeToString(sourceFlags & NodeFlags.Private ? source : target),
typeToString(sourceFlags & NodeFlags.Private ? target : source));
}
}
return false;
}
}
return false;
}
else if (isOptionalProperty(sourceProp) && !targetPropIsOptional) {
// TypeScript 1.0 spec (April 2014): 3.8.3
// S is a subtype of a type T, and T is a supertype of S if ...
// S' and T are object types and, for each member M in T..
// M is a property and S' contains a property N where
// if M is a required property, N is also a required property
// (M - property in T)
// (N - property in S)
if (reportErrors) {
reportError(Diagnostics.Required_property_0_cannot_be_reimplemented_with_optional_property_in_1, targetProp.name, typeToString(source));
else if (targetFlags & NodeFlags.Protected) {
var sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & SymbolFlags.Class;
var sourceClass = sourceDeclaredInClass ? <InterfaceType>getDeclaredTypeOfSymbol(sourceProp.parent) : undefined;
var targetClass = <InterfaceType>getDeclaredTypeOfSymbol(targetProp.parent);
if (!sourceClass || !hasBaseType(sourceClass, targetClass)) {
if (reportErrors) {
reportError(Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2,
symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass));
}
return false;
}
}
else if (sourceFlags & NodeFlags.Protected) {
if (reportErrors) {
reportError(Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2,
symbolToString(targetProp), typeToString(source), typeToString(target));
}
return false;
}
if (!isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors)) {
if (reportErrors) {
reportError(Diagnostics.Types_of_property_0_are_incompatible_Colon, symbolToString(targetProp));
}
return false;
}
if (isOptionalProperty(sourceProp) && !isOptionalProperty(targetProp)) {
// TypeScript 1.0 spec (April 2014): 3.8.3
// S is a subtype of a type T, and T is a supertype of S if ...
// S' and T are object types and, for each member M in T..
// M is a property and S' contains a property N where
// if M is a required property, N is also a required property
// (M - property in T)
// (N - property in S)
if (reportErrors) {
reportError(Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2,
symbolToString(targetProp), typeToString(source), typeToString(target));
}
return false;
}
return false;
}
}
}
@@ -3970,6 +3982,44 @@ module ts {
return s.valueDeclaration ? s.valueDeclaration.flags : s.flags & SymbolFlags.Prototype ? NodeFlags.Public | NodeFlags.Static : 0;
}
function checkClassPropertyAccess(node: PropertyAccess, type: Type, prop: Symbol) {
var flags = getDeclarationFlagsFromSymbol(prop);
// Public properties are always accessible
if (!(flags & (NodeFlags.Private | NodeFlags.Protected))) {
return;
}
// Property is known to be private or protected at this point
// Get the declaring and enclosing class instance types
var enclosingClassDeclaration = getAncestor(node, SyntaxKind.ClassDeclaration);
var enclosingClass = enclosingClassDeclaration ? <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined;
var declaringClass = <InterfaceType>getDeclaredTypeOfSymbol(prop.parent);
// Private property is accessible if declaring and enclosing class are the same
if (flags & NodeFlags.Private) {
if (declaringClass !== enclosingClass) {
error(node, Diagnostics.Property_0_is_private_and_only_accessible_within_class_1, symbolToString(prop), typeToString(declaringClass));
}
return;
}
// Property is known to be protected at this point
// All protected properties of a supertype are accessible in a super access
if (node.left.kind === SyntaxKind.SuperKeyword) {
return;
}
// A protected property is accessible in the declaring class and classes derived from it
if (!enclosingClass || !hasBaseType(enclosingClass, declaringClass)) {
error(node, Diagnostics.Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses, symbolToString(prop), typeToString(declaringClass));
return;
}
// No further restrictions for static properties
if (flags & NodeFlags.Static) {
return;
}
// An instance property must be accessed through an instance of the enclosing class
if (!(getTargetType(type).flags & (TypeFlags.Class | TypeFlags.Interface) && hasBaseType(<InterfaceType>type, enclosingClass))) {
error(node, Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1, symbolToString(prop), typeToString(enclosingClass));
}
}
function checkPropertyAccess(node: PropertyAccess) {
var type = checkExpression(node.left);
if (type === unknownType) return type;
@@ -3988,7 +4038,6 @@ module ts {
}
getNodeLinks(node).resolvedSymbol = prop;
if (prop.parent && prop.parent.flags & SymbolFlags.Class) {
// TS 1.0 spec (April 2014): 4.8.2
// - In a constructor, instance member function, instance member accessor, or
// instance member variable initializer where this references a derived class instance,
@@ -3997,13 +4046,10 @@ module ts {
// where this references the constructor function object of a derived class,
// a super property access is permitted and must specify a public static member function of the base class.
if (node.left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) {
error(node.right, Diagnostics.Only_public_methods_of_the_base_class_are_accessible_via_the_super_keyword);
error(node.right, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword);
}
else if (getDeclarationFlagsFromSymbol(prop) & NodeFlags.Private) {
var classDeclaration = getAncestor(node, SyntaxKind.ClassDeclaration);
if (!classDeclaration || !contains(prop.parent.declarations, classDeclaration)) {
error(node, Diagnostics.Property_0_is_inaccessible, getFullyQualifiedName(prop));
}
else {
checkClassPropertyAccess(node, type, prop);
}
}
return getTypeOfSymbol(prop);
@@ -4959,7 +5005,8 @@ module ts {
if (fullTypeCheck) {
checkCollisionWithIndexVariableInGeneratedCode(parameterDeclaration, parameterDeclaration.name);
if (parameterDeclaration.flags & (NodeFlags.Public | NodeFlags.Private) && !(parameterDeclaration.parent.kind === SyntaxKind.Constructor && (<ConstructorDeclaration>parameterDeclaration.parent).body)) {
if (parameterDeclaration.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected) &&
!(parameterDeclaration.parent.kind === SyntaxKind.Constructor && (<ConstructorDeclaration>parameterDeclaration.parent).body)) {
error(parameterDeclaration, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
}
if (parameterDeclaration.flags & NodeFlags.Rest) {
@@ -5152,7 +5199,7 @@ module ts {
// or the containing class declares instance member variables with initializers.
var superCallShouldBeFirst =
forEach((<ClassDeclaration>node.parent).members, isInstancePropertyWithInitializer) ||
forEach(node.parameters, p => p.flags & (NodeFlags.Public | NodeFlags.Private));
forEach(node.parameters, p => p.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected));
if (superCallShouldBeFirst) {
var statements = (<Block>node.body).statements;
@@ -5329,8 +5376,8 @@ module ts {
else if (deviation & NodeFlags.Ambient) {
error(o.name, Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient);
}
else if (deviation & NodeFlags.Private) {
error(o.name, Diagnostics.Overload_signatures_must_all_be_public_or_private);
else if (deviation & (NodeFlags.Private | NodeFlags.Protected)) {
error(o.name, Diagnostics.Overload_signatures_must_all_be_public_private_or_protected);
}
else if (deviation & NodeFlags.QuestionMark) {
error(o.name, Diagnostics.Overload_signatures_must_all_be_optional_or_required);
@@ -5339,7 +5386,7 @@ module ts {
}
}
var flagsToCheck: NodeFlags = NodeFlags.Export | NodeFlags.Ambient | NodeFlags.Private | NodeFlags.QuestionMark;
var flagsToCheck: NodeFlags = NodeFlags.Export | NodeFlags.Ambient | NodeFlags.Private | NodeFlags.Protected | NodeFlags.QuestionMark;
var someNodeFlags: NodeFlags = 0;
var allNodeFlags = flagsToCheck;
var hasOverloads = false;
@@ -6119,7 +6166,7 @@ module ts {
}
function getTargetSymbol(s: Symbol) {
// if symbol is instantiated it's flags are not copied from the 'target'
// if symbol is instantiated its flags are not copied from the 'target'
// so we'll need to get back original 'target' symbol to work with correct set of flags
return s.flags & SymbolFlags.Instantiated ? getSymbolLinks(s).target : s;
}

View File

@@ -138,9 +138,9 @@ module ts {
Type_0_is_not_assignable_to_type_1_Colon: { code: 2322, category: DiagnosticCategory.Error, key: "Type '{0}' is not assignable to type '{1}':" },
Type_0_is_not_assignable_to_type_1: { code: 2323, category: DiagnosticCategory.Error, key: "Type '{0}' is not assignable to type '{1}'." },
Property_0_is_missing_in_type_1: { code: 2324, category: DiagnosticCategory.Error, key: "Property '{0}' is missing in type '{1}'." },
Private_property_0_cannot_be_reimplemented: { code: 2325, category: DiagnosticCategory.Error, key: "Private property '{0}' cannot be reimplemented." },
Property_0_is_private_in_type_1_but_not_in_type_2: { code: 2325, category: DiagnosticCategory.Error, key: "Property '{0}' is private in type '{1}' but not in type '{2}'." },
Types_of_property_0_are_incompatible_Colon: { code: 2326, category: DiagnosticCategory.Error, key: "Types of property '{0}' are incompatible:" },
Required_property_0_cannot_be_reimplemented_with_optional_property_in_1: { code: 2327, category: DiagnosticCategory.Error, key: "Required property '{0}' cannot be reimplemented with optional property in '{1}'." },
Property_0_is_optional_in_type_1_but_required_in_type_2: { code: 2327, category: DiagnosticCategory.Error, key: "Property '{0}' is optional in type '{1}' but required in type '{2}'." },
Types_of_parameters_0_and_1_are_incompatible_Colon: { code: 2328, category: DiagnosticCategory.Error, key: "Types of parameters '{0}' and '{1}' are incompatible:" },
Index_signature_is_missing_in_type_0: { code: 2329, category: DiagnosticCategory.Error, key: "Index signature is missing in type '{0}'." },
Index_signatures_are_incompatible_Colon: { code: 2330, category: DiagnosticCategory.Error, key: "Index signatures are incompatible:" },
@@ -153,8 +153,8 @@ module ts {
Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors: { code: 2337, category: DiagnosticCategory.Error, key: "Super calls are not permitted outside constructors or in nested functions inside constructors" },
super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class: { code: 2338, category: DiagnosticCategory.Error, key: "'super' property access is permitted only in a constructor, member function, or member accessor of a derived class" },
Property_0_does_not_exist_on_type_1: { code: 2339, category: DiagnosticCategory.Error, key: "Property '{0}' does not exist on type '{1}'." },
Only_public_methods_of_the_base_class_are_accessible_via_the_super_keyword: { code: 2340, category: DiagnosticCategory.Error, key: "Only public methods of the base class are accessible via the 'super' keyword" },
Property_0_is_inaccessible: { code: 2341, category: DiagnosticCategory.Error, key: "Property '{0}' is inaccessible." },
Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword: { code: 2340, category: DiagnosticCategory.Error, key: "Only public and protected methods of the base class are accessible via the 'super' keyword" },
Property_0_is_private_and_only_accessible_within_class_1: { code: 2341, category: DiagnosticCategory.Error, key: "Property '{0}' is private and only accessible within class '{1}'." },
An_index_expression_argument_must_be_of_type_string_number_or_any: { code: 2342, category: DiagnosticCategory.Error, key: "An index expression argument must be of type 'string', 'number', or 'any'." },
Type_0_does_not_satisfy_the_constraint_1_Colon: { code: 2343, category: DiagnosticCategory.Error, key: "Type '{0}' does not satisfy the constraint '{1}':" },
Type_0_does_not_satisfy_the_constraint_1: { code: 2344, category: DiagnosticCategory.Error, key: "Type '{0}' does not satisfy the constraint '{1}'." },
@@ -198,7 +198,7 @@ module ts {
Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature: { code: 2382, category: DiagnosticCategory.Error, key: "Specialized overload signature is not assignable to any non-specialized signature." },
Overload_signatures_must_all_be_exported_or_not_exported: { code: 2383, category: DiagnosticCategory.Error, key: "Overload signatures must all be exported or not exported." },
Overload_signatures_must_all_be_ambient_or_non_ambient: { code: 2384, category: DiagnosticCategory.Error, key: "Overload signatures must all be ambient or non-ambient." },
Overload_signatures_must_all_be_public_or_private: { code: 2385, category: DiagnosticCategory.Error, key: "Overload signatures must all be public or private." },
Overload_signatures_must_all_be_public_private_or_protected: { code: 2385, category: DiagnosticCategory.Error, key: "Overload signatures must all be public, private or protected." },
Overload_signatures_must_all_be_optional_or_required: { code: 2386, category: DiagnosticCategory.Error, key: "Overload signatures must all be optional or required." },
Function_overload_must_be_static: { code: 2387, category: DiagnosticCategory.Error, key: "Function overload must be static." },
Function_overload_must_not_be_static: { code: 2388, category: DiagnosticCategory.Error, key: "Function overload must not be static." },
@@ -255,6 +255,11 @@ module ts {
Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name: { code: 2439, category: DiagnosticCategory.Error, key: "Import declaration in an ambient external module declaration cannot reference external module through relative external module name." },
Import_declaration_conflicts_with_local_declaration_of_0: { code: 2440, category: DiagnosticCategory.Error, key: "Import declaration conflicts with local declaration of '{0}'" },
Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module: { code: 2441, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler reserves name '{1}' in top level scope of an external module." },
Types_have_separate_declarations_of_a_private_property_0: { code: 2442, category: DiagnosticCategory.Error, key: "Types have separate declarations of a private property '{0}'." },
Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2: { code: 2443, category: DiagnosticCategory.Error, key: "Property '{0}' is protected but type '{1}' is not a class derived from '{2}'." },
Property_0_is_protected_in_type_1_but_public_in_type_2: { code: 2444, category: DiagnosticCategory.Error, key: "Property '{0}' is protected in type '{1}' but public in type '{2}'." },
Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: { code: 2445, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible within class '{1}' and its subclasses." },
Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." },
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
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}'." },

View File

@@ -544,7 +544,7 @@
"category": "Error",
"code": 2324
},
"Private property '{0}' cannot be reimplemented.": {
"Property '{0}' is private in type '{1}' but not in type '{2}'.": {
"category": "Error",
"code": 2325
},
@@ -552,7 +552,7 @@
"category": "Error",
"code": 2326
},
"Required property '{0}' cannot be reimplemented with optional property in '{1}'.": {
"Property '{0}' is optional in type '{1}' but required in type '{2}'.": {
"category": "Error",
"code": 2327
},
@@ -604,11 +604,11 @@
"category": "Error",
"code": 2339
},
"Only public methods of the base class are accessible via the 'super' keyword": {
"Only public and protected methods of the base class are accessible via the 'super' keyword": {
"category": "Error",
"code": 2340
},
"Property '{0}' is inaccessible.": {
"Property '{0}' is private and only accessible within class '{1}'.": {
"category": "Error",
"code": 2341
},
@@ -784,7 +784,7 @@
"category": "Error",
"code": 2384
},
"Overload signatures must all be public or private.": {
"Overload signatures must all be public, private or protected.": {
"category": "Error",
"code": 2385
},
@@ -1012,7 +1012,26 @@
"category": "Error",
"code": 2441
},
"Types have separate declarations of a private property '{0}'.": {
"category": "Error",
"code": 2442
},
"Property '{0}' is protected but type '{1}' is not a class derived from '{2}'.": {
"category": "Error",
"code": 2443
},
"Property '{0}' is protected in type '{1}' but public in type '{2}'.": {
"category": "Error",
"code": 2444
},
"Property '{0}' is protected and only accessible within class '{1}' and its subclasses.": {
"category": "Error",
"code": 2445
},
"Property '{0}' is protected and only accessible through an instance of class '{1}'.": {
"category": "Error",
"code": 2446
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",

View File

@@ -2371,12 +2371,18 @@ module ts {
if (node.flags & NodeFlags.Private) {
write("private ");
}
else if (node.flags & NodeFlags.Protected) {
write("protected ");
}
write("static ");
}
else {
if (node.flags & NodeFlags.Private) {
write("private ");
}
else if (node.flags & NodeFlags.Protected) {
write("protected ");
}
// If the node is parented in the current source file we need to emit export declare or just export
else if (node.parent === currentSourceFile) {
// If the node is exported

View File

@@ -656,6 +656,7 @@ module ts {
switch (token) {
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
case SyntaxKind.StaticKeyword:
case SyntaxKind.ExportKeyword:
case SyntaxKind.DeclareKeyword:
@@ -2981,6 +2982,7 @@ module ts {
}
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
case SyntaxKind.StaticKeyword:
// When followed by an identifier or keyword, these do not start a statement but
// might instead be following type members
@@ -3299,6 +3301,8 @@ module ts {
var lastDeclareModifierLength: number;
var lastPrivateModifierStart: number;
var lastPrivateModifierLength: number;
var lastProtectedModifierStart: number;
var lastProtectedModifierLength: number;
while (true) {
var modifierStart = scanner.getTokenPos();
@@ -3338,6 +3342,21 @@ module ts {
flags |= NodeFlags.Private;
break;
case SyntaxKind.ProtectedKeyword:
if (flags & NodeFlags.Public || flags & NodeFlags.Private || flags & NodeFlags.Protected) {
grammarErrorAtPos(modifierStart, modifierLength, Diagnostics.Accessibility_modifier_already_seen);
}
else if (flags & NodeFlags.Static) {
grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_must_precede_1_modifier, "protected", "static");
}
else if (context === ModifierContext.ModuleElements || context === ModifierContext.SourceElements) {
grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_cannot_appear_on_a_module_element, "protected");
}
lastProtectedModifierStart = modifierStart;
lastProtectedModifierLength = modifierLength;
flags |= NodeFlags.Protected;
break;
case SyntaxKind.StaticKeyword:
if (flags & NodeFlags.Static) {
grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_already_seen, "static");
@@ -3395,6 +3414,9 @@ module ts {
else if (token === SyntaxKind.ConstructorKeyword && flags & NodeFlags.Private) {
grammarErrorAtPos(lastPrivateModifierStart, lastPrivateModifierLength, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private");
}
else if (token === SyntaxKind.ConstructorKeyword && flags & NodeFlags.Protected) {
grammarErrorAtPos(lastProtectedModifierStart, lastProtectedModifierLength, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected");
}
else if (token === SyntaxKind.ImportKeyword) {
if (flags & NodeFlags.Ambient) {
grammarErrorAtPos(lastDeclareModifierStart, lastDeclareModifierLength, Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare");
@@ -3671,6 +3693,7 @@ module ts {
case SyntaxKind.DeclareKeyword:
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
case SyntaxKind.StaticKeyword:
// Check for modifier on source element
return lookAhead(() => { nextToken(); return isDeclaration(); });

View File

@@ -238,13 +238,14 @@ module ts {
Rest = 0x00000008, // Parameter
Public = 0x00000010, // Property/Method
Private = 0x00000020, // Property/Method
Static = 0x00000040, // Property/Method
MultiLine = 0x00000080, // Multi-line array or object literal
Synthetic = 0x00000100, // Synthetic node (for full fidelity)
DeclarationFile = 0x00000200, // Node is a .d.ts file
Protected = 0x00000040, // Property/Method
Static = 0x00000080, // Property/Method
MultiLine = 0x00000100, // Multi-line array or object literal
Synthetic = 0x00000200, // Synthetic node (for full fidelity)
DeclarationFile = 0x00000400, // Node is a .d.ts file
Modifier = Export | Ambient | Public | Private | Static,
AccessibilityModifier = Public | Private
Modifier = Export | Ambient | Public | Private | Protected | Static,
AccessibilityModifier = Public | Private | Protected
}
export interface Node extends TextRange {

View File

@@ -42,6 +42,10 @@ module TypeScript {
walker.walk(preAst.typeArguments);
}
function walkTupleTypeChildren(preAst: TupleTypeSyntax, walker: AstWalker): void {
walker.walk(preAst.types);
}
function walkTypeOfExpressionChildren(preAst: TypeOfExpressionSyntax, walker: AstWalker): void {
walker.walk(preAst.expression);
}
@@ -561,6 +565,7 @@ module TypeScript {
childrenWalkers[SyntaxKind.TriviaList] = null;
childrenWalkers[SyntaxKind.TrueKeyword] = null;
childrenWalkers[SyntaxKind.TryStatement] = walkTryStatementChildren;
childrenWalkers[SyntaxKind.TupleType] = walkTupleTypeChildren;
childrenWalkers[SyntaxKind.TypeAnnotation] = walkTypeAnnotationChildren;
childrenWalkers[SyntaxKind.TypeArgumentList] = walkTypeArgumentListChildren;
childrenWalkers[SyntaxKind.TypeOfExpression] = walkTypeOfExpressionChildren;

View File

@@ -42,6 +42,10 @@ module TypeScript {
return this.defaultVisit(node);
}
public visitTupleType(node: TupleTypeSyntax): any {
return this.defaultVisit(node);
}
public visitInterfaceDeclaration(node: InterfaceDeclarationSyntax): any {
return this.defaultVisit(node);
}

View File

@@ -1048,6 +1048,7 @@ module TypeScript.Parser {
case SyntaxKind.ExportKeyword:
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
case SyntaxKind.StaticKeyword:
case SyntaxKind.DeclareKeyword:
return true;
@@ -1434,6 +1435,19 @@ module TypeScript.Parser {
return new syntaxFactory.ObjectTypeSyntax(parseNodeData, openBraceToken, typeMembers, eatToken(SyntaxKind.CloseBraceToken));
}
function parseTupleType(currentToken: ISyntaxToken): TupleTypeSyntax {
var openBracket = consumeToken(currentToken);
var types = Syntax.emptySeparatedList<ITypeSyntax>();
if (openBracket.fullWidth() > 0) {
var skippedTokens: ISyntaxToken[] = getArray();
types = parseSeparatedSyntaxList<ITypeSyntax>(ListParsingState.TupleType_Types, skippedTokens);
openBracket = addSkippedTokensAfterToken(openBracket, skippedTokens);
}
return new syntaxFactory.TupleTypeSyntax(parseNodeData, openBracket, types, eatToken(SyntaxKind.CloseBracketToken));
}
function isTypeMember(inErrorRecovery: boolean): boolean {
if (SyntaxUtilities.isTypeMember(currentNode())) {
return true;
@@ -1663,6 +1677,7 @@ module TypeScript.Parser {
// ERROR RECOVERY
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
case SyntaxKind.StaticKeyword:
// None of the above are actually keywords. And they might show up in a real
// statement (i.e. "public();"). However, if we see 'public <identifier>' then
@@ -1731,6 +1746,7 @@ module TypeScript.Parser {
// ERROR RECOVERY
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
case SyntaxKind.StaticKeyword:
// None of the above are actually keywords. And they might show up in a real
// statement (i.e. "public();"). However, if we see 'public <identifier>' then
@@ -3133,7 +3149,7 @@ module TypeScript.Parser {
token2 = peekToken(2);
token2Kind = token2.kind();
if (token1Kind === SyntaxKind.PublicKeyword || token1Kind === SyntaxKind.PrivateKeyword) {
if (SyntaxFacts.isAccessibilityModifier(token1Kind)) {
if (isIdentifier(token2)) {
// "(public id" or "(function id". Definitely an arrow function. Could never
// be a parenthesized expression. Note: this will be an *illegal* arrow
@@ -3557,11 +3573,12 @@ module TypeScript.Parser {
return consumeToken(_currentToken);
case SyntaxKind.OpenParenToken:
case SyntaxKind.LessThanToken: return tryParseFunctionType();
case SyntaxKind.VoidKeyword: return consumeToken(_currentToken);
case SyntaxKind.OpenBraceToken: return parseObjectType();
case SyntaxKind.NewKeyword: return parseConstructorType();
case SyntaxKind.TypeOfKeyword: return parseTypeQuery(_currentToken);
case SyntaxKind.LessThanToken: return tryParseFunctionType();
case SyntaxKind.VoidKeyword: return consumeToken(_currentToken);
case SyntaxKind.OpenBraceToken: return parseObjectType();
case SyntaxKind.NewKeyword: return parseConstructorType();
case SyntaxKind.TypeOfKeyword: return parseTypeQuery(_currentToken);
case SyntaxKind.OpenBracketToken: return parseTupleType(_currentToken);
}
return tryParseNameOrGenericType();
@@ -3973,6 +3990,7 @@ module TypeScript.Parser {
case ListParsingState.IndexSignature_Parameters: return isExpectedIndexSignature_ParametersTerminator();
case ListParsingState.TypeArgumentList_Types: return isExpectedTypeArgumentList_TypesTerminator();
case ListParsingState.TypeParameterList_TypeParameters: return isExpectedTypeParameterList_TypeParametersTerminator();
case ListParsingState.TupleType_Types: return isExpectedTupleType_TypesTerminator();
default:
throw Errors.invalidOperation();
}
@@ -4019,6 +4037,17 @@ module TypeScript.Parser {
return false;
}
function isExpectedTupleType_TypesTerminator(): boolean {
var token = currentToken();
var tokenKind = token.kind();
if (tokenKind === SyntaxKind.CloseBracketToken) {
return true;
}
// TODO: add more cases as necessary for error tolerance.
return false;
}
function isExpectedTypeParameterList_TypeParametersTerminator(): boolean {
var tokenKind = currentToken().kind();
if (tokenKind === SyntaxKind.GreaterThanToken) {
@@ -4187,6 +4216,7 @@ module TypeScript.Parser {
case ListParsingState.IndexSignature_Parameters: return isParameter();
case ListParsingState.TypeArgumentList_Types: return isType();
case ListParsingState.TypeParameterList_TypeParameters: return isTypeParameter();
case ListParsingState.TupleType_Types: return isType();
default: throw Errors.invalidOperation();
}
}
@@ -4230,6 +4260,7 @@ module TypeScript.Parser {
case ListParsingState.IndexSignature_Parameters: return tryParseParameter();
case ListParsingState.TypeArgumentList_Types: return tryParseType();
case ListParsingState.TypeParameterList_TypeParameters: return tryParseTypeParameter();
case ListParsingState.TupleType_Types: return tryParseType();
default: throw Errors.invalidOperation();
}
}
@@ -4254,6 +4285,7 @@ module TypeScript.Parser {
case ListParsingState.IndexSignature_Parameters: return getLocalizedText(DiagnosticCode.parameter, null);
case ListParsingState.TypeArgumentList_Types: return getLocalizedText(DiagnosticCode.type, null);
case ListParsingState.TypeParameterList_TypeParameters: return getLocalizedText(DiagnosticCode.type_parameter, null);
case ListParsingState.TupleType_Types: return getLocalizedText(DiagnosticCode.type, null);
case ListParsingState.ArrayLiteralExpression_AssignmentExpressions: return getLocalizedText(DiagnosticCode.expression, null);
default: throw Errors.invalidOperation();
}
@@ -4376,9 +4408,10 @@ module TypeScript.Parser {
IndexSignature_Parameters = 18,
TypeArgumentList_Types = 19,
TypeParameterList_TypeParameters = 20,
TupleType_Types = 21,
FirstListParsingState = SourceUnit_ModuleElements,
LastListParsingState = TypeParameterList_TypeParameters,
LastListParsingState = TupleType_Types,
}
// We keep the parser around as a singleton. This is because calling createParser is actually

View File

@@ -421,6 +421,12 @@ module TypeScript.PrettyPrinter {
this.appendToken(node.greaterThanToken);
}
public visitTupleType(node: TupleTypeSyntax): void {
this.appendToken(node.openBracketToken);
this.appendSeparatorSpaceList(node.types);
this.appendToken(node.closeBracketToken);
}
public visitConstructorType(node: ConstructorTypeSyntax): void {
this.appendToken(node.newKeyword);
this.ensureSpace();

View File

@@ -26,4 +26,15 @@ module TypeScript.SyntaxFacts {
var tokenKind = token.kind();
return tokenKind === SyntaxKind.IdentifierName || SyntaxFacts.isAnyKeyword(tokenKind);
}
export function isAccessibilityModifier(kind: SyntaxKind): boolean {
switch (kind) {
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
return true;
}
return false;
}
}

View File

@@ -354,6 +354,17 @@ var definitions:ITypeDefinition[] = [
],
isTypeScriptSpecific: true
},
<any> {
name: 'TupleTypeSyntax',
baseType: 'ISyntaxNode',
interfaces: ['ITypeSyntax'],
children: [
<any>{ name: 'openBracketToken', isToken: true, excludeFromAST: true },
<any>{ name: 'types', isSeparatedList: true, elementType: 'ITypeSyntax' },
<any>{ name: 'closeBracketToken', isToken: true, excludeFromAST: true }
],
isTypeScriptSpecific: true
},
<any>{
name: 'TypeAnnotationSyntax',
baseType: 'ISyntaxNode',

View File

@@ -158,6 +158,7 @@ module TypeScript {
ConstructorType,
GenericType,
TypeQuery,
TupleType,
// Module elements.
InterfaceDeclaration,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -84,6 +84,7 @@ module TypeScript {
private cacheSyntaxTreeInfo(): void {
// If we're not keeping around the syntax tree, store the diagnostics and line
// map so they don't have to be recomputed.
var sourceUnit = this.sourceUnit();
var firstToken = firstSyntaxTreeToken(this);
var leadingTrivia = firstToken.leadingTrivia(this.text);
@@ -238,7 +239,7 @@ module TypeScript {
}
private checkParameterAccessibilityModifier(parameterList: ParameterListSyntax, modifier: ISyntaxToken, modifierIndex: number): boolean {
if (modifier.kind() !== SyntaxKind.PublicKeyword && modifier.kind() !== SyntaxKind.PrivateKeyword) {
if (!SyntaxFacts.isAccessibilityModifier(modifier.kind())) {
this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_cannot_appear_on_a_parameter, [modifier.text()]);
return true;
}
@@ -320,6 +321,15 @@ module TypeScript {
super.visitTypeArgumentList(node);
}
public visitTupleType(node: TupleTypeSyntax): void {
if (this.checkForTrailingComma(node.types) ||
this.checkForAtLeastOneElement(node, node.types, node.openBracketToken, getLocalizedText(DiagnosticCode.type, null))) {
return
}
super.visitTupleType(node);
}
public visitTypeParameterList(node: TypeParameterListSyntax): void {
if (this.checkForTrailingComma(node.typeParameters) ||
this.checkForAtLeastOneElement(node, node.typeParameters, node.lessThanToken, getLocalizedText(DiagnosticCode.type_parameter, null))) {
@@ -514,9 +524,7 @@ module TypeScript {
for (var i = 0, n = list.length; i < n; i++) {
var modifier = list[i];
if (modifier.kind() === SyntaxKind.PublicKeyword ||
modifier.kind() === SyntaxKind.PrivateKeyword) {
if (SyntaxFacts.isAccessibilityModifier(modifier.kind())) {
if (seenAccessibilityModifier) {
this.pushDiagnostic(modifier, DiagnosticCode.Accessibility_modifier_already_seen);
return true;
@@ -751,8 +759,7 @@ module TypeScript {
for (var i = 0, n = modifiers.length; i < n; i++) {
var modifier = modifiers[i];
if (modifier.kind() === SyntaxKind.PublicKeyword ||
modifier.kind() === SyntaxKind.PrivateKeyword ||
if (SyntaxFacts.isAccessibilityModifier(modifier.kind()) ||
modifier.kind() === SyntaxKind.StaticKeyword) {
this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_cannot_appear_on_a_module_element, [modifier.text()]);
return true;

View File

@@ -13,6 +13,7 @@ module TypeScript {
case SyntaxKind.ConstructorType: return visitor.visitConstructorType(<ConstructorTypeSyntax>element);
case SyntaxKind.GenericType: return visitor.visitGenericType(<GenericTypeSyntax>element);
case SyntaxKind.TypeQuery: return visitor.visitTypeQuery(<TypeQuerySyntax>element);
case SyntaxKind.TupleType: return visitor.visitTupleType(<TupleTypeSyntax>element);
case SyntaxKind.InterfaceDeclaration: return visitor.visitInterfaceDeclaration(<InterfaceDeclarationSyntax>element);
case SyntaxKind.FunctionDeclaration: return visitor.visitFunctionDeclaration(<FunctionDeclarationSyntax>element);
case SyntaxKind.ModuleDeclaration: return visitor.visitModuleDeclaration(<ModuleDeclarationSyntax>element);
@@ -109,6 +110,7 @@ module TypeScript {
visitConstructorType(node: ConstructorTypeSyntax): any;
visitGenericType(node: GenericTypeSyntax): any;
visitTypeQuery(node: TypeQuerySyntax): any;
visitTupleType(node: TupleTypeSyntax): any;
visitInterfaceDeclaration(node: InterfaceDeclarationSyntax): any;
visitFunctionDeclaration(node: FunctionDeclarationSyntax): any;
visitModuleDeclaration(node: ModuleDeclarationSyntax): any;

View File

@@ -103,6 +103,12 @@ module TypeScript {
this.visitNodeOrToken(node.name);
}
public visitTupleType(node: TupleTypeSyntax): void {
this.visitToken(node.openBracketToken);
this.visitSeparatedList(node.types);
this.visitToken(node.closeBracketToken);
}
public visitInterfaceDeclaration(node: InterfaceDeclarationSyntax): void {
this.visitList(node.modifiers);
this.visitToken(node.interfaceKeyword);