Skip to content

Commit da12d46

Browse files
author
Yui T
committed
Add tests for extension, type arguments, overload
1 parent 890aa4a commit da12d46

File tree

29 files changed

+622
-94
lines changed

29 files changed

+622
-94
lines changed

src/compiler/emitter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4407,7 +4407,9 @@ module ts {
44074407
emitComputedPropertyName(<ComputedPropertyName>memberName);
44084408
}
44094409
else {
4410-
if (languageVersion < ScriptTarget.ES6) {
4410+
// For script-target that is ES6 or above, we want to emit memberName by itself without prefix "." if the memberName is a name of method.
4411+
// If the memberName is the name of property, we need to emit it with prefix ".".
4412+
if (languageVersion < ScriptTarget.ES6 || memberName.parent.kind === SyntaxKind.PropertyDeclaration) {
44114413
write(".");
44124414
}
44134415
emitNodeWithoutSourceMap(memberName);
@@ -4667,7 +4669,7 @@ module ts {
46674669
var baseTypeNode = getClassBaseTypeNode(node);
46684670
if (baseTypeNode) {
46694671
write(" extends ");
4670-
emitDeclarationName(node);
4672+
emitNodeWithoutSourceMap(baseTypeNode.typeName);
46714673
}
46724674
write(" {");
46734675
increaseIndent();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [emitClassDeclarationWithConstructorInES6.ts]
2+
class C {
3+
y: number;
4+
constructor(x: number) {
5+
}
6+
}
7+
8+
class D {
9+
y: number;
10+
x: string = "hello";
11+
constructor(x: number, z = "hello") {
12+
this.y = 10;
13+
}
14+
}
15+
16+
//// [emitClassDeclarationWithConstructorInES6.js]
17+
class C {
18+
constructor(x) {
19+
}
20+
}
21+
class D {
22+
constructor(x, z = "hello") {
23+
this.x = "hello";
24+
this.y = 10;
25+
}
26+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts ===
2+
class C {
3+
>C : C
4+
5+
y: number;
6+
>y : number
7+
8+
constructor(x: number) {
9+
>x : number
10+
}
11+
}
12+
13+
class D {
14+
>D : D
15+
16+
y: number;
17+
>y : number
18+
19+
x: string = "hello";
20+
>x : string
21+
22+
constructor(x: number, z = "hello") {
23+
>x : number
24+
>z : string
25+
26+
this.y = 10;
27+
>this.y = 10 : number
28+
>this.y : number
29+
>this : D
30+
>y : number
31+
}
32+
}

tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ class F extends D{
2727
//// [emitClassDeclarationWithConstructorPropertyAssignmentInES6.js]
2828
class C {
2929
constructor() {
30-
thisx = "Hello world";
30+
this.x = "Hello world";
3131
}
3232
}
3333
class D {
3434
constructor() {
35-
thisx = "Hello world";
35+
this.x = "Hello world";
3636
this.y = 10;
3737
}
3838
}
39-
class E extends E {
39+
class E extends D {
4040
constructor(...args) {
4141
super(...args);
42-
thisz = true;
42+
this.z = true;
4343
}
4444
}
45-
class F extends F {
45+
class F extends D {
4646
constructor() {
4747
super();
48-
thisz = true;
48+
this.z = true;
4949
this.j = "HI";
5050
}
5151
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts]
2+
class B<T> {
3+
constructor(a: T) { }
4+
}
5+
class C extends B<string> { }
6+
class D extends B<number> {
7+
constructor(a: any)
8+
constructor(b: number) {
9+
super(b);
10+
}
11+
}
12+
13+
//// [emitClassDeclarationWithExtensionAndTypeArgumentInES6.js]
14+
class B {
15+
constructor(a) {
16+
}
17+
}
18+
class C extends B {
19+
constructor(...args) {
20+
super(...args);
21+
}
22+
}
23+
class D extends B {
24+
constructor(b) {
25+
super(b);
26+
}
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts ===
2+
class B<T> {
3+
>B : B<T>
4+
>T : T
5+
6+
constructor(a: T) { }
7+
>a : T
8+
>T : T
9+
}
10+
class C extends B<string> { }
11+
>C : C
12+
>B : B<T>
13+
14+
class D extends B<number> {
15+
>D : D
16+
>B : B<T>
17+
18+
constructor(a: any)
19+
>a : any
20+
21+
constructor(b: number) {
22+
>b : number
23+
24+
super(b);
25+
>super(b) : void
26+
>super : typeof B
27+
>b : number
28+
}
29+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [emitClassDeclarationWithExtensionInES6.ts]
2+
class B { }
3+
class C extends B { }
4+
class D extends B {
5+
constructor() {
6+
super();
7+
}
8+
}
9+
10+
11+
//// [emitClassDeclarationWithExtensionInES6.js]
12+
class B {
13+
constructor() {
14+
}
15+
}
16+
class C extends B {
17+
constructor(...args) {
18+
super(...args);
19+
}
20+
}
21+
class D extends B {
22+
constructor() {
23+
super();
24+
}
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts ===
2+
class B { }
3+
>B : B
4+
5+
class C extends B { }
6+
>C : C
7+
>B : B
8+
9+
class D extends B {
10+
>D : D
11+
>B : B
12+
13+
constructor() {
14+
super();
15+
>super() : void
16+
>super : typeof B
17+
}
18+
}
19+

tests/baselines/reference/emitClassDeclarationWithMethodInES6.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
//// [emitClassDeclarationWithMethodInES6.ts]
22
class D {
3+
_bar: string;
34
foo() { }
45
["computedName"]() { }
56
["computedName"](a: string) { }
67
["computedName"](a: string): number { return 1; }
78
bar(): string {
8-
return "HI";
9+
return this._bar;
910
}
1011
baz(a: any, x: string): string {
1112
return "HELLO";
1213
}
14+
static ["computedname"]() { }
15+
static ["computedname"](a: string) { }
16+
static ["computedname"](a: string): boolean { return true; }
17+
static staticMethod() {
18+
var x = 1 + 2;
19+
return x
20+
}
21+
static foo(a: string) { }
22+
static bar(a: string): number { return 1; }
1323
}
1424

1525
//// [emitClassDeclarationWithMethodInES6.js]
@@ -26,9 +36,25 @@ class D {
2636
return 1;
2737
}
2838
bar() {
29-
return "HI";
39+
return this._bar;
3040
}
3141
baz(a, x) {
3242
return "HELLO";
3343
}
44+
static ["computedname"]() {
45+
}
46+
static ["computedname"](a) {
47+
}
48+
static ["computedname"](a) {
49+
return true;
50+
}
51+
static staticMethod() {
52+
var x = 1 + 2;
53+
return x;
54+
}
55+
static foo(a) {
56+
}
57+
static bar(a) {
58+
return 1;
59+
}
3460
}

tests/baselines/reference/emitClassDeclarationWithMethodInES6.types

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
class D {
33
>D : D
44

5+
_bar: string;
6+
>_bar : string
7+
58
foo() { }
69
>foo : () => void
710

@@ -15,7 +18,10 @@ class D {
1518
bar(): string {
1619
>bar : () => string
1720

18-
return "HI";
21+
return this._bar;
22+
>this._bar : string
23+
>this : D
24+
>_bar : string
1925
}
2026
baz(a: any, x: string): string {
2127
>baz : (a: any, x: string) => string
@@ -24,4 +30,28 @@ class D {
2430

2531
return "HELLO";
2632
}
33+
static ["computedname"]() { }
34+
static ["computedname"](a: string) { }
35+
>a : string
36+
37+
static ["computedname"](a: string): boolean { return true; }
38+
>a : string
39+
40+
static staticMethod() {
41+
>staticMethod : () => number
42+
43+
var x = 1 + 2;
44+
>x : number
45+
>1 + 2 : number
46+
47+
return x
48+
>x : number
49+
}
50+
static foo(a: string) { }
51+
>foo : (a: string) => void
52+
>a : string
53+
54+
static bar(a: string): number { return 1; }
55+
>bar : (a: string) => number
56+
>a : string
2757
}

0 commit comments

Comments
 (0)