Skip to content

Commit

Permalink
Cherry-pick PR #44290 into release-4.3 (#44425)
Browse files Browse the repository at this point in the history
Component commits:
f3bf29a fix(44273): preserves 'override' modifier in JavaScript output

Co-authored-by: Oleksandr T <oleksandr.tarasiuk@outlook.com>
  • Loading branch information
TypeScript Bot and a-tarasyuk authored Jun 3, 2021
1 parent e425f57 commit 4f7fe4a
Show file tree
Hide file tree
Showing 25 changed files with 574 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ namespace ts {
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
case SyntaxKind.AbstractKeyword:
case SyntaxKind.OverrideKeyword:
case SyntaxKind.ConstKeyword:
case SyntaxKind.DeclareKeyword:
case SyntaxKind.ReadonlyKeyword:
Expand Down
19 changes: 19 additions & 0 deletions tests/baselines/reference/override16(target=es2015).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [override16.ts]
class A {
foo?: string;
}

class B extends A {
override foo = "string";
}


//// [override16.js]
class A {
}
class B extends A {
constructor() {
super(...arguments);
this.foo = "string";
}
}
16 changes: 16 additions & 0 deletions tests/baselines/reference/override16(target=es2015).symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== tests/cases/conformance/override/override16.ts ===
class A {
>A : Symbol(A, Decl(override16.ts, 0, 0))

foo?: string;
>foo : Symbol(A.foo, Decl(override16.ts, 0, 9))
}

class B extends A {
>B : Symbol(B, Decl(override16.ts, 2, 1))
>A : Symbol(A, Decl(override16.ts, 0, 0))

override foo = "string";
>foo : Symbol(B.foo, Decl(override16.ts, 4, 19))
}

17 changes: 17 additions & 0 deletions tests/baselines/reference/override16(target=es2015).types
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== tests/cases/conformance/override/override16.ts ===
class A {
>A : A

foo?: string;
>foo : string
}

class B extends A {
>B : B
>A : A

override foo = "string";
>foo : string
>"string" : "string"
}

17 changes: 17 additions & 0 deletions tests/baselines/reference/override16(target=esnext).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [override16.ts]
class A {
foo?: string;
}

class B extends A {
override foo = "string";
}


//// [override16.js]
class A {
foo;
}
class B extends A {
foo = "string";
}
16 changes: 16 additions & 0 deletions tests/baselines/reference/override16(target=esnext).symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== tests/cases/conformance/override/override16.ts ===
class A {
>A : Symbol(A, Decl(override16.ts, 0, 0))

foo?: string;
>foo : Symbol(A.foo, Decl(override16.ts, 0, 9))
}

class B extends A {
>B : Symbol(B, Decl(override16.ts, 2, 1))
>A : Symbol(A, Decl(override16.ts, 0, 0))

override foo = "string";
>foo : Symbol(B.foo, Decl(override16.ts, 4, 19))
}

17 changes: 17 additions & 0 deletions tests/baselines/reference/override16(target=esnext).types
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== tests/cases/conformance/override/override16.ts ===
class A {
>A : A

foo?: string;
>foo : string
}

class B extends A {
>B : B
>A : A

override foo = "string";
>foo : string
>"string" : "string"
}

17 changes: 17 additions & 0 deletions tests/baselines/reference/override16.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [override16.ts]
class A {
foo?: string;
}

class B extends A {
override foo = "string";
}


//// [override16.js]
class A {
foo;
}
class B extends A {
foo = "string";
}
16 changes: 16 additions & 0 deletions tests/baselines/reference/override16.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== tests/cases/conformance/override/override16.ts ===
class A {
>A : Symbol(A, Decl(override16.ts, 0, 0))

foo?: string;
>foo : Symbol(A.foo, Decl(override16.ts, 0, 9))
}

class B extends A {
>B : Symbol(B, Decl(override16.ts, 2, 1))
>A : Symbol(A, Decl(override16.ts, 0, 0))

override foo = "string";
>foo : Symbol(B.foo, Decl(override16.ts, 4, 19))
}

17 changes: 17 additions & 0 deletions tests/baselines/reference/override16.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== tests/cases/conformance/override/override16.ts ===
class A {
>A : A

foo?: string;
>foo : string
}

class B extends A {
>B : B
>A : A

override foo = "string";
>foo : string
>"string" : "string"
}

45 changes: 45 additions & 0 deletions tests/baselines/reference/override17(target=es2015).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//// [override17.ts]
class A {
public m1(): number {
return 0;
}

public m2(): number {
return 0;
}

public m3(): void {}
}

class B extends A {
override m1() {
return 10;
}

override m2(): number {
return 30;
}

override m3(): void {}
}


//// [override17.js]
class A {
m1() {
return 0;
}
m2() {
return 0;
}
m3() { }
}
class B extends A {
m1() {
return 10;
}
m2() {
return 30;
}
m3() { }
}
40 changes: 40 additions & 0 deletions tests/baselines/reference/override17(target=es2015).symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
=== tests/cases/conformance/override/override17.ts ===
class A {
>A : Symbol(A, Decl(override17.ts, 0, 0))

public m1(): number {
>m1 : Symbol(A.m1, Decl(override17.ts, 0, 9))

return 0;
}

public m2(): number {
>m2 : Symbol(A.m2, Decl(override17.ts, 3, 5))

return 0;
}

public m3(): void {}
>m3 : Symbol(A.m3, Decl(override17.ts, 7, 5))
}

class B extends A {
>B : Symbol(B, Decl(override17.ts, 10, 1))
>A : Symbol(A, Decl(override17.ts, 0, 0))

override m1() {
>m1 : Symbol(B.m1, Decl(override17.ts, 12, 19))

return 10;
}

override m2(): number {
>m2 : Symbol(B.m2, Decl(override17.ts, 15, 5))

return 30;
}

override m3(): void {}
>m3 : Symbol(B.m3, Decl(override17.ts, 19, 5))
}

44 changes: 44 additions & 0 deletions tests/baselines/reference/override17(target=es2015).types
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
=== tests/cases/conformance/override/override17.ts ===
class A {
>A : A

public m1(): number {
>m1 : () => number

return 0;
>0 : 0
}

public m2(): number {
>m2 : () => number

return 0;
>0 : 0
}

public m3(): void {}
>m3 : () => void
}

class B extends A {
>B : B
>A : A

override m1() {
>m1 : () => number

return 10;
>10 : 10
}

override m2(): number {
>m2 : () => number

return 30;
>30 : 30
}

override m3(): void {}
>m3 : () => void
}

45 changes: 45 additions & 0 deletions tests/baselines/reference/override17(target=esnext).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//// [override17.ts]
class A {
public m1(): number {
return 0;
}

public m2(): number {
return 0;
}

public m3(): void {}
}

class B extends A {
override m1() {
return 10;
}

override m2(): number {
return 30;
}

override m3(): void {}
}


//// [override17.js]
class A {
m1() {
return 0;
}
m2() {
return 0;
}
m3() { }
}
class B extends A {
m1() {
return 10;
}
m2() {
return 30;
}
m3() { }
}
40 changes: 40 additions & 0 deletions tests/baselines/reference/override17(target=esnext).symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
=== tests/cases/conformance/override/override17.ts ===
class A {
>A : Symbol(A, Decl(override17.ts, 0, 0))

public m1(): number {
>m1 : Symbol(A.m1, Decl(override17.ts, 0, 9))

return 0;
}

public m2(): number {
>m2 : Symbol(A.m2, Decl(override17.ts, 3, 5))

return 0;
}

public m3(): void {}
>m3 : Symbol(A.m3, Decl(override17.ts, 7, 5))
}

class B extends A {
>B : Symbol(B, Decl(override17.ts, 10, 1))
>A : Symbol(A, Decl(override17.ts, 0, 0))

override m1() {
>m1 : Symbol(B.m1, Decl(override17.ts, 12, 19))

return 10;
}

override m2(): number {
>m2 : Symbol(B.m2, Decl(override17.ts, 15, 5))

return 30;
}

override m3(): void {}
>m3 : Symbol(B.m3, Decl(override17.ts, 19, 5))
}

Loading

0 comments on commit 4f7fe4a

Please sign in to comment.