@alloy-js/csharp 0.18.0-dev.24 → 0.18.0-dev.3
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/dist/src/components/Class.d.ts +26 -0
- package/dist/src/components/Class.d.ts.map +1 -0
- package/dist/src/components/{ClassDeclaration.js → Class.js} +38 -70
- package/dist/src/components/ClassMethod.d.ts +5 -44
- package/dist/src/components/ClassMethod.d.ts.map +1 -1
- package/dist/src/components/ClassMethod.js +9 -33
- package/dist/src/components/Enum.d.ts +15 -0
- package/dist/src/components/Enum.d.ts.map +1 -0
- package/dist/src/components/{EnumDeclaration.js → Enum.js} +5 -25
- package/dist/src/components/Parameters.d.ts +13 -0
- package/dist/src/components/Parameters.d.ts.map +1 -0
- package/dist/src/components/Parameters.js +34 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +0 -1
- package/dist/src/components/index.d.ts +4 -14
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +5 -15
- package/dist/src/components/stc/index.d.ts +2 -2
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +2 -2
- package/dist/src/modifiers.d.ts +4 -10
- package/dist/src/modifiers.d.ts.map +1 -1
- package/dist/src/modifiers.js +32 -9
- package/dist/src/name-policy.d.ts +1 -1
- package/dist/src/name-policy.d.ts.map +1 -1
- package/dist/src/name-policy.js +0 -2
- package/dist/test/class-method.test.js +14 -37
- package/dist/test/class.test.d.ts +2 -0
- package/dist/test/class.test.d.ts.map +1 -0
- package/dist/test/class.test.js +298 -0
- package/dist/test/enum.test.js +12 -12
- package/dist/test/namespace.test.js +8 -8
- package/dist/test/projectdirectory.test.d.ts +2 -0
- package/dist/test/projectdirectory.test.d.ts.map +1 -0
- package/dist/test/{project-directory.test.js → projectdirectory.test.js} +8 -8
- package/dist/test/sourcefile.test.js +4 -4
- package/dist/test/using.test.js +9 -9
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/src/components/Class.tsx +149 -0
- package/src/components/ClassMethod.tsx +15 -74
- package/src/components/{EnumDeclaration.tsx → Enum.tsx} +6 -30
- package/src/components/Parameters.tsx +51 -0
- package/src/components/SourceFile.tsx +0 -1
- package/src/components/index.ts +4 -14
- package/src/components/stc/index.ts +2 -2
- package/src/modifiers.ts +42 -25
- package/src/name-policy.ts +0 -5
- package/temp/api.json +1298 -6463
- package/test/class-method.test.tsx +14 -24
- package/test/class.test.tsx +292 -0
- package/test/enum.test.tsx +11 -11
- package/test/namespace.test.tsx +4 -4
- package/test/{project-directory.test.tsx → projectdirectory.test.tsx} +4 -4
- package/test/sourcefile.test.tsx +2 -2
- package/test/using.test.tsx +9 -9
- package/vitest.config.ts +0 -3
- package/dist/src/components/ClassDeclaration.d.ts +0 -92
- package/dist/src/components/ClassDeclaration.d.ts.map +0 -1
- package/dist/src/components/EnumDeclaration.d.ts +0 -34
- package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
- package/dist/src/components/attributes/attributes.d.ts +0 -39
- package/dist/src/components/attributes/attributes.d.ts.map +0 -1
- package/dist/src/components/attributes/attributes.js +0 -62
- package/dist/src/components/attributes/attributes.test.d.ts +0 -2
- package/dist/src/components/attributes/attributes.test.d.ts.map +0 -1
- package/dist/src/components/attributes/attributes.test.js +0 -75
- package/dist/src/components/doc/comment.d.ts +0 -70
- package/dist/src/components/doc/comment.d.ts.map +0 -1
- package/dist/src/components/doc/comment.js +0 -88
- package/dist/src/components/doc/comment.test.d.ts +0 -2
- package/dist/src/components/doc/comment.test.d.ts.map +0 -1
- package/dist/src/components/doc/comment.test.js +0 -348
- package/dist/src/components/doc/from-markdown.d.ts +0 -6
- package/dist/src/components/doc/from-markdown.d.ts.map +0 -1
- package/dist/src/components/doc/from-markdown.js +0 -58
- package/dist/src/components/doc/from-markdown.test.d.ts +0 -2
- package/dist/src/components/doc/from-markdown.test.d.ts.map +0 -1
- package/dist/src/components/doc/from-markdown.test.js +0 -83
- package/dist/src/components/interface/declaration.d.ts +0 -65
- package/dist/src/components/interface/declaration.d.ts.map +0 -1
- package/dist/src/components/interface/declaration.js +0 -83
- package/dist/src/components/interface/declaration.test.d.ts +0 -2
- package/dist/src/components/interface/declaration.test.d.ts.map +0 -1
- package/dist/src/components/interface/declaration.test.js +0 -171
- package/dist/src/components/interface/method.d.ts +0 -50
- package/dist/src/components/interface/method.d.ts.map +0 -1
- package/dist/src/components/interface/method.js +0 -74
- package/dist/src/components/interface/method.test.d.ts +0 -2
- package/dist/src/components/interface/method.test.d.ts.map +0 -1
- package/dist/src/components/interface/method.test.js +0 -300
- package/dist/src/components/interface/property.d.ts +0 -56
- package/dist/src/components/interface/property.d.ts.map +0 -1
- package/dist/src/components/interface/property.js +0 -73
- package/dist/src/components/interface/property.test.d.ts +0 -2
- package/dist/src/components/interface/property.test.d.ts.map +0 -1
- package/dist/src/components/interface/property.test.js +0 -189
- package/dist/src/components/parameters/parameters.d.ts +0 -19
- package/dist/src/components/parameters/parameters.d.ts.map +0 -1
- package/dist/src/components/parameters/parameters.js +0 -43
- package/dist/src/components/property/property.d.ts +0 -80
- package/dist/src/components/property/property.d.ts.map +0 -1
- package/dist/src/components/property/property.js +0 -76
- package/dist/src/components/property/property.test.d.ts +0 -2
- package/dist/src/components/property/property.test.d.ts.map +0 -1
- package/dist/src/components/property/property.test.js +0 -242
- package/dist/src/components/record/declaration.d.ts +0 -35
- package/dist/src/components/record/declaration.d.ts.map +0 -1
- package/dist/src/components/record/declaration.js +0 -90
- package/dist/src/components/record/declaration.test.d.ts +0 -2
- package/dist/src/components/record/declaration.test.d.ts.map +0 -1
- package/dist/src/components/record/declaration.test.js +0 -94
- package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +0 -8
- package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameter-constraints.js +0 -44
- package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +0 -2
- package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameter-constraints.test.js +0 -67
- package/dist/src/components/type-parameters/type-parameter.d.ts +0 -20
- package/dist/src/components/type-parameters/type-parameter.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameter.js +0 -22
- package/dist/src/components/type-parameters/type-parameters.d.ts +0 -17
- package/dist/src/components/type-parameters/type-parameters.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameters.js +0 -54
- package/dist/src/components/type-parameters/type-parameters.test.d.ts +0 -2
- package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameters.test.js +0 -48
- package/dist/src/components/var/declaration.d.ts +0 -35
- package/dist/src/components/var/declaration.d.ts.map +0 -1
- package/dist/src/components/var/declaration.js +0 -40
- package/dist/src/components/var/declaration.test.d.ts +0 -2
- package/dist/src/components/var/declaration.test.d.ts.map +0 -1
- package/dist/src/components/var/declaration.test.js +0 -73
- package/dist/test/class-declaration.test.d.ts +0 -2
- package/dist/test/class-declaration.test.d.ts.map +0 -1
- package/dist/test/class-declaration.test.js +0 -481
- package/dist/test/project-directory.test.d.ts +0 -2
- package/dist/test/project-directory.test.d.ts.map +0 -1
- package/dist/test/vitest.setup.d.ts +0 -2
- package/dist/test/vitest.setup.d.ts.map +0 -1
- package/dist/test/vitest.setup.js +0 -1
- package/src/components/ClassDeclaration.tsx +0 -233
- package/src/components/attributes/attributes.test.tsx +0 -61
- package/src/components/attributes/attributes.tsx +0 -100
- package/src/components/doc/comment.test.tsx +0 -337
- package/src/components/doc/comment.tsx +0 -152
- package/src/components/doc/from-markdown.test.tsx +0 -103
- package/src/components/doc/from-markdown.tsx +0 -58
- package/src/components/interface/declaration.test.tsx +0 -158
- package/src/components/interface/declaration.tsx +0 -125
- package/src/components/interface/method.test.tsx +0 -293
- package/src/components/interface/method.tsx +0 -122
- package/src/components/interface/property.test.tsx +0 -165
- package/src/components/interface/property.tsx +0 -127
- package/src/components/parameters/parameters.tsx +0 -74
- package/src/components/property/property.test.tsx +0 -209
- package/src/components/property/property.tsx +0 -172
- package/src/components/record/declaration.test.tsx +0 -73
- package/src/components/record/declaration.tsx +0 -109
- package/src/components/type-parameters/type-parameter-constraints.test.tsx +0 -93
- package/src/components/type-parameters/type-parameter-constraints.tsx +0 -46
- package/src/components/type-parameters/type-parameter.tsx +0 -35
- package/src/components/type-parameters/type-parameters.test.tsx +0 -46
- package/src/components/type-parameters/type-parameters.tsx +0 -63
- package/src/components/var/declaration.test.tsx +0 -59
- package/src/components/var/declaration.tsx +0 -47
- package/test/class-declaration.test.tsx +0 -430
- package/test/vitest.setup.ts +0 -1
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { TestNamespace } from "../../../test/utils.js";
|
|
4
|
-
import { Attribute } from "../attributes/attributes.js";
|
|
5
|
-
import { ClassDeclaration } from "../ClassDeclaration.js";
|
|
6
|
-
import { Property } from "./property.js";
|
|
7
|
-
const Wrapper = props => _$createComponent(TestNamespace, {
|
|
8
|
-
get children() {
|
|
9
|
-
return _$createComponent(ClassDeclaration, {
|
|
10
|
-
"public": true,
|
|
11
|
-
name: "TestClass",
|
|
12
|
-
get children() {
|
|
13
|
-
return props.children;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
describe("modifiers", () => {
|
|
19
|
-
describe("access modifiers", () => {
|
|
20
|
-
it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
|
|
21
|
-
expect(_$createComponent(Wrapper, {
|
|
22
|
-
get children() {
|
|
23
|
-
return _$createComponent(Property, _$mergeProps({
|
|
24
|
-
[accessModifier]: true
|
|
25
|
-
}, {
|
|
26
|
-
name: "TestProp",
|
|
27
|
-
type: "string",
|
|
28
|
-
get: true
|
|
29
|
-
}));
|
|
30
|
-
}
|
|
31
|
-
})).toRenderTo(`
|
|
32
|
-
public class TestClass
|
|
33
|
-
{
|
|
34
|
-
${accessModifier} string TestProp { get; }
|
|
35
|
-
}
|
|
36
|
-
`);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
describe("property modifiers", () => {
|
|
40
|
-
it.each(["new", "static", "virtual", "sealed", "override", "abstract", "extern", "readonly", "required"])("%s", methodModifier => {
|
|
41
|
-
expect(_$createComponent(Wrapper, {
|
|
42
|
-
get children() {
|
|
43
|
-
return _$createComponent(Property, _$mergeProps({
|
|
44
|
-
[methodModifier]: true
|
|
45
|
-
}, {
|
|
46
|
-
name: "TestProp",
|
|
47
|
-
type: "string",
|
|
48
|
-
get: true
|
|
49
|
-
}));
|
|
50
|
-
}
|
|
51
|
-
})).toRenderTo(`
|
|
52
|
-
public class TestClass
|
|
53
|
-
{
|
|
54
|
-
${methodModifier} string TestProp { get; }
|
|
55
|
-
}
|
|
56
|
-
`);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
it("combine modifiers", () => {
|
|
60
|
-
expect(_$createComponent(Wrapper, {
|
|
61
|
-
get children() {
|
|
62
|
-
return _$createComponent(Property, {
|
|
63
|
-
"public": true,
|
|
64
|
-
"new": true,
|
|
65
|
-
name: "TestProp",
|
|
66
|
-
type: "string",
|
|
67
|
-
get: true
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
})).toRenderTo(`
|
|
71
|
-
public class TestClass
|
|
72
|
-
{
|
|
73
|
-
public new string TestProp { get; }
|
|
74
|
-
}
|
|
75
|
-
`);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
it("applies PascalCase naming policy", () => {
|
|
79
|
-
expect(_$createComponent(Wrapper, {
|
|
80
|
-
get children() {
|
|
81
|
-
return _$createComponent(Property, {
|
|
82
|
-
name: "test_prop",
|
|
83
|
-
type: "string",
|
|
84
|
-
get: true
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
})).toRenderTo(`
|
|
88
|
-
public class TestClass
|
|
89
|
-
{
|
|
90
|
-
string TestProp { get; }
|
|
91
|
-
}
|
|
92
|
-
`);
|
|
93
|
-
});
|
|
94
|
-
it("has getter only", () => {
|
|
95
|
-
expect(_$createComponent(Wrapper, {
|
|
96
|
-
get children() {
|
|
97
|
-
return _$createComponent(Property, {
|
|
98
|
-
name: "TestProp",
|
|
99
|
-
type: "string",
|
|
100
|
-
get: true
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
})).toRenderTo(`
|
|
104
|
-
public class TestClass
|
|
105
|
-
{
|
|
106
|
-
string TestProp { get; }
|
|
107
|
-
}
|
|
108
|
-
`);
|
|
109
|
-
});
|
|
110
|
-
it("has setter only", () => {
|
|
111
|
-
expect(_$createComponent(Wrapper, {
|
|
112
|
-
get children() {
|
|
113
|
-
return _$createComponent(Property, {
|
|
114
|
-
name: "TestProp",
|
|
115
|
-
type: "string",
|
|
116
|
-
set: true
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
})).toRenderTo(`
|
|
120
|
-
public class TestClass
|
|
121
|
-
{
|
|
122
|
-
string TestProp { set; }
|
|
123
|
-
}
|
|
124
|
-
`);
|
|
125
|
-
});
|
|
126
|
-
it("has getter and setter", () => {
|
|
127
|
-
expect(_$createComponent(Wrapper, {
|
|
128
|
-
get children() {
|
|
129
|
-
return _$createComponent(Property, {
|
|
130
|
-
name: "TestProp",
|
|
131
|
-
type: "string",
|
|
132
|
-
get: true,
|
|
133
|
-
set: true
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
})).toRenderTo(`
|
|
137
|
-
public class TestClass
|
|
138
|
-
{
|
|
139
|
-
string TestProp { get; set; }
|
|
140
|
-
}
|
|
141
|
-
`);
|
|
142
|
-
});
|
|
143
|
-
it("has getter and init", () => {
|
|
144
|
-
expect(_$createComponent(Wrapper, {
|
|
145
|
-
get children() {
|
|
146
|
-
return _$createComponent(Property, {
|
|
147
|
-
name: "TestProp",
|
|
148
|
-
type: "string",
|
|
149
|
-
get: true,
|
|
150
|
-
init: true
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
})).toRenderTo(`
|
|
154
|
-
public class TestClass
|
|
155
|
-
{
|
|
156
|
-
string TestProp { get; init; }
|
|
157
|
-
}
|
|
158
|
-
`);
|
|
159
|
-
});
|
|
160
|
-
it("specify doc comment", () => {
|
|
161
|
-
expect(_$createComponent(TestNamespace, {
|
|
162
|
-
get children() {
|
|
163
|
-
return _$createComponent(ClassDeclaration, {
|
|
164
|
-
name: "Test",
|
|
165
|
-
get children() {
|
|
166
|
-
return _$createComponent(Property, {
|
|
167
|
-
name: "Method",
|
|
168
|
-
type: "string",
|
|
169
|
-
get: true,
|
|
170
|
-
set: true,
|
|
171
|
-
doc: "This is a test"
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
})).toRenderTo(`
|
|
177
|
-
class Test
|
|
178
|
-
{
|
|
179
|
-
/// This is a test
|
|
180
|
-
string Method { get; set; }
|
|
181
|
-
}
|
|
182
|
-
`);
|
|
183
|
-
});
|
|
184
|
-
it("specify nullable property", () => {
|
|
185
|
-
expect(_$createComponent(Wrapper, {
|
|
186
|
-
get children() {
|
|
187
|
-
return _$createComponent(Property, {
|
|
188
|
-
name: "TestProp",
|
|
189
|
-
type: "string",
|
|
190
|
-
nullable: true,
|
|
191
|
-
get: true,
|
|
192
|
-
set: true
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
})).toRenderTo(`
|
|
196
|
-
public class TestClass
|
|
197
|
-
{
|
|
198
|
-
string? TestProp { get; set; }
|
|
199
|
-
}
|
|
200
|
-
`);
|
|
201
|
-
});
|
|
202
|
-
it("specify initializer", () => {
|
|
203
|
-
expect(_$createComponent(Wrapper, {
|
|
204
|
-
get children() {
|
|
205
|
-
return _$createComponent(Property, {
|
|
206
|
-
name: "TestProp",
|
|
207
|
-
type: "string",
|
|
208
|
-
get: true,
|
|
209
|
-
set: true,
|
|
210
|
-
initializer: `"abc"`
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
})).toRenderTo(`
|
|
214
|
-
public class TestClass
|
|
215
|
-
{
|
|
216
|
-
string TestProp { get; set; } = "abc";
|
|
217
|
-
}
|
|
218
|
-
`);
|
|
219
|
-
});
|
|
220
|
-
it("specify attributes", () => {
|
|
221
|
-
expect(_$createComponent(Wrapper, {
|
|
222
|
-
get children() {
|
|
223
|
-
return _$createComponent(Property, {
|
|
224
|
-
name: "Test",
|
|
225
|
-
type: "int",
|
|
226
|
-
get attributes() {
|
|
227
|
-
return [_$createComponent(Attribute, {
|
|
228
|
-
name: "Test"
|
|
229
|
-
})];
|
|
230
|
-
},
|
|
231
|
-
get: true,
|
|
232
|
-
set: true
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
})).toRenderTo(`
|
|
236
|
-
public class TestClass
|
|
237
|
-
{
|
|
238
|
-
[Test]
|
|
239
|
-
int Test { get; set; }
|
|
240
|
-
}
|
|
241
|
-
`);
|
|
242
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import * as core from "@alloy-js/core";
|
|
2
|
-
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
-
export interface RecordModifiers {
|
|
4
|
-
readonly partial?: boolean;
|
|
5
|
-
}
|
|
6
|
-
/** Props to use the {@link RecordDeclaration} component */
|
|
7
|
-
export interface RecordDeclarationProps extends Omit<core.DeclarationProps, "nameKind">, AccessModifiers, RecordModifiers {
|
|
8
|
-
name: string;
|
|
9
|
-
/** Doc comment */
|
|
10
|
-
doc?: core.Children;
|
|
11
|
-
refkey?: core.Refkey;
|
|
12
|
-
typeParameters?: Record<string, core.Refkey>;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* CSharp record declaration.
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* <RecordDeclaration public name="IMyRecord">
|
|
19
|
-
* <RecordMember public name="MyProperty" type="int" />
|
|
20
|
-
* <RecordMethod public name="MyMethod" returnType="void">
|
|
21
|
-
* <Parameter name="value" type="int" />
|
|
22
|
-
* </RecordMethod>
|
|
23
|
-
* </RecordDeclaration>
|
|
24
|
-
* ```
|
|
25
|
-
* This will produce:
|
|
26
|
-
* ```csharp
|
|
27
|
-
* public record MyIface
|
|
28
|
-
* {
|
|
29
|
-
* public int MyProperty { get; set; }
|
|
30
|
-
* public void MyMethod(int value);
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export declare function RecordDeclaration(props: RecordDeclarationProps): core.Children;
|
|
35
|
-
//# sourceMappingURL=declaration.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/record/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAO5B,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAID,2DAA2D;AAC3D,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,eAAe;IACjB,IAAI,EAAE,MAAM,CAAC;IAEb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,iBAwD9D"}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import * as core from "@alloy-js/core";
|
|
3
|
-
import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../modifiers.js";
|
|
4
|
-
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
|
-
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
|
-
import { CSharpMemberScope } from "../../symbols/scopes.js";
|
|
7
|
-
import { DocWhen } from "../doc/comment.js";
|
|
8
|
-
import { Name } from "../Name.js";
|
|
9
|
-
const getRecordModifiers = makeModifiers(["partial"]);
|
|
10
|
-
|
|
11
|
-
/** Props to use the {@link RecordDeclaration} component */
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* CSharp record declaration.
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* <RecordDeclaration public name="IMyRecord">
|
|
18
|
-
* <RecordMember public name="MyProperty" type="int" />
|
|
19
|
-
* <RecordMethod public name="MyMethod" returnType="void">
|
|
20
|
-
* <Parameter name="value" type="int" />
|
|
21
|
-
* </RecordMethod>
|
|
22
|
-
* </RecordDeclaration>
|
|
23
|
-
* ```
|
|
24
|
-
* This will produce:
|
|
25
|
-
* ```csharp
|
|
26
|
-
* public record MyIface
|
|
27
|
-
* {
|
|
28
|
-
* public int MyProperty { get; set; }
|
|
29
|
-
* public void MyMethod(int value);
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export function RecordDeclaration(props) {
|
|
34
|
-
const name = useCSharpNamePolicy().getName(props.name, "record");
|
|
35
|
-
const thisRecordSymbol = new CSharpOutputSymbol(name, {
|
|
36
|
-
refkeys: props.refkey
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// this creates a new scope for the record definition.
|
|
40
|
-
// members will automatically "inherit" this scope so
|
|
41
|
-
// that refkeys to them will produce the fully-qualified
|
|
42
|
-
// name e.g. Foo.Bar.
|
|
43
|
-
const thisRecordScope = new CSharpMemberScope("record-decl", {
|
|
44
|
-
owner: thisRecordSymbol
|
|
45
|
-
});
|
|
46
|
-
let typeParams;
|
|
47
|
-
if (props.typeParameters) {
|
|
48
|
-
const typeParamNames = new Array();
|
|
49
|
-
for (const entry of Object.entries(props.typeParameters)) {
|
|
50
|
-
typeParamNames.push(useCSharpNamePolicy().getName(entry[0], "type-parameter"));
|
|
51
|
-
// create a symbol for each type param so its
|
|
52
|
-
// refkey resolves to the type param's name
|
|
53
|
-
new CSharpOutputSymbol(entry[0], {
|
|
54
|
-
scope: thisRecordScope,
|
|
55
|
-
refkeys: entry[1]
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
typeParams = _$createIntrinsic("group", {
|
|
59
|
-
get children() {
|
|
60
|
-
return ["<", _$createComponent(core.For, {
|
|
61
|
-
each: typeParamNames,
|
|
62
|
-
comma: true,
|
|
63
|
-
line: true,
|
|
64
|
-
children: name => name
|
|
65
|
-
}), ">"];
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
const modifiers = computeModifiersPrefix([getAccessModifier(props), getRecordModifiers(props)]);
|
|
70
|
-
return _$createComponent(core.Declaration, {
|
|
71
|
-
symbol: thisRecordSymbol,
|
|
72
|
-
get children() {
|
|
73
|
-
return [_$createComponent(DocWhen, {
|
|
74
|
-
get doc() {
|
|
75
|
-
return props.doc;
|
|
76
|
-
}
|
|
77
|
-
}), modifiers, "record ", _$createComponent(Name, {}), typeParams, _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(core.Block, {
|
|
78
|
-
newline: true,
|
|
79
|
-
get children() {
|
|
80
|
-
return _$createComponent(core.Scope, {
|
|
81
|
-
value: thisRecordScope,
|
|
82
|
-
get children() {
|
|
83
|
-
return props.children;
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}) : ";")];
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"declaration.test.d.ts","sourceRoot":"","sources":["../../../../src/components/record/declaration.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { TestNamespace } from "../../../test/utils.js";
|
|
4
|
-
import { Property } from "../property/property.js";
|
|
5
|
-
import { RecordDeclaration } from "./declaration.js";
|
|
6
|
-
it("declares class with no members", () => {
|
|
7
|
-
expect(_$createComponent(TestNamespace, {
|
|
8
|
-
get children() {
|
|
9
|
-
return _$createComponent(RecordDeclaration, {
|
|
10
|
-
name: "TestRecord"
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
})).toRenderTo(`
|
|
14
|
-
record TestRecord;
|
|
15
|
-
`);
|
|
16
|
-
});
|
|
17
|
-
describe("modifiers", () => {
|
|
18
|
-
it.each(["public", "private", "internal"])("%s", mod => {
|
|
19
|
-
expect(_$createComponent(TestNamespace, {
|
|
20
|
-
get children() {
|
|
21
|
-
return _$createComponent(RecordDeclaration, _$mergeProps({
|
|
22
|
-
[mod]: true
|
|
23
|
-
}, {
|
|
24
|
-
name: "TestRecord"
|
|
25
|
-
}));
|
|
26
|
-
}
|
|
27
|
-
})).toRenderTo(`
|
|
28
|
-
${mod} record TestRecord;
|
|
29
|
-
`);
|
|
30
|
-
});
|
|
31
|
-
it.each(["partial"])("%s", mod => {
|
|
32
|
-
expect(_$createComponent(TestNamespace, {
|
|
33
|
-
get children() {
|
|
34
|
-
return _$createComponent(RecordDeclaration, _$mergeProps({
|
|
35
|
-
[mod]: true
|
|
36
|
-
}, {
|
|
37
|
-
name: "TestRecord"
|
|
38
|
-
}));
|
|
39
|
-
}
|
|
40
|
-
})).toRenderTo(`
|
|
41
|
-
${mod} record TestRecord;
|
|
42
|
-
`);
|
|
43
|
-
});
|
|
44
|
-
it("combines modifiers", () => {
|
|
45
|
-
expect(_$createComponent(TestNamespace, {
|
|
46
|
-
get children() {
|
|
47
|
-
return _$createComponent(RecordDeclaration, {
|
|
48
|
-
"public": true,
|
|
49
|
-
partial: true,
|
|
50
|
-
name: "TestRecord"
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
})).toRenderTo(`
|
|
54
|
-
public partial record TestRecord;
|
|
55
|
-
`);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
it("specify doc comment", () => {
|
|
59
|
-
expect(_$createComponent(TestNamespace, {
|
|
60
|
-
get children() {
|
|
61
|
-
return _$createComponent(RecordDeclaration, {
|
|
62
|
-
name: "TestRecord",
|
|
63
|
-
doc: "This is a test"
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
})).toRenderTo(`
|
|
67
|
-
/// This is a test
|
|
68
|
-
record TestRecord;
|
|
69
|
-
`);
|
|
70
|
-
});
|
|
71
|
-
it("specify class property inside", () => {
|
|
72
|
-
expect(_$createComponent(TestNamespace, {
|
|
73
|
-
get children() {
|
|
74
|
-
return _$createComponent(RecordDeclaration, {
|
|
75
|
-
name: "TestRecord",
|
|
76
|
-
doc: "This is a test",
|
|
77
|
-
get children() {
|
|
78
|
-
return _$createComponent(Property, {
|
|
79
|
-
name: "Prop",
|
|
80
|
-
get: true,
|
|
81
|
-
set: true,
|
|
82
|
-
type: "string"
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
})).toRenderTo(`
|
|
88
|
-
/// This is a test
|
|
89
|
-
record TestRecord
|
|
90
|
-
{
|
|
91
|
-
string Prop { get; set; }
|
|
92
|
-
}
|
|
93
|
-
`);
|
|
94
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Children } from "@alloy-js/core";
|
|
2
|
-
import { TypeParameterProps } from "./type-parameter.jsx";
|
|
3
|
-
export interface TypeParameterConstraintsProps {
|
|
4
|
-
/** Parameters */
|
|
5
|
-
parameters: (TypeParameterProps | string)[];
|
|
6
|
-
}
|
|
7
|
-
export declare function TypeParameterConstraints(props: TypeParameterConstraintsProps): Children;
|
|
8
|
-
//# sourceMappingURL=type-parameter-constraints.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type-parameter-constraints.d.ts","sourceRoot":"","sources":["../../../../src/components/type-parameters/type-parameter-constraints.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAqB,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,MAAM,WAAW,6BAA6B;IAC5C,iBAAiB;IACjB,UAAU,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;CAC7C;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,6BAA6B,GACnC,QAAQ,CAcV"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { code, For, Indent } from "@alloy-js/core";
|
|
3
|
-
import { normalizeParameters } from "./type-parameters.js";
|
|
4
|
-
export function TypeParameterConstraints(props) {
|
|
5
|
-
const parameters = normalizeParameters(props.parameters);
|
|
6
|
-
if (!parameters.some(x => x.constraints)) {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
return _$createIntrinsic("group", {
|
|
10
|
-
get children() {
|
|
11
|
-
return _$createComponent(Indent, {
|
|
12
|
-
line: true,
|
|
13
|
-
get children() {
|
|
14
|
-
return _$createComponent(For, {
|
|
15
|
-
each: parameters,
|
|
16
|
-
hardline: true,
|
|
17
|
-
children: param => _$createComponent(TypeParameterConstraint, param)
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
function TypeParameterConstraint(props) {
|
|
25
|
-
const constraints = arrayify(props.constraints);
|
|
26
|
-
return ["where ", _$memo(() => code`${props.name} : `), _$createIntrinsic("group", {
|
|
27
|
-
get children() {
|
|
28
|
-
return _$createComponent(Indent, {
|
|
29
|
-
softline: true,
|
|
30
|
-
get children() {
|
|
31
|
-
return _$createComponent(For, {
|
|
32
|
-
each: constraints,
|
|
33
|
-
comma: true,
|
|
34
|
-
line: true,
|
|
35
|
-
children: constraint => code`${constraint}`
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
})];
|
|
41
|
-
}
|
|
42
|
-
function arrayify(value) {
|
|
43
|
-
return Array.isArray(value) ? value : [value];
|
|
44
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type-parameter-constraints.test.d.ts","sourceRoot":"","sources":["../../../../src/components/type-parameters/type-parameter-constraints.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { expect, it } from "vitest";
|
|
3
|
-
import { TypeParameterConstraints } from "./type-parameter-constraints.js";
|
|
4
|
-
it("renders nothing if there is no constraints", () => {
|
|
5
|
-
expect(_$createComponent(TypeParameterConstraints, {
|
|
6
|
-
parameters: ["A", "B"]
|
|
7
|
-
})).toRenderTo(``);
|
|
8
|
-
});
|
|
9
|
-
it("renders inline if there is only one", () => {
|
|
10
|
-
expect(["code()", _$createComponent(TypeParameterConstraints, {
|
|
11
|
-
parameters: [{
|
|
12
|
-
name: "A",
|
|
13
|
-
constraints: "string"
|
|
14
|
-
}]
|
|
15
|
-
})]).toRenderTo(`
|
|
16
|
-
code() where A : string
|
|
17
|
-
`);
|
|
18
|
-
});
|
|
19
|
-
it("renders multiple constraints", () => {
|
|
20
|
-
expect(["code()", _$createComponent(TypeParameterConstraints, {
|
|
21
|
-
parameters: [{
|
|
22
|
-
name: "A",
|
|
23
|
-
constraints: ["string", "int"]
|
|
24
|
-
}]
|
|
25
|
-
})]).toRenderTo(`
|
|
26
|
-
code() where A : string, int
|
|
27
|
-
`);
|
|
28
|
-
});
|
|
29
|
-
it("renders newline if constraint is very long", () => {
|
|
30
|
-
expect(["code()", _$createComponent(TypeParameterConstraints, {
|
|
31
|
-
parameters: [{
|
|
32
|
-
name: "ThisIsQuiteALongName",
|
|
33
|
-
constraints: "VeryLongBuilderFactorySingletonThatShouldBeSplit"
|
|
34
|
-
}]
|
|
35
|
-
})]).toRenderTo(`
|
|
36
|
-
code()
|
|
37
|
-
where ThisIsQuiteALongName : VeryLongBuilderFactorySingletonThatShouldBeSplit
|
|
38
|
-
`);
|
|
39
|
-
});
|
|
40
|
-
it("renders multiple constraints on new lines if they are very long", () => {
|
|
41
|
-
expect(["code()", _$createComponent(TypeParameterConstraints, {
|
|
42
|
-
parameters: [{
|
|
43
|
-
name: "A",
|
|
44
|
-
constraints: ["IVeryLongBuilderFactorySingletonThatShouldBeSplitA", "IVeryLongBuilderFactorySingletonThatShouldBeSplitB"]
|
|
45
|
-
}]
|
|
46
|
-
})]).toRenderTo(`
|
|
47
|
-
code()
|
|
48
|
-
where A :
|
|
49
|
-
IVeryLongBuilderFactorySingletonThatShouldBeSplitA,
|
|
50
|
-
IVeryLongBuilderFactorySingletonThatShouldBeSplitB
|
|
51
|
-
`);
|
|
52
|
-
});
|
|
53
|
-
it("declare type parameters using parameters", () => {
|
|
54
|
-
expect(["code()", _$createComponent(TypeParameterConstraints, {
|
|
55
|
-
parameters: [{
|
|
56
|
-
name: "A",
|
|
57
|
-
constraints: "string"
|
|
58
|
-
}, {
|
|
59
|
-
name: "B",
|
|
60
|
-
constraints: "string"
|
|
61
|
-
}]
|
|
62
|
-
})]).toRenderTo(`
|
|
63
|
-
code()
|
|
64
|
-
where A : string
|
|
65
|
-
where B : string
|
|
66
|
-
`);
|
|
67
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Children, Refkey } from "@alloy-js/core";
|
|
2
|
-
/**
|
|
3
|
-
* Information for a TypeScript generic type parameter.
|
|
4
|
-
*/
|
|
5
|
-
export interface TypeParameterProps {
|
|
6
|
-
/**
|
|
7
|
-
* The name of the type parameter.
|
|
8
|
-
*/
|
|
9
|
-
readonly name: string;
|
|
10
|
-
/**
|
|
11
|
-
* The parameter constraint
|
|
12
|
-
*/
|
|
13
|
-
readonly constraints?: Children | Children[];
|
|
14
|
-
/**
|
|
15
|
-
* A refkey or array of refkeys for this type parameter.
|
|
16
|
-
*/
|
|
17
|
-
readonly refkey?: Refkey | Refkey[];
|
|
18
|
-
}
|
|
19
|
-
export declare function TypeParameter(props: TypeParameterProps): Children;
|
|
20
|
-
//# sourceMappingURL=type-parameter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type-parameter.d.ts","sourceRoot":"","sources":["../../../../src/components/type-parameters/type-parameter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA6B,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAK7E;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAAC;IAE7C;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACrC;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,YAStD"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { MemberDeclaration, refkey } from "@alloy-js/core";
|
|
3
|
-
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
4
|
-
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
5
|
-
import { useCSharpScope } from "../../symbols/scopes.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Information for a TypeScript generic type parameter.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export function TypeParameter(props) {
|
|
12
|
-
const name = useCSharpNamePolicy().getName(props.name, "type-parameter");
|
|
13
|
-
const scope = useCSharpScope();
|
|
14
|
-
const symbol = new CSharpOutputSymbol(name, {
|
|
15
|
-
scope,
|
|
16
|
-
refkeys: props.refkey ?? refkey(props.name)
|
|
17
|
-
});
|
|
18
|
-
return _$createComponent(MemberDeclaration, {
|
|
19
|
-
symbol: symbol,
|
|
20
|
-
children: name
|
|
21
|
-
});
|
|
22
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { TypeParameterProps } from "./type-parameter.jsx";
|
|
2
|
-
export declare const typeParametersTag: unique symbol;
|
|
3
|
-
export interface TypeParametersProps {
|
|
4
|
-
/** Parameters */
|
|
5
|
-
parameters: (TypeParameterProps | string)[];
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Represent type parameters
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* <A, B extends string>
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export declare const TypeParameters: import("@alloy-js/core").Component<TypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<TypeParametersProps>, "tag">>;
|
|
16
|
-
export declare function normalizeParameters(parameters: (TypeParameterProps | string)[]): TypeParameterProps[];
|
|
17
|
-
//# sourceMappingURL=type-parameters.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type-parameters.d.ts","sourceRoot":"","sources":["../../../../src/components/type-parameters/type-parameters.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAEzE,eAAO,MAAM,iBAAiB,eAAuC,CAAC;AAEtE,MAAM,WAAW,mBAAmB;IAClC,iBAAiB;IACjB,UAAU,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,0IAmB1B,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,GAC1C,kBAAkB,EAAE,CAOtB"}
|