@alloy-js/csharp 0.19.0-dev.5 → 0.19.0-dev.7
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/field/field.d.ts +8 -1
- package/dist/src/components/field/field.d.ts.map +1 -1
- package/dist/src/components/field/field.js +8 -4
- package/dist/src/components/field/field.test.js +125 -19
- package/dist/src/components/struct/declaration.test.js +4 -4
- package/dist/src/name-policy.d.ts.map +1 -1
- package/dist/src/name-policy.js +2 -0
- package/dist/test/class-declaration.test.js +12 -12
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/field/field.test.tsx +108 -10
- package/src/components/field/field.tsx +24 -4
- package/src/components/struct/declaration.test.tsx +5 -5
- package/src/name-policy.ts +2 -0
- package/temp/api.json +139 -0
- package/test/class-declaration.test.tsx +12 -13
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Children, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
-
|
|
3
|
+
/** Field modifiers. */
|
|
4
|
+
export interface FieldModifiers {
|
|
5
|
+
readonly new?: boolean;
|
|
6
|
+
readonly static?: boolean;
|
|
7
|
+
readonly readonly?: boolean;
|
|
8
|
+
readonly volatile?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface FieldProps extends AccessModifiers, FieldModifiers {
|
|
4
11
|
name: string;
|
|
5
12
|
type: Children;
|
|
6
13
|
refkey?: Refkey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../../src/components/field/field.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA6B,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EACL,eAAe,
|
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../../src/components/field/field.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA6B,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAM5B,uBAAuB;AACvB,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AASD,MAAM,WAAW,UAAW,SAAQ,eAAe,EAAE,cAAc;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED,wBAAwB;AACxB,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,YAiCtC"}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { Declaration, Name, refkey } from "@alloy-js/core";
|
|
3
|
-
import { computeModifiersPrefix, getAccessModifier } from "../../modifiers.js";
|
|
3
|
+
import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../modifiers.js";
|
|
4
4
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
5
|
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
6
|
import { useCSharpScope } from "../../symbols/scopes.js";
|
|
7
7
|
import { DocWhen } from "../doc/comment.js";
|
|
8
|
+
|
|
9
|
+
/** Field modifiers. */
|
|
10
|
+
|
|
11
|
+
const getModifiers = makeModifiers(["new", "static", "readonly", "volatile"]);
|
|
8
12
|
/** Render a c# field */
|
|
9
13
|
export function Field(props) {
|
|
10
14
|
let nameElement = "class-member-private";
|
|
11
|
-
if (props.public) {
|
|
15
|
+
if (props.public || props.protected || props.internal) {
|
|
12
16
|
nameElement = "class-member-public";
|
|
13
17
|
}
|
|
14
18
|
const name = useCSharpNamePolicy().getName(props.name, nameElement);
|
|
@@ -20,7 +24,7 @@ export function Field(props) {
|
|
|
20
24
|
scope,
|
|
21
25
|
refkeys: props.refkey ?? refkey(props.name)
|
|
22
26
|
});
|
|
23
|
-
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
27
|
+
const modifiers = computeModifiersPrefix([getAccessModifier(props), getModifiers(props)]);
|
|
24
28
|
return _$createComponent(Declaration, {
|
|
25
29
|
symbol: memberSymbol,
|
|
26
30
|
get children() {
|
|
@@ -28,7 +32,7 @@ export function Field(props) {
|
|
|
28
32
|
get doc() {
|
|
29
33
|
return props.doc;
|
|
30
34
|
}
|
|
31
|
-
}), modifiers, _$memo(() => props.type), " ", _$createComponent(Name, {})];
|
|
35
|
+
}), modifiers, _$memo(() => props.type), " ", _$createComponent(Name, {}), ";"];
|
|
32
36
|
}
|
|
33
37
|
});
|
|
34
38
|
}
|
|
@@ -1,29 +1,36 @@
|
|
|
1
|
-
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { expect, it } from "vitest";
|
|
1
|
+
import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { List } from "@alloy-js/core";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
4
|
import { TestNamespace } from "../../../test/utils.js";
|
|
5
5
|
import { ClassDeclaration } from "../ClassDeclaration.js";
|
|
6
6
|
import { Field } from "./field.js";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
function Wrapper(props) {
|
|
8
|
+
return _$createComponent(TestNamespace, {
|
|
9
9
|
get children() {
|
|
10
10
|
return _$createComponent(ClassDeclaration, {
|
|
11
11
|
"public": true,
|
|
12
12
|
name: "TestClass",
|
|
13
13
|
get children() {
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
return props.children;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
it("declares multiple fields", () => {
|
|
21
|
+
expect(_$createComponent(Wrapper, {
|
|
22
|
+
get children() {
|
|
23
|
+
return _$createComponent(List, {
|
|
24
|
+
get children() {
|
|
25
|
+
return [_$createComponent(Field, {
|
|
26
|
+
"public": true,
|
|
27
|
+
name: "MemberOne",
|
|
28
|
+
type: "string"
|
|
29
|
+
}), _$createComponent(Field, {
|
|
30
|
+
"public": true,
|
|
31
|
+
name: "MemberTwo",
|
|
32
|
+
type: "int"
|
|
33
|
+
})];
|
|
27
34
|
}
|
|
28
35
|
});
|
|
29
36
|
}
|
|
@@ -31,7 +38,106 @@ it("declares some field", () => {
|
|
|
31
38
|
public class TestClass
|
|
32
39
|
{
|
|
33
40
|
public string MemberOne;
|
|
34
|
-
|
|
41
|
+
public int MemberTwo;
|
|
42
|
+
}
|
|
43
|
+
`);
|
|
44
|
+
});
|
|
45
|
+
describe("modifiers", () => {
|
|
46
|
+
describe("access modifiers", () => {
|
|
47
|
+
it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
|
|
48
|
+
expect(_$createComponent(Wrapper, {
|
|
49
|
+
get children() {
|
|
50
|
+
return _$createComponent(Field, _$mergeProps({
|
|
51
|
+
[accessModifier]: true
|
|
52
|
+
}, {
|
|
53
|
+
name: "TestProp",
|
|
54
|
+
type: "string"
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
})).toRenderTo(`
|
|
58
|
+
public class TestClass
|
|
59
|
+
{
|
|
60
|
+
${accessModifier} string ${accessModifier === "private" ? "_testProp" : "TestProp"};
|
|
61
|
+
}
|
|
62
|
+
`);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe("modifiers", () => {
|
|
66
|
+
it.each(["new", "static", "readonly", "volatile"])("%s", methodModifier => {
|
|
67
|
+
expect(_$createComponent(Wrapper, {
|
|
68
|
+
get children() {
|
|
69
|
+
return _$createComponent(Field, _$mergeProps({
|
|
70
|
+
[methodModifier]: true
|
|
71
|
+
}, {
|
|
72
|
+
name: "TestField",
|
|
73
|
+
type: "string"
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
})).toRenderTo(`
|
|
77
|
+
public class TestClass
|
|
78
|
+
{
|
|
79
|
+
${methodModifier} string _testField;
|
|
80
|
+
}
|
|
81
|
+
`);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
it("combine modifiers", () => {
|
|
85
|
+
expect(_$createComponent(Wrapper, {
|
|
86
|
+
get children() {
|
|
87
|
+
return _$createComponent(Field, {
|
|
88
|
+
"public": true,
|
|
89
|
+
"new": true,
|
|
90
|
+
name: "TestField",
|
|
91
|
+
type: "string"
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
})).toRenderTo(`
|
|
95
|
+
public class TestClass
|
|
96
|
+
{
|
|
97
|
+
public new string TestField;
|
|
98
|
+
}
|
|
99
|
+
`);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
describe("naming", () => {
|
|
103
|
+
it("public field are PascalCase", () => {
|
|
104
|
+
expect(_$createComponent(Wrapper, {
|
|
105
|
+
get children() {
|
|
106
|
+
return _$createComponent(List, {
|
|
107
|
+
get children() {
|
|
108
|
+
return _$createComponent(Field, {
|
|
109
|
+
"public": true,
|
|
110
|
+
name: "member_one",
|
|
111
|
+
type: "string"
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
})).toRenderTo(`
|
|
117
|
+
public class TestClass
|
|
118
|
+
{
|
|
119
|
+
public string MemberOne;
|
|
120
|
+
}
|
|
121
|
+
`);
|
|
122
|
+
});
|
|
123
|
+
it("private field are camelCase with _ prefix", () => {
|
|
124
|
+
expect(_$createComponent(Wrapper, {
|
|
125
|
+
get children() {
|
|
126
|
+
return _$createComponent(List, {
|
|
127
|
+
get children() {
|
|
128
|
+
return _$createComponent(Field, {
|
|
129
|
+
"private": true,
|
|
130
|
+
name: "member_one",
|
|
131
|
+
type: "string"
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
})).toRenderTo(`
|
|
137
|
+
public class TestClass
|
|
138
|
+
{
|
|
139
|
+
private string _memberOne;
|
|
35
140
|
}
|
|
36
141
|
`);
|
|
142
|
+
});
|
|
37
143
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { List, refkey
|
|
2
|
+
import { List, refkey } from "@alloy-js/core";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
import { TestNamespace } from "../../../test/utils.js";
|
|
5
5
|
import { Attribute } from "../attributes/attributes.js";
|
|
@@ -217,14 +217,14 @@ it("defines fields", () => {
|
|
|
217
217
|
"public": true,
|
|
218
218
|
name: "TestClass",
|
|
219
219
|
get children() {
|
|
220
|
-
return _$createComponent(
|
|
220
|
+
return _$createComponent(List, {
|
|
221
221
|
get children() {
|
|
222
222
|
return [_$createComponent(Field, {
|
|
223
223
|
"public": true,
|
|
224
224
|
name: "MemberOne",
|
|
225
225
|
type: "string"
|
|
226
226
|
}), _$createComponent(Field, {
|
|
227
|
-
"
|
|
227
|
+
"public": true,
|
|
228
228
|
name: "MemberTwo",
|
|
229
229
|
type: "int"
|
|
230
230
|
})];
|
|
@@ -237,7 +237,7 @@ it("defines fields", () => {
|
|
|
237
237
|
public struct TestClass
|
|
238
238
|
{
|
|
239
239
|
public string MemberOne;
|
|
240
|
-
|
|
240
|
+
public int MemberTwo;
|
|
241
241
|
}
|
|
242
242
|
`);
|
|
243
243
|
});
|
|
@@ -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,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,
|
|
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,CAsBxE;AAGD,wBAAgB,mBAAmB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAErE"}
|
package/dist/src/name-policy.js
CHANGED
|
@@ -20,6 +20,8 @@ export function createCSharpNamePolicy() {
|
|
|
20
20
|
return changecase.pascalCase(name);
|
|
21
21
|
case "constant":
|
|
22
22
|
return changecase.constantCase(name);
|
|
23
|
+
case "class-member-private":
|
|
24
|
+
return `_${changecase.camelCase(name)}`;
|
|
23
25
|
default:
|
|
24
26
|
return changecase.camelCase(name);
|
|
25
27
|
}
|
|
@@ -106,14 +106,14 @@ it("declares class with some members", () => {
|
|
|
106
106
|
"public": true,
|
|
107
107
|
name: "TestClass",
|
|
108
108
|
get children() {
|
|
109
|
-
return _$createComponent(
|
|
109
|
+
return _$createComponent(List, {
|
|
110
110
|
get children() {
|
|
111
111
|
return [_$createComponent(Field, {
|
|
112
112
|
"public": true,
|
|
113
113
|
name: "MemberOne",
|
|
114
114
|
type: "string"
|
|
115
115
|
}), _$createComponent(Field, {
|
|
116
|
-
"
|
|
116
|
+
"public": true,
|
|
117
117
|
name: "MemberTwo",
|
|
118
118
|
type: "int"
|
|
119
119
|
})];
|
|
@@ -127,7 +127,7 @@ it("declares class with some members", () => {
|
|
|
127
127
|
public class TestClass
|
|
128
128
|
{
|
|
129
129
|
public string MemberOne;
|
|
130
|
-
|
|
130
|
+
public int MemberTwo;
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
`);
|
|
@@ -217,7 +217,7 @@ it("uses refkeys for members, params, and return type", () => {
|
|
|
217
217
|
"private": true,
|
|
218
218
|
name: "MemberOne",
|
|
219
219
|
type: enumTypeRefkey
|
|
220
|
-
}),
|
|
220
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.Method, {
|
|
221
221
|
"public": true,
|
|
222
222
|
name: "MethodOne",
|
|
223
223
|
parameters: params,
|
|
@@ -246,7 +246,7 @@ it("uses refkeys for members, params, and return type", () => {
|
|
|
246
246
|
public class TestResult;
|
|
247
247
|
public class TestClass
|
|
248
248
|
{
|
|
249
|
-
private TestEnum
|
|
249
|
+
private TestEnum _memberOne;
|
|
250
250
|
public TestResult MethodOne(int intParam, TestInput bodyParam)
|
|
251
251
|
{
|
|
252
252
|
return new TestResult();
|
|
@@ -393,12 +393,12 @@ it("declares class with constructor params and assigns values to fields", () =>
|
|
|
393
393
|
name: "name",
|
|
394
394
|
type: "string",
|
|
395
395
|
refkey: thisNameRefkey
|
|
396
|
-
}),
|
|
396
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(Field, {
|
|
397
397
|
"private": true,
|
|
398
398
|
name: "size",
|
|
399
399
|
type: "int",
|
|
400
400
|
refkey: thisSizeRefkey
|
|
401
|
-
}),
|
|
401
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(Constructor, {
|
|
402
402
|
"public": true,
|
|
403
403
|
parameters: ctorParams,
|
|
404
404
|
get children() {
|
|
@@ -415,12 +415,12 @@ it("declares class with constructor params and assigns values to fields", () =>
|
|
|
415
415
|
{
|
|
416
416
|
public class TestClass
|
|
417
417
|
{
|
|
418
|
-
private string
|
|
419
|
-
private int
|
|
418
|
+
private string _name;
|
|
419
|
+
private int _size;
|
|
420
420
|
public TestClass(string name, int size)
|
|
421
421
|
{
|
|
422
|
-
|
|
423
|
-
|
|
422
|
+
_name = name;
|
|
423
|
+
_size = size;
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
426
|
}
|
|
@@ -460,7 +460,7 @@ it("supports class member doc comments", () => {
|
|
|
460
460
|
class Test
|
|
461
461
|
{
|
|
462
462
|
/// This is a member
|
|
463
|
-
public int Member
|
|
463
|
+
public int Member;
|
|
464
464
|
}
|
|
465
465
|
`);
|
|
466
466
|
});
|