/
decorator.ts
42 lines (36 loc) · 1.38 KB
/
decorator.ts
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
import { DeclarationOption, TypeDocOptionMap, KeyToDeclaration } from '../declaration';
import { Options } from '..';
import { Application } from '../../../application';
const declared: DeclarationOption[] = [];
export function addDecoratedOptions(options: Options) {
options.addDeclarations(declared);
}
/**
* Declares the given option and binds it to the decorated property.
* @param option
*/
export function Option<K extends keyof TypeDocOptionMap>(option: { name: K } & KeyToDeclaration<K>);
/**
* Declares the given option and binds it to the decorated property without strict checks.
*
* @privateRemarks
* Intended for plugin use only. SHOULD NOT BE USED INTERNALLY.
* @param option
*/
export function Option<K extends keyof TypeDocOptionMap>(option: DeclarationOption);
export function Option(option: DeclarationOption) {
declared.push(option);
return function(target: { application: Application } | { options: Options }, key: PropertyKey) {
Object.defineProperty(target, key, {
get(this: { application: Application } | { options: Options }) {
if ('options' in this) {
return this.options.getValue(option.name);
} else {
return this.application.options.getValue(option.name);
}
},
enumerable: true,
configurable: true
});
};
}