@goast/typescript 0.9.0 → 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.
Files changed (143) hide show
  1. package/dist/src/assets.d.ts +18 -0
  2. package/dist/src/assets.js +18 -0
  3. package/dist/src/ast/common.d.ts +6 -0
  4. package/dist/src/ast/node.d.ts +15 -0
  5. package/dist/src/ast/node.js +15 -0
  6. package/dist/src/ast/nodes/argument.d.ts +31 -0
  7. package/dist/src/ast/nodes/argument.js +31 -0
  8. package/dist/src/ast/nodes/array-type.d.ts +32 -0
  9. package/dist/src/ast/nodes/array-type.js +32 -0
  10. package/dist/src/ast/nodes/arrow-function.d.ts +56 -0
  11. package/dist/src/ast/nodes/arrow-function.js +56 -0
  12. package/dist/src/ast/nodes/call.d.ts +34 -0
  13. package/dist/src/ast/nodes/call.js +34 -0
  14. package/dist/src/ast/nodes/class.d.ts +73 -0
  15. package/dist/src/ast/nodes/class.js +73 -0
  16. package/dist/src/ast/nodes/constructor-parameter.d.ts +37 -0
  17. package/dist/src/ast/nodes/constructor-parameter.js +37 -0
  18. package/dist/src/ast/nodes/constructor.d.ts +44 -0
  19. package/dist/src/ast/nodes/constructor.js +44 -0
  20. package/dist/src/ast/nodes/decorator.d.ts +35 -0
  21. package/dist/src/ast/nodes/decorator.js +35 -0
  22. package/dist/src/ast/nodes/doc-tag.d.ts +39 -0
  23. package/dist/src/ast/nodes/doc-tag.js +39 -0
  24. package/dist/src/ast/nodes/doc.d.ts +38 -0
  25. package/dist/src/ast/nodes/doc.js +38 -0
  26. package/dist/src/ast/nodes/enum-value.d.ts +37 -0
  27. package/dist/src/ast/nodes/enum-value.js +37 -0
  28. package/dist/src/ast/nodes/enum.d.ts +47 -0
  29. package/dist/src/ast/nodes/enum.js +47 -0
  30. package/dist/src/ast/nodes/export.d.ts +51 -0
  31. package/dist/src/ast/nodes/export.js +51 -0
  32. package/dist/src/ast/nodes/function-type.d.ts +35 -0
  33. package/dist/src/ast/nodes/function-type.js +35 -0
  34. package/dist/src/ast/nodes/function.d.ts +61 -0
  35. package/dist/src/ast/nodes/function.js +61 -0
  36. package/dist/src/ast/nodes/generic-parameter.d.ts +44 -0
  37. package/dist/src/ast/nodes/generic-parameter.js +44 -0
  38. package/dist/src/ast/nodes/indexer.d.ts +41 -0
  39. package/dist/src/ast/nodes/indexer.js +41 -0
  40. package/dist/src/ast/nodes/interface.d.ts +57 -0
  41. package/dist/src/ast/nodes/interface.js +57 -0
  42. package/dist/src/ast/nodes/intersection-type.d.ts +32 -0
  43. package/dist/src/ast/nodes/intersection-type.js +32 -0
  44. package/dist/src/ast/nodes/lookup-type.d.ts +34 -0
  45. package/dist/src/ast/nodes/lookup-type.js +34 -0
  46. package/dist/src/ast/nodes/method.d.ts +90 -0
  47. package/dist/src/ast/nodes/method.js +90 -0
  48. package/dist/src/ast/nodes/object-type.d.ts +34 -0
  49. package/dist/src/ast/nodes/object-type.js +34 -0
  50. package/dist/src/ast/nodes/object.d.ts +34 -0
  51. package/dist/src/ast/nodes/object.js +34 -0
  52. package/dist/src/ast/nodes/parameter.d.ts +51 -0
  53. package/dist/src/ast/nodes/parameter.js +51 -0
  54. package/dist/src/ast/nodes/property-accessor.d.ts +94 -0
  55. package/dist/src/ast/nodes/property-accessor.js +94 -0
  56. package/dist/src/ast/nodes/property.d.ts +113 -0
  57. package/dist/src/ast/nodes/property.js +113 -0
  58. package/dist/src/ast/nodes/reference.d.ts +90 -0
  59. package/dist/src/ast/nodes/reference.js +66 -0
  60. package/dist/src/ast/nodes/string.d.ts +35 -0
  61. package/dist/src/ast/nodes/string.js +35 -0
  62. package/dist/src/ast/nodes/tuple.d.ts +33 -0
  63. package/dist/src/ast/nodes/tuple.js +33 -0
  64. package/dist/src/ast/nodes/type-alias.d.ts +44 -0
  65. package/dist/src/ast/nodes/type-alias.js +44 -0
  66. package/dist/src/ast/nodes/typeof.d.ts +41 -0
  67. package/dist/src/ast/nodes/typeof.js +41 -0
  68. package/dist/src/ast/nodes/types.d.ts +12 -0
  69. package/dist/src/ast/nodes/union-type.d.ts +31 -0
  70. package/dist/src/ast/nodes/union-type.js +31 -0
  71. package/dist/src/ast/nodes/variable.d.ts +46 -0
  72. package/dist/src/ast/nodes/variable.js +46 -0
  73. package/dist/src/ast/references/angular.d.ts +7 -0
  74. package/dist/src/ast/references/angular.js +7 -0
  75. package/dist/src/ast/references/easy-network-stub.d.ts +4 -0
  76. package/dist/src/ast/references/easy-network-stub.js +4 -0
  77. package/dist/src/ast/references/k6.d.ts +3 -0
  78. package/dist/src/ast/references/k6.js +3 -0
  79. package/dist/src/ast/references/rxjs.d.ts +5 -0
  80. package/dist/src/ast/references/rxjs.js +5 -0
  81. package/dist/src/ast/references/typescript.d.ts +30 -0
  82. package/dist/src/ast/references/typescript.js +30 -0
  83. package/dist/src/ast/utils/get-type-script-builder-options.d.ts +8 -0
  84. package/dist/src/ast/utils/get-type-script-builder-options.js +8 -0
  85. package/dist/src/ast/utils/to-ts-node.d.ts +28 -0
  86. package/dist/src/ast/utils/write-ts-generic-parameters.d.ts +9 -0
  87. package/dist/src/ast/utils/write-ts-generic-parameters.js +9 -0
  88. package/dist/src/ast/utils/write-ts-members.d.ts +12 -0
  89. package/dist/src/ast/utils/write-ts-members.js +12 -0
  90. package/dist/src/ast/utils/write-ts-nodes.d.ts +16 -0
  91. package/dist/src/ast/utils/write-ts-nodes.js +16 -0
  92. package/dist/src/ast/utils/write-ts-parameters.d.ts +9 -0
  93. package/dist/src/ast/utils/write-ts-parameters.js +9 -0
  94. package/dist/src/common-results.d.ts +65 -0
  95. package/dist/src/config.d.ts +32 -0
  96. package/dist/src/config.js +5 -0
  97. package/dist/src/file-builder.d.ts +104 -0
  98. package/dist/src/file-builder.js +93 -0
  99. package/dist/src/generators/file-generator.d.ts +14 -0
  100. package/dist/src/generators/file-generator.js +9 -0
  101. package/dist/src/generators/models/model-generator.d.ts +24 -0
  102. package/dist/src/generators/models/model-generator.js +15 -0
  103. package/dist/src/generators/models/models-generator.d.ts +16 -0
  104. package/dist/src/generators/models/models-generator.js +16 -0
  105. package/dist/src/generators/models/models.d.ts +53 -0
  106. package/dist/src/generators/models/models.js +8 -0
  107. package/dist/src/generators/services/angular-services/angular-service-generator.d.ts +27 -0
  108. package/dist/src/generators/services/angular-services/angular-service-generator.js +17 -0
  109. package/dist/src/generators/services/angular-services/angular-services-generator.d.ts +21 -0
  110. package/dist/src/generators/services/angular-services/angular-services-generator.js +21 -0
  111. package/dist/src/generators/services/angular-services/models.d.ts +70 -1
  112. package/dist/src/generators/services/angular-services/models.js +5 -0
  113. package/dist/src/generators/services/angular-services/refs.d.ts +11 -0
  114. package/dist/src/generators/services/angular-services/refs.js +11 -0
  115. package/dist/src/generators/services/easy-network-stub/easy-network-stub-generator.d.ts +22 -0
  116. package/dist/src/generators/services/easy-network-stub/easy-network-stub-generator.js +12 -0
  117. package/dist/src/generators/services/easy-network-stub/easy-network-stubs-generator.d.ts +16 -0
  118. package/dist/src/generators/services/easy-network-stub/easy-network-stubs-generator.js +16 -0
  119. package/dist/src/generators/services/easy-network-stub/models.d.ts +61 -0
  120. package/dist/src/generators/services/easy-network-stub/models.js +5 -0
  121. package/dist/src/generators/services/easy-network-stub/refs.d.ts +7 -0
  122. package/dist/src/generators/services/easy-network-stub/refs.js +7 -0
  123. package/dist/src/generators/services/fetch-clients/fetch-client-generator.d.ts +22 -0
  124. package/dist/src/generators/services/fetch-clients/fetch-client-generator.js +12 -0
  125. package/dist/src/generators/services/fetch-clients/fetch-clients-generator.d.ts +17 -0
  126. package/dist/src/generators/services/fetch-clients/fetch-clients-generator.js +17 -0
  127. package/dist/src/generators/services/fetch-clients/models.d.ts +64 -1
  128. package/dist/src/generators/services/fetch-clients/models.js +5 -0
  129. package/dist/src/generators/services/fetch-clients/refs.d.ts +7 -0
  130. package/dist/src/generators/services/fetch-clients/refs.js +7 -0
  131. package/dist/src/generators/services/k6-clients/k6-client-generator.d.ts +21 -0
  132. package/dist/src/generators/services/k6-clients/k6-client-generator.js +11 -0
  133. package/dist/src/generators/services/k6-clients/k6-clients-generator.d.ts +18 -0
  134. package/dist/src/generators/services/k6-clients/k6-clients-generator.js +18 -0
  135. package/dist/src/generators/services/k6-clients/models.d.ts +65 -1
  136. package/dist/src/generators/services/k6-clients/models.js +5 -0
  137. package/dist/src/generators/services/k6-clients/refs.d.ts +8 -0
  138. package/dist/src/generators/services/k6-clients/refs.js +8 -0
  139. package/dist/src/import-collection.d.ts +81 -0
  140. package/dist/src/import-collection.js +58 -0
  141. package/dist/src/utils.d.ts +62 -0
  142. package/dist/src/utils.js +47 -0
  143. package/package.json +2 -2
@@ -24,30 +24,124 @@ declare abstract class TsPropertyAccessor<TBuilder extends SourceBuilder, TInjec
24
24
  private _static;
25
25
  private _abstract;
26
26
  private _override;
27
+ /**
28
+ * The doc comment written above the accessor, or `null` to omit it. It is written as given, after the doc comment of
29
+ * the owning property when there is one.
30
+ */
27
31
  doc: TsDoc<TBuilder> | null;
32
+ /**
33
+ * The decorators written before the accessor. They are separated by spaces and written on the same line as the
34
+ * accessor, such as `@decorator get x();`.
35
+ */
28
36
  decorators: TsDecorator<TBuilder>[];
37
+ /**
38
+ * The code written in braces after the signature, on separate lines. `null` writes the accessor without a body,
39
+ * which ends with a semicolon instead.
40
+ */
29
41
  body: AppendValue<TBuilder> | null;
42
+ /**
43
+ * The name written after `get` or `set`. When the accessor belongs to an accessor property, the name of that property
44
+ * is used instead. Defaults to `someProperty` when neither is set.
45
+ */
30
46
  get propertyName(): string;
31
47
  set propertyName(value: string | null);
48
+ /**
49
+ * The type of the accessor. A getter writes it as its return type, such as `: number`, and a setter writes it as the
50
+ * type of its `value` parameter. When the accessor belongs to an accessor property, the type of that property is used
51
+ * if it is set. `null` omits the type.
52
+ */
32
53
  get type(): TsType<TBuilder> | null;
33
54
  set type(value: TsType<TBuilder> | null);
55
+ /**
56
+ * The access modifier written before the accessor, such as `public`, or `null` to omit it. When the accessor belongs
57
+ * to an accessor property, the modifier of that property is used if it is set.
58
+ */
34
59
  get accessModifier(): TsAccessModifier | null;
35
60
  set accessModifier(value: TsAccessModifier | null);
61
+ /**
62
+ * Whether the accessor is written with the `static` keyword. When the accessor belongs to an accessor property, the
63
+ * value of that property is used if it is set.
64
+ * @default false
65
+ */
36
66
  get static(): boolean;
37
67
  set static(value: boolean);
68
+ /**
69
+ * Whether the accessor is written with the `abstract` keyword. When the accessor belongs to an accessor property, the
70
+ * value of that property is used if it is set.
71
+ * @default false
72
+ */
38
73
  get abstract(): boolean;
39
74
  set abstract(value: boolean);
75
+ /**
76
+ * Whether the accessor is written with the `override` keyword. When the accessor belongs to an accessor property, the
77
+ * value of that property is used if it is set.
78
+ * @default false
79
+ */
40
80
  get override(): boolean;
41
81
  set override(value: boolean);
42
82
  protected property?: TsProperty<TBuilder>;
83
+ /**
84
+ * Initializes a new instance of the TsPropertyAccessor class.
85
+ * @param options The options to use for this instance.
86
+ */
43
87
  constructor(options: Options<TBuilder, TInjects>);
44
88
  }
89
+ /**
90
+ * Represents the setter of a property, such as `set x(value: number) { ... }`.
91
+ *
92
+ * Written in this order: doc comment, decorators, modifiers (access modifier, `static`, `abstract`, `override`), the
93
+ * `set` keyword, the name, and a `value` parameter, which is typed when a type is set. Without a body the setter ends
94
+ * with a semicolon. A body is written in braces over several lines.
95
+ *
96
+ * @template TBuilder The type of the source builder the setter is written to.
97
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
98
+ * @see createPropertySetter
99
+ */
45
100
  export declare class TsPropertySetter<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsPropertyAccessor<TBuilder, TInjects> {
46
101
  protected onWrite(builder: TBuilder): void;
47
102
  }
103
+ /**
104
+ * Represents the getter of a property, such as `get x(): number { ... }`.
105
+ *
106
+ * Written in this order: doc comment, decorators, modifiers (access modifier, `static`, `abstract`, `override`), the
107
+ * `get` keyword, the name, an empty parameter list, and the return type when a type is set. Without a body the getter
108
+ * ends with a semicolon. A body is written in braces over several lines.
109
+ *
110
+ * @template TBuilder The type of the source builder the getter is written to.
111
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
112
+ * @see createPropertyGetter
113
+ */
48
114
  export declare class TsPropertyGetter<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsPropertyAccessor<TBuilder, TInjects> {
49
115
  protected onWrite(builder: TBuilder): void;
50
116
  }
117
+ /**
118
+ * Factory for creating property setter nodes. The returned node is written with its `write` method, or it is passed
119
+ * to the `set` of an accessor property (see `tsProperty`).
120
+ *
121
+ * @param options The settings of the setter. See `TsPropertySetter` for the available properties.
122
+ * @example
123
+ * ```ts
124
+ * createPropertySetter({ propertyName: 'x', type: 'number', body: 'this.x = value;' });
125
+ * // Emits:
126
+ * // set x(value: number) {
127
+ * // this.x = value;
128
+ * // }
129
+ * ```
130
+ */
51
131
  export declare const createPropertySetter: <TBuilder extends SourceBuilder>(options?: Options<TBuilder>) => TsPropertySetter<TBuilder>;
132
+ /**
133
+ * Factory for creating property getter nodes. The returned node is written with its `write` method, or it is passed
134
+ * to the `get` of an accessor property (see `tsProperty`).
135
+ *
136
+ * @param options The settings of the getter. See `TsPropertyGetter` for the available properties.
137
+ * @example
138
+ * ```ts
139
+ * createPropertyGetter({ propertyName: 'x', type: 'number', body: 'return this.x;' });
140
+ * // Emits:
141
+ * // get x(): number {
142
+ * // return this.x;
143
+ * // }
144
+ * ```
145
+ */
52
146
  export declare const createPropertyGetter: <TBuilder extends SourceBuilder>(options?: Options<TBuilder>) => TsPropertyGetter<TBuilder>;
53
147
  export {};
@@ -10,39 +10,79 @@ class TsPropertyAccessor extends TsNode {
10
10
  _static;
11
11
  _abstract;
12
12
  _override;
13
+ /**
14
+ * The doc comment written above the accessor, or `null` to omit it. It is written as given, after the doc comment of
15
+ * the owning property when there is one.
16
+ */
13
17
  doc;
18
+ /**
19
+ * The decorators written before the accessor. They are separated by spaces and written on the same line as the
20
+ * accessor, such as `@decorator get x();`.
21
+ */
14
22
  decorators;
23
+ /**
24
+ * The code written in braces after the signature, on separate lines. `null` writes the accessor without a body,
25
+ * which ends with a semicolon instead.
26
+ */
15
27
  body;
28
+ /**
29
+ * The name written after `get` or `set`. When the accessor belongs to an accessor property, the name of that property
30
+ * is used instead. Defaults to `someProperty` when neither is set.
31
+ */
16
32
  get propertyName() {
17
33
  return this.property?.name ?? this._propertyName ?? 'someProperty';
18
34
  }
19
35
  set propertyName(value) {
20
36
  this._propertyName = value;
21
37
  }
38
+ /**
39
+ * The type of the accessor. A getter writes it as its return type, such as `: number`, and a setter writes it as the
40
+ * type of its `value` parameter. When the accessor belongs to an accessor property, the type of that property is used
41
+ * if it is set. `null` omits the type.
42
+ */
22
43
  get type() {
23
44
  return this.property?.type ?? this._type;
24
45
  }
25
46
  set type(value) {
26
47
  this._type = value;
27
48
  }
49
+ /**
50
+ * The access modifier written before the accessor, such as `public`, or `null` to omit it. When the accessor belongs
51
+ * to an accessor property, the modifier of that property is used if it is set.
52
+ */
28
53
  get accessModifier() {
29
54
  return this.property?.accessModifier ?? this._accessModifier;
30
55
  }
31
56
  set accessModifier(value) {
32
57
  this._accessModifier = value;
33
58
  }
59
+ /**
60
+ * Whether the accessor is written with the `static` keyword. When the accessor belongs to an accessor property, the
61
+ * value of that property is used if it is set.
62
+ * @default false
63
+ */
34
64
  get static() {
35
65
  return this.property?.static ?? this._static;
36
66
  }
37
67
  set static(value) {
38
68
  this._static = value;
39
69
  }
70
+ /**
71
+ * Whether the accessor is written with the `abstract` keyword. When the accessor belongs to an accessor property, the
72
+ * value of that property is used if it is set.
73
+ * @default false
74
+ */
40
75
  get abstract() {
41
76
  return this.property?.abstract ?? this._abstract;
42
77
  }
43
78
  set abstract(value) {
44
79
  this._abstract = value;
45
80
  }
81
+ /**
82
+ * Whether the accessor is written with the `override` keyword. When the accessor belongs to an accessor property, the
83
+ * value of that property is used if it is set.
84
+ * @default false
85
+ */
46
86
  get override() {
47
87
  return this.property?.override ?? this._override;
48
88
  }
@@ -50,6 +90,10 @@ class TsPropertyAccessor extends TsNode {
50
90
  this._override = value;
51
91
  }
52
92
  property;
93
+ /**
94
+ * Initializes a new instance of the TsPropertyAccessor class.
95
+ * @param options The options to use for this instance.
96
+ */
53
97
  constructor(options) {
54
98
  super(options);
55
99
  this._propertyName = options.propertyName ?? null;
@@ -63,6 +107,17 @@ class TsPropertyAccessor extends TsNode {
63
107
  this._override = options.override ?? false;
64
108
  }
65
109
  }
110
+ /**
111
+ * Represents the setter of a property, such as `set x(value: number) { ... }`.
112
+ *
113
+ * Written in this order: doc comment, decorators, modifiers (access modifier, `static`, `abstract`, `override`), the
114
+ * `set` keyword, the name, and a `value` parameter, which is typed when a type is set. Without a body the setter ends
115
+ * with a semicolon. A body is written in braces over several lines.
116
+ *
117
+ * @template TBuilder The type of the source builder the setter is written to.
118
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
119
+ * @see createPropertySetter
120
+ */
66
121
  export class TsPropertySetter extends TsPropertyAccessor {
67
122
  onWrite(builder) {
68
123
  tsDoc.write(builder, this.doc);
@@ -93,6 +148,17 @@ export class TsPropertySetter extends TsPropertyAccessor {
93
148
  builder.appendLine();
94
149
  }
95
150
  }
151
+ /**
152
+ * Represents the getter of a property, such as `get x(): number { ... }`.
153
+ *
154
+ * Written in this order: doc comment, decorators, modifiers (access modifier, `static`, `abstract`, `override`), the
155
+ * `get` keyword, the name, an empty parameter list, and the return type when a type is set. Without a body the getter
156
+ * ends with a semicolon. A body is written in braces over several lines.
157
+ *
158
+ * @template TBuilder The type of the source builder the getter is written to.
159
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
160
+ * @see createPropertyGetter
161
+ */
96
162
  export class TsPropertyGetter extends TsPropertyAccessor {
97
163
  onWrite(builder) {
98
164
  tsDoc.write(builder, this.doc);
@@ -120,5 +186,33 @@ export class TsPropertyGetter extends TsPropertyAccessor {
120
186
  builder.appendLine();
121
187
  }
122
188
  }
189
+ /**
190
+ * Factory for creating property setter nodes. The returned node is written with its `write` method, or it is passed
191
+ * to the `set` of an accessor property (see `tsProperty`).
192
+ *
193
+ * @param options The settings of the setter. See `TsPropertySetter` for the available properties.
194
+ * @example
195
+ * ```ts
196
+ * createPropertySetter({ propertyName: 'x', type: 'number', body: 'this.x = value;' });
197
+ * // Emits:
198
+ * // set x(value: number) {
199
+ * // this.x = value;
200
+ * // }
201
+ * ```
202
+ */
123
203
  export const createPropertySetter = (options) => new TsPropertySetter(options ?? {});
204
+ /**
205
+ * Factory for creating property getter nodes. The returned node is written with its `write` method, or it is passed
206
+ * to the `get` of an accessor property (see `tsProperty`).
207
+ *
208
+ * @param options The settings of the getter. See `TsPropertyGetter` for the available properties.
209
+ * @example
210
+ * ```ts
211
+ * createPropertyGetter({ propertyName: 'x', type: 'number', body: 'return this.x;' });
212
+ * // Emits:
213
+ * // get x(): number {
214
+ * // return this.x;
215
+ * // }
216
+ * ```
217
+ */
124
218
  export const createPropertyGetter = (options) => new TsPropertyGetter(options ?? {});
@@ -26,35 +26,148 @@ type AccessorOptions<TBuilder extends SourceBuilder, TInjects extends string = n
26
26
  get?: Nullable<TsPropertyGetter<TBuilder>>;
27
27
  set?: Nullable<TsPropertySetter<TBuilder>>;
28
28
  };
29
+ /**
30
+ * Base class for the properties of classes and object literals. It holds the parts that all properties share: the name,
31
+ * the doc comment, the decorators, the type and the modifiers.
32
+ *
33
+ * Use `tsProperty` to create a property. It returns a `TsSimpleProperty` for a plain property, and a
34
+ * `TsAccessorProperty` when getters or setters are passed in its options.
35
+ *
36
+ * @template TBuilder The type of the source builder the property is written to.
37
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
38
+ * @see tsProperty
39
+ */
29
40
  export declare abstract class TsProperty<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | BaseInjects> {
41
+ /**
42
+ * The name of the property. A simple property writes it verbatim, or in quotes when it is not a plain identifier,
43
+ * such as `'x y'`. An accessor property writes it through its getter and setter instead.
44
+ */
30
45
  name: string;
46
+ /**
47
+ * The doc comment written above the property, or `null` to omit it. It is written as given, so no tags are added.
48
+ */
31
49
  doc: TsDoc<TBuilder> | null;
50
+ /**
51
+ * The decorators written before the property. They are separated by spaces and written on the same line as the
52
+ * property, such as `@decorator x;`.
53
+ */
32
54
  decorators: TsDecorator<TBuilder>[];
55
+ /**
56
+ * The type annotation written after the name, such as `: number`, or `null` to omit it. A simple property also omits
57
+ * the annotation inside an object literal, which has none.
58
+ */
33
59
  type: TsType<TBuilder> | null;
60
+ /**
61
+ * The access modifier written before the property, such as `public`, or `null` to omit it.
62
+ */
34
63
  accessModifier: TsAccessModifier | null;
64
+ /**
65
+ * Whether the property is written with the `static` keyword. `null` and `false` both omit the keyword.
66
+ * @default null
67
+ */
35
68
  static: boolean | null;
69
+ /**
70
+ * Whether the property is written with the `abstract` keyword. `null` and `false` both omit the keyword.
71
+ * @default null
72
+ */
36
73
  abstract: boolean | null;
74
+ /**
75
+ * Whether the property is written with the `override` keyword. `null` and `false` both omit the keyword.
76
+ * @default null
77
+ */
37
78
  override: boolean | null;
79
+ /**
80
+ * Initializes a new instance of the TsProperty class.
81
+ * @param options The options to use for this instance.
82
+ */
38
83
  constructor(options: BaseOptions<TBuilder, TInjects>);
39
84
  }
85
+ /**
86
+ * Represents a property with a name, an optional type and an optional value, such as `readonly x?: number = 42;`.
87
+ *
88
+ * Written in this order: doc comment, decorators, modifiers (access modifier, `static`, `abstract`, `override`,
89
+ * `readonly`), name, optional marker, type annotation, value, and a terminator. Inside an object literal (`tsObject`),
90
+ * the property is written as `x: 42,` instead: the type annotation is omitted, the value follows a colon, and a comma
91
+ * ends the property.
92
+ *
93
+ * @template TBuilder The type of the source builder the property is written to.
94
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
95
+ * @see tsProperty
96
+ */
40
97
  export declare class TsSimpleProperty<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsProperty<TBuilder, TInjects> {
98
+ /**
99
+ * The initial value of the property, or `null` to omit it. In a class it is written after ` = `, such as `x = 42;`,
100
+ * and in an object literal after a colon, such as `x: 42,`. Falsy values are not written.
101
+ */
41
102
  value: TsValue<TBuilder> | null;
103
+ /**
104
+ * Whether the property is written with the `readonly` keyword, which is placed after the other modifiers.
105
+ * @default false
106
+ */
42
107
  readonly: boolean;
108
+ /**
109
+ * Whether the name is followed by `?`, which marks the property as optional, such as `x?: number`.
110
+ * @default false
111
+ */
43
112
  optional: boolean;
113
+ /**
114
+ * Initializes a new instance of the TsSimpleProperty class.
115
+ * @param options The options to use for this instance.
116
+ */
44
117
  constructor(options: SimpleOptions<TBuilder, TInjects>);
45
118
  protected onWrite(builder: TBuilder): void;
46
119
  }
120
+ /**
121
+ * Represents a property that is written as a getter, a setter, or both, such as `get x(): number` and `set x(value)`.
122
+ *
123
+ * The property writes its doc comment and decorators first, then its getter, and then its setter. The accessors take
124
+ * their name, type and modifiers from this property when those are set here.
125
+ *
126
+ * @template TBuilder The type of the source builder the property is written to.
127
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
128
+ * @see tsProperty
129
+ * @see TsPropertyGetter
130
+ * @see TsPropertySetter
131
+ */
47
132
  export declare class TsAccessorProperty<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsProperty<TBuilder, TInjects> {
48
133
  private _get;
49
134
  private _set;
135
+ /**
136
+ * The getter of the property, or `null` to omit it. Assigning a getter links it to this property, so the getter takes
137
+ * its name, type and modifiers from here. A getter that was assigned before is unlinked.
138
+ */
50
139
  get get(): TsPropertyGetter<TBuilder> | null;
51
140
  set get(value: TsPropertyGetter<TBuilder> | null);
141
+ /**
142
+ * The setter of the property, or `null` to omit it. Assigning a setter links it to this property, so the setter takes
143
+ * its name, type and modifiers from here. A setter that was assigned before is unlinked.
144
+ */
52
145
  get set(): TsPropertySetter<TBuilder> | null;
53
146
  set set(value: TsPropertySetter<TBuilder> | null);
147
+ /**
148
+ * Initializes a new instance of the TsAccessorProperty class.
149
+ * @param options The options to use for this instance.
150
+ */
54
151
  constructor(options: AccessorOptions<TBuilder, TInjects>);
55
152
  protected onWrite(builder: TBuilder): void;
56
153
  }
57
154
  declare const createProperty: <TBuilder extends SourceBuilder>(name: BaseOptions<TBuilder>['name'], options?: Prettify<Omit<SimpleOptions<TBuilder>, 'name'>> | Prettify<Omit<AccessorOptions<TBuilder>, 'name'>>) => TsProperty<TBuilder>;
155
+ /**
156
+ * Factory for creating property nodes. The `write` function writes one or more property nodes to a builder. The
157
+ * `getter` and `setter` functions create the accessors that are passed to an accessor property.
158
+ *
159
+ * Passing `get` or `set` in the options creates a `TsAccessorProperty`. Otherwise a `TsSimpleProperty` is created.
160
+ *
161
+ * @param name The name of the property. See `TsProperty.name`.
162
+ * @param options The settings of the property. See `TsSimpleProperty` and `TsAccessorProperty` for the available
163
+ * properties.
164
+ * @example
165
+ * ```ts
166
+ * tsProperty('x', { type: 'number', value: 42, readonly: true, accessModifier: 'public' });
167
+ * // Emits:
168
+ * // public readonly x: number = 42;
169
+ * ```
170
+ */
58
171
  export declare const tsProperty: typeof createProperty & {
59
172
  write: typeof writeTsNodes;
60
173
  getter: typeof createPropertyGetter;
@@ -6,15 +6,60 @@ import { tsDoc } from './doc.js';
6
6
  import { TsObject } from './object.js';
7
7
  import { createPropertyGetter, createPropertySetter, } from './property-accessor.js';
8
8
  import { tsString } from './string.js';
9
+ /**
10
+ * Base class for the properties of classes and object literals. It holds the parts that all properties share: the name,
11
+ * the doc comment, the decorators, the type and the modifiers.
12
+ *
13
+ * Use `tsProperty` to create a property. It returns a `TsSimpleProperty` for a plain property, and a
14
+ * `TsAccessorProperty` when getters or setters are passed in its options.
15
+ *
16
+ * @template TBuilder The type of the source builder the property is written to.
17
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
18
+ * @see tsProperty
19
+ */
9
20
  export class TsProperty extends TsNode {
21
+ /**
22
+ * The name of the property. A simple property writes it verbatim, or in quotes when it is not a plain identifier,
23
+ * such as `'x y'`. An accessor property writes it through its getter and setter instead.
24
+ */
10
25
  name;
26
+ /**
27
+ * The doc comment written above the property, or `null` to omit it. It is written as given, so no tags are added.
28
+ */
11
29
  doc;
30
+ /**
31
+ * The decorators written before the property. They are separated by spaces and written on the same line as the
32
+ * property, such as `@decorator x;`.
33
+ */
12
34
  decorators;
35
+ /**
36
+ * The type annotation written after the name, such as `: number`, or `null` to omit it. A simple property also omits
37
+ * the annotation inside an object literal, which has none.
38
+ */
13
39
  type;
40
+ /**
41
+ * The access modifier written before the property, such as `public`, or `null` to omit it.
42
+ */
14
43
  accessModifier;
44
+ /**
45
+ * Whether the property is written with the `static` keyword. `null` and `false` both omit the keyword.
46
+ * @default null
47
+ */
15
48
  static;
49
+ /**
50
+ * Whether the property is written with the `abstract` keyword. `null` and `false` both omit the keyword.
51
+ * @default null
52
+ */
16
53
  abstract;
54
+ /**
55
+ * Whether the property is written with the `override` keyword. `null` and `false` both omit the keyword.
56
+ * @default null
57
+ */
17
58
  override;
59
+ /**
60
+ * Initializes a new instance of the TsProperty class.
61
+ * @param options The options to use for this instance.
62
+ */
18
63
  constructor(options) {
19
64
  super(options);
20
65
  this.name = options.name;
@@ -27,10 +72,38 @@ export class TsProperty extends TsNode {
27
72
  this.override = options.override ?? null;
28
73
  }
29
74
  }
75
+ /**
76
+ * Represents a property with a name, an optional type and an optional value, such as `readonly x?: number = 42;`.
77
+ *
78
+ * Written in this order: doc comment, decorators, modifiers (access modifier, `static`, `abstract`, `override`,
79
+ * `readonly`), name, optional marker, type annotation, value, and a terminator. Inside an object literal (`tsObject`),
80
+ * the property is written as `x: 42,` instead: the type annotation is omitted, the value follows a colon, and a comma
81
+ * ends the property.
82
+ *
83
+ * @template TBuilder The type of the source builder the property is written to.
84
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
85
+ * @see tsProperty
86
+ */
30
87
  export class TsSimpleProperty extends TsProperty {
88
+ /**
89
+ * The initial value of the property, or `null` to omit it. In a class it is written after ` = `, such as `x = 42;`,
90
+ * and in an object literal after a colon, such as `x: 42,`. Falsy values are not written.
91
+ */
31
92
  value;
93
+ /**
94
+ * Whether the property is written with the `readonly` keyword, which is placed after the other modifiers.
95
+ * @default false
96
+ */
32
97
  readonly;
98
+ /**
99
+ * Whether the name is followed by `?`, which marks the property as optional, such as `x?: number`.
100
+ * @default false
101
+ */
33
102
  optional;
103
+ /**
104
+ * Initializes a new instance of the TsSimpleProperty class.
105
+ * @param options The options to use for this instance.
106
+ */
34
107
  constructor(options) {
35
108
  super(options);
36
109
  this.value = options.value ?? null;
@@ -66,9 +139,25 @@ export class TsSimpleProperty extends TsProperty {
66
139
  builder.appendLine();
67
140
  }
68
141
  }
142
+ /**
143
+ * Represents a property that is written as a getter, a setter, or both, such as `get x(): number` and `set x(value)`.
144
+ *
145
+ * The property writes its doc comment and decorators first, then its getter, and then its setter. The accessors take
146
+ * their name, type and modifiers from this property when those are set here.
147
+ *
148
+ * @template TBuilder The type of the source builder the property is written to.
149
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
150
+ * @see tsProperty
151
+ * @see TsPropertyGetter
152
+ * @see TsPropertySetter
153
+ */
69
154
  export class TsAccessorProperty extends TsProperty {
70
155
  _get = null;
71
156
  _set = null;
157
+ /**
158
+ * The getter of the property, or `null` to omit it. Assigning a getter links it to this property, so the getter takes
159
+ * its name, type and modifiers from here. A getter that was assigned before is unlinked.
160
+ */
72
161
  get get() {
73
162
  return this._get;
74
163
  }
@@ -81,6 +170,10 @@ export class TsAccessorProperty extends TsProperty {
81
170
  }
82
171
  this._get = value;
83
172
  }
173
+ /**
174
+ * The setter of the property, or `null` to omit it. Assigning a setter links it to this property, so the setter takes
175
+ * its name, type and modifiers from here. A setter that was assigned before is unlinked.
176
+ */
84
177
  get set() {
85
178
  return this._set;
86
179
  }
@@ -93,6 +186,10 @@ export class TsAccessorProperty extends TsProperty {
93
186
  }
94
187
  this._set = value;
95
188
  }
189
+ /**
190
+ * Initializes a new instance of the TsAccessorProperty class.
191
+ * @param options The options to use for this instance.
192
+ */
96
193
  constructor(options) {
97
194
  super(options);
98
195
  this.get = options.get ?? null;
@@ -114,6 +211,22 @@ const createProperty = (name, options) => {
114
211
  }
115
212
  return new TsSimpleProperty({ ...options, name });
116
213
  };
214
+ /**
215
+ * Factory for creating property nodes. The `write` function writes one or more property nodes to a builder. The
216
+ * `getter` and `setter` functions create the accessors that are passed to an accessor property.
217
+ *
218
+ * Passing `get` or `set` in the options creates a `TsAccessorProperty`. Otherwise a `TsSimpleProperty` is created.
219
+ *
220
+ * @param name The name of the property. See `TsProperty.name`.
221
+ * @param options The settings of the property. See `TsSimpleProperty` and `TsAccessorProperty` for the available
222
+ * properties.
223
+ * @example
224
+ * ```ts
225
+ * tsProperty('x', { type: 'number', value: 42, readonly: true, accessModifier: 'public' });
226
+ * // Emits:
227
+ * // public readonly x: number = 42;
228
+ * ```
229
+ */
117
230
  export const tsProperty = Object.assign(createProperty, {
118
231
  write: writeTsNodes,
119
232
  getter: createPropertyGetter,