Skip to content

Commit 0872ed6

Browse files
committed
Merge pull request #3266 from Microsoft/localTypes
Local types
2 parents f531ff8 + 6f734d6 commit 0872ed6

Some content is hidden

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

50 files changed

+2916
-489
lines changed

src/compiler/binder.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,17 @@ module ts {
519519
bindBlockScopedDeclaration(<Declaration>node, SymbolFlags.Class, SymbolFlags.ClassExcludes);
520520
break;
521521
case SyntaxKind.InterfaceDeclaration:
522-
bindDeclaration(<Declaration>node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes, /*isBlockScopeContainer*/ false);
522+
bindBlockScopedDeclaration(<Declaration>node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes);
523523
break;
524524
case SyntaxKind.TypeAliasDeclaration:
525-
bindDeclaration(<Declaration>node, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes, /*isBlockScopeContainer*/ false);
525+
bindBlockScopedDeclaration(<Declaration>node, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes);
526526
break;
527527
case SyntaxKind.EnumDeclaration:
528528
if (isConst(node)) {
529-
bindDeclaration(<Declaration>node, SymbolFlags.ConstEnum, SymbolFlags.ConstEnumExcludes, /*isBlockScopeContainer*/ false);
529+
bindBlockScopedDeclaration(<Declaration>node, SymbolFlags.ConstEnum, SymbolFlags.ConstEnumExcludes);
530530
}
531531
else {
532-
bindDeclaration(<Declaration>node, SymbolFlags.RegularEnum, SymbolFlags.RegularEnumExcludes, /*isBlockScopeContainer*/ false);
532+
bindBlockScopedDeclaration(<Declaration>node, SymbolFlags.RegularEnum, SymbolFlags.RegularEnumExcludes);
533533
}
534534
break;
535535
case SyntaxKind.ModuleDeclaration:

src/compiler/checker.ts

+151-46
Large diffs are not rendered by default.

src/compiler/core.ts

+10
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ module ts {
129129
}
130130
}
131131

132+
export function rangeEquals<T>(array1: T[], array2: T[], pos: number, end: number) {
133+
while (pos < end) {
134+
if (array1[pos] !== array2[pos]) {
135+
return false;
136+
}
137+
pos++;
138+
}
139+
return true;
140+
}
141+
132142
/**
133143
* Returns the last element of an array if non-empty, undefined otherwise.
134144
*/

src/compiler/diagnosticInformationMap.generated.ts

-1
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,5 @@ module ts {
548548
decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." },
549549
Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." },
550550
class_expressions_are_not_currently_supported: { code: 9003, category: DiagnosticCategory.Error, key: "'class' expressions are not currently supported." },
551-
class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration: { code: 9004, category: DiagnosticCategory.Error, key: "'class' declarations are only supported directly inside a module or as a top level declaration." },
552551
};
553552
}

src/compiler/diagnosticMessages.json

-4
Original file line numberDiff line numberDiff line change
@@ -2185,9 +2185,5 @@
21852185
"'class' expressions are not currently supported.": {
21862186
"category": "Error",
21872187
"code": 9003
2188-
},
2189-
"'class' declarations are only supported directly inside a module or as a top level declaration.": {
2190-
"category": "Error",
2191-
"code": 9004
21922188
}
21932189
}

src/compiler/parser.ts

+229-298
Large diffs are not rendered by default.

src/compiler/types.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ module ts {
917917
_classElementBrand: any;
918918
}
919919

920-
export interface InterfaceDeclaration extends Declaration, ModuleElement {
920+
export interface InterfaceDeclaration extends Declaration, Statement {
921921
name: Identifier;
922922
typeParameters?: NodeArray<TypeParameterDeclaration>;
923923
heritageClauses?: NodeArray<HeritageClause>;
@@ -929,7 +929,7 @@ module ts {
929929
types?: NodeArray<ExpressionWithTypeArguments>;
930930
}
931931

932-
export interface TypeAliasDeclaration extends Declaration, ModuleElement {
932+
export interface TypeAliasDeclaration extends Declaration, Statement {
933933
name: Identifier;
934934
type: TypeNode;
935935
}
@@ -941,7 +941,7 @@ module ts {
941941
initializer?: Expression;
942942
}
943943

944-
export interface EnumDeclaration extends Declaration, ModuleElement {
944+
export interface EnumDeclaration extends Declaration, Statement {
945945
name: Identifier;
946946
members: NodeArray<EnumMember>;
947947
}
@@ -1626,6 +1626,8 @@ module ts {
16261626
// Class and interface types (TypeFlags.Class and TypeFlags.Interface)
16271627
export interface InterfaceType extends ObjectType {
16281628
typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic)
1629+
outerTypeParameters: TypeParameter[]; // Outer type parameters (undefined if none)
1630+
localTypeParameters: TypeParameter[]; // Local type parameters (undefined if none)
16291631
}
16301632

16311633
export interface InterfaceTypeWithBaseTypes extends InterfaceType {

tests/baselines/reference/classDeclarationBlockScoping1.errors.txt

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/classDeclarationBlockScoping1.ts ===
2+
class C {
3+
>C : Symbol(C, Decl(classDeclarationBlockScoping1.ts, 0, 0))
4+
}
5+
6+
{
7+
class C {
8+
>C : Symbol(C, Decl(classDeclarationBlockScoping1.ts, 3, 1))
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/classDeclarationBlockScoping1.ts ===
2+
class C {
3+
>C : C
4+
}
5+
6+
{
7+
class C {
8+
>C : C
9+
}
10+
}

tests/baselines/reference/classDeclarationBlockScoping2.errors.txt

-18
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/compiler/classDeclarationBlockScoping2.ts ===
2+
function f() {
3+
>f : Symbol(f, Decl(classDeclarationBlockScoping2.ts, 0, 0))
4+
5+
class C {}
6+
>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 0, 14))
7+
8+
var c1 = C;
9+
>c1 : Symbol(c1, Decl(classDeclarationBlockScoping2.ts, 2, 7))
10+
>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 0, 14))
11+
{
12+
class C {}
13+
>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 3, 5))
14+
15+
var c2 = C;
16+
>c2 : Symbol(c2, Decl(classDeclarationBlockScoping2.ts, 5, 11))
17+
>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 3, 5))
18+
}
19+
return C === c1;
20+
>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 0, 14))
21+
>c1 : Symbol(c1, Decl(classDeclarationBlockScoping2.ts, 2, 7))
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== tests/cases/compiler/classDeclarationBlockScoping2.ts ===
2+
function f() {
3+
>f : () => boolean
4+
5+
class C {}
6+
>C : C
7+
8+
var c1 = C;
9+
>c1 : typeof C
10+
>C : typeof C
11+
{
12+
class C {}
13+
>C : C
14+
15+
var c2 = C;
16+
>c2 : typeof C
17+
>C : typeof C
18+
}
19+
return C === c1;
20+
>C === c1 : boolean
21+
>C : typeof C
22+
>c1 : typeof C
23+
}

tests/baselines/reference/classExpressionTest1.errors.txt

-18
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=== tests/cases/compiler/classExpressionTest1.ts ===
2+
function M() {
3+
>M : Symbol(M, Decl(classExpressionTest1.ts, 0, 0))
4+
5+
class C<X> {
6+
>C : Symbol(C, Decl(classExpressionTest1.ts, 0, 14))
7+
>X : Symbol(X, Decl(classExpressionTest1.ts, 1, 12))
8+
9+
f<T>() {
10+
>f : Symbol(f, Decl(classExpressionTest1.ts, 1, 16))
11+
>T : Symbol(T, Decl(classExpressionTest1.ts, 2, 10))
12+
13+
var t: T;
14+
>t : Symbol(t, Decl(classExpressionTest1.ts, 3, 15))
15+
>T : Symbol(T, Decl(classExpressionTest1.ts, 2, 10))
16+
17+
var x: X;
18+
>x : Symbol(x, Decl(classExpressionTest1.ts, 4, 15))
19+
>X : Symbol(X, Decl(classExpressionTest1.ts, 1, 12))
20+
21+
return { t, x };
22+
>t : Symbol(t, Decl(classExpressionTest1.ts, 5, 20))
23+
>x : Symbol(x, Decl(classExpressionTest1.ts, 5, 23))
24+
}
25+
}
26+
27+
var v = new C<number>();
28+
>v : Symbol(v, Decl(classExpressionTest1.ts, 9, 7))
29+
>C : Symbol(C, Decl(classExpressionTest1.ts, 0, 14))
30+
31+
return v.f<string>();
32+
>v.f : Symbol(C.f, Decl(classExpressionTest1.ts, 1, 16))
33+
>v : Symbol(v, Decl(classExpressionTest1.ts, 9, 7))
34+
>f : Symbol(C.f, Decl(classExpressionTest1.ts, 1, 16))
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
=== tests/cases/compiler/classExpressionTest1.ts ===
2+
function M() {
3+
>M : () => { t: string; x: number; }
4+
5+
class C<X> {
6+
>C : C<X>
7+
>X : X
8+
9+
f<T>() {
10+
>f : <T>() => { t: T; x: X; }
11+
>T : T
12+
13+
var t: T;
14+
>t : T
15+
>T : T
16+
17+
var x: X;
18+
>x : X
19+
>X : X
20+
21+
return { t, x };
22+
>{ t, x } : { t: T; x: X; }
23+
>t : T
24+
>x : X
25+
}
26+
}
27+
28+
var v = new C<number>();
29+
>v : C<number>
30+
>new C<number>() : C<number>
31+
>C : typeof C
32+
33+
return v.f<string>();
34+
>v.f<string>() : { t: string; x: number; }
35+
>v.f : <T>() => { t: T; x: number; }
36+
>v : C<number>
37+
>f : <T>() => { t: T; x: number; }
38+
}

tests/baselines/reference/classInsideBlock.errors.txt

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/conformance/classes/classDeclarations/classInsideBlock.ts ===
2+
function foo() {
3+
>foo : Symbol(foo, Decl(classInsideBlock.ts, 0, 0))
4+
5+
class C { }
6+
>C : Symbol(C, Decl(classInsideBlock.ts, 0, 16))
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/conformance/classes/classDeclarations/classInsideBlock.ts ===
2+
function foo() {
3+
>foo : () => void
4+
5+
class C { }
6+
>C : C
7+
}

tests/baselines/reference/functionsWithModifiersInBlocks1.errors.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ tests/cases/compiler/functionsWithModifiersInBlocks1.ts(2,25): error TS1184: An
44
tests/cases/compiler/functionsWithModifiersInBlocks1.ts(3,4): error TS1184: Modifiers cannot appear here.
55
tests/cases/compiler/functionsWithModifiersInBlocks1.ts(3,20): error TS2393: Duplicate function implementation.
66
tests/cases/compiler/functionsWithModifiersInBlocks1.ts(4,4): error TS1184: Modifiers cannot appear here.
7-
tests/cases/compiler/functionsWithModifiersInBlocks1.ts(4,12): error TS1029: 'export' modifier must precede 'declare' modifier.
87
tests/cases/compiler/functionsWithModifiersInBlocks1.ts(4,28): error TS2393: Duplicate function implementation.
98
tests/cases/compiler/functionsWithModifiersInBlocks1.ts(4,32): error TS1184: An implementation cannot be declared in ambient contexts.
109

1110

12-
==== tests/cases/compiler/functionsWithModifiersInBlocks1.ts (9 errors) ====
11+
==== tests/cases/compiler/functionsWithModifiersInBlocks1.ts (8 errors) ====
1312
{
1413
declare function f() { }
1514
~~~~~~~
@@ -26,8 +25,6 @@ tests/cases/compiler/functionsWithModifiersInBlocks1.ts(4,32): error TS1184: An
2625
declare export function f() { }
2726
~~~~~~~
2827
!!! error TS1184: Modifiers cannot appear here.
29-
~~~~~~
30-
!!! error TS1029: 'export' modifier must precede 'declare' modifier.
3128
~
3229
!!! error TS2393: Duplicate function implementation.
3330
~
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,5): error TS1129: Statement expected.
2-
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,6): error TS2346: Supplied parameters do not match any signature of call target.
3-
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,16): error TS2304: Cannot find name 'yield'.
4-
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,22): error TS1005: ',' expected.
5-
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(9,1): error TS1128: Declaration or statement expected.
1+
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,16): error TS1163: A 'yield' expression is only allowed in a generator body.
2+
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(7,13): error TS1163: A 'yield' expression is only allowed in a generator body.
63

74

8-
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts (5 errors) ====
5+
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts (2 errors) ====
96
function decorator(x: any) {
107
return y => { };
118
}
129
function* g() {
1310
@decorator(yield 0)
14-
~
15-
!!! error TS1129: Statement expected.
16-
~~~~~~~~~~~~~~~~~~
17-
!!! error TS2346: Supplied parameters do not match any signature of call target.
1811
~~~~~
19-
!!! error TS2304: Cannot find name 'yield'.
20-
~
21-
!!! error TS1005: ',' expected.
12+
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
2213
class C {
2314
x = yield 0;
15+
~~~~~
16+
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
2417
}
25-
}
26-
~
27-
!!! error TS1128: Declaration or statement expected.
18+
}

0 commit comments

Comments
 (0)