@alloy-js/csharp 0.18.0-dev.24 → 0.18.0-dev.4
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 +23 -0
- package/dist/src/components/Class.d.ts.map +1 -0
- package/dist/src/components/{ClassDeclaration.js → Class.js} +37 -67
- package/dist/src/components/ClassMethod.d.ts +3 -44
- package/dist/src/components/ClassMethod.d.ts.map +1 -1
- package/dist/src/components/ClassMethod.js +8 -32
- package/dist/src/components/Enum.d.ts +14 -0
- package/dist/src/components/Enum.d.ts.map +1 -0
- package/dist/src/components/{EnumDeclaration.js → Enum.js} +2 -21
- 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 +9 -2
- package/dist/src/modifiers.d.ts.map +1 -1
- package/dist/src/modifiers.js +9 -6
- 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 +2 -23
- package/dist/test/class.test.d.ts +2 -0
- package/dist/test/class.test.d.ts.map +1 -0
- package/dist/test/{class-declaration.test.js → class.test.js} +51 -234
- package/dist/test/enum.test.js +6 -6
- package/dist/test/namespace.test.js +4 -4
- 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} +4 -4
- package/dist/test/sourcefile.test.js +2 -2
- package/dist/test/using.test.js +4 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/src/components/{ClassDeclaration.tsx → Class.tsx} +38 -116
- package/src/components/ClassMethod.tsx +7 -70
- package/src/components/{EnumDeclaration.tsx → Enum.tsx} +3 -22
- 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 +30 -16
- package/src/name-policy.ts +0 -5
- package/temp/api.json +1194 -6218
- package/test/class-method.test.tsx +3 -19
- package/test/class.test.tsx +257 -0
- package/test/enum.test.tsx +11 -13
- 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 +6 -14
- 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/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/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,300 +0,0 @@
|
|
|
1
|
-
import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { refkey } from "@alloy-js/core";
|
|
3
|
-
import { describe, expect, it } from "vitest";
|
|
4
|
-
import { TestNamespace } from "../../../test/utils.js";
|
|
5
|
-
import { Attribute } from "../attributes/attributes.js";
|
|
6
|
-
import { SourceFile } from "../SourceFile.js";
|
|
7
|
-
import { InterfaceDeclaration } from "./declaration.js";
|
|
8
|
-
import { InterfaceMethod } from "./method.js";
|
|
9
|
-
const Wrapper = props => _$createComponent(TestNamespace, {
|
|
10
|
-
get children() {
|
|
11
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
12
|
-
"public": true,
|
|
13
|
-
name: "TestInterface",
|
|
14
|
-
get children() {
|
|
15
|
-
return props.children;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
describe("modifiers", () => {
|
|
21
|
-
describe("access modifiers", () => {
|
|
22
|
-
it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
|
|
23
|
-
expect(_$createComponent(Wrapper, {
|
|
24
|
-
get children() {
|
|
25
|
-
return _$createComponent(InterfaceMethod, _$mergeProps({
|
|
26
|
-
[accessModifier]: true
|
|
27
|
-
}, {
|
|
28
|
-
name: "MethodOne"
|
|
29
|
-
}));
|
|
30
|
-
}
|
|
31
|
-
})).toRenderTo(`
|
|
32
|
-
public interface TestInterface
|
|
33
|
-
{
|
|
34
|
-
${accessModifier} void MethodOne();
|
|
35
|
-
}
|
|
36
|
-
`);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
describe("method modifiers", () => {
|
|
40
|
-
it.each(["new"])("%s", methodModifier => {
|
|
41
|
-
expect(_$createComponent(Wrapper, {
|
|
42
|
-
get children() {
|
|
43
|
-
return _$createComponent(InterfaceMethod, _$mergeProps({
|
|
44
|
-
[methodModifier]: true
|
|
45
|
-
}, {
|
|
46
|
-
name: "MethodOne"
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
})).toRenderTo(`
|
|
50
|
-
public interface TestInterface
|
|
51
|
-
{
|
|
52
|
-
${methodModifier} void MethodOne();
|
|
53
|
-
}
|
|
54
|
-
`);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
it("combine modifiers", () => {
|
|
58
|
-
expect(_$createComponent(Wrapper, {
|
|
59
|
-
get children() {
|
|
60
|
-
return _$createComponent(InterfaceMethod, {
|
|
61
|
-
returns: "Task",
|
|
62
|
-
"public": true,
|
|
63
|
-
"new": true,
|
|
64
|
-
name: "MethodOne"
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
})).toRenderTo(`
|
|
68
|
-
public interface TestInterface
|
|
69
|
-
{
|
|
70
|
-
public new Task MethodOne();
|
|
71
|
-
}
|
|
72
|
-
`);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
it("applies PascalCase naming policy", () => {
|
|
76
|
-
expect(_$createComponent(Wrapper, {
|
|
77
|
-
get children() {
|
|
78
|
-
return _$createComponent(InterfaceMethod, {
|
|
79
|
-
name: "method_one"
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
})).toRenderTo(`
|
|
83
|
-
public interface TestInterface
|
|
84
|
-
{
|
|
85
|
-
void MethodOne();
|
|
86
|
-
}
|
|
87
|
-
`);
|
|
88
|
-
});
|
|
89
|
-
it("defines params and return type", () => {
|
|
90
|
-
const params = [{
|
|
91
|
-
name: "intParam",
|
|
92
|
-
type: "int"
|
|
93
|
-
}, {
|
|
94
|
-
name: "stringParam",
|
|
95
|
-
type: "string"
|
|
96
|
-
}];
|
|
97
|
-
const res = _$createComponent(Wrapper, {
|
|
98
|
-
get children() {
|
|
99
|
-
return _$createComponent(InterfaceMethod, {
|
|
100
|
-
"public": true,
|
|
101
|
-
name: "MethodOne",
|
|
102
|
-
parameters: params,
|
|
103
|
-
returns: "string"
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
expect(res).toRenderTo(`
|
|
108
|
-
public interface TestInterface
|
|
109
|
-
{
|
|
110
|
-
public string MethodOne(int intParam, string stringParam);
|
|
111
|
-
}
|
|
112
|
-
`);
|
|
113
|
-
});
|
|
114
|
-
it("defines optional param", () => {
|
|
115
|
-
const res = _$createComponent(Wrapper, {
|
|
116
|
-
get children() {
|
|
117
|
-
return _$createComponent(InterfaceMethod, {
|
|
118
|
-
"public": true,
|
|
119
|
-
name: "MethodOne",
|
|
120
|
-
parameters: [{
|
|
121
|
-
name: "intParam",
|
|
122
|
-
type: "int",
|
|
123
|
-
optional: true
|
|
124
|
-
}],
|
|
125
|
-
returns: "string"
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
expect(res).toRenderTo(`
|
|
130
|
-
public interface TestInterface
|
|
131
|
-
{
|
|
132
|
-
public string MethodOne(int? intParam);
|
|
133
|
-
}
|
|
134
|
-
`);
|
|
135
|
-
});
|
|
136
|
-
it("defines optional param with default", () => {
|
|
137
|
-
const res = _$createComponent(Wrapper, {
|
|
138
|
-
get children() {
|
|
139
|
-
return _$createComponent(InterfaceMethod, {
|
|
140
|
-
"public": true,
|
|
141
|
-
name: "MethodOne",
|
|
142
|
-
parameters: [{
|
|
143
|
-
name: "intParam",
|
|
144
|
-
type: "int",
|
|
145
|
-
default: 12
|
|
146
|
-
}],
|
|
147
|
-
returns: "string"
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
expect(res).toRenderTo(`
|
|
152
|
-
public interface TestInterface
|
|
153
|
-
{
|
|
154
|
-
public string MethodOne(int intParam = 12);
|
|
155
|
-
}
|
|
156
|
-
`);
|
|
157
|
-
});
|
|
158
|
-
it("specify doc comment", () => {
|
|
159
|
-
expect(_$createComponent(TestNamespace, {
|
|
160
|
-
get children() {
|
|
161
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
162
|
-
name: "Test",
|
|
163
|
-
get children() {
|
|
164
|
-
return _$createComponent(InterfaceMethod, {
|
|
165
|
-
name: "Method",
|
|
166
|
-
doc: "This is a test"
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
})).toRenderTo(`
|
|
172
|
-
interface Test
|
|
173
|
-
{
|
|
174
|
-
/// This is a test
|
|
175
|
-
void Method();
|
|
176
|
-
}
|
|
177
|
-
`);
|
|
178
|
-
});
|
|
179
|
-
it("specify attributes", () => {
|
|
180
|
-
expect(_$createComponent(Wrapper, {
|
|
181
|
-
get children() {
|
|
182
|
-
return _$createComponent(InterfaceMethod, {
|
|
183
|
-
name: "Test",
|
|
184
|
-
get attributes() {
|
|
185
|
-
return [_$createComponent(Attribute, {
|
|
186
|
-
name: "Test"
|
|
187
|
-
})];
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
})).toRenderTo(`
|
|
192
|
-
public interface TestInterface
|
|
193
|
-
{
|
|
194
|
-
[Test]
|
|
195
|
-
void Test();
|
|
196
|
-
}
|
|
197
|
-
`);
|
|
198
|
-
});
|
|
199
|
-
describe("with type parameters", () => {
|
|
200
|
-
it("reference parameters", () => {
|
|
201
|
-
const typeParameters = [{
|
|
202
|
-
name: "T",
|
|
203
|
-
refkey: refkey()
|
|
204
|
-
}, {
|
|
205
|
-
name: "U",
|
|
206
|
-
refkey: refkey()
|
|
207
|
-
}];
|
|
208
|
-
expect(_$createComponent(TestNamespace, {
|
|
209
|
-
get children() {
|
|
210
|
-
return _$createComponent(SourceFile, {
|
|
211
|
-
path: "TestFile.cs",
|
|
212
|
-
get children() {
|
|
213
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
214
|
-
"public": true,
|
|
215
|
-
name: "TestInterface",
|
|
216
|
-
get children() {
|
|
217
|
-
return _$createComponent(InterfaceMethod, {
|
|
218
|
-
name: "Test",
|
|
219
|
-
"public": true,
|
|
220
|
-
typeParameters: typeParameters,
|
|
221
|
-
get parameters() {
|
|
222
|
-
return [{
|
|
223
|
-
name: "paramA",
|
|
224
|
-
type: typeParameters[0].refkey
|
|
225
|
-
}];
|
|
226
|
-
},
|
|
227
|
-
get returns() {
|
|
228
|
-
return typeParameters[0].refkey;
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
})).toRenderTo(`
|
|
237
|
-
namespace TestCode
|
|
238
|
-
{
|
|
239
|
-
public interface TestInterface
|
|
240
|
-
{
|
|
241
|
-
public T Test<T, U>(T paramA);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
`);
|
|
245
|
-
});
|
|
246
|
-
it("defines with constraints", () => {
|
|
247
|
-
const typeParameters = [{
|
|
248
|
-
name: "T",
|
|
249
|
-
constraints: "IFoo"
|
|
250
|
-
}, {
|
|
251
|
-
name: "U",
|
|
252
|
-
constraints: "IBar"
|
|
253
|
-
}];
|
|
254
|
-
expect(_$createComponent(Wrapper, {
|
|
255
|
-
get children() {
|
|
256
|
-
return _$createComponent(InterfaceMethod, {
|
|
257
|
-
"public": true,
|
|
258
|
-
name: "Test",
|
|
259
|
-
typeParameters: typeParameters,
|
|
260
|
-
children: "// Body"
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
})).toRenderTo(`
|
|
264
|
-
public interface TestInterface
|
|
265
|
-
{
|
|
266
|
-
public void Test<T, U>()
|
|
267
|
-
where T : IFoo
|
|
268
|
-
where U : IBar
|
|
269
|
-
{
|
|
270
|
-
// Body
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
`);
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
describe("formatting", () => {
|
|
277
|
-
it("Split parameters before type parameters", () => {
|
|
278
|
-
expect(_$createComponent(Wrapper, {
|
|
279
|
-
get children() {
|
|
280
|
-
return _$createComponent(InterfaceMethod, {
|
|
281
|
-
"public": true,
|
|
282
|
-
name: "Handle",
|
|
283
|
-
parameters: [{
|
|
284
|
-
name: "message",
|
|
285
|
-
type: "Some.Quite.Long.Type.That.Will.Split"
|
|
286
|
-
}],
|
|
287
|
-
typeParameters: ["T"],
|
|
288
|
-
returns: "Some.Quite.Long.Type.That.Will.Split"
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
})).toRenderTo(`
|
|
292
|
-
public interface TestInterface
|
|
293
|
-
{
|
|
294
|
-
public Some.Quite.Long.Type.That.Will.Split Handle<T>(
|
|
295
|
-
Some.Quite.Long.Type.That.Will.Split message
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
`);
|
|
299
|
-
});
|
|
300
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Children, Refkey } from "@alloy-js/core";
|
|
2
|
-
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
-
import { AttributesProp } from "../attributes/attributes.jsx";
|
|
4
|
-
/** Method modifiers. Can only be one. */
|
|
5
|
-
export interface InterfacePropertyModifiers {
|
|
6
|
-
readonly new?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface InterfacePropertyProps extends AccessModifiers, InterfacePropertyModifiers {
|
|
9
|
-
name: string;
|
|
10
|
-
refkey?: Refkey;
|
|
11
|
-
/** Property type */
|
|
12
|
-
type: Children;
|
|
13
|
-
/** If property should have a getter */
|
|
14
|
-
get?: boolean;
|
|
15
|
-
/** If property should have a setter */
|
|
16
|
-
set?: boolean;
|
|
17
|
-
/** Doc comment */
|
|
18
|
-
doc?: Children;
|
|
19
|
-
/**
|
|
20
|
-
* Property initializer
|
|
21
|
-
* @example `<ClassProperty name="My" get set nullable />`
|
|
22
|
-
*
|
|
23
|
-
* ```cs
|
|
24
|
-
* int? My { get; set; };
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
nullable?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Define attributes to attach
|
|
30
|
-
* @example
|
|
31
|
-
* ```tsx
|
|
32
|
-
* <InterfaceProperty name="MyProp" attributes={[
|
|
33
|
-
* <Attribute name="Test" />
|
|
34
|
-
* <Attribute name="Test2" args={["arg1", "arg2"]} />
|
|
35
|
-
* ]} />
|
|
36
|
-
* ```
|
|
37
|
-
* This will produce:
|
|
38
|
-
* ```csharp
|
|
39
|
-
* [Test]
|
|
40
|
-
* [Test2("arg1", "arg2")]
|
|
41
|
-
* int MyProp { get; set; }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
attributes?: AttributesProp;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Render a C# interface property.
|
|
48
|
-
*
|
|
49
|
-
* @example `<InterfaceProperty public name="My" get set />`
|
|
50
|
-
*
|
|
51
|
-
* ```cs
|
|
52
|
-
* public int My { get; set; };
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export declare function InterfaceProperty(props: InterfacePropertyProps): Children;
|
|
56
|
-
//# sourceMappingURL=property.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAIR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG7E,yCAAyC;AACzC,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAKD,MAAM,WAAW,sBACf,SAAQ,eAAe,EACrB,0BAA0B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,oBAAoB;IACpB,IAAI,EAAE,QAAQ,CAAC;IAEf,uCAAuC;IACvC,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,uCAAuC;IACvC,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;IAEf;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,YAyC9D"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { Block, List, MemberDeclaration, refkey, Scope } 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, useCSharpScope } from "../../symbols/scopes.js";
|
|
7
|
-
import { AttributeList } from "../attributes/attributes.js";
|
|
8
|
-
import { DocWhen } from "../doc/comment.js";
|
|
9
|
-
|
|
10
|
-
/** Method modifiers. Can only be one. */
|
|
11
|
-
|
|
12
|
-
const getModifiers = makeModifiers(["new"]);
|
|
13
|
-
|
|
14
|
-
// properties for creating a method
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Render a C# interface property.
|
|
18
|
-
*
|
|
19
|
-
* @example `<InterfaceProperty public name="My" get set />`
|
|
20
|
-
*
|
|
21
|
-
* ```cs
|
|
22
|
-
* public int My { get; set; };
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export function InterfaceProperty(props) {
|
|
26
|
-
const name = useCSharpNamePolicy().getName(props.name, "class-property");
|
|
27
|
-
const scope = useCSharpScope();
|
|
28
|
-
if (scope.kind !== "member" || scope.name !== "interface-decl") {
|
|
29
|
-
throw new Error("can't define an interface method outside of an interface scope");
|
|
30
|
-
}
|
|
31
|
-
const propertySymbol = new CSharpOutputSymbol(name, {
|
|
32
|
-
scope,
|
|
33
|
-
refkeys: props.refkey ?? refkey(props.name)
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// scope for property declaration
|
|
37
|
-
const propertyScope = new CSharpMemberScope("property-decl", {
|
|
38
|
-
owner: propertySymbol
|
|
39
|
-
});
|
|
40
|
-
const modifiers = computeModifiersPrefix([getAccessModifier(props), getModifiers(props)]);
|
|
41
|
-
// note that scope wraps the method decl so that the params get the correct scope
|
|
42
|
-
return _$createComponent(MemberDeclaration, {
|
|
43
|
-
symbol: propertySymbol,
|
|
44
|
-
get children() {
|
|
45
|
-
return _$createComponent(Scope, {
|
|
46
|
-
value: propertyScope,
|
|
47
|
-
get children() {
|
|
48
|
-
return [_$createComponent(DocWhen, {
|
|
49
|
-
get doc() {
|
|
50
|
-
return props.doc;
|
|
51
|
-
}
|
|
52
|
-
}), _$createComponent(AttributeList, {
|
|
53
|
-
get attributes() {
|
|
54
|
-
return props.attributes;
|
|
55
|
-
},
|
|
56
|
-
endline: true
|
|
57
|
-
}), modifiers, _$memo(() => props.type), _$memo(() => props.nullable && "?"), " ", name, " ", _$createComponent(Block, {
|
|
58
|
-
newline: true,
|
|
59
|
-
inline: true,
|
|
60
|
-
get children() {
|
|
61
|
-
return _$createComponent(List, {
|
|
62
|
-
joiner: " ",
|
|
63
|
-
get children() {
|
|
64
|
-
return [_$memo(() => props.get && "get;"), _$memo(() => props.set && "set;")];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
})];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"property.test.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/property.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,189 +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 { InterfaceDeclaration } from "./declaration.js";
|
|
6
|
-
import { InterfaceProperty } from "./property.js";
|
|
7
|
-
const Wrapper = props => _$createComponent(TestNamespace, {
|
|
8
|
-
get children() {
|
|
9
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
10
|
-
"public": true,
|
|
11
|
-
name: "TestInterface",
|
|
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(InterfaceProperty, _$mergeProps({
|
|
24
|
-
[accessModifier]: true
|
|
25
|
-
}, {
|
|
26
|
-
name: "TestProp",
|
|
27
|
-
type: "string",
|
|
28
|
-
get: true
|
|
29
|
-
}));
|
|
30
|
-
}
|
|
31
|
-
})).toRenderTo(`
|
|
32
|
-
public interface TestInterface
|
|
33
|
-
{
|
|
34
|
-
${accessModifier} string TestProp { get; }
|
|
35
|
-
}
|
|
36
|
-
`);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
describe("method modifiers", () => {
|
|
40
|
-
it.each(["new"])("%s", methodModifier => {
|
|
41
|
-
expect(_$createComponent(Wrapper, {
|
|
42
|
-
get children() {
|
|
43
|
-
return _$createComponent(InterfaceProperty, _$mergeProps({
|
|
44
|
-
[methodModifier]: true
|
|
45
|
-
}, {
|
|
46
|
-
name: "TestProp",
|
|
47
|
-
type: "string",
|
|
48
|
-
get: true
|
|
49
|
-
}));
|
|
50
|
-
}
|
|
51
|
-
})).toRenderTo(`
|
|
52
|
-
public interface TestInterface
|
|
53
|
-
{
|
|
54
|
-
${methodModifier} string TestProp { get; }
|
|
55
|
-
}
|
|
56
|
-
`);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
it("combine modifiers", () => {
|
|
60
|
-
expect(_$createComponent(Wrapper, {
|
|
61
|
-
get children() {
|
|
62
|
-
return _$createComponent(InterfaceProperty, {
|
|
63
|
-
"public": true,
|
|
64
|
-
"new": true,
|
|
65
|
-
name: "TestProp",
|
|
66
|
-
type: "string",
|
|
67
|
-
get: true
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
})).toRenderTo(`
|
|
71
|
-
public interface TestInterface
|
|
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(InterfaceProperty, {
|
|
82
|
-
name: "test_prop",
|
|
83
|
-
type: "string",
|
|
84
|
-
get: true
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
})).toRenderTo(`
|
|
88
|
-
public interface TestInterface
|
|
89
|
-
{
|
|
90
|
-
string TestProp { get; }
|
|
91
|
-
}
|
|
92
|
-
`);
|
|
93
|
-
});
|
|
94
|
-
it("has getter only", () => {
|
|
95
|
-
expect(_$createComponent(Wrapper, {
|
|
96
|
-
get children() {
|
|
97
|
-
return _$createComponent(InterfaceProperty, {
|
|
98
|
-
name: "TestProp",
|
|
99
|
-
type: "string",
|
|
100
|
-
get: true
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
})).toRenderTo(`
|
|
104
|
-
public interface TestInterface
|
|
105
|
-
{
|
|
106
|
-
string TestProp { get; }
|
|
107
|
-
}
|
|
108
|
-
`);
|
|
109
|
-
});
|
|
110
|
-
it("has setter only", () => {
|
|
111
|
-
expect(_$createComponent(Wrapper, {
|
|
112
|
-
get children() {
|
|
113
|
-
return _$createComponent(InterfaceProperty, {
|
|
114
|
-
name: "TestProp",
|
|
115
|
-
type: "string",
|
|
116
|
-
set: true
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
})).toRenderTo(`
|
|
120
|
-
public interface TestInterface
|
|
121
|
-
{
|
|
122
|
-
string TestProp { set; }
|
|
123
|
-
}
|
|
124
|
-
`);
|
|
125
|
-
});
|
|
126
|
-
it("has getter and setter", () => {
|
|
127
|
-
expect(_$createComponent(Wrapper, {
|
|
128
|
-
get children() {
|
|
129
|
-
return _$createComponent(InterfaceProperty, {
|
|
130
|
-
name: "TestProp",
|
|
131
|
-
type: "string",
|
|
132
|
-
get: true,
|
|
133
|
-
set: true
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
})).toRenderTo(`
|
|
137
|
-
public interface TestInterface
|
|
138
|
-
{
|
|
139
|
-
string TestProp { get; set; }
|
|
140
|
-
}
|
|
141
|
-
`);
|
|
142
|
-
});
|
|
143
|
-
it("specify doc comment", () => {
|
|
144
|
-
expect(_$createComponent(TestNamespace, {
|
|
145
|
-
get children() {
|
|
146
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
147
|
-
name: "Test",
|
|
148
|
-
get children() {
|
|
149
|
-
return _$createComponent(InterfaceProperty, {
|
|
150
|
-
name: "Method",
|
|
151
|
-
type: "string",
|
|
152
|
-
get: true,
|
|
153
|
-
set: true,
|
|
154
|
-
doc: "This is a test"
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
})).toRenderTo(`
|
|
160
|
-
interface Test
|
|
161
|
-
{
|
|
162
|
-
/// This is a test
|
|
163
|
-
string Method { get; set; }
|
|
164
|
-
}
|
|
165
|
-
`);
|
|
166
|
-
});
|
|
167
|
-
it("specify attributes", () => {
|
|
168
|
-
expect(_$createComponent(Wrapper, {
|
|
169
|
-
get children() {
|
|
170
|
-
return _$createComponent(InterfaceProperty, {
|
|
171
|
-
name: "Test",
|
|
172
|
-
type: "int",
|
|
173
|
-
get attributes() {
|
|
174
|
-
return [_$createComponent(Attribute, {
|
|
175
|
-
name: "Test"
|
|
176
|
-
})];
|
|
177
|
-
},
|
|
178
|
-
get: true,
|
|
179
|
-
set: true
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
})).toRenderTo(`
|
|
183
|
-
public interface TestInterface
|
|
184
|
-
{
|
|
185
|
-
[Test]
|
|
186
|
-
int Test { get; set; }
|
|
187
|
-
}
|
|
188
|
-
`);
|
|
189
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Children, OutputSymbol, Refkey } from "@alloy-js/core";
|
|
2
|
-
export interface ParameterProps {
|
|
3
|
-
name: string;
|
|
4
|
-
type: Children;
|
|
5
|
-
/** If the parmaeter is optional(without default value) */
|
|
6
|
-
optional?: boolean;
|
|
7
|
-
/** Default value for the parameter */
|
|
8
|
-
default?: Children;
|
|
9
|
-
refkey?: Refkey;
|
|
10
|
-
symbol?: OutputSymbol;
|
|
11
|
-
}
|
|
12
|
-
/** Define a parameter to be used in class or interface method. */
|
|
13
|
-
export declare function Parameter(props: ParameterProps): Children;
|
|
14
|
-
export interface ParametersProps {
|
|
15
|
-
parameters: ParameterProps[] | undefined;
|
|
16
|
-
}
|
|
17
|
-
/** Render a collection of parameters */
|
|
18
|
-
export declare function Parameters(props: ParametersProps): Children;
|
|
19
|
-
//# sourceMappingURL=parameters.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parameters.d.ts","sourceRoot":"","sources":["../../../../src/components/parameters/parameters.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAKR,YAAY,EAEZ,MAAM,EACP,MAAM,gBAAgB,CAAC;AAMxB,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sCAAsC;IACtC,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,YAwB9C;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;CAC1C;AAED,wCAAwC;AACxC,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,YAehD"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { code, Declaration, For, Indent, 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
|
-
import { Name } from "../Name.js";
|
|
7
|
-
/** Define a parameter to be used in class or interface method. */
|
|
8
|
-
export function Parameter(props) {
|
|
9
|
-
const name = useCSharpNamePolicy().getName(props.name, "parameter");
|
|
10
|
-
const scope = useCSharpScope();
|
|
11
|
-
if (scope.kind !== "member" || scope.name !== "constructor-decl" && scope.name !== "method-decl") {
|
|
12
|
-
throw new Error("can't define a parameter outside of a constructor-decl or method-decl scope");
|
|
13
|
-
}
|
|
14
|
-
const memberSymbol = new CSharpOutputSymbol(name, {
|
|
15
|
-
scope,
|
|
16
|
-
refkeys: props.refkey ?? refkey(props.name)
|
|
17
|
-
});
|
|
18
|
-
return _$createComponent(Declaration, {
|
|
19
|
-
symbol: memberSymbol,
|
|
20
|
-
get children() {
|
|
21
|
-
return [_$memo(() => props.type), _$memo(() => props.optional ? "?" : ""), " ", _$createComponent(Name, {}), _$memo(() => props.default ? code` = ${props.default}` : "")];
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
/** Render a collection of parameters */
|
|
26
|
-
export function Parameters(props) {
|
|
27
|
-
return _$createIntrinsic("group", {
|
|
28
|
-
get children() {
|
|
29
|
-
return ["(", _$memo(() => _$memo(() => !!props.parameters)() && _$createComponent(Indent, {
|
|
30
|
-
softline: true,
|
|
31
|
-
get children() {
|
|
32
|
-
return _$createComponent(For, {
|
|
33
|
-
get each() {
|
|
34
|
-
return props.parameters;
|
|
35
|
-
},
|
|
36
|
-
joiner: ", ",
|
|
37
|
-
children: param => _$createComponent(Parameter, param)
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
})), _$createIntrinsic("softline", {}), ")"];
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|