@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,558 @@
|
|
|
1
|
+
import { List, Output, refkey, render } from "@alloy-js/core";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { assertFileContents, TestPackage } from "../../../test/utils.js";
|
|
4
|
+
import { ModuleDirectory } from "../ModuleDirectory.js";
|
|
5
|
+
import { SourceDirectory } from "../SourceDirectory.js";
|
|
6
|
+
import { SourceFile } from "../SourceFile.js";
|
|
7
|
+
import { TypeConstraint } from "../interface/declaration.jsx";
|
|
8
|
+
import { Pointer } from "../pointer/pointer.js";
|
|
9
|
+
import { TypeDeclaration } from "../type/declaration.js";
|
|
10
|
+
import {
|
|
11
|
+
StructDeclaration,
|
|
12
|
+
StructEmbed,
|
|
13
|
+
StructMember,
|
|
14
|
+
} from "./declaration.jsx";
|
|
15
|
+
|
|
16
|
+
function Wrapper(props: { children: any }) {
|
|
17
|
+
return (
|
|
18
|
+
<TestPackage>
|
|
19
|
+
<TypeDeclaration name="TestStruct">
|
|
20
|
+
<StructDeclaration>{props.children}</StructDeclaration>
|
|
21
|
+
</TypeDeclaration>
|
|
22
|
+
</TestPackage>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
it("declares struct with no members", () => {
|
|
27
|
+
expect(
|
|
28
|
+
<TestPackage>
|
|
29
|
+
<TypeDeclaration name="test">
|
|
30
|
+
<StructDeclaration />
|
|
31
|
+
</TypeDeclaration>
|
|
32
|
+
</TestPackage>,
|
|
33
|
+
).toRenderTo(`
|
|
34
|
+
package alloy
|
|
35
|
+
|
|
36
|
+
type test struct{}
|
|
37
|
+
`);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("specify doc comment", () => {
|
|
41
|
+
expect(
|
|
42
|
+
<TestPackage>
|
|
43
|
+
<TypeDeclaration name="test" doc="This is a test">
|
|
44
|
+
<StructDeclaration />
|
|
45
|
+
</TypeDeclaration>
|
|
46
|
+
</TestPackage>,
|
|
47
|
+
).toRenderTo(`
|
|
48
|
+
package alloy
|
|
49
|
+
|
|
50
|
+
// This is a test
|
|
51
|
+
type test struct{}
|
|
52
|
+
`);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("defines fields", () => {
|
|
56
|
+
expect(
|
|
57
|
+
<TestPackage>
|
|
58
|
+
<TypeDeclaration name="TestStruct">
|
|
59
|
+
<StructDeclaration>
|
|
60
|
+
<List>
|
|
61
|
+
<StructMember name="MemberOne" type="string" />
|
|
62
|
+
<StructMember name="memberTwo" type="int" />
|
|
63
|
+
</List>
|
|
64
|
+
</StructDeclaration>
|
|
65
|
+
</TypeDeclaration>
|
|
66
|
+
</TestPackage>,
|
|
67
|
+
).toRenderTo(`
|
|
68
|
+
package alloy
|
|
69
|
+
|
|
70
|
+
type TestStruct struct {
|
|
71
|
+
MemberOne string
|
|
72
|
+
memberTwo int
|
|
73
|
+
}
|
|
74
|
+
`);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("nested struct", () => {
|
|
78
|
+
const Member1 = refkey("Member1");
|
|
79
|
+
const Member2 = refkey("Member2");
|
|
80
|
+
const Member3 = refkey("Member3");
|
|
81
|
+
const Member4 = refkey("Member4");
|
|
82
|
+
|
|
83
|
+
expect(
|
|
84
|
+
<TestPackage>
|
|
85
|
+
<TypeDeclaration name="TestStruct">
|
|
86
|
+
<StructDeclaration>
|
|
87
|
+
<List>
|
|
88
|
+
<StructMember name="MemberOne" type="string" refkey={Member1} />
|
|
89
|
+
<StructMember
|
|
90
|
+
name="MemberTwo"
|
|
91
|
+
refkey={Member2}
|
|
92
|
+
type={
|
|
93
|
+
<StructDeclaration>
|
|
94
|
+
<List>
|
|
95
|
+
<StructMember
|
|
96
|
+
name="MemberOne"
|
|
97
|
+
type="string"
|
|
98
|
+
refkey={Member3}
|
|
99
|
+
/>
|
|
100
|
+
<StructMember
|
|
101
|
+
name="NestedMemberTwo"
|
|
102
|
+
type="int"
|
|
103
|
+
refkey={Member4}
|
|
104
|
+
/>
|
|
105
|
+
</List>
|
|
106
|
+
</StructDeclaration>
|
|
107
|
+
}
|
|
108
|
+
/>
|
|
109
|
+
</List>
|
|
110
|
+
</StructDeclaration>
|
|
111
|
+
</TypeDeclaration>
|
|
112
|
+
<hbr />
|
|
113
|
+
{Member1}
|
|
114
|
+
<hbr />
|
|
115
|
+
{Member2}
|
|
116
|
+
<hbr />
|
|
117
|
+
{Member3}
|
|
118
|
+
<hbr />
|
|
119
|
+
{Member4}
|
|
120
|
+
</TestPackage>,
|
|
121
|
+
).toRenderTo(`
|
|
122
|
+
package alloy
|
|
123
|
+
|
|
124
|
+
type TestStruct struct {
|
|
125
|
+
MemberOne string
|
|
126
|
+
MemberTwo struct {
|
|
127
|
+
MemberOne string
|
|
128
|
+
NestedMemberTwo int
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
TestStruct.MemberOne
|
|
132
|
+
TestStruct.MemberTwo
|
|
133
|
+
TestStruct.MemberTwo.MemberOne
|
|
134
|
+
TestStruct.MemberTwo.NestedMemberTwo
|
|
135
|
+
`);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("declares multiple fields", () => {
|
|
139
|
+
expect(
|
|
140
|
+
<Wrapper>
|
|
141
|
+
<List>
|
|
142
|
+
<StructMember name="MemberOne" type="string" />
|
|
143
|
+
<StructMember name="MemberTwo" type="int" />
|
|
144
|
+
</List>
|
|
145
|
+
</Wrapper>,
|
|
146
|
+
).toRenderTo(`
|
|
147
|
+
package alloy
|
|
148
|
+
|
|
149
|
+
type TestStruct struct {
|
|
150
|
+
MemberOne string
|
|
151
|
+
MemberTwo int
|
|
152
|
+
}
|
|
153
|
+
`);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("declares multiple fields with tags", () => {
|
|
157
|
+
expect(
|
|
158
|
+
<Wrapper>
|
|
159
|
+
<List>
|
|
160
|
+
<StructMember
|
|
161
|
+
name="MemberOne"
|
|
162
|
+
type="string"
|
|
163
|
+
tag="this is arbitrary tag #1"
|
|
164
|
+
/>
|
|
165
|
+
<StructMember
|
|
166
|
+
name="MemberTwo"
|
|
167
|
+
type="int"
|
|
168
|
+
tag="this is arbitrary tag #2"
|
|
169
|
+
/>
|
|
170
|
+
</List>
|
|
171
|
+
</Wrapper>,
|
|
172
|
+
).toRenderTo(`
|
|
173
|
+
package alloy
|
|
174
|
+
|
|
175
|
+
type TestStruct struct {
|
|
176
|
+
MemberOne string "this is arbitrary tag #1"
|
|
177
|
+
MemberTwo int "this is arbitrary tag #2"
|
|
178
|
+
}
|
|
179
|
+
`);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("declares multiple fields with tag object", () => {
|
|
183
|
+
expect(
|
|
184
|
+
<Wrapper>
|
|
185
|
+
<List>
|
|
186
|
+
<StructMember
|
|
187
|
+
name="MemberOne"
|
|
188
|
+
type="string"
|
|
189
|
+
tag={{ json: "member_one,omit_empty" }}
|
|
190
|
+
/>
|
|
191
|
+
<StructMember
|
|
192
|
+
name="MemberTwo"
|
|
193
|
+
type="int"
|
|
194
|
+
tag={{ xml: "member_two,omit_empty", yaml: "memberTwo" }}
|
|
195
|
+
/>
|
|
196
|
+
</List>
|
|
197
|
+
</Wrapper>,
|
|
198
|
+
).toRenderTo(`
|
|
199
|
+
package alloy
|
|
200
|
+
|
|
201
|
+
type TestStruct struct {
|
|
202
|
+
MemberOne string \`json:"member_one,omit_empty"\`
|
|
203
|
+
MemberTwo int \`xml:"member_two,omit_empty" yaml:"memberTwo"\`
|
|
204
|
+
}
|
|
205
|
+
`);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe("naming", () => {
|
|
209
|
+
it("public field is PascalCase", () => {
|
|
210
|
+
expect(
|
|
211
|
+
<Wrapper>
|
|
212
|
+
<List>
|
|
213
|
+
<StructMember name="MemberOne" type="string" />
|
|
214
|
+
</List>
|
|
215
|
+
</Wrapper>,
|
|
216
|
+
).toRenderTo(`
|
|
217
|
+
package alloy
|
|
218
|
+
|
|
219
|
+
type TestStruct struct {
|
|
220
|
+
MemberOne string
|
|
221
|
+
}
|
|
222
|
+
`);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("private field are camelCase", () => {
|
|
226
|
+
expect(
|
|
227
|
+
<Wrapper>
|
|
228
|
+
<List>
|
|
229
|
+
<StructMember name="memberOne" type="string" />
|
|
230
|
+
</List>
|
|
231
|
+
</Wrapper>,
|
|
232
|
+
).toRenderTo(`
|
|
233
|
+
package alloy
|
|
234
|
+
|
|
235
|
+
type TestStruct struct {
|
|
236
|
+
memberOne string
|
|
237
|
+
}
|
|
238
|
+
`);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe("embedded", () => {
|
|
243
|
+
it("embed using children", () => {
|
|
244
|
+
const TestStructEmbed = refkey("TestStructEmbed");
|
|
245
|
+
expect(
|
|
246
|
+
<TestPackage>
|
|
247
|
+
<TypeDeclaration name="TestStruct">
|
|
248
|
+
<StructDeclaration>
|
|
249
|
+
<List>
|
|
250
|
+
<StructMember name="MemberOne" type="string" />
|
|
251
|
+
</List>
|
|
252
|
+
</StructDeclaration>
|
|
253
|
+
</TypeDeclaration>
|
|
254
|
+
<hbr />
|
|
255
|
+
<TypeDeclaration name="TestStruct2">
|
|
256
|
+
<StructDeclaration>
|
|
257
|
+
<List>
|
|
258
|
+
<StructEmbed refkey={TestStructEmbed}>TestStruct</StructEmbed>
|
|
259
|
+
<StructMember name="MemberOne" type="string" />
|
|
260
|
+
</List>
|
|
261
|
+
</StructDeclaration>
|
|
262
|
+
</TypeDeclaration>
|
|
263
|
+
<hbr />
|
|
264
|
+
{TestStructEmbed}
|
|
265
|
+
</TestPackage>,
|
|
266
|
+
).toRenderTo(`
|
|
267
|
+
package alloy
|
|
268
|
+
|
|
269
|
+
type TestStruct struct {
|
|
270
|
+
MemberOne string
|
|
271
|
+
}
|
|
272
|
+
type TestStruct2 struct {
|
|
273
|
+
TestStruct
|
|
274
|
+
MemberOne string
|
|
275
|
+
}
|
|
276
|
+
TestStruct2.TestStruct
|
|
277
|
+
`);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("embed using refkey", () => {
|
|
281
|
+
const TestStruct = refkey("TestStruct");
|
|
282
|
+
const TestStructEmbed = refkey("TestStructEmbed");
|
|
283
|
+
|
|
284
|
+
expect(
|
|
285
|
+
<TestPackage>
|
|
286
|
+
<TypeDeclaration name="TestStruct" refkey={TestStruct}>
|
|
287
|
+
<StructDeclaration>
|
|
288
|
+
<List>
|
|
289
|
+
<StructMember name="MemberOne" type="string" />
|
|
290
|
+
</List>
|
|
291
|
+
</StructDeclaration>
|
|
292
|
+
</TypeDeclaration>
|
|
293
|
+
<hbr />
|
|
294
|
+
<TypeDeclaration name="TestStruct2">
|
|
295
|
+
<StructDeclaration>
|
|
296
|
+
<List>
|
|
297
|
+
<StructEmbed refkey={TestStructEmbed}>{TestStruct}</StructEmbed>
|
|
298
|
+
<StructMember name="MemberOne" type="string" />
|
|
299
|
+
</List>
|
|
300
|
+
</StructDeclaration>
|
|
301
|
+
</TypeDeclaration>
|
|
302
|
+
<hbr />
|
|
303
|
+
{TestStructEmbed}
|
|
304
|
+
</TestPackage>,
|
|
305
|
+
).toRenderTo(`
|
|
306
|
+
package alloy
|
|
307
|
+
|
|
308
|
+
type TestStruct struct {
|
|
309
|
+
MemberOne string
|
|
310
|
+
}
|
|
311
|
+
type TestStruct2 struct {
|
|
312
|
+
TestStruct
|
|
313
|
+
MemberOne string
|
|
314
|
+
}
|
|
315
|
+
TestStruct2.TestStruct
|
|
316
|
+
`);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it("embed using cross-package refkey", () => {
|
|
320
|
+
const TestStruct = refkey("TestStruct");
|
|
321
|
+
const TestStructEmbed = refkey("TestStructEmbed");
|
|
322
|
+
|
|
323
|
+
const res = render(
|
|
324
|
+
<Output>
|
|
325
|
+
<ModuleDirectory name="github.com/alloy-framework/alloy">
|
|
326
|
+
<SourceDirectory path=".">
|
|
327
|
+
<SourceDirectory path="hello">
|
|
328
|
+
<SourceFile path="types.go">
|
|
329
|
+
<TypeDeclaration name="TestStruct" refkey={TestStruct}>
|
|
330
|
+
<StructDeclaration>
|
|
331
|
+
<List>
|
|
332
|
+
<StructMember name="MemberOne" type="string" />
|
|
333
|
+
</List>
|
|
334
|
+
</StructDeclaration>
|
|
335
|
+
</TypeDeclaration>
|
|
336
|
+
</SourceFile>
|
|
337
|
+
</SourceDirectory>
|
|
338
|
+
<SourceFile path="Test.go">
|
|
339
|
+
<TypeDeclaration name="TestStruct2">
|
|
340
|
+
<StructDeclaration>
|
|
341
|
+
<List>
|
|
342
|
+
<StructEmbed refkey={TestStructEmbed}>
|
|
343
|
+
{TestStruct}
|
|
344
|
+
</StructEmbed>
|
|
345
|
+
<StructMember name="MemberOne" type="string" />
|
|
346
|
+
</List>
|
|
347
|
+
</StructDeclaration>
|
|
348
|
+
</TypeDeclaration>
|
|
349
|
+
<hbr />
|
|
350
|
+
{TestStructEmbed}
|
|
351
|
+
</SourceFile>
|
|
352
|
+
</SourceDirectory>
|
|
353
|
+
</ModuleDirectory>
|
|
354
|
+
</Output>,
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
assertFileContents(res, {
|
|
358
|
+
"hello/types.go": `
|
|
359
|
+
package hello
|
|
360
|
+
|
|
361
|
+
type TestStruct struct {
|
|
362
|
+
MemberOne string
|
|
363
|
+
}
|
|
364
|
+
`,
|
|
365
|
+
"Test.go": `
|
|
366
|
+
package alloy
|
|
367
|
+
|
|
368
|
+
import "github.com/alloy-framework/alloy/hello"
|
|
369
|
+
|
|
370
|
+
type TestStruct2 struct {
|
|
371
|
+
hello.TestStruct
|
|
372
|
+
MemberOne string
|
|
373
|
+
}
|
|
374
|
+
TestStruct2.TestStruct
|
|
375
|
+
`,
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it("embed using cross-package refkey pointer", () => {
|
|
380
|
+
const TestStruct = refkey("TestStruct");
|
|
381
|
+
const TestStructEmbed = refkey("TestStructEmbed");
|
|
382
|
+
|
|
383
|
+
const res = render(
|
|
384
|
+
<Output>
|
|
385
|
+
<ModuleDirectory name="github.com/alloy-framework/alloy">
|
|
386
|
+
<SourceDirectory path=".">
|
|
387
|
+
<SourceDirectory path="hello">
|
|
388
|
+
<SourceFile path="types.go">
|
|
389
|
+
<TypeDeclaration name="TestStruct" refkey={TestStruct}>
|
|
390
|
+
<StructDeclaration>
|
|
391
|
+
<List>
|
|
392
|
+
<StructMember name="MemberOne" type="string" />
|
|
393
|
+
</List>
|
|
394
|
+
</StructDeclaration>
|
|
395
|
+
</TypeDeclaration>
|
|
396
|
+
</SourceFile>
|
|
397
|
+
</SourceDirectory>
|
|
398
|
+
<SourceFile path="Test.go">
|
|
399
|
+
<TypeDeclaration name="TestStruct2">
|
|
400
|
+
<StructDeclaration>
|
|
401
|
+
<List>
|
|
402
|
+
<StructEmbed refkey={TestStructEmbed}>
|
|
403
|
+
<Pointer>{TestStruct}</Pointer>
|
|
404
|
+
</StructEmbed>
|
|
405
|
+
<StructMember name="MemberOne" type="string" />
|
|
406
|
+
</List>
|
|
407
|
+
</StructDeclaration>
|
|
408
|
+
</TypeDeclaration>
|
|
409
|
+
<hbr />
|
|
410
|
+
{TestStructEmbed}
|
|
411
|
+
</SourceFile>
|
|
412
|
+
</SourceDirectory>
|
|
413
|
+
</ModuleDirectory>
|
|
414
|
+
</Output>,
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
assertFileContents(res, {
|
|
418
|
+
"hello/types.go": `
|
|
419
|
+
package hello
|
|
420
|
+
|
|
421
|
+
type TestStruct struct {
|
|
422
|
+
MemberOne string
|
|
423
|
+
}
|
|
424
|
+
`,
|
|
425
|
+
"Test.go": `
|
|
426
|
+
package alloy
|
|
427
|
+
|
|
428
|
+
import "github.com/alloy-framework/alloy/hello"
|
|
429
|
+
|
|
430
|
+
type TestStruct2 struct {
|
|
431
|
+
*hello.TestStruct
|
|
432
|
+
MemberOne string
|
|
433
|
+
}
|
|
434
|
+
TestStruct2.TestStruct
|
|
435
|
+
`,
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
describe("type parameters", () => {
|
|
441
|
+
it("single type parameter", () => {
|
|
442
|
+
const T = refkey("T");
|
|
443
|
+
|
|
444
|
+
expect(
|
|
445
|
+
<TestPackage>
|
|
446
|
+
<TypeDeclaration
|
|
447
|
+
name="TestStruct"
|
|
448
|
+
typeParameters={[{ name: "T", constraint: "any", refkey: T }]}
|
|
449
|
+
>
|
|
450
|
+
<StructDeclaration>
|
|
451
|
+
<List>
|
|
452
|
+
<StructMember name="MemberOne" type={T} />
|
|
453
|
+
</List>
|
|
454
|
+
</StructDeclaration>
|
|
455
|
+
</TypeDeclaration>
|
|
456
|
+
</TestPackage>,
|
|
457
|
+
).toRenderTo(`
|
|
458
|
+
package alloy
|
|
459
|
+
|
|
460
|
+
type TestStruct[T any] struct {
|
|
461
|
+
MemberOne T
|
|
462
|
+
}
|
|
463
|
+
`);
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
it("multiple type parameters", () => {
|
|
467
|
+
const TestStructType = refkey("TestStructType");
|
|
468
|
+
const U = refkey("U");
|
|
469
|
+
|
|
470
|
+
expect(
|
|
471
|
+
<TestPackage>
|
|
472
|
+
<TypeDeclaration name="TestStructType" refkey={TestStructType}>
|
|
473
|
+
<StructDeclaration>
|
|
474
|
+
<List>
|
|
475
|
+
<StructMember name="MemberOne" type="string" />
|
|
476
|
+
</List>
|
|
477
|
+
</StructDeclaration>
|
|
478
|
+
</TypeDeclaration>
|
|
479
|
+
<hbr />
|
|
480
|
+
<TypeDeclaration
|
|
481
|
+
name="TestStruct"
|
|
482
|
+
typeParameters={[
|
|
483
|
+
{
|
|
484
|
+
name: "T",
|
|
485
|
+
constraint: <TypeConstraint constraints={["string", "int"]} />,
|
|
486
|
+
},
|
|
487
|
+
{ name: "U", constraint: TestStructType, refkey: U },
|
|
488
|
+
]}
|
|
489
|
+
>
|
|
490
|
+
<StructDeclaration>
|
|
491
|
+
<List>
|
|
492
|
+
<StructMember name="MemberOne" type={U} />
|
|
493
|
+
</List>
|
|
494
|
+
</StructDeclaration>
|
|
495
|
+
</TypeDeclaration>
|
|
496
|
+
</TestPackage>,
|
|
497
|
+
).toRenderTo(`
|
|
498
|
+
package alloy
|
|
499
|
+
|
|
500
|
+
type TestStructType struct {
|
|
501
|
+
MemberOne string
|
|
502
|
+
}
|
|
503
|
+
type TestStruct[T string | int, U TestStructType] struct {
|
|
504
|
+
MemberOne U
|
|
505
|
+
}
|
|
506
|
+
`);
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
it("type parameter overflow", () => {
|
|
510
|
+
expect(
|
|
511
|
+
<TestPackage>
|
|
512
|
+
<TypeDeclaration
|
|
513
|
+
name="TestStruct"
|
|
514
|
+
typeParameters={[
|
|
515
|
+
{
|
|
516
|
+
name: "T",
|
|
517
|
+
constraint: <TypeConstraint constraints={["string", "int"]} />,
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
name: "T",
|
|
521
|
+
constraint: <TypeConstraint constraints={["string", "int"]} />,
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
name: "T",
|
|
525
|
+
constraint: <TypeConstraint constraints={["string", "int"]} />,
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
name: "T",
|
|
529
|
+
constraint: <TypeConstraint constraints={["string", "int"]} />,
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
name: "T",
|
|
533
|
+
constraint: <TypeConstraint constraints={["string", "int"]} />,
|
|
534
|
+
},
|
|
535
|
+
]}
|
|
536
|
+
>
|
|
537
|
+
<StructDeclaration>
|
|
538
|
+
<List>
|
|
539
|
+
<StructMember name="MemberOne" type="string" />
|
|
540
|
+
</List>
|
|
541
|
+
</StructDeclaration>
|
|
542
|
+
</TypeDeclaration>
|
|
543
|
+
</TestPackage>,
|
|
544
|
+
).toRenderTo(`
|
|
545
|
+
package alloy
|
|
546
|
+
|
|
547
|
+
type TestStruct[
|
|
548
|
+
T string | int,
|
|
549
|
+
T_2 string | int,
|
|
550
|
+
T_3 string | int,
|
|
551
|
+
T_4 string | int,
|
|
552
|
+
T_5 string | int,
|
|
553
|
+
] struct {
|
|
554
|
+
MemberOne string
|
|
555
|
+
}
|
|
556
|
+
`);
|
|
557
|
+
});
|
|
558
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
ComponentContext,
|
|
4
|
+
createContext,
|
|
5
|
+
Declaration,
|
|
6
|
+
Indent,
|
|
7
|
+
List,
|
|
8
|
+
Name,
|
|
9
|
+
Namekey,
|
|
10
|
+
Refkey,
|
|
11
|
+
Scope,
|
|
12
|
+
Show,
|
|
13
|
+
useContext,
|
|
14
|
+
} from "@alloy-js/core";
|
|
15
|
+
import { createNamedTypeScope } from "../../scopes/factories.js";
|
|
16
|
+
import { createTypeSymbol } from "../../symbols/factories.js";
|
|
17
|
+
import { NamedTypeSymbol } from "../../symbols/named-type.js";
|
|
18
|
+
import { LineComment } from "../doc/comment.js";
|
|
19
|
+
import {
|
|
20
|
+
TypeParameterProps,
|
|
21
|
+
TypeParameters,
|
|
22
|
+
} from "../parameters/typeparameters.jsx";
|
|
23
|
+
|
|
24
|
+
export interface TypeDeclarationGroupProps {
|
|
25
|
+
children: Children;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface TypeDeclarationGroupContext {
|
|
29
|
+
active: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const TypeDeclarationGroupContext: ComponentContext<TypeDeclarationGroupContext> =
|
|
33
|
+
createContext<TypeDeclarationGroupContext>();
|
|
34
|
+
|
|
35
|
+
export function TypeDeclarationGroup(props: TypeDeclarationGroupProps) {
|
|
36
|
+
return (
|
|
37
|
+
<TypeDeclarationGroupContext.Provider value={{ active: true }}>
|
|
38
|
+
type (
|
|
39
|
+
<Indent trailingBreak>
|
|
40
|
+
<List hardline>{props.children}</List>
|
|
41
|
+
</Indent>
|
|
42
|
+
)
|
|
43
|
+
</TypeDeclarationGroupContext.Provider>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface TypeDeclarationProps {
|
|
48
|
+
/** Type name */
|
|
49
|
+
name: string | Namekey;
|
|
50
|
+
/** Type refkey */
|
|
51
|
+
refkey?: Refkey;
|
|
52
|
+
/** Type symbol */
|
|
53
|
+
symbol?: NamedTypeSymbol;
|
|
54
|
+
/** Documentation comment */
|
|
55
|
+
doc?: Children;
|
|
56
|
+
/** Whether the type is an alias */
|
|
57
|
+
alias?: boolean;
|
|
58
|
+
/** Type expression */
|
|
59
|
+
children?: Children;
|
|
60
|
+
/** Type parameters */
|
|
61
|
+
typeParameters?: TypeParameterProps[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function TypeDeclaration(props: TypeDeclarationProps) {
|
|
65
|
+
const typeGroup = useContext(TypeDeclarationGroupContext);
|
|
66
|
+
|
|
67
|
+
const symbol =
|
|
68
|
+
props.symbol ??
|
|
69
|
+
createTypeSymbol(props.name, "type", {
|
|
70
|
+
refkeys: props.refkey,
|
|
71
|
+
typeParameters: props.typeParameters,
|
|
72
|
+
// TODO: set aliasTarget when alias is true
|
|
73
|
+
});
|
|
74
|
+
const typeScope = createNamedTypeScope(symbol);
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
<Show when={Boolean(props.doc)}>
|
|
79
|
+
<LineComment children={props.doc} />
|
|
80
|
+
<hbr />
|
|
81
|
+
</Show>
|
|
82
|
+
<Declaration symbol={symbol}>
|
|
83
|
+
{typeGroup?.active ? "" : "type "}
|
|
84
|
+
<Name />
|
|
85
|
+
<Scope value={typeScope}>
|
|
86
|
+
<TypeParameters parameters={props.typeParameters} />
|
|
87
|
+
{props.alias ? " = " : " "}
|
|
88
|
+
{props.children}
|
|
89
|
+
</Scope>
|
|
90
|
+
</Declaration>
|
|
91
|
+
</>
|
|
92
|
+
);
|
|
93
|
+
}
|