@alloy-js/csharp 0.19.0-dev.4 → 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.
Files changed (34) hide show
  1. package/dist/src/components/ClassDeclaration.d.ts +0 -8
  2. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  3. package/dist/src/components/ClassDeclaration.js +1 -31
  4. package/dist/src/components/field/field.d.ts +19 -0
  5. package/dist/src/components/field/field.d.ts.map +1 -0
  6. package/dist/src/components/field/field.js +38 -0
  7. package/dist/src/components/field/field.test.d.ts +2 -0
  8. package/dist/src/components/field/field.test.d.ts.map +1 -0
  9. package/dist/src/components/field/field.test.js +143 -0
  10. package/dist/src/components/index.d.ts +1 -0
  11. package/dist/src/components/index.d.ts.map +1 -1
  12. package/dist/src/components/index.js +1 -0
  13. package/dist/src/components/stc/index.d.ts +1 -1
  14. package/dist/src/components/stc/index.d.ts.map +1 -1
  15. package/dist/src/components/stc/index.js +1 -1
  16. package/dist/src/components/struct/declaration.d.ts +2 -0
  17. package/dist/src/components/struct/declaration.d.ts.map +1 -1
  18. package/dist/src/components/struct/declaration.js +6 -2
  19. package/dist/src/components/struct/declaration.test.js +44 -0
  20. package/dist/src/name-policy.d.ts.map +1 -1
  21. package/dist/src/name-policy.js +2 -0
  22. package/dist/test/class-declaration.test.js +19 -18
  23. package/dist/tsconfig.tsbuildinfo +1 -1
  24. package/package.json +1 -1
  25. package/src/components/ClassDeclaration.tsx +2 -40
  26. package/src/components/field/field.test.tsx +122 -0
  27. package/src/components/field/field.tsx +70 -0
  28. package/src/components/index.ts +1 -0
  29. package/src/components/stc/index.ts +1 -1
  30. package/src/components/struct/declaration.test.tsx +30 -0
  31. package/src/components/struct/declaration.tsx +11 -0
  32. package/src/name-policy.ts +2 -0
  33. package/temp/api.json +361 -190
  34. package/test/class-declaration.test.tsx +19 -38
@@ -73,12 +73,4 @@ export interface ClassDeclarationProps extends Omit<core.DeclarationProps, "name
73
73
  * ```
74
74
  */
75
75
  export declare function ClassDeclaration(props: ClassDeclarationProps): core.Children;
76
- export interface ClassMemberProps extends AccessModifiers {
77
- name: string;
78
- type: core.Children;
79
- refkey?: core.Refkey;
80
- /** Doc comment */
81
- doc?: core.Children;
82
- }
83
- export declare function ClassMember(props: ClassMemberProps): core.Children;
84
76
  //# sourceMappingURL=ClassDeclaration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ClassDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/ClassDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EACL,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAiB,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAI5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAG1E,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B;AAUD,MAAM,WAAW,qBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,cAAc;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IAErB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,CAAC;IAEjD,yCAAyC;IACzC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IAEzB,uCAAuC;IACvC,cAAc,CAAC,EAAE,IA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AE,IAAI,CAAC,MAAM,CAAC;IAErB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,CAAC;IAEjD,yCAAyC;IACzC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IAEzB,uCAAuC;IACvC,cAAc,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;IAEjC;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,iBA6C5D"}
@@ -4,7 +4,7 @@ import { join } from "@alloy-js/core";
4
4
  import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../modifiers.js";
5
5
  import { useCSharpNamePolicy } from "../name-policy.js";
6
6
  import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
7
- import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
7
+ import { CSharpMemberScope } from "../symbols/scopes.js";
8
8
  import { AttributeList } from "./attributes/attributes.js";
9
9
  import { DocWhen } from "./doc/comment.js";
10
10
  import { Name } from "./Name.js";
@@ -89,34 +89,4 @@ export function ClassDeclaration(props) {
89
89
  }))];
90
90
  }
91
91
  });
92
- }
93
-
94
- // properties for creating a class member
95
-
96
- // a C# class member (i.e. a field within a class like "private int count")
97
- export function ClassMember(props) {
98
- let nameElement = "class-member-private";
99
- if (props.public) {
100
- nameElement = "class-member-public";
101
- }
102
- const name = useCSharpNamePolicy().getName(props.name, nameElement);
103
- const scope = useCSharpScope();
104
- if (scope.kind !== "member" || scope.name !== "class-decl") {
105
- throw new Error("can't define a class member outside of a class-decl scope");
106
- }
107
- const memberSymbol = new CSharpOutputSymbol(name, {
108
- scope,
109
- refkeys: props.refkey ?? core.refkey(props.name)
110
- });
111
- const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
112
- return _$createComponent(core.Declaration, {
113
- symbol: memberSymbol,
114
- get children() {
115
- return [_$createComponent(DocWhen, {
116
- get doc() {
117
- return props.doc;
118
- }
119
- }), modifiers, _$memo(() => props.type), " ", _$createComponent(Name, {})];
120
- }
121
- });
122
92
  }
@@ -0,0 +1,19 @@
1
+ import { Children, Refkey } from "@alloy-js/core";
2
+ import { AccessModifiers } from "../../modifiers.js";
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 {
11
+ name: string;
12
+ type: Children;
13
+ refkey?: Refkey;
14
+ /** Doc comment */
15
+ doc?: Children;
16
+ }
17
+ /** Render a c# field */
18
+ export declare function Field(props: FieldProps): Children;
19
+ //# sourceMappingURL=field.d.ts.map
@@ -0,0 +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,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"}
@@ -0,0 +1,38 @@
1
+ import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import { Declaration, Name, refkey } 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 { useCSharpScope } from "../../symbols/scopes.js";
7
+ import { DocWhen } from "../doc/comment.js";
8
+
9
+ /** Field modifiers. */
10
+
11
+ const getModifiers = makeModifiers(["new", "static", "readonly", "volatile"]);
12
+ /** Render a c# field */
13
+ export function Field(props) {
14
+ let nameElement = "class-member-private";
15
+ if (props.public || props.protected || props.internal) {
16
+ nameElement = "class-member-public";
17
+ }
18
+ const name = useCSharpNamePolicy().getName(props.name, nameElement);
19
+ const scope = useCSharpScope();
20
+ if (scope.kind !== "member" || scope.name !== "class-decl" && scope.name !== "struct-decl") {
21
+ throw new Error("can't define a class member outside of a class or struct scope");
22
+ }
23
+ const memberSymbol = new CSharpOutputSymbol(name, {
24
+ scope,
25
+ refkeys: props.refkey ?? refkey(props.name)
26
+ });
27
+ const modifiers = computeModifiersPrefix([getAccessModifier(props), getModifiers(props)]);
28
+ return _$createComponent(Declaration, {
29
+ symbol: memberSymbol,
30
+ get children() {
31
+ return [_$createComponent(DocWhen, {
32
+ get doc() {
33
+ return props.doc;
34
+ }
35
+ }), modifiers, _$memo(() => props.type), " ", _$createComponent(Name, {}), ";"];
36
+ }
37
+ });
38
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=field.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.test.d.ts","sourceRoot":"","sources":["../../../../src/components/field/field.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,143 @@
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
+ import { TestNamespace } from "../../../test/utils.js";
5
+ import { ClassDeclaration } from "../ClassDeclaration.js";
6
+ import { Field } from "./field.js";
7
+ function Wrapper(props) {
8
+ return _$createComponent(TestNamespace, {
9
+ get children() {
10
+ return _$createComponent(ClassDeclaration, {
11
+ "public": true,
12
+ name: "TestClass",
13
+ get children() {
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
+ })];
34
+ }
35
+ });
36
+ }
37
+ })).toRenderTo(`
38
+ public class TestClass
39
+ {
40
+ public string MemberOne;
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;
140
+ }
141
+ `);
142
+ });
143
+ });
@@ -5,6 +5,7 @@ export * from "./Declaration.js";
5
5
  export * from "./doc/comment.jsx";
6
6
  export * from "./doc/from-markdown.jsx";
7
7
  export * from "./EnumDeclaration.jsx";
8
+ export * from "./field/field.jsx";
8
9
  export * from "./interface/declaration.js";
9
10
  export * from "./interface/method.js";
10
11
  export * from "./interface/property.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC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Ac,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
@@ -5,6 +5,7 @@ export * from "./Declaration.js";
5
5
  export * from "./doc/comment.js";
6
6
  export * from "./doc/from-markdown.js";
7
7
  export * from "./EnumDeclaration.js";
8
+ export * from "./field/field.js";
8
9
  export * from "./interface/declaration.js";
9
10
  export * from "./interface/method.js";
10
11
  export * from "./interface/property.js";
@@ -2,7 +2,7 @@ import * as core from "@alloy-js/core";
2
2
  import * as base from "../index.js";
3
3
  export declare const ClassDeclaration: core.StcSignature<base.ClassDeclarationProps>;
4
4
  export declare const Constructor: core.StcSignature<base.ConstructorProps>;
5
- export declare const ClassMember: core.StcSignature<base.ClassMemberProps>;
5
+ export declare const Field: core.StcSignature<base.FieldProps>;
6
6
  export declare const ClassMethod: core.StcSignature<base.MethodProps>;
7
7
  export declare const EnumDeclaration: core.StcSignature<base.EnumDeclarationProps>;
8
8
  export declare const EnumMember: core.StcSignature<base.EnumMemberProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/stc/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,WAAW,qCAAwB,CAAC;AACjD,eAAO,MAAM,eAAe,8CAAiC,CAAC;AAC9D,eAAO,MAAM,UAAU,yCAA4B,CAAC;AACpD,eAAO,MAAM,SAAS,wCAA2B,CAAC;AAClD,eAAO,MAAM,UAAU,yCAA4B,CAAC;AACpD,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,cAAc,6CAAgC,CAAC;AAC5D,eAAO,MAAM,iBAAiB,gDAAmC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/stc/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,KAAK,oCAAuB,CAAC;AAC1C,eAAO,MAAM,WAAW,qCAAwB,CAAC;AACjD,eAAO,MAAM,eAAe,8CAAiC,CAAC;AAC9D,eAAO,MAAM,UAAU,yCAA4B,CAAC;AACpD,eAAO,MAAM,SAAS,wCAA2B,CAAC;AAClD,eAAO,MAAM,UAAU,yCAA4B,CAAC;AACpD,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,cAAc,6CAAgC,CAAC;AAC5D,eAAO,MAAM,iBAAiB,gDAAmC,CAAC"}
@@ -2,7 +2,7 @@ import * as core from "@alloy-js/core";
2
2
  import * as base from "../index.js";
3
3
  export const ClassDeclaration = core.stc(base.ClassDeclaration);
4
4
  export const Constructor = core.stc(base.Constructor);
5
- export const ClassMember = core.stc(base.ClassMember);
5
+ export const Field = core.stc(base.Field);
6
6
  export const ClassMethod = core.stc(base.Method);
7
7
  export const EnumDeclaration = core.stc(base.EnumDeclaration);
8
8
  export const EnumMember = core.stc(base.EnumMember);
@@ -43,6 +43,8 @@ export interface StructDeclarationProps extends Omit<core.DeclarationProps, "nam
43
43
  * ```
44
44
  */
45
45
  attributes?: AttributesProp;
46
+ /** Interfaces this struct implements */
47
+ interfaceTypes?: core.Children[];
46
48
  }
47
49
  /**
48
50
  * CSharp struct declaration.
@@ -1 +1 @@
1
- {"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/struct/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,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AAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAUD,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,eAAe;IACjB,IAAI,EAAE,MAAM,CAAC;IAEb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IAErB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;IAEjD;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;IAE5B,wCAAwC;IACxC,cAAc,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,iBAwC9D"}
@@ -1,5 +1,6 @@
1
- import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
1
+ import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
2
  import * as core from "@alloy-js/core";
3
+ import { join } from "@alloy-js/core";
3
4
  import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../modifiers.js";
4
5
  import { useCSharpNamePolicy } from "../../name-policy.js";
5
6
  import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
@@ -42,6 +43,9 @@ export function StructDeclaration(props) {
42
43
  owner: thisStructSymbol
43
44
  });
44
45
  const modifiers = computeModifiersPrefix([getAccessModifier(props), getStructModifiers(props)]);
46
+ const base = props.interfaceTypes && props.interfaceTypes.length > 0 ? [" : ", _$memo(() => join(props.interfaceTypes, {
47
+ joiner: ", "
48
+ }))] : null;
45
49
  return _$createComponent(core.Declaration, {
46
50
  symbol: thisStructSymbol,
47
51
  get children() {
@@ -58,7 +62,7 @@ export function StructDeclaration(props) {
58
62
  get parameters() {
59
63
  return props.typeParameters;
60
64
  }
61
- })), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
65
+ })), base, _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
62
66
  get parameters() {
63
67
  return props.typeParameters;
64
68
  }
@@ -4,6 +4,7 @@ import { describe, expect, it } from "vitest";
4
4
  import { TestNamespace } from "../../../test/utils.js";
5
5
  import { Attribute } from "../attributes/attributes.js";
6
6
  import { Constructor } from "../constructor/constructor.js";
7
+ import { Field } from "../field/field.js";
7
8
  import { Method } from "../method/method.js";
8
9
  import { Property } from "../property/property.js";
9
10
  import { SourceFile } from "../SourceFile.js";
@@ -208,4 +209,47 @@ it("define constructor", () => {
208
209
  public Test() {}
209
210
  }
210
211
  `);
212
+ });
213
+ it("defines fields", () => {
214
+ expect(_$createComponent(TestNamespace, {
215
+ get children() {
216
+ return _$createComponent(StructDeclaration, {
217
+ "public": true,
218
+ name: "TestClass",
219
+ get children() {
220
+ return _$createComponent(List, {
221
+ get children() {
222
+ return [_$createComponent(Field, {
223
+ "public": true,
224
+ name: "MemberOne",
225
+ type: "string"
226
+ }), _$createComponent(Field, {
227
+ "public": true,
228
+ name: "MemberTwo",
229
+ type: "int"
230
+ })];
231
+ }
232
+ });
233
+ }
234
+ });
235
+ }
236
+ })).toRenderTo(`
237
+ public struct TestClass
238
+ {
239
+ public string MemberOne;
240
+ public int MemberTwo;
241
+ }
242
+ `);
243
+ });
244
+ it("define multiple interface types", () => {
245
+ expect(_$createComponent(TestNamespace, {
246
+ get children() {
247
+ return _$createComponent(StructDeclaration, {
248
+ name: "Test",
249
+ interfaceTypes: ["Foo", "Bar"]
250
+ });
251
+ }
252
+ })).toRenderTo(`
253
+ struct Test : Foo, Bar;
254
+ `);
211
255
  });
@@ -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,CAoBxE;AAGD,wBAAgB,mBAAmB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAErE"}
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"}
@@ -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
  }
@@ -4,9 +4,10 @@ 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 { Field } from "../src/components/field/field.js";
7
8
  import { Constructor } from "../src/components/stc/index.js";
8
9
  import * as csharp from "../src/index.js";
9
- import { ClassDeclaration, ClassMember, Property, SourceFile } from "../src/index.js";
10
+ import { ClassDeclaration, Property, SourceFile } from "../src/index.js";
10
11
  import * as utils from "./utils.js";
11
12
  it("declares class with no members", () => {
12
13
  expect(_$createComponent(utils.TestNamespace, {
@@ -105,14 +106,14 @@ it("declares class with some members", () => {
105
106
  "public": true,
106
107
  name: "TestClass",
107
108
  get children() {
108
- return _$createComponent(core.StatementList, {
109
+ return _$createComponent(List, {
109
110
  get children() {
110
- return [_$createComponent(csharp.ClassMember, {
111
+ return [_$createComponent(Field, {
111
112
  "public": true,
112
113
  name: "MemberOne",
113
114
  type: "string"
114
- }), _$createComponent(csharp.ClassMember, {
115
- "private": true,
115
+ }), _$createComponent(Field, {
116
+ "public": true,
116
117
  name: "MemberTwo",
117
118
  type: "int"
118
119
  })];
@@ -126,7 +127,7 @@ it("declares class with some members", () => {
126
127
  public class TestClass
127
128
  {
128
129
  public string MemberOne;
129
- private int memberTwo;
130
+ public int MemberTwo;
130
131
  }
131
132
  }
132
133
  `);
@@ -212,11 +213,11 @@ it("uses refkeys for members, params, and return type", () => {
212
213
  "public": true,
213
214
  name: "TestClass",
214
215
  get children() {
215
- return [_$createComponent(csharp.ClassMember, {
216
+ return [_$createComponent(Field, {
216
217
  "private": true,
217
218
  name: "MemberOne",
218
219
  type: enumTypeRefkey
219
- }), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.Method, {
220
+ }), _$createIntrinsic("hbr", {}), _$createComponent(csharp.Method, {
220
221
  "public": true,
221
222
  name: "MethodOne",
222
223
  parameters: params,
@@ -245,7 +246,7 @@ it("uses refkeys for members, params, and return type", () => {
245
246
  public class TestResult;
246
247
  public class TestClass
247
248
  {
248
- private TestEnum memberOne;
249
+ private TestEnum _memberOne;
249
250
  public TestResult MethodOne(int intParam, TestInput bodyParam)
250
251
  {
251
252
  return new TestResult();
@@ -387,17 +388,17 @@ it("declares class with constructor params and assigns values to fields", () =>
387
388
  "public": true,
388
389
  name: "TestClass",
389
390
  get children() {
390
- return [_$createComponent(csharp.ClassMember, {
391
+ return [_$createComponent(Field, {
391
392
  "private": true,
392
393
  name: "name",
393
394
  type: "string",
394
395
  refkey: thisNameRefkey
395
- }), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassMember, {
396
+ }), _$createIntrinsic("hbr", {}), _$createComponent(Field, {
396
397
  "private": true,
397
398
  name: "size",
398
399
  type: "int",
399
400
  refkey: thisSizeRefkey
400
- }), ";", _$createIntrinsic("hbr", {}), _$createComponent(Constructor, {
401
+ }), _$createIntrinsic("hbr", {}), _$createComponent(Constructor, {
401
402
  "public": true,
402
403
  parameters: ctorParams,
403
404
  get children() {
@@ -414,12 +415,12 @@ it("declares class with constructor params and assigns values to fields", () =>
414
415
  {
415
416
  public class TestClass
416
417
  {
417
- private string name;
418
- private int size;
418
+ private string _name;
419
+ private int _size;
419
420
  public TestClass(string name, int size)
420
421
  {
421
- name = name;
422
- size = size;
422
+ _name = name;
423
+ _size = size;
423
424
  }
424
425
  }
425
426
  }
@@ -445,7 +446,7 @@ it("supports class member doc comments", () => {
445
446
  name: "Test",
446
447
  doc: "This is a test",
447
448
  get children() {
448
- return _$createComponent(ClassMember, {
449
+ return _$createComponent(Field, {
449
450
  name: "Member",
450
451
  "public": true,
451
452
  type: "int",
@@ -459,7 +460,7 @@ it("supports class member doc comments", () => {
459
460
  class Test
460
461
  {
461
462
  /// This is a member
462
- public int Member
463
+ public int Member;
463
464
  }
464
465
  `);
465
466
  });