Skip to content

Commit 763a114

Browse files
committed
Merge pull request #1122 from Microsoft/useTypeAnnotationInDeclarationsEmitter
Use type annotation in declarations emitter
2 parents 4fb04c7 + b760000 commit 763a114

File tree

88 files changed

+4579
-1005
lines changed

Some content is hidden

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

88 files changed

+4579
-1005
lines changed

src/compiler/checker.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -885,13 +885,13 @@ module ts {
885885
if (accessibleSymbolChain) {
886886
var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]);
887887
if (!hasAccessibleDeclarations) {
888-
return {
888+
return <SymbolAccessiblityResult>{
889889
accessibility: SymbolAccessibility.NotAccessible,
890890
errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning),
891891
errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, SymbolFlags.Namespace) : undefined,
892892
};
893893
}
894-
return { accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible: hasAccessibleDeclarations.aliasesToMakeVisible };
894+
return hasAccessibleDeclarations;
895895
}
896896

897897
// If we haven't got the accessible symbol, it doesn't mean the symbol is actually inaccessible.
@@ -948,12 +948,12 @@ module ts {
948948
(declaration.kind === SyntaxKind.SourceFile && isExternalModule(<SourceFile>declaration));
949949
}
950950

951-
function hasVisibleDeclarations(symbol: Symbol): { aliasesToMakeVisible?: ImportDeclaration[]; } {
951+
function hasVisibleDeclarations(symbol: Symbol): SymbolVisibilityResult {
952952
var aliasesToMakeVisible: ImportDeclaration[];
953953
if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) {
954954
return undefined;
955955
}
956-
return { aliasesToMakeVisible };
956+
return { accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible };
957957

958958
function getIsDeclarationVisible(declaration: Declaration) {
959959
if (!isDeclarationVisible(declaration)) {
@@ -982,14 +982,32 @@ module ts {
982982
}
983983
}
984984

985-
function isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName: EntityName): SymbolAccessiblityResult {
985+
function isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult {
986+
// get symbol of the first identifier of the entityName
987+
var meaning: SymbolFlags;
988+
if (entityName.parent.kind === SyntaxKind.TypeQuery) {
989+
// Typeof value
990+
meaning = SymbolFlags.Value | SymbolFlags.ExportValue;
991+
}
992+
else if (entityName.kind === SyntaxKind.QualifiedName ||
993+
entityName.parent.kind === SyntaxKind.ImportDeclaration) {
994+
// Left identifier from type reference or TypeAlias
995+
// Entity name of the import declaration
996+
meaning = SymbolFlags.Namespace;
997+
}
998+
else {
999+
// Type Reference or TypeAlias entity = Identifier
1000+
meaning = SymbolFlags.Type;
1001+
}
9861002
var firstIdentifier = getFirstIdentifier(entityName);
987-
var symbolOfNameSpace = resolveName(entityName.parent, (<Identifier>firstIdentifier).text, SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, firstIdentifier);
1003+
var symbol = resolveName(enclosingDeclaration, (<Identifier>firstIdentifier).text, meaning, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
1004+
9881005
// Verify if the symbol is accessible
989-
var hasNamespaceDeclarationsVisibile = hasVisibleDeclarations(symbolOfNameSpace);
990-
return hasNamespaceDeclarationsVisibile ?
991-
{ accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible: hasNamespaceDeclarationsVisibile.aliasesToMakeVisible } :
992-
{ accessibility: SymbolAccessibility.NotAccessible, errorSymbolName: declarationNameToString(<Identifier>firstIdentifier) };
1006+
return hasVisibleDeclarations(symbol) || <SymbolVisibilityResult>{
1007+
accessibility: SymbolAccessibility.NotAccessible,
1008+
errorSymbolName: getTextOfNode(firstIdentifier),
1009+
errorNode: firstIdentifier
1010+
};
9931011
}
9941012

9951013
function releaseStringWriter(writer: StringSymbolWriter) {
@@ -1601,6 +1619,7 @@ module ts {
16011619
case SyntaxKind.IndexSignature:
16021620
case SyntaxKind.Parameter:
16031621
case SyntaxKind.ModuleBlock:
1622+
case SyntaxKind.TypeParameter:
16041623
return isDeclarationVisible(node.parent);
16051624

16061625
// Source file is always visible
@@ -9135,7 +9154,7 @@ module ts {
91359154
writeTypeAtLocation,
91369155
writeReturnTypeOfSignatureDeclaration,
91379156
isSymbolAccessible,
9138-
isImportDeclarationEntityNameReferenceDeclarationVisibile,
9157+
isEntityNameVisible,
91399158
getConstantValue,
91409159
};
91419160
checkProgram();

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -275,27 +275,16 @@ module ts {
275275
Type_alias_name_cannot_be_0: { code: 2457, category: DiagnosticCategory.Error, key: "Type alias name cannot be '{0}'" },
276276
An_AMD_module_cannot_have_multiple_name_assignments: { code: 2458, category: DiagnosticCategory.Error, key: "An AMD module cannot have multiple name assignments." },
277277
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
278-
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}'." },
279278
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}'." },
280-
Type_parameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4003, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'." },
281279
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}'." },
282-
Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4005, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'." },
283280
Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4006, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." },
284-
Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4007, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'." },
285281
Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4008, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of call signature from exported interface has or is using private name '{1}'." },
286-
Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4009, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'." },
287282
Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 4010, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public static method from exported class has or is using private name '{1}'." },
288-
Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4011, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'." },
289283
Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: { code: 4012, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public method from exported class has or is using private name '{1}'." },
290-
Type_parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4013, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'." },
291284
Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: { code: 4014, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of method from exported interface has or is using private name '{1}'." },
292-
Type_parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4015, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
293285
Type_parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4016, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported function has or is using private name '{1}'." },
294-
Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 4017, category: DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." },
295-
Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 4018, category: DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." },
296286
Implements_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 4019, category: DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using private name '{1}'." },
297287
Extends_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 4020, category: DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using private name '{1}'." },
298-
Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2: { code: 4021, category: DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'." },
299288
Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1: { code: 4022, category: DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using private name '{1}'." },
300289
Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4023, category: DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using name '{1}' from external module {2} but cannot be named." },
301290
Exported_variable_0_has_or_is_using_name_1_from_private_module_2: { code: 4024, category: DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using name '{1}' from private module '{2}'." },
@@ -353,8 +342,6 @@ module ts {
353342
Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4076, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from external module {2} but cannot be named." },
354343
Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
355344
Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." },
356-
Exported_type_alias_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4079, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using name '{1}' from external module {2} but cannot be named." },
357-
Exported_type_alias_0_has_or_is_using_name_1_from_private_module_2: { code: 4080, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using name '{1}' from private module '{2}'." },
358345
Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." },
359346
Enum_declarations_must_all_be_const_or_non_const: { code: 4082, category: DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." },
360347
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 },

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,78 +1097,38 @@
10971097
"category": "Error",
10981098
"code": 4000
10991099
},
1100-
"Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'.": {
1101-
"category": "Error",
1102-
"code": 4001
1103-
},
11041100
"Type parameter '{0}' of exported class has or is using private name '{1}'.": {
11051101
"category": "Error",
11061102
"code": 4002
11071103
},
1108-
"Type parameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'.": {
1109-
"category": "Error",
1110-
"code": 4003
1111-
},
11121104
"Type parameter '{0}' of exported interface has or is using private name '{1}'.": {
11131105
"category": "Error",
11141106
"code": 4004
11151107
},
1116-
"Type parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'.": {
1117-
"category": "Error",
1118-
"code": 4005
1119-
},
11201108
"Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'.": {
11211109
"category": "Error",
11221110
"code": 4006
11231111
},
1124-
"Type parameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'.": {
1125-
"category": "Error",
1126-
"code": 4007
1127-
},
11281112
"Type parameter '{0}' of call signature from exported interface has or is using private name '{1}'.": {
11291113
"category": "Error",
11301114
"code": 4008
11311115
},
1132-
"Type parameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'.": {
1133-
"category": "Error",
1134-
"code": 4009
1135-
},
11361116
"Type parameter '{0}' of public static method from exported class has or is using private name '{1}'.": {
11371117
"category": "Error",
11381118
"code": 4010
11391119
},
1140-
"Type parameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'.": {
1141-
"category": "Error",
1142-
"code": 4011
1143-
},
11441120
"Type parameter '{0}' of public method from exported class has or is using private name '{1}'.": {
11451121
"category": "Error",
11461122
"code": 4012
11471123
},
1148-
"Type parameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'.": {
1149-
"category": "Error",
1150-
"code": 4013
1151-
},
11521124
"Type parameter '{0}' of method from exported interface has or is using private name '{1}'.": {
11531125
"category": "Error",
11541126
"code": 4014
11551127
},
1156-
"Type parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'.": {
1157-
"category": "Error",
1158-
"code": 4015
1159-
},
11601128
"Type parameter '{0}' of exported function has or is using private name '{1}'.": {
11611129
"category": "Error",
11621130
"code": 4016
11631131
},
1164-
"Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'.": {
1165-
"category": "Error",
1166-
"code": 4017
1167-
},
1168-
"Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'.": {
1169-
"category": "Error",
1170-
"code": 4018
1171-
},
11721132
"Implements clause of exported class '{0}' has or is using private name '{1}'.": {
11731133
"category": "Error",
11741134
"code": 4019
@@ -1177,10 +1137,6 @@
11771137
"category": "Error",
11781138
"code": 4020
11791139
},
1180-
"Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'.": {
1181-
"category": "Error",
1182-
"code": 4021
1183-
},
11841140
"Extends clause of exported interface '{0}' has or is using private name '{1}'.": {
11851141
"category": "Error",
11861142
"code": 4022
@@ -1409,14 +1365,6 @@
14091365
"category": "Error",
14101366
"code": 4078
14111367
},
1412-
"Exported type alias '{0}' has or is using name '{1}' from external module {2} but cannot be named.": {
1413-
"category": "Error",
1414-
"code": 4079
1415-
},
1416-
"Exported type alias '{0}' has or is using name '{1}' from private module '{2}'.": {
1417-
"category": "Error",
1418-
"code": 4080
1419-
},
14201368
"Exported type alias '{0}' has or is using private name '{1}'.": {
14211369
"category": "Error",
14221370
"code": 4081

0 commit comments

Comments
 (0)