@alloy-js/csharp 0.18.0-dev.9 → 0.19.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/dist/src/components/ClassDeclaration.d.ts +39 -2
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +35 -34
- package/dist/src/components/ClassMethod.d.ts +33 -1
- package/dist/src/components/ClassMethod.d.ts.map +1 -1
- package/dist/src/components/ClassMethod.js +22 -7
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +1 -0
- package/dist/src/components/attributes/attributes.d.ts +39 -0
- package/dist/src/components/attributes/attributes.d.ts.map +1 -0
- package/dist/src/components/attributes/attributes.js +62 -0
- package/dist/src/components/attributes/attributes.test.d.ts +2 -0
- package/dist/src/components/attributes/attributes.test.d.ts.map +1 -0
- package/dist/src/components/attributes/attributes.test.js +75 -0
- package/dist/src/components/index.d.ts +7 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +8 -2
- package/dist/src/components/interface/declaration.d.ts +32 -1
- package/dist/src/components/interface/declaration.d.ts.map +1 -1
- package/dist/src/components/interface/declaration.js +18 -25
- package/dist/src/components/interface/declaration.test.js +102 -0
- package/dist/src/components/interface/method.d.ts +33 -1
- package/dist/src/components/interface/method.d.ts.map +1 -1
- package/dist/src/components/interface/method.js +22 -7
- package/dist/src/components/interface/method.test.js +169 -0
- package/dist/src/components/interface/property.d.ts +36 -1
- package/dist/src/components/interface/property.d.ts.map +1 -1
- package/dist/src/components/interface/property.js +18 -4
- package/dist/src/components/interface/property.test.js +24 -0
- package/dist/src/components/parameters/parameters.d.ts +19 -0
- package/dist/src/components/parameters/parameters.d.ts.map +1 -0
- package/dist/src/components/parameters/parameters.js +43 -0
- package/dist/src/components/property/property.d.ts +80 -0
- package/dist/src/components/property/property.d.ts.map +1 -0
- package/dist/src/components/property/property.js +76 -0
- package/dist/src/components/property/property.test.d.ts +2 -0
- package/dist/src/components/property/property.test.d.ts.map +1 -0
- package/dist/src/components/property/property.test.js +242 -0
- package/dist/src/components/record/declaration.d.ts +35 -0
- package/dist/src/components/record/declaration.d.ts.map +1 -0
- package/dist/src/components/record/declaration.js +90 -0
- package/dist/src/components/record/declaration.test.d.ts +2 -0
- package/dist/src/components/record/declaration.test.d.ts.map +1 -0
- package/dist/src/components/record/declaration.test.js +94 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +8 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.js +44 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +2 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.test.js +67 -0
- package/dist/src/components/type-parameters/type-parameter.d.ts +20 -0
- package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameter.js +22 -0
- package/dist/src/components/type-parameters/type-parameters.d.ts +17 -0
- package/dist/src/components/type-parameters/type-parameters.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameters.js +54 -0
- package/dist/src/components/type-parameters/type-parameters.test.d.ts +2 -0
- package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameters.test.js +48 -0
- package/dist/src/components/var/declaration.d.ts +35 -0
- package/dist/src/components/var/declaration.d.ts.map +1 -0
- package/dist/src/components/var/declaration.js +40 -0
- package/dist/src/components/var/declaration.test.d.ts +2 -0
- package/dist/src/components/var/declaration.test.d.ts.map +1 -0
- package/dist/src/components/var/declaration.test.js +73 -0
- 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 +1 -0
- package/dist/test/class-declaration.test.d.ts +2 -0
- package/dist/test/class-declaration.test.d.ts.map +1 -0
- package/dist/test/{class.test.js → class-declaration.test.js} +161 -33
- package/dist/test/project-directory.test.d.ts +2 -0
- package/dist/test/project-directory.test.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/ClassDeclaration.tsx +65 -33
- package/src/components/ClassMethod.tsx +46 -4
- package/src/components/SourceFile.tsx +1 -0
- package/src/components/attributes/attributes.test.tsx +61 -0
- package/src/components/attributes/attributes.tsx +100 -0
- package/src/components/index.ts +7 -1
- package/src/components/interface/declaration.test.tsx +102 -0
- package/src/components/interface/declaration.tsx +43 -27
- package/src/components/interface/method.test.tsx +173 -0
- package/src/components/interface/method.tsx +45 -5
- package/src/components/interface/property.test.tsx +21 -0
- package/src/components/interface/property.tsx +43 -6
- package/src/components/parameters/parameters.tsx +74 -0
- package/src/components/property/property.test.tsx +209 -0
- package/src/components/property/property.tsx +172 -0
- package/src/components/record/declaration.test.tsx +73 -0
- package/src/components/record/declaration.tsx +109 -0
- package/src/components/type-parameters/type-parameter-constraints.test.tsx +93 -0
- package/src/components/type-parameters/type-parameter-constraints.tsx +46 -0
- package/src/components/type-parameters/type-parameter.tsx +35 -0
- package/src/components/type-parameters/type-parameters.test.tsx +46 -0
- package/src/components/type-parameters/type-parameters.tsx +63 -0
- package/src/components/var/declaration.test.tsx +59 -0
- package/src/components/var/declaration.tsx +47 -0
- package/src/name-policy.ts +3 -0
- package/temp/api.json +4722 -2384
- package/test/{class.test.tsx → class-declaration.test.tsx} +144 -26
- package/dist/src/components/Parameters.d.ts +0 -13
- package/dist/src/components/Parameters.d.ts.map +0 -1
- package/dist/src/components/Parameters.js +0 -34
- package/dist/test/class.test.d.ts +0 -2
- package/dist/test/class.test.d.ts.map +0 -1
- package/dist/test/projectdirectory.test.d.ts +0 -2
- package/dist/test/projectdirectory.test.d.ts.map +0 -1
- package/src/components/Parameters.tsx +0 -51
- /package/dist/test/{projectdirectory.test.js → project-directory.test.js} +0 -0
- /package/test/{projectdirectory.test.tsx → project-directory.test.tsx} +0 -0
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
|
+
import { List, refkey } from "@alloy-js/core";
|
|
2
3
|
import * as coretest from "@alloy-js/core/testing";
|
|
3
4
|
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { Attribute } from "../src/components/attributes/attributes.jsx";
|
|
6
|
+
import { TypeParameterProps } from "../src/components/type-parameters/type-parameter.jsx";
|
|
4
7
|
import * as csharp from "../src/index.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
8
|
+
import {
|
|
9
|
+
ClassDeclaration,
|
|
10
|
+
ClassMember,
|
|
11
|
+
Property,
|
|
12
|
+
SourceFile,
|
|
13
|
+
} from "../src/index.js";
|
|
14
|
+
import * as utils from "./utils.jsx";
|
|
7
15
|
|
|
8
16
|
it("declares class with no members", () => {
|
|
9
17
|
expect(
|
|
@@ -47,6 +55,45 @@ describe("modifiers", () => {
|
|
|
47
55
|
});
|
|
48
56
|
});
|
|
49
57
|
|
|
58
|
+
describe("base", () => {
|
|
59
|
+
it("define base class", () => {
|
|
60
|
+
expect(
|
|
61
|
+
<utils.TestNamespace>
|
|
62
|
+
<csharp.ClassDeclaration name="TestClass" baseType="Foo" />
|
|
63
|
+
</utils.TestNamespace>,
|
|
64
|
+
).toRenderTo(`
|
|
65
|
+
class TestClass : Foo;
|
|
66
|
+
`);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("define multiple interface types", () => {
|
|
70
|
+
expect(
|
|
71
|
+
<utils.TestNamespace>
|
|
72
|
+
<csharp.ClassDeclaration
|
|
73
|
+
name="TestClass"
|
|
74
|
+
interfaceTypes={["Foo", "Bar"]}
|
|
75
|
+
/>
|
|
76
|
+
</utils.TestNamespace>,
|
|
77
|
+
).toRenderTo(`
|
|
78
|
+
class TestClass : Foo, Bar;
|
|
79
|
+
`);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("define base class and multiple interface types", () => {
|
|
83
|
+
expect(
|
|
84
|
+
<utils.TestNamespace>
|
|
85
|
+
<csharp.ClassDeclaration
|
|
86
|
+
name="TestClass"
|
|
87
|
+
baseType="BaseClass"
|
|
88
|
+
interfaceTypes={["Foo", "Bar"]}
|
|
89
|
+
/>
|
|
90
|
+
</utils.TestNamespace>,
|
|
91
|
+
).toRenderTo(`
|
|
92
|
+
class TestClass : BaseClass, Foo, Bar;
|
|
93
|
+
`);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
50
97
|
it("declares class with some members", () => {
|
|
51
98
|
const res = utils.toSourceText(
|
|
52
99
|
<csharp.ClassDeclaration public name="TestClass">
|
|
@@ -178,34 +225,77 @@ it("uses refkeys for members, params, and return type", () => {
|
|
|
178
225
|
`);
|
|
179
226
|
});
|
|
180
227
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
<csharp.ClassMember public name="memberOne" type={typeParameters.T} />
|
|
194
|
-
;<hbr />
|
|
195
|
-
<csharp.ClassMember private name="memberTwo" type={typeParameters.U} />;
|
|
196
|
-
</csharp.ClassDeclaration>,
|
|
197
|
-
);
|
|
228
|
+
describe("with type parameters", () => {
|
|
229
|
+
it("reference parameters", () => {
|
|
230
|
+
const typeParameters: TypeParameterProps[] = [
|
|
231
|
+
{
|
|
232
|
+
name: "T",
|
|
233
|
+
refkey: refkey(),
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
name: "U",
|
|
237
|
+
refkey: refkey(),
|
|
238
|
+
},
|
|
239
|
+
];
|
|
198
240
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
241
|
+
expect(
|
|
242
|
+
<utils.TestNamespace>
|
|
243
|
+
<SourceFile path="Test.cs">
|
|
244
|
+
<ClassDeclaration
|
|
245
|
+
public
|
|
246
|
+
name="TestClass"
|
|
247
|
+
typeParameters={typeParameters}
|
|
248
|
+
>
|
|
249
|
+
<List>
|
|
250
|
+
<Property name="PropA" type={typeParameters[0].refkey} get set />
|
|
251
|
+
<Property name="PropB" type={typeParameters[1].refkey} get set />
|
|
252
|
+
</List>
|
|
253
|
+
</ClassDeclaration>
|
|
254
|
+
</SourceFile>
|
|
255
|
+
</utils.TestNamespace>,
|
|
256
|
+
).toRenderTo(`
|
|
257
|
+
namespace TestCode
|
|
258
|
+
{
|
|
202
259
|
public class TestClass<T, U>
|
|
203
260
|
{
|
|
204
|
-
|
|
205
|
-
|
|
261
|
+
T PropA { get; set; }
|
|
262
|
+
U PropB { get; set; }
|
|
206
263
|
}
|
|
207
|
-
|
|
208
|
-
|
|
264
|
+
}
|
|
265
|
+
`);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it("defines with constraints", () => {
|
|
269
|
+
const typeParameters: TypeParameterProps[] = [
|
|
270
|
+
{
|
|
271
|
+
name: "T",
|
|
272
|
+
constraints: "IFoo",
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
name: "U",
|
|
276
|
+
constraints: "IBar",
|
|
277
|
+
},
|
|
278
|
+
];
|
|
279
|
+
|
|
280
|
+
expect(
|
|
281
|
+
<utils.TestNamespace>
|
|
282
|
+
<ClassDeclaration
|
|
283
|
+
public
|
|
284
|
+
name="TestClass"
|
|
285
|
+
typeParameters={typeParameters}
|
|
286
|
+
>
|
|
287
|
+
// Body
|
|
288
|
+
</ClassDeclaration>
|
|
289
|
+
</utils.TestNamespace>,
|
|
290
|
+
).toRenderTo(`
|
|
291
|
+
public class TestClass<T, U>
|
|
292
|
+
where T : IFoo
|
|
293
|
+
where U : IBar
|
|
294
|
+
{
|
|
295
|
+
// Body
|
|
296
|
+
}
|
|
297
|
+
`);
|
|
298
|
+
});
|
|
209
299
|
});
|
|
210
300
|
|
|
211
301
|
it("declares class with invalid members", () => {
|
|
@@ -310,3 +400,31 @@ it("specify doc comment", () => {
|
|
|
310
400
|
class Test;
|
|
311
401
|
`);
|
|
312
402
|
});
|
|
403
|
+
|
|
404
|
+
it("supports class member doc comments", () => {
|
|
405
|
+
expect(
|
|
406
|
+
<utils.TestNamespace>
|
|
407
|
+
<ClassDeclaration name="Test" doc="This is a test">
|
|
408
|
+
<ClassMember name="Member" public type="int" doc="This is a member" />
|
|
409
|
+
</ClassDeclaration>
|
|
410
|
+
</utils.TestNamespace>,
|
|
411
|
+
).toRenderTo(`
|
|
412
|
+
/// This is a test
|
|
413
|
+
class Test
|
|
414
|
+
{
|
|
415
|
+
/// This is a member
|
|
416
|
+
public int Member
|
|
417
|
+
}
|
|
418
|
+
`);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
it("specify attributes", () => {
|
|
422
|
+
expect(
|
|
423
|
+
<utils.TestNamespace>
|
|
424
|
+
<ClassDeclaration name="Test" attributes={[<Attribute name="Test" />]} />
|
|
425
|
+
</utils.TestNamespace>,
|
|
426
|
+
).toRenderTo(`
|
|
427
|
+
[Test]
|
|
428
|
+
class Test;
|
|
429
|
+
`);
|
|
430
|
+
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as core from "@alloy-js/core";
|
|
2
|
-
export interface ParameterProps {
|
|
3
|
-
name: string;
|
|
4
|
-
type: core.Children;
|
|
5
|
-
refkey?: core.Refkey;
|
|
6
|
-
symbol?: core.OutputSymbol;
|
|
7
|
-
}
|
|
8
|
-
export declare function Parameter(props: ParameterProps): core.Children;
|
|
9
|
-
export interface ParametersProps {
|
|
10
|
-
parameters: Array<ParameterProps>;
|
|
11
|
-
}
|
|
12
|
-
export declare function Parameters(props: ParametersProps): core.Children;
|
|
13
|
-
//# sourceMappingURL=Parameters.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Parameters.d.ts","sourceRoot":"","sources":["../../../src/components/Parameters.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAMvC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC;CAC5B;AAGD,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,iBAsB9C;AAED,MAAM,WAAW,eAAe;IAE9B,UAAU,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;CACnC;AAGD,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,iBAMhD"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import * as core 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
|
-
// a constructor/method parameter
|
|
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 ?? core.refkey(props.name)
|
|
17
|
-
});
|
|
18
|
-
return _$createComponent(core.Declaration, {
|
|
19
|
-
symbol: memberSymbol,
|
|
20
|
-
get children() {
|
|
21
|
-
return [_$memo(() => props.type), " ", _$createComponent(Name, {})];
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
// a collection of parameters
|
|
26
|
-
export function Parameters(props) {
|
|
27
|
-
return _$createComponent(core.For, {
|
|
28
|
-
get each() {
|
|
29
|
-
return props.parameters;
|
|
30
|
-
},
|
|
31
|
-
joiner: ", ",
|
|
32
|
-
children: param => _$createComponent(Parameter, param)
|
|
33
|
-
});
|
|
34
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"class.test.d.ts","sourceRoot":"","sources":["../../test/class.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"projectdirectory.test.d.ts","sourceRoot":"","sources":["../../test/projectdirectory.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import * as core from "@alloy-js/core";
|
|
2
|
-
import { useCSharpNamePolicy } from "../name-policy.js";
|
|
3
|
-
import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
|
|
4
|
-
import { useCSharpScope } from "../symbols/scopes.js";
|
|
5
|
-
import { Name } from "./Name.js";
|
|
6
|
-
|
|
7
|
-
export interface ParameterProps {
|
|
8
|
-
name: string;
|
|
9
|
-
type: core.Children;
|
|
10
|
-
refkey?: core.Refkey;
|
|
11
|
-
symbol?: core.OutputSymbol;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// a constructor/method parameter
|
|
15
|
-
export function Parameter(props: ParameterProps) {
|
|
16
|
-
const name = useCSharpNamePolicy().getName(props.name, "parameter");
|
|
17
|
-
const scope = useCSharpScope();
|
|
18
|
-
if (
|
|
19
|
-
scope.kind !== "member" ||
|
|
20
|
-
(scope.name !== "constructor-decl" && scope.name !== "method-decl")
|
|
21
|
-
) {
|
|
22
|
-
throw new Error(
|
|
23
|
-
"can't define a parameter outside of a constructor-decl or method-decl scope",
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const memberSymbol = new CSharpOutputSymbol(name, {
|
|
28
|
-
scope,
|
|
29
|
-
refkeys: props.refkey ?? core.refkey(props.name),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
return (
|
|
33
|
-
<core.Declaration symbol={memberSymbol}>
|
|
34
|
-
{props.type} <Name />
|
|
35
|
-
</core.Declaration>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface ParametersProps {
|
|
40
|
-
// param name and type
|
|
41
|
-
parameters: Array<ParameterProps>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// a collection of parameters
|
|
45
|
-
export function Parameters(props: ParametersProps) {
|
|
46
|
-
return (
|
|
47
|
-
<core.For each={props.parameters} joiner={", "}>
|
|
48
|
-
{(param) => <Parameter {...param} />}
|
|
49
|
-
</core.For>
|
|
50
|
-
);
|
|
51
|
-
}
|
|
File without changes
|
|
File without changes
|