TypeScript/tests/baselines/reference/privateNameComputedPropertyName1(target=esnext).js
Titian Cernicova-Dragomir 2484210a00
Gh 41788 incorrect output for esprivate with nested class in esnext (#42663)
* If target:esnext,then useDefineForClassFields: true will now be the default.

* Added error if a private identifier is used in a static a initializer if target:ESNext and useDefineForClassFields:false.

* Added test for new useDefineForClassFields default and error message.

* Fixed tests after changing the default of useDefineForClassFields to true for target esnext

* Fixed code review suggestions.

* Updated error message.

* Added missing static check for the containing property. Fixed other code review issues.
2021-04-07 08:23:16 -07:00

64 lines
1.4 KiB
TypeScript

//// [privateNameComputedPropertyName1.ts]
class A {
#a = 'a';
#b: string;
readonly #c = 'c';
readonly #d: string;
#e = '';
constructor() {
this.#b = 'b';
this.#d = 'd';
}
test() {
const data: Record<string, string> = { a: 'a', b: 'b', c: 'c', d: 'd', e: 'e' };
const {
[this.#a]: a,
[this.#b]: b,
[this.#c]: c,
[this.#d]: d,
[this.#e = 'e']: e,
} = data;
console.log(a, b, c, d, e);
const a1 = data[this.#a];
const b1 = data[this.#b];
const c1 = data[this.#c];
const d1 = data[this.#d];
const e1 = data[this.#e];
console.log(a1, b1, c1, d1);
}
}
new A().test();
//// [privateNameComputedPropertyName1.js]
class A {
#a = 'a';
#b;
#c = 'c';
#d;
#e = '';
constructor() {
this.#b = 'b';
this.#d = 'd';
}
test() {
const data = { a: 'a', b: 'b', c: 'c', d: 'd', e: 'e' };
const { [this.#a]: a, [this.#b]: b, [this.#c]: c, [this.#d]: d, [this.#e = 'e']: e, } = data;
console.log(a, b, c, d, e);
const a1 = data[this.#a];
const b1 = data[this.#b];
const c1 = data[this.#c];
const d1 = data[this.#d];
const e1 = data[this.#e];
console.log(a1, b1, c1, d1);
}
}
new A().test();