forked from swc-project/swc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
privateNamesUnique-3_es2015.1.normal.js
54 lines (54 loc) · 1.62 KB
/
privateNamesUnique-3_es2015.1.normal.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
function _checkPrivateRedeclaration(obj, privateCollection) {
if (privateCollection.has(obj)) {
throw new TypeError("Cannot initialize the same private elements twice on an object");
}
}
function _classApplyDescriptorGet(receiver, descriptor) {
if (descriptor.get) {
return descriptor.get.call(receiver);
}
return descriptor.value;
}
function _classCheckPrivateStaticFieldDescriptor(descriptor, action) {
if (descriptor === undefined) {
throw new TypeError("attempted to " + action + " private static field before its declaration");
}
}
function _classPrivateFieldInit(obj, privateMap, value) {
_checkPrivateRedeclaration(obj, privateMap);
privateMap.set(obj, value);
}
function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) {
_classCheckPrivateStaticAccess(receiver, classConstructor);
_classCheckPrivateStaticFieldDescriptor(descriptor, "get");
return _classApplyDescriptorGet(receiver, descriptor);
}
function _classCheckPrivateStaticAccess(receiver, classConstructor) {
if (receiver !== classConstructor) {
throw new TypeError("Private static access of wrong provenance");
}
}
var _foo = new WeakMap();
// @target: es2015
class A {
constructor(){
_classPrivateFieldInit(this, _foo, {
writable: true,
value: 1
});
}
}
var _foo = {
writable: true,
value: true
}// error (duplicate)
;
class B {
test(x) {
_classStaticPrivateFieldSpecGet(x, B, _foo1); // error (#foo is a static property on B, not an instance property)
}
}
var _foo1 = {
writable: true,
value: true
};