TypeScript/tests/baselines/reference/privateNameFieldDestructuredBinding(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

51 lines
1.3 KiB
TypeScript

//// [privateNameFieldDestructuredBinding.ts]
class A {
#field = 1;
otherObject = new A();
testObject() {
return { x: 10, y: 6 };
}
testArray() {
return [10, 11];
}
constructor() {
let y: number;
({ x: this.#field, y } = this.testObject());
([this.#field, y] = this.testArray());
({ a: this.#field, b: [this.#field] } = { a: 1, b: [2] });
[this.#field, [this.#field]] = [1, [2]];
({ a: this.#field = 1, b: [this.#field = 1] } = { b: [] });
[this.#field = 2] = [];
[this.otherObject.#field = 2] = [];
}
static test(_a: A) {
[_a.#field] = [2];
}
}
//// [privateNameFieldDestructuredBinding.js]
class A {
#field = 1;
otherObject = new A();
testObject() {
return { x: 10, y: 6 };
}
testArray() {
return [10, 11];
}
constructor() {
let y;
({ x: this.#field, y } = this.testObject());
([this.#field, y] = this.testArray());
({ a: this.#field, b: [this.#field] } = { a: 1, b: [2] });
[this.#field, [this.#field]] = [1, [2]];
({ a: this.#field = 1, b: [this.#field = 1] } = { b: [] });
[this.#field = 2] = [];
[this.otherObject.#field = 2] = [];
}
static test(_a) {
[_a.#field] = [2];
}
}