@alloy-js/csharp 0.19.0-dev.1 → 0.19.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/ClassDeclaration.d.ts +0 -8
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +0 -43
- package/dist/src/components/constructor/constructor.d.ts +17 -0
- package/dist/src/components/constructor/constructor.d.ts.map +1 -0
- package/dist/src/components/constructor/constructor.js +47 -0
- package/dist/src/components/constructor/constructor.test.d.ts +2 -0
- package/dist/src/components/constructor/constructor.test.d.ts.map +1 -0
- package/dist/src/components/constructor/constructor.test.js +54 -0
- package/dist/src/components/index.d.ts +3 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +3 -1
- package/dist/src/components/{ClassMethod.d.ts → method/method.d.ts} +22 -8
- package/dist/src/components/method/method.d.ts.map +1 -0
- package/dist/src/components/{ClassMethod.js → method/method.js} +13 -13
- package/dist/src/components/method/method.test.d.ts +2 -0
- package/dist/src/components/method/method.test.d.ts.map +1 -0
- package/dist/{test/class-method.test.js → src/components/method/method.test.js} +33 -10
- package/dist/src/components/property/property.d.ts.map +1 -1
- package/dist/src/components/property/property.js +1 -1
- package/dist/src/components/stc/index.d.ts +3 -2
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +4 -3
- package/dist/src/components/struct/declaration.d.ts +68 -0
- package/dist/src/components/struct/declaration.d.ts.map +1 -0
- package/dist/src/components/struct/declaration.js +78 -0
- package/dist/src/components/struct/declaration.test.d.ts +2 -0
- package/dist/src/components/struct/declaration.test.d.ts.map +1 -0
- package/dist/src/components/struct/declaration.test.js +211 -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.js +6 -5
- package/dist/test/using.test.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/ClassDeclaration.tsx +0 -44
- package/src/components/constructor/constructor.test.tsx +41 -0
- package/src/components/constructor/constructor.tsx +67 -0
- package/src/components/index.ts +3 -1
- package/{test/class-method.test.tsx → src/components/method/method.test.tsx} +28 -15
- package/src/components/{ClassMethod.tsx → method/method.tsx} +44 -19
- package/src/components/property/property.tsx +3 -1
- package/src/components/stc/index.ts +3 -2
- package/src/components/struct/declaration.test.tsx +169 -0
- package/src/components/struct/declaration.tsx +129 -0
- package/src/name-policy.ts +2 -0
- package/temp/api.json +3544 -3163
- package/test/class-declaration.test.tsx +8 -7
- package/test/using.test.tsx +1 -1
- package/dist/src/components/ClassMethod.d.ts.map +0 -1
- package/dist/test/class-method.test.d.ts +0 -2
- package/dist/test/class-method.test.d.ts.map +0 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, 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 { AttributeList } from "../attributes/attributes.js";
|
|
8
|
+
import { DocWhen } from "../doc/comment.js";
|
|
9
|
+
import { Name } from "../Name.js";
|
|
10
|
+
import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
|
|
11
|
+
import { TypeParameters } from "../type-parameters/type-parameters.js";
|
|
12
|
+
const getStructModifiers = makeModifiers(["new", "readonly", "ref", "partial"]);
|
|
13
|
+
|
|
14
|
+
// properties for creating a class
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* CSharp struct declaration.
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* <StructDeclaration public name="IMyStruct">
|
|
21
|
+
* <StructMember public name="MyProperty" type="int" />
|
|
22
|
+
* <StructMethod public name="MyMethod" returnType="void">
|
|
23
|
+
* <Parameter name="value" type="int" />
|
|
24
|
+
* </StructMethod>
|
|
25
|
+
* </StructDeclaration>
|
|
26
|
+
* ```
|
|
27
|
+
* This will produce:
|
|
28
|
+
* ```csharp
|
|
29
|
+
* public struct MyIface
|
|
30
|
+
* {
|
|
31
|
+
* public int MyProperty { get; set; }
|
|
32
|
+
* public void MyMethod(int value);
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function StructDeclaration(props) {
|
|
37
|
+
const name = useCSharpNamePolicy().getName(props.name, "struct");
|
|
38
|
+
const thisStructSymbol = new CSharpOutputSymbol(name, {
|
|
39
|
+
refkeys: props.refkey
|
|
40
|
+
});
|
|
41
|
+
const thisStructScope = new CSharpMemberScope("struct-decl", {
|
|
42
|
+
owner: thisStructSymbol
|
|
43
|
+
});
|
|
44
|
+
const modifiers = computeModifiersPrefix([getAccessModifier(props), getStructModifiers(props)]);
|
|
45
|
+
return _$createComponent(core.Declaration, {
|
|
46
|
+
symbol: thisStructSymbol,
|
|
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, "struct ", _$createComponent(Name, {}), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
|
|
58
|
+
get parameters() {
|
|
59
|
+
return props.typeParameters;
|
|
60
|
+
}
|
|
61
|
+
})), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
|
|
62
|
+
get parameters() {
|
|
63
|
+
return props.typeParameters;
|
|
64
|
+
}
|
|
65
|
+
})), _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(core.Block, {
|
|
66
|
+
newline: true,
|
|
67
|
+
get children() {
|
|
68
|
+
return _$createComponent(core.Scope, {
|
|
69
|
+
value: thisStructScope,
|
|
70
|
+
get children() {
|
|
71
|
+
return props.children;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}) : ";")];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declaration.test.d.ts","sourceRoot":"","sources":["../../../../src/components/struct/declaration.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { List, 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 { Constructor } from "../constructor/constructor.js";
|
|
7
|
+
import { Method } from "../method/method.js";
|
|
8
|
+
import { Property } from "../property/property.js";
|
|
9
|
+
import { SourceFile } from "../SourceFile.js";
|
|
10
|
+
import { StructDeclaration } from "./declaration.js";
|
|
11
|
+
it("declares struct with no members", () => {
|
|
12
|
+
expect(_$createComponent(TestNamespace, {
|
|
13
|
+
get children() {
|
|
14
|
+
return _$createComponent(StructDeclaration, {
|
|
15
|
+
name: "Test"
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
})).toRenderTo(`
|
|
19
|
+
struct Test;
|
|
20
|
+
`);
|
|
21
|
+
});
|
|
22
|
+
describe("modifiers", () => {
|
|
23
|
+
it.each(["public", "private", "internal"])("%s", mod => {
|
|
24
|
+
expect(_$createComponent(TestNamespace, {
|
|
25
|
+
get children() {
|
|
26
|
+
return _$createComponent(StructDeclaration, _$mergeProps({
|
|
27
|
+
[mod]: true
|
|
28
|
+
}, {
|
|
29
|
+
name: "Test"
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
})).toRenderTo(`
|
|
33
|
+
${mod} struct Test;
|
|
34
|
+
`);
|
|
35
|
+
});
|
|
36
|
+
it.each(["partial"])("%s", mod => {
|
|
37
|
+
expect(_$createComponent(TestNamespace, {
|
|
38
|
+
get children() {
|
|
39
|
+
return _$createComponent(StructDeclaration, _$mergeProps({
|
|
40
|
+
[mod]: true
|
|
41
|
+
}, {
|
|
42
|
+
name: "Test"
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
})).toRenderTo(`
|
|
46
|
+
${mod} struct Test;
|
|
47
|
+
`);
|
|
48
|
+
});
|
|
49
|
+
it("combines modifiers", () => {
|
|
50
|
+
expect(_$createComponent(TestNamespace, {
|
|
51
|
+
get children() {
|
|
52
|
+
return _$createComponent(StructDeclaration, {
|
|
53
|
+
"public": true,
|
|
54
|
+
partial: true,
|
|
55
|
+
name: "Test"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
})).toRenderTo(`
|
|
59
|
+
public partial struct Test;
|
|
60
|
+
`);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
it("specify doc comment", () => {
|
|
64
|
+
expect(_$createComponent(TestNamespace, {
|
|
65
|
+
get children() {
|
|
66
|
+
return _$createComponent(StructDeclaration, {
|
|
67
|
+
name: "Test",
|
|
68
|
+
doc: "This is a test"
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
})).toRenderTo(`
|
|
72
|
+
/// This is a test
|
|
73
|
+
struct Test;
|
|
74
|
+
`);
|
|
75
|
+
});
|
|
76
|
+
describe("with type parameters", () => {
|
|
77
|
+
it("reference parameters", () => {
|
|
78
|
+
const typeParameters = [{
|
|
79
|
+
name: "T",
|
|
80
|
+
refkey: refkey()
|
|
81
|
+
}, {
|
|
82
|
+
name: "U",
|
|
83
|
+
refkey: refkey()
|
|
84
|
+
}];
|
|
85
|
+
expect(_$createComponent(TestNamespace, {
|
|
86
|
+
get children() {
|
|
87
|
+
return _$createComponent(SourceFile, {
|
|
88
|
+
path: "Test.cs",
|
|
89
|
+
get children() {
|
|
90
|
+
return _$createComponent(StructDeclaration, {
|
|
91
|
+
"public": true,
|
|
92
|
+
name: "Test",
|
|
93
|
+
typeParameters: typeParameters,
|
|
94
|
+
get children() {
|
|
95
|
+
return _$createComponent(List, {
|
|
96
|
+
get children() {
|
|
97
|
+
return [_$createComponent(Property, {
|
|
98
|
+
name: "PropA",
|
|
99
|
+
get type() {
|
|
100
|
+
return typeParameters[0].refkey;
|
|
101
|
+
},
|
|
102
|
+
get: true,
|
|
103
|
+
set: true
|
|
104
|
+
}), _$createComponent(Property, {
|
|
105
|
+
name: "PropB",
|
|
106
|
+
get type() {
|
|
107
|
+
return typeParameters[1].refkey;
|
|
108
|
+
},
|
|
109
|
+
get: true,
|
|
110
|
+
set: true
|
|
111
|
+
})];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
})).toRenderTo(`
|
|
120
|
+
namespace TestCode
|
|
121
|
+
{
|
|
122
|
+
public struct Test<T, U>
|
|
123
|
+
{
|
|
124
|
+
T PropA { get; set; }
|
|
125
|
+
U PropB { get; set; }
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
`);
|
|
129
|
+
});
|
|
130
|
+
it("defines with constraints", () => {
|
|
131
|
+
const typeParameters = [{
|
|
132
|
+
name: "T",
|
|
133
|
+
constraints: "IFoo"
|
|
134
|
+
}, {
|
|
135
|
+
name: "U",
|
|
136
|
+
constraints: "IBar"
|
|
137
|
+
}];
|
|
138
|
+
expect(_$createComponent(TestNamespace, {
|
|
139
|
+
get children() {
|
|
140
|
+
return _$createComponent(StructDeclaration, {
|
|
141
|
+
"public": true,
|
|
142
|
+
name: "Test",
|
|
143
|
+
typeParameters: typeParameters,
|
|
144
|
+
children: "// Body"
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
})).toRenderTo(`
|
|
148
|
+
public struct Test<T, U>
|
|
149
|
+
where T : IFoo
|
|
150
|
+
where U : IBar
|
|
151
|
+
{
|
|
152
|
+
// Body
|
|
153
|
+
}
|
|
154
|
+
`);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
it("specify attributes", () => {
|
|
158
|
+
expect(_$createComponent(TestNamespace, {
|
|
159
|
+
get children() {
|
|
160
|
+
return _$createComponent(StructDeclaration, {
|
|
161
|
+
name: "Test",
|
|
162
|
+
get attributes() {
|
|
163
|
+
return [_$createComponent(Attribute, {
|
|
164
|
+
name: "Test"
|
|
165
|
+
})];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
})).toRenderTo(`
|
|
170
|
+
[Test]
|
|
171
|
+
struct Test;
|
|
172
|
+
`);
|
|
173
|
+
});
|
|
174
|
+
it("define methods", () => {
|
|
175
|
+
expect(_$createComponent(TestNamespace, {
|
|
176
|
+
get children() {
|
|
177
|
+
return _$createComponent(StructDeclaration, {
|
|
178
|
+
name: "Test",
|
|
179
|
+
get children() {
|
|
180
|
+
return _$createComponent(Method, {
|
|
181
|
+
name: "MethodOne"
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
})).toRenderTo(`
|
|
187
|
+
struct Test
|
|
188
|
+
{
|
|
189
|
+
void MethodOne() {}
|
|
190
|
+
}
|
|
191
|
+
`);
|
|
192
|
+
});
|
|
193
|
+
it("define constructor", () => {
|
|
194
|
+
expect(_$createComponent(TestNamespace, {
|
|
195
|
+
get children() {
|
|
196
|
+
return _$createComponent(StructDeclaration, {
|
|
197
|
+
name: "Test",
|
|
198
|
+
get children() {
|
|
199
|
+
return _$createComponent(Constructor, {
|
|
200
|
+
"public": true
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
})).toRenderTo(`
|
|
206
|
+
struct Test
|
|
207
|
+
{
|
|
208
|
+
public Test() {}
|
|
209
|
+
}
|
|
210
|
+
`);
|
|
211
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
|
-
export type CSharpElements = "class" | "constant" | "variable" | "enum" | "enum-member" | "function" | "interface" | "record" | "class-member-private" | "class-member-public" | "class-method" | "class-property" | "parameter" | "type-parameter";
|
|
2
|
+
export type CSharpElements = "class" | "constant" | "variable" | "struct" | "enum" | "enum-member" | "function" | "interface" | "record" | "class-member-private" | "class-member-public" | "class-method" | "class-property" | "parameter" | "type-parameter";
|
|
3
3
|
export declare function createCSharpNamePolicy(): core.NamePolicy<CSharpElements>;
|
|
4
4
|
export declare function useCSharpNamePolicy(): core.NamePolicy<CSharpElements>;
|
|
5
5
|
//# sourceMappingURL=name-policy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"name-policy.d.ts","sourceRoot":"","sources":["../../src/name-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAIvC,MAAM,MAAM,cAAc,GACtB,OAAO,GACP,UAAU,GACV,UAAU,GACV,MAAM,GACN,aAAa,GACb,UAAU,GACV,WAAW,GACX,QAAQ,GACR,sBAAsB,GACtB,qBAAqB,GACrB,cAAc,GACd,gBAAgB,GAChB,WAAW,GACX,gBAAgB,CAAC;AAGrB,wBAAgB,sBAAsB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"name-policy.d.ts","sourceRoot":"","sources":["../../src/name-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAIvC,MAAM,MAAM,cAAc,GACtB,OAAO,GACP,UAAU,GACV,UAAU,GACV,QAAQ,GACR,MAAM,GACN,aAAa,GACb,UAAU,GACV,WAAW,GACX,QAAQ,GACR,sBAAsB,GACtB,qBAAqB,GACrB,cAAc,GACd,gBAAgB,GAChB,WAAW,GACX,gBAAgB,CAAC;AAGrB,wBAAgB,sBAAsB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAoBxE;AAGD,wBAAgB,mBAAmB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAErE"}
|
package/dist/src/name-policy.js
CHANGED
|
@@ -4,6 +4,7 @@ import { List, refkey } from "@alloy-js/core";
|
|
|
4
4
|
import * as coretest from "@alloy-js/core/testing";
|
|
5
5
|
import { describe, expect, it } from "vitest";
|
|
6
6
|
import { Attribute } from "../src/components/attributes/attributes.js";
|
|
7
|
+
import { Constructor } from "../src/components/stc/index.js";
|
|
7
8
|
import * as csharp from "../src/index.js";
|
|
8
9
|
import { ClassDeclaration, ClassMember, Property, SourceFile } from "../src/index.js";
|
|
9
10
|
import * as utils from "./utils.js";
|
|
@@ -137,10 +138,10 @@ it("declares class with some methods", () => {
|
|
|
137
138
|
get children() {
|
|
138
139
|
return _$createComponent(core.List, {
|
|
139
140
|
get children() {
|
|
140
|
-
return [_$createComponent(csharp.
|
|
141
|
+
return [_$createComponent(csharp.Method, {
|
|
141
142
|
"public": true,
|
|
142
143
|
name: "MethodOne"
|
|
143
|
-
}), _$createComponent(csharp.
|
|
144
|
+
}), _$createComponent(csharp.Method, {
|
|
144
145
|
"private": true,
|
|
145
146
|
virtual: true,
|
|
146
147
|
name: "MethodTwo"
|
|
@@ -215,7 +216,7 @@ it("uses refkeys for members, params, and return type", () => {
|
|
|
215
216
|
"private": true,
|
|
216
217
|
name: "MemberOne",
|
|
217
218
|
type: enumTypeRefkey
|
|
218
|
-
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.
|
|
219
|
+
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.Method, {
|
|
219
220
|
"public": true,
|
|
220
221
|
name: "MethodOne",
|
|
221
222
|
parameters: params,
|
|
@@ -353,7 +354,7 @@ it("declares class with constructor", () => {
|
|
|
353
354
|
"public": true,
|
|
354
355
|
name: "TestClass",
|
|
355
356
|
get children() {
|
|
356
|
-
return _$createComponent(
|
|
357
|
+
return _$createComponent(Constructor, {
|
|
357
358
|
"public": true
|
|
358
359
|
});
|
|
359
360
|
}
|
|
@@ -396,7 +397,7 @@ it("declares class with constructor params and assigns values to fields", () =>
|
|
|
396
397
|
name: "size",
|
|
397
398
|
type: "int",
|
|
398
399
|
refkey: thisSizeRefkey
|
|
399
|
-
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(
|
|
400
|
+
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(Constructor, {
|
|
400
401
|
"public": true,
|
|
401
402
|
parameters: ctorParams,
|
|
402
403
|
get children() {
|
package/dist/test/using.test.js
CHANGED
|
@@ -97,7 +97,7 @@ it("adds using statement across namespaces", () => {
|
|
|
97
97
|
"public": true,
|
|
98
98
|
name: "Client",
|
|
99
99
|
get children() {
|
|
100
|
-
return _$createComponent(csharp.
|
|
100
|
+
return _$createComponent(csharp.Method, {
|
|
101
101
|
"public": true,
|
|
102
102
|
name: "MethodOne",
|
|
103
103
|
parameters: params,
|