|
1 | 1 | /** |
2 | | - * SEE: https://github.com/Microsoft/TypeScript/blob/master/src/compiler/transformers/ts.ts#L3598 |
| 2 | + * TypeScript 5.0 decorators |
3 | 3 | */ |
4 | | -import { __TS__ObjectGetOwnPropertyDescriptor } from "./ObjectGetOwnPropertyDescriptor"; |
5 | | -import { __TS__SetDescriptor } from "./SetDescriptor"; |
6 | 4 | import { Decorator } from "./Decorator"; |
7 | 5 |
|
8 | | -export function __TS__Decorate<TTarget extends AnyTable, TKey extends keyof TTarget>( |
9 | | - this: void, |
10 | | - decorators: Array<Decorator<TTarget, TKey>>, |
11 | | - target: TTarget, |
12 | | - key?: TKey, |
13 | | - desc?: any |
| 6 | +export function __TS__Decorate<TClass, TTarget>( |
| 7 | + this: TClass, |
| 8 | + originalValue: TTarget, |
| 9 | + decorators: Array<Decorator<TTarget>>, |
| 10 | + context: DecoratorContext |
14 | 11 | ): TTarget { |
15 | | - let result = target; |
| 12 | + let result = originalValue; |
16 | 13 |
|
17 | 14 | for (let i = decorators.length; i >= 0; i--) { |
18 | 15 | const decorator = decorators[i]; |
19 | 16 | if (decorator !== undefined) { |
20 | | - const oldResult = result; |
21 | | - |
22 | | - if (key === undefined) { |
23 | | - result = decorator(result); |
24 | | - } else if (desc === true) { |
25 | | - const value = rawget(target, key); |
26 | | - const descriptor = __TS__ObjectGetOwnPropertyDescriptor(target, key) ?? { |
27 | | - configurable: true, |
28 | | - writable: true, |
29 | | - value, |
30 | | - }; |
31 | | - const desc = decorator(target, key, descriptor) || descriptor; |
32 | | - const isSimpleValue = desc.configurable === true && desc.writable === true && !desc.get && !desc.set; |
33 | | - if (isSimpleValue) { |
34 | | - rawset(target, key, desc.value); |
35 | | - } else { |
36 | | - __TS__SetDescriptor(target, key, { ...descriptor, ...desc }); |
37 | | - } |
38 | | - } else if (desc === false) { |
39 | | - result = decorator(target, key, desc); |
40 | | - } else { |
41 | | - result = decorator(target, key); |
42 | | - } |
43 | | - |
44 | | - result = result || oldResult; |
| 17 | + result = decorator.call(this, result, context) ?? result; |
45 | 18 | } |
46 | 19 | } |
47 | 20 |
|
|
0 commit comments