-
-
Notifications
You must be signed in to change notification settings - Fork 185
Expand file tree
/
Copy pathCloneDescriptor.ts
More file actions
26 lines (22 loc) · 844 Bytes
/
CloneDescriptor.ts
File metadata and controls
26 lines (22 loc) · 844 Bytes
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
export function __TS__CloneDescriptor(
this: void,
{ enumerable, configurable, get, set, writable, value }: PropertyDescriptor
): PropertyDescriptor {
const descriptor: PropertyDescriptor = {
enumerable: enumerable === true,
configurable: configurable === true,
};
const hasGetterOrSetter = get !== undefined || set !== undefined;
const hasValueOrWritableAttribute = writable !== undefined || value !== undefined;
if (hasGetterOrSetter && hasValueOrWritableAttribute) {
throw "Invalid property descriptor. Cannot both specify accessors and a value or writable attribute.";
}
if (get || set) {
descriptor.get = get;
descriptor.set = set;
} else {
descriptor.value = value;
descriptor.writable = writable === true;
}
return descriptor;
}