-
-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathSetDescriptor.ts
More file actions
36 lines (30 loc) · 1.17 KB
/
SetDescriptor.ts
File metadata and controls
36 lines (30 loc) · 1.17 KB
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
import { __TS__CloneDescriptor } from "./CloneDescriptor";
import { __TS__DescriptorGet } from "./DescriptorGet";
import { __TS__DescriptorSet } from "./DescriptorSet";
const getmetatable = _G.getmetatable;
function descriptorIndex(this: any, key: string): void {
return __TS__DescriptorGet.call(this, getmetatable(this), key);
}
function descriptorNewIndex(this: any, key: string, value: any): void {
return __TS__DescriptorSet.call(this, getmetatable(this), key, value);
}
// It's also used directly in class transform to add descriptors to the prototype
export function __TS__SetDescriptor(
this: void,
target: any,
key: any,
desc: PropertyDescriptor,
isPrototype = false
): void {
let metatable = isPrototype ? target : getmetatable(target);
if (!metatable) {
metatable = {};
setmetatable(target, metatable);
}
const value = rawget(target, key);
if (value !== undefined) rawset(target, key, undefined);
if (!rawget(metatable, "_descriptors")) metatable._descriptors = {};
metatable._descriptors[key] = __TS__CloneDescriptor(desc);
metatable.__index = descriptorIndex;
metatable.__newindex = descriptorNewIndex;
}