@alloy-js/typescript 0.6.0 → 0.8.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 (230) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/src/components/ArrayExpression.d.ts.map +1 -1
  3. package/dist/src/components/ArrayExpression.js +9 -3
  4. package/dist/src/components/ArrayExpression.js.map +1 -1
  5. package/dist/src/components/BlockScope.d.ts +13 -0
  6. package/dist/src/components/BlockScope.d.ts.map +1 -0
  7. package/dist/src/components/BlockScope.js +20 -0
  8. package/dist/src/components/BlockScope.js.map +1 -0
  9. package/dist/src/components/CallSignature.d.ts +38 -0
  10. package/dist/src/components/CallSignature.d.ts.map +1 -0
  11. package/dist/src/components/CallSignature.js +26 -0
  12. package/dist/src/components/CallSignature.js.map +1 -0
  13. package/dist/src/components/ClassDeclaration.d.ts +3 -4
  14. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  15. package/dist/src/components/ClassDeclaration.js +99 -41
  16. package/dist/src/components/ClassDeclaration.js.map +1 -1
  17. package/dist/src/components/Declaration.d.ts +21 -4
  18. package/dist/src/components/Declaration.d.ts.map +1 -1
  19. package/dist/src/components/Declaration.js +40 -21
  20. package/dist/src/components/Declaration.js.map +1 -1
  21. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  22. package/dist/src/components/EnumDeclaration.js +19 -6
  23. package/dist/src/components/EnumDeclaration.js.map +1 -1
  24. package/dist/src/components/EnumMember.d.ts +8 -0
  25. package/dist/src/components/EnumMember.d.ts.map +1 -1
  26. package/dist/src/components/EnumMember.js +27 -5
  27. package/dist/src/components/EnumMember.js.map +1 -1
  28. package/dist/src/components/ExportStatement.d.ts.map +1 -1
  29. package/dist/src/components/ExportStatement.js +3 -1
  30. package/dist/src/components/ExportStatement.js.map +1 -1
  31. package/dist/src/components/FunctionCallExpression.js +1 -1
  32. package/dist/src/components/FunctionCallExpression.js.map +1 -1
  33. package/dist/src/components/FunctionDeclaration.d.ts +21 -12
  34. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  35. package/dist/src/components/FunctionDeclaration.js +80 -45
  36. package/dist/src/components/FunctionDeclaration.js.map +1 -1
  37. package/dist/src/components/IfStatement.d.ts +25 -0
  38. package/dist/src/components/IfStatement.d.ts.map +1 -0
  39. package/dist/src/components/IfStatement.js +34 -0
  40. package/dist/src/components/IfStatement.js.map +1 -0
  41. package/dist/src/components/Interface.d.ts +10 -2
  42. package/dist/src/components/Interface.d.ts.map +1 -1
  43. package/dist/src/components/Interface.js +66 -6
  44. package/dist/src/components/Interface.js.map +1 -1
  45. package/dist/src/components/JSDoc.d.ts.map +1 -1
  46. package/dist/src/components/JSDoc.js +1 -5
  47. package/dist/src/components/JSDoc.js.map +1 -1
  48. package/dist/src/components/JSDocParam.d.ts +22 -0
  49. package/dist/src/components/JSDocParam.d.ts.map +1 -0
  50. package/dist/src/components/JSDocParam.js +121 -0
  51. package/dist/src/components/JSDocParam.js.map +1 -0
  52. package/dist/src/components/MemberChainExpression.d.ts +2 -2
  53. package/dist/src/components/MemberChainExpression.d.ts.map +1 -1
  54. package/dist/src/components/MemberChainExpression.js +43 -7
  55. package/dist/src/components/MemberChainExpression.js.map +1 -1
  56. package/dist/src/components/ObjectExpression.d.ts.map +1 -1
  57. package/dist/src/components/ObjectExpression.js +9 -2
  58. package/dist/src/components/ObjectExpression.js.map +1 -1
  59. package/dist/src/components/PackageDirectory.d.ts +1 -3
  60. package/dist/src/components/PackageDirectory.d.ts.map +1 -1
  61. package/dist/src/components/PackageDirectory.js +9 -16
  62. package/dist/src/components/PackageDirectory.js.map +1 -1
  63. package/dist/src/components/PackageJson.d.ts +39 -0
  64. package/dist/src/components/PackageJson.d.ts.map +1 -1
  65. package/dist/src/components/PackageJson.js +30 -12
  66. package/dist/src/components/PackageJson.js.map +1 -1
  67. package/dist/src/components/PropertyName.d.ts +19 -0
  68. package/dist/src/components/PropertyName.d.ts.map +1 -0
  69. package/dist/src/components/PropertyName.js +36 -0
  70. package/dist/src/components/PropertyName.js.map +1 -0
  71. package/dist/src/components/SingleLineCommentBlock.d.ts +10 -0
  72. package/dist/src/components/SingleLineCommentBlock.d.ts.map +1 -0
  73. package/dist/src/components/SingleLineCommentBlock.js +20 -0
  74. package/dist/src/components/SingleLineCommentBlock.js.map +1 -0
  75. package/dist/src/components/SourceFile.d.ts +6 -0
  76. package/dist/src/components/SourceFile.d.ts.map +1 -1
  77. package/dist/src/components/SourceFile.js +31 -0
  78. package/dist/src/components/SourceFile.js.map +1 -1
  79. package/dist/src/components/SwitchStatement.d.ts +31 -0
  80. package/dist/src/components/SwitchStatement.d.ts.map +1 -0
  81. package/dist/src/components/SwitchStatement.js +48 -0
  82. package/dist/src/components/SwitchStatement.js.map +1 -0
  83. package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
  84. package/dist/src/components/TypeDeclaration.js +16 -3
  85. package/dist/src/components/TypeDeclaration.js.map +1 -1
  86. package/dist/src/components/VarDeclaration.d.ts +1 -1
  87. package/dist/src/components/VarDeclaration.d.ts.map +1 -1
  88. package/dist/src/components/VarDeclaration.js +20 -6
  89. package/dist/src/components/VarDeclaration.js.map +1 -1
  90. package/dist/src/components/index.d.ts +7 -0
  91. package/dist/src/components/index.d.ts.map +1 -1
  92. package/dist/src/components/index.js +7 -0
  93. package/dist/src/components/index.js.map +1 -1
  94. package/dist/src/components/stc/index.d.ts +35 -112
  95. package/dist/src/components/stc/index.d.ts.map +1 -1
  96. package/dist/src/components/stc/index.js +8 -1
  97. package/dist/src/components/stc/index.js.map +1 -1
  98. package/dist/src/context/index.d.ts +2 -0
  99. package/dist/src/context/index.d.ts.map +1 -0
  100. package/dist/src/context/index.js +1 -0
  101. package/dist/src/context/index.js.map +1 -0
  102. package/dist/src/context/private-scope.d.ts +18 -0
  103. package/dist/src/context/private-scope.d.ts.map +1 -0
  104. package/dist/src/context/private-scope.js +9 -0
  105. package/dist/src/context/private-scope.js.map +1 -0
  106. package/dist/src/index.d.ts +1 -0
  107. package/dist/src/index.d.ts.map +1 -1
  108. package/dist/src/index.js +1 -0
  109. package/dist/src/index.js.map +1 -1
  110. package/dist/src/parameter-descriptor.d.ts +60 -0
  111. package/dist/src/parameter-descriptor.d.ts.map +1 -0
  112. package/dist/src/parameter-descriptor.js +1 -0
  113. package/dist/src/parameter-descriptor.js.map +1 -0
  114. package/dist/src/symbols/reference.d.ts.map +1 -1
  115. package/dist/src/symbols/reference.js +55 -14
  116. package/dist/src/symbols/reference.js.map +1 -1
  117. package/dist/src/symbols/ts-member-scope.d.ts +1 -1
  118. package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
  119. package/dist/src/symbols/ts-member-scope.js +2 -0
  120. package/dist/src/symbols/ts-member-scope.js.map +1 -1
  121. package/dist/src/symbols/ts-output-symbol.d.ts +7 -3
  122. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
  123. package/dist/src/symbols/ts-output-symbol.js +14 -2
  124. package/dist/src/symbols/ts-output-symbol.js.map +1 -1
  125. package/dist/src/symbols/ts-package-scope.d.ts +0 -15
  126. package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
  127. package/dist/src/symbols/ts-package-scope.js +0 -8
  128. package/dist/src/symbols/ts-package-scope.js.map +1 -1
  129. package/dist/src/utils.d.ts +7 -0
  130. package/dist/src/utils.d.ts.map +1 -1
  131. package/dist/src/utils.js +17 -0
  132. package/dist/src/utils.js.map +1 -1
  133. package/dist/test/block-scope.test.d.ts +2 -0
  134. package/dist/test/block-scope.test.d.ts.map +1 -0
  135. package/dist/test/enum-jsdoc.test.d.ts +2 -0
  136. package/dist/test/enum-jsdoc.test.d.ts.map +1 -0
  137. package/dist/test/function-declaration-jsdoc.test.d.ts +2 -0
  138. package/dist/test/function-declaration-jsdoc.test.d.ts.map +1 -0
  139. package/dist/test/if-statement.test.d.ts +2 -0
  140. package/dist/test/if-statement.test.d.ts.map +1 -0
  141. package/dist/test/interface-jsdoc.test.d.ts +2 -0
  142. package/dist/test/interface-jsdoc.test.d.ts.map +1 -0
  143. package/dist/test/jscomment.test.d.ts +2 -0
  144. package/dist/test/jscomment.test.d.ts.map +1 -0
  145. package/dist/test/jsdoc.test.d.ts.map +1 -1
  146. package/dist/test/jsdocparam.test.d.ts +2 -0
  147. package/dist/test/jsdocparam.test.d.ts.map +1 -0
  148. package/dist/test/name-conflict.test.d.ts +2 -0
  149. package/dist/test/name-conflict.test.d.ts.map +1 -0
  150. package/dist/test/package-json.test.d.ts +2 -0
  151. package/dist/test/package-json.test.d.ts.map +1 -0
  152. package/dist/test/source-file.test.d.ts +2 -0
  153. package/dist/test/source-file.test.d.ts.map +1 -0
  154. package/dist/test/switch-statement.test.d.ts +2 -0
  155. package/dist/test/switch-statement.test.d.ts.map +1 -0
  156. package/dist/test/var-declaration-jsdoc.test.d.ts +2 -0
  157. package/dist/test/var-declaration-jsdoc.test.d.ts.map +1 -0
  158. package/dist/tsconfig.tsbuildinfo +1 -1
  159. package/package.json +3 -3
  160. package/src/components/ArrayExpression.tsx +13 -8
  161. package/src/components/BlockScope.tsx +31 -0
  162. package/src/components/CallSignature.tsx +67 -0
  163. package/src/components/ClassDeclaration.tsx +103 -50
  164. package/src/components/Declaration.tsx +72 -22
  165. package/src/components/EnumDeclaration.tsx +27 -19
  166. package/src/components/EnumMember.tsx +24 -4
  167. package/src/components/ExportStatement.tsx +3 -1
  168. package/src/components/FunctionCallExpression.tsx +1 -1
  169. package/src/components/FunctionDeclaration.tsx +107 -81
  170. package/src/components/IfStatement.tsx +51 -0
  171. package/src/components/Interface.tsx +61 -14
  172. package/src/components/JSDoc.tsx +1 -10
  173. package/src/components/JSDocParam.tsx +115 -0
  174. package/src/components/MemberChainExpression.tsx +37 -5
  175. package/src/components/ObjectExpression.tsx +7 -2
  176. package/src/components/PackageDirectory.tsx +12 -22
  177. package/src/components/PackageJson.tsx +86 -27
  178. package/src/components/PropertyName.tsx +50 -0
  179. package/src/components/SingleLineCommentBlock.tsx +21 -0
  180. package/src/components/SourceFile.tsx +29 -0
  181. package/src/components/SwitchStatement.tsx +78 -0
  182. package/src/components/TypeDeclaration.tsx +11 -4
  183. package/src/components/VarDeclaration.tsx +20 -12
  184. package/src/components/index.ts +7 -0
  185. package/src/components/stc/index.ts +8 -1
  186. package/src/context/index.ts +1 -0
  187. package/src/context/private-scope.ts +23 -0
  188. package/src/index.ts +1 -0
  189. package/src/parameter-descriptor.ts +71 -0
  190. package/src/symbols/reference.ts +77 -22
  191. package/src/symbols/ts-member-scope.ts +6 -2
  192. package/src/symbols/ts-output-symbol.ts +27 -10
  193. package/src/symbols/ts-package-scope.ts +0 -28
  194. package/src/utils.ts +33 -0
  195. package/temp/api.json +5372 -3410
  196. package/test/array.test.tsx +72 -0
  197. package/test/basic.test.tsx +2 -2
  198. package/test/block-scope.test.tsx +29 -0
  199. package/test/class.test.tsx +173 -5
  200. package/test/enum-jsdoc.test.tsx +74 -0
  201. package/test/enum.test.tsx +50 -3
  202. package/test/function-call-expression.test.tsx +5 -2
  203. package/test/function-declaration-jsdoc.test.tsx +89 -0
  204. package/test/function-declaration.test.tsx +13 -9
  205. package/test/if-statement.test.tsx +28 -0
  206. package/test/imports.test.tsx +25 -10
  207. package/test/interface-jsdoc.test.tsx +164 -0
  208. package/test/interface.test.tsx +17 -3
  209. package/test/jscomment.test.tsx +104 -0
  210. package/test/jsdoc.test.tsx +9 -15
  211. package/test/jsdocparam.test.tsx +188 -0
  212. package/test/member-chain.test.tsx +77 -0
  213. package/test/name-conflict.test.tsx +105 -0
  214. package/test/name-policy.test.tsx +1 -1
  215. package/test/package-external.test.tsx +98 -3
  216. package/test/package-json.test.tsx +93 -0
  217. package/test/package.test.tsx +56 -3
  218. package/test/reference.test.tsx +6 -2
  219. package/test/source-file.test.tsx +38 -0
  220. package/test/switch-statement.test.tsx +50 -0
  221. package/test/value-expression.test.tsx +9 -0
  222. package/test/var-declaration-jsdoc.test.tsx +70 -0
  223. package/test/var-declaration.test.tsx +1 -1
  224. package/tsconfig.json +1 -8
  225. package/vitest.config.ts +2 -10
  226. package/dist/src/components/JSDocParagraph.d.ts +0 -10
  227. package/dist/src/components/JSDocParagraph.d.ts.map +0 -1
  228. package/dist/src/components/JSDocParagraph.js +0 -23
  229. package/dist/src/components/JSDocParagraph.js.map +0 -1
  230. package/src/components/JSDocParagraph.tsx +0 -35
@@ -2,11 +2,8 @@ import { Props, refkey } from "@alloy-js/core";
2
2
  import { d } from "@alloy-js/core/testing";
3
3
  import { describe, expect, it } from "vitest";
4
4
  import { StatementList } from "../../core/src/components/StatementList.jsx";
5
- import {
6
- FunctionDeclaration,
7
- ParameterDescriptor,
8
- VarDeclaration,
9
- } from "../src/index.js";
5
+ import { FunctionDeclaration, VarDeclaration } from "../src/index.js";
6
+ import { ParameterDescriptor } from "../src/parameter-descriptor.js";
10
7
  import { toSourceText } from "./utils.js";
11
8
 
12
9
  it("works", () => {
@@ -76,7 +73,10 @@ it("supports type parameters by descriptor object", () => {
76
73
  const decl = (
77
74
  <FunctionDeclaration
78
75
  name="foo"
79
- typeParameters={{ a: "any", b: "any" }}
76
+ typeParameters={[
77
+ { name: "a", extends: "any" },
78
+ { name: "b", extends: "any" },
79
+ ]}
80
80
  ></FunctionDeclaration>
81
81
  );
82
82
 
@@ -164,7 +164,7 @@ describe("symbols", () => {
164
164
  <>
165
165
  <FunctionDeclaration
166
166
  name="foo"
167
- parameters={{ sym: { type: "any", refkey: rk } }}
167
+ parameters={[{ name: "sym", type: "any", refkey: rk }]}
168
168
  >
169
169
  <FunctionDeclaration name="bar">{rk}</FunctionDeclaration>
170
170
  </FunctionDeclaration>
@@ -183,7 +183,10 @@ describe("symbols", () => {
183
183
  it("creates symbols for parameters and addresses conflicts", () => {
184
184
  const decl = (
185
185
  <>
186
- <FunctionDeclaration name="foo" parameters={{ conflict: "any" }}>
186
+ <FunctionDeclaration
187
+ name="foo"
188
+ parameters={[{ name: "conflict", type: "any" }]}
189
+ >
187
190
  <VarDeclaration name="conflict">1</VarDeclaration>;
188
191
  </FunctionDeclaration>
189
192
  </>
@@ -198,13 +201,14 @@ describe("symbols", () => {
198
201
 
199
202
  it("create optional parameters", () => {
200
203
  const paramDesc: ParameterDescriptor = {
204
+ name: "foo",
201
205
  refkey: refkey(),
202
206
  type: "any",
203
207
  optional: true,
204
208
  };
205
209
  const decl = (
206
210
  <>
207
- <FunctionDeclaration name="foo" parameters={{ foo: paramDesc }}>
211
+ <FunctionDeclaration name="foo" parameters={[paramDesc]}>
208
212
  console.log(foo);
209
213
  </FunctionDeclaration>
210
214
  </>
@@ -0,0 +1,28 @@
1
+ import { d } from "@alloy-js/core/testing";
2
+ import { expect, it } from "vitest";
3
+ import {
4
+ ElseClause,
5
+ ElseIfClause,
6
+ IfStatement,
7
+ } from "../src/components/IfStatement.jsx";
8
+ import { toSourceText } from "./utils.jsx";
9
+
10
+ it("works with blocks", () => {
11
+ const text = toSourceText(
12
+ <>
13
+ <IfStatement condition="x === 1">// do thing</IfStatement>
14
+ <ElseIfClause condition="x === 2">// do another thing</ElseIfClause>
15
+ <ElseClause>// do default thing</ElseClause>
16
+ </>,
17
+ );
18
+
19
+ expect(text).toBe(d`
20
+ if (x === 1) {
21
+ // do thing
22
+ } else if (x === 2) {
23
+ // do another thing
24
+ } else {
25
+ // do default thing
26
+ }
27
+ `);
28
+ });
@@ -46,7 +46,7 @@ it("works with named imports", () => {
46
46
  const res = render(
47
47
  <Output>
48
48
  <ts.SourceFile path="test1.ts">
49
- <ts.FunctionDeclaration export name="test" />
49
+ <ts.FunctionDeclaration export name="test" refkey={refkey("test")} />
50
50
  </ts.SourceFile>
51
51
 
52
52
  <ts.SourceFile path="test2.ts">
@@ -71,9 +71,14 @@ it("works with default and named imports", () => {
71
71
  const res = render(
72
72
  <Output>
73
73
  <ts.SourceFile path="test1.ts">
74
- <ts.FunctionDeclaration export default name="test1" />
74
+ <ts.FunctionDeclaration
75
+ export
76
+ default
77
+ name="test1"
78
+ refkey={refkey("test1")}
79
+ />
75
80
  <hbr />
76
- <ts.FunctionDeclaration export name="test2" />
81
+ <ts.FunctionDeclaration export name="test2" refkey={refkey("test2")} />
77
82
  </ts.SourceFile>
78
83
 
79
84
  <ts.SourceFile path="test2.ts">
@@ -101,9 +106,14 @@ it("works with default and named imports and name conflicts", () => {
101
106
  const res = render(
102
107
  <Output nameConflictResolver={tsNameConflictResolver}>
103
108
  <ts.SourceFile path="test1.ts">
104
- <ts.FunctionDeclaration export default name="test1" />
109
+ <ts.FunctionDeclaration
110
+ export
111
+ default
112
+ name="test1"
113
+ refkey={refkey("test1")}
114
+ />
105
115
  <br />
106
- <ts.FunctionDeclaration export name="test2" />
116
+ <ts.FunctionDeclaration export name="test2" refkey={refkey("test2")} />
107
117
  </ts.SourceFile>
108
118
 
109
119
  <ts.SourceFile path="test2.ts">
@@ -165,9 +175,14 @@ it("works with default and named imports and name conflicts and references in ne
165
175
  const res = render(
166
176
  <Output nameConflictResolver={tsNameConflictResolver}>
167
177
  <ts.SourceFile path="test1.ts">
168
- <ts.FunctionDeclaration export default name="test1" />
178
+ <ts.FunctionDeclaration
179
+ export
180
+ default
181
+ name="test1"
182
+ refkey={refkey("test1")}
183
+ />
169
184
  <hbr />
170
- <ts.FunctionDeclaration export name="test2" />
185
+ <ts.FunctionDeclaration export name="test2" refkey={refkey("test2")} />
171
186
  </ts.SourceFile>
172
187
 
173
188
  <ts.SourceFile path="test2.ts">
@@ -237,7 +252,7 @@ it("works with imports from different directories", () => {
237
252
  <Output>
238
253
  <SourceDirectory path="src">
239
254
  <ts.SourceFile path="test1.ts">
240
- <ts.FunctionDeclaration export name="test" />
255
+ <ts.FunctionDeclaration export name="test" refkey={refkey("test")} />
241
256
  <hbr />
242
257
  const v = <Reference refkey={refkey("test2")} />;
243
258
  </ts.SourceFile>
@@ -245,7 +260,7 @@ it("works with imports from different directories", () => {
245
260
 
246
261
  <ts.SourceFile path="test2.ts">
247
262
  const v = <Reference refkey={refkey("test")} />;<hbr />
248
- <ts.FunctionDeclaration export name="test2" />
263
+ <ts.FunctionDeclaration export name="test2" refkey={refkey("test2")} />
249
264
  </ts.SourceFile>
250
265
  </Output>,
251
266
  );
@@ -271,7 +286,7 @@ it("handles conflicts with local declarations", () => {
271
286
  <Output nameConflictResolver={tsNameConflictResolver}>
272
287
  <SourceDirectory path="src">
273
288
  <ts.SourceFile path="test1.ts">
274
- <ts.FunctionDeclaration export name="test" />
289
+ <ts.FunctionDeclaration export name="test" refkey={refkey("test")} />
275
290
  <hbr />
276
291
  const v = <Reference refkey={refkey("test2")} />;
277
292
  </ts.SourceFile>
@@ -0,0 +1,164 @@
1
+ import { StatementList } from "@alloy-js/core";
2
+ import { d } from "@alloy-js/core/testing";
3
+ import { expect, it } from "vitest";
4
+ import * as ts from "../src/index.js";
5
+ import { toSourceText } from "./utils.js";
6
+
7
+ it("renders an interface declaration with documentation", () => {
8
+ const res = toSourceText(
9
+ <ts.InterfaceDeclaration
10
+ name="Person"
11
+ doc="Interface representing a person"
12
+ >
13
+ <StatementList>
14
+ <ts.InterfaceMember name="name" type="string" />
15
+ <ts.InterfaceMember name="age" type="number" />
16
+ </StatementList>
17
+ </ts.InterfaceDeclaration>,
18
+ );
19
+ expect(res).toEqual(d`
20
+ /**
21
+ * Interface representing a person
22
+ **/
23
+ interface Person {
24
+ name: string;
25
+ age: number;
26
+ }
27
+ `);
28
+ });
29
+
30
+ it("renders an interface declaration with docs from a string array with single element", () => {
31
+ const res = toSourceText(
32
+ <ts.InterfaceDeclaration
33
+ name="Person"
34
+ doc={["Interface representing a person"]}
35
+ >
36
+ <StatementList>
37
+ <ts.InterfaceMember name="name" type="string" />
38
+ <ts.InterfaceMember name="age" type="number" />
39
+ </StatementList>
40
+ </ts.InterfaceDeclaration>,
41
+ );
42
+ expect(res).toEqual(d`
43
+ /**
44
+ * Interface representing a person
45
+ **/
46
+ interface Person {
47
+ name: string;
48
+ age: number;
49
+ }
50
+ `);
51
+ });
52
+
53
+ it("renders an interface declaration with docs from a string array", () => {
54
+ const res = toSourceText(
55
+ <ts.InterfaceDeclaration
56
+ name="Person"
57
+ doc={[
58
+ "Interface representing a person",
59
+ "This should be another paragraph",
60
+ ]}
61
+ >
62
+ <StatementList>
63
+ <ts.InterfaceMember name="name" type="string" />
64
+ <ts.InterfaceMember name="age" type="number" />
65
+ </StatementList>
66
+ </ts.InterfaceDeclaration>,
67
+ );
68
+ expect(res).toEqual(d`
69
+ /**
70
+ * Interface representing a person
71
+ *
72
+ * This should be another paragraph
73
+ **/
74
+ interface Person {
75
+ name: string;
76
+ age: number;
77
+ }
78
+ `);
79
+ });
80
+
81
+ it("renders an interface declaration with documented properties", () => {
82
+ const res = toSourceText(
83
+ <ts.InterfaceDeclaration
84
+ export
85
+ name="APIResponse"
86
+ doc="Standard API response format"
87
+ >
88
+ <StatementList>
89
+ <ts.InterfaceMember
90
+ name="success"
91
+ type="boolean"
92
+ doc="Wether or not the request completed successfully"
93
+ />
94
+ <ts.InterfaceMember
95
+ name="data"
96
+ type="unknown"
97
+ doc="the response payload"
98
+ />
99
+ <ts.InterfaceMember name="error" optional type="string" />
100
+ </StatementList>
101
+ </ts.InterfaceDeclaration>,
102
+ );
103
+ expect(res).toEqual(d`
104
+ /**
105
+ * Standard API response format
106
+ **/
107
+ export interface APIResponse {
108
+ /**
109
+ * Wether or not the request completed successfully
110
+ **/
111
+ success: boolean;
112
+ /**
113
+ * the response payload
114
+ **/
115
+ data: unknown;
116
+ error?: string;
117
+ }
118
+ `);
119
+ });
120
+
121
+ it("renders an interface declaration with array documented properties ", () => {
122
+ const res = toSourceText(
123
+ <ts.InterfaceDeclaration
124
+ export
125
+ name="APIResponse"
126
+ doc="Standard API response format"
127
+ >
128
+ <StatementList>
129
+ <ts.InterfaceMember
130
+ name="success"
131
+ type="boolean"
132
+ doc={[
133
+ "Wether or not the request completed successfully",
134
+ "This is another paragraph",
135
+ ]}
136
+ />
137
+ <ts.InterfaceMember
138
+ name="data"
139
+ type="unknown"
140
+ doc="the response payload"
141
+ />
142
+ <ts.InterfaceMember name="error" optional type="string" />
143
+ </StatementList>
144
+ </ts.InterfaceDeclaration>,
145
+ );
146
+ expect(res).toEqual(d`
147
+ /**
148
+ * Standard API response format
149
+ **/
150
+ export interface APIResponse {
151
+ /**
152
+ * Wether or not the request completed successfully
153
+ *
154
+ * This is another paragraph
155
+ **/
156
+ success: boolean;
157
+ /**
158
+ * the response payload
159
+ **/
160
+ data: unknown;
161
+ error?: string;
162
+ }
163
+ `);
164
+ });
@@ -35,7 +35,7 @@ it("creates extends", () => {
35
35
 
36
36
  it("can create members", () => {
37
37
  const res = toSourceText(
38
- <ts.InterfaceDeclaration name="Foo">
38
+ <ts.InterfaceDeclaration name="Foo" refkey={refkey("Foo")}>
39
39
  <StatementList>
40
40
  <ts.InterfaceMember name="member" type="string" />
41
41
  <ts.InterfaceMember
@@ -58,7 +58,7 @@ it("can create members", () => {
58
58
 
59
59
  it("can create optional members", () => {
60
60
  const res = toSourceText(
61
- <ts.InterfaceDeclaration name="Foo">
61
+ <ts.InterfaceDeclaration name="Foo" refkey={refkey("Foo")}>
62
62
  <StatementList>
63
63
  <ts.InterfaceMember name="member" type="string" />
64
64
  <ts.InterfaceMember
@@ -82,7 +82,7 @@ it("can create optional members", () => {
82
82
 
83
83
  it("can create readonly members", () => {
84
84
  const res = toSourceText(
85
- <ts.InterfaceDeclaration name="Foo">
85
+ <ts.InterfaceDeclaration name="Foo" refkey={refkey("Foo")}>
86
86
  <StatementList>
87
87
  <ts.InterfaceMember readonly name="member" type="string" />
88
88
  <ts.InterfaceMember
@@ -132,3 +132,17 @@ it("supports the naming policy", () => {
132
132
  }
133
133
  `);
134
134
  });
135
+
136
+ it("handles invalid identifier names", () => {
137
+ const res = toSourceText(
138
+ <ts.InterfaceExpression>
139
+ <ts.InterfaceMember name="invalid-name" type="string" />;
140
+ </ts.InterfaceExpression>,
141
+ );
142
+
143
+ expect(res).toEqual(d`
144
+ {
145
+ "invalid-name": string;
146
+ }
147
+ `);
148
+ });
@@ -0,0 +1,104 @@
1
+ import { List } from "@alloy-js/core";
2
+ import "@alloy-js/core/testing";
3
+ import { d } from "@alloy-js/core/testing";
4
+ import { describe, expect, it } from "vitest";
5
+ import { SingleLineCommentBlock } from "../src/components/SingleLineCommentBlock.jsx";
6
+
7
+ describe("JSComment", () => {
8
+ it("formats properly a simple comment", () => {
9
+ const template = (
10
+ <>
11
+ <SingleLineCommentBlock>Hello!</SingleLineCommentBlock>
12
+ <hbr />
13
+ Should not be part of the comment
14
+ </>
15
+ );
16
+
17
+ expect(template).toRenderTo(
18
+ d`
19
+ // Hello!
20
+ Should not be part of the comment
21
+ `,
22
+ { printWidth: 40 },
23
+ );
24
+ });
25
+
26
+ it("should not add extra line breaks", () => {
27
+ const template = (
28
+ <>
29
+ <List hardline>
30
+ <SingleLineCommentBlock>
31
+ Hello!
32
+ <hbr />
33
+ <hbr />
34
+ This is another line
35
+ </SingleLineCommentBlock>
36
+ </List>
37
+ <hbr />
38
+ Hello
39
+ </>
40
+ );
41
+
42
+ expect(template).toRenderTo(
43
+ d`
44
+ // Hello!
45
+ //
46
+ // This is another line
47
+ Hello
48
+ `,
49
+ { printWidth: 40 },
50
+ );
51
+ });
52
+
53
+ it("formats properly multiple children", () => {
54
+ const template = (
55
+ <>
56
+ <SingleLineCommentBlock>
57
+ Hello!
58
+ <hbr />
59
+ <hbr />
60
+ This is another line
61
+ </SingleLineCommentBlock>
62
+ <hbr />
63
+ foo should be outside the comment
64
+ </>
65
+ );
66
+
67
+ expect(template).toRenderTo(
68
+ d`
69
+ // Hello!
70
+ //
71
+ // This is another line
72
+ foo should be outside the comment
73
+ `,
74
+ { printWidth: 40 },
75
+ );
76
+ });
77
+
78
+ it("It correctly do word wrapping", () => {
79
+ const template = (
80
+ <>
81
+ <SingleLineCommentBlock>
82
+ This is a very long line that should be broken into multiple lines. It
83
+ should also be aligned properly. The line breaks in this paragraph
84
+ should not be carried over into the JSDoc comment.
85
+ </SingleLineCommentBlock>
86
+ <hbr />
87
+ <>This should not be part of the comment</>
88
+ </>
89
+ );
90
+
91
+ expect(template).toRenderTo(
92
+ d`
93
+ // This is a very long line that should
94
+ // be broken into multiple lines. It
95
+ // should also be aligned properly. The
96
+ // line breaks in this paragraph should
97
+ // not be carried over into the JSDoc
98
+ // comment.
99
+ This should not be part of the comment
100
+ `,
101
+ { printWidth: 40 },
102
+ );
103
+ });
104
+ });
@@ -1,10 +1,10 @@
1
+ import { Prose } from "@alloy-js/core";
1
2
  import "@alloy-js/core/testing";
2
3
  import { d } from "@alloy-js/core/testing";
3
4
  import { describe, expect, it } from "vitest";
4
5
  import { JSDoc } from "../src/components/JSDoc.jsx";
5
6
  import { JSDocComment } from "../src/components/JSDocComment.jsx";
6
7
  import { JSDocExample } from "../src/components/JSDocExample.jsx";
7
- import { JSDocParagraph } from "../src/components/JSDocParagraph.jsx";
8
8
  import { FunctionCallExpression } from "../src/index.js";
9
9
 
10
10
  describe("JSDoc", () => {
@@ -31,19 +31,19 @@ describe("JSDoc", () => {
31
31
  });
32
32
  });
33
33
 
34
- describe("JSDocParagraph", () => {
34
+ describe("Prose", () => {
35
35
  it("formats properly", () => {
36
36
  const template = (
37
37
  <JSDoc>
38
- <JSDocParagraph>
38
+ <Prose>
39
39
  This is a long paragraph that should end up being broken into multiple
40
40
  paragraphs. Moreover, the line breaks in this paragraph should not be
41
41
  carried over into the JSDoc comment.
42
- </JSDocParagraph>
43
- <JSDocParagraph>
42
+ </Prose>
43
+ <Prose>
44
44
  This is another paragraph. There should be a couple breaks in front of
45
45
  it.
46
- </JSDocParagraph>
46
+ </Prose>
47
47
  </JSDoc>
48
48
  );
49
49
 
@@ -70,9 +70,7 @@ describe("JSDocExample", () => {
70
70
  it("creates unfenced code samples", () => {
71
71
  const template = (
72
72
  <JSDoc>
73
- <JSDocParagraph>
74
- This API is awesome, and it comes with an example!
75
- </JSDocParagraph>
73
+ <Prose>This API is awesome, and it comes with an example!</Prose>
76
74
  <JSDocExample>console.log("Hello world!")</JSDocExample>
77
75
  </JSDoc>
78
76
  );
@@ -94,9 +92,7 @@ describe("JSDocExample", () => {
94
92
  it("creates fenced code samples", () => {
95
93
  const template = (
96
94
  <JSDoc>
97
- <JSDocParagraph>
98
- This API is awesome, and it comes with an example!
99
- </JSDocParagraph>
95
+ <Prose>This API is awesome, and it comes with an example!</Prose>
100
96
  <JSDocExample fenced language="ts">
101
97
  console.log("Hello world!")
102
98
  </JSDocExample>
@@ -122,9 +118,7 @@ describe("JSDocExample", () => {
122
118
  it("creates code samples using other components", () => {
123
119
  const template = (
124
120
  <JSDoc>
125
- <JSDocParagraph>
126
- This API is awesome, and it comes with an example!
127
- </JSDocParagraph>
121
+ <Prose>This API is awesome, and it comes with an example!</Prose>
128
122
  <JSDocExample language="ts">
129
123
  // make a function call.
130
124
  <hbr />