@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.
- package/CHANGELOG.md +1 -0
- package/LICENSE +7 -0
- package/api-extractor.json +4 -0
- package/dist/src/builtins/fmt/fmt.d.ts +147 -0
- package/dist/src/builtins/fmt/fmt.d.ts.map +1 -0
- package/dist/src/builtins/fmt/fmt.js +148 -0
- package/dist/src/builtins/fmt/fmt.js.map +1 -0
- package/dist/src/builtins/index.d.ts +2004 -0
- package/dist/src/builtins/index.d.ts.map +1 -0
- package/dist/src/builtins/index.js +9 -0
- package/dist/src/builtins/index.js.map +1 -0
- package/dist/src/builtins/io/io.d.ts +648 -0
- package/dist/src/builtins/io/io.d.ts.map +1 -0
- package/dist/src/builtins/io/io.js +650 -0
- package/dist/src/builtins/io/io.js.map +1 -0
- package/dist/src/builtins/net/net.d.ts +1210 -0
- package/dist/src/builtins/net/net.d.ts.map +1 -0
- package/dist/src/builtins/net/net.js +1212 -0
- package/dist/src/builtins/net/net.js.map +1 -0
- package/dist/src/components/ImportStatement.d.ts +15 -0
- package/dist/src/components/ImportStatement.d.ts.map +1 -0
- package/dist/src/components/ImportStatement.js +90 -0
- package/dist/src/components/ImportStatement.js.map +1 -0
- package/dist/src/components/ModuleDirectory.d.ts +8 -0
- package/dist/src/components/ModuleDirectory.d.ts.map +1 -0
- package/dist/src/components/ModuleDirectory.js +20 -0
- package/dist/src/components/ModuleDirectory.js.map +1 -0
- package/dist/src/components/Name.d.ts +2 -0
- package/dist/src/components/Name.d.ts.map +1 -0
- package/dist/src/components/Name.js +12 -0
- package/dist/src/components/Name.js.map +1 -0
- package/dist/src/components/Reference.d.ts +6 -0
- package/dist/src/components/Reference.d.ts.map +1 -0
- package/dist/src/components/Reference.js +15 -0
- package/dist/src/components/Reference.js.map +1 -0
- package/dist/src/components/SourceDirectory.d.ts +6 -0
- package/dist/src/components/SourceDirectory.d.ts.map +1 -0
- package/dist/src/components/SourceDirectory.js +30 -0
- package/dist/src/components/SourceDirectory.js.map +1 -0
- package/dist/src/components/SourceFile.d.ts +16 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -0
- package/dist/src/components/SourceFile.js +75 -0
- package/dist/src/components/SourceFile.js.map +1 -0
- package/dist/src/components/doc/comment.d.ts +21 -0
- package/dist/src/components/doc/comment.d.ts.map +1 -0
- package/dist/src/components/doc/comment.js +30 -0
- package/dist/src/components/doc/comment.js.map +1 -0
- package/dist/src/components/doc/comment.test.d.ts +2 -0
- package/dist/src/components/doc/comment.test.d.ts.map +1 -0
- package/dist/src/components/doc/comment.test.js +215 -0
- package/dist/src/components/doc/comment.test.js.map +1 -0
- package/dist/src/components/function/function.d.ts +31 -0
- package/dist/src/components/function/function.d.ts.map +1 -0
- package/dist/src/components/function/function.js +134 -0
- package/dist/src/components/function/function.js.map +1 -0
- package/dist/src/components/function/function.test.d.ts +2 -0
- package/dist/src/components/function/function.test.d.ts.map +1 -0
- package/dist/src/components/function/function.test.js +410 -0
- package/dist/src/components/function/function.test.js.map +1 -0
- package/dist/src/components/index.d.ts +16 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +16 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/interface/declaration.d.ts +68 -0
- package/dist/src/components/interface/declaration.d.ts.map +1 -0
- package/dist/src/components/interface/declaration.js +181 -0
- package/dist/src/components/interface/declaration.js.map +1 -0
- package/dist/src/components/interface/interface.test.d.ts +2 -0
- package/dist/src/components/interface/interface.test.d.ts.map +1 -0
- package/dist/src/components/interface/interface.test.js +517 -0
- package/dist/src/components/interface/interface.test.js.map +1 -0
- package/dist/src/components/package.test.d.ts +2 -0
- package/dist/src/components/package.test.d.ts.map +1 -0
- package/dist/src/components/package.test.js +89 -0
- package/dist/src/components/package.test.js.map +1 -0
- package/dist/src/components/parameters/parameters.d.ts +15 -0
- package/dist/src/components/parameters/parameters.d.ts.map +1 -0
- package/dist/src/components/parameters/parameters.js +58 -0
- package/dist/src/components/parameters/parameters.js.map +1 -0
- package/dist/src/components/parameters/typeparameters.d.ts +25 -0
- package/dist/src/components/parameters/typeparameters.d.ts.map +1 -0
- package/dist/src/components/parameters/typeparameters.js +53 -0
- package/dist/src/components/parameters/typeparameters.js.map +1 -0
- package/dist/src/components/pointer/pointer.d.ts +9 -0
- package/dist/src/components/pointer/pointer.d.ts.map +1 -0
- package/dist/src/components/pointer/pointer.js +8 -0
- package/dist/src/components/pointer/pointer.js.map +1 -0
- package/dist/src/components/stc/index.d.ts +27 -0
- package/dist/src/components/stc/index.d.ts.map +1 -0
- package/dist/src/components/stc/index.js +27 -0
- package/dist/src/components/stc/index.js.map +1 -0
- package/dist/src/components/struct/declaration.d.ts +62 -0
- package/dist/src/components/struct/declaration.d.ts.map +1 -0
- package/dist/src/components/struct/declaration.js +161 -0
- package/dist/src/components/struct/declaration.js.map +1 -0
- package/dist/src/components/struct/struct.test.d.ts +2 -0
- package/dist/src/components/struct/struct.test.d.ts.map +1 -0
- package/dist/src/components/struct/struct.test.js +741 -0
- package/dist/src/components/struct/struct.test.js.map +1 -0
- package/dist/src/components/type/declaration.d.ts +29 -0
- package/dist/src/components/type/declaration.d.ts.map +1 -0
- package/dist/src/components/type/declaration.js +63 -0
- package/dist/src/components/type/declaration.js.map +1 -0
- package/dist/src/components/var/declaration.d.ts +27 -0
- package/dist/src/components/var/declaration.d.ts.map +1 -0
- package/dist/src/components/var/declaration.js +84 -0
- package/dist/src/components/var/declaration.js.map +1 -0
- package/dist/src/components/var/var-declaration.test.d.ts +2 -0
- package/dist/src/components/var/var-declaration.test.d.ts.map +1 -0
- package/dist/src/components/var/var-declaration.test.js +340 -0
- package/dist/src/components/var/var-declaration.test.js.map +1 -0
- package/dist/src/context/package.d.ts +9 -0
- package/dist/src/context/package.d.ts.map +1 -0
- package/dist/src/context/package.js +6 -0
- package/dist/src/context/package.js.map +1 -0
- package/dist/src/create-module.d.ts +47 -0
- package/dist/src/create-module.d.ts.map +1 -0
- package/dist/src/create-module.js +158 -0
- package/dist/src/create-module.js.map +1 -0
- package/dist/src/create-module.test.d.ts +2 -0
- package/dist/src/create-module.test.d.ts.map +1 -0
- package/dist/src/create-module.test.js +147 -0
- package/dist/src/create-module.test.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/name-policy.d.ts +5 -0
- package/dist/src/name-policy.d.ts.map +1 -0
- package/dist/src/name-policy.js +27 -0
- package/dist/src/name-policy.js.map +1 -0
- package/dist/src/scopes/contexts.d.ts +9 -0
- package/dist/src/scopes/contexts.d.ts.map +1 -0
- package/dist/src/scopes/contexts.js +34 -0
- package/dist/src/scopes/contexts.js.map +1 -0
- package/dist/src/scopes/factories.d.ts +7 -0
- package/dist/src/scopes/factories.d.ts.map +1 -0
- package/dist/src/scopes/factories.js +16 -0
- package/dist/src/scopes/factories.js.map +1 -0
- package/dist/src/scopes/function.d.ts +9 -0
- package/dist/src/scopes/function.d.ts.map +1 -0
- package/dist/src/scopes/function.js +14 -0
- package/dist/src/scopes/function.js.map +1 -0
- package/dist/src/scopes/go.d.ts +8 -0
- package/dist/src/scopes/go.d.ts.map +1 -0
- package/dist/src/scopes/go.js +12 -0
- package/dist/src/scopes/go.js.map +1 -0
- package/dist/src/scopes/index.d.ts +10 -0
- package/dist/src/scopes/index.d.ts.map +1 -0
- package/dist/src/scopes/index.js +10 -0
- package/dist/src/scopes/index.js.map +1 -0
- package/dist/src/scopes/lexical.d.ts +8 -0
- package/dist/src/scopes/lexical.d.ts.map +1 -0
- package/dist/src/scopes/lexical.js +11 -0
- package/dist/src/scopes/lexical.js.map +1 -0
- package/dist/src/scopes/module.d.ts +9 -0
- package/dist/src/scopes/module.d.ts.map +1 -0
- package/dist/src/scopes/module.js +31 -0
- package/dist/src/scopes/module.js.map +1 -0
- package/dist/src/scopes/named-type.d.ts +23 -0
- package/dist/src/scopes/named-type.d.ts.map +1 -0
- package/dist/src/scopes/named-type.js +33 -0
- package/dist/src/scopes/named-type.js.map +1 -0
- package/dist/src/scopes/package.d.ts +11 -0
- package/dist/src/scopes/package.d.ts.map +1 -0
- package/dist/src/scopes/package.js +39 -0
- package/dist/src/scopes/package.js.map +1 -0
- package/dist/src/scopes/source-file.d.ts +17 -0
- package/dist/src/scopes/source-file.d.ts.map +1 -0
- package/dist/src/scopes/source-file.js +42 -0
- package/dist/src/scopes/source-file.js.map +1 -0
- package/dist/src/symbols/factories.d.ts +25 -0
- package/dist/src/symbols/factories.d.ts.map +1 -0
- package/dist/src/symbols/factories.js +114 -0
- package/dist/src/symbols/factories.js.map +1 -0
- package/dist/src/symbols/function.d.ts +10 -0
- package/dist/src/symbols/function.d.ts.map +1 -0
- package/dist/src/symbols/function.js +12 -0
- package/dist/src/symbols/function.js.map +1 -0
- package/dist/src/symbols/go.d.ts +22 -0
- package/dist/src/symbols/go.d.ts.map +1 -0
- package/dist/src/symbols/go.js +56 -0
- package/dist/src/symbols/go.js.map +1 -0
- package/dist/src/symbols/index.d.ts +7 -0
- package/dist/src/symbols/index.d.ts.map +1 -0
- package/dist/src/symbols/index.js +7 -0
- package/dist/src/symbols/index.js.map +1 -0
- package/dist/src/symbols/named-type.d.ts +24 -0
- package/dist/src/symbols/named-type.d.ts.map +1 -0
- package/dist/src/symbols/named-type.js +53 -0
- package/dist/src/symbols/named-type.js.map +1 -0
- package/dist/src/symbols/package.d.ts +18 -0
- package/dist/src/symbols/package.d.ts.map +1 -0
- package/dist/src/symbols/package.js +38 -0
- package/dist/src/symbols/package.js.map +1 -0
- package/dist/src/symbols/reference.d.ts +3 -0
- package/dist/src/symbols/reference.d.ts.map +1 -0
- package/dist/src/symbols/reference.js +76 -0
- package/dist/src/symbols/reference.js.map +1 -0
- package/dist/test/utils.d.ts +8 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/utils.js +68 -0
- package/dist/test/utils.js.map +1 -0
- package/dist/test/vitest.setup.d.ts +2 -0
- package/dist/test/vitest.setup.d.ts.map +1 -0
- package/dist/test/vitest.setup.js +2 -0
- package/dist/test/vitest.setup.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +45 -0
- package/src/builtins/fmt/fmt.ts +78 -0
- package/src/builtins/index.ts +9 -0
- package/src/builtins/io/io.ts +355 -0
- package/src/builtins/net/net.ts +502 -0
- package/src/components/ImportStatement.tsx +115 -0
- package/src/components/ModuleDirectory.tsx +18 -0
- package/src/components/Name.tsx +11 -0
- package/src/components/Reference.tsx +18 -0
- package/src/components/SourceDirectory.tsx +32 -0
- package/src/components/SourceFile.tsx +74 -0
- package/src/components/doc/comment.test.tsx +278 -0
- package/src/components/doc/comment.tsx +40 -0
- package/src/components/function/function.test.tsx +387 -0
- package/src/components/function/function.tsx +194 -0
- package/src/components/index.ts +15 -0
- package/src/components/interface/declaration.tsx +250 -0
- package/src/components/interface/interface.test.tsx +390 -0
- package/src/components/package.test.tsx +63 -0
- package/src/components/parameters/parameters.tsx +74 -0
- package/src/components/parameters/typeparameters.tsx +78 -0
- package/src/components/pointer/pointer.tsx +12 -0
- package/src/components/stc/index.ts +27 -0
- package/src/components/struct/declaration.tsx +228 -0
- package/src/components/struct/struct.test.tsx +558 -0
- package/src/components/type/declaration.tsx +93 -0
- package/src/components/var/declaration.tsx +138 -0
- package/src/components/var/var-declaration.test.tsx +236 -0
- package/src/context/package.ts +13 -0
- package/src/create-module.test.tsx +128 -0
- package/src/create-module.ts +347 -0
- package/src/index.ts +5 -0
- package/src/name-policy.ts +65 -0
- package/src/scopes/contexts.ts +45 -0
- package/src/scopes/factories.ts +29 -0
- package/src/scopes/function.ts +22 -0
- package/src/scopes/go.ts +18 -0
- package/src/scopes/index.ts +9 -0
- package/src/scopes/lexical.ts +14 -0
- package/src/scopes/module.ts +35 -0
- package/src/scopes/named-type.ts +49 -0
- package/src/scopes/package.ts +55 -0
- package/src/scopes/source-file.ts +66 -0
- package/src/symbols/factories.ts +234 -0
- package/src/symbols/function.ts +17 -0
- package/src/symbols/go.ts +82 -0
- package/src/symbols/index.ts +6 -0
- package/src/symbols/named-type.ts +90 -0
- package/src/symbols/package.ts +54 -0
- package/src/symbols/reference.ts +87 -0
- package/temp/api.json +8753 -0
- package/test/utils.tsx +77 -0
- package/test/vitest.setup.ts +1 -0
- package/tsconfig.json +15 -0
- package/tsdoc-metadata.json +11 -0
- 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
|
+
}
|