Skip to content

Commit 35cf95c

Browse files
Merge branch 'master' into templates
Conflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json src/compiler/types.ts src/services/utilities.ts
2 parents ead3c1b + b187a0a commit 35cf95c

27 files changed

+4447
-4149
lines changed

bin/tsc.js

Lines changed: 1646 additions & 1311 deletions
Large diffs are not rendered by default.

bin/typescriptServices.js

Lines changed: 2441 additions & 2625 deletions
Large diffs are not rendered by default.

src/compiler/binder.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ module ts {
360360
case SyntaxKind.InterfaceDeclaration:
361361
bindDeclaration(<Declaration>node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes, /*isBlockScopeContainer*/ false);
362362
break;
363+
case SyntaxKind.TypeAliasDeclaration:
364+
bindDeclaration(<Declaration>node, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes, /*isBlockScopeContainer*/ false);
365+
break;
363366
case SyntaxKind.EnumDeclaration:
364367
bindDeclaration(<Declaration>node, SymbolFlags.Enum, SymbolFlags.EnumExcludes, /*isBlockScopeContainer*/ false);
365368
break;

src/compiler/checker.ts

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ module ts {
8686
emitFiles: invokeEmitter,
8787
getParentOfSymbol: getParentOfSymbol,
8888
getTypeOfSymbol: getTypeOfSymbol,
89+
getDeclaredTypeOfSymbol: getDeclaredTypeOfSymbol,
8990
getPropertiesOfType: getPropertiesOfType,
9091
getPropertyOfType: getPropertyOfType,
9192
getSignaturesOfType: getSignaturesOfType,
@@ -191,6 +192,7 @@ module ts {
191192
if (flags & SymbolFlags.GetAccessor) result |= SymbolFlags.GetAccessorExcludes;
192193
if (flags & SymbolFlags.SetAccessor) result |= SymbolFlags.SetAccessorExcludes;
193194
if (flags & SymbolFlags.TypeParameter) result |= SymbolFlags.TypeParameterExcludes;
195+
if (flags & SymbolFlags.TypeAlias) result |= SymbolFlags.TypeAliasExcludes;
194196
if (flags & SymbolFlags.Import) result |= SymbolFlags.ImportExcludes;
195197
return result;
196198
}
@@ -479,7 +481,7 @@ module ts {
479481
// import a = |b.c|; // Value, type, namespace
480482
// import a = |b.c|.d; // Namespace
481483
if (entityName.kind === SyntaxKind.Identifier && isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
482-
entityName = entityName.parent;
484+
entityName = <QualifiedName>entityName.parent;
483485
}
484486
// Check for case 1 and 3 in the above example
485487
if (entityName.kind === SyntaxKind.Identifier || entityName.parent.kind === SyntaxKind.QualifiedName) {
@@ -1022,6 +1024,19 @@ module ts {
10221024
return result;
10231025
}
10241026

1027+
function getTypeAliasForTypeLiteral(type: Type): Symbol {
1028+
if (type.symbol && type.symbol.flags & SymbolFlags.TypeLiteral) {
1029+
var node = type.symbol.declarations[0].parent;
1030+
while (node.kind === SyntaxKind.ParenType) {
1031+
node = node.parent;
1032+
}
1033+
if (node.kind === SyntaxKind.TypeAliasDeclaration) {
1034+
return getSymbolOfNode(node);
1035+
}
1036+
}
1037+
return undefined;
1038+
}
1039+
10251040
// This is for caching the result of getSymbolDisplayBuilder. Do not access directly.
10261041
var _displayBuilder: SymbolDisplayBuilder;
10271042
function getSymbolDisplayBuilder(): SymbolDisplayBuilder {
@@ -1212,8 +1227,15 @@ module ts {
12121227
writeTypeofSymbol(type);
12131228
}
12141229
else if (typeStack && contains(typeStack, type)) {
1215-
// Recursive usage, use any
1216-
writeKeyword(writer, SyntaxKind.AnyKeyword);
1230+
// If type is an anonymous type literal in a type alias declaration, use type alias name
1231+
var typeAlias = getTypeAliasForTypeLiteral(type);
1232+
if (typeAlias) {
1233+
buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type);
1234+
}
1235+
else {
1236+
// Recursive usage, use any
1237+
writeKeyword(writer, SyntaxKind.AnyKeyword);
1238+
}
12171239
}
12181240
else {
12191241
if (!typeStack) {
@@ -1537,6 +1559,7 @@ module ts {
15371559
case SyntaxKind.ModuleDeclaration:
15381560
case SyntaxKind.ClassDeclaration:
15391561
case SyntaxKind.InterfaceDeclaration:
1562+
case SyntaxKind.TypeAliasDeclaration:
15401563
case SyntaxKind.FunctionDeclaration:
15411564
case SyntaxKind.EnumDeclaration:
15421565
case SyntaxKind.ImportDeclaration:
@@ -1940,6 +1963,24 @@ module ts {
19401963
return <InterfaceType>links.declaredType;
19411964
}
19421965

1966+
function getDeclaredTypeOfTypeAlias(symbol: Symbol): Type {
1967+
var links = getSymbolLinks(symbol);
1968+
if (!links.declaredType) {
1969+
links.declaredType = resolvingType;
1970+
var declaration = <TypeAliasDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration);
1971+
var type = getTypeFromTypeNode(declaration.type);
1972+
if (links.declaredType === resolvingType) {
1973+
links.declaredType = type;
1974+
}
1975+
}
1976+
else if (links.declaredType === resolvingType) {
1977+
links.declaredType = unknownType;
1978+
var declaration = <TypeAliasDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration);
1979+
error(declaration.name, Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
1980+
}
1981+
return links.declaredType;
1982+
}
1983+
19431984
function getDeclaredTypeOfEnum(symbol: Symbol): Type {
19441985
var links = getSymbolLinks(symbol);
19451986
if (!links.declaredType) {
@@ -1979,6 +2020,9 @@ module ts {
19792020
if (symbol.flags & SymbolFlags.Interface) {
19802021
return getDeclaredTypeOfInterface(symbol);
19812022
}
2023+
if (symbol.flags & SymbolFlags.TypeAlias) {
2024+
return getDeclaredTypeOfTypeAlias(symbol);
2025+
}
19822026
if (symbol.flags & SymbolFlags.Enum) {
19832027
return getDeclaredTypeOfEnum(symbol);
19842028
}
@@ -7590,6 +7634,10 @@ module ts {
75907634
}
75917635
}
75927636

7637+
function checkTypeAliasDeclaration(node: TypeAliasDeclaration) {
7638+
checkSourceElement(node.type);
7639+
}
7640+
75937641
function getConstantValueForExpression(node: Expression): number {
75947642
var isNegative = false;
75957643
if (node.kind === SyntaxKind.PrefixOperator) {
@@ -7882,6 +7930,8 @@ module ts {
78827930
return checkClassDeclaration(<ClassDeclaration>node);
78837931
case SyntaxKind.InterfaceDeclaration:
78847932
return checkInterfaceDeclaration(<InterfaceDeclaration>node);
7933+
case SyntaxKind.TypeAliasDeclaration:
7934+
return checkTypeAliasDeclaration(<TypeAliasDeclaration>node);
78857935
case SyntaxKind.EnumDeclaration:
78867936
return checkEnumDeclaration(<EnumDeclaration>node);
78877937
case SyntaxKind.ModuleDeclaration:
@@ -8127,6 +8177,7 @@ module ts {
81278177
case SyntaxKind.TypeParameter:
81288178
case SyntaxKind.ClassDeclaration:
81298179
case SyntaxKind.InterfaceDeclaration:
8180+
case SyntaxKind.TypeAliasDeclaration:
81308181
case SyntaxKind.EnumDeclaration:
81318182
return true;
81328183
}
@@ -8216,7 +8267,7 @@ module ts {
82168267

82178268
function isInRightSideOfImportOrExportAssignment(node: EntityName) {
82188269
while (node.parent.kind === SyntaxKind.QualifiedName) {
8219-
node = node.parent;
8270+
node = <QualifiedName>node.parent;
82208271
}
82218272

82228273
if (node.parent.kind === SyntaxKind.ImportDeclaration) {
@@ -8250,7 +8301,7 @@ module ts {
82508301
}
82518302

82528303
if (isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
8253-
entityName = entityName.parent;
8304+
entityName = <QualifiedName>entityName.parent;
82548305
}
82558306

82568307
if (isExpression(entityName)) {
@@ -8263,7 +8314,7 @@ module ts {
82638314
else if (entityName.kind === SyntaxKind.QualifiedName || entityName.kind === SyntaxKind.PropertyAccess) {
82648315
var symbol = getNodeLinks(entityName).resolvedSymbol;
82658316
if (!symbol) {
8266-
checkPropertyAccess(<PropertyAccess>entityName);
8317+
checkPropertyAccess(<QualifiedName>entityName);
82678318
}
82688319
return getNodeLinks(entityName).resolvedSymbol;
82698320
}
@@ -8295,10 +8346,10 @@ module ts {
82958346
return getSymbolOfNode(node.parent);
82968347
}
82978348

8298-
if (node.kind === SyntaxKind.Identifier && isInRightSideOfImportOrExportAssignment(node)) {
8349+
if (node.kind === SyntaxKind.Identifier && isInRightSideOfImportOrExportAssignment(<Identifier>node)) {
82998350
return node.parent.kind === SyntaxKind.ExportAssignment
83008351
? getSymbolOfEntityName(<Identifier>node)
8301-
: getSymbolOfPartOfRightHandSideOfImport(node);
8352+
: getSymbolOfPartOfRightHandSideOfImport(<Identifier>node);
83028353
}
83038354

83048355
switch (node.kind) {
@@ -8379,7 +8430,7 @@ module ts {
83798430
return symbol && getTypeOfSymbol(symbol);
83808431
}
83818432

8382-
if (isInRightSideOfImportOrExportAssignment(node)) {
8433+
if (isInRightSideOfImportOrExportAssignment(<Identifier>node)) {
83838434
var symbol = getSymbolInfo(node);
83848435
var declaredType = symbol && getDeclaredTypeOfSymbol(symbol);
83858436
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,10 @@ module ts {
183183
break;
184184
// If not a primitive, the possible types are specified in what is effectively a map of options.
185185
default:
186-
var value = (args[i++] || "").toLowerCase();
187-
if (hasProperty(opt.type, value)) {
188-
options[opt.name] = opt.type[value];
186+
var map = <Map<number>>opt.type;
187+
var key = (args[i++] || "").toLowerCase();
188+
if (hasProperty(map, key)) {
189+
options[opt.name] = map[key];
189190
}
190191
else {
191192
errors.push(createCompilerDiagnostic(opt.error));

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ module ts {
120120
const_declarations_must_be_initialized: { code: 1155, category: DiagnosticCategory.Error, key: "'const' declarations must be initialized" },
121121
const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "'const' declarations can only be declared inside a block." },
122122
let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block." },
123-
Invalid_template_literal_expected: { code: 1158, category: DiagnosticCategory.Error, key: "Invalid template literal; expected '}'" },
124-
Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: DiagnosticCategory.Error, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." },
123+
Aliased_type_cannot_be_an_object_type_literal_Use_an_interface_declaration_instead: { code: 1158, category: DiagnosticCategory.Error, key: "Aliased type cannot be an object type literal. Use an interface declaration instead." },
124+
Invalid_template_literal_expected: { code: 1159, category: DiagnosticCategory.Error, key: "Invalid template literal; expected '}'" },
125+
Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1160, category: DiagnosticCategory.Error, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." },
125126
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
126127
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
127128
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
@@ -268,6 +269,7 @@ module ts {
268269
An_enum_member_cannot_have_a_numeric_name: { code: 2452, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." },
269270
The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly: { code: 2453, category: DiagnosticCategory.Error, key: "The type argument for type parameter '{0}' cannot be inferred from the usage. Consider specifying the type arguments explicitly." },
270271
Type_argument_candidate_1_is_not_a_valid_type_argument_because_it_is_not_a_supertype_of_candidate_0: { code: 2455, category: DiagnosticCategory.Error, key: "Type argument candidate '{1}' is not a valid type argument because it is not a supertype of candidate '{0}'." },
272+
Type_alias_0_circularly_references_itself: { code: 2456, category: DiagnosticCategory.Error, key: "Type alias '{0}' circularly references itself." },
271273
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
272274
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}'." },
273275
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}'." },
@@ -347,6 +349,9 @@ module ts {
347349
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." },
348350
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}'." },
349351
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}'." },
352+
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." },
353+
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}'." },
354+
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}'." },
350355
The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." },
351356
Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." },
352357
Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" },

src/compiler/diagnosticMessages.json

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,17 @@
471471
"category": "Error",
472472
"code": 1157
473473
},
474+
"Aliased type cannot be an object type literal. Use an interface declaration instead.": {
475+
"category": "Error",
476+
"code": 1158
477+
},
474478
"Invalid template literal; expected '}'": {
475479
"category": "Error",
476-
"code": 1158
480+
"code": 1159
477481
},
478482
"Tagged templates are only available when targeting ECMAScript 6 and higher.": {
479483
"category": "Error",
480-
"code": 1159
484+
"code": 1160
481485
},
482486

483487
"Duplicate identifier '{0}'.": {
@@ -1072,6 +1076,10 @@
10721076
"category": "Error",
10731077
"code": 2455
10741078
},
1079+
"Type alias '{0}' circularly references itself.": {
1080+
"category": "Error",
1081+
"code": 2456
1082+
},
10751083

10761084
"Import declaration '{0}' is using private name '{1}'.": {
10771085
"category": "Error",
@@ -1389,6 +1397,18 @@
13891397
"category": "Error",
13901398
"code": 4078
13911399
},
1400+
"Exported type alias '{0}' has or is using name '{1}' from external module {2} but cannot be named.": {
1401+
"category": "Error",
1402+
"code": 4079
1403+
},
1404+
"Exported type alias '{0}' has or is using name '{1}' from private module '{2}'.": {
1405+
"category": "Error",
1406+
"code": 4080
1407+
},
1408+
"Exported type alias '{0}' has or is using private name '{1}'.": {
1409+
"category": "Error",
1410+
"code": 4081
1411+
},
13921412

13931413

13941414
"The current host does not support the '{0}' option.": {

src/compiler/emitter.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,6 +2692,32 @@ module ts {
26922692
}
26932693
}
26942694

2695+
function emitTypeAliasDeclaration(node: TypeAliasDeclaration) {
2696+
if (resolver.isDeclarationVisible(node)) {
2697+
emitJsDocComments(node);
2698+
emitDeclarationFlags(node);
2699+
write("type ");
2700+
emitSourceTextOfNode(node.name);
2701+
write(" = ");
2702+
getSymbolVisibilityDiagnosticMessage = getTypeAliasDeclarationVisibilityError;
2703+
resolver.writeTypeAtLocation(node.type, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
2704+
write(";");
2705+
writeLine();
2706+
}
2707+
function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
2708+
var diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2709+
symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
2710+
Diagnostics.Exported_type_alias_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
2711+
Diagnostics.Exported_type_alias_0_has_or_is_using_name_1_from_private_module_2 :
2712+
Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1;
2713+
return {
2714+
diagnosticMessage: diagnosticMessage,
2715+
errorNode: node,
2716+
typeName: node.name
2717+
};
2718+
}
2719+
}
2720+
26952721
function emitEnumDeclaration(node: EnumDeclaration) {
26962722
if (resolver.isDeclarationVisible(node)) {
26972723
emitJsDocComments(node);
@@ -3289,6 +3315,8 @@ module ts {
32893315
return emitInterfaceDeclaration(<InterfaceDeclaration>node);
32903316
case SyntaxKind.ClassDeclaration:
32913317
return emitClassDeclaration(<ClassDeclaration>node);
3318+
case SyntaxKind.TypeAliasDeclaration:
3319+
return emitTypeAliasDeclaration(<TypeAliasDeclaration>node);
32923320
case SyntaxKind.EnumMember:
32933321
return emitEnumMemberDeclaration(<EnumMember>node);
32943322
case SyntaxKind.EnumDeclaration:

0 commit comments

Comments
 (0)