forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry-pick PR microsoft#34987 into release-3.7
Component commits: 5810765 Emit defineProperty calls before param prop assignments Note that I restricted this to --useDefineForClassFields is true. Nothing changes when it's off. I think this is the correct fix for a patch release. However, in principal there's nothing wrong with moving parameter property initialisation after property declaration initialisation. It would be Extremely Bad and Wrong to rely on this working: ```ts class C { p = this.q // what is q? constructor(public q: number) { } } ``` But today it does, and probably somebody relies on it without knowing. ec79590 Put parameter property initialiser into defineProperty's value
- Loading branch information
1 parent
c18d72f
commit 97fe9f2
Showing
10 changed files
with
242 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//// [definePropertyESNext.ts] | ||
var x: "p" = "p" | ||
class A { | ||
a = 12 | ||
b | ||
["computed"] = 13 | ||
;[x] = 14 | ||
m() { } | ||
constructor(public readonly y: number) { } | ||
} | ||
class B { | ||
} | ||
class C extends B { | ||
z = this.ka | ||
constructor(public ka: number) { | ||
super() | ||
} | ||
ki = this.ka | ||
} | ||
|
||
|
||
//// [definePropertyESNext.js] | ||
var x = "p"; | ||
class A { | ||
y; | ||
a = 12; | ||
b; | ||
["computed"] = 13; | ||
[x] = 14; | ||
m() { } | ||
constructor(y) { | ||
this.y = y; | ||
} | ||
} | ||
class B { | ||
} | ||
class C extends B { | ||
ka; | ||
z = this.ka; | ||
constructor(ka) { | ||
super(); | ||
this.ka = ka; | ||
} | ||
ki = this.ka; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
=== tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyESNext.ts === | ||
var x: "p" = "p" | ||
>x : Symbol(x, Decl(definePropertyESNext.ts, 0, 3)) | ||
|
||
class A { | ||
>A : Symbol(A, Decl(definePropertyESNext.ts, 0, 16)) | ||
|
||
a = 12 | ||
>a : Symbol(A.a, Decl(definePropertyESNext.ts, 1, 9)) | ||
|
||
b | ||
>b : Symbol(A.b, Decl(definePropertyESNext.ts, 2, 10)) | ||
|
||
["computed"] = 13 | ||
>["computed"] : Symbol(A["computed"], Decl(definePropertyESNext.ts, 3, 5)) | ||
>"computed" : Symbol(A["computed"], Decl(definePropertyESNext.ts, 3, 5)) | ||
|
||
;[x] = 14 | ||
>[x] : Symbol(A[x], Decl(definePropertyESNext.ts, 5, 5)) | ||
>x : Symbol(x, Decl(definePropertyESNext.ts, 0, 3)) | ||
|
||
m() { } | ||
>m : Symbol(A.m, Decl(definePropertyESNext.ts, 5, 13)) | ||
|
||
constructor(public readonly y: number) { } | ||
>y : Symbol(A.y, Decl(definePropertyESNext.ts, 7, 16)) | ||
} | ||
class B { | ||
>B : Symbol(B, Decl(definePropertyESNext.ts, 8, 1)) | ||
} | ||
class C extends B { | ||
>C : Symbol(C, Decl(definePropertyESNext.ts, 10, 1)) | ||
>B : Symbol(B, Decl(definePropertyESNext.ts, 8, 1)) | ||
|
||
z = this.ka | ||
>z : Symbol(C.z, Decl(definePropertyESNext.ts, 11, 19)) | ||
>this.ka : Symbol(C.ka, Decl(definePropertyESNext.ts, 13, 16)) | ||
>this : Symbol(C, Decl(definePropertyESNext.ts, 10, 1)) | ||
>ka : Symbol(C.ka, Decl(definePropertyESNext.ts, 13, 16)) | ||
|
||
constructor(public ka: number) { | ||
>ka : Symbol(C.ka, Decl(definePropertyESNext.ts, 13, 16)) | ||
|
||
super() | ||
>super : Symbol(B, Decl(definePropertyESNext.ts, 8, 1)) | ||
} | ||
ki = this.ka | ||
>ki : Symbol(C.ki, Decl(definePropertyESNext.ts, 15, 5)) | ||
>this.ka : Symbol(C.ka, Decl(definePropertyESNext.ts, 13, 16)) | ||
>this : Symbol(C, Decl(definePropertyESNext.ts, 10, 1)) | ||
>ka : Symbol(C.ka, Decl(definePropertyESNext.ts, 13, 16)) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
=== tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyESNext.ts === | ||
var x: "p" = "p" | ||
>x : "p" | ||
>"p" : "p" | ||
|
||
class A { | ||
>A : A | ||
|
||
a = 12 | ||
>a : number | ||
>12 : 12 | ||
|
||
b | ||
>b : any | ||
|
||
["computed"] = 13 | ||
>["computed"] : number | ||
>"computed" : "computed" | ||
>13 : 13 | ||
|
||
;[x] = 14 | ||
>[x] : number | ||
>x : "p" | ||
>14 : 14 | ||
|
||
m() { } | ||
>m : () => void | ||
|
||
constructor(public readonly y: number) { } | ||
>y : number | ||
} | ||
class B { | ||
>B : B | ||
} | ||
class C extends B { | ||
>C : C | ||
>B : B | ||
|
||
z = this.ka | ||
>z : number | ||
>this.ka : number | ||
>this : this | ||
>ka : number | ||
|
||
constructor(public ka: number) { | ||
>ka : number | ||
|
||
super() | ||
>super() : void | ||
>super : typeof B | ||
} | ||
ki = this.ka | ||
>ki : number | ||
>this.ka : number | ||
>this : this | ||
>ka : number | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyESNext.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// @target: esnext | ||
// @useDefineForClassFields: true | ||
var x: "p" = "p" | ||
class A { | ||
a = 12 | ||
b | ||
["computed"] = 13 | ||
;[x] = 14 | ||
m() { } | ||
constructor(public readonly y: number) { } | ||
} | ||
class B { | ||
} | ||
class C extends B { | ||
z = this.ka | ||
constructor(public ka: number) { | ||
super() | ||
} | ||
ki = this.ka | ||
} |