forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathprivateNameAndAny.js
66 lines (64 loc) · 2.09 KB
/
privateNameAndAny.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//// [privateNameAndAny.ts]
class A {
#foo = true;
static #baz = 10;
static #m() {}
method(thing: any) {
thing.#foo; // OK
thing.#m();
thing.#baz;
thing.#bar; // Error
thing.#foo();
}
methodU(thing: unknown) {
thing.#foo;
thing.#m();
thing.#baz;
thing.#bar;
thing.#foo();
}
methodN(thing: never) {
thing.#foo;
thing.#m();
thing.#baz;
thing.#bar;
thing.#foo();
}
};
//// [privateNameAndAny.js]
"use strict";
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 _a, _A_foo, _A_baz, _A_m;
class A {
constructor() {
_A_foo.set(this, true);
}
method(thing) {
__classPrivateFieldGet(thing, _A_foo, "f"); // OK
__classPrivateFieldGet(thing, _a, "m", _A_m).call(thing);
__classPrivateFieldGet(thing, _a, "f", _A_baz);
thing.; // Error
__classPrivateFieldGet(thing, _A_foo, "f").call(thing);
}
methodU(thing) {
__classPrivateFieldGet(thing, _A_foo, "f");
__classPrivateFieldGet(thing, _a, "m", _A_m).call(thing);
__classPrivateFieldGet(thing, _a, "f", _A_baz);
thing.;
__classPrivateFieldGet(thing, _A_foo, "f").call(thing);
}
methodN(thing) {
__classPrivateFieldGet(thing, _A_foo, "f");
__classPrivateFieldGet(thing, _a, "m", _A_m).call(thing);
__classPrivateFieldGet(thing, _a, "f", _A_baz);
thing.;
__classPrivateFieldGet(thing, _A_foo, "f").call(thing);
}
}
_a = A, _A_foo = new WeakMap(), _A_m = function _A_m() { };
_A_baz = { value: 10 };
;