@alloy-js/typescript 0.7.0 → 0.9.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 (211) hide show
  1. package/CHANGELOG.md +35 -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 -8
  18. package/dist/src/components/Declaration.d.ts.map +1 -1
  19. package/dist/src/components/Declaration.js +39 -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 +18 -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/FunctionCallExpression.js +1 -1
  29. package/dist/src/components/FunctionCallExpression.js.map +1 -1
  30. package/dist/src/components/FunctionDeclaration.d.ts +21 -13
  31. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  32. package/dist/src/components/FunctionDeclaration.js +79 -45
  33. package/dist/src/components/FunctionDeclaration.js.map +1 -1
  34. package/dist/src/components/IfStatement.d.ts +25 -0
  35. package/dist/src/components/IfStatement.d.ts.map +1 -0
  36. package/dist/src/components/IfStatement.js +34 -0
  37. package/dist/src/components/IfStatement.js.map +1 -0
  38. package/dist/src/components/Interface.d.ts +10 -2
  39. package/dist/src/components/Interface.d.ts.map +1 -1
  40. package/dist/src/components/Interface.js +66 -6
  41. package/dist/src/components/Interface.js.map +1 -1
  42. package/dist/src/components/JSDoc.d.ts.map +1 -1
  43. package/dist/src/components/JSDoc.js +1 -5
  44. package/dist/src/components/JSDoc.js.map +1 -1
  45. package/dist/src/components/JSDocParam.d.ts +22 -0
  46. package/dist/src/components/JSDocParam.d.ts.map +1 -0
  47. package/dist/src/components/JSDocParam.js +121 -0
  48. package/dist/src/components/JSDocParam.js.map +1 -0
  49. package/dist/src/components/MemberExpression.d.ts +62 -0
  50. package/dist/src/components/MemberExpression.d.ts.map +1 -0
  51. package/dist/src/components/MemberExpression.js +179 -0
  52. package/dist/src/components/MemberExpression.js.map +1 -0
  53. package/dist/src/components/ObjectExpression.d.ts +1 -1
  54. package/dist/src/components/ObjectExpression.d.ts.map +1 -1
  55. package/dist/src/components/ObjectExpression.js +9 -2
  56. package/dist/src/components/ObjectExpression.js.map +1 -1
  57. package/dist/src/components/PropertyName.d.ts +19 -0
  58. package/dist/src/components/PropertyName.d.ts.map +1 -0
  59. package/dist/src/components/PropertyName.js +36 -0
  60. package/dist/src/components/PropertyName.js.map +1 -0
  61. package/dist/src/components/SingleLineCommentBlock.d.ts +10 -0
  62. package/dist/src/components/SingleLineCommentBlock.d.ts.map +1 -0
  63. package/dist/src/components/SingleLineCommentBlock.js +20 -0
  64. package/dist/src/components/SingleLineCommentBlock.js.map +1 -0
  65. package/dist/src/components/SourceFile.d.ts +6 -0
  66. package/dist/src/components/SourceFile.d.ts.map +1 -1
  67. package/dist/src/components/SourceFile.js +31 -0
  68. package/dist/src/components/SourceFile.js.map +1 -1
  69. package/dist/src/components/SwitchStatement.d.ts +31 -0
  70. package/dist/src/components/SwitchStatement.d.ts.map +1 -0
  71. package/dist/src/components/SwitchStatement.js +48 -0
  72. package/dist/src/components/SwitchStatement.js.map +1 -0
  73. package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
  74. package/dist/src/components/TypeDeclaration.js +16 -3
  75. package/dist/src/components/TypeDeclaration.js.map +1 -1
  76. package/dist/src/components/VarDeclaration.d.ts +1 -1
  77. package/dist/src/components/VarDeclaration.d.ts.map +1 -1
  78. package/dist/src/components/VarDeclaration.js +19 -6
  79. package/dist/src/components/VarDeclaration.js.map +1 -1
  80. package/dist/src/components/index.d.ts +7 -0
  81. package/dist/src/components/index.d.ts.map +1 -1
  82. package/dist/src/components/index.js +7 -0
  83. package/dist/src/components/index.js.map +1 -1
  84. package/dist/src/components/stc/index.d.ts +35 -112
  85. package/dist/src/components/stc/index.d.ts.map +1 -1
  86. package/dist/src/components/stc/index.js +8 -1
  87. package/dist/src/components/stc/index.js.map +1 -1
  88. package/dist/src/context/index.d.ts +2 -0
  89. package/dist/src/context/index.d.ts.map +1 -0
  90. package/dist/src/context/index.js +1 -0
  91. package/dist/src/context/index.js.map +1 -0
  92. package/dist/src/context/private-scope.d.ts +18 -0
  93. package/dist/src/context/private-scope.d.ts.map +1 -0
  94. package/dist/src/context/private-scope.js +9 -0
  95. package/dist/src/context/private-scope.js.map +1 -0
  96. package/dist/src/index.d.ts +1 -0
  97. package/dist/src/index.d.ts.map +1 -1
  98. package/dist/src/index.js +1 -0
  99. package/dist/src/index.js.map +1 -1
  100. package/dist/src/parameter-descriptor.d.ts +60 -0
  101. package/dist/src/parameter-descriptor.d.ts.map +1 -0
  102. package/dist/src/parameter-descriptor.js +1 -0
  103. package/dist/src/parameter-descriptor.js.map +1 -0
  104. package/dist/src/symbols/reference.d.ts.map +1 -1
  105. package/dist/src/symbols/reference.js +50 -12
  106. package/dist/src/symbols/reference.js.map +1 -1
  107. package/dist/src/symbols/ts-member-scope.d.ts +1 -1
  108. package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
  109. package/dist/src/symbols/ts-member-scope.js +2 -0
  110. package/dist/src/symbols/ts-member-scope.js.map +1 -1
  111. package/dist/src/symbols/ts-output-symbol.d.ts +7 -4
  112. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
  113. package/dist/src/symbols/ts-output-symbol.js +11 -2
  114. package/dist/src/symbols/ts-output-symbol.js.map +1 -1
  115. package/dist/src/utils.d.ts +7 -0
  116. package/dist/src/utils.d.ts.map +1 -1
  117. package/dist/src/utils.js +17 -0
  118. package/dist/src/utils.js.map +1 -1
  119. package/dist/test/block-scope.test.d.ts +2 -0
  120. package/dist/test/block-scope.test.d.ts.map +1 -0
  121. package/dist/test/enum-jsdoc.test.d.ts +2 -0
  122. package/dist/test/enum-jsdoc.test.d.ts.map +1 -0
  123. package/dist/test/function-declaration-jsdoc.test.d.ts +2 -0
  124. package/dist/test/function-declaration-jsdoc.test.d.ts.map +1 -0
  125. package/dist/test/if-statement.test.d.ts +2 -0
  126. package/dist/test/if-statement.test.d.ts.map +1 -0
  127. package/dist/test/interface-jsdoc.test.d.ts +2 -0
  128. package/dist/test/interface-jsdoc.test.d.ts.map +1 -0
  129. package/dist/test/jscomment.test.d.ts +2 -0
  130. package/dist/test/jscomment.test.d.ts.map +1 -0
  131. package/dist/test/jsdoc.test.d.ts.map +1 -1
  132. package/dist/test/jsdocparam.test.d.ts +2 -0
  133. package/dist/test/jsdocparam.test.d.ts.map +1 -0
  134. package/dist/test/member-expression.test.d.ts +2 -0
  135. package/dist/test/member-expression.test.d.ts.map +1 -0
  136. package/dist/test/name-conflict.test.d.ts +2 -0
  137. package/dist/test/name-conflict.test.d.ts.map +1 -0
  138. package/dist/test/package-json.test.d.ts +2 -0
  139. package/dist/test/package-json.test.d.ts.map +1 -0
  140. package/dist/test/source-file.test.d.ts +2 -0
  141. package/dist/test/source-file.test.d.ts.map +1 -0
  142. package/dist/test/switch-statement.test.d.ts +2 -0
  143. package/dist/test/switch-statement.test.d.ts.map +1 -0
  144. package/dist/test/var-declaration-jsdoc.test.d.ts +2 -0
  145. package/dist/test/var-declaration-jsdoc.test.d.ts.map +1 -0
  146. package/dist/tsconfig.tsbuildinfo +1 -1
  147. package/package.json +3 -3
  148. package/src/components/ArrayExpression.tsx +13 -12
  149. package/src/components/BlockScope.tsx +31 -0
  150. package/src/components/CallSignature.tsx +67 -0
  151. package/src/components/ClassDeclaration.tsx +103 -50
  152. package/src/components/Declaration.tsx +72 -27
  153. package/src/components/EnumDeclaration.tsx +26 -18
  154. package/src/components/EnumMember.tsx +24 -4
  155. package/src/components/FunctionCallExpression.tsx +1 -1
  156. package/src/components/FunctionDeclaration.tsx +106 -82
  157. package/src/components/IfStatement.tsx +51 -0
  158. package/src/components/Interface.tsx +61 -14
  159. package/src/components/JSDoc.tsx +1 -10
  160. package/src/components/JSDocParam.tsx +115 -0
  161. package/src/components/MemberExpression.tsx +237 -0
  162. package/src/components/ObjectExpression.tsx +8 -3
  163. package/src/components/PropertyName.tsx +50 -0
  164. package/src/components/SingleLineCommentBlock.tsx +21 -0
  165. package/src/components/SourceFile.tsx +29 -0
  166. package/src/components/SwitchStatement.tsx +78 -0
  167. package/src/components/TypeDeclaration.tsx +11 -4
  168. package/src/components/VarDeclaration.tsx +19 -11
  169. package/src/components/index.ts +7 -0
  170. package/src/components/stc/index.ts +8 -1
  171. package/src/context/index.ts +1 -0
  172. package/src/context/private-scope.ts +23 -0
  173. package/src/index.ts +1 -0
  174. package/src/parameter-descriptor.ts +71 -0
  175. package/src/symbols/reference.ts +70 -18
  176. package/src/symbols/ts-member-scope.ts +6 -2
  177. package/src/symbols/ts-output-symbol.ts +24 -11
  178. package/src/utils.ts +33 -0
  179. package/temp/api.json +3819 -1915
  180. package/test/array.test.tsx +60 -0
  181. package/test/basic.test.tsx +2 -2
  182. package/test/block-scope.test.tsx +29 -0
  183. package/test/class.test.tsx +173 -5
  184. package/test/enum-jsdoc.test.tsx +74 -0
  185. package/test/enum.test.tsx +50 -3
  186. package/test/function-call-expression.test.tsx +5 -2
  187. package/test/function-declaration-jsdoc.test.tsx +89 -0
  188. package/test/function-declaration.test.tsx +13 -9
  189. package/test/if-statement.test.tsx +28 -0
  190. package/test/interface-jsdoc.test.tsx +164 -0
  191. package/test/interface.test.tsx +14 -0
  192. package/test/jscomment.test.tsx +104 -0
  193. package/test/jsdoc.test.tsx +9 -15
  194. package/test/jsdocparam.test.tsx +188 -0
  195. package/test/member-expression.test.tsx +297 -0
  196. package/test/name-conflict.test.tsx +105 -0
  197. package/test/name-policy.test.tsx +1 -1
  198. package/test/package-json.test.tsx +93 -0
  199. package/test/reference.test.tsx +6 -2
  200. package/test/source-file.test.tsx +38 -0
  201. package/test/switch-statement.test.tsx +50 -0
  202. package/test/value-expression.test.tsx +9 -0
  203. package/test/var-declaration-jsdoc.test.tsx +70 -0
  204. package/test/var-declaration.test.tsx +1 -1
  205. package/tsconfig.json +1 -8
  206. package/vitest.config.ts +2 -10
  207. package/dist/src/components/JSDocParagraph.d.ts +0 -10
  208. package/dist/src/components/JSDocParagraph.d.ts.map +0 -1
  209. package/dist/src/components/JSDocParagraph.js +0 -23
  210. package/dist/src/components/JSDocParagraph.js.map +0 -1
  211. package/src/components/JSDocParagraph.tsx +0 -35
@@ -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
+ });
@@ -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
+ });
@@ -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 />
@@ -0,0 +1,188 @@
1
+ import { d } from "@alloy-js/core/testing";
2
+ import { expect, it } from "vitest";
3
+ import { JSDocParam } from "../src/components/JSDocParam.jsx";
4
+ import { JSDoc } from "../src/index.js";
5
+
6
+ it("name only", () => {
7
+ const template = (
8
+ <JSDoc>
9
+ <JSDocParam name="somebody" />
10
+ </JSDoc>
11
+ );
12
+
13
+ expect(template).toRenderTo(
14
+ d`
15
+ /**
16
+ * @param somebody
17
+ **/
18
+ `,
19
+ );
20
+ });
21
+
22
+ it("name and type", () => {
23
+ const template = (
24
+ <JSDoc>
25
+ <JSDocParam name="somebody" type="string" />
26
+ </JSDoc>
27
+ );
28
+
29
+ expect(template).toRenderTo(
30
+ d`
31
+ /**
32
+ * @param {string} somebody
33
+ **/
34
+ `,
35
+ );
36
+ });
37
+
38
+ it("name, type and description", () => {
39
+ const template = (
40
+ <JSDoc>
41
+ <JSDocParam name="somebody" type="string">
42
+ Somebody's name.
43
+ </JSDocParam>
44
+ </JSDoc>
45
+ );
46
+
47
+ expect(template).toRenderTo(
48
+ d`
49
+ /**
50
+ * @param {string} somebody Somebody's name.
51
+ **/
52
+ `,
53
+ );
54
+ });
55
+
56
+ it("name, type and description with hyphen", () => {
57
+ const template = (
58
+ <JSDoc>
59
+ <JSDocParam name="somebody" type="string" hyphen>
60
+ Somebody's name.
61
+ </JSDocParam>
62
+ </JSDoc>
63
+ );
64
+
65
+ expect(template).toRenderTo(
66
+ d`
67
+ /**
68
+ * @param {string} somebody - Somebody's name.
69
+ **/
70
+ `,
71
+ );
72
+ });
73
+
74
+ it("name, type, description, hyphen and optional", () => {
75
+ const template = (
76
+ <JSDoc>
77
+ <JSDocParam name="somebody" type="string" optional hyphen>
78
+ Somebody's name.
79
+ </JSDocParam>
80
+ </JSDoc>
81
+ );
82
+
83
+ expect(template).toRenderTo(
84
+ d`
85
+ /**
86
+ * @param {string} [somebody] - Somebody's name.
87
+ **/
88
+ `,
89
+ );
90
+ });
91
+
92
+ it("name, type, description, hyphen and optional with default value", () => {
93
+ const template = (
94
+ <JSDoc>
95
+ <JSDocParam
96
+ name="somebody"
97
+ type="string"
98
+ optional
99
+ defaultValue="John Doe"
100
+ hyphen
101
+ >
102
+ Somebody's name.
103
+ </JSDocParam>
104
+ </JSDoc>
105
+ );
106
+
107
+ expect(template).toRenderTo(
108
+ d`
109
+ /**
110
+ * @param {string} [somebody=John Doe] - Somebody's name.
111
+ **/
112
+ `,
113
+ );
114
+ });
115
+
116
+ it("name, type, description, hyphen and optional with default value with a very lon description", () => {
117
+ const template = (
118
+ <JSDoc>
119
+ <JSDocParam
120
+ name="somebody"
121
+ type="string"
122
+ optional
123
+ defaultValue="John Doe"
124
+ hyphen
125
+ >
126
+ Somebody's name. This can be any string representing a person, whether
127
+ it's a first name, full name, nickname, or even a codename (e.g., "Agent
128
+ X"). It's used primarily for display purposes, logging, or greeting
129
+ messages and is not required to be unique or validated unless specified
130
+ by the caller.
131
+ </JSDocParam>
132
+ <JSDocParam name="somebody2" type="string" hyphen>
133
+ Somebody's name. This can be any string representing a person, whether
134
+ it's a first name, full name, nickname, or even a codename (e.g., "Agent
135
+ X"). It's used primarily for display purposes, logging, or greeting
136
+ messages and is not required to be unique or validated unless specified
137
+ by the caller.
138
+ </JSDocParam>
139
+ </JSDoc>
140
+ );
141
+
142
+ expect(template).toRenderTo(
143
+ d`
144
+ /**
145
+ * @param {string} [somebody=John Doe] - Somebody's name. This can be any string
146
+ * representing a person, whether it's a first name, full name, nickname, or
147
+ * even a codename (e.g., "Agent X"). It's used primarily for display
148
+ * purposes, logging, or greeting messages and is not required to be unique or
149
+ * validated unless specified by the caller.
150
+ *
151
+ * @param {string} somebody2 - Somebody's name. This can be any string
152
+ * representing a person, whether it's a first name, full name, nickname, or
153
+ * even a codename (e.g., "Agent X"). It's used primarily for display
154
+ * purposes, logging, or greeting messages and is not required to be unique or
155
+ * validated unless specified by the caller.
156
+ **/
157
+ `,
158
+ { printWidth: 80 },
159
+ );
160
+ });
161
+
162
+ it("name, type, description, hyphen and optional with default value with a description containing a linebreak", () => {
163
+ const template = (
164
+ <JSDoc>
165
+ <JSDocParam
166
+ name="somebody"
167
+ type="string"
168
+ optional
169
+ defaultValue="John Doe"
170
+ hyphen
171
+ >
172
+ Somebody's name. This is one line
173
+ <hbr />
174
+ This is another line
175
+ </JSDocParam>
176
+ </JSDoc>
177
+ );
178
+
179
+ expect(template).toRenderTo(
180
+ d`
181
+ /**
182
+ * @param {string} [somebody=John Doe] - Somebody's name. This is one line
183
+ * This is another line
184
+ **/
185
+ `,
186
+ { printWidth: 80 },
187
+ );
188
+ });