@alloy-js/typescript 0.9.0 → 0.11.0

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 (203) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/src/builtins/node.js +1 -2
  3. package/dist/src/components/ArrayExpression.js +2 -5
  4. package/dist/src/components/ArrowFunction.d.ts +40 -0
  5. package/dist/src/components/ArrowFunction.d.ts.map +1 -0
  6. package/dist/src/components/ArrowFunction.js +67 -0
  7. package/dist/src/components/BarrelFile.js +1 -2
  8. package/dist/src/components/BlockScope.js +2 -4
  9. package/dist/src/components/CallSignature.js +2 -4
  10. package/dist/src/components/ClassDeclaration.js +2 -6
  11. package/dist/src/components/CommaList.js +2 -5
  12. package/dist/src/components/Declaration.js +3 -5
  13. package/dist/src/components/EnumDeclaration.js +2 -5
  14. package/dist/src/components/EnumMember.js +2 -4
  15. package/dist/src/components/ExportStatement.js +1 -2
  16. package/dist/src/components/FunctionBase.d.ts +60 -0
  17. package/dist/src/components/FunctionBase.d.ts.map +1 -0
  18. package/dist/src/components/FunctionBase.js +207 -0
  19. package/dist/src/components/FunctionCallExpression.js +2 -5
  20. package/dist/src/components/FunctionDeclaration.d.ts +3 -18
  21. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  22. package/dist/src/components/FunctionDeclaration.js +9 -157
  23. package/dist/src/components/FunctionExpression.d.ts +39 -0
  24. package/dist/src/components/FunctionExpression.d.ts.map +1 -0
  25. package/dist/src/components/FunctionExpression.js +66 -0
  26. package/dist/src/components/FunctionType.d.ts +39 -0
  27. package/dist/src/components/FunctionType.d.ts.map +1 -0
  28. package/dist/src/components/FunctionType.js +73 -0
  29. package/dist/src/components/IfStatement.js +2 -4
  30. package/dist/src/components/ImportStatement.js +1 -2
  31. package/dist/src/components/Interface.d.ts.map +1 -1
  32. package/dist/src/components/Interface.js +32 -11
  33. package/dist/src/components/InterfaceMethod.d.ts +43 -0
  34. package/dist/src/components/InterfaceMethod.d.ts.map +1 -0
  35. package/dist/src/components/InterfaceMethod.js +87 -0
  36. package/dist/src/components/JSDoc.js +1 -2
  37. package/dist/src/components/JSDocComment.js +2 -4
  38. package/dist/src/components/JSDocExample.js +2 -5
  39. package/dist/src/components/JSDocParam.js +2 -5
  40. package/dist/src/components/MemberChainExpression.js +2 -4
  41. package/dist/src/components/MemberDeclaration.d.ts +30 -0
  42. package/dist/src/components/MemberDeclaration.d.ts.map +1 -0
  43. package/dist/src/components/MemberDeclaration.js +29 -0
  44. package/dist/src/components/MemberExpression.d.ts +1 -2
  45. package/dist/src/components/MemberExpression.d.ts.map +1 -1
  46. package/dist/src/components/MemberExpression.js +2 -5
  47. package/dist/src/components/ObjectExpression.js +2 -5
  48. package/dist/src/components/PackageDirectory.js +2 -5
  49. package/dist/src/components/PackageJson.js +1 -2
  50. package/dist/src/components/PropertyName.js +1 -2
  51. package/dist/src/components/Reference.js +1 -2
  52. package/dist/src/components/SingleLineCommentBlock.js +2 -4
  53. package/dist/src/components/SourceFile.js +2 -4
  54. package/dist/src/components/SwitchStatement.js +2 -5
  55. package/dist/src/components/TsConfigJson.js +1 -2
  56. package/dist/src/components/TypeDeclaration.js +2 -6
  57. package/dist/src/components/ValueExpression.js +1 -2
  58. package/dist/src/components/VarDeclaration.js +2 -5
  59. package/dist/src/components/index.d.ts +7 -0
  60. package/dist/src/components/index.d.ts.map +1 -1
  61. package/dist/src/components/index.js +7 -1
  62. package/dist/src/components/stc/index.d.ts +8 -0
  63. package/dist/src/components/stc/index.d.ts.map +1 -1
  64. package/dist/src/components/stc/index.js +9 -2
  65. package/dist/src/context/private-scope.js +1 -2
  66. package/dist/src/create-package.js +1 -2
  67. package/dist/src/index.js +1 -2
  68. package/dist/src/name-conflict-resolver.js +1 -2
  69. package/dist/src/name-policy.js +1 -2
  70. package/dist/src/parameter-descriptor.d.ts +27 -17
  71. package/dist/src/parameter-descriptor.d.ts.map +1 -1
  72. package/dist/src/source-directory-data.js +1 -2
  73. package/dist/src/symbols/index.js +1 -2
  74. package/dist/src/symbols/reference.js +2 -3
  75. package/dist/src/symbols/scopes.js +1 -2
  76. package/dist/src/symbols/ts-member-scope.js +1 -2
  77. package/dist/src/symbols/ts-module-scope.js +1 -2
  78. package/dist/src/symbols/ts-output-symbol.js +1 -2
  79. package/dist/src/symbols/ts-package-scope.js +1 -2
  80. package/dist/src/utils.js +1 -2
  81. package/dist/test/array.test.js +105 -0
  82. package/dist/test/arrow-function.test.d.ts +2 -0
  83. package/dist/test/arrow-function.test.d.ts.map +1 -0
  84. package/dist/test/arrow-function.test.js +194 -0
  85. package/dist/test/barrel.test.js +53 -0
  86. package/dist/test/basic.test.js +91 -0
  87. package/dist/test/block-scope.test.js +30 -0
  88. package/dist/test/class.test.js +438 -0
  89. package/dist/test/enum-jsdoc.test.js +88 -0
  90. package/dist/test/enum.test.js +247 -0
  91. package/dist/test/externals.test.js +145 -0
  92. package/dist/test/function-call-expression.test.js +87 -0
  93. package/dist/test/function-declaration-jsdoc.test.js +91 -0
  94. package/dist/test/function-declaration.test.js +228 -0
  95. package/dist/test/function-expression.test.d.ts +2 -0
  96. package/dist/test/function-expression.test.d.ts.map +1 -0
  97. package/dist/test/function-expression.test.js +194 -0
  98. package/dist/test/function-type.test.d.ts +2 -0
  99. package/dist/test/function-type.test.d.ts.map +1 -0
  100. package/dist/test/function-type.test.js +122 -0
  101. package/dist/test/if-statement.test.js +25 -0
  102. package/dist/test/imports.test.js +434 -0
  103. package/dist/test/interface-jsdoc.test.js +178 -0
  104. package/dist/test/interface.test.d.ts.map +1 -1
  105. package/dist/test/interface.test.js +490 -0
  106. package/dist/test/jscomment.test.js +70 -0
  107. package/dist/test/jsdoc.test.js +134 -0
  108. package/dist/test/jsdocparam.test.js +164 -0
  109. package/dist/test/member-chain.test.js +141 -0
  110. package/dist/test/member-expression.test.js +359 -0
  111. package/dist/test/name-conflict.test.js +108 -0
  112. package/dist/test/name-policy.test.js +122 -0
  113. package/dist/test/package-external.test.js +196 -0
  114. package/dist/test/package-json.test.js +93 -0
  115. package/dist/test/package.test.js +136 -0
  116. package/dist/test/reference.test.js +81 -0
  117. package/dist/test/source-file.test.js +36 -0
  118. package/dist/test/switch-statement.test.js +61 -0
  119. package/dist/test/utils.js +45 -0
  120. package/dist/test/value-expression.test.js +30 -0
  121. package/dist/test/values.test.js +351 -0
  122. package/dist/test/var-declaration-jsdoc.test.js +50 -0
  123. package/dist/test/var-declaration.test.js +63 -0
  124. package/dist/test/vitest.d.js +1 -0
  125. package/dist/tsconfig.tsbuildinfo +1 -1
  126. package/package.json +12 -17
  127. package/src/components/ArrowFunction.tsx +87 -0
  128. package/src/components/Declaration.tsx +1 -1
  129. package/src/components/FunctionBase.tsx +271 -0
  130. package/src/components/FunctionDeclaration.tsx +13 -195
  131. package/src/components/FunctionExpression.tsx +86 -0
  132. package/src/components/FunctionType.tsx +88 -0
  133. package/src/components/Interface.tsx +33 -5
  134. package/src/components/InterfaceMethod.tsx +96 -0
  135. package/src/components/MemberDeclaration.tsx +70 -0
  136. package/src/components/MemberExpression.tsx +1 -1
  137. package/src/components/index.ts +11 -0
  138. package/src/components/stc/index.ts +8 -0
  139. package/src/parameter-descriptor.ts +29 -18
  140. package/src/symbols/reference.ts +4 -1
  141. package/temp/api.json +3099 -863
  142. package/test/arrow-function.test.tsx +188 -0
  143. package/test/class.test.tsx +1 -2
  144. package/test/function-call-expression.test.tsx +1 -2
  145. package/test/function-declaration.test.tsx +1 -2
  146. package/test/function-expression.test.tsx +195 -0
  147. package/test/function-type.test.tsx +118 -0
  148. package/test/interface.test.tsx +256 -6
  149. package/tsdoc-metadata.json +1 -1
  150. package/babel.config.cjs +0 -4
  151. package/dist/src/builtins/index.js.map +0 -1
  152. package/dist/src/builtins/node.js.map +0 -1
  153. package/dist/src/components/ArrayExpression.js.map +0 -1
  154. package/dist/src/components/BarrelFile.js.map +0 -1
  155. package/dist/src/components/BlockScope.js.map +0 -1
  156. package/dist/src/components/CallSignature.js.map +0 -1
  157. package/dist/src/components/ClassDeclaration.js.map +0 -1
  158. package/dist/src/components/CommaList.js.map +0 -1
  159. package/dist/src/components/Declaration.js.map +0 -1
  160. package/dist/src/components/EnumDeclaration.js.map +0 -1
  161. package/dist/src/components/EnumMember.js.map +0 -1
  162. package/dist/src/components/ExportStatement.js.map +0 -1
  163. package/dist/src/components/FunctionCallExpression.js.map +0 -1
  164. package/dist/src/components/FunctionDeclaration.js.map +0 -1
  165. package/dist/src/components/IfStatement.js.map +0 -1
  166. package/dist/src/components/ImportStatement.js.map +0 -1
  167. package/dist/src/components/Interface.js.map +0 -1
  168. package/dist/src/components/JSDoc.js.map +0 -1
  169. package/dist/src/components/JSDocComment.js.map +0 -1
  170. package/dist/src/components/JSDocExample.js.map +0 -1
  171. package/dist/src/components/JSDocParam.js.map +0 -1
  172. package/dist/src/components/MemberChainExpression.js.map +0 -1
  173. package/dist/src/components/MemberExpression.js.map +0 -1
  174. package/dist/src/components/ObjectExpression.js.map +0 -1
  175. package/dist/src/components/PackageDirectory.js.map +0 -1
  176. package/dist/src/components/PackageJson.js.map +0 -1
  177. package/dist/src/components/PropertyName.js.map +0 -1
  178. package/dist/src/components/Reference.js.map +0 -1
  179. package/dist/src/components/SingleLineCommentBlock.js.map +0 -1
  180. package/dist/src/components/SourceFile.js.map +0 -1
  181. package/dist/src/components/SwitchStatement.js.map +0 -1
  182. package/dist/src/components/TsConfigJson.js.map +0 -1
  183. package/dist/src/components/TypeDeclaration.js.map +0 -1
  184. package/dist/src/components/ValueExpression.js.map +0 -1
  185. package/dist/src/components/VarDeclaration.js.map +0 -1
  186. package/dist/src/components/index.js.map +0 -1
  187. package/dist/src/components/stc/index.js.map +0 -1
  188. package/dist/src/context/index.js.map +0 -1
  189. package/dist/src/context/private-scope.js.map +0 -1
  190. package/dist/src/create-package.js.map +0 -1
  191. package/dist/src/index.js.map +0 -1
  192. package/dist/src/name-conflict-resolver.js.map +0 -1
  193. package/dist/src/name-policy.js.map +0 -1
  194. package/dist/src/parameter-descriptor.js.map +0 -1
  195. package/dist/src/source-directory-data.js.map +0 -1
  196. package/dist/src/symbols/index.js.map +0 -1
  197. package/dist/src/symbols/reference.js.map +0 -1
  198. package/dist/src/symbols/scopes.js.map +0 -1
  199. package/dist/src/symbols/ts-member-scope.js.map +0 -1
  200. package/dist/src/symbols/ts-module-scope.js.map +0 -1
  201. package/dist/src/symbols/ts-output-symbol.js.map +0 -1
  202. package/dist/src/symbols/ts-package-scope.js.map +0 -1
  203. package/dist/src/utils.js.map +0 -1
@@ -1,20 +1,11 @@
1
- import { mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
- import { createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
3
- import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
4
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
5
- import { Block, childrenArray, code, findKeyedChild, findUnkeyedChildren, For, Indent, Name, Prose, Scope, Show, taggedComponent } from "@alloy-js/core";
6
- import { onCleanup } from "@alloy-js/core/jsx-runtime";
7
- import { useTSNamePolicy } from "../name-policy.js";
8
- import { createTSSymbol, TSSymbolFlags } from "../symbols/index.js";
1
+ import { createComponent as _$createComponent, memo as _$memo, createIntrinsic as _$createIntrinsic, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { childrenArray, findKeyedChild, findUnkeyedChildren, Name, Prose, Scope, Show } from "@alloy-js/core";
9
3
  import { getCallSignatureProps } from "../utils.js";
10
4
  import { CallSignature } from "./CallSignature.js";
11
5
  import { Declaration } from "./Declaration.js";
6
+ import { FunctionBody, FunctionParameters, getReturnType, TypeParameters } from "./FunctionBase.js";
12
7
  import { JSDoc } from "./JSDoc.js";
13
8
  import { JSDocParams } from "./JSDocParam.js";
14
- export const functionParametersTag = Symbol();
15
- export const functionTypeParametersTag = Symbol();
16
- export const functionBodyTag = Symbol();
17
-
18
9
  /**
19
10
  * A TypeScript function declaration.
20
11
  *
@@ -33,9 +24,9 @@ export const functionBodyTag = Symbol();
33
24
  */
34
25
  export function FunctionDeclaration(props) {
35
26
  const children = childrenArray(() => props.children);
36
- const typeParametersChildren = findKeyedChild(children, functionTypeParametersTag) ?? undefined;
37
- const parametersChildren = findKeyedChild(children, functionParametersTag) ?? undefined;
38
- const bodyChildren = findKeyedChild(children, functionBodyTag) ?? undefined;
27
+ const typeParametersChildren = findKeyedChild(children, TypeParameters.tag) ?? undefined;
28
+ const parametersChildren = findKeyedChild(children, FunctionParameters.tag) ?? undefined;
29
+ const bodyChildren = findKeyedChild(children, FunctionBody.tag) ?? undefined;
39
30
  const filteredChildren = findUnkeyedChildren(children);
40
31
  const returnType = getReturnType(props.returnType, {
41
32
  async: props.async
@@ -84,145 +75,6 @@ export function FunctionDeclaration(props) {
84
75
  }
85
76
  }))];
86
77
  }
87
- function getReturnType(returnType, options = {
88
- async: false
89
- }) {
90
- if (returnType) {
91
- return options.async ? code`Promise<${returnType}>` : returnType;
92
- }
93
- }
94
- function normalizeAndDeclareParameters(parameters, flags = TSSymbolFlags.ParameterSymbol) {
95
- const namePolicy = useTSNamePolicy();
96
- if (parameters.length === 0) {
97
- return [];
98
- }
99
- if (typeof parameters[0] === "string") {
100
- return parameters.map(paramName => {
101
- const symbol = createTSSymbol({
102
- name: namePolicy.getName(paramName, flags & TSSymbolFlags.TypeSymbol ? "type" : "parameter"),
103
- tsFlags: flags
104
- });
105
- return {
106
- refkeys: symbol.refkeys,
107
- symbol
108
- };
109
- });
110
- } else {
111
- return parameters.map(param => {
112
- const symbol = createTSSymbol({
113
- name: namePolicy.getName(param.name, flags & TSSymbolFlags.TypeSymbol ? "type" : "parameter"),
114
- refkey: param.refkey,
115
- tsFlags: flags,
116
- metadata: param.metadata
117
- });
118
- return {
119
- ...param,
120
- symbol
121
- };
122
- });
123
- }
124
- }
125
- FunctionDeclaration.TypeParameters = taggedComponent(functionTypeParametersTag, function TypeParameters(props) {
126
- if (props.children) {
127
- return props.children;
128
- }
129
- if (!props.parameters) {
130
- return undefined;
131
- }
132
- const typeParameters = normalizeAndDeclareParameters(props.parameters);
133
- onCleanup(() => {
134
- for (const param of typeParameters) {
135
- param.symbol.binder.deleteSymbol(param.symbol);
136
- }
137
- });
138
- return ["<", _$createIntrinsic("group", {
139
- get children() {
140
- return _$createComponent(Indent, {
141
- softline: true,
142
- get children() {
143
- return [_$createComponent(For, {
144
- each: typeParameters,
145
- comma: true,
146
- line: true,
147
- children: param => typeParameter(param)
148
- }), _$createIntrinsic("ifBreak", {
149
- children: ","
150
- })];
151
- }
152
- });
153
- }
154
- }), ">"];
155
- });
156
- function typeParameter(param) {
157
- return _$createIntrinsic("group", {
158
- get children() {
159
- return [_$memo(() => param.symbol.name), _$createComponent(Show, {
160
- get when() {
161
- return !!param.extends;
162
- },
163
- get children() {
164
- return [" ", "extends", _$createIntrinsic("indent", {
165
- get children() {
166
- return [" ", _$memo(() => param.extends)];
167
- }
168
- })];
169
- }
170
- })];
171
- }
172
- });
173
- }
174
- FunctionDeclaration.Parameters = taggedComponent(functionParametersTag, function Parameters(props) {
175
- if (props.children) {
176
- return props.children;
177
- }
178
- const parameters = normalizeAndDeclareParameters(props.parameters ?? []);
179
- return _$createIntrinsic("group", {
180
- get children() {
181
- return _$createComponent(Indent, {
182
- softline: true,
183
- trailingBreak: true,
184
- get children() {
185
- return [_$createComponent(For, {
186
- each: parameters,
187
- comma: true,
188
- line: true,
189
- children: param => parameter(param)
190
- }), _$createIntrinsic("ifBreak", {
191
- children: ","
192
- })];
193
- }
194
- });
195
- }
196
- });
197
- });
198
- function parameter(param) {
199
- return _$createIntrinsic("group", {
200
- get children() {
201
- return [_$memo(() => param.symbol.name), _$createComponent(Show, {
202
- get when() {
203
- return !!param.optional;
204
- },
205
- children: "?"
206
- }), _$createComponent(Show, {
207
- get when() {
208
- return !!param.type;
209
- },
210
- get children() {
211
- return _$createIntrinsic("indent", {
212
- get children() {
213
- return [": ", _$memo(() => param.type)];
214
- }
215
- });
216
- }
217
- })];
218
- }
219
- });
220
- }
221
- FunctionDeclaration.Body = taggedComponent(functionBodyTag, function Body(props) {
222
- return _$createComponent(Block, {
223
- get children() {
224
- return props.children;
225
- }
226
- });
227
- });
228
- //# sourceMappingURL=FunctionDeclaration.js.map
78
+ FunctionDeclaration.TypeParameters = TypeParameters;
79
+ FunctionDeclaration.Parameters = FunctionParameters;
80
+ FunctionDeclaration.Body = FunctionBody;
@@ -0,0 +1,39 @@
1
+ import { Children } from "@alloy-js/core/jsx-runtime";
2
+ import { CallSignatureProps } from "./CallSignature.jsx";
3
+ export interface FunctionExpressionProps extends CallSignatureProps {
4
+ async?: boolean;
5
+ children?: Children;
6
+ }
7
+ /**
8
+ * A TypeScript function expression.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * <FunctionExpression async parameters={[{ name: "a", type: "number" }, { name: "b", type: "number" }]}>
13
+ * return a + b;
14
+ * <FunctionExpression>
15
+ * ```
16
+ * renders to
17
+ * ```ts
18
+ * async function (a, b) { return a + b; }
19
+ * ```
20
+ * @remarks
21
+ *
22
+ * Providing parameters and type parameters can be accomplished in one of three
23
+ * ways:
24
+ *
25
+ * 1. As an array of {@link ParameterDescriptor}s or
26
+ * {@link TypeParameterDescriptor}s.
27
+ * 2. As raw content via the `parametersChildren` or `typeParametersChildren`
28
+ * props.
29
+ * 3. As a child of this component via the
30
+ * {@link (FunctionExpression:namespace).Parameters} or
31
+ * {@link (FunctionExpression:namespace).TypeParameters} components.
32
+ */
33
+ export declare function FunctionExpression(props: FunctionExpressionProps): Children;
34
+ export declare namespace FunctionExpression {
35
+ var TypeParameters: import("@alloy-js/core").Component<import("./FunctionBase.jsx").TypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<import("./FunctionBase.jsx").TypeParametersProps>, "tag">>;
36
+ var Parameters: import("@alloy-js/core").Component<import("./FunctionBase.jsx").FunctionParametersProps> & Required<Pick<import("@alloy-js/core").Component<import("./FunctionBase.jsx").FunctionParametersProps>, "tag">>;
37
+ var Body: import("@alloy-js/core").Component<import("./FunctionBase.jsx").FunctionBodyProps> & Required<Pick<import("@alloy-js/core").Component<import("./FunctionBase.jsx").FunctionBodyProps>, "tag">>;
38
+ }
39
+ //# sourceMappingURL=FunctionExpression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FunctionExpression.d.ts","sourceRoot":"","sources":["../../../src/components/FunctionExpression.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,OAAO,EAAiB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AASxE,MAAM,WAAW,uBAAwB,SAAQ,kBAAkB;IACjE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,YAiChE;yBAjCe,kBAAkB"}
@@ -0,0 +1,66 @@
1
+ import { createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { childrenArray, findKeyedChild, findUnkeyedChildren, Scope } from "@alloy-js/core";
3
+ import { getCallSignatureProps } from "../utils.js";
4
+ import { CallSignature } from "./CallSignature.js";
5
+ import { Declaration } from "./Declaration.js";
6
+ import { FunctionBody, FunctionParameters, getReturnType, TypeParameters } from "./FunctionBase.js";
7
+ /**
8
+ * A TypeScript function expression.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * <FunctionExpression async parameters={[{ name: "a", type: "number" }, { name: "b", type: "number" }]}>
13
+ * return a + b;
14
+ * <FunctionExpression>
15
+ * ```
16
+ * renders to
17
+ * ```ts
18
+ * async function (a, b) { return a + b; }
19
+ * ```
20
+ * @remarks
21
+ *
22
+ * Providing parameters and type parameters can be accomplished in one of three
23
+ * ways:
24
+ *
25
+ * 1. As an array of {@link ParameterDescriptor}s or
26
+ * {@link TypeParameterDescriptor}s.
27
+ * 2. As raw content via the `parametersChildren` or `typeParametersChildren`
28
+ * props.
29
+ * 3. As a child of this component via the
30
+ * {@link (FunctionExpression:namespace).Parameters} or
31
+ * {@link (FunctionExpression:namespace).TypeParameters} components.
32
+ */
33
+ export function FunctionExpression(props) {
34
+ const children = childrenArray(() => props.children);
35
+ const typeParametersChildren = findKeyedChild(children, TypeParameters.tag) ?? undefined;
36
+ const parametersChildren = findKeyedChild(children, FunctionParameters.tag) ?? undefined;
37
+ const bodyChildren = findKeyedChild(children, FunctionBody.tag) ?? undefined;
38
+ const filteredChildren = findUnkeyedChildren(children);
39
+ const returnType = getReturnType(props.returnType, {
40
+ async: props.async
41
+ });
42
+ const sBody = bodyChildren ?? _$createComponent(FunctionExpression.Body, {
43
+ children: filteredChildren
44
+ });
45
+ const asyncKwd = props.async ? "async " : "";
46
+ const callSignatureProps = getCallSignatureProps(props, {
47
+ parametersChildren,
48
+ typeParametersChildren
49
+ });
50
+ return [_$createComponent(Declaration, _$mergeProps(props, {
51
+ nameKind: "function",
52
+ get children() {
53
+ return [asyncKwd, "function ", _$createComponent(Scope, {
54
+ kind: "function",
55
+ get children() {
56
+ return [_$createComponent(CallSignature, _$mergeProps(callSignatureProps, {
57
+ returnType: returnType
58
+ })), " ", sBody];
59
+ }
60
+ })];
61
+ }
62
+ }))];
63
+ }
64
+ FunctionExpression.TypeParameters = TypeParameters;
65
+ FunctionExpression.Parameters = FunctionParameters;
66
+ FunctionExpression.Body = FunctionBody;
@@ -0,0 +1,39 @@
1
+ import { Children } from "@alloy-js/core/jsx-runtime";
2
+ import { CallSignatureProps } from "./CallSignature.jsx";
3
+ /**
4
+ * Options for {@link (FunctionType:namespace)} component.
5
+ */
6
+ export interface FunctionTypeProps extends CallSignatureProps {
7
+ /** If the method is async */
8
+ readonly async?: boolean;
9
+ /** Documentation for this method. */
10
+ readonly doc?: Children;
11
+ /** Jsx content */
12
+ readonly children?: Children;
13
+ }
14
+ /**
15
+ * A TypeScript function declaration.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * (foo: string, bar: number) => void
20
+ * ```
21
+ * @remarks
22
+ *
23
+ * Providing parameters and type parameters can be accomplished in one of three
24
+ * ways:
25
+ *
26
+ * 1. As an array of {@link TypeParameterDescriptor}s or
27
+ * {@link TypeParameterDescriptor}s.
28
+ * 2. As raw content via the `parametersChildren` or `typeParametersChildren`
29
+ * props.
30
+ * 3. As a child of this component via the
31
+ * {@link (FunctionType:namespace).Parameters} or
32
+ * {@link (FunctionType:namespace).TypeParameters} components.
33
+ */
34
+ export declare function FunctionType(props: FunctionTypeProps): Children;
35
+ export declare namespace FunctionType {
36
+ var TypeParameters: import("@alloy-js/core").Component<import("./FunctionBase.jsx").TypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<import("./FunctionBase.jsx").TypeParametersProps>, "tag">>;
37
+ var Parameters: import("@alloy-js/core").Component<import("./FunctionBase.jsx").FunctionTypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<import("./FunctionBase.jsx").FunctionTypeParametersProps>, "tag">>;
38
+ }
39
+ //# sourceMappingURL=FunctionType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FunctionType.d.ts","sourceRoot":"","sources":["../../../src/components/FunctionType.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,OAAO,EAAiB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAUxE;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,kBAAkB;IAC3D,6BAA6B;IAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,qCAAqC;IACrC,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC;IACxB,kBAAkB;IAClB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,YAiCpD;yBAjCe,YAAY"}
@@ -0,0 +1,73 @@
1
+ import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { childrenArray, findKeyedChild, Prose, Scope, Show } from "@alloy-js/core";
3
+ import { getCallSignatureProps } from "../utils.js";
4
+ import { CallSignature } from "./CallSignature.js";
5
+ import { FunctionParameters, FunctionTypeParameters, getReturnType, TypeParameters } from "./FunctionBase.js";
6
+ import { JSDoc } from "./JSDoc.js";
7
+ import { JSDocParams } from "./JSDocParam.js";
8
+
9
+ /**
10
+ * Options for {@link (FunctionType:namespace)} component.
11
+ */
12
+
13
+ /**
14
+ * A TypeScript function declaration.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * (foo: string, bar: number) => void
19
+ * ```
20
+ * @remarks
21
+ *
22
+ * Providing parameters and type parameters can be accomplished in one of three
23
+ * ways:
24
+ *
25
+ * 1. As an array of {@link TypeParameterDescriptor}s or
26
+ * {@link TypeParameterDescriptor}s.
27
+ * 2. As raw content via the `parametersChildren` or `typeParametersChildren`
28
+ * props.
29
+ * 3. As a child of this component via the
30
+ * {@link (FunctionType:namespace).Parameters} or
31
+ * {@link (FunctionType:namespace).TypeParameters} components.
32
+ */
33
+ export function FunctionType(props) {
34
+ const children = childrenArray(() => props.children);
35
+ const typeParametersChildren = findKeyedChild(children, TypeParameters.tag) ?? undefined;
36
+ const parametersChildren = findKeyedChild(children, FunctionParameters.tag) ?? undefined;
37
+ const returnType = getReturnType(props.returnType ?? "void", {
38
+ async: props.async
39
+ });
40
+ const callSignatureProps = getCallSignatureProps(props, {
41
+ parametersChildren,
42
+ typeParametersChildren
43
+ });
44
+ return [_$createComponent(Show, {
45
+ get when() {
46
+ return Boolean(props.doc);
47
+ },
48
+ get children() {
49
+ return [_$createComponent(JSDoc, {
50
+ get children() {
51
+ return [_$memo(() => _$memo(() => !!props.doc)() && _$createComponent(Prose, {
52
+ get children() {
53
+ return props.doc;
54
+ }
55
+ })), _$memo(() => _$memo(() => !!Array.isArray(props.parameters))() && _$createComponent(JSDocParams, {
56
+ get parameters() {
57
+ return props.parameters;
58
+ }
59
+ }))];
60
+ }
61
+ }), _$createIntrinsic("hbr", {})];
62
+ }
63
+ }), _$createComponent(Scope, {
64
+ kind: "function",
65
+ get children() {
66
+ return [_$createComponent(CallSignature, _$mergeProps(callSignatureProps, {
67
+ returnType: null
68
+ })), " => ", returnType];
69
+ }
70
+ })];
71
+ }
72
+ FunctionType.TypeParameters = TypeParameters;
73
+ FunctionType.Parameters = FunctionTypeParameters;
@@ -1,5 +1,4 @@
1
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
1
+ import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
3
2
  import { Block } from "@alloy-js/core";
4
3
  /**
5
4
  * An if statement.
@@ -30,5 +29,4 @@ export function ElseClause(props) {
30
29
  return props.children;
31
30
  }
32
31
  })];
33
- }
34
- //# sourceMappingURL=IfStatement.js.map
32
+ }
@@ -82,5 +82,4 @@ function ImportBinding(props) {
82
82
  }
83
83
  });
84
84
  return text;
85
- }
86
- //# sourceMappingURL=ImportStatement.js.map
85
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"Interface.d.ts","sourceRoot":"","sources":["../../../src/components/Interface.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAIR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAe,MAAM,kBAAkB,CAAC;AAKrE,MAAM,WAAW,yBAA0B,SAAQ,oBAAoB;IACrE,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,YAiBpE;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,YAElE;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YAwC1D"}
1
+ {"version":3,"file":"Interface.d.ts","sourceRoot":"","sources":["../../../src/components/Interface.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAIR,MAAM,EAKP,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAe,MAAM,kBAAkB,CAAC;AAMrE,MAAM,WAAW,yBAA0B,SAAQ,oBAAoB;IACrE,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,YAiBpE;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,YAiBlE;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YAiD1D"}
@@ -1,11 +1,9 @@
1
- import { mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
- import { createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
3
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
4
- import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
5
- import { Block, MemberDeclaration, Name, OutputSymbolFlags, Show } from "@alloy-js/core";
1
+ import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { Block, MemberScope, Name, OutputSymbolFlags, Show, useMemberDeclaration, useMemberScope, Wrap } from "@alloy-js/core";
6
3
  import { useTSNamePolicy } from "../name-policy.js";
7
4
  import { Declaration } from "./Declaration.js";
8
5
  import { JSDoc } from "./JSDoc.js";
6
+ import { MemberDeclaration } from "./MemberDeclaration.js";
9
7
  import { PropertyName } from "./PropertyName.js";
10
8
  /**
11
9
  * Create a TypeScript interface declaration.
@@ -33,6 +31,7 @@ export function InterfaceDeclaration(props) {
33
31
  }), _$createComponent(Declaration, _$mergeProps(props, {
34
32
  nameKind: "interface",
35
33
  flags: flags,
34
+ kind: "type",
36
35
  get children() {
37
36
  return ["interface ", _$createComponent(Name, {}), extendsPart, " ", _$createComponent(InterfaceExpression, {
38
37
  get children() {
@@ -43,9 +42,26 @@ export function InterfaceDeclaration(props) {
43
42
  }))];
44
43
  }
45
44
  export function InterfaceExpression(props) {
46
- return _$createComponent(Block, {
45
+ const parentMemberSym = useMemberDeclaration();
46
+ if (parentMemberSym) {
47
+ parentMemberSym.binder.addStaticMembersToSymbol(parentMemberSym);
48
+ }
49
+ return _$createIntrinsic("group", {
47
50
  get children() {
48
- return props.children;
51
+ return _$createComponent(Wrap, {
52
+ when: !!parentMemberSym,
53
+ "with": MemberScope,
54
+ props: {
55
+ owner: parentMemberSym
56
+ },
57
+ get children() {
58
+ return _$createComponent(Block, {
59
+ get children() {
60
+ return props.children;
61
+ }
62
+ });
63
+ }
64
+ });
49
65
  }
50
66
  });
51
67
  }
@@ -67,10 +83,16 @@ export function InterfaceMember(props) {
67
83
  } else {
68
84
  const namer = useTSNamePolicy();
69
85
  const name = namer.getName(props.name, "interface-member");
70
- if (props.refkey) {
86
+ const memberScope = useMemberScope();
87
+ if (memberScope) {
71
88
  return _$createComponent(MemberDeclaration, {
72
89
  "static": true,
73
- name: name,
90
+ exactName: name,
91
+ kind: "type",
92
+ nameKind: "interface-member",
93
+ get flags() {
94
+ return OutputSymbolFlags.StaticMember;
95
+ },
74
96
  get refkey() {
75
97
  return props.refkey;
76
98
  },
@@ -106,5 +128,4 @@ export function InterfaceMember(props) {
106
128
  }), optionality, ": ", type];
107
129
  }
108
130
  }
109
- }
110
- //# sourceMappingURL=Interface.js.map
131
+ }
@@ -0,0 +1,43 @@
1
+ import { Refkey } from "@alloy-js/core";
2
+ import { Children } from "@alloy-js/core/jsx-runtime";
3
+ import { CallSignatureProps } from "./CallSignature.jsx";
4
+ /** Props for {@link (InterfaceMethod:namespace)} component */
5
+ export interface InterfaceMethodProps extends CallSignatureProps {
6
+ /** Interface member name */
7
+ readonly name: string;
8
+ /** If the method is async. It will change the returnType from `T` to `Promise<T>` */
9
+ readonly async?: boolean;
10
+ /** Documentation for this method. */
11
+ readonly doc?: Children;
12
+ /** Jsx content */
13
+ readonly children?: Children;
14
+ /** Ref key for the member declaration */
15
+ readonly refkey?: Refkey | Refkey[];
16
+ }
17
+ /**
18
+ * An interface method declaration.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * (foo: string, bar: number) => void
23
+ * ```
24
+ *
25
+ * @remarks
26
+ *
27
+ * Providing parameters and type parameters can be accomplished in one of three
28
+ * ways:
29
+ *
30
+ * 1. As an array of {@link TypeParameterDescriptor}s or
31
+ * {@link TypeParameterDescriptor}s.
32
+ * 2. As raw content via the `parametersChildren` or `typeParametersChildren`
33
+ * props.
34
+ * 3. As a child of this component via the
35
+ * {@link (InterfaceMethod:namespace).Parameters} or
36
+ * {@link (InterfaceMethod:namespace).TypeParameters} components.
37
+ */
38
+ export declare function InterfaceMethod(props: InterfaceMethodProps): Children;
39
+ export declare namespace InterfaceMethod {
40
+ var TypeParameters: import("@alloy-js/core").Component<import("./FunctionBase.jsx").TypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<import("./FunctionBase.jsx").TypeParametersProps>, "tag">>;
41
+ var Parameters: import("@alloy-js/core").Component<import("./FunctionBase.jsx").FunctionTypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<import("./FunctionBase.jsx").FunctionTypeParametersProps>, "tag">>;
42
+ }
43
+ //# sourceMappingURL=InterfaceMethod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InterfaceMethod.d.ts","sourceRoot":"","sources":["../../../src/components/InterfaceMethod.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,MAAM,EAGP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAGtD,OAAO,EAAiB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAUxE,8DAA8D;AAC9D,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC9D,4BAA4B;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qFAAqF;IACrF,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,qCAAqC;IACrC,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC;IACxB,kBAAkB;IAClB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B,yCAAyC;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YAmC1D;yBAnCe,eAAe"}
@@ -0,0 +1,87 @@
1
+ import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { childrenArray, findKeyedChild, MemberDeclaration, Prose, Scope, Show } from "@alloy-js/core";
3
+ import { useTSNamePolicy } from "../name-policy.js";
4
+ import { getCallSignatureProps } from "../utils.js";
5
+ import { CallSignature } from "./CallSignature.js";
6
+ import { FunctionParameters, FunctionTypeParameters, getReturnType, TypeParameters } from "./FunctionBase.js";
7
+ import { JSDoc } from "./JSDoc.js";
8
+ import { JSDocParams } from "./JSDocParam.js";
9
+
10
+ /** Props for {@link (InterfaceMethod:namespace)} component */
11
+
12
+ /**
13
+ * An interface method declaration.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * (foo: string, bar: number) => void
18
+ * ```
19
+ *
20
+ * @remarks
21
+ *
22
+ * Providing parameters and type parameters can be accomplished in one of three
23
+ * ways:
24
+ *
25
+ * 1. As an array of {@link TypeParameterDescriptor}s or
26
+ * {@link TypeParameterDescriptor}s.
27
+ * 2. As raw content via the `parametersChildren` or `typeParametersChildren`
28
+ * props.
29
+ * 3. As a child of this component via the
30
+ * {@link (InterfaceMethod:namespace).Parameters} or
31
+ * {@link (InterfaceMethod:namespace).TypeParameters} components.
32
+ */
33
+ export function InterfaceMethod(props) {
34
+ const children = childrenArray(() => props.children);
35
+ const typeParametersChildren = findKeyedChild(children, TypeParameters.tag) ?? undefined;
36
+ const parametersChildren = findKeyedChild(children, FunctionParameters.tag) ?? undefined;
37
+ const returnType = getReturnType(props.returnType ?? "void", {
38
+ async: props.async
39
+ });
40
+ const callSignatureProps = getCallSignatureProps(props, {
41
+ parametersChildren,
42
+ typeParametersChildren
43
+ });
44
+ const namer = useTSNamePolicy();
45
+ const name = namer.getName(props.name, "interface-member");
46
+ return [_$createComponent(Show, {
47
+ get when() {
48
+ return Boolean(props.doc);
49
+ },
50
+ get children() {
51
+ return [_$createComponent(JSDoc, {
52
+ get children() {
53
+ return [_$memo(() => _$memo(() => !!props.doc)() && _$createComponent(Prose, {
54
+ get children() {
55
+ return props.doc;
56
+ }
57
+ })), _$memo(() => _$memo(() => !!Array.isArray(props.parameters))() && _$createComponent(JSDocParams, {
58
+ get parameters() {
59
+ return props.parameters;
60
+ }
61
+ }))];
62
+ }
63
+ }), _$createIntrinsic("hbr", {})];
64
+ }
65
+ }), _$createComponent(MemberDeclaration, _$mergeProps({
66
+ "static": true
67
+ }, props, {
68
+ get refkey() {
69
+ return props.refkey;
70
+ },
71
+ get children() {
72
+ return [name, _$createComponent(Scope, {
73
+ get name() {
74
+ return props.name;
75
+ },
76
+ kind: "function",
77
+ get children() {
78
+ return _$createComponent(CallSignature, _$mergeProps(callSignatureProps, {
79
+ returnType: returnType
80
+ }));
81
+ }
82
+ })];
83
+ }
84
+ }))];
85
+ }
86
+ InterfaceMethod.TypeParameters = TypeParameters;
87
+ InterfaceMethod.Parameters = FunctionTypeParameters;
@@ -16,5 +16,4 @@ export function JSDoc(props) {
16
16
  });
17
17
  }
18
18
  });
19
- }
20
- //# sourceMappingURL=JSDoc.js.map
19
+ }