Skip to content

Commit bd2a2ec

Browse files
committed
Add second test case
1 parent 74c337b commit bd2a2ec

4 files changed

+128
-1
lines changed

tests/baselines/reference/constructorWithParameterPropertiesAndPrivateFields.es2015.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ class A {
1313
console.log(this.exposedField);
1414
}
1515
}
16+
17+
class B {
18+
readonly #privateField: string;
19+
20+
constructor(arg: { key: string }, public exposedField: number) {
21+
"prologue";
22+
({ key: this.#privateField } = arg);
23+
}
24+
25+
log() {
26+
console.log(this.#privateField);
27+
console.log(this.exposedField);
28+
}
29+
}
1630

1731

1832
//// [constructorWithParameterPropertiesAndPrivateFields.es2015.js]
@@ -28,7 +42,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
2842
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
2943
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
3044
};
31-
var _A_privateField;
45+
var _A_privateField, _B_privateField;
3246
class A {
3347
constructor(arg, exposedField) {
3448
this.exposedField = exposedField;
@@ -42,3 +56,17 @@ class A {
4256
}
4357
}
4458
_A_privateField = new WeakMap();
59+
class B {
60+
constructor(arg, exposedField) {
61+
this.exposedField = exposedField;
62+
"prologue";
63+
var _a;
64+
_B_privateField.set(this, void 0);
65+
(_a = this, { key: ({ set value(_b) { __classPrivateFieldSet(_a, _B_privateField, _b, "f"); } }).value } = arg);
66+
}
67+
log() {
68+
console.log(__classPrivateFieldGet(this, _B_privateField, "f"));
69+
console.log(this.exposedField);
70+
}
71+
}
72+
_B_privateField = new WeakMap();

tests/baselines/reference/constructorWithParameterPropertiesAndPrivateFields.es2015.symbols

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,42 @@ class A {
3939
}
4040
}
4141

42+
class B {
43+
>B : Symbol(B, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 13, 1))
44+
45+
readonly #privateField: string;
46+
>#privateField : Symbol(B.#privateField, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 15, 9))
47+
48+
constructor(arg: { key: string }, public exposedField: number) {
49+
>arg : Symbol(arg, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 18, 14))
50+
>key : Symbol(key, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 18, 20))
51+
>exposedField : Symbol(B.exposedField, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 18, 35))
52+
53+
"prologue";
54+
({ key: this.#privateField } = arg);
55+
>key : Symbol(key, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 20, 6))
56+
>this.#privateField : Symbol(B.#privateField, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 15, 9))
57+
>this : Symbol(B, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 13, 1))
58+
>arg : Symbol(arg, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 18, 14))
59+
}
60+
61+
log() {
62+
>log : Symbol(B.log, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 21, 3))
63+
64+
console.log(this.#privateField);
65+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
66+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
67+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
68+
>this.#privateField : Symbol(B.#privateField, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 15, 9))
69+
>this : Symbol(B, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 13, 1))
70+
71+
console.log(this.exposedField);
72+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
73+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
74+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
75+
>this.exposedField : Symbol(B.exposedField, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 18, 35))
76+
>this : Symbol(B, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 13, 1))
77+
>exposedField : Symbol(B.exposedField, Decl(constructorWithParameterPropertiesAndPrivateFields.es2015.ts, 18, 35))
78+
}
79+
}
80+

tests/baselines/reference/constructorWithParameterPropertiesAndPrivateFields.es2015.types

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,49 @@ class A {
4444
}
4545
}
4646

47+
class B {
48+
>B : B
49+
50+
readonly #privateField: string;
51+
>#privateField : string
52+
53+
constructor(arg: { key: string }, public exposedField: number) {
54+
>arg : { key: string; }
55+
>key : string
56+
>exposedField : number
57+
58+
"prologue";
59+
>"prologue" : "prologue"
60+
61+
({ key: this.#privateField } = arg);
62+
>({ key: this.#privateField } = arg) : { key: string; }
63+
>{ key: this.#privateField } = arg : { key: string; }
64+
>{ key: this.#privateField } : { key: string; }
65+
>key : string
66+
>this.#privateField : string
67+
>this : this
68+
>arg : { key: string; }
69+
}
70+
71+
log() {
72+
>log : () => void
73+
74+
console.log(this.#privateField);
75+
>console.log(this.#privateField) : void
76+
>console.log : (...data: any[]) => void
77+
>console : Console
78+
>log : (...data: any[]) => void
79+
>this.#privateField : string
80+
>this : this
81+
82+
console.log(this.exposedField);
83+
>console.log(this.exposedField) : void
84+
>console.log : (...data: any[]) => void
85+
>console : Console
86+
>log : (...data: any[]) => void
87+
>this.exposedField : number
88+
>this : this
89+
>exposedField : number
90+
}
91+
}
92+

tests/cases/compiler/constructorWithParameterPropertiesAndPrivateFields.es2015.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,17 @@ class A {
1313
console.log(this.exposedField);
1414
}
1515
}
16+
17+
class B {
18+
readonly #privateField: string;
19+
20+
constructor(arg: { key: string }, public exposedField: number) {
21+
"prologue";
22+
({ key: this.#privateField } = arg);
23+
}
24+
25+
log() {
26+
console.log(this.#privateField);
27+
console.log(this.exposedField);
28+
}
29+
}

0 commit comments

Comments
 (0)