Skip to content

Commit 00b4c2e

Browse files
committed
Report errors on properties and variable type visibility
Fixes #69
1 parent 5c4009a commit 00b4c2e

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ module ts {
112112
Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 2021, category: DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." },
113113
Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 2022, category: DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." },
114114
Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2: { code: 2023, category: DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'." },
115+
Public_static_property_0_of_exported_class_has_or_is_using_private_name_1: { code: 2024, category: DiagnosticCategory.Error, key: "Public static property '{0}' of exported class has or is using private name '{1}'." },
116+
Public_property_0_of_exported_class_has_or_is_using_private_name_1: { code: 2025, category: DiagnosticCategory.Error, key: "Public property '{0}' of exported class has or is using private name '{1}'." },
117+
Property_0_of_exported_interface_has_or_is_using_private_name_1: { code: 2026, category: DiagnosticCategory.Error, key: "Property '{0}' of exported interface has or is using private name '{1}'." },
118+
Exported_variable_0_has_or_is_using_private_name_1: { code: 2027, category: DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using private name '{1}'." },
119+
Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2028, category: DiagnosticCategory.Error, key: "Public static property '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
120+
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}'." },
121+
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}'." },
122+
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}'." },
115123
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}'." },
116124
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}'." },
117125
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,38 @@
440440
"category": "Error",
441441
"code": 2023
442442
},
443+
"Public static property '{0}' of exported class has or is using private name '{1}'.": {
444+
"category": "Error",
445+
"code": 2024
446+
},
447+
"Public property '{0}' of exported class has or is using private name '{1}'.": {
448+
"category": "Error",
449+
"code": 2025
450+
},
451+
"Property '{0}' of exported interface has or is using private name '{1}'.": {
452+
"category": "Error",
453+
"code": 2026
454+
},
455+
"Exported variable '{0}' has or is using private name '{1}'.": {
456+
"category": "Error",
457+
"code": 2027
458+
},
459+
"Public static property '{0}' of exported class has or is using name '{1}' from private module '{2}'.": {
460+
"category": "Error",
461+
"code": 2028
462+
},
463+
"Public property '{0}' of exported class has or is using name '{1}' from private module '{2}'.": {
464+
"category": "Error",
465+
"code": 2029
466+
},
467+
"Property '{0}' of exported interface has or is using name '{1}' from private module '{2}'.": {
468+
"category": "Error",
469+
"code": 2030
470+
},
471+
"Exported variable '{0}' has or is using name '{1}' from private module '{2}'.": {
472+
"category": "Error",
473+
"code": 2031
474+
},
443475
"Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'.": {
444476
"category": "Error",
445477
"code": 2208

src/compiler/emitter.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ module ts {
20822082
diagnosticMessage: diagnosticMessage,
20832083
errorNode: node,
20842084
typeName: node.name
2085-
}
2085+
};
20862086
}
20872087

20882088
emitSourceTextOfNode(node.name);
@@ -2160,7 +2160,7 @@ module ts {
21602160
diagnosticMessage: diagnosticMessage,
21612161
errorNode: node,
21622162
typeName: (<Declaration>node.parent).name
2163-
}
2163+
};
21642164
}
21652165
}
21662166
}
@@ -2237,9 +2237,45 @@ module ts {
22372237
}
22382238
if (!(node.flags & NodeFlags.Private)) {
22392239
write(": ");
2240+
getSymbolVisibilityDiagnosticMessage = getVariableDeclarationTypeVisibilityError;
22402241
resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.None, writer);
2242+
// TODO(shkamat) This is just till we get rest of the error reporting up
2243+
getSymbolVisibilityDiagnosticMessage = undefined;
22412244
}
22422245
}
2246+
2247+
function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
2248+
// TODO(shkamat) Cannot access name errors
2249+
var diagnosticMessage: DiagnosticMessage;
2250+
if (node.kind === SyntaxKind.VariableDeclaration) {
2251+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2252+
Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 :
2253+
Diagnostics.Exported_variable_0_has_or_is_using_private_name_1;
2254+
}
2255+
else {
2256+
if (node.parent.flags & NodeFlags.Static) {
2257+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2258+
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
2259+
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1;
2260+
}
2261+
else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
2262+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2263+
Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
2264+
Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1;
2265+
}
2266+
else {
2267+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2268+
Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
2269+
Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1;
2270+
}
2271+
}
2272+
2273+
return {
2274+
diagnosticMessage: diagnosticMessage,
2275+
errorNode: node,
2276+
typeName: node.name
2277+
};
2278+
}
22432279
}
22442280

22452281
function emitVariableStatement(node: VariableStatement) {
@@ -2469,6 +2505,11 @@ module ts {
24692505
if (compilerOptions.out) {
24702506
emitFile(compilerOptions.out);
24712507
}
2508+
2509+
// Sort and make the unique list of diagnostics
2510+
diagnostics.sort(compareDiagnostics);
2511+
diagnostics = deduplicateSortedDiagnostics(diagnostics);
2512+
24722513
return {
24732514
errors: diagnostics,
24742515
sourceMaps: sourceMapDataList

0 commit comments

Comments
 (0)