Skip to content

Commit 91c5bae

Browse files
author
Yui T
committed
Address code review
1 parent 88933d5 commit 91c5bae

14 files changed

+134
-39
lines changed

src/compiler/emitter.ts

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4511,50 +4511,26 @@ module ts {
45114511
return emitPinnedOrTripleSlashComments(member);
45124512
}
45134513

4514+
}
4515+
if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) {
45144516
writeLine();
45154517
emitLeadingComments(member);
45164518
emitStart(member);
45174519
if (member.flags & NodeFlags.Static) {
45184520
write("static ");
45194521
}
4522+
4523+
if (member.kind === SyntaxKind.GetAccessor) {
4524+
write("get ");
4525+
}
4526+
else if (member.kind === SyntaxKind.SetAccessor) {
4527+
write("set ");
4528+
}
45204529
emit((<MethodDeclaration>member).name);
45214530
emitSignatureAndBody(<MethodDeclaration>member);
45224531
emitEnd(member);
45234532
emitTrailingComments(member);
45244533
}
4525-
else if (member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) {
4526-
var accessors = getAllAccessorDeclarations(node.members, <AccessorDeclaration>member);
4527-
if (member === accessors.firstAccessor) {
4528-
writeLine();
4529-
if (accessors.getAccessor) {
4530-
writeLine();
4531-
emitLeadingComments(accessors.getAccessor);
4532-
emitStart(accessors.getAccessor);
4533-
if (member.flags & NodeFlags.Static) {
4534-
write("static ");
4535-
}
4536-
write("get ");
4537-
emit((<MethodDeclaration>member).name);
4538-
emitSignatureAndBody(accessors.getAccessor);
4539-
emitEnd(accessors.getAccessor);
4540-
emitTrailingComments(accessors.getAccessor);
4541-
}
4542-
if (accessors.setAccessor) {
4543-
// We will only write new line if we just emit getAccessor
4544-
writeLine();
4545-
emitLeadingComments(accessors.setAccessor);
4546-
emitStart(accessors.setAccessor);
4547-
if (member.flags & NodeFlags.Static) {
4548-
write("static ");
4549-
}
4550-
write("set ");
4551-
emit((<MethodDeclaration>member).name);
4552-
emitSignatureAndBody(accessors.setAccessor);
4553-
emitEnd(accessors.setAccessor);
4554-
emitTrailingComments(accessors.setAccessor);;
4555-
}
4556-
}
4557-
}
45584534
});
45594535
}
45604536

tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ class C {
1010
static get ["computedname"]() {
1111
return "";
1212
}
13+
get ["computedname"]() {
14+
return "";
15+
}
16+
get ["computedname"]() {
17+
return "";
18+
}
19+
20+
set ["computedname"](x: any) {
21+
}
22+
set ["computedname"](y: string) {
23+
}
1324

1425
set foo(a: string) { }
1526
static set bar(b: number) { }
@@ -27,6 +38,16 @@ class C {
2738
static get ["computedname"]() {
2839
return "";
2940
}
41+
get ["computedname"]() {
42+
return "";
43+
}
44+
get ["computedname"]() {
45+
return "";
46+
}
47+
set ["computedname"](x) {
48+
}
49+
set ["computedname"](y) {
50+
}
3051
set foo(a) {
3152
}
3253
static set bar(b) {

tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ class C {
2121
static get ["computedname"]() {
2222
return "";
2323
}
24+
get ["computedname"]() {
25+
return "";
26+
}
27+
get ["computedname"]() {
28+
return "";
29+
}
30+
31+
set ["computedname"](x: any) {
32+
>x : any
33+
}
34+
set ["computedname"](y: string) {
35+
>y : string
36+
}
2437

2538
set foo(a: string) { }
2639
>foo : string
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//// [emitClassDeclarationWithLiteralPropertyNameInES6.ts]
2+
class B {
3+
"hello" = 10;
4+
0b110 = "world";
5+
0o23534 = "WORLD";
6+
20 = "twenty";
7+
"foo"() { }
8+
0b1110() {}
9+
11() { }
10+
interface() { }
11+
static "hi" = 10000;
12+
static 22 = "twenty-two";
13+
static 0b101 = "binary";
14+
static 0o3235 = "octal";
15+
}
16+
17+
//// [emitClassDeclarationWithLiteralPropertyNameInES6.js]
18+
class B {
19+
constructor() {
20+
this["hello"] = 10;
21+
this[0b110] = "world";
22+
this[0o23534] = "WORLD";
23+
this[20] = "twenty";
24+
}
25+
"foo"() {
26+
}
27+
0b1110() {
28+
}
29+
11() {
30+
}
31+
interface() {
32+
}
33+
}
34+
B["hi"] = 10000;
35+
B[22] = "twenty-two";
36+
B[0b101] = "binary";
37+
B[0o3235] = "octal";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithLiteralPropertyNameInES6.ts ===
2+
class B {
3+
>B : B
4+
5+
"hello" = 10;
6+
0b110 = "world";
7+
0o23534 = "WORLD";
8+
20 = "twenty";
9+
"foo"() { }
10+
0b1110() {}
11+
11() { }
12+
interface() { }
13+
>interface : () => void
14+
15+
static "hi" = 10000;
16+
static 22 = "twenty-two";
17+
static 0b101 = "binary";
18+
static 0o3235 = "octal";
19+
}

tests/baselines/reference/emitClassDeclarationWithThisKeyword.js renamed to tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [emitClassDeclarationWithThisKeyword.ts]
1+
//// [emitClassDeclarationWithThisKeywordInES6.ts]
22
class B {
33
x = 10;
44
constructor() {
@@ -18,7 +18,7 @@ class B {
1818
}
1919
}
2020

21-
//// [emitClassDeclarationWithThisKeyword.js]
21+
//// [emitClassDeclarationWithThisKeywordInES6.js]
2222
class B {
2323
constructor() {
2424
this.x = 10;

tests/baselines/reference/emitClassDeclarationWithThisKeyword.types renamed to tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts ===
1+
=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeywordInES6.ts ===
22
class B {
33
>B : B
44

tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js renamed to tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [emitClassDeclarationWithTypeArgumentAndOverload.ts]
1+
//// [emitClassDeclarationWithTypeArgumentAndOverloadInES6.ts]
22
class B<T> {
33
x: T;
44
B: T;
@@ -22,7 +22,7 @@ class B<T> {
2222
}
2323
}
2424

25-
//// [emitClassDeclarationWithTypeArgumentAndOverload.js]
25+
//// [emitClassDeclarationWithTypeArgumentAndOverloadInES6.js]
2626
class B {
2727
constructor(a) {
2828
this.B = a;

tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types renamed to tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts ===
1+
=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverloadInES6.ts ===
22
class B<T> {
33
>B : B<T>
44
>T : T

tests/baselines/reference/symbolProperty44.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ class C {
1313
get [Symbol.hasInstance]() {
1414
return "";
1515
}
16+
get [Symbol.hasInstance]() {
17+
return "";
18+
}
1619
}

0 commit comments

Comments
 (0)