TypeScript/tests/baselines/reference/privateNameMethodAssignment.js
Wenlu Wang dc237b317e
Change static fields emits (#43114)
* use emit into iife

* Update emit

* Revert un-related changes

* Allow super in static context

* Allow this and super in static property declaration

* Add more tests

* Avoid errors

* Accept baseline

* Accept baseline

* Add decorated classes test

* Add errors

* Avoid this in emitter

* make lint happy

* Add class expression tests

* Add computed name test

* Avoid super if target below es6

* Adjust function boundary

* Add internal

* Fix minor CR issues

* accept baseline

* Update behavior

* Avoid spaces

* Make lint happy

* Avoid function boundary utils

* Update baseline

* Avoid errors

* Accept baseline

* Accept baseline

* Accept baseline

* Accept baseline

* Use substitutions

* Full coverage for super, this, merge static and private context

* Fix use-before-def in static fields

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2021-06-25 15:49:27 -07:00

42 lines
2.4 KiB
TypeScript

//// [privateNameMethodAssignment.ts]
class A3 {
#method() { };
constructor(a: A3, b: any) {
this.#method = () => {} // Error, not writable
a.#method = () => { }; // Error, not writable
b.#method = () => { } //Error, not writable
({ x: this.#method } = { x: () => {}}); //Error, not writable
let x = this.#method;
b.#method++ //Error, not writable
}
}
//// [privateNameMethodAssignment.js]
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _A3_instances, _A3_method;
class A3 {
constructor(a, b) {
var _a, _b, _c;
_A3_instances.add(this);
__classPrivateFieldSet(this, _A3_instances, () => { }, "m"); // Error, not writable
__classPrivateFieldSet(a, _A3_instances, () => { }, "m"); // Error, not writable
__classPrivateFieldSet(b, _A3_instances, () => { }, "m"); //Error, not writable
(_a = this, { x: ({ set value(_b) { __classPrivateFieldSet(_a, _A3_instances, _b, "m"); } }).value } = { x: () => { } }); //Error, not writable
let x = __classPrivateFieldGet(this, _A3_instances, "m", _A3_method);
__classPrivateFieldSet(_b = b, _A3_instances, (_c = __classPrivateFieldGet(_b, _A3_instances, "m", _A3_method), _c++, _c), "m"); //Error, not writable
}
;
}
_A3_instances = new WeakSet(), _A3_method = function _A3_method() { };