@goast/typescript 0.9.0-beta.2 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/assets.d.ts +18 -0
- package/dist/src/assets.js +18 -0
- package/dist/src/ast/common.d.ts +6 -0
- package/dist/src/ast/node.d.ts +15 -0
- package/dist/src/ast/node.js +15 -0
- package/dist/src/ast/nodes/argument.d.ts +31 -0
- package/dist/src/ast/nodes/argument.js +31 -0
- package/dist/src/ast/nodes/array-type.d.ts +32 -0
- package/dist/src/ast/nodes/array-type.js +32 -0
- package/dist/src/ast/nodes/arrow-function.d.ts +56 -0
- package/dist/src/ast/nodes/arrow-function.js +56 -0
- package/dist/src/ast/nodes/call.d.ts +34 -0
- package/dist/src/ast/nodes/call.js +34 -0
- package/dist/src/ast/nodes/class.d.ts +73 -0
- package/dist/src/ast/nodes/class.js +73 -0
- package/dist/src/ast/nodes/constructor-parameter.d.ts +37 -0
- package/dist/src/ast/nodes/constructor-parameter.js +37 -0
- package/dist/src/ast/nodes/constructor.d.ts +44 -0
- package/dist/src/ast/nodes/constructor.js +44 -0
- package/dist/src/ast/nodes/decorator.d.ts +35 -0
- package/dist/src/ast/nodes/decorator.js +35 -0
- package/dist/src/ast/nodes/doc-tag.d.ts +39 -0
- package/dist/src/ast/nodes/doc-tag.js +39 -0
- package/dist/src/ast/nodes/doc.d.ts +38 -0
- package/dist/src/ast/nodes/doc.js +38 -0
- package/dist/src/ast/nodes/enum-value.d.ts +37 -0
- package/dist/src/ast/nodes/enum-value.js +37 -0
- package/dist/src/ast/nodes/enum.d.ts +47 -0
- package/dist/src/ast/nodes/enum.js +47 -0
- package/dist/src/ast/nodes/export.d.ts +51 -0
- package/dist/src/ast/nodes/export.js +51 -0
- package/dist/src/ast/nodes/function-type.d.ts +35 -0
- package/dist/src/ast/nodes/function-type.js +35 -0
- package/dist/src/ast/nodes/function.d.ts +61 -0
- package/dist/src/ast/nodes/function.js +61 -0
- package/dist/src/ast/nodes/generic-parameter.d.ts +44 -0
- package/dist/src/ast/nodes/generic-parameter.js +44 -0
- package/dist/src/ast/nodes/indexer.d.ts +41 -0
- package/dist/src/ast/nodes/indexer.js +41 -0
- package/dist/src/ast/nodes/interface.d.ts +57 -0
- package/dist/src/ast/nodes/interface.js +57 -0
- package/dist/src/ast/nodes/intersection-type.d.ts +32 -0
- package/dist/src/ast/nodes/intersection-type.js +32 -0
- package/dist/src/ast/nodes/lookup-type.d.ts +34 -0
- package/dist/src/ast/nodes/lookup-type.js +34 -0
- package/dist/src/ast/nodes/method.d.ts +90 -0
- package/dist/src/ast/nodes/method.js +90 -0
- package/dist/src/ast/nodes/object-type.d.ts +34 -0
- package/dist/src/ast/nodes/object-type.js +34 -0
- package/dist/src/ast/nodes/object.d.ts +34 -0
- package/dist/src/ast/nodes/object.js +34 -0
- package/dist/src/ast/nodes/parameter.d.ts +51 -0
- package/dist/src/ast/nodes/parameter.js +51 -0
- package/dist/src/ast/nodes/property-accessor.d.ts +94 -0
- package/dist/src/ast/nodes/property-accessor.js +94 -0
- package/dist/src/ast/nodes/property.d.ts +113 -0
- package/dist/src/ast/nodes/property.js +113 -0
- package/dist/src/ast/nodes/reference.d.ts +90 -0
- package/dist/src/ast/nodes/reference.js +66 -0
- package/dist/src/ast/nodes/string.d.ts +35 -0
- package/dist/src/ast/nodes/string.js +35 -0
- package/dist/src/ast/nodes/tuple.d.ts +33 -0
- package/dist/src/ast/nodes/tuple.js +33 -0
- package/dist/src/ast/nodes/type-alias.d.ts +44 -0
- package/dist/src/ast/nodes/type-alias.js +44 -0
- package/dist/src/ast/nodes/typeof.d.ts +41 -0
- package/dist/src/ast/nodes/typeof.js +41 -0
- package/dist/src/ast/nodes/types.d.ts +12 -0
- package/dist/src/ast/nodes/union-type.d.ts +31 -0
- package/dist/src/ast/nodes/union-type.js +31 -0
- package/dist/src/ast/nodes/variable.d.ts +46 -0
- package/dist/src/ast/nodes/variable.js +46 -0
- package/dist/src/ast/references/angular.d.ts +7 -0
- package/dist/src/ast/references/angular.js +7 -0
- package/dist/src/ast/references/easy-network-stub.d.ts +4 -0
- package/dist/src/ast/references/easy-network-stub.js +4 -0
- package/dist/src/ast/references/k6.d.ts +3 -0
- package/dist/src/ast/references/k6.js +3 -0
- package/dist/src/ast/references/rxjs.d.ts +5 -0
- package/dist/src/ast/references/rxjs.js +5 -0
- package/dist/src/ast/references/typescript.d.ts +30 -0
- package/dist/src/ast/references/typescript.js +30 -0
- package/dist/src/ast/utils/get-type-script-builder-options.d.ts +8 -0
- package/dist/src/ast/utils/get-type-script-builder-options.js +8 -0
- package/dist/src/ast/utils/to-ts-node.d.ts +28 -0
- package/dist/src/ast/utils/write-ts-generic-parameters.d.ts +9 -0
- package/dist/src/ast/utils/write-ts-generic-parameters.js +9 -0
- package/dist/src/ast/utils/write-ts-members.d.ts +12 -0
- package/dist/src/ast/utils/write-ts-members.js +12 -0
- package/dist/src/ast/utils/write-ts-nodes.d.ts +16 -0
- package/dist/src/ast/utils/write-ts-nodes.js +16 -0
- package/dist/src/ast/utils/write-ts-parameters.d.ts +9 -0
- package/dist/src/ast/utils/write-ts-parameters.js +9 -0
- package/dist/src/common-results.d.ts +65 -0
- package/dist/src/config.d.ts +32 -0
- package/dist/src/config.js +5 -0
- package/dist/src/file-builder.d.ts +104 -0
- package/dist/src/file-builder.js +93 -0
- package/dist/src/generators/file-generator.d.ts +14 -0
- package/dist/src/generators/file-generator.js +9 -0
- package/dist/src/generators/models/model-generator.d.ts +24 -0
- package/dist/src/generators/models/model-generator.js +15 -0
- package/dist/src/generators/models/models-generator.d.ts +16 -0
- package/dist/src/generators/models/models-generator.js +16 -0
- package/dist/src/generators/models/models.d.ts +53 -0
- package/dist/src/generators/models/models.js +8 -0
- package/dist/src/generators/services/angular-services/angular-service-generator.d.ts +27 -0
- package/dist/src/generators/services/angular-services/angular-service-generator.js +17 -0
- package/dist/src/generators/services/angular-services/angular-services-generator.d.ts +21 -0
- package/dist/src/generators/services/angular-services/angular-services-generator.js +21 -0
- package/dist/src/generators/services/angular-services/models.d.ts +70 -1
- package/dist/src/generators/services/angular-services/models.js +5 -0
- package/dist/src/generators/services/angular-services/refs.d.ts +11 -0
- package/dist/src/generators/services/angular-services/refs.js +11 -0
- package/dist/src/generators/services/easy-network-stub/easy-network-stub-generator.d.ts +22 -0
- package/dist/src/generators/services/easy-network-stub/easy-network-stub-generator.js +12 -0
- package/dist/src/generators/services/easy-network-stub/easy-network-stubs-generator.d.ts +16 -0
- package/dist/src/generators/services/easy-network-stub/easy-network-stubs-generator.js +16 -0
- package/dist/src/generators/services/easy-network-stub/models.d.ts +61 -0
- package/dist/src/generators/services/easy-network-stub/models.js +5 -0
- package/dist/src/generators/services/easy-network-stub/refs.d.ts +7 -0
- package/dist/src/generators/services/easy-network-stub/refs.js +7 -0
- package/dist/src/generators/services/fetch-clients/fetch-client-generator.d.ts +22 -0
- package/dist/src/generators/services/fetch-clients/fetch-client-generator.js +12 -0
- package/dist/src/generators/services/fetch-clients/fetch-clients-generator.d.ts +17 -0
- package/dist/src/generators/services/fetch-clients/fetch-clients-generator.js +17 -0
- package/dist/src/generators/services/fetch-clients/models.d.ts +64 -1
- package/dist/src/generators/services/fetch-clients/models.js +5 -0
- package/dist/src/generators/services/fetch-clients/refs.d.ts +7 -0
- package/dist/src/generators/services/fetch-clients/refs.js +7 -0
- package/dist/src/generators/services/k6-clients/k6-client-generator.d.ts +21 -0
- package/dist/src/generators/services/k6-clients/k6-client-generator.js +11 -0
- package/dist/src/generators/services/k6-clients/k6-clients-generator.d.ts +18 -0
- package/dist/src/generators/services/k6-clients/k6-clients-generator.js +18 -0
- package/dist/src/generators/services/k6-clients/models.d.ts +65 -1
- package/dist/src/generators/services/k6-clients/models.js +5 -0
- package/dist/src/generators/services/k6-clients/refs.d.ts +8 -0
- package/dist/src/generators/services/k6-clients/refs.js +8 -0
- package/dist/src/import-collection.d.ts +81 -0
- package/dist/src/import-collection.js +58 -0
- package/dist/src/utils.d.ts +62 -0
- package/dist/src/utils.js +47 -0
- package/package.json +2 -2
|
@@ -23,24 +23,114 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
23
23
|
returnType?: Nullable<TsType<TBuilder>>;
|
|
24
24
|
body?: Nullable<AppendValue<TBuilder>>;
|
|
25
25
|
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Represents a method of a class, or a method signature of an object type or an object literal.
|
|
28
|
+
*
|
|
29
|
+
* Written in this order: doc comment, decorators, modifiers (access modifier, `static`, `abstract`, `override`,
|
|
30
|
+
* `async`), name, optional marker, generics, parameters, return type, and the body. Without a body the method ends
|
|
31
|
+
* with a semicolon, except inside an object literal (`tsObject`), where every method ends with a comma instead. The
|
|
32
|
+
* injection points are named after the parts they wrap, such as `beforeParams` and `afterReturnType`.
|
|
33
|
+
*
|
|
34
|
+
* @template TBuilder The type of the source builder the method is written to.
|
|
35
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
36
|
+
* @see tsMethod
|
|
37
|
+
*/
|
|
26
38
|
export declare class TsMethod<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
|
|
39
|
+
/**
|
|
40
|
+
* The doc comment written above the method, or `null` to omit it. The descriptions of the generic parameters and of
|
|
41
|
+
* the parameters are added to it as `@template` and `@param` tags.
|
|
42
|
+
*/
|
|
27
43
|
doc: TsDoc<TBuilder> | null;
|
|
44
|
+
/**
|
|
45
|
+
* The decorators written above the method, each on its own line.
|
|
46
|
+
*/
|
|
28
47
|
decorators: TsDecorator<TBuilder>[];
|
|
48
|
+
/**
|
|
49
|
+
* The access modifier written before the method, such as `public`, or `null` to omit it.
|
|
50
|
+
*/
|
|
29
51
|
accessModifier: TsAccessModifier | null;
|
|
52
|
+
/**
|
|
53
|
+
* Whether the method is written with the `static` keyword.
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
30
56
|
static: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether the method is written with the `abstract` keyword.
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
31
61
|
abstract: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the method is written with the `override` keyword.
|
|
64
|
+
* @default false
|
|
65
|
+
*/
|
|
32
66
|
override: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Whether the method is written with the `async` keyword, which is placed after `override`.
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
33
71
|
async: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* The method name, written verbatim after the modifiers.
|
|
74
|
+
*/
|
|
34
75
|
name: string;
|
|
76
|
+
/**
|
|
77
|
+
* Whether the name is followed by `?`, which marks the method as optional, such as `x?()`.
|
|
78
|
+
* @default false
|
|
79
|
+
*/
|
|
35
80
|
optional: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The type parameters written in angle brackets after the name, such as `<T, U>`. Described parameters also add a
|
|
83
|
+
* `@template` tag to the doc comment.
|
|
84
|
+
*/
|
|
36
85
|
generics: (TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
|
|
86
|
+
/**
|
|
87
|
+
* The parameters written in parentheses, in the given order. Each parameter with a description adds a `@param` tag to
|
|
88
|
+
* the doc comment.
|
|
89
|
+
*/
|
|
37
90
|
parameters: (TsParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
|
|
91
|
+
/**
|
|
92
|
+
* The return type written after the parameters, such as `: number`, or `null` to omit it.
|
|
93
|
+
*/
|
|
38
94
|
returnType: TsType<TBuilder> | null;
|
|
95
|
+
/**
|
|
96
|
+
* The code written in braces after the signature, one statement per line. `null` writes the method without a body,
|
|
97
|
+
* which ends with a semicolon outside of object literals.
|
|
98
|
+
*/
|
|
39
99
|
body: AppendValue<TBuilder> | null;
|
|
100
|
+
/**
|
|
101
|
+
* Initializes a new instance of the TsMethod class.
|
|
102
|
+
* @param options The options to use for this instance.
|
|
103
|
+
*/
|
|
40
104
|
constructor(options: Options<TBuilder, TInjects>);
|
|
41
105
|
protected onWrite(builder: TBuilder): void;
|
|
42
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Creates a method node. This is the function that `tsMethod` wraps, and `tsMethod` also provides `write`.
|
|
109
|
+
*
|
|
110
|
+
* @param name The name of the method. See `TsMethod.name`.
|
|
111
|
+
* @param options The settings of the method. See `TsMethod` for the available properties.
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* createMethod('x', { returnType: 'number' });
|
|
115
|
+
* // Emits:
|
|
116
|
+
* // x(): number;
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
43
119
|
export declare const createMethod: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => TsMethod<TBuilder>;
|
|
120
|
+
/**
|
|
121
|
+
* Factory for creating method nodes. The `write` function writes one or more method nodes to a builder.
|
|
122
|
+
*
|
|
123
|
+
* @param name The name of the method. See `TsMethod.name`.
|
|
124
|
+
* @param options The settings of the method. See `TsMethod` for the available properties.
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* tsMethod('x', { parameters: [tsParameter('y'), tsParameter('z')], returnType: 'number', body: 'return 42;' });
|
|
128
|
+
* // Emits:
|
|
129
|
+
* // x(y, z): number {
|
|
130
|
+
* // return 42;
|
|
131
|
+
* // }
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
44
134
|
export declare const tsMethod: typeof createMethod & {
|
|
45
135
|
write: typeof writeTsNodes;
|
|
46
136
|
};
|
|
@@ -6,20 +6,84 @@ import { tsDoc } from './doc.js';
|
|
|
6
6
|
import { tsGenericParameter } from './generic-parameter.js';
|
|
7
7
|
import { TsObject } from './object.js';
|
|
8
8
|
import { tsParameter } from './parameter.js';
|
|
9
|
+
/**
|
|
10
|
+
* Represents a method of a class, or a method signature of an object type or an object literal.
|
|
11
|
+
*
|
|
12
|
+
* Written in this order: doc comment, decorators, modifiers (access modifier, `static`, `abstract`, `override`,
|
|
13
|
+
* `async`), name, optional marker, generics, parameters, return type, and the body. Without a body the method ends
|
|
14
|
+
* with a semicolon, except inside an object literal (`tsObject`), where every method ends with a comma instead. The
|
|
15
|
+
* injection points are named after the parts they wrap, such as `beforeParams` and `afterReturnType`.
|
|
16
|
+
*
|
|
17
|
+
* @template TBuilder The type of the source builder the method is written to.
|
|
18
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
19
|
+
* @see tsMethod
|
|
20
|
+
*/
|
|
9
21
|
export class TsMethod extends TsNode {
|
|
22
|
+
/**
|
|
23
|
+
* The doc comment written above the method, or `null` to omit it. The descriptions of the generic parameters and of
|
|
24
|
+
* the parameters are added to it as `@template` and `@param` tags.
|
|
25
|
+
*/
|
|
10
26
|
doc;
|
|
27
|
+
/**
|
|
28
|
+
* The decorators written above the method, each on its own line.
|
|
29
|
+
*/
|
|
11
30
|
decorators;
|
|
31
|
+
/**
|
|
32
|
+
* The access modifier written before the method, such as `public`, or `null` to omit it.
|
|
33
|
+
*/
|
|
12
34
|
accessModifier;
|
|
35
|
+
/**
|
|
36
|
+
* Whether the method is written with the `static` keyword.
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
13
39
|
static;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the method is written with the `abstract` keyword.
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
14
44
|
abstract;
|
|
45
|
+
/**
|
|
46
|
+
* Whether the method is written with the `override` keyword.
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
15
49
|
override;
|
|
50
|
+
/**
|
|
51
|
+
* Whether the method is written with the `async` keyword, which is placed after `override`.
|
|
52
|
+
* @default false
|
|
53
|
+
*/
|
|
16
54
|
async;
|
|
55
|
+
/**
|
|
56
|
+
* The method name, written verbatim after the modifiers.
|
|
57
|
+
*/
|
|
17
58
|
name;
|
|
59
|
+
/**
|
|
60
|
+
* Whether the name is followed by `?`, which marks the method as optional, such as `x?()`.
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
18
63
|
optional;
|
|
64
|
+
/**
|
|
65
|
+
* The type parameters written in angle brackets after the name, such as `<T, U>`. Described parameters also add a
|
|
66
|
+
* `@template` tag to the doc comment.
|
|
67
|
+
*/
|
|
19
68
|
generics;
|
|
69
|
+
/**
|
|
70
|
+
* The parameters written in parentheses, in the given order. Each parameter with a description adds a `@param` tag to
|
|
71
|
+
* the doc comment.
|
|
72
|
+
*/
|
|
20
73
|
parameters;
|
|
74
|
+
/**
|
|
75
|
+
* The return type written after the parameters, such as `: number`, or `null` to omit it.
|
|
76
|
+
*/
|
|
21
77
|
returnType;
|
|
78
|
+
/**
|
|
79
|
+
* The code written in braces after the signature, one statement per line. `null` writes the method without a body,
|
|
80
|
+
* which ends with a semicolon outside of object literals.
|
|
81
|
+
*/
|
|
22
82
|
body;
|
|
83
|
+
/**
|
|
84
|
+
* Initializes a new instance of the TsMethod class.
|
|
85
|
+
* @param options The options to use for this instance.
|
|
86
|
+
*/
|
|
23
87
|
constructor(options) {
|
|
24
88
|
super(options);
|
|
25
89
|
this.doc = options.doc ?? null;
|
|
@@ -86,7 +150,33 @@ export class TsMethod extends TsNode {
|
|
|
86
150
|
builder.appendLine();
|
|
87
151
|
}
|
|
88
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Creates a method node. This is the function that `tsMethod` wraps, and `tsMethod` also provides `write`.
|
|
155
|
+
*
|
|
156
|
+
* @param name The name of the method. See `TsMethod.name`.
|
|
157
|
+
* @param options The settings of the method. See `TsMethod` for the available properties.
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* createMethod('x', { returnType: 'number' });
|
|
161
|
+
* // Emits:
|
|
162
|
+
* // x(): number;
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
89
165
|
export const createMethod = (name, options) => new TsMethod({ ...options, name });
|
|
166
|
+
/**
|
|
167
|
+
* Factory for creating method nodes. The `write` function writes one or more method nodes to a builder.
|
|
168
|
+
*
|
|
169
|
+
* @param name The name of the method. See `TsMethod.name`.
|
|
170
|
+
* @param options The settings of the method. See `TsMethod` for the available properties.
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* tsMethod('x', { parameters: [tsParameter('y'), tsParameter('z')], returnType: 'number', body: 'return 42;' });
|
|
174
|
+
* // Emits:
|
|
175
|
+
* // x(y, z): number {
|
|
176
|
+
* // return 42;
|
|
177
|
+
* // }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
90
180
|
export const tsMethod = Object.assign(createMethod, {
|
|
91
181
|
write: writeTsNodes,
|
|
92
182
|
});
|
|
@@ -9,12 +9,46 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
9
9
|
members?: Nullable<Nullable<Member<TBuilder>>[]>;
|
|
10
10
|
}>;
|
|
11
11
|
type Member<TBuilder extends SourceBuilder> = TsProperty<TBuilder> | TsMethod<TBuilder> | TsIndexer<TBuilder> | BasicAppendValue<TBuilder>;
|
|
12
|
+
/**
|
|
13
|
+
* Represents an object type literal, which describes the shape of a value in a type position.
|
|
14
|
+
*
|
|
15
|
+
* The members are written between braces, one per line. An object type without members is written as `{}`.
|
|
16
|
+
* Properties and bodyless methods end with a semicolon.
|
|
17
|
+
*
|
|
18
|
+
* @template TBuilder The type of the source builder the object type is written to.
|
|
19
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
20
|
+
* @see tsObjectType
|
|
21
|
+
* @see TsObject
|
|
22
|
+
*/
|
|
12
23
|
export declare class TsObjectType<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
|
|
24
|
+
/**
|
|
25
|
+
* The members written between the braces, in the given order. Null entries are skipped. Properties and bodyless
|
|
26
|
+
* methods without a doc comment or decorators are written without blank lines, other members are set off by blank
|
|
27
|
+
* lines.
|
|
28
|
+
*/
|
|
13
29
|
members: Member<TBuilder>[];
|
|
30
|
+
/**
|
|
31
|
+
* Initializes a new instance of the TsObjectType class.
|
|
32
|
+
* @param options The options to use for this instance.
|
|
33
|
+
*/
|
|
14
34
|
constructor(options: Options<TBuilder, TInjects>);
|
|
15
35
|
protected onWrite(builder: TBuilder): void;
|
|
16
36
|
}
|
|
17
37
|
declare const createObjectType: <TBuilder extends SourceBuilder>(options?: Options<TBuilder>) => TsObjectType<TBuilder>;
|
|
38
|
+
/**
|
|
39
|
+
* Factory for creating object type nodes. The `write` function writes one or more object type nodes to a builder.
|
|
40
|
+
*
|
|
41
|
+
* @param options The settings of the object type. See `TsObjectType` for the available properties.
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* tsObjectType({ members: [tsProperty('x'), tsProperty('y')] });
|
|
45
|
+
* // Emits:
|
|
46
|
+
* // {
|
|
47
|
+
* // x;
|
|
48
|
+
* // y;
|
|
49
|
+
* // }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
18
52
|
export declare const tsObjectType: typeof createObjectType & {
|
|
19
53
|
write: typeof writeTsNodes;
|
|
20
54
|
};
|
|
@@ -2,8 +2,28 @@ import { notNullish } from '@goast/core';
|
|
|
2
2
|
import { TsNode } from '../node.js';
|
|
3
3
|
import { writeTsMembers } from '../utils/write-ts-members.js';
|
|
4
4
|
import { writeTsNodes } from '../utils/write-ts-nodes.js';
|
|
5
|
+
/**
|
|
6
|
+
* Represents an object type literal, which describes the shape of a value in a type position.
|
|
7
|
+
*
|
|
8
|
+
* The members are written between braces, one per line. An object type without members is written as `{}`.
|
|
9
|
+
* Properties and bodyless methods end with a semicolon.
|
|
10
|
+
*
|
|
11
|
+
* @template TBuilder The type of the source builder the object type is written to.
|
|
12
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
13
|
+
* @see tsObjectType
|
|
14
|
+
* @see TsObject
|
|
15
|
+
*/
|
|
5
16
|
export class TsObjectType extends TsNode {
|
|
17
|
+
/**
|
|
18
|
+
* The members written between the braces, in the given order. Null entries are skipped. Properties and bodyless
|
|
19
|
+
* methods without a doc comment or decorators are written without blank lines, other members are set off by blank
|
|
20
|
+
* lines.
|
|
21
|
+
*/
|
|
6
22
|
members;
|
|
23
|
+
/**
|
|
24
|
+
* Initializes a new instance of the TsObjectType class.
|
|
25
|
+
* @param options The options to use for this instance.
|
|
26
|
+
*/
|
|
7
27
|
constructor(options) {
|
|
8
28
|
super(options);
|
|
9
29
|
this.members = options.members?.filter(notNullish) ?? [];
|
|
@@ -15,6 +35,20 @@ export class TsObjectType extends TsNode {
|
|
|
15
35
|
}
|
|
16
36
|
}
|
|
17
37
|
const createObjectType = (options) => new TsObjectType(options ?? {});
|
|
38
|
+
/**
|
|
39
|
+
* Factory for creating object type nodes. The `write` function writes one or more object type nodes to a builder.
|
|
40
|
+
*
|
|
41
|
+
* @param options The settings of the object type. See `TsObjectType` for the available properties.
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* tsObjectType({ members: [tsProperty('x'), tsProperty('y')] });
|
|
45
|
+
* // Emits:
|
|
46
|
+
* // {
|
|
47
|
+
* // x;
|
|
48
|
+
* // y;
|
|
49
|
+
* // }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
18
52
|
export const tsObjectType = Object.assign(createObjectType, {
|
|
19
53
|
write: writeTsNodes,
|
|
20
54
|
});
|
|
@@ -8,11 +8,45 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
8
8
|
members?: Nullable<Nullable<Member<TBuilder>>[]>;
|
|
9
9
|
}>;
|
|
10
10
|
type Member<TBuilder extends SourceBuilder> = TsProperty<TBuilder> | TsMethod<TBuilder> | BasicAppendValue<TBuilder>;
|
|
11
|
+
/**
|
|
12
|
+
* Represents an object literal, which creates a value in an expression position.
|
|
13
|
+
*
|
|
14
|
+
* The members are written between braces, one per line, and each member ends with a comma. Object literals have no
|
|
15
|
+
* type annotations, so properties are written without one. An object without members is written as `{}`.
|
|
16
|
+
*
|
|
17
|
+
* @template TBuilder The type of the source builder the object literal is written to.
|
|
18
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
19
|
+
* @see tsObject
|
|
20
|
+
* @see TsObjectType
|
|
21
|
+
*/
|
|
11
22
|
export declare class TsObject<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
|
|
23
|
+
/**
|
|
24
|
+
* The members written between the braces, in the given order. Null entries are skipped. Properties are written as
|
|
25
|
+
* `name: value,`, or as `name,` when they have no value. Properties and bodyless methods without a doc comment or
|
|
26
|
+
* decorators are written without blank lines, other members are set off by blank lines.
|
|
27
|
+
*/
|
|
12
28
|
members: Member<TBuilder>[];
|
|
29
|
+
/**
|
|
30
|
+
* Initializes a new instance of the TsObject class.
|
|
31
|
+
* @param options The options to use for this instance.
|
|
32
|
+
*/
|
|
13
33
|
constructor(options: Options<TBuilder, TInjects>);
|
|
14
34
|
protected onWrite(builder: TBuilder): void;
|
|
15
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Factory for creating object literal nodes. The `write` function writes one or more object literal nodes to a builder.
|
|
38
|
+
*
|
|
39
|
+
* @param options The settings of the object literal. See `TsObject` for the available properties.
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* tsObject({ members: [tsProperty('x'), tsProperty('y')] });
|
|
43
|
+
* // Emits:
|
|
44
|
+
* // {
|
|
45
|
+
* // x,
|
|
46
|
+
* // y,
|
|
47
|
+
* // }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
16
50
|
declare const createObject: <TBuilder extends SourceBuilder>(options?: Options<TBuilder>) => TsObject<TBuilder>;
|
|
17
51
|
export declare const tsObject: typeof createObject & {
|
|
18
52
|
write: typeof writeTsNodes;
|
|
@@ -2,8 +2,28 @@ import { notNullish } from '@goast/core';
|
|
|
2
2
|
import { TsNode } from '../node.js';
|
|
3
3
|
import { writeTsMembers } from '../utils/write-ts-members.js';
|
|
4
4
|
import { writeTsNodes } from '../utils/write-ts-nodes.js';
|
|
5
|
+
/**
|
|
6
|
+
* Represents an object literal, which creates a value in an expression position.
|
|
7
|
+
*
|
|
8
|
+
* The members are written between braces, one per line, and each member ends with a comma. Object literals have no
|
|
9
|
+
* type annotations, so properties are written without one. An object without members is written as `{}`.
|
|
10
|
+
*
|
|
11
|
+
* @template TBuilder The type of the source builder the object literal is written to.
|
|
12
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
13
|
+
* @see tsObject
|
|
14
|
+
* @see TsObjectType
|
|
15
|
+
*/
|
|
5
16
|
export class TsObject extends TsNode {
|
|
17
|
+
/**
|
|
18
|
+
* The members written between the braces, in the given order. Null entries are skipped. Properties are written as
|
|
19
|
+
* `name: value,`, or as `name,` when they have no value. Properties and bodyless methods without a doc comment or
|
|
20
|
+
* decorators are written without blank lines, other members are set off by blank lines.
|
|
21
|
+
*/
|
|
6
22
|
members;
|
|
23
|
+
/**
|
|
24
|
+
* Initializes a new instance of the TsObject class.
|
|
25
|
+
* @param options The options to use for this instance.
|
|
26
|
+
*/
|
|
7
27
|
constructor(options) {
|
|
8
28
|
super(options);
|
|
9
29
|
this.members = options.members?.filter(notNullish) ?? [];
|
|
@@ -14,6 +34,20 @@ export class TsObject extends TsNode {
|
|
|
14
34
|
}, { multiline: this.members.length > 0 });
|
|
15
35
|
}
|
|
16
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Factory for creating object literal nodes. The `write` function writes one or more object literal nodes to a builder.
|
|
39
|
+
*
|
|
40
|
+
* @param options The settings of the object literal. See `TsObject` for the available properties.
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* tsObject({ members: [tsProperty('x'), tsProperty('y')] });
|
|
44
|
+
* // Emits:
|
|
45
|
+
* // {
|
|
46
|
+
* // x,
|
|
47
|
+
* // y,
|
|
48
|
+
* // }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
17
51
|
const createObject = (options) => new TsObject(options ?? {});
|
|
18
52
|
export const tsObject = Object.assign(createObject, {
|
|
19
53
|
write: writeTsNodes,
|
|
@@ -12,17 +12,68 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
12
12
|
optional?: Nullable<boolean>;
|
|
13
13
|
default?: Nullable<TsValue<TBuilder>>;
|
|
14
14
|
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Represents a parameter of a function or method, such as `x?: number = 42`.
|
|
17
|
+
*
|
|
18
|
+
* Written in this order: decorators, name, optional marker, type annotation, and default value. The injection points
|
|
19
|
+
* `beforeDecorators` and `afterDecorators` wrap the decorators, `beforeName` and `afterName` wrap the name,
|
|
20
|
+
* `beforeType` and `afterType` wrap the type, and `beforeDefault` and `afterDefault` wrap the default value.
|
|
21
|
+
*
|
|
22
|
+
* A parameter does not write its own parentheses. `tsParameter.write` writes a list of parameters in parentheses, one
|
|
23
|
+
* per line when there are more than two parameters or when one of them has decorators.
|
|
24
|
+
*
|
|
25
|
+
* @template TBuilder The type of the source builder the parameter is written to.
|
|
26
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
27
|
+
* @see tsParameter
|
|
28
|
+
*/
|
|
15
29
|
export declare class TsParameter<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
|
|
30
|
+
/**
|
|
31
|
+
* The name of the parameter, written verbatim.
|
|
32
|
+
*/
|
|
16
33
|
name: string;
|
|
34
|
+
/**
|
|
35
|
+
* The text of the `@param` tag that the method or function that owns this parameter writes for it. The parameter
|
|
36
|
+
* itself does not write the description, so `null` only omits the tag.
|
|
37
|
+
*/
|
|
17
38
|
description: BasicAppendValue<TBuilder> | null;
|
|
39
|
+
/**
|
|
40
|
+
* The decorators written before the parameter. They are separated by spaces and written on the same line, such as
|
|
41
|
+
* `@decorator x`.
|
|
42
|
+
*/
|
|
18
43
|
decorators: TsDecorator<TBuilder>[];
|
|
44
|
+
/**
|
|
45
|
+
* The type annotation written after the name, such as `: number`, or `null` to omit it.
|
|
46
|
+
*/
|
|
19
47
|
type: TsType<TBuilder> | null;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the name is followed by `?`, which marks the parameter as optional.
|
|
50
|
+
* @default false
|
|
51
|
+
*/
|
|
20
52
|
optional: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* The default value written after ` = `, such as ` = 42`, or `null` to omit it. Falsy values are not written.
|
|
55
|
+
*/
|
|
21
56
|
default: TsValue<TBuilder> | null;
|
|
57
|
+
/**
|
|
58
|
+
* Initializes a new instance of the TsParameter class.
|
|
59
|
+
* @param options The options to use for this instance.
|
|
60
|
+
*/
|
|
22
61
|
constructor(options: Options<TBuilder, TInjects>);
|
|
23
62
|
protected onWrite(builder: TBuilder): void;
|
|
24
63
|
}
|
|
25
64
|
declare const createParameter: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => TsParameter<TBuilder>;
|
|
65
|
+
/**
|
|
66
|
+
* Factory for creating parameter nodes. The `write` function writes a parenthesized list of parameters to a builder.
|
|
67
|
+
*
|
|
68
|
+
* @param name The name of the parameter. See `TsParameter.name`.
|
|
69
|
+
* @param options The settings of the parameter. See `TsParameter` for the available properties.
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* tsParameter('x', { decorators: [tsDecorator('decorator')], type: 'number', default: '42', optional: true });
|
|
73
|
+
* // Emits:
|
|
74
|
+
* // @decorator x?: number = 42
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
26
77
|
export declare const tsParameter: typeof createParameter & {
|
|
27
78
|
write: typeof writeTsParameters;
|
|
28
79
|
};
|
|
@@ -3,13 +3,52 @@ import { TsNode } from '../node.js';
|
|
|
3
3
|
import { writeTsNode } from '../utils/write-ts-nodes.js';
|
|
4
4
|
import { writeTsParameters } from '../utils/write-ts-parameters.js';
|
|
5
5
|
import { tsDecorator } from './decorator.js';
|
|
6
|
+
/**
|
|
7
|
+
* Represents a parameter of a function or method, such as `x?: number = 42`.
|
|
8
|
+
*
|
|
9
|
+
* Written in this order: decorators, name, optional marker, type annotation, and default value. The injection points
|
|
10
|
+
* `beforeDecorators` and `afterDecorators` wrap the decorators, `beforeName` and `afterName` wrap the name,
|
|
11
|
+
* `beforeType` and `afterType` wrap the type, and `beforeDefault` and `afterDefault` wrap the default value.
|
|
12
|
+
*
|
|
13
|
+
* A parameter does not write its own parentheses. `tsParameter.write` writes a list of parameters in parentheses, one
|
|
14
|
+
* per line when there are more than two parameters or when one of them has decorators.
|
|
15
|
+
*
|
|
16
|
+
* @template TBuilder The type of the source builder the parameter is written to.
|
|
17
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
18
|
+
* @see tsParameter
|
|
19
|
+
*/
|
|
6
20
|
export class TsParameter extends TsNode {
|
|
21
|
+
/**
|
|
22
|
+
* The name of the parameter, written verbatim.
|
|
23
|
+
*/
|
|
7
24
|
name;
|
|
25
|
+
/**
|
|
26
|
+
* The text of the `@param` tag that the method or function that owns this parameter writes for it. The parameter
|
|
27
|
+
* itself does not write the description, so `null` only omits the tag.
|
|
28
|
+
*/
|
|
8
29
|
description;
|
|
30
|
+
/**
|
|
31
|
+
* The decorators written before the parameter. They are separated by spaces and written on the same line, such as
|
|
32
|
+
* `@decorator x`.
|
|
33
|
+
*/
|
|
9
34
|
decorators;
|
|
35
|
+
/**
|
|
36
|
+
* The type annotation written after the name, such as `: number`, or `null` to omit it.
|
|
37
|
+
*/
|
|
10
38
|
type;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the name is followed by `?`, which marks the parameter as optional.
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
11
43
|
optional;
|
|
44
|
+
/**
|
|
45
|
+
* The default value written after ` = `, such as ` = 42`, or `null` to omit it. Falsy values are not written.
|
|
46
|
+
*/
|
|
12
47
|
default;
|
|
48
|
+
/**
|
|
49
|
+
* Initializes a new instance of the TsParameter class.
|
|
50
|
+
* @param options The options to use for this instance.
|
|
51
|
+
*/
|
|
13
52
|
constructor(options) {
|
|
14
53
|
super(options);
|
|
15
54
|
this.name = options.name;
|
|
@@ -41,6 +80,18 @@ export class TsParameter extends TsNode {
|
|
|
41
80
|
}
|
|
42
81
|
}
|
|
43
82
|
const createParameter = (name, options) => new TsParameter({ ...options, name });
|
|
83
|
+
/**
|
|
84
|
+
* Factory for creating parameter nodes. The `write` function writes a parenthesized list of parameters to a builder.
|
|
85
|
+
*
|
|
86
|
+
* @param name The name of the parameter. See `TsParameter.name`.
|
|
87
|
+
* @param options The settings of the parameter. See `TsParameter` for the available properties.
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* tsParameter('x', { decorators: [tsDecorator('decorator')], type: 'number', default: '42', optional: true });
|
|
91
|
+
* // Emits:
|
|
92
|
+
* // @decorator x?: number = 42
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
44
95
|
export const tsParameter = Object.assign(createParameter, {
|
|
45
96
|
write: writeTsParameters,
|
|
46
97
|
});
|