Skip to content

Commit 6f4ea86

Browse files
committed
merge with master
2 parents 2dd9511 + 8c7fd3c commit 6f4ea86

File tree

403 files changed

+8989
-8475
lines changed

Some content is hidden

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

403 files changed

+8989
-8475
lines changed

bin/tsc.js

+1,646-1,311
Large diffs are not rendered by default.

bin/typescriptServices.js

+2,441-2,625
Large diffs are not rendered by default.

src/compiler/binder.ts

+3
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

+91-50
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

+4-3
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

+13-16
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

+29-37
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@
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

475479
"Duplicate identifier '{0}'.": {
476480
"category": "Error",
@@ -552,15 +556,15 @@
552556
"category": "Error",
553557
"code": 2319
554558
},
555-
"Interface '{0}' cannot simultaneously extend types '{1}' and '{2}':": {
559+
"Interface '{0}' cannot simultaneously extend types '{1}' and '{2}'.": {
556560
"category": "Error",
557561
"code": 2320
558562
},
559563
"Excessive stack depth comparing types '{0}' and '{1}'.": {
560564
"category": "Error",
561565
"code": 2321
562566
},
563-
"Type '{0}' is not assignable to type '{1}':": {
567+
"Type '{0}' is not assignable to type '{1}'.": {
564568
"category": "Error",
565569
"code": 2322
566570
},
@@ -576,23 +580,23 @@
576580
"category": "Error",
577581
"code": 2325
578582
},
579-
"Types of property '{0}' are incompatible:": {
583+
"Types of property '{0}' are incompatible.": {
580584
"category": "Error",
581585
"code": 2326
582586
},
583587
"Property '{0}' is optional in type '{1}' but required in type '{2}'.": {
584588
"category": "Error",
585589
"code": 2327
586590
},
587-
"Types of parameters '{0}' and '{1}' are incompatible:": {
591+
"Types of parameters '{0}' and '{1}' are incompatible.": {
588592
"category": "Error",
589593
"code": 2328
590594
},
591595
"Index signature is missing in type '{0}'.": {
592596
"category": "Error",
593597
"code": 2329
594598
},
595-
"Index signatures are incompatible:": {
599+
"Index signatures are incompatible.": {
596600
"category": "Error",
597601
"code": 2330
598602
},
@@ -644,10 +648,6 @@
644648
"category": "Error",
645649
"code": 2342
646650
},
647-
"Type '{0}' does not satisfy the constraint '{1}':": {
648-
"category": "Error",
649-
"code": 2343
650-
},
651651
"Type '{0}' does not satisfy the constraint '{1}'.": {
652652
"category": "Error",
653653
"code": 2344
@@ -684,10 +684,6 @@
684684
"category": "Error",
685685
"code": 2352
686686
},
687-
"Neither type '{0}' nor type '{1}' is assignable to the other:": {
688-
"category": "Error",
689-
"code": 2353
690-
},
691687
"No best common type exists among return expressions.": {
692688
"category": "Error",
693689
"code": 2354
@@ -928,18 +924,10 @@
928924
"category": "Error",
929925
"code": 2415
930926
},
931-
"Class '{0}' incorrectly extends base class '{1}':": {
932-
"category": "Error",
933-
"code": 2416
934-
},
935927
"Class static side '{0}' incorrectly extends base class static side '{1}'.": {
936928
"category": "Error",
937929
"code": 2417
938930
},
939-
"Class static side '{0}' incorrectly extends base class static side '{1}':": {
940-
"category": "Error",
941-
"code": 2418
942-
},
943931
"Type name '{0}' in extends clause does not reference constructor function for '{0}'.": {
944932
"category": "Error",
945933
"code": 2419
@@ -948,10 +936,6 @@
948936
"category": "Error",
949937
"code": 2420
950938
},
951-
"Class '{0}' incorrectly implements interface '{1}':": {
952-
"category": "Error",
953-
"code": 2421
954-
},
955939
"A class may only implement another class or interface.": {
956940
"category": "Error",
957941
"code": 2422
@@ -980,10 +964,6 @@
980964
"category": "Error",
981965
"code": 2428
982966
},
983-
"Interface '{0}' incorrectly extends interface '{1}':": {
984-
"category": "Error",
985-
"code": 2429
986-
},
987967
"Interface '{0}' incorrectly extends interface '{1}'.": {
988968
"category": "Error",
989969
"code": 2430
@@ -1080,18 +1060,18 @@
10801060
"category": "Error",
10811061
"code": 2452
10821062
},
1083-
"The type argument for type parameter '{0}' cannot be inferred from the usage. Consider specifying the type arguments explicitly:": {
1063+
"The type argument for type parameter '{0}' cannot be inferred from the usage. Consider specifying the type arguments explicitly.": {
10841064
"category": "Error",
10851065
"code": 2453
10861066
},
1087-
"Type argument candidate '{1}' is not a valid type argument because it is not a supertype of candidate '{0}':": {
1088-
"category": "Error",
1089-
"code": 2454
1090-
},
10911067
"Type argument candidate '{1}' is not a valid type argument because it is not a supertype of candidate '{0}'.": {
10921068
"category": "Error",
10931069
"code": 2455
10941070
},
1071+
"Type alias '{0}' circularly references itself.": {
1072+
"category": "Error",
1073+
"code": 2456
1074+
},
10951075

10961076
"Import declaration '{0}' is using private name '{1}'.": {
10971077
"category": "Error",
@@ -1409,17 +1389,29 @@
14091389
"category": "Error",
14101390
"code": 4078
14111391
},
1412-
"Enum declarations must all be const or non-const.": {
1392+
"Exported type alias '{0}' has or is using name '{1}' from external module {2} but cannot be named.": {
14131393
"category": "Error",
14141394
"code": 4079
14151395
},
1396+
"Exported type alias '{0}' has or is using name '{1}' from private module '{2}'.": {
1397+
"category": "Error",
1398+
"code": 4080
1399+
},
1400+
"Exported type alias '{0}' has or is using private name '{1}'.": {
1401+
"category": "Error",
1402+
"code": 4081
1403+
},
1404+
"Enum declarations must all be const or non-const.": {
1405+
"category": "Error",
1406+
"code": 4082
1407+
},
14161408
"In 'const' enum declarations member initializer must be constant expression.": {
14171409
"category": "Error",
1418-
"code": 4079
1410+
"code": 4083
14191411
},
14201412
"'const' enums can only be used in property access expressions.": {
14211413
"category": "Error",
1422-
"code": 4079
1414+
"code": 4084
14231415
},
14241416
"The current host does not support the '{0}' option.": {
14251417
"category": "Error",

src/compiler/emitter.ts

+28
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,32 @@ module ts {
25692569
}
25702570
}
25712571

2572+
function emitTypeAliasDeclaration(node: TypeAliasDeclaration) {
2573+
if (resolver.isDeclarationVisible(node)) {
2574+
emitJsDocComments(node);
2575+
emitDeclarationFlags(node);
2576+
write("type ");
2577+
emitSourceTextOfNode(node.name);
2578+
write(" = ");
2579+
getSymbolVisibilityDiagnosticMessage = getTypeAliasDeclarationVisibilityError;
2580+
resolver.writeTypeAtLocation(node.type, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
2581+
write(";");
2582+
writeLine();
2583+
}
2584+
function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
2585+
var diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2586+
symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
2587+
Diagnostics.Exported_type_alias_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
2588+
Diagnostics.Exported_type_alias_0_has_or_is_using_name_1_from_private_module_2 :
2589+
Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1;
2590+
return {
2591+
diagnosticMessage: diagnosticMessage,
2592+
errorNode: node,
2593+
typeName: node.name
2594+
};
2595+
}
2596+
}
2597+
25722598
function emitEnumDeclaration(node: EnumDeclaration) {
25732599
if (resolver.isDeclarationVisible(node)) {
25742600
emitJsDocComments(node);
@@ -3169,6 +3195,8 @@ module ts {
31693195
return emitInterfaceDeclaration(<InterfaceDeclaration>node);
31703196
case SyntaxKind.ClassDeclaration:
31713197
return emitClassDeclaration(<ClassDeclaration>node);
3198+
case SyntaxKind.TypeAliasDeclaration:
3199+
return emitTypeAliasDeclaration(<TypeAliasDeclaration>node);
31723200
case SyntaxKind.EnumMember:
31733201
return emitEnumMemberDeclaration(<EnumMember>node);
31743202
case SyntaxKind.EnumDeclaration:

src/compiler/parser.ts

+29-2
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ module ts {
408408
children((<InterfaceDeclaration>node).typeParameters) ||
409409
children((<InterfaceDeclaration>node).baseTypes) ||
410410
children((<InterfaceDeclaration>node).members);
411+
case SyntaxKind.TypeAliasDeclaration:
412+
return child((<TypeAliasDeclaration>node).name) ||
413+
child((<TypeAliasDeclaration>node).type);
411414
case SyntaxKind.EnumDeclaration:
412415
return child((<EnumDeclaration>node).name) ||
413416
children((<EnumDeclaration>node).members);
@@ -553,6 +556,7 @@ module ts {
553556
case SyntaxKind.SetAccessor:
554557
case SyntaxKind.ClassDeclaration:
555558
case SyntaxKind.InterfaceDeclaration:
559+
case SyntaxKind.TypeAliasDeclaration:
556560
case SyntaxKind.EnumDeclaration:
557561
case SyntaxKind.ModuleDeclaration:
558562
case SyntaxKind.ImportDeclaration:
@@ -615,6 +619,7 @@ module ts {
615619
return <ClassDeclaration>node;
616620
case SyntaxKind.EnumDeclaration:
617621
case SyntaxKind.InterfaceDeclaration:
622+
case SyntaxKind.TypeAliasDeclaration:
618623
case SyntaxKind.ModuleDeclaration:
619624
case SyntaxKind.ImportDeclaration:
620625
// early exit cases - declarations cannot be nested in classes
@@ -1085,7 +1090,6 @@ module ts {
10851090
return finishNode(node);
10861091
}
10871092
error(Diagnostics.Identifier_expected);
1088-
10891093
var node = <Identifier>createMissingNode();
10901094
node.text = "";
10911095
return node;
@@ -3178,6 +3182,7 @@ module ts {
31783182
case SyntaxKind.ClassKeyword:
31793183
case SyntaxKind.ModuleKeyword:
31803184
case SyntaxKind.EnumKeyword:
3185+
case SyntaxKind.TypeKeyword:
31813186
// When followed by an identifier, these do not start a statement but might
31823187
// instead be following declarations
31833188
if (isDeclaration()) {
@@ -3757,7 +3762,25 @@ module ts {
37573762
}
37583763
return finishNode(node);
37593764
}
3760-
3765+
3766+
function parseTypeAliasDeclaration(pos: number, flags: NodeFlags): TypeAliasDeclaration {
3767+
var node = <TypeAliasDeclaration>createNode(SyntaxKind.TypeAliasDeclaration, pos);
3768+
node.flags = flags;
3769+
parseExpected(SyntaxKind.TypeKeyword);
3770+
node.name = parseIdentifier();
3771+
parseExpected(SyntaxKind.EqualsToken);
3772+
node.type = parseType();
3773+
parseSemicolon();
3774+
var n = node.type;
3775+
while (n.kind === SyntaxKind.ParenType) {
3776+
n = (<ParenTypeNode>n).type;
3777+
}
3778+
if (n.kind === SyntaxKind.TypeLiteral && (n.pos !== (<TypeLiteralNode>n).members.pos || n.end !== (<TypeLiteralNode>n).members.end)) {
3779+
grammarErrorOnNode(node.type, Diagnostics.Aliased_type_cannot_be_an_object_type_literal_Use_an_interface_declaration_instead);
3780+
}
3781+
return finishNode(node);
3782+
}
3783+
37613784
function parseAndCheckEnumDeclaration(pos: number, flags: NodeFlags): EnumDeclaration {
37623785
var enumIsConst = flags & NodeFlags.Const;
37633786
function isIntegerLiteral(expression: Expression): boolean {
@@ -3927,6 +3950,7 @@ module ts {
39273950
case SyntaxKind.InterfaceKeyword:
39283951
case SyntaxKind.EnumKeyword:
39293952
case SyntaxKind.ImportKeyword:
3953+
case SyntaxKind.TypeKeyword:
39303954
// Not true keywords so ensure an identifier follows
39313955
return lookAhead(() => nextToken() >= SyntaxKind.Identifier);
39323956
case SyntaxKind.ModuleKeyword:
@@ -3992,6 +4016,9 @@ module ts {
39924016
case SyntaxKind.InterfaceKeyword:
39934017
result = parseInterfaceDeclaration(pos, flags);
39944018
break;
4019+
case SyntaxKind.TypeKeyword:
4020+
result = parseTypeAliasDeclaration(pos, flags);
4021+
break;
39954022
case SyntaxKind.EnumKeyword:
39964023
result = parseAndCheckEnumDeclaration(pos, flags);
39974024
break;

src/compiler/scanner.ts

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ module ts {
8080
"throw": SyntaxKind.ThrowKeyword,
8181
"true": SyntaxKind.TrueKeyword,
8282
"try": SyntaxKind.TryKeyword,
83+
"type": SyntaxKind.TypeKeyword,
8384
"typeof": SyntaxKind.TypeOfKeyword,
8485
"var": SyntaxKind.VarKeyword,
8586
"void": SyntaxKind.VoidKeyword,

0 commit comments

Comments
 (0)