Skip to content

Commit 4115077

Browse files
committed
Report privacy errors on parameter types
1 parent 4b12353 commit 4115077

File tree

7 files changed

+2915
-9
lines changed

7 files changed

+2915
-9
lines changed

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,20 @@ module ts {
120120
Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2029, category: DiagnosticCategory.Error, key: "Public property '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
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}'." },
123+
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_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}'." },
125+
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}'." },
126+
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}'." },
127+
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}'." },
128+
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}'." },
129+
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}'." },
130+
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}'." },
131+
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}'." },
132+
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}'." },
133+
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}'." },
134+
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}'." },
135+
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}'." },
136+
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}'." },
123137
Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 2208, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." },
124138
Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 2209, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of call signature from exported interface has or is using private name '{1}'." },
125139
Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 2210, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public static method from exported class has or is using private name '{1}'." },

src/compiler/diagnosticMessages.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,62 @@
472472
"category": "Error",
473473
"code": 2031
474474
},
475+
"Parameter '{0}' of constructor from exported class has or is using private name '{1}'.": {
476+
"category": "Error",
477+
"code": 2032
478+
},
479+
"Parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'.": {
480+
"category": "Error",
481+
"code": 2035
482+
},
483+
"Parameter '{0}' of call signature from exported interface has or is using private name '{1}'.": {
484+
"category": "Error",
485+
"code": 2036
486+
},
487+
"Parameter '{0}' of public static method from exported class has or is using private name '{1}'.": {
488+
"category": "Error",
489+
"code": 2037
490+
},
491+
"Parameter '{0}' of public method from exported class has or is using private name '{1}'.": {
492+
"category": "Error",
493+
"code": 2038
494+
},
495+
"Parameter '{0}' of method from exported interface has or is using private name '{1}'.": {
496+
"category": "Error",
497+
"code": 2039
498+
},
499+
"Parameter '{0}' of exported function has or is using private name '{1}'.": {
500+
"category": "Error",
501+
"code": 2040
502+
},
503+
"Parameter '{0}' of constructor from exported class has or is using name '{1}' from private module '{2}'.": {
504+
"category": "Error",
505+
"code": 2041
506+
},
507+
"Parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'.": {
508+
"category": "Error",
509+
"code": 2044
510+
},
511+
"Parameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'.": {
512+
"category": "Error",
513+
"code": 2045
514+
},
515+
"Parameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'.": {
516+
"category": "Error",
517+
"code": 2046
518+
},
519+
"Parameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'.": {
520+
"category": "Error",
521+
"code": 2047
522+
},
523+
"Parameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'.": {
524+
"category": "Error",
525+
"code": 2048
526+
},
527+
"Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'.": {
528+
"category": "Error",
529+
"code": 2049
530+
},
475531
"Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'.": {
476532
"category": "Error",
477533
"code": 2208

src/compiler/emitter.ts

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,11 +1908,13 @@ module ts {
19081908
// Report error
19091909
reportedDeclarationError = true;
19101910
var errorInfo = getSymbolVisibilityDiagnosticMessage(symbolAccesibilityResult);
1911-
diagnostics.push(createDiagnosticForNode(errorInfo.errorNode,
1912-
errorInfo.diagnosticMessage,
1913-
getSourceTextOfLocalNode(errorInfo.typeName),
1914-
symbolAccesibilityResult.errorSymbolName,
1915-
symbolAccesibilityResult.errorModuleName));
1911+
if (errorInfo) {
1912+
diagnostics.push(createDiagnosticForNode(errorInfo.errorNode,
1913+
errorInfo.diagnosticMessage,
1914+
getSourceTextOfLocalNode(errorInfo.typeName),
1915+
symbolAccesibilityResult.errorSymbolName,
1916+
symbolAccesibilityResult.errorModuleName));
1917+
}
19161918
}
19171919
}
19181920

@@ -2290,7 +2292,8 @@ module ts {
22902292
Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 :
22912293
Diagnostics.Exported_variable_0_has_or_is_using_private_name_1;
22922294
}
2293-
else {
2295+
// This check is to ensure we dont report error on constructor parameter property as that error would be reported during parameter emit
2296+
else if (node.kind === SyntaxKind.Property) {
22942297
if (node.flags & NodeFlags.Static) {
22952298
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
22962299
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
@@ -2308,11 +2311,11 @@ module ts {
23082311
}
23092312
}
23102313

2311-
return {
2314+
return diagnosticMessage !== undefined ? {
23122315
diagnosticMessage: diagnosticMessage,
23132316
errorNode: node,
23142317
typeName: node.name
2315-
};
2318+
} : undefined;
23162319
}
23172320
}
23182321

@@ -2408,7 +2411,67 @@ module ts {
24082411

24092412
if (!(node.parent.flags & NodeFlags.Private)) {
24102413
write(": ");
2414+
getSymbolVisibilityDiagnosticMessage = getParameterDeclarationTypeVisibilityError;
24112415
resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.None, writer);
2416+
// TODO(shkamat) This is just till we get rest of the error reporting up
2417+
getSymbolVisibilityDiagnosticMessage = undefined;
2418+
}
2419+
2420+
function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
2421+
// TODO(shkamat) Cannot access name errors
2422+
var diagnosticMessage: DiagnosticMessage;
2423+
switch (node.parent.kind) {
2424+
case SyntaxKind.Constructor:
2425+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2426+
Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
2427+
Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1;
2428+
break;
2429+
2430+
case SyntaxKind.ConstructSignature:
2431+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2432+
Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
2433+
Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
2434+
break;
2435+
2436+
case SyntaxKind.CallSignature:
2437+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2438+
Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
2439+
Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
2440+
break;
2441+
2442+
case SyntaxKind.Method:
2443+
if (node.parent.flags & NodeFlags.Static) {
2444+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2445+
Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
2446+
Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
2447+
}
2448+
else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
2449+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2450+
Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
2451+
Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
2452+
}
2453+
else {
2454+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2455+
Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
2456+
Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
2457+
}
2458+
break;
2459+
2460+
case SyntaxKind.FunctionDeclaration:
2461+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2462+
Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 :
2463+
Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1;
2464+
break;
2465+
2466+
default:
2467+
Debug.fail("This is unknown parent for parameter: " + SyntaxKind[node.parent.kind]);
2468+
}
2469+
2470+
return {
2471+
diagnosticMessage: diagnosticMessage,
2472+
errorNode: node,
2473+
typeName: node.name
2474+
};
24122475
}
24132476
}
24142477

tests/baselines/reference/declInput-2.errors.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
==== tests/cases/compiler/declInput-2.ts (2 errors) ====
1+
==== tests/cases/compiler/declInput-2.ts (3 errors) ====
22
module M {
33
class C { }
44
export class E {}
@@ -21,6 +21,8 @@
2121
public m252(): I2 { return null; } // don't generate
2222
public m26(i:I1) {}
2323
public m262(i:I2) {}
24+
~~~~
25+
!!! Parameter 'i' of public method from exported class has or is using private name 'I2'.
2426
public m3():C { return new C(); }
2527
}
2628
}

0 commit comments

Comments
 (0)