Skip to content

Commit 2654eed

Browse files
committed
Report privacy errors for accessors
1 parent 4cd2d3f commit 2654eed

12 files changed

+6553
-445
lines changed

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,26 +121,34 @@ module ts {
121121
Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2030, category: DiagnosticCategory.Error, key: "Property '{0}' of exported interface has or is using name '{1}' from private module '{2}'." },
122122
Exported_variable_0_has_or_is_using_name_1_from_private_module_2: { code: 2031, category: DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using name '{1}' from private module '{2}'." },
123123
Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1: { code: 2032, category: DiagnosticCategory.Error, key: "Parameter '{0}' of constructor from exported class has or is using private name '{1}'." },
124+
Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1: { code: 2033, category: DiagnosticCategory.Error, key: "Parameter '{0}' of public static property setter from exported class has or is using private name '{1}'." },
125+
Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1: { code: 2034, category: DiagnosticCategory.Error, key: "Parameter '{0}' of public property setter from exported class has or is using private name '{1}'." },
124126
Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 2035, category: DiagnosticCategory.Error, key: "Parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." },
125127
Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 2036, category: DiagnosticCategory.Error, key: "Parameter '{0}' of call signature from exported interface has or is using private name '{1}'." },
126128
Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 2037, category: DiagnosticCategory.Error, key: "Parameter '{0}' of public static method from exported class has or is using private name '{1}'." },
127129
Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: { code: 2038, category: DiagnosticCategory.Error, key: "Parameter '{0}' of public method from exported class has or is using private name '{1}'." },
128130
Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: { code: 2039, category: DiagnosticCategory.Error, key: "Parameter '{0}' of method from exported interface has or is using private name '{1}'." },
129131
Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 2040, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." },
130132
Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2041, category: DiagnosticCategory.Error, key: "Parameter '{0}' of constructor from exported class has or is using name '{1}' from private module '{2}'." },
133+
Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2042, category: DiagnosticCategory.Error, key: "Parameter '{0}' of public static property setter from exported class has or is using name '{1}' from private module '{2}'." },
134+
Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2043, category: DiagnosticCategory.Error, key: "Parameter '{0}' of public property setter from exported class has or is using name '{1}' from private module '{2}'." },
131135
Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2044, category: DiagnosticCategory.Error, key: "Parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'." },
132136
Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2045, category: DiagnosticCategory.Error, key: "Parameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'." },
133137
Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2046, category: DiagnosticCategory.Error, key: "Parameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'." },
134138
Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2047, category: DiagnosticCategory.Error, key: "Parameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'." },
135139
Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2048, category: DiagnosticCategory.Error, key: "Parameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'." },
136140
Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 2049, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
141+
Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0: { code: 2050, category: DiagnosticCategory.Error, key: "Return type of public static property getter from exported class has or is using private name '{0}'." },
142+
Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0: { code: 2051, category: DiagnosticCategory.Error, key: "Return type of public property getter from exported class has or is using private name '{0}'." },
137143
Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0: { code: 2052, category: DiagnosticCategory.Error, key: "Return type of constructor signature from exported interface has or is using private name '{0}'." },
138144
Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0: { code: 2053, category: DiagnosticCategory.Error, key: "Return type of call signature from exported interface has or is using private name '{0}'." },
139145
Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0: { code: 2054, category: DiagnosticCategory.Error, key: "Return type of index signature from exported interface has or is using private name '{0}'." },
140146
Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0: { code: 2055, category: DiagnosticCategory.Error, key: "Return type of public static method from exported class has or is using private name '{0}'." },
141147
Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0: { code: 2056, category: DiagnosticCategory.Error, key: "Return type of public method from exported class has or is using private name '{0}'." },
142148
Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0: { code: 2057, category: DiagnosticCategory.Error, key: "Return type of method from exported interface has or is using private name '{0}'." },
143149
Return_type_of_exported_function_has_or_is_using_private_name_0: { code: 2058, category: DiagnosticCategory.Error, key: "Return type of exported function has or is using private name '{0}'." },
150+
Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1: { code: 2059, category: DiagnosticCategory.Error, key: "Return type of public static property getter from exported class has or is using name '{0}' from private module '{1}'." },
151+
Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1: { code: 2060, category: DiagnosticCategory.Error, key: "Return type of public property getter from exported class has or is using name '{0}' from private module '{1}'." },
144152
Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1: { code: 2061, category: DiagnosticCategory.Error, key: "Return type of constructor signature from exported interface has or is using name '{0}' from private module '{1}'." },
145153
Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1: { code: 2062, category: DiagnosticCategory.Error, key: "Return type of call signature from exported interface has or is using name '{0}' from private module '{1}'." },
146154
Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1: { code: 2063, category: DiagnosticCategory.Error, key: "Return type of index signature from exported interface has or is using name '{0}' from private module '{1}'." },

src/compiler/diagnosticMessages.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,14 @@
476476
"category": "Error",
477477
"code": 2032
478478
},
479+
"Parameter '{0}' of public static property setter from exported class has or is using private name '{1}'.": {
480+
"category": "Error",
481+
"code": 2033
482+
},
483+
"Parameter '{0}' of public property setter from exported class has or is using private name '{1}'.": {
484+
"category": "Error",
485+
"code": 2034
486+
},
479487
"Parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'.": {
480488
"category": "Error",
481489
"code": 2035
@@ -504,6 +512,14 @@
504512
"category": "Error",
505513
"code": 2041
506514
},
515+
"Parameter '{0}' of public static property setter from exported class has or is using name '{1}' from private module '{2}'.": {
516+
"category": "Error",
517+
"code": 2042
518+
},
519+
"Parameter '{0}' of public property setter from exported class has or is using name '{1}' from private module '{2}'.": {
520+
"category": "Error",
521+
"code": 2043
522+
},
507523
"Parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'.": {
508524
"category": "Error",
509525
"code": 2044
@@ -528,6 +544,14 @@
528544
"category": "Error",
529545
"code": 2049
530546
},
547+
"Return type of public static property getter from exported class has or is using private name '{0}'.": {
548+
"category": "Error",
549+
"code": 2050
550+
},
551+
"Return type of public property getter from exported class has or is using private name '{0}'.": {
552+
"category": "Error",
553+
"code": 2051
554+
},
531555
"Return type of constructor signature from exported interface has or is using private name '{0}'.": {
532556
"category": "Error",
533557
"code": 2052
@@ -556,6 +580,14 @@
556580
"category": "Error",
557581
"code": 2058
558582
},
583+
"Return type of public static property getter from exported class has or is using name '{0}' from private module '{1}'.": {
584+
"category": "Error",
585+
"code": 2059
586+
},
587+
"Return type of public property getter from exported class has or is using name '{0}' from private module '{1}'.": {
588+
"category": "Error",
589+
"code": 2060
590+
},
559591
"Return type of constructor signature from exported interface has or is using name '{0}' from private module '{1}'.": {
560592
"category": "Error",
561593
"code": 2061

src/compiler/emitter.ts

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,8 +1884,7 @@ module ts {
18841884

18851885
function writeSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) {
18861886
var symbolAccesibilityResult = resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning);
1887-
// TODO(shkamat): Since we dont have error reporting for all the cases as yet we have this check on handler being present
1888-
if (!getSymbolVisibilityDiagnosticMessage || symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) {
1887+
if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) {
18891888
resolver.writeSymbol(symbol, enclosingDeclaration, meaning, writer);
18901889

18911890
// write the aliases
@@ -2139,8 +2138,6 @@ module ts {
21392138
write(" extends ");
21402139
getSymbolVisibilityDiagnosticMessage = getTypeParameterConstraintVisibilityError;
21412140
resolver.writeTypeAtLocation(node.constraint, enclosingDeclaration, TypeFormatFlags.None, writer);
2142-
// TODO(shkamat) This is just till we get rest of the error reporting up
2143-
getSymbolVisibilityDiagnosticMessage = undefined;
21442141
}
21452142
}
21462143

@@ -2160,8 +2157,6 @@ module ts {
21602157
function emitTypeOfTypeReference(node: Node) {
21612158
getSymbolVisibilityDiagnosticMessage = getHeritageClauseVisibilityError;
21622159
resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.WriteArrayAsGenericType, writer);
2163-
// TODO(shkamat) This is just till we get rest of the error reporting up
2164-
getSymbolVisibilityDiagnosticMessage = undefined;
21652160

21662161
function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
21672162
var diagnosticMessage: DiagnosticMessage;
@@ -2287,8 +2282,6 @@ module ts {
22872282
write(": ");
22882283
getSymbolVisibilityDiagnosticMessage = getVariableDeclarationTypeVisibilityError;
22892284
resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.None, writer);
2290-
// TODO(shkamat) This is just till we get rest of the error reporting up
2291-
getSymbolVisibilityDiagnosticMessage = undefined;
22922285
}
22932286
}
22942287

@@ -2345,11 +2338,51 @@ module ts {
23452338
emitSourceTextOfNode(node.name);
23462339
if (!(node.flags & NodeFlags.Private)) {
23472340
write(": ");
2341+
getSymbolVisibilityDiagnosticMessage = getAccessorDeclarationTypeVisibilityError;
23482342
resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.None, writer);
23492343
}
23502344
write(";");
23512345
writeLine();
23522346
}
2347+
2348+
function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
2349+
// TODO(shkamat) Cannot access name errors
2350+
var diagnosticMessage: DiagnosticMessage;
2351+
if (node.kind === SyntaxKind.SetAccessor) {
2352+
if (node.parent.flags & NodeFlags.Static) {
2353+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2354+
Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
2355+
Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1;
2356+
}
2357+
else {
2358+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2359+
Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
2360+
Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1;
2361+
}
2362+
return {
2363+
diagnosticMessage: diagnosticMessage,
2364+
errorNode: node.parameters[0],
2365+
typeName: node.name
2366+
};
2367+
}
2368+
else {
2369+
if (node.flags & NodeFlags.Static) {
2370+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2371+
Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
2372+
Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0;
2373+
}
2374+
else {
2375+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2376+
Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
2377+
Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0;
2378+
}
2379+
return {
2380+
diagnosticMessage: diagnosticMessage,
2381+
errorNode: node.name,
2382+
typeName: undefined
2383+
};
2384+
}
2385+
}
23532386
}
23542387

23552388
function emitFunctionDeclaration(node: FunctionDeclaration) {
@@ -2404,8 +2437,6 @@ module ts {
24042437
write(": ");
24052438
getSymbolVisibilityDiagnosticMessage = getReturnTypeVisibilityError;
24062439
resolver.writeReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, TypeFormatFlags.None, writer);
2407-
// TODO(shkamat) This is just till we get rest of the error reporting up
2408-
getSymbolVisibilityDiagnosticMessage = undefined;
24092440
}
24102441
write(";");
24112442
writeLine();
@@ -2481,8 +2512,6 @@ module ts {
24812512
write(": ");
24822513
getSymbolVisibilityDiagnosticMessage = getParameterDeclarationTypeVisibilityError;
24832514
resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.None, writer);
2484-
// TODO(shkamat) This is just till we get rest of the error reporting up
2485-
getSymbolVisibilityDiagnosticMessage = undefined;
24862515
}
24872516

24882517
function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {

0 commit comments

Comments
 (0)