* Add private method syntax support * Add private method spec support * Add private method loose support * Throw error if static private method is used * Add more isStatic & isMethod checks * Remove `writable:false` from private method inits `writable` is false by default. * Add private method func obj equality check * Throw if private accessor is used * Add check for fields === private method loose mode * Throw buildCodeFrameErrors instead of Errors * Move obj destructuring inside for loop * Remove "computed" from ClassPrivateMethod type def
42 lines
917 B
JavaScript
42 lines
917 B
JavaScript
class Foo {
|
|
constructor(status) {
|
|
this.status = status;
|
|
expect(() => this.#getStatus = null).toThrow(TypeError);
|
|
}
|
|
|
|
#getStatus() {
|
|
return this.status;
|
|
}
|
|
|
|
getCurrentStatus() {
|
|
return this.#getStatus();
|
|
}
|
|
|
|
setCurrentStatus(newStatus) {
|
|
this.status = newStatus;
|
|
}
|
|
|
|
getFakeStatus(fakeStatus) {
|
|
const getStatus = this.#getStatus;
|
|
return function () {
|
|
return getStatus.call({ status: fakeStatus });
|
|
};
|
|
}
|
|
|
|
getFakeStatusFunc() {
|
|
return {
|
|
status: 'fake-status',
|
|
getFakeStatus: this.#getStatus,
|
|
};
|
|
}
|
|
}
|
|
|
|
const f = new Foo('inactive');
|
|
expect(f.getCurrentStatus()).toBe('inactive');
|
|
|
|
f.setCurrentStatus('new-status');
|
|
expect(f.getCurrentStatus()).toBe('new-status');
|
|
|
|
expect(f.getFakeStatus('fake')()).toBe('fake');
|
|
expect(f.getFakeStatusFunc().getFakeStatus()).toBe('fake-status');
|