@alloy-js/go 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (264) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE +7 -0
  3. package/api-extractor.json +4 -0
  4. package/dist/src/builtins/fmt/fmt.d.ts +147 -0
  5. package/dist/src/builtins/fmt/fmt.d.ts.map +1 -0
  6. package/dist/src/builtins/fmt/fmt.js +148 -0
  7. package/dist/src/builtins/fmt/fmt.js.map +1 -0
  8. package/dist/src/builtins/index.d.ts +2004 -0
  9. package/dist/src/builtins/index.d.ts.map +1 -0
  10. package/dist/src/builtins/index.js +9 -0
  11. package/dist/src/builtins/index.js.map +1 -0
  12. package/dist/src/builtins/io/io.d.ts +648 -0
  13. package/dist/src/builtins/io/io.d.ts.map +1 -0
  14. package/dist/src/builtins/io/io.js +650 -0
  15. package/dist/src/builtins/io/io.js.map +1 -0
  16. package/dist/src/builtins/net/net.d.ts +1210 -0
  17. package/dist/src/builtins/net/net.d.ts.map +1 -0
  18. package/dist/src/builtins/net/net.js +1212 -0
  19. package/dist/src/builtins/net/net.js.map +1 -0
  20. package/dist/src/components/ImportStatement.d.ts +15 -0
  21. package/dist/src/components/ImportStatement.d.ts.map +1 -0
  22. package/dist/src/components/ImportStatement.js +90 -0
  23. package/dist/src/components/ImportStatement.js.map +1 -0
  24. package/dist/src/components/ModuleDirectory.d.ts +8 -0
  25. package/dist/src/components/ModuleDirectory.d.ts.map +1 -0
  26. package/dist/src/components/ModuleDirectory.js +20 -0
  27. package/dist/src/components/ModuleDirectory.js.map +1 -0
  28. package/dist/src/components/Name.d.ts +2 -0
  29. package/dist/src/components/Name.d.ts.map +1 -0
  30. package/dist/src/components/Name.js +12 -0
  31. package/dist/src/components/Name.js.map +1 -0
  32. package/dist/src/components/Reference.d.ts +6 -0
  33. package/dist/src/components/Reference.d.ts.map +1 -0
  34. package/dist/src/components/Reference.js +15 -0
  35. package/dist/src/components/Reference.js.map +1 -0
  36. package/dist/src/components/SourceDirectory.d.ts +6 -0
  37. package/dist/src/components/SourceDirectory.d.ts.map +1 -0
  38. package/dist/src/components/SourceDirectory.js +30 -0
  39. package/dist/src/components/SourceDirectory.js.map +1 -0
  40. package/dist/src/components/SourceFile.d.ts +16 -0
  41. package/dist/src/components/SourceFile.d.ts.map +1 -0
  42. package/dist/src/components/SourceFile.js +75 -0
  43. package/dist/src/components/SourceFile.js.map +1 -0
  44. package/dist/src/components/doc/comment.d.ts +21 -0
  45. package/dist/src/components/doc/comment.d.ts.map +1 -0
  46. package/dist/src/components/doc/comment.js +30 -0
  47. package/dist/src/components/doc/comment.js.map +1 -0
  48. package/dist/src/components/doc/comment.test.d.ts +2 -0
  49. package/dist/src/components/doc/comment.test.d.ts.map +1 -0
  50. package/dist/src/components/doc/comment.test.js +215 -0
  51. package/dist/src/components/doc/comment.test.js.map +1 -0
  52. package/dist/src/components/function/function.d.ts +31 -0
  53. package/dist/src/components/function/function.d.ts.map +1 -0
  54. package/dist/src/components/function/function.js +134 -0
  55. package/dist/src/components/function/function.js.map +1 -0
  56. package/dist/src/components/function/function.test.d.ts +2 -0
  57. package/dist/src/components/function/function.test.d.ts.map +1 -0
  58. package/dist/src/components/function/function.test.js +410 -0
  59. package/dist/src/components/function/function.test.js.map +1 -0
  60. package/dist/src/components/index.d.ts +16 -0
  61. package/dist/src/components/index.d.ts.map +1 -0
  62. package/dist/src/components/index.js +16 -0
  63. package/dist/src/components/index.js.map +1 -0
  64. package/dist/src/components/interface/declaration.d.ts +68 -0
  65. package/dist/src/components/interface/declaration.d.ts.map +1 -0
  66. package/dist/src/components/interface/declaration.js +181 -0
  67. package/dist/src/components/interface/declaration.js.map +1 -0
  68. package/dist/src/components/interface/interface.test.d.ts +2 -0
  69. package/dist/src/components/interface/interface.test.d.ts.map +1 -0
  70. package/dist/src/components/interface/interface.test.js +517 -0
  71. package/dist/src/components/interface/interface.test.js.map +1 -0
  72. package/dist/src/components/package.test.d.ts +2 -0
  73. package/dist/src/components/package.test.d.ts.map +1 -0
  74. package/dist/src/components/package.test.js +89 -0
  75. package/dist/src/components/package.test.js.map +1 -0
  76. package/dist/src/components/parameters/parameters.d.ts +15 -0
  77. package/dist/src/components/parameters/parameters.d.ts.map +1 -0
  78. package/dist/src/components/parameters/parameters.js +58 -0
  79. package/dist/src/components/parameters/parameters.js.map +1 -0
  80. package/dist/src/components/parameters/typeparameters.d.ts +25 -0
  81. package/dist/src/components/parameters/typeparameters.d.ts.map +1 -0
  82. package/dist/src/components/parameters/typeparameters.js +53 -0
  83. package/dist/src/components/parameters/typeparameters.js.map +1 -0
  84. package/dist/src/components/pointer/pointer.d.ts +9 -0
  85. package/dist/src/components/pointer/pointer.d.ts.map +1 -0
  86. package/dist/src/components/pointer/pointer.js +8 -0
  87. package/dist/src/components/pointer/pointer.js.map +1 -0
  88. package/dist/src/components/stc/index.d.ts +27 -0
  89. package/dist/src/components/stc/index.d.ts.map +1 -0
  90. package/dist/src/components/stc/index.js +27 -0
  91. package/dist/src/components/stc/index.js.map +1 -0
  92. package/dist/src/components/struct/declaration.d.ts +62 -0
  93. package/dist/src/components/struct/declaration.d.ts.map +1 -0
  94. package/dist/src/components/struct/declaration.js +161 -0
  95. package/dist/src/components/struct/declaration.js.map +1 -0
  96. package/dist/src/components/struct/struct.test.d.ts +2 -0
  97. package/dist/src/components/struct/struct.test.d.ts.map +1 -0
  98. package/dist/src/components/struct/struct.test.js +741 -0
  99. package/dist/src/components/struct/struct.test.js.map +1 -0
  100. package/dist/src/components/type/declaration.d.ts +29 -0
  101. package/dist/src/components/type/declaration.d.ts.map +1 -0
  102. package/dist/src/components/type/declaration.js +63 -0
  103. package/dist/src/components/type/declaration.js.map +1 -0
  104. package/dist/src/components/var/declaration.d.ts +27 -0
  105. package/dist/src/components/var/declaration.d.ts.map +1 -0
  106. package/dist/src/components/var/declaration.js +84 -0
  107. package/dist/src/components/var/declaration.js.map +1 -0
  108. package/dist/src/components/var/var-declaration.test.d.ts +2 -0
  109. package/dist/src/components/var/var-declaration.test.d.ts.map +1 -0
  110. package/dist/src/components/var/var-declaration.test.js +340 -0
  111. package/dist/src/components/var/var-declaration.test.js.map +1 -0
  112. package/dist/src/context/package.d.ts +9 -0
  113. package/dist/src/context/package.d.ts.map +1 -0
  114. package/dist/src/context/package.js +6 -0
  115. package/dist/src/context/package.js.map +1 -0
  116. package/dist/src/create-module.d.ts +47 -0
  117. package/dist/src/create-module.d.ts.map +1 -0
  118. package/dist/src/create-module.js +158 -0
  119. package/dist/src/create-module.js.map +1 -0
  120. package/dist/src/create-module.test.d.ts +2 -0
  121. package/dist/src/create-module.test.d.ts.map +1 -0
  122. package/dist/src/create-module.test.js +147 -0
  123. package/dist/src/create-module.test.js.map +1 -0
  124. package/dist/src/index.d.ts +6 -0
  125. package/dist/src/index.d.ts.map +1 -0
  126. package/dist/src/index.js +6 -0
  127. package/dist/src/index.js.map +1 -0
  128. package/dist/src/name-policy.d.ts +5 -0
  129. package/dist/src/name-policy.d.ts.map +1 -0
  130. package/dist/src/name-policy.js +27 -0
  131. package/dist/src/name-policy.js.map +1 -0
  132. package/dist/src/scopes/contexts.d.ts +9 -0
  133. package/dist/src/scopes/contexts.d.ts.map +1 -0
  134. package/dist/src/scopes/contexts.js +34 -0
  135. package/dist/src/scopes/contexts.js.map +1 -0
  136. package/dist/src/scopes/factories.d.ts +7 -0
  137. package/dist/src/scopes/factories.d.ts.map +1 -0
  138. package/dist/src/scopes/factories.js +16 -0
  139. package/dist/src/scopes/factories.js.map +1 -0
  140. package/dist/src/scopes/function.d.ts +9 -0
  141. package/dist/src/scopes/function.d.ts.map +1 -0
  142. package/dist/src/scopes/function.js +14 -0
  143. package/dist/src/scopes/function.js.map +1 -0
  144. package/dist/src/scopes/go.d.ts +8 -0
  145. package/dist/src/scopes/go.d.ts.map +1 -0
  146. package/dist/src/scopes/go.js +12 -0
  147. package/dist/src/scopes/go.js.map +1 -0
  148. package/dist/src/scopes/index.d.ts +10 -0
  149. package/dist/src/scopes/index.d.ts.map +1 -0
  150. package/dist/src/scopes/index.js +10 -0
  151. package/dist/src/scopes/index.js.map +1 -0
  152. package/dist/src/scopes/lexical.d.ts +8 -0
  153. package/dist/src/scopes/lexical.d.ts.map +1 -0
  154. package/dist/src/scopes/lexical.js +11 -0
  155. package/dist/src/scopes/lexical.js.map +1 -0
  156. package/dist/src/scopes/module.d.ts +9 -0
  157. package/dist/src/scopes/module.d.ts.map +1 -0
  158. package/dist/src/scopes/module.js +31 -0
  159. package/dist/src/scopes/module.js.map +1 -0
  160. package/dist/src/scopes/named-type.d.ts +23 -0
  161. package/dist/src/scopes/named-type.d.ts.map +1 -0
  162. package/dist/src/scopes/named-type.js +33 -0
  163. package/dist/src/scopes/named-type.js.map +1 -0
  164. package/dist/src/scopes/package.d.ts +11 -0
  165. package/dist/src/scopes/package.d.ts.map +1 -0
  166. package/dist/src/scopes/package.js +39 -0
  167. package/dist/src/scopes/package.js.map +1 -0
  168. package/dist/src/scopes/source-file.d.ts +17 -0
  169. package/dist/src/scopes/source-file.d.ts.map +1 -0
  170. package/dist/src/scopes/source-file.js +42 -0
  171. package/dist/src/scopes/source-file.js.map +1 -0
  172. package/dist/src/symbols/factories.d.ts +25 -0
  173. package/dist/src/symbols/factories.d.ts.map +1 -0
  174. package/dist/src/symbols/factories.js +114 -0
  175. package/dist/src/symbols/factories.js.map +1 -0
  176. package/dist/src/symbols/function.d.ts +10 -0
  177. package/dist/src/symbols/function.d.ts.map +1 -0
  178. package/dist/src/symbols/function.js +12 -0
  179. package/dist/src/symbols/function.js.map +1 -0
  180. package/dist/src/symbols/go.d.ts +22 -0
  181. package/dist/src/symbols/go.d.ts.map +1 -0
  182. package/dist/src/symbols/go.js +56 -0
  183. package/dist/src/symbols/go.js.map +1 -0
  184. package/dist/src/symbols/index.d.ts +7 -0
  185. package/dist/src/symbols/index.d.ts.map +1 -0
  186. package/dist/src/symbols/index.js +7 -0
  187. package/dist/src/symbols/index.js.map +1 -0
  188. package/dist/src/symbols/named-type.d.ts +24 -0
  189. package/dist/src/symbols/named-type.d.ts.map +1 -0
  190. package/dist/src/symbols/named-type.js +53 -0
  191. package/dist/src/symbols/named-type.js.map +1 -0
  192. package/dist/src/symbols/package.d.ts +18 -0
  193. package/dist/src/symbols/package.d.ts.map +1 -0
  194. package/dist/src/symbols/package.js +38 -0
  195. package/dist/src/symbols/package.js.map +1 -0
  196. package/dist/src/symbols/reference.d.ts +3 -0
  197. package/dist/src/symbols/reference.d.ts.map +1 -0
  198. package/dist/src/symbols/reference.js +76 -0
  199. package/dist/src/symbols/reference.js.map +1 -0
  200. package/dist/test/utils.d.ts +8 -0
  201. package/dist/test/utils.d.ts.map +1 -0
  202. package/dist/test/utils.js +68 -0
  203. package/dist/test/utils.js.map +1 -0
  204. package/dist/test/vitest.setup.d.ts +2 -0
  205. package/dist/test/vitest.setup.d.ts.map +1 -0
  206. package/dist/test/vitest.setup.js +2 -0
  207. package/dist/test/vitest.setup.js.map +1 -0
  208. package/dist/tsconfig.tsbuildinfo +1 -0
  209. package/package.json +45 -0
  210. package/src/builtins/fmt/fmt.ts +78 -0
  211. package/src/builtins/index.ts +9 -0
  212. package/src/builtins/io/io.ts +355 -0
  213. package/src/builtins/net/net.ts +502 -0
  214. package/src/components/ImportStatement.tsx +115 -0
  215. package/src/components/ModuleDirectory.tsx +18 -0
  216. package/src/components/Name.tsx +11 -0
  217. package/src/components/Reference.tsx +18 -0
  218. package/src/components/SourceDirectory.tsx +32 -0
  219. package/src/components/SourceFile.tsx +74 -0
  220. package/src/components/doc/comment.test.tsx +278 -0
  221. package/src/components/doc/comment.tsx +40 -0
  222. package/src/components/function/function.test.tsx +387 -0
  223. package/src/components/function/function.tsx +194 -0
  224. package/src/components/index.ts +15 -0
  225. package/src/components/interface/declaration.tsx +250 -0
  226. package/src/components/interface/interface.test.tsx +390 -0
  227. package/src/components/package.test.tsx +63 -0
  228. package/src/components/parameters/parameters.tsx +74 -0
  229. package/src/components/parameters/typeparameters.tsx +78 -0
  230. package/src/components/pointer/pointer.tsx +12 -0
  231. package/src/components/stc/index.ts +27 -0
  232. package/src/components/struct/declaration.tsx +228 -0
  233. package/src/components/struct/struct.test.tsx +558 -0
  234. package/src/components/type/declaration.tsx +93 -0
  235. package/src/components/var/declaration.tsx +138 -0
  236. package/src/components/var/var-declaration.test.tsx +236 -0
  237. package/src/context/package.ts +13 -0
  238. package/src/create-module.test.tsx +128 -0
  239. package/src/create-module.ts +347 -0
  240. package/src/index.ts +5 -0
  241. package/src/name-policy.ts +65 -0
  242. package/src/scopes/contexts.ts +45 -0
  243. package/src/scopes/factories.ts +29 -0
  244. package/src/scopes/function.ts +22 -0
  245. package/src/scopes/go.ts +18 -0
  246. package/src/scopes/index.ts +9 -0
  247. package/src/scopes/lexical.ts +14 -0
  248. package/src/scopes/module.ts +35 -0
  249. package/src/scopes/named-type.ts +49 -0
  250. package/src/scopes/package.ts +55 -0
  251. package/src/scopes/source-file.ts +66 -0
  252. package/src/symbols/factories.ts +234 -0
  253. package/src/symbols/function.ts +17 -0
  254. package/src/symbols/go.ts +82 -0
  255. package/src/symbols/index.ts +6 -0
  256. package/src/symbols/named-type.ts +90 -0
  257. package/src/symbols/package.ts +54 -0
  258. package/src/symbols/reference.ts +87 -0
  259. package/temp/api.json +8753 -0
  260. package/test/utils.tsx +77 -0
  261. package/test/vitest.setup.ts +1 -0
  262. package/tsconfig.json +15 -0
  263. package/tsdoc-metadata.json +11 -0
  264. package/vitest.config.ts +13 -0
@@ -0,0 +1,32 @@
1
+ import {
2
+ SourceDirectory as CoreSourceDirectory,
3
+ SourceDirectoryProps as CoreSourceDirectoryProps,
4
+ Scope,
5
+ SourceDirectoryContext,
6
+ useContext,
7
+ } from "@alloy-js/core";
8
+ import { basename, join } from "pathe";
9
+ import { useModule } from "../scopes/module.js";
10
+ import { createGoPackageScope } from "../scopes/package.js";
11
+ import { createPackageSymbol } from "../symbols/factories.js";
12
+
13
+ export interface SourceDirectoryProps extends CoreSourceDirectoryProps {
14
+ name?: string;
15
+ }
16
+
17
+ export function SourceDirectory(props: SourceDirectoryProps) {
18
+ const mod = useModule();
19
+ const directoryContext = useContext(SourceDirectoryContext)!;
20
+ const currentDir = join(directoryContext.path, props.path);
21
+ const dname = basename(currentDir);
22
+ const modName = mod ? basename(mod.name) : "main";
23
+ const packageName = props.name ?? (dname === "." ? modName : dname);
24
+ const packageSymbol = createPackageSymbol(packageName, props.path);
25
+ const packageScope = createGoPackageScope(packageSymbol);
26
+
27
+ return (
28
+ <CoreSourceDirectory path={props.path}>
29
+ <Scope value={packageScope}>{props.children}</Scope>;
30
+ </CoreSourceDirectory>
31
+ );
32
+ }
@@ -0,0 +1,74 @@
1
+ import {
2
+ SourceFile as CoreSourceFile,
3
+ Scope,
4
+ Show,
5
+ SourceDirectoryContext,
6
+ useContext,
7
+ type Children,
8
+ } from "@alloy-js/core";
9
+ import { join } from "pathe";
10
+ import { usePackage } from "../scopes/package.js";
11
+ import { GoSourceFileScope } from "../scopes/source-file.js";
12
+ import { ImportStatements } from "./ImportStatement.js";
13
+ import { Reference } from "./Reference.js";
14
+ import { LineComment } from "./doc/comment.js";
15
+
16
+ export interface SourceFileProps {
17
+ path: string;
18
+ package?: string;
19
+ children?: Children;
20
+ header?: Children;
21
+ headerComment?: string;
22
+ export?: boolean | string;
23
+ }
24
+
25
+ export function SourceFile(props: SourceFileProps) {
26
+ const pkg = usePackage();
27
+ const directoryContext = useContext(SourceDirectoryContext)!;
28
+ const currentDir = directoryContext.path;
29
+ const path: string = join(currentDir, props.path);
30
+ const scope = new GoSourceFileScope(path, pkg);
31
+
32
+ const header = (
33
+ <SourceFileHeader
34
+ package={pkg?.ownerSymbol.name ?? "main"}
35
+ header={props.header}
36
+ headerComment={props.headerComment}
37
+ />
38
+ );
39
+
40
+ return (
41
+ <CoreSourceFile
42
+ path={props.path}
43
+ filetype="go"
44
+ reference={Reference}
45
+ header={header}
46
+ >
47
+ <Show when={scope.imports.size > 0}>
48
+ <ImportStatements records={scope.imports} />
49
+ <hbr />
50
+ <hbr />
51
+ </Show>
52
+ <Scope value={scope}>{props.children}</Scope>
53
+ </CoreSourceFile>
54
+ );
55
+ }
56
+
57
+ export interface SourceFileHeaderProps {
58
+ package: string;
59
+ header?: Children;
60
+ headerComment?: string;
61
+ }
62
+
63
+ function SourceFileHeader(props: SourceFileHeaderProps) {
64
+ return (
65
+ <>
66
+ <Show when={props.headerComment !== undefined}>
67
+ <LineComment>{props.headerComment}</LineComment>
68
+ </Show>
69
+ <Show when={props.header !== undefined}>{props.header}</Show>
70
+ package {props.package}
71
+ <hbr />
72
+ </>
73
+ );
74
+ }
@@ -0,0 +1,278 @@
1
+ import { List, Prose } 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 { BlockComment, LineComment } from "./comment.jsx";
6
+
7
+ describe("GoLineComment", () => {
8
+ it("formats properly a simple comment", () => {
9
+ const template = (
10
+ <>
11
+ <LineComment>Hello!</LineComment>
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
+ <LineComment>
31
+ Hello!
32
+ <hbr />
33
+ <hbr />
34
+ This is another line
35
+ </LineComment>
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
+ <LineComment>
57
+ <Prose>Hello!</Prose>
58
+ <hbr />
59
+ <hbr />
60
+ <Prose>This is another line</Prose>
61
+ </LineComment>
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
+ <LineComment>
82
+ <Prose>
83
+ This is a very long line that should be broken into multiple lines.
84
+ It should also be aligned properly. The line breaks in this
85
+ paragraph should not be carried over into the JSDoc comment.
86
+ </Prose>
87
+ </LineComment>
88
+ <hbr />
89
+ <>This should not be part of the comment</>
90
+ </>
91
+ );
92
+
93
+ expect(template).toRenderTo(
94
+ d`
95
+ // This is a very long line that should
96
+ // be broken into multiple lines. It
97
+ // should also be aligned properly. The
98
+ // line breaks in this paragraph should
99
+ // not be carried over into the JSDoc
100
+ // comment.
101
+ This should not be part of the comment
102
+ `,
103
+ { printWidth: 40 },
104
+ );
105
+ });
106
+
107
+ it("formats properly", () => {
108
+ const template = (
109
+ <LineComment>
110
+ <Prose>
111
+ This is a long paragraph that should end up being broken into multiple
112
+ paragraphs. Moreover, the line breaks in this paragraph should not be
113
+ carried over into the JSDoc comment.
114
+ </Prose>
115
+ <hbr />
116
+ <hbr />
117
+ <Prose>
118
+ This is another paragraph. There should be a couple breaks in front of
119
+ it.
120
+ </Prose>
121
+ </LineComment>
122
+ );
123
+
124
+ expect(template).toRenderTo(
125
+ d`
126
+ // This is a long paragraph that should
127
+ // end up being broken into multiple
128
+ // paragraphs. Moreover, the line breaks
129
+ // in this paragraph should not be
130
+ // carried over into the JSDoc comment.
131
+ //
132
+ // This is another paragraph. There
133
+ // should be a couple breaks in front of
134
+ // it.
135
+ `,
136
+ { printWidth: 40 },
137
+ );
138
+ });
139
+ });
140
+
141
+ describe("GoBlockComment", () => {
142
+ it("formats properly a simple comment", () => {
143
+ const template = (
144
+ <>
145
+ <BlockComment>Hello!</BlockComment>
146
+ <hbr />
147
+ Should not be part of the comment
148
+ </>
149
+ );
150
+
151
+ expect(template).toRenderTo(
152
+ d`
153
+ /*
154
+ Hello!
155
+ */
156
+ Should not be part of the comment
157
+ `,
158
+ { printWidth: 40 },
159
+ );
160
+ });
161
+
162
+ it("should not add extra line breaks", () => {
163
+ const template = (
164
+ <>
165
+ <List hardline>
166
+ <BlockComment>
167
+ <Prose>Hello!</Prose>
168
+ <Prose>World!</Prose>
169
+ <Prose>This is another line</Prose>
170
+ </BlockComment>
171
+ </List>
172
+ <hbr />
173
+ Hello
174
+ </>
175
+ );
176
+
177
+ expect(template).toRenderTo(
178
+ d`
179
+ /*
180
+ Hello!
181
+
182
+ World!
183
+
184
+ This is another line
185
+ */
186
+ Hello
187
+ `,
188
+ { printWidth: 40 },
189
+ );
190
+ });
191
+
192
+ it("formats properly multiple children", () => {
193
+ const template = (
194
+ <>
195
+ <BlockComment>
196
+ <Prose>Hello!</Prose>
197
+ <Prose>This is another line</Prose>
198
+ </BlockComment>
199
+ <hbr />
200
+ foo should be outside the comment
201
+ </>
202
+ );
203
+
204
+ expect(template).toRenderTo(
205
+ d`
206
+ /*
207
+ Hello!
208
+
209
+ This is another line
210
+ */
211
+ foo should be outside the comment
212
+ `,
213
+ { printWidth: 40 },
214
+ );
215
+ });
216
+
217
+ it("It correctly do word wrapping", () => {
218
+ const template = (
219
+ <>
220
+ <BlockComment>
221
+ <Prose>
222
+ This is a very long line that should be broken into multiple lines.
223
+ It should also be aligned properly. The line breaks in this
224
+ paragraph should not be carried over into the JSDoc comment.
225
+ </Prose>
226
+ </BlockComment>
227
+ <hbr />
228
+ <>This should not be part of the comment</>
229
+ </>
230
+ );
231
+
232
+ expect(template).toRenderTo(
233
+ d`
234
+ /*
235
+ This is a very long line that should be
236
+ broken into multiple lines. It should
237
+ also be aligned properly. The line
238
+ breaks in this paragraph should not be
239
+ carried over into the JSDoc comment.
240
+ */
241
+ This should not be part of the comment
242
+ `,
243
+ { printWidth: 40 },
244
+ );
245
+ });
246
+
247
+ it("formats properly", () => {
248
+ const template = (
249
+ <BlockComment>
250
+ <Prose>
251
+ This is a long paragraph that should end up being broken into multiple
252
+ paragraphs. Moreover, the line breaks in this paragraph should not be
253
+ carried over into the JSDoc comment.
254
+ </Prose>
255
+ <Prose>
256
+ This is another paragraph. There should be a couple breaks in front of
257
+ it.
258
+ </Prose>
259
+ </BlockComment>
260
+ );
261
+
262
+ expect(template).toRenderTo(
263
+ d`
264
+ /*
265
+ This is a long paragraph that should end
266
+ up being broken into multiple
267
+ paragraphs. Moreover, the line breaks in
268
+ this paragraph should not be carried
269
+ over into the JSDoc comment.
270
+
271
+ This is another paragraph. There should
272
+ be a couple breaks in front of it.
273
+ */
274
+ `,
275
+ { printWidth: 40 },
276
+ );
277
+ });
278
+ });
@@ -0,0 +1,40 @@
1
+ import { List, childrenArray, type Children } from "@alloy-js/core";
2
+
3
+ export interface BlockCommentProps {
4
+ children: Children;
5
+ }
6
+
7
+ /**
8
+ * A Go block comment. In go, line comments are the norm, so consider
9
+ * using {@link LineComment} instead. The children of this component
10
+ * are joined with two hard linebreaks. This is useful for creating
11
+ * block comments with multiple paragraphs.
12
+ */
13
+ export function BlockComment(props: BlockCommentProps) {
14
+ return (
15
+ <>
16
+ /*
17
+ <hbr />
18
+ <List doubleHardline>{childrenArray(() => props.children)}</List>
19
+ <hbr />
20
+ */
21
+ </>
22
+ );
23
+ }
24
+
25
+ export interface LineCommentProps {
26
+ children: Children;
27
+ }
28
+
29
+ /**
30
+ * A Go line comment block. The children of this component
31
+ * are joined with two hard linebreaks. This is useful for creating
32
+ * line comments with multiple paragraphs.
33
+ */
34
+ export function LineComment(props: LineCommentProps) {
35
+ return (
36
+ <>
37
+ // <align string="// ">{props.children}</align>
38
+ </>
39
+ );
40
+ }