@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
|
@@ -8,15 +8,52 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
8
8
|
name: string;
|
|
9
9
|
value?: Nullable<TsString<TBuilder> | BasicAppendValue<TBuilder>>;
|
|
10
10
|
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Represents a member of an enum, such as `Active = 1`.
|
|
13
|
+
*
|
|
14
|
+
* Written in this order: the doc comment, the name, then ` = ` and the value when one is set. The enclosing enum
|
|
15
|
+
* separates its members with commas and line breaks.
|
|
16
|
+
*
|
|
17
|
+
* @template TBuilder The type of the source builder the enum value is written to.
|
|
18
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
19
|
+
* @see tsEnumValue
|
|
20
|
+
*/
|
|
11
21
|
export declare class TsEnumValue<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
|
|
22
|
+
/**
|
|
23
|
+
* The doc comment written above the member, or `null` to omit it.
|
|
24
|
+
*/
|
|
12
25
|
doc: TsDoc<TBuilder> | null;
|
|
26
|
+
/**
|
|
27
|
+
* The name of the member, written verbatim before the value.
|
|
28
|
+
*/
|
|
13
29
|
name: string;
|
|
30
|
+
/**
|
|
31
|
+
* The value written after ` = `, or `null` to write the member without a value, so that TypeScript assigns it. Nodes
|
|
32
|
+
* are written with their own output, and other values are appended as they are.
|
|
33
|
+
*/
|
|
14
34
|
value: TsString<TBuilder> | BasicAppendValue<TBuilder> | null;
|
|
35
|
+
/**
|
|
36
|
+
* Initializes a new instance of the TsEnumValue class.
|
|
37
|
+
* @param options The options to use for this instance.
|
|
38
|
+
*/
|
|
15
39
|
constructor(options: Options<TBuilder, TInjects>);
|
|
16
40
|
protected onWrite(builder: TBuilder): void;
|
|
17
41
|
}
|
|
18
42
|
declare const createEnumValue: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => TsEnumValue<TBuilder>;
|
|
19
43
|
declare const writeEnumValues: <TBuilder extends SourceBuilder>(builder: TBuilder, nodes: SingleOrMultiple<Nullable<TsEnumValue<TBuilder> | AppendValue<TBuilder>>>) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Factory for creating enum member nodes. The `write` function writes one or more members to a builder, separated by
|
|
46
|
+
* commas and line breaks.
|
|
47
|
+
*
|
|
48
|
+
* @param name The name of the member.
|
|
49
|
+
* @param options The settings of the member. See `TsEnumValue` for the available properties.
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* tsEnumValue('Active', { value: '1' });
|
|
53
|
+
* // Emits:
|
|
54
|
+
* // Active = 1
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
20
57
|
export declare const tsEnumValue: typeof createEnumValue & {
|
|
21
58
|
write: typeof writeEnumValues;
|
|
22
59
|
};
|
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
import { TsNode } from '../node.js';
|
|
2
2
|
import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a member of an enum, such as `Active = 1`.
|
|
5
|
+
*
|
|
6
|
+
* Written in this order: the doc comment, the name, then ` = ` and the value when one is set. The enclosing enum
|
|
7
|
+
* separates its members with commas and line breaks.
|
|
8
|
+
*
|
|
9
|
+
* @template TBuilder The type of the source builder the enum value is written to.
|
|
10
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
11
|
+
* @see tsEnumValue
|
|
12
|
+
*/
|
|
3
13
|
export class TsEnumValue extends TsNode {
|
|
14
|
+
/**
|
|
15
|
+
* The doc comment written above the member, or `null` to omit it.
|
|
16
|
+
*/
|
|
4
17
|
doc;
|
|
18
|
+
/**
|
|
19
|
+
* The name of the member, written verbatim before the value.
|
|
20
|
+
*/
|
|
5
21
|
name;
|
|
22
|
+
/**
|
|
23
|
+
* The value written after ` = `, or `null` to write the member without a value, so that TypeScript assigns it. Nodes
|
|
24
|
+
* are written with their own output, and other values are appended as they are.
|
|
25
|
+
*/
|
|
6
26
|
value;
|
|
27
|
+
/**
|
|
28
|
+
* Initializes a new instance of the TsEnumValue class.
|
|
29
|
+
* @param options The options to use for this instance.
|
|
30
|
+
*/
|
|
7
31
|
constructor(options) {
|
|
8
32
|
super(options);
|
|
9
33
|
this.name = options.name;
|
|
@@ -27,6 +51,19 @@ const createEnumValue = (name, options) => new TsEnumValue({ ...options, name })
|
|
|
27
51
|
const writeEnumValues = (builder, nodes) => {
|
|
28
52
|
writeTsNodes(builder, nodes, { separator: ',\n' });
|
|
29
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* Factory for creating enum member nodes. The `write` function writes one or more members to a builder, separated by
|
|
56
|
+
* commas and line breaks.
|
|
57
|
+
*
|
|
58
|
+
* @param name The name of the member.
|
|
59
|
+
* @param options The settings of the member. See `TsEnumValue` for the available properties.
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* tsEnumValue('Active', { value: '1' });
|
|
63
|
+
* // Emits:
|
|
64
|
+
* // Active = 1
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
30
67
|
export const tsEnumValue = Object.assign(createEnumValue, {
|
|
31
68
|
write: writeEnumValues,
|
|
32
69
|
});
|
|
@@ -11,16 +11,63 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
11
11
|
name: string;
|
|
12
12
|
members?: Nullable<Nullable<TsEnumValue<TBuilder>>[]>;
|
|
13
13
|
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Represents an enum declaration.
|
|
16
|
+
*
|
|
17
|
+
* Written in this order: the doc comment, the `export` and `const` keywords, then `enum`, the name, and the members in
|
|
18
|
+
* braces, followed by a line break.
|
|
19
|
+
*
|
|
20
|
+
* @template TBuilder The type of the source builder the enum is written to.
|
|
21
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
22
|
+
* @see tsEnum
|
|
23
|
+
*/
|
|
14
24
|
export declare class TsEnum<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
|
|
25
|
+
/**
|
|
26
|
+
* The doc comment written above the enum, or `null` to omit it.
|
|
27
|
+
*/
|
|
15
28
|
doc: TsDoc<TBuilder> | null;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the enum is written with the `export` keyword.
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
16
33
|
export: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the enum is written as a `const enum`. The `const` keyword is placed after `export` when both are set.
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
17
38
|
const: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The name of the enum, written after the `enum` keyword.
|
|
41
|
+
*/
|
|
18
42
|
name: string;
|
|
43
|
+
/**
|
|
44
|
+
* The members written in the body, one per line and separated by commas. The last member has no trailing comma, and
|
|
45
|
+
* the braces are written empty when there are no members.
|
|
46
|
+
*/
|
|
19
47
|
members: TsEnumValue<TBuilder>[];
|
|
48
|
+
/**
|
|
49
|
+
* Initializes a new instance of the TsEnum class.
|
|
50
|
+
* @param options The options to use for this instance.
|
|
51
|
+
*/
|
|
20
52
|
constructor(options: Options<TBuilder, TInjects>);
|
|
21
53
|
protected onWrite(builder: TBuilder): void;
|
|
22
54
|
}
|
|
23
55
|
declare const createEnum: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => TsEnum<TBuilder>;
|
|
56
|
+
/**
|
|
57
|
+
* Factory for creating enum nodes. The `write` function writes one or more enums to a builder.
|
|
58
|
+
*
|
|
59
|
+
* @param name The name of the enum.
|
|
60
|
+
* @param options The settings of the enum. See `TsEnum` for the available properties.
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* tsEnum('Color', { export: true, members: [tsEnumValue('Red'), tsEnumValue('Green')] });
|
|
64
|
+
* // Emits:
|
|
65
|
+
* // export enum Color {
|
|
66
|
+
* // Red,
|
|
67
|
+
* // Green
|
|
68
|
+
* // }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
24
71
|
export declare const tsEnum: typeof createEnum & {
|
|
25
72
|
write: typeof writeTsNodes;
|
|
26
73
|
};
|
|
@@ -2,12 +2,44 @@ import { notNullish } from '@goast/core';
|
|
|
2
2
|
import { TsNode } from '../node.js';
|
|
3
3
|
import { writeTsNodes } from '../utils/write-ts-nodes.js';
|
|
4
4
|
import { tsEnumValue } from './enum-value.js';
|
|
5
|
+
/**
|
|
6
|
+
* Represents an enum declaration.
|
|
7
|
+
*
|
|
8
|
+
* Written in this order: the doc comment, the `export` and `const` keywords, then `enum`, the name, and the members in
|
|
9
|
+
* braces, followed by a line break.
|
|
10
|
+
*
|
|
11
|
+
* @template TBuilder The type of the source builder the enum is written to.
|
|
12
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
13
|
+
* @see tsEnum
|
|
14
|
+
*/
|
|
5
15
|
export class TsEnum extends TsNode {
|
|
16
|
+
/**
|
|
17
|
+
* The doc comment written above the enum, or `null` to omit it.
|
|
18
|
+
*/
|
|
6
19
|
doc;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the enum is written with the `export` keyword.
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
7
24
|
export;
|
|
25
|
+
/**
|
|
26
|
+
* Whether the enum is written as a `const enum`. The `const` keyword is placed after `export` when both are set.
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
8
29
|
const;
|
|
30
|
+
/**
|
|
31
|
+
* The name of the enum, written after the `enum` keyword.
|
|
32
|
+
*/
|
|
9
33
|
name;
|
|
34
|
+
/**
|
|
35
|
+
* The members written in the body, one per line and separated by commas. The last member has no trailing comma, and
|
|
36
|
+
* the braces are written empty when there are no members.
|
|
37
|
+
*/
|
|
10
38
|
members;
|
|
39
|
+
/**
|
|
40
|
+
* Initializes a new instance of the TsEnum class.
|
|
41
|
+
* @param options The options to use for this instance.
|
|
42
|
+
*/
|
|
11
43
|
constructor(options) {
|
|
12
44
|
super(options);
|
|
13
45
|
this.doc = options.doc ?? null;
|
|
@@ -40,6 +72,21 @@ export class TsEnum extends TsNode {
|
|
|
40
72
|
}
|
|
41
73
|
}
|
|
42
74
|
const createEnum = (name, options) => new TsEnum({ ...options, name });
|
|
75
|
+
/**
|
|
76
|
+
* Factory for creating enum nodes. The `write` function writes one or more enums to a builder.
|
|
77
|
+
*
|
|
78
|
+
* @param name The name of the enum.
|
|
79
|
+
* @param options The settings of the enum. See `TsEnum` for the available properties.
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* tsEnum('Color', { export: true, members: [tsEnumValue('Red'), tsEnumValue('Green')] });
|
|
83
|
+
* // Emits:
|
|
84
|
+
* // export enum Color {
|
|
85
|
+
* // Red,
|
|
86
|
+
* // Green
|
|
87
|
+
* // }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
43
90
|
export const tsEnum = Object.assign(createEnum, {
|
|
44
91
|
write: writeTsNodes,
|
|
45
92
|
});
|
|
@@ -8,14 +8,65 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
8
8
|
filePath: string;
|
|
9
9
|
kind?: Nullable<TypeScriptExportType>;
|
|
10
10
|
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Represents a re-export of a symbol from another module, such as `export { X } from './x';`.
|
|
13
|
+
*
|
|
14
|
+
* In a `TypeScriptFileBuilder` the export is not written in place. The file collects it and writes it together with its
|
|
15
|
+
* other exports, grouped by module path. Any other builder receives the export statement as text, followed by a line
|
|
16
|
+
* break.
|
|
17
|
+
*
|
|
18
|
+
* @template TBuilder The type of the source builder the export is written to.
|
|
19
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
20
|
+
* @see tsExport
|
|
21
|
+
*/
|
|
11
22
|
export declare class TsExport<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
|
|
23
|
+
/**
|
|
24
|
+
* The name of the exported symbol, written inside the braces, such as `X` in `export { X } from './x';`.
|
|
25
|
+
*/
|
|
12
26
|
name: string;
|
|
27
|
+
/**
|
|
28
|
+
* The module path that the symbol is re-exported from, such as `./x`. The file builder groups exports by this path.
|
|
29
|
+
*/
|
|
13
30
|
filePath: string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the symbol is re-exported as a value with `export`, or as a type with `export type`.
|
|
33
|
+
* @default 'export'
|
|
34
|
+
*/
|
|
14
35
|
kind: TypeScriptExportType;
|
|
36
|
+
/**
|
|
37
|
+
* Initializes a new instance of the TsExport class.
|
|
38
|
+
* @param options The options to use for this instance.
|
|
39
|
+
*/
|
|
15
40
|
constructor(options: Options<TBuilder, TInjects>);
|
|
16
41
|
protected onWrite(builder: TBuilder): void;
|
|
17
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a re-export node. The `tsExport` factory creates the same node and also provides a `write` function.
|
|
45
|
+
*
|
|
46
|
+
* @param name The name of the exported symbol.
|
|
47
|
+
* @param filePath The module path to re-export from.
|
|
48
|
+
* @param options The settings of the export. See `TsExport` for the available properties.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* createExport('myFunction', './my-function');
|
|
52
|
+
* // Emits (outside a TypeScriptFileBuilder):
|
|
53
|
+
* // export { myFunction } from './my-function';
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
18
56
|
export declare const createExport: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], filePath: Options<TBuilder>['filePath'], options?: Prettify<Omit<Options<TBuilder>, 'name' | 'filePath'>>) => TsExport<TBuilder>;
|
|
57
|
+
/**
|
|
58
|
+
* Factory for creating re-export nodes. The `write` function writes one or more re-exports to a builder.
|
|
59
|
+
*
|
|
60
|
+
* @param name The name of the exported symbol.
|
|
61
|
+
* @param filePath The module path to re-export from.
|
|
62
|
+
* @param options The settings of the export. See `TsExport` for the available properties.
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* tsExport('myFunction', './my-function');
|
|
66
|
+
* // Emits (outside a TypeScriptFileBuilder):
|
|
67
|
+
* // export { myFunction } from './my-function';
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
19
70
|
export declare const tsExport: typeof createExport & {
|
|
20
71
|
write: typeof writeTsNodes;
|
|
21
72
|
};
|
|
@@ -1,10 +1,35 @@
|
|
|
1
1
|
import { TypeScriptFileBuilder } from '../../file-builder.js';
|
|
2
2
|
import { TsNode } from '../node.js';
|
|
3
3
|
import { writeTsNodes } from '../utils/write-ts-nodes.js';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a re-export of a symbol from another module, such as `export { X } from './x';`.
|
|
6
|
+
*
|
|
7
|
+
* In a `TypeScriptFileBuilder` the export is not written in place. The file collects it and writes it together with its
|
|
8
|
+
* other exports, grouped by module path. Any other builder receives the export statement as text, followed by a line
|
|
9
|
+
* break.
|
|
10
|
+
*
|
|
11
|
+
* @template TBuilder The type of the source builder the export is written to.
|
|
12
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
13
|
+
* @see tsExport
|
|
14
|
+
*/
|
|
4
15
|
export class TsExport extends TsNode {
|
|
16
|
+
/**
|
|
17
|
+
* The name of the exported symbol, written inside the braces, such as `X` in `export { X } from './x';`.
|
|
18
|
+
*/
|
|
5
19
|
name;
|
|
20
|
+
/**
|
|
21
|
+
* The module path that the symbol is re-exported from, such as `./x`. The file builder groups exports by this path.
|
|
22
|
+
*/
|
|
6
23
|
filePath;
|
|
24
|
+
/**
|
|
25
|
+
* Whether the symbol is re-exported as a value with `export`, or as a type with `export type`.
|
|
26
|
+
* @default 'export'
|
|
27
|
+
*/
|
|
7
28
|
kind;
|
|
29
|
+
/**
|
|
30
|
+
* Initializes a new instance of the TsExport class.
|
|
31
|
+
* @param options The options to use for this instance.
|
|
32
|
+
*/
|
|
8
33
|
constructor(options) {
|
|
9
34
|
super(options);
|
|
10
35
|
this.name = options.name;
|
|
@@ -20,7 +45,33 @@ export class TsExport extends TsNode {
|
|
|
20
45
|
}
|
|
21
46
|
}
|
|
22
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Creates a re-export node. The `tsExport` factory creates the same node and also provides a `write` function.
|
|
50
|
+
*
|
|
51
|
+
* @param name The name of the exported symbol.
|
|
52
|
+
* @param filePath The module path to re-export from.
|
|
53
|
+
* @param options The settings of the export. See `TsExport` for the available properties.
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* createExport('myFunction', './my-function');
|
|
57
|
+
* // Emits (outside a TypeScriptFileBuilder):
|
|
58
|
+
* // export { myFunction } from './my-function';
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
23
61
|
export const createExport = (name, filePath, options) => new TsExport({ ...options, name, filePath });
|
|
62
|
+
/**
|
|
63
|
+
* Factory for creating re-export nodes. The `write` function writes one or more re-exports to a builder.
|
|
64
|
+
*
|
|
65
|
+
* @param name The name of the exported symbol.
|
|
66
|
+
* @param filePath The module path to re-export from.
|
|
67
|
+
* @param options The settings of the export. See `TsExport` for the available properties.
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* tsExport('myFunction', './my-function');
|
|
71
|
+
* // Emits (outside a TypeScriptFileBuilder):
|
|
72
|
+
* // export { myFunction } from './my-function';
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
24
75
|
export const tsExport = Object.assign(createExport, {
|
|
25
76
|
write: writeTsNodes,
|
|
26
77
|
});
|
|
@@ -10,14 +10,49 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
10
10
|
parameters?: Nullable<Nullable<TsParameter<TBuilder> | BasicAppendValue<TBuilder>>[]>;
|
|
11
11
|
returnType?: Nullable<TsType<TBuilder>>;
|
|
12
12
|
}>;
|
|
13
|
+
/**
|
|
14
|
+
* Represents a function type, such as `(x: number) => string`.
|
|
15
|
+
*
|
|
16
|
+
* Written in this order: the generics, the parameters in parentheses, ` => `, then the return type. The return type is
|
|
17
|
+
* written as `void` when it is not set.
|
|
18
|
+
*
|
|
19
|
+
* @template TBuilder The type of the source builder the function type is written to.
|
|
20
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
21
|
+
* @see tsFunctionType
|
|
22
|
+
*/
|
|
13
23
|
export declare class TsFunctionType<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
|
|
24
|
+
/**
|
|
25
|
+
* The type parameters written in angle brackets before the parameters, such as `<T, U>`. Nothing is written when
|
|
26
|
+
* there are none.
|
|
27
|
+
*/
|
|
14
28
|
generics: (TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
|
|
29
|
+
/**
|
|
30
|
+
* The parameters written in parentheses, such as `(x, y)`. More than two parameters are written one per line.
|
|
31
|
+
*/
|
|
15
32
|
parameters: (TsParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
|
|
33
|
+
/**
|
|
34
|
+
* The return type written after ` => `, or `void` when it is `null`.
|
|
35
|
+
*/
|
|
16
36
|
returnType: TsType<TBuilder> | null;
|
|
37
|
+
/**
|
|
38
|
+
* Initializes a new instance of the TsFunctionType class.
|
|
39
|
+
* @param options The options to use for this instance.
|
|
40
|
+
*/
|
|
17
41
|
constructor(options: Options<TBuilder, TInjects>);
|
|
18
42
|
protected onWrite(builder: TBuilder): void;
|
|
19
43
|
}
|
|
20
44
|
declare const createFunctionType: <TBuilder extends SourceBuilder>(options?: Options<TBuilder>) => TsFunctionType<TBuilder>;
|
|
45
|
+
/**
|
|
46
|
+
* Factory for creating function type nodes. The `write` function writes one or more function types to a builder.
|
|
47
|
+
*
|
|
48
|
+
* @param options The settings of the function type. See `TsFunctionType` for the available properties.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* tsFunctionType({ parameters: [tsParameter('x', { type: 'number' })], returnType: 'string' });
|
|
52
|
+
* // Emits:
|
|
53
|
+
* // (x: number) => string
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
21
56
|
export declare const tsFunctionType: typeof createFunctionType & {
|
|
22
57
|
write: typeof writeTsNodes;
|
|
23
58
|
};
|
|
@@ -3,10 +3,34 @@ import { TsNode } from '../node.js';
|
|
|
3
3
|
import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
|
|
4
4
|
import { tsGenericParameter } from './generic-parameter.js';
|
|
5
5
|
import { tsParameter } from './parameter.js';
|
|
6
|
+
/**
|
|
7
|
+
* Represents a function type, such as `(x: number) => string`.
|
|
8
|
+
*
|
|
9
|
+
* Written in this order: the generics, the parameters in parentheses, ` => `, then the return type. The return type is
|
|
10
|
+
* written as `void` when it is not set.
|
|
11
|
+
*
|
|
12
|
+
* @template TBuilder The type of the source builder the function type is written to.
|
|
13
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
14
|
+
* @see tsFunctionType
|
|
15
|
+
*/
|
|
6
16
|
export class TsFunctionType extends TsNode {
|
|
17
|
+
/**
|
|
18
|
+
* The type parameters written in angle brackets before the parameters, such as `<T, U>`. Nothing is written when
|
|
19
|
+
* there are none.
|
|
20
|
+
*/
|
|
7
21
|
generics;
|
|
22
|
+
/**
|
|
23
|
+
* The parameters written in parentheses, such as `(x, y)`. More than two parameters are written one per line.
|
|
24
|
+
*/
|
|
8
25
|
parameters;
|
|
26
|
+
/**
|
|
27
|
+
* The return type written after ` => `, or `void` when it is `null`.
|
|
28
|
+
*/
|
|
9
29
|
returnType;
|
|
30
|
+
/**
|
|
31
|
+
* Initializes a new instance of the TsFunctionType class.
|
|
32
|
+
* @param options The options to use for this instance.
|
|
33
|
+
*/
|
|
10
34
|
constructor(options) {
|
|
11
35
|
super(options);
|
|
12
36
|
this.generics = options.generics?.filter(notNullish) ?? [];
|
|
@@ -27,6 +51,17 @@ export class TsFunctionType extends TsNode {
|
|
|
27
51
|
}
|
|
28
52
|
}
|
|
29
53
|
const createFunctionType = (options) => new TsFunctionType(options ?? {});
|
|
54
|
+
/**
|
|
55
|
+
* Factory for creating function type nodes. The `write` function writes one or more function types to a builder.
|
|
56
|
+
*
|
|
57
|
+
* @param options The settings of the function type. See `TsFunctionType` for the available properties.
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* tsFunctionType({ parameters: [tsParameter('x', { type: 'number' })], returnType: 'string' });
|
|
61
|
+
* // Emits:
|
|
62
|
+
* // (x: number) => string
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
30
65
|
export const tsFunctionType = Object.assign(createFunctionType, {
|
|
31
66
|
write: writeTsNodes,
|
|
32
67
|
});
|
|
@@ -17,19 +17,80 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
17
17
|
returnType?: Nullable<TsType<TBuilder>>;
|
|
18
18
|
body?: Nullable<AppendValue<TBuilder>>;
|
|
19
19
|
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Represents a function declaration.
|
|
22
|
+
*
|
|
23
|
+
* Written in this order: the doc comment, the decorators, the `export` keyword, the name, the generics, the parameters,
|
|
24
|
+
* the return type, then the body in braces, followed by a line break.
|
|
25
|
+
*
|
|
26
|
+
* @template TBuilder The type of the source builder the function is written to.
|
|
27
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
28
|
+
* @see tsFunction
|
|
29
|
+
*/
|
|
20
30
|
export declare class TsFunction<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
|
|
31
|
+
/**
|
|
32
|
+
* The doc comment written above the function, or `null` to omit it. Descriptions of generic parameters are merged
|
|
33
|
+
* into it as `@template` tags. Parameter descriptions are not written for functions, so add `@param` tags to the doc
|
|
34
|
+
* instead.
|
|
35
|
+
*/
|
|
21
36
|
doc: TsDoc<TBuilder> | null;
|
|
37
|
+
/**
|
|
38
|
+
* The decorators written above the function, each on its own line.
|
|
39
|
+
*/
|
|
22
40
|
decorators: TsDecorator<TBuilder>[];
|
|
41
|
+
/**
|
|
42
|
+
* Whether the function is written with the `export` keyword.
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
23
45
|
export: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The name of the function, written after the `function` keyword.
|
|
48
|
+
*/
|
|
24
49
|
name: string;
|
|
50
|
+
/**
|
|
51
|
+
* The type parameters written in angle brackets after the name, such as `<T, U>`. Nothing is written when empty.
|
|
52
|
+
*/
|
|
25
53
|
generics: TsGenericParameter<TBuilder>[];
|
|
54
|
+
/**
|
|
55
|
+
* The parameters written in parentheses after the name. More than two parameters are written one per line.
|
|
56
|
+
*/
|
|
26
57
|
parameters: TsParameter<TBuilder>[];
|
|
58
|
+
/**
|
|
59
|
+
* The return type written after the parameters as `: Type`, or `null` to omit it.
|
|
60
|
+
*/
|
|
27
61
|
returnType: TsType<TBuilder> | null;
|
|
62
|
+
/**
|
|
63
|
+
* The statements written in the body, on their own indented lines, or `null` to write empty braces `{}`.
|
|
64
|
+
*/
|
|
28
65
|
body: AppendValue<TBuilder> | null;
|
|
66
|
+
/**
|
|
67
|
+
* Initializes a new instance of the TsFunction class.
|
|
68
|
+
* @param options The options to use for this instance.
|
|
69
|
+
*/
|
|
29
70
|
constructor(options: Options<TBuilder, TInjects>);
|
|
30
71
|
protected onWrite(builder: TBuilder): void;
|
|
31
72
|
}
|
|
32
73
|
declare const createFunction: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => TsFunction<TBuilder>;
|
|
74
|
+
/**
|
|
75
|
+
* Factory for creating function declaration nodes. The `write` function writes one or more functions to a builder.
|
|
76
|
+
*
|
|
77
|
+
* @param name The name of the function.
|
|
78
|
+
* @param options The settings of the function. See `TsFunction` for the available properties.
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* tsFunction('add', {
|
|
82
|
+
* export: true,
|
|
83
|
+
* generics: [tsGenericParameter('T')],
|
|
84
|
+
* parameters: [tsParameter('a', { type: 'T' }), tsParameter('b', { type: 'T' })],
|
|
85
|
+
* returnType: 'T',
|
|
86
|
+
* body: 'return a;',
|
|
87
|
+
* });
|
|
88
|
+
* // Emits:
|
|
89
|
+
* // export function add<T>(a: T, b: T): T {
|
|
90
|
+
* // return a;
|
|
91
|
+
* // }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
33
94
|
export declare const tsFunction: typeof createFunction & {
|
|
34
95
|
write: typeof writeTsNodes;
|
|
35
96
|
};
|
|
@@ -5,15 +5,56 @@ import { tsDecorator } from './decorator.js';
|
|
|
5
5
|
import { tsDoc } from './doc.js';
|
|
6
6
|
import { tsGenericParameter } from './generic-parameter.js';
|
|
7
7
|
import { tsParameter } from './parameter.js';
|
|
8
|
+
/**
|
|
9
|
+
* Represents a function declaration.
|
|
10
|
+
*
|
|
11
|
+
* Written in this order: the doc comment, the decorators, the `export` keyword, the name, the generics, the parameters,
|
|
12
|
+
* the return type, then the body in braces, followed by a line break.
|
|
13
|
+
*
|
|
14
|
+
* @template TBuilder The type of the source builder the function is written to.
|
|
15
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
16
|
+
* @see tsFunction
|
|
17
|
+
*/
|
|
8
18
|
export class TsFunction extends TsNode {
|
|
19
|
+
/**
|
|
20
|
+
* The doc comment written above the function, or `null` to omit it. Descriptions of generic parameters are merged
|
|
21
|
+
* into it as `@template` tags. Parameter descriptions are not written for functions, so add `@param` tags to the doc
|
|
22
|
+
* instead.
|
|
23
|
+
*/
|
|
9
24
|
doc;
|
|
25
|
+
/**
|
|
26
|
+
* The decorators written above the function, each on its own line.
|
|
27
|
+
*/
|
|
10
28
|
decorators;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the function is written with the `export` keyword.
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
11
33
|
export;
|
|
34
|
+
/**
|
|
35
|
+
* The name of the function, written after the `function` keyword.
|
|
36
|
+
*/
|
|
12
37
|
name;
|
|
38
|
+
/**
|
|
39
|
+
* The type parameters written in angle brackets after the name, such as `<T, U>`. Nothing is written when empty.
|
|
40
|
+
*/
|
|
13
41
|
generics;
|
|
42
|
+
/**
|
|
43
|
+
* The parameters written in parentheses after the name. More than two parameters are written one per line.
|
|
44
|
+
*/
|
|
14
45
|
parameters;
|
|
46
|
+
/**
|
|
47
|
+
* The return type written after the parameters as `: Type`, or `null` to omit it.
|
|
48
|
+
*/
|
|
15
49
|
returnType;
|
|
50
|
+
/**
|
|
51
|
+
* The statements written in the body, on their own indented lines, or `null` to write empty braces `{}`.
|
|
52
|
+
*/
|
|
16
53
|
body;
|
|
54
|
+
/**
|
|
55
|
+
* Initializes a new instance of the TsFunction class.
|
|
56
|
+
* @param options The options to use for this instance.
|
|
57
|
+
*/
|
|
17
58
|
constructor(options) {
|
|
18
59
|
super(options);
|
|
19
60
|
this.doc = options.doc ?? null;
|
|
@@ -58,6 +99,26 @@ export class TsFunction extends TsNode {
|
|
|
58
99
|
}
|
|
59
100
|
}
|
|
60
101
|
const createFunction = (name, options) => new TsFunction({ ...options, name });
|
|
102
|
+
/**
|
|
103
|
+
* Factory for creating function declaration nodes. The `write` function writes one or more functions to a builder.
|
|
104
|
+
*
|
|
105
|
+
* @param name The name of the function.
|
|
106
|
+
* @param options The settings of the function. See `TsFunction` for the available properties.
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* tsFunction('add', {
|
|
110
|
+
* export: true,
|
|
111
|
+
* generics: [tsGenericParameter('T')],
|
|
112
|
+
* parameters: [tsParameter('a', { type: 'T' }), tsParameter('b', { type: 'T' })],
|
|
113
|
+
* returnType: 'T',
|
|
114
|
+
* body: 'return a;',
|
|
115
|
+
* });
|
|
116
|
+
* // Emits:
|
|
117
|
+
* // export function add<T>(a: T, b: T): T {
|
|
118
|
+
* // return a;
|
|
119
|
+
* // }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
61
122
|
export const tsFunction = Object.assign(createFunction, {
|
|
62
123
|
write: writeTsNodes,
|
|
63
124
|
});
|