@alloy-js/csharp 0.18.0-dev.19 → 0.18.0-dev.2
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} +32 -59
- package/dist/src/components/ClassMethod.d.ts +4 -25
- package/dist/src/components/ClassMethod.d.ts.map +1 -1
- package/dist/src/components/ClassMethod.js +3 -22
- 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 +1 -6
- package/dist/src/components/Parameters.d.ts.map +1 -1
- package/dist/src/components/Parameters.js +2 -3
- package/dist/src/components/index.d.ts +3 -12
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +4 -13
- 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 +21 -21
- package/src/components/{ClassDeclaration.tsx → Class.tsx} +43 -108
- package/src/components/ClassMethod.tsx +12 -53
- package/src/components/{EnumDeclaration.tsx → Enum.tsx} +6 -30
- package/src/components/Parameters.tsx +3 -10
- package/src/components/index.ts +3 -12
- 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 +714 -5256
- 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/LICENSE +0 -7
- package/dist/src/components/ClassDeclaration.d.ts +0 -74
- 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/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 -47
- package/dist/src/components/interface/declaration.d.ts.map +0 -1
- package/dist/src/components/interface/declaration.js +0 -77
- 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 -153
- package/dist/src/components/interface/method.d.ts +0 -32
- package/dist/src/components/interface/method.d.ts.map +0 -1
- package/dist/src/components/interface/method.js +0 -69
- 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 -254
- package/dist/src/components/interface/property.d.ts +0 -38
- package/dist/src/components/interface/property.d.ts.map +0 -1
- package/dist/src/components/interface/property.js +0 -67
- 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 -165
- package/dist/src/components/property/property.d.ts +0 -57
- package/dist/src/components/property/property.d.ts.map +0 -1
- package/dist/src/components/property/property.js +0 -70
- 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 -218
- 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 -65
- 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 -26
- 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 -463
- 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/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 -143
- package/src/components/interface/declaration.tsx +0 -105
- package/src/components/interface/method.test.tsx +0 -250
- package/src/components/interface/method.tsx +0 -105
- package/src/components/interface/property.test.tsx +0 -144
- package/src/components/interface/property.tsx +0 -107
- package/src/components/property/property.test.tsx +0 -187
- package/src/components/property/property.tsx +0 -146
- 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 -19
- package/src/components/type-parameters/type-parameters.tsx +0 -72
- package/src/components/var/declaration.test.tsx +0 -59
- package/src/components/var/declaration.tsx +0 -47
- package/test/class-declaration.test.tsx +0 -418
- package/test/vitest.setup.ts +0 -1
|
@@ -1,254 +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 { SourceFile } from "../SourceFile.js";
|
|
6
|
-
import { InterfaceDeclaration } from "./declaration.js";
|
|
7
|
-
import { InterfaceMethod } from "./method.js";
|
|
8
|
-
const Wrapper = props => _$createComponent(TestNamespace, {
|
|
9
|
-
get children() {
|
|
10
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
11
|
-
"public": true,
|
|
12
|
-
name: "TestInterface",
|
|
13
|
-
get children() {
|
|
14
|
-
return props.children;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
describe("modifiers", () => {
|
|
20
|
-
describe("access modifiers", () => {
|
|
21
|
-
it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
|
|
22
|
-
expect(_$createComponent(Wrapper, {
|
|
23
|
-
get children() {
|
|
24
|
-
return _$createComponent(InterfaceMethod, _$mergeProps({
|
|
25
|
-
[accessModifier]: true
|
|
26
|
-
}, {
|
|
27
|
-
name: "MethodOne"
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
})).toRenderTo(`
|
|
31
|
-
public interface TestInterface
|
|
32
|
-
{
|
|
33
|
-
${accessModifier} void MethodOne();
|
|
34
|
-
}
|
|
35
|
-
`);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
describe("method modifiers", () => {
|
|
39
|
-
it.each(["new"])("%s", methodModifier => {
|
|
40
|
-
expect(_$createComponent(Wrapper, {
|
|
41
|
-
get children() {
|
|
42
|
-
return _$createComponent(InterfaceMethod, _$mergeProps({
|
|
43
|
-
[methodModifier]: true
|
|
44
|
-
}, {
|
|
45
|
-
name: "MethodOne"
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
})).toRenderTo(`
|
|
49
|
-
public interface TestInterface
|
|
50
|
-
{
|
|
51
|
-
${methodModifier} void MethodOne();
|
|
52
|
-
}
|
|
53
|
-
`);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
it("combine modifiers", () => {
|
|
57
|
-
expect(_$createComponent(Wrapper, {
|
|
58
|
-
get children() {
|
|
59
|
-
return _$createComponent(InterfaceMethod, {
|
|
60
|
-
returns: "Task",
|
|
61
|
-
"public": true,
|
|
62
|
-
"new": true,
|
|
63
|
-
name: "MethodOne"
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
})).toRenderTo(`
|
|
67
|
-
public interface TestInterface
|
|
68
|
-
{
|
|
69
|
-
public new Task MethodOne();
|
|
70
|
-
}
|
|
71
|
-
`);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
it("applies PascalCase naming policy", () => {
|
|
75
|
-
expect(_$createComponent(Wrapper, {
|
|
76
|
-
get children() {
|
|
77
|
-
return _$createComponent(InterfaceMethod, {
|
|
78
|
-
name: "method_one"
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
})).toRenderTo(`
|
|
82
|
-
public interface TestInterface
|
|
83
|
-
{
|
|
84
|
-
void MethodOne();
|
|
85
|
-
}
|
|
86
|
-
`);
|
|
87
|
-
});
|
|
88
|
-
it("defines params and return type", () => {
|
|
89
|
-
const params = [{
|
|
90
|
-
name: "intParam",
|
|
91
|
-
type: "int"
|
|
92
|
-
}, {
|
|
93
|
-
name: "stringParam",
|
|
94
|
-
type: "string"
|
|
95
|
-
}];
|
|
96
|
-
const res = _$createComponent(Wrapper, {
|
|
97
|
-
get children() {
|
|
98
|
-
return _$createComponent(InterfaceMethod, {
|
|
99
|
-
"public": true,
|
|
100
|
-
name: "MethodOne",
|
|
101
|
-
parameters: params,
|
|
102
|
-
returns: "string"
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
expect(res).toRenderTo(`
|
|
107
|
-
public interface TestInterface
|
|
108
|
-
{
|
|
109
|
-
public string MethodOne(int intParam, string stringParam);
|
|
110
|
-
}
|
|
111
|
-
`);
|
|
112
|
-
});
|
|
113
|
-
it("defines optional param", () => {
|
|
114
|
-
const res = _$createComponent(Wrapper, {
|
|
115
|
-
get children() {
|
|
116
|
-
return _$createComponent(InterfaceMethod, {
|
|
117
|
-
"public": true,
|
|
118
|
-
name: "MethodOne",
|
|
119
|
-
parameters: [{
|
|
120
|
-
name: "intParam",
|
|
121
|
-
type: "int",
|
|
122
|
-
optional: true
|
|
123
|
-
}],
|
|
124
|
-
returns: "string"
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
expect(res).toRenderTo(`
|
|
129
|
-
public interface TestInterface
|
|
130
|
-
{
|
|
131
|
-
public string MethodOne(int? intParam);
|
|
132
|
-
}
|
|
133
|
-
`);
|
|
134
|
-
});
|
|
135
|
-
it("defines optional param with default", () => {
|
|
136
|
-
const res = _$createComponent(Wrapper, {
|
|
137
|
-
get children() {
|
|
138
|
-
return _$createComponent(InterfaceMethod, {
|
|
139
|
-
"public": true,
|
|
140
|
-
name: "MethodOne",
|
|
141
|
-
parameters: [{
|
|
142
|
-
name: "intParam",
|
|
143
|
-
type: "int",
|
|
144
|
-
default: 12
|
|
145
|
-
}],
|
|
146
|
-
returns: "string"
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
expect(res).toRenderTo(`
|
|
151
|
-
public interface TestInterface
|
|
152
|
-
{
|
|
153
|
-
public string MethodOne(int intParam = 12);
|
|
154
|
-
}
|
|
155
|
-
`);
|
|
156
|
-
});
|
|
157
|
-
it("specify doc comment", () => {
|
|
158
|
-
expect(_$createComponent(TestNamespace, {
|
|
159
|
-
get children() {
|
|
160
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
161
|
-
name: "Test",
|
|
162
|
-
get children() {
|
|
163
|
-
return _$createComponent(InterfaceMethod, {
|
|
164
|
-
name: "Method",
|
|
165
|
-
doc: "This is a test"
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
})).toRenderTo(`
|
|
171
|
-
interface Test
|
|
172
|
-
{
|
|
173
|
-
/// This is a test
|
|
174
|
-
void Method();
|
|
175
|
-
}
|
|
176
|
-
`);
|
|
177
|
-
});
|
|
178
|
-
describe("with type parameters", () => {
|
|
179
|
-
it("reference parameters", () => {
|
|
180
|
-
const typeParameters = [{
|
|
181
|
-
name: "T",
|
|
182
|
-
refkey: refkey()
|
|
183
|
-
}, {
|
|
184
|
-
name: "U",
|
|
185
|
-
refkey: refkey()
|
|
186
|
-
}];
|
|
187
|
-
expect(_$createComponent(TestNamespace, {
|
|
188
|
-
get children() {
|
|
189
|
-
return _$createComponent(SourceFile, {
|
|
190
|
-
path: "TestFile.cs",
|
|
191
|
-
get children() {
|
|
192
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
193
|
-
"public": true,
|
|
194
|
-
name: "TestInterface",
|
|
195
|
-
get children() {
|
|
196
|
-
return _$createComponent(InterfaceMethod, {
|
|
197
|
-
name: "Test",
|
|
198
|
-
"public": true,
|
|
199
|
-
typeParameters: typeParameters,
|
|
200
|
-
get parameters() {
|
|
201
|
-
return [{
|
|
202
|
-
name: "paramA",
|
|
203
|
-
type: typeParameters[0].refkey
|
|
204
|
-
}];
|
|
205
|
-
},
|
|
206
|
-
get returns() {
|
|
207
|
-
return typeParameters[0].refkey;
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
})).toRenderTo(`
|
|
216
|
-
namespace TestCode
|
|
217
|
-
{
|
|
218
|
-
public interface TestInterface
|
|
219
|
-
{
|
|
220
|
-
public T Test<T, U>(T paramA);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
`);
|
|
224
|
-
});
|
|
225
|
-
it("defines with constraints", () => {
|
|
226
|
-
const typeParameters = [{
|
|
227
|
-
name: "T",
|
|
228
|
-
constraints: "IFoo"
|
|
229
|
-
}, {
|
|
230
|
-
name: "U",
|
|
231
|
-
constraints: "IBar"
|
|
232
|
-
}];
|
|
233
|
-
expect(_$createComponent(Wrapper, {
|
|
234
|
-
get children() {
|
|
235
|
-
return _$createComponent(InterfaceMethod, {
|
|
236
|
-
"public": true,
|
|
237
|
-
name: "Test",
|
|
238
|
-
typeParameters: typeParameters,
|
|
239
|
-
children: "// Body"
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
})).toRenderTo(`
|
|
243
|
-
public interface TestInterface
|
|
244
|
-
{
|
|
245
|
-
public void Test<T, U>()
|
|
246
|
-
where T : IFoo
|
|
247
|
-
where U : IBar
|
|
248
|
-
{
|
|
249
|
-
// Body
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
`);
|
|
253
|
-
});
|
|
254
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Children, Refkey } from "@alloy-js/core";
|
|
2
|
-
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
-
/** Method modifiers. Can only be one. */
|
|
4
|
-
export interface InterfacePropertyModifiers {
|
|
5
|
-
readonly new?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export interface InterfacePropertyProps extends AccessModifiers, InterfacePropertyModifiers {
|
|
8
|
-
name: string;
|
|
9
|
-
refkey?: Refkey;
|
|
10
|
-
/** Property type */
|
|
11
|
-
type: Children;
|
|
12
|
-
/** If property should have a getter */
|
|
13
|
-
get?: boolean;
|
|
14
|
-
/** If property should have a setter */
|
|
15
|
-
set?: boolean;
|
|
16
|
-
/** Doc comment */
|
|
17
|
-
doc?: Children;
|
|
18
|
-
/**
|
|
19
|
-
* Property initializer
|
|
20
|
-
* @example `<ClassProperty name="My" get set nullable />`
|
|
21
|
-
*
|
|
22
|
-
* ```cs
|
|
23
|
-
* int? My { get; set; };
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
nullable?: boolean;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Render a C# interface property.
|
|
30
|
-
*
|
|
31
|
-
* @example `<InterfaceProperty public name="My" get set />`
|
|
32
|
-
*
|
|
33
|
-
* ```cs
|
|
34
|
-
* public int My { get; set; };
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export declare function InterfaceProperty(props: InterfacePropertyProps): Children;
|
|
38
|
-
//# 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;AAM5B,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;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,YAwC9D"}
|
|
@@ -1,67 +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 { DocWhen } from "../doc/comment.js";
|
|
8
|
-
|
|
9
|
-
/** Method modifiers. Can only be one. */
|
|
10
|
-
|
|
11
|
-
const getModifiers = makeModifiers(["new"]);
|
|
12
|
-
|
|
13
|
-
// properties for creating a method
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Render a C# interface property.
|
|
17
|
-
*
|
|
18
|
-
* @example `<InterfaceProperty public name="My" get set />`
|
|
19
|
-
*
|
|
20
|
-
* ```cs
|
|
21
|
-
* public int My { get; set; };
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export function InterfaceProperty(props) {
|
|
25
|
-
const name = useCSharpNamePolicy().getName(props.name, "class-property");
|
|
26
|
-
const scope = useCSharpScope();
|
|
27
|
-
if (scope.kind !== "member" || scope.name !== "interface-decl") {
|
|
28
|
-
throw new Error("can't define an interface method outside of an interface scope");
|
|
29
|
-
}
|
|
30
|
-
const propertySymbol = new CSharpOutputSymbol(name, {
|
|
31
|
-
scope,
|
|
32
|
-
refkeys: props.refkey ?? refkey(props.name)
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// scope for property declaration
|
|
36
|
-
const propertyScope = new CSharpMemberScope("property-decl", {
|
|
37
|
-
owner: propertySymbol
|
|
38
|
-
});
|
|
39
|
-
const modifiers = computeModifiersPrefix([getAccessModifier(props), getModifiers(props)]);
|
|
40
|
-
// note that scope wraps the method decl so that the params get the correct scope
|
|
41
|
-
return _$createComponent(MemberDeclaration, {
|
|
42
|
-
symbol: propertySymbol,
|
|
43
|
-
get children() {
|
|
44
|
-
return _$createComponent(Scope, {
|
|
45
|
-
value: propertyScope,
|
|
46
|
-
get children() {
|
|
47
|
-
return [_$createComponent(DocWhen, {
|
|
48
|
-
get doc() {
|
|
49
|
-
return props.doc;
|
|
50
|
-
}
|
|
51
|
-
}), modifiers, _$memo(() => props.type), _$memo(() => props.nullable && "?"), " ", name, " ", _$createComponent(Block, {
|
|
52
|
-
newline: true,
|
|
53
|
-
inline: true,
|
|
54
|
-
get children() {
|
|
55
|
-
return _$createComponent(List, {
|
|
56
|
-
joiner: " ",
|
|
57
|
-
get children() {
|
|
58
|
-
return [_$memo(() => props.get && "get;"), _$memo(() => props.set && "set;")];
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
})];
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"property.test.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/property.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,165 +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 { InterfaceDeclaration } from "./declaration.js";
|
|
5
|
-
import { InterfaceProperty } from "./property.js";
|
|
6
|
-
const Wrapper = props => _$createComponent(TestNamespace, {
|
|
7
|
-
get children() {
|
|
8
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
9
|
-
"public": true,
|
|
10
|
-
name: "TestInterface",
|
|
11
|
-
get children() {
|
|
12
|
-
return props.children;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
describe("modifiers", () => {
|
|
18
|
-
describe("access modifiers", () => {
|
|
19
|
-
it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
|
|
20
|
-
expect(_$createComponent(Wrapper, {
|
|
21
|
-
get children() {
|
|
22
|
-
return _$createComponent(InterfaceProperty, _$mergeProps({
|
|
23
|
-
[accessModifier]: true
|
|
24
|
-
}, {
|
|
25
|
-
name: "TestProp",
|
|
26
|
-
type: "string",
|
|
27
|
-
get: true
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
})).toRenderTo(`
|
|
31
|
-
public interface TestInterface
|
|
32
|
-
{
|
|
33
|
-
${accessModifier} string TestProp { get; }
|
|
34
|
-
}
|
|
35
|
-
`);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
describe("method modifiers", () => {
|
|
39
|
-
it.each(["new"])("%s", methodModifier => {
|
|
40
|
-
expect(_$createComponent(Wrapper, {
|
|
41
|
-
get children() {
|
|
42
|
-
return _$createComponent(InterfaceProperty, _$mergeProps({
|
|
43
|
-
[methodModifier]: true
|
|
44
|
-
}, {
|
|
45
|
-
name: "TestProp",
|
|
46
|
-
type: "string",
|
|
47
|
-
get: true
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
})).toRenderTo(`
|
|
51
|
-
public interface TestInterface
|
|
52
|
-
{
|
|
53
|
-
${methodModifier} string TestProp { get; }
|
|
54
|
-
}
|
|
55
|
-
`);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
it("combine modifiers", () => {
|
|
59
|
-
expect(_$createComponent(Wrapper, {
|
|
60
|
-
get children() {
|
|
61
|
-
return _$createComponent(InterfaceProperty, {
|
|
62
|
-
"public": true,
|
|
63
|
-
"new": true,
|
|
64
|
-
name: "TestProp",
|
|
65
|
-
type: "string",
|
|
66
|
-
get: true
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
})).toRenderTo(`
|
|
70
|
-
public interface TestInterface
|
|
71
|
-
{
|
|
72
|
-
public new string TestProp { get; }
|
|
73
|
-
}
|
|
74
|
-
`);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
it("applies PascalCase naming policy", () => {
|
|
78
|
-
expect(_$createComponent(Wrapper, {
|
|
79
|
-
get children() {
|
|
80
|
-
return _$createComponent(InterfaceProperty, {
|
|
81
|
-
name: "test_prop",
|
|
82
|
-
type: "string",
|
|
83
|
-
get: true
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
})).toRenderTo(`
|
|
87
|
-
public interface TestInterface
|
|
88
|
-
{
|
|
89
|
-
string TestProp { get; }
|
|
90
|
-
}
|
|
91
|
-
`);
|
|
92
|
-
});
|
|
93
|
-
it("has getter only", () => {
|
|
94
|
-
expect(_$createComponent(Wrapper, {
|
|
95
|
-
get children() {
|
|
96
|
-
return _$createComponent(InterfaceProperty, {
|
|
97
|
-
name: "TestProp",
|
|
98
|
-
type: "string",
|
|
99
|
-
get: true
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
})).toRenderTo(`
|
|
103
|
-
public interface TestInterface
|
|
104
|
-
{
|
|
105
|
-
string TestProp { get; }
|
|
106
|
-
}
|
|
107
|
-
`);
|
|
108
|
-
});
|
|
109
|
-
it("has setter only", () => {
|
|
110
|
-
expect(_$createComponent(Wrapper, {
|
|
111
|
-
get children() {
|
|
112
|
-
return _$createComponent(InterfaceProperty, {
|
|
113
|
-
name: "TestProp",
|
|
114
|
-
type: "string",
|
|
115
|
-
set: true
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
})).toRenderTo(`
|
|
119
|
-
public interface TestInterface
|
|
120
|
-
{
|
|
121
|
-
string TestProp { set; }
|
|
122
|
-
}
|
|
123
|
-
`);
|
|
124
|
-
});
|
|
125
|
-
it("has getter and setter", () => {
|
|
126
|
-
expect(_$createComponent(Wrapper, {
|
|
127
|
-
get children() {
|
|
128
|
-
return _$createComponent(InterfaceProperty, {
|
|
129
|
-
name: "TestProp",
|
|
130
|
-
type: "string",
|
|
131
|
-
get: true,
|
|
132
|
-
set: true
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
})).toRenderTo(`
|
|
136
|
-
public interface TestInterface
|
|
137
|
-
{
|
|
138
|
-
string TestProp { get; set; }
|
|
139
|
-
}
|
|
140
|
-
`);
|
|
141
|
-
});
|
|
142
|
-
it("specify doc comment", () => {
|
|
143
|
-
expect(_$createComponent(TestNamespace, {
|
|
144
|
-
get children() {
|
|
145
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
146
|
-
name: "Test",
|
|
147
|
-
get children() {
|
|
148
|
-
return _$createComponent(InterfaceProperty, {
|
|
149
|
-
name: "Method",
|
|
150
|
-
type: "string",
|
|
151
|
-
get: true,
|
|
152
|
-
set: true,
|
|
153
|
-
doc: "This is a test"
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
})).toRenderTo(`
|
|
159
|
-
interface Test
|
|
160
|
-
{
|
|
161
|
-
/// This is a test
|
|
162
|
-
string Method { get; set; }
|
|
163
|
-
}
|
|
164
|
-
`);
|
|
165
|
-
});
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Children, Refkey } from "@alloy-js/core";
|
|
2
|
-
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
-
/** Property modifiers. */
|
|
4
|
-
export interface PropertyModifiers {
|
|
5
|
-
readonly new?: boolean;
|
|
6
|
-
readonly static?: boolean;
|
|
7
|
-
readonly virtual?: boolean;
|
|
8
|
-
readonly sealed?: boolean;
|
|
9
|
-
readonly override?: boolean;
|
|
10
|
-
readonly abstract?: boolean;
|
|
11
|
-
readonly extern?: boolean;
|
|
12
|
-
readonly readonly?: boolean;
|
|
13
|
-
}
|
|
14
|
-
/** Properties for {@link Property} component */
|
|
15
|
-
export interface PropertyProps extends AccessModifiers, PropertyModifiers {
|
|
16
|
-
name: string;
|
|
17
|
-
refkey?: Refkey;
|
|
18
|
-
/** Property type */
|
|
19
|
-
type: Children;
|
|
20
|
-
/** If property should have a getter */
|
|
21
|
-
get?: boolean;
|
|
22
|
-
/** If property should have a setter */
|
|
23
|
-
set?: boolean;
|
|
24
|
-
/** If property should only be set on the type creation */
|
|
25
|
-
init?: boolean;
|
|
26
|
-
/** Doc comment */
|
|
27
|
-
doc?: Children;
|
|
28
|
-
/**
|
|
29
|
-
* Property initializer
|
|
30
|
-
* @example `<ClassProperty name="My" get set nullable />`
|
|
31
|
-
*
|
|
32
|
-
* ```cs
|
|
33
|
-
* int? My { get; set; };
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
nullable?: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Property initializer
|
|
39
|
-
* @example `<ClassProperty name="My" get set init={42} />`
|
|
40
|
-
*
|
|
41
|
-
* ```cs
|
|
42
|
-
* int My { get; set; } = 42;
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
initializer?: Children;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Render a C# class property.
|
|
49
|
-
*
|
|
50
|
-
* @example `<ClassProperty public name="My" get set />`
|
|
51
|
-
*
|
|
52
|
-
* ```cs
|
|
53
|
-
* public int My { get; set; };
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
export declare function Property(props: PropertyProps): Children;
|
|
57
|
-
//# sourceMappingURL=property.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../src/components/property/property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAKR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAM5B,0BAA0B;AAC1B,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAaD,gDAAgD;AAChD,MAAM,WAAW,aAAc,SAAQ,eAAe,EAAE,iBAAiB;IACvE,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,0DAA0D;IAC1D,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;IAEf;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,QAAQ,CAAC;CACxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,YAmD5C"}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { Block, code, 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 { DocWhen } from "../doc/comment.js";
|
|
8
|
-
|
|
9
|
-
/** Property modifiers. */
|
|
10
|
-
|
|
11
|
-
const getModifiers = makeModifiers(["new", "static", "virtual", "sealed", "override", "abstract", "extern", "readonly"]);
|
|
12
|
-
|
|
13
|
-
/** Properties for {@link Property} component */
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Render a C# class property.
|
|
17
|
-
*
|
|
18
|
-
* @example `<ClassProperty public name="My" get set />`
|
|
19
|
-
*
|
|
20
|
-
* ```cs
|
|
21
|
-
* public int My { get; set; };
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export function Property(props) {
|
|
25
|
-
const name = useCSharpNamePolicy().getName(props.name, "class-property");
|
|
26
|
-
const scope = useCSharpScope();
|
|
27
|
-
if (scope.kind !== "member" || scope.name !== "class-decl" && scope.name !== "record-decl") {
|
|
28
|
-
throw new Error("can't define an interface method outside of an interface scope");
|
|
29
|
-
}
|
|
30
|
-
const propertySymbol = new CSharpOutputSymbol(name, {
|
|
31
|
-
scope,
|
|
32
|
-
refkeys: props.refkey ?? refkey(props.name)
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// scope for property declaration
|
|
36
|
-
const propertyScope = new CSharpMemberScope("property-decl", {
|
|
37
|
-
owner: propertySymbol
|
|
38
|
-
});
|
|
39
|
-
const modifiers = computeModifiersPrefix([getAccessModifier(props), getModifiers(props)]);
|
|
40
|
-
if (props.init && props.set) {
|
|
41
|
-
throw new Error(`Cannot use 'init' and 'set' together on property '${name}'`);
|
|
42
|
-
}
|
|
43
|
-
// note that scope wraps the method decl so that the params get the correct scope
|
|
44
|
-
return _$createComponent(MemberDeclaration, {
|
|
45
|
-
symbol: propertySymbol,
|
|
46
|
-
get children() {
|
|
47
|
-
return _$createComponent(Scope, {
|
|
48
|
-
value: propertyScope,
|
|
49
|
-
get children() {
|
|
50
|
-
return [_$createComponent(DocWhen, {
|
|
51
|
-
get doc() {
|
|
52
|
-
return props.doc;
|
|
53
|
-
}
|
|
54
|
-
}), modifiers, _$memo(() => props.type), _$memo(() => props.nullable && "?"), " ", name, " ", _$createComponent(Block, {
|
|
55
|
-
newline: true,
|
|
56
|
-
inline: true,
|
|
57
|
-
get children() {
|
|
58
|
-
return _$createComponent(List, {
|
|
59
|
-
joiner: " ",
|
|
60
|
-
get children() {
|
|
61
|
-
return [_$memo(() => props.get && "get;"), _$memo(() => props.set && "set;"), _$memo(() => props.init && "init;")];
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}), _$memo(() => props.initializer && code` = ${props.initializer};`)];
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"property.test.d.ts","sourceRoot":"","sources":["../../../../src/components/property/property.test.tsx"],"names":[],"mappings":""}
|