@alloy-js/csharp 0.18.0-dev.8 → 0.18.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.
Files changed (127) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/src/components/ClassDeclaration.d.ts +39 -2
  3. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  4. package/dist/src/components/ClassDeclaration.js +35 -34
  5. package/dist/src/components/ClassMethod.d.ts +33 -1
  6. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  7. package/dist/src/components/ClassMethod.js +22 -7
  8. package/dist/src/components/SourceFile.d.ts.map +1 -1
  9. package/dist/src/components/SourceFile.js +1 -0
  10. package/dist/src/components/attributes/attributes.d.ts +39 -0
  11. package/dist/src/components/attributes/attributes.d.ts.map +1 -0
  12. package/dist/src/components/attributes/attributes.js +62 -0
  13. package/dist/src/components/attributes/attributes.test.d.ts +2 -0
  14. package/dist/src/components/attributes/attributes.test.d.ts.map +1 -0
  15. package/dist/src/components/attributes/attributes.test.js +75 -0
  16. package/dist/src/components/doc/comment.d.ts +12 -11
  17. package/dist/src/components/doc/comment.d.ts.map +1 -1
  18. package/dist/src/components/doc/comment.js +27 -10
  19. package/dist/src/components/doc/comment.test.js +98 -88
  20. package/dist/src/components/doc/from-markdown.d.ts +6 -0
  21. package/dist/src/components/doc/from-markdown.d.ts.map +1 -0
  22. package/dist/src/components/doc/from-markdown.js +58 -0
  23. package/dist/src/components/doc/from-markdown.test.d.ts +2 -0
  24. package/dist/src/components/doc/from-markdown.test.d.ts.map +1 -0
  25. package/dist/src/components/doc/from-markdown.test.js +83 -0
  26. package/dist/src/components/index.d.ts +9 -1
  27. package/dist/src/components/index.d.ts.map +1 -1
  28. package/dist/src/components/index.js +10 -2
  29. package/dist/src/components/interface/declaration.d.ts +32 -1
  30. package/dist/src/components/interface/declaration.d.ts.map +1 -1
  31. package/dist/src/components/interface/declaration.js +18 -25
  32. package/dist/src/components/interface/declaration.test.js +102 -0
  33. package/dist/src/components/interface/method.d.ts +33 -1
  34. package/dist/src/components/interface/method.d.ts.map +1 -1
  35. package/dist/src/components/interface/method.js +22 -7
  36. package/dist/src/components/interface/method.test.js +169 -0
  37. package/dist/src/components/interface/property.d.ts +36 -1
  38. package/dist/src/components/interface/property.d.ts.map +1 -1
  39. package/dist/src/components/interface/property.js +18 -4
  40. package/dist/src/components/interface/property.test.js +24 -0
  41. package/dist/src/components/parameters/parameters.d.ts +19 -0
  42. package/dist/src/components/parameters/parameters.d.ts.map +1 -0
  43. package/dist/src/components/parameters/parameters.js +43 -0
  44. package/dist/src/components/property/property.d.ts +80 -0
  45. package/dist/src/components/property/property.d.ts.map +1 -0
  46. package/dist/src/components/property/property.js +76 -0
  47. package/dist/src/components/property/property.test.d.ts +2 -0
  48. package/dist/src/components/property/property.test.d.ts.map +1 -0
  49. package/dist/src/components/property/property.test.js +242 -0
  50. package/dist/src/components/record/declaration.d.ts +35 -0
  51. package/dist/src/components/record/declaration.d.ts.map +1 -0
  52. package/dist/src/components/record/declaration.js +90 -0
  53. package/dist/src/components/record/declaration.test.d.ts +2 -0
  54. package/dist/src/components/record/declaration.test.d.ts.map +1 -0
  55. package/dist/src/components/record/declaration.test.js +94 -0
  56. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +8 -0
  57. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +1 -0
  58. package/dist/src/components/type-parameters/type-parameter-constraints.js +44 -0
  59. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +2 -0
  60. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +1 -0
  61. package/dist/src/components/type-parameters/type-parameter-constraints.test.js +67 -0
  62. package/dist/src/components/type-parameters/type-parameter.d.ts +20 -0
  63. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -0
  64. package/dist/src/components/type-parameters/type-parameter.js +22 -0
  65. package/dist/src/components/type-parameters/type-parameters.d.ts +17 -0
  66. package/dist/src/components/type-parameters/type-parameters.d.ts.map +1 -0
  67. package/dist/src/components/type-parameters/type-parameters.js +54 -0
  68. package/dist/src/components/type-parameters/type-parameters.test.d.ts +2 -0
  69. package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +1 -0
  70. package/dist/src/components/type-parameters/type-parameters.test.js +48 -0
  71. package/dist/src/components/var/declaration.d.ts +35 -0
  72. package/dist/src/components/var/declaration.d.ts.map +1 -0
  73. package/dist/src/components/var/declaration.js +40 -0
  74. package/dist/src/components/var/declaration.test.d.ts +2 -0
  75. package/dist/src/components/var/declaration.test.d.ts.map +1 -0
  76. package/dist/src/components/var/declaration.test.js +73 -0
  77. package/dist/src/name-policy.d.ts +1 -1
  78. package/dist/src/name-policy.d.ts.map +1 -1
  79. package/dist/src/name-policy.js +1 -0
  80. package/dist/test/class-declaration.test.d.ts +2 -0
  81. package/dist/test/class-declaration.test.d.ts.map +1 -0
  82. package/dist/test/{class.test.js → class-declaration.test.js} +161 -33
  83. package/dist/test/project-directory.test.d.ts +2 -0
  84. package/dist/test/project-directory.test.d.ts.map +1 -0
  85. package/dist/tsconfig.tsbuildinfo +1 -1
  86. package/package.json +7 -6
  87. package/src/components/ClassDeclaration.tsx +65 -33
  88. package/src/components/ClassMethod.tsx +46 -4
  89. package/src/components/SourceFile.tsx +1 -0
  90. package/src/components/attributes/attributes.test.tsx +61 -0
  91. package/src/components/attributes/attributes.tsx +100 -0
  92. package/src/components/doc/comment.test.tsx +80 -79
  93. package/src/components/doc/comment.tsx +44 -14
  94. package/src/components/doc/from-markdown.test.tsx +103 -0
  95. package/src/components/doc/from-markdown.tsx +58 -0
  96. package/src/components/index.ts +9 -1
  97. package/src/components/interface/declaration.test.tsx +102 -0
  98. package/src/components/interface/declaration.tsx +43 -27
  99. package/src/components/interface/method.test.tsx +173 -0
  100. package/src/components/interface/method.tsx +45 -5
  101. package/src/components/interface/property.test.tsx +21 -0
  102. package/src/components/interface/property.tsx +43 -6
  103. package/src/components/parameters/parameters.tsx +74 -0
  104. package/src/components/property/property.test.tsx +209 -0
  105. package/src/components/property/property.tsx +172 -0
  106. package/src/components/record/declaration.test.tsx +73 -0
  107. package/src/components/record/declaration.tsx +109 -0
  108. package/src/components/type-parameters/type-parameter-constraints.test.tsx +93 -0
  109. package/src/components/type-parameters/type-parameter-constraints.tsx +46 -0
  110. package/src/components/type-parameters/type-parameter.tsx +35 -0
  111. package/src/components/type-parameters/type-parameters.test.tsx +46 -0
  112. package/src/components/type-parameters/type-parameters.tsx +63 -0
  113. package/src/components/var/declaration.test.tsx +59 -0
  114. package/src/components/var/declaration.tsx +47 -0
  115. package/src/name-policy.ts +3 -0
  116. package/temp/api.json +5838 -1626
  117. package/test/{class.test.tsx → class-declaration.test.tsx} +144 -26
  118. package/dist/src/components/Parameters.d.ts +0 -13
  119. package/dist/src/components/Parameters.d.ts.map +0 -1
  120. package/dist/src/components/Parameters.js +0 -34
  121. package/dist/test/class.test.d.ts +0 -2
  122. package/dist/test/class.test.d.ts.map +0 -1
  123. package/dist/test/projectdirectory.test.d.ts +0 -2
  124. package/dist/test/projectdirectory.test.d.ts.map +0 -1
  125. package/src/components/Parameters.tsx +0 -51
  126. /package/dist/test/{projectdirectory.test.js → project-directory.test.js} +0 -0
  127. /package/test/{projectdirectory.test.tsx → project-directory.test.tsx} +0 -0
@@ -1,7 +1,11 @@
1
1
  import { createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { List, refkey } from "@alloy-js/core";
2
3
  import { describe, expect, it } from "vitest";
3
4
  import { TestNamespace } from "../../../test/utils.js";
5
+ import { Attribute } from "../attributes/attributes.js";
6
+ import { SourceFile } from "../SourceFile.js";
4
7
  import { InterfaceDeclaration } from "./declaration.js";
8
+ import { InterfaceProperty } from "./property.js";
5
9
  it("declares class with no members", () => {
6
10
  expect(_$createComponent(TestNamespace, {
7
11
  get children() {
@@ -66,4 +70,102 @@ it("specify doc comment", () => {
66
70
  /// This is a test
67
71
  interface TestInterface;
68
72
  `);
73
+ });
74
+ describe("with type parameters", () => {
75
+ it("reference parameters", () => {
76
+ const typeParameters = [{
77
+ name: "T",
78
+ refkey: refkey()
79
+ }, {
80
+ name: "U",
81
+ refkey: refkey()
82
+ }];
83
+ expect(_$createComponent(TestNamespace, {
84
+ get children() {
85
+ return _$createComponent(SourceFile, {
86
+ path: "Test.cs",
87
+ get children() {
88
+ return _$createComponent(InterfaceDeclaration, {
89
+ "public": true,
90
+ name: "Test",
91
+ typeParameters: typeParameters,
92
+ get children() {
93
+ return _$createComponent(List, {
94
+ get children() {
95
+ return [_$createComponent(InterfaceProperty, {
96
+ name: "PropA",
97
+ get type() {
98
+ return typeParameters[0].refkey;
99
+ },
100
+ get: true,
101
+ set: true
102
+ }), _$createComponent(InterfaceProperty, {
103
+ name: "PropB",
104
+ get type() {
105
+ return typeParameters[1].refkey;
106
+ },
107
+ get: true,
108
+ set: true
109
+ })];
110
+ }
111
+ });
112
+ }
113
+ });
114
+ }
115
+ });
116
+ }
117
+ })).toRenderTo(`
118
+ namespace TestCode
119
+ {
120
+ public interface Test<T, U>
121
+ {
122
+ T PropA { get; set; }
123
+ U PropB { get; set; }
124
+ }
125
+ }
126
+ `);
127
+ });
128
+ it("defines with constraints", () => {
129
+ const typeParameters = [{
130
+ name: "T",
131
+ constraints: "IFoo"
132
+ }, {
133
+ name: "U",
134
+ constraints: "IBar"
135
+ }];
136
+ expect(_$createComponent(TestNamespace, {
137
+ get children() {
138
+ return _$createComponent(InterfaceDeclaration, {
139
+ "public": true,
140
+ name: "Test",
141
+ typeParameters: typeParameters,
142
+ children: "// Body"
143
+ });
144
+ }
145
+ })).toRenderTo(`
146
+ public interface Test<T, U>
147
+ where T : IFoo
148
+ where U : IBar
149
+ {
150
+ // Body
151
+ }
152
+ `);
153
+ });
154
+ });
155
+ it("specify attributes", () => {
156
+ expect(_$createComponent(TestNamespace, {
157
+ get children() {
158
+ return _$createComponent(InterfaceDeclaration, {
159
+ name: "Test",
160
+ get attributes() {
161
+ return [_$createComponent(Attribute, {
162
+ name: "Test"
163
+ })];
164
+ }
165
+ });
166
+ }
167
+ })).toRenderTo(`
168
+ [Test]
169
+ interface Test;
170
+ `);
69
171
  });
@@ -1,6 +1,8 @@
1
1
  import { Children, Refkey } from "@alloy-js/core";
2
2
  import { AccessModifiers } from "../../modifiers.js";
3
- import { ParameterProps } from "../Parameters.jsx";
3
+ import { AttributesProp } from "../attributes/attributes.jsx";
4
+ import { ParameterProps } from "../parameters/parameters.jsx";
5
+ import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
4
6
  /** Method modifiers. Can only be one. */
5
7
  export interface InterfaceMethodModifiers {
6
8
  readonly new?: boolean;
@@ -10,9 +12,39 @@ export interface InterfaceMethodProps extends AccessModifiers, InterfaceMethodMo
10
12
  refkey?: Refkey;
11
13
  children?: Children;
12
14
  parameters?: Array<ParameterProps>;
15
+ /**
16
+ * Type parameters for the method
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * <InterfaceMethod name="Test" typeParameters={["T"]} />
21
+ * ```
22
+ * This will produce:
23
+ * ```csharp
24
+ * public void Test<T>()
25
+ * ```
26
+ */
27
+ typeParameters?: (TypeParameterProps | string)[];
13
28
  returns?: Children;
14
29
  /** Doc comment */
15
30
  doc?: Children;
31
+ /**
32
+ * Define attributes to attach
33
+ * @example
34
+ * ```tsx
35
+ * <InterfaceMethod name="MyMethod" attributes={[
36
+ * <Attribute name="Test" />
37
+ * <Attribute name="Test2" args={["arg1", "arg2"]} />
38
+ * ]} />
39
+ * ```
40
+ * This will produce:
41
+ * ```csharp
42
+ * [Test]
43
+ * [Test2("arg1", "arg2")]
44
+ * void MyMethod();
45
+ * ```
46
+ */
47
+ attributes?: AttributesProp;
16
48
  }
17
49
  export declare function InterfaceMethod(props: InterfaceMethodProps): Children;
18
50
  //# sourceMappingURL=method.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/method.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,cAAc,EAAc,MAAM,mBAAmB,CAAC;AAG/D,yCAAyC;AACzC,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAKD,MAAM,WAAW,oBACf,SAAQ,eAAe,EACrB,wBAAwB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACnC,OAAO,CAAC,EAAE,QAAQ,CAAC;IAEnB,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAGD,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YAuC1D"}
1
+ {"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/method.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE7E,OAAO,EAAE,cAAc,EAAc,MAAM,8BAA8B,CAAC;AAE1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAG3E,yCAAyC;AACzC,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAKD,MAAM,WAAW,oBACf,SAAQ,eAAe,EACrB,wBAAwB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACnC;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;IACjD,OAAO,CAAC,EAAE,QAAQ,CAAC;IAEnB,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;IAEf;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAGD,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YA4C1D"}
@@ -4,8 +4,11 @@ import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../
4
4
  import { useCSharpNamePolicy } from "../../name-policy.js";
5
5
  import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
6
6
  import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
7
- import { Parameters } from "../Parameters.js";
7
+ import { AttributeList } from "../attributes/attributes.js";
8
8
  import { DocWhen } from "../doc/comment.js";
9
+ import { Parameters } from "../parameters/parameters.js";
10
+ import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
11
+ import { TypeParameters } from "../type-parameters/type-parameters.js";
9
12
 
10
13
  /** Method modifiers. Can only be one. */
11
14
 
@@ -29,11 +32,6 @@ export function InterfaceMethod(props) {
29
32
  const methodScope = new CSharpMemberScope("method-decl", {
30
33
  owner: methodSymbol
31
34
  });
32
- const params = props.parameters ? _$createComponent(Parameters, {
33
- get parameters() {
34
- return props.parameters;
35
- }
36
- }) : "";
37
35
  const modifiers = computeModifiersPrefix([getAccessModifier(props), getMethodModifier(props)]);
38
36
  // note that scope wraps the method decl so that the params get the correct scope
39
37
  return _$createComponent(MemberDeclaration, {
@@ -46,7 +44,24 @@ export function InterfaceMethod(props) {
46
44
  get doc() {
47
45
  return props.doc;
48
46
  }
49
- }), modifiers, _$memo(() => props.returns ?? "void"), " ", name, "(", params, ")", _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(Block, {
47
+ }), _$createComponent(AttributeList, {
48
+ get attributes() {
49
+ return props.attributes;
50
+ },
51
+ endline: true
52
+ }), modifiers, _$memo(() => props.returns ?? "void"), " ", name, _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
53
+ get parameters() {
54
+ return props.typeParameters;
55
+ }
56
+ })), _$createComponent(Parameters, {
57
+ get parameters() {
58
+ return props.parameters;
59
+ }
60
+ }), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
61
+ get parameters() {
62
+ return props.typeParameters;
63
+ }
64
+ })), _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(Block, {
50
65
  newline: true,
51
66
  get children() {
52
67
  return props.children;
@@ -1,6 +1,9 @@
1
1
  import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { refkey } from "@alloy-js/core";
2
3
  import { describe, expect, it } from "vitest";
3
4
  import { TestNamespace } from "../../../test/utils.js";
5
+ import { Attribute } from "../attributes/attributes.js";
6
+ import { SourceFile } from "../SourceFile.js";
4
7
  import { InterfaceDeclaration } from "./declaration.js";
5
8
  import { InterfaceMethod } from "./method.js";
6
9
  const Wrapper = props => _$createComponent(TestNamespace, {
@@ -108,6 +111,50 @@ it("defines params and return type", () => {
108
111
  }
109
112
  `);
110
113
  });
114
+ it("defines optional param", () => {
115
+ const res = _$createComponent(Wrapper, {
116
+ get children() {
117
+ return _$createComponent(InterfaceMethod, {
118
+ "public": true,
119
+ name: "MethodOne",
120
+ parameters: [{
121
+ name: "intParam",
122
+ type: "int",
123
+ optional: true
124
+ }],
125
+ returns: "string"
126
+ });
127
+ }
128
+ });
129
+ expect(res).toRenderTo(`
130
+ public interface TestInterface
131
+ {
132
+ public string MethodOne(int? intParam);
133
+ }
134
+ `);
135
+ });
136
+ it("defines optional param with default", () => {
137
+ const res = _$createComponent(Wrapper, {
138
+ get children() {
139
+ return _$createComponent(InterfaceMethod, {
140
+ "public": true,
141
+ name: "MethodOne",
142
+ parameters: [{
143
+ name: "intParam",
144
+ type: "int",
145
+ default: 12
146
+ }],
147
+ returns: "string"
148
+ });
149
+ }
150
+ });
151
+ expect(res).toRenderTo(`
152
+ public interface TestInterface
153
+ {
154
+ public string MethodOne(int intParam = 12);
155
+ }
156
+ `);
157
+ });
111
158
  it("specify doc comment", () => {
112
159
  expect(_$createComponent(TestNamespace, {
113
160
  get children() {
@@ -128,4 +175,126 @@ it("specify doc comment", () => {
128
175
  void Method();
129
176
  }
130
177
  `);
178
+ });
179
+ it("specify attributes", () => {
180
+ expect(_$createComponent(Wrapper, {
181
+ get children() {
182
+ return _$createComponent(InterfaceMethod, {
183
+ name: "Test",
184
+ get attributes() {
185
+ return [_$createComponent(Attribute, {
186
+ name: "Test"
187
+ })];
188
+ }
189
+ });
190
+ }
191
+ })).toRenderTo(`
192
+ public interface TestInterface
193
+ {
194
+ [Test]
195
+ void Test();
196
+ }
197
+ `);
198
+ });
199
+ describe("with type parameters", () => {
200
+ it("reference parameters", () => {
201
+ const typeParameters = [{
202
+ name: "T",
203
+ refkey: refkey()
204
+ }, {
205
+ name: "U",
206
+ refkey: refkey()
207
+ }];
208
+ expect(_$createComponent(TestNamespace, {
209
+ get children() {
210
+ return _$createComponent(SourceFile, {
211
+ path: "TestFile.cs",
212
+ get children() {
213
+ return _$createComponent(InterfaceDeclaration, {
214
+ "public": true,
215
+ name: "TestInterface",
216
+ get children() {
217
+ return _$createComponent(InterfaceMethod, {
218
+ name: "Test",
219
+ "public": true,
220
+ typeParameters: typeParameters,
221
+ get parameters() {
222
+ return [{
223
+ name: "paramA",
224
+ type: typeParameters[0].refkey
225
+ }];
226
+ },
227
+ get returns() {
228
+ return typeParameters[0].refkey;
229
+ }
230
+ });
231
+ }
232
+ });
233
+ }
234
+ });
235
+ }
236
+ })).toRenderTo(`
237
+ namespace TestCode
238
+ {
239
+ public interface TestInterface
240
+ {
241
+ public T Test<T, U>(T paramA);
242
+ }
243
+ }
244
+ `);
245
+ });
246
+ it("defines with constraints", () => {
247
+ const typeParameters = [{
248
+ name: "T",
249
+ constraints: "IFoo"
250
+ }, {
251
+ name: "U",
252
+ constraints: "IBar"
253
+ }];
254
+ expect(_$createComponent(Wrapper, {
255
+ get children() {
256
+ return _$createComponent(InterfaceMethod, {
257
+ "public": true,
258
+ name: "Test",
259
+ typeParameters: typeParameters,
260
+ children: "// Body"
261
+ });
262
+ }
263
+ })).toRenderTo(`
264
+ public interface TestInterface
265
+ {
266
+ public void Test<T, U>()
267
+ where T : IFoo
268
+ where U : IBar
269
+ {
270
+ // Body
271
+ }
272
+ }
273
+ `);
274
+ });
275
+ });
276
+ describe("formatting", () => {
277
+ it("Split parameters before type parameters", () => {
278
+ expect(_$createComponent(Wrapper, {
279
+ get children() {
280
+ return _$createComponent(InterfaceMethod, {
281
+ "public": true,
282
+ name: "Handle",
283
+ parameters: [{
284
+ name: "message",
285
+ type: "Some.Quite.Long.Type.That.Will.Split"
286
+ }],
287
+ typeParameters: ["T"],
288
+ returns: "Some.Quite.Long.Type.That.Will.Split"
289
+ });
290
+ }
291
+ })).toRenderTo(`
292
+ public interface TestInterface
293
+ {
294
+ public Some.Quite.Long.Type.That.Will.Split Handle<T>(
295
+ Some.Quite.Long.Type.That.Will.Split message
296
+ );
297
+ }
298
+ `);
299
+ });
131
300
  });
@@ -1,10 +1,10 @@
1
1
  import { Children, Refkey } from "@alloy-js/core";
2
2
  import { AccessModifiers } from "../../modifiers.js";
3
+ import { AttributesProp } from "../attributes/attributes.jsx";
3
4
  /** Method modifiers. Can only be one. */
4
5
  export interface InterfacePropertyModifiers {
5
6
  readonly new?: boolean;
6
7
  }
7
- export declare const getMethodModifier: (data: InterfacePropertyModifiers) => string;
8
8
  export interface InterfacePropertyProps extends AccessModifiers, InterfacePropertyModifiers {
9
9
  name: string;
10
10
  refkey?: Refkey;
@@ -16,6 +16,41 @@ export interface InterfacePropertyProps extends AccessModifiers, InterfaceProper
16
16
  set?: boolean;
17
17
  /** Doc comment */
18
18
  doc?: Children;
19
+ /**
20
+ * Property initializer
21
+ * @example `<ClassProperty name="My" get set nullable />`
22
+ *
23
+ * ```cs
24
+ * int? My { get; set; };
25
+ * ```
26
+ */
27
+ nullable?: boolean;
28
+ /**
29
+ * Define attributes to attach
30
+ * @example
31
+ * ```tsx
32
+ * <InterfaceProperty name="MyProp" attributes={[
33
+ * <Attribute name="Test" />
34
+ * <Attribute name="Test2" args={["arg1", "arg2"]} />
35
+ * ]} />
36
+ * ```
37
+ * This will produce:
38
+ * ```csharp
39
+ * [Test]
40
+ * [Test2("arg1", "arg2")]
41
+ * int MyProp { get; set; }
42
+ * ```
43
+ */
44
+ attributes?: AttributesProp;
19
45
  }
46
+ /**
47
+ * Render a C# interface property.
48
+ *
49
+ * @example `<InterfaceProperty public name="My" get set />`
50
+ *
51
+ * ```cs
52
+ * public int My { get; set; };
53
+ * ```
54
+ */
20
55
  export declare function InterfaceProperty(props: InterfacePropertyProps): Children;
21
56
  //# sourceMappingURL=property.d.ts.map
@@ -1 +1 @@
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;AAED,eAAO,MAAM,iBAAiB,8CAE5B,CAAC;AAGH,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;CAChB;AAGD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,YAuC9D"}
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;AAI5B,OAAO,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG7E,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;IAEnB;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,YAyC9D"}
@@ -4,15 +4,24 @@ import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../
4
4
  import { useCSharpNamePolicy } from "../../name-policy.js";
5
5
  import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
6
6
  import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
7
+ import { AttributeList } from "../attributes/attributes.js";
7
8
  import { DocWhen } from "../doc/comment.js";
8
9
 
9
10
  /** Method modifiers. Can only be one. */
10
11
 
11
- export const getMethodModifier = makeModifiers(["new"]);
12
+ const getModifiers = makeModifiers(["new"]);
12
13
 
13
14
  // properties for creating a method
14
15
 
15
- // a C# interface property
16
+ /**
17
+ * Render a C# interface property.
18
+ *
19
+ * @example `<InterfaceProperty public name="My" get set />`
20
+ *
21
+ * ```cs
22
+ * public int My { get; set; };
23
+ * ```
24
+ */
16
25
  export function InterfaceProperty(props) {
17
26
  const name = useCSharpNamePolicy().getName(props.name, "class-property");
18
27
  const scope = useCSharpScope();
@@ -28,7 +37,7 @@ export function InterfaceProperty(props) {
28
37
  const propertyScope = new CSharpMemberScope("property-decl", {
29
38
  owner: propertySymbol
30
39
  });
31
- const modifiers = computeModifiersPrefix([getAccessModifier(props), getMethodModifier(props)]);
40
+ const modifiers = computeModifiersPrefix([getAccessModifier(props), getModifiers(props)]);
32
41
  // note that scope wraps the method decl so that the params get the correct scope
33
42
  return _$createComponent(MemberDeclaration, {
34
43
  symbol: propertySymbol,
@@ -40,7 +49,12 @@ export function InterfaceProperty(props) {
40
49
  get doc() {
41
50
  return props.doc;
42
51
  }
43
- }), modifiers, _$memo(() => props.type), " ", name, " ", _$createComponent(Block, {
52
+ }), _$createComponent(AttributeList, {
53
+ get attributes() {
54
+ return props.attributes;
55
+ },
56
+ endline: true
57
+ }), modifiers, _$memo(() => props.type), _$memo(() => props.nullable && "?"), " ", name, " ", _$createComponent(Block, {
44
58
  newline: true,
45
59
  inline: true,
46
60
  get children() {
@@ -1,6 +1,7 @@
1
1
  import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
2
  import { describe, expect, it } from "vitest";
3
3
  import { TestNamespace } from "../../../test/utils.js";
4
+ import { Attribute } from "../attributes/attributes.js";
4
5
  import { InterfaceDeclaration } from "./declaration.js";
5
6
  import { InterfaceProperty } from "./property.js";
6
7
  const Wrapper = props => _$createComponent(TestNamespace, {
@@ -162,4 +163,27 @@ it("specify doc comment", () => {
162
163
  string Method { get; set; }
163
164
  }
164
165
  `);
166
+ });
167
+ it("specify attributes", () => {
168
+ expect(_$createComponent(Wrapper, {
169
+ get children() {
170
+ return _$createComponent(InterfaceProperty, {
171
+ name: "Test",
172
+ type: "int",
173
+ get attributes() {
174
+ return [_$createComponent(Attribute, {
175
+ name: "Test"
176
+ })];
177
+ },
178
+ get: true,
179
+ set: true
180
+ });
181
+ }
182
+ })).toRenderTo(`
183
+ public interface TestInterface
184
+ {
185
+ [Test]
186
+ int Test { get; set; }
187
+ }
188
+ `);
165
189
  });
@@ -0,0 +1,19 @@
1
+ import { Children, OutputSymbol, Refkey } from "@alloy-js/core";
2
+ export interface ParameterProps {
3
+ name: string;
4
+ type: Children;
5
+ /** If the parmaeter is optional(without default value) */
6
+ optional?: boolean;
7
+ /** Default value for the parameter */
8
+ default?: Children;
9
+ refkey?: Refkey;
10
+ symbol?: OutputSymbol;
11
+ }
12
+ /** Define a parameter to be used in class or interface method. */
13
+ export declare function Parameter(props: ParameterProps): Children;
14
+ export interface ParametersProps {
15
+ parameters: ParameterProps[] | undefined;
16
+ }
17
+ /** Render a collection of parameters */
18
+ export declare function Parameters(props: ParametersProps): Children;
19
+ //# sourceMappingURL=parameters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parameters.d.ts","sourceRoot":"","sources":["../../../../src/components/parameters/parameters.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAKR,YAAY,EAEZ,MAAM,EACP,MAAM,gBAAgB,CAAC;AAMxB,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sCAAsC;IACtC,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,YAwB9C;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;CAC1C;AAED,wCAAwC;AACxC,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,YAehD"}
@@ -0,0 +1,43 @@
1
+ import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { code, Declaration, For, Indent, refkey } 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
+ /** Define a parameter to be used in class or interface method. */
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 ?? refkey(props.name)
17
+ });
18
+ return _$createComponent(Declaration, {
19
+ symbol: memberSymbol,
20
+ get children() {
21
+ return [_$memo(() => props.type), _$memo(() => props.optional ? "?" : ""), " ", _$createComponent(Name, {}), _$memo(() => props.default ? code` = ${props.default}` : "")];
22
+ }
23
+ });
24
+ }
25
+ /** Render a collection of parameters */
26
+ export function Parameters(props) {
27
+ return _$createIntrinsic("group", {
28
+ get children() {
29
+ return ["(", _$memo(() => _$memo(() => !!props.parameters)() && _$createComponent(Indent, {
30
+ softline: true,
31
+ get children() {
32
+ return _$createComponent(For, {
33
+ get each() {
34
+ return props.parameters;
35
+ },
36
+ joiner: ", ",
37
+ children: param => _$createComponent(Parameter, param)
38
+ });
39
+ }
40
+ })), _$createIntrinsic("softline", {}), ")"];
41
+ }
42
+ });
43
+ }