@alloy-js/csharp 0.20.0-dev.2 → 0.20.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.
Files changed (251) hide show
  1. package/dist/src/components/Declaration.d.ts +2 -2
  2. package/dist/src/components/Declaration.d.ts.map +1 -1
  3. package/dist/src/components/Declaration.js +3 -13
  4. package/dist/src/components/Reference.d.ts.map +1 -1
  5. package/dist/src/components/Reference.js +5 -1
  6. package/dist/src/components/SourceFile.d.ts +8 -9
  7. package/dist/src/components/SourceFile.d.ts.map +1 -1
  8. package/dist/src/components/SourceFile.js +69 -45
  9. package/dist/src/components/UsingDirective.d.ts +5 -1
  10. package/dist/src/components/UsingDirective.d.ts.map +1 -1
  11. package/dist/src/components/UsingDirective.js +3 -1
  12. package/dist/src/components/class/declaration.d.ts +2 -2
  13. package/dist/src/components/class/declaration.d.ts.map +1 -1
  14. package/dist/src/components/class/declaration.js +19 -33
  15. package/dist/src/components/class/declaration.test.js +192 -193
  16. package/dist/src/components/constructor/constructor.d.ts.map +1 -1
  17. package/dist/src/components/constructor/constructor.js +11 -19
  18. package/dist/src/components/constructor/constructor.test.js +10 -19
  19. package/dist/src/components/{EnumDeclaration.d.ts → enum/declaration.d.ts} +6 -11
  20. package/dist/src/components/enum/declaration.d.ts.map +1 -0
  21. package/dist/src/components/enum/declaration.js +54 -0
  22. package/dist/src/components/enum/declaration.ref.test.d.ts +2 -0
  23. package/dist/src/components/enum/declaration.ref.test.d.ts.map +1 -0
  24. package/dist/src/components/enum/declaration.ref.test.js +120 -0
  25. package/dist/src/components/enum/declaration.test.d.ts +2 -0
  26. package/dist/src/components/enum/declaration.test.d.ts.map +1 -0
  27. package/dist/src/components/enum/declaration.test.js +39 -0
  28. package/dist/src/components/enum/member.d.ts +7 -0
  29. package/dist/src/components/enum/member.d.ts.map +1 -0
  30. package/dist/src/components/enum/member.js +29 -0
  31. package/dist/src/components/enum/member.test.d.ts +2 -0
  32. package/dist/src/components/enum/member.test.d.ts.map +1 -0
  33. package/dist/src/components/enum/member.test.js +28 -0
  34. package/dist/src/components/field/field.d.ts.map +1 -1
  35. package/dist/src/components/field/field.js +9 -17
  36. package/dist/src/components/field/field.test.js +7 -7
  37. package/dist/src/components/index.d.ts +5 -2
  38. package/dist/src/components/index.d.ts.map +1 -1
  39. package/dist/src/components/index.js +5 -2
  40. package/dist/src/components/interface/declaration.d.ts.map +1 -1
  41. package/dist/src/components/interface/declaration.js +19 -21
  42. package/dist/src/components/interface/declaration.test.js +26 -35
  43. package/dist/src/components/interface/method.d.ts.map +1 -1
  44. package/dist/src/components/interface/method.js +7 -18
  45. package/dist/src/components/interface/method.test.js +38 -47
  46. package/dist/src/components/interface/property.d.ts.map +1 -1
  47. package/dist/src/components/interface/property.js +21 -39
  48. package/dist/src/components/interface/property.test.js +11 -11
  49. package/dist/src/components/lexical-scope.d.ts +8 -0
  50. package/dist/src/components/lexical-scope.d.ts.map +1 -0
  51. package/dist/src/components/lexical-scope.js +24 -0
  52. package/dist/src/components/method/method.d.ts +5 -2
  53. package/dist/src/components/method/method.d.ts.map +1 -1
  54. package/dist/src/components/method/method.js +7 -16
  55. package/dist/src/components/method/method.test.js +11 -11
  56. package/dist/src/components/method-scope.d.ts +8 -0
  57. package/dist/src/components/method-scope.d.ts.map +1 -0
  58. package/dist/src/components/method-scope.js +24 -0
  59. package/dist/src/components/namespace-scopes.d.ts +13 -0
  60. package/dist/src/components/namespace-scopes.d.ts.map +1 -0
  61. package/dist/src/components/namespace-scopes.js +44 -0
  62. package/dist/src/components/namespace.d.ts +7 -0
  63. package/dist/src/components/namespace.d.ts.map +1 -0
  64. package/dist/src/components/namespace.js +46 -0
  65. package/dist/src/components/namespace.ref.test.d.ts +2 -0
  66. package/dist/src/components/namespace.ref.test.d.ts.map +1 -0
  67. package/dist/src/components/namespace.ref.test.js +181 -0
  68. package/dist/src/components/namespace.test.d.ts.map +1 -0
  69. package/dist/src/components/namespace.test.js +78 -0
  70. package/dist/src/components/parameters/parameters.d.ts +2 -2
  71. package/dist/src/components/parameters/parameters.d.ts.map +1 -1
  72. package/dist/src/components/parameters/parameters.js +12 -14
  73. package/dist/src/components/parameters/parameters.test.d.ts +2 -0
  74. package/dist/src/components/parameters/parameters.test.d.ts.map +1 -0
  75. package/dist/src/components/parameters/parameters.test.js +87 -0
  76. package/dist/src/components/property/property.d.ts.map +1 -1
  77. package/dist/src/components/property/property.js +21 -39
  78. package/dist/src/components/property/property.test.js +14 -14
  79. package/dist/src/components/record/declaration.d.ts +18 -0
  80. package/dist/src/components/record/declaration.d.ts.map +1 -1
  81. package/dist/src/components/record/declaration.js +19 -13
  82. package/dist/src/components/record/declaration.test.js +50 -3
  83. package/dist/src/components/struct/declaration.d.ts.map +1 -1
  84. package/dist/src/components/struct/declaration.js +4 -6
  85. package/dist/src/components/struct/declaration.test.js +30 -39
  86. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -1
  87. package/dist/src/components/type-parameters/type-parameter.js +7 -10
  88. package/dist/src/components/type-parameters/type-parameters.test.js +3 -3
  89. package/dist/src/components/var/declaration.d.ts.map +1 -1
  90. package/dist/src/components/var/declaration.js +6 -8
  91. package/dist/src/components/var/declaration.test.js +11 -20
  92. package/dist/src/contexts/global-namespace.d.ts +5 -0
  93. package/dist/src/contexts/global-namespace.d.ts.map +1 -0
  94. package/dist/src/contexts/global-namespace.js +24 -0
  95. package/dist/src/contexts/namespace.d.ts +8 -0
  96. package/dist/src/contexts/namespace.d.ts.map +1 -0
  97. package/dist/src/contexts/namespace.js +5 -0
  98. package/dist/src/index.d.ts +1 -0
  99. package/dist/src/index.d.ts.map +1 -1
  100. package/dist/src/index.js +1 -0
  101. package/dist/src/modifiers.d.ts +11 -0
  102. package/dist/src/modifiers.d.ts.map +1 -1
  103. package/dist/src/scopes/class.d.ts +10 -0
  104. package/dist/src/scopes/class.d.ts.map +1 -0
  105. package/dist/src/scopes/class.js +10 -0
  106. package/dist/src/scopes/contexts.d.ts +9 -0
  107. package/dist/src/scopes/contexts.d.ts.map +1 -0
  108. package/dist/src/scopes/contexts.js +33 -0
  109. package/dist/src/scopes/csharp.d.ts +8 -0
  110. package/dist/src/scopes/csharp.d.ts.map +1 -0
  111. package/dist/src/scopes/csharp.js +11 -0
  112. package/dist/src/scopes/factories.d.ts +9 -0
  113. package/dist/src/scopes/factories.d.ts.map +1 -0
  114. package/dist/src/scopes/factories.js +23 -0
  115. package/dist/src/scopes/index.d.ts +10 -0
  116. package/dist/src/scopes/index.d.ts.map +1 -0
  117. package/dist/src/scopes/index.js +9 -0
  118. package/dist/src/scopes/lexical.d.ts +7 -0
  119. package/dist/src/scopes/lexical.d.ts.map +1 -0
  120. package/dist/src/scopes/lexical.js +7 -0
  121. package/dist/src/scopes/method.d.ts +9 -0
  122. package/dist/src/scopes/method.d.ts.map +1 -0
  123. package/dist/src/scopes/method.js +13 -0
  124. package/dist/src/scopes/named-type.d.ts +22 -0
  125. package/dist/src/scopes/named-type.d.ts.map +1 -0
  126. package/dist/src/scopes/named-type.js +32 -0
  127. package/dist/src/scopes/namespace.d.ts +11 -0
  128. package/dist/src/scopes/namespace.d.ts.map +1 -0
  129. package/dist/src/scopes/namespace.js +38 -0
  130. package/dist/src/scopes/source-file.d.ts +16 -0
  131. package/dist/src/scopes/source-file.d.ts.map +1 -0
  132. package/dist/src/scopes/source-file.js +43 -0
  133. package/dist/src/symbols/csharp.d.ts +76 -0
  134. package/dist/src/symbols/csharp.d.ts.map +1 -0
  135. package/dist/src/symbols/csharp.js +222 -0
  136. package/dist/src/symbols/factories.d.ts +25 -0
  137. package/dist/src/symbols/factories.d.ts.map +1 -0
  138. package/dist/src/symbols/factories.js +86 -0
  139. package/dist/src/symbols/index.d.ts +5 -2
  140. package/dist/src/symbols/index.d.ts.map +1 -1
  141. package/dist/src/symbols/index.js +6 -3
  142. package/dist/src/symbols/method.d.ts +13 -0
  143. package/dist/src/symbols/method.d.ts.map +1 -0
  144. package/dist/src/symbols/method.js +15 -0
  145. package/dist/src/symbols/named-type.d.ts +19 -0
  146. package/dist/src/symbols/named-type.d.ts.map +1 -0
  147. package/dist/src/symbols/named-type.js +30 -0
  148. package/dist/src/symbols/namespace.d.ts +22 -0
  149. package/dist/src/symbols/namespace.d.ts.map +1 -0
  150. package/dist/src/symbols/namespace.js +44 -0
  151. package/dist/src/symbols/reference.d.ts +2 -2
  152. package/dist/src/symbols/reference.d.ts.map +1 -1
  153. package/dist/src/symbols/reference.js +36 -43
  154. package/dist/test/project-directory.test.js +12 -16
  155. package/dist/test/sourcefile.test.js +7 -19
  156. package/dist/test/using.test.js +18 -16
  157. package/dist/test/utils.js +2 -2
  158. package/dist/tsconfig.tsbuildinfo +1 -1
  159. package/package.json +8 -4
  160. package/src/components/Declaration.tsx +3 -6
  161. package/src/components/Reference.tsx +3 -1
  162. package/src/components/SourceFile.tsx +68 -55
  163. package/src/components/UsingDirective.tsx +12 -2
  164. package/src/components/class/declaration.test.tsx +138 -143
  165. package/src/components/class/declaration.tsx +20 -33
  166. package/src/components/constructor/constructor.test.tsx +10 -16
  167. package/src/components/constructor/constructor.tsx +13 -32
  168. package/src/components/enum/declaration.ref.test.tsx +93 -0
  169. package/src/components/enum/declaration.test.tsx +34 -0
  170. package/src/components/enum/declaration.tsx +65 -0
  171. package/src/components/enum/member.test.tsx +24 -0
  172. package/src/components/enum/member.tsx +36 -0
  173. package/src/components/field/field.test.tsx +7 -7
  174. package/src/components/field/field.tsx +12 -22
  175. package/src/components/index.ts +5 -2
  176. package/src/components/interface/declaration.test.tsx +26 -32
  177. package/src/components/interface/declaration.tsx +16 -18
  178. package/src/components/interface/method.test.tsx +38 -44
  179. package/src/components/interface/method.tsx +7 -20
  180. package/src/components/interface/property.test.tsx +11 -11
  181. package/src/components/interface/property.tsx +15 -34
  182. package/src/components/lexical-scope.tsx +29 -0
  183. package/src/components/method/method.test.tsx +11 -11
  184. package/src/components/method/method.tsx +12 -23
  185. package/src/components/method-scope.tsx +27 -0
  186. package/src/components/namespace-scopes.tsx +44 -0
  187. package/src/components/namespace.ref.test.tsx +139 -0
  188. package/src/components/namespace.test.tsx +52 -0
  189. package/src/components/namespace.tsx +45 -0
  190. package/src/components/parameters/parameters.test.tsx +71 -0
  191. package/src/components/parameters/parameters.tsx +9 -21
  192. package/src/components/property/property.test.tsx +14 -14
  193. package/src/components/property/property.tsx +17 -41
  194. package/src/components/record/declaration.test.tsx +47 -3
  195. package/src/components/record/declaration.tsx +34 -11
  196. package/src/components/struct/declaration.test.tsx +16 -22
  197. package/src/components/struct/declaration.tsx +4 -6
  198. package/src/components/type-parameters/type-parameter.tsx +14 -11
  199. package/src/components/type-parameters/type-parameters.test.tsx +4 -4
  200. package/src/components/var/declaration.test.tsx +8 -14
  201. package/src/components/var/declaration.tsx +12 -6
  202. package/src/contexts/global-namespace.ts +29 -0
  203. package/src/contexts/namespace.ts +13 -0
  204. package/src/index.ts +1 -0
  205. package/src/modifiers.ts +14 -0
  206. package/src/scopes/class.ts +12 -0
  207. package/src/scopes/contexts.ts +45 -0
  208. package/src/scopes/csharp.ts +18 -0
  209. package/src/scopes/factories.ts +45 -0
  210. package/src/scopes/index.ts +9 -0
  211. package/src/scopes/lexical.ts +10 -0
  212. package/src/scopes/method.ts +22 -0
  213. package/src/scopes/named-type.ts +44 -0
  214. package/src/scopes/namespace.ts +59 -0
  215. package/src/scopes/source-file.ts +67 -0
  216. package/src/symbols/csharp.ts +307 -0
  217. package/src/symbols/factories.ts +199 -0
  218. package/src/symbols/index.ts +5 -2
  219. package/src/symbols/method.ts +26 -0
  220. package/src/symbols/named-type.ts +54 -0
  221. package/src/symbols/namespace.ts +62 -0
  222. package/src/symbols/reference.ts +47 -50
  223. package/temp/api.json +6152 -2151
  224. package/test/project-directory.test.tsx +12 -16
  225. package/test/sourcefile.test.tsx +7 -21
  226. package/test/using.test.tsx +18 -16
  227. package/test/utils.tsx +1 -1
  228. package/tsdoc-metadata.json +1 -1
  229. package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
  230. package/dist/src/components/EnumDeclaration.js +0 -85
  231. package/dist/src/components/Namespace.d.ts +0 -11
  232. package/dist/src/components/Namespace.d.ts.map +0 -1
  233. package/dist/src/components/Namespace.js +0 -33
  234. package/dist/src/symbols/csharp-output-symbol.d.ts +0 -8
  235. package/dist/src/symbols/csharp-output-symbol.d.ts.map +0 -1
  236. package/dist/src/symbols/csharp-output-symbol.js +0 -19
  237. package/dist/src/symbols/scopes.d.ts +0 -14
  238. package/dist/src/symbols/scopes.d.ts.map +0 -1
  239. package/dist/src/symbols/scopes.js +0 -31
  240. package/dist/test/enum.test.d.ts +0 -2
  241. package/dist/test/enum.test.d.ts.map +0 -1
  242. package/dist/test/enum.test.js +0 -178
  243. package/dist/test/namespace.test.d.ts.map +0 -1
  244. package/dist/test/namespace.test.js +0 -81
  245. package/src/components/EnumDeclaration.tsx +0 -99
  246. package/src/components/Namespace.tsx +0 -35
  247. package/src/symbols/csharp-output-symbol.ts +0 -22
  248. package/src/symbols/scopes.ts +0 -41
  249. package/test/enum.test.tsx +0 -149
  250. package/test/namespace.test.tsx +0 -55
  251. /package/dist/{test → src/components}/namespace.test.d.ts +0 -0
@@ -1,4 +1,7 @@
1
1
  import { createComponent as _$createComponent, mergeProps as _$mergeProps, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { Constructor } from "#components/constructor/constructor.js";
3
+ import { EnumDeclaration } from "#components/enum/declaration.js";
4
+ import { EnumMember } from "#components/enum/member.js";
2
5
  import { code, createNamePolicy, List, NamePolicyContext, Output, refkey, render } from "@alloy-js/core";
3
6
  import * as coretest from "@alloy-js/core/testing";
4
7
  import { describe, expect, it } from "vitest";
@@ -7,21 +10,14 @@ import { createCSharpNamePolicy } from "../../name-policy.js";
7
10
  import { Attribute } from "../attributes/attributes.js";
8
11
  import { Field } from "../field/field.js";
9
12
  import { Method } from "../method/method.js";
10
- import { Namespace } from "../Namespace.js";
11
13
  import { Property } from "../property/property.js";
12
14
  import { SourceFile } from "../SourceFile.js";
13
- import { Constructor, EnumDeclaration, EnumMember } from "../stc/index.js";
14
15
  import { ClassDeclaration } from "./declaration.js";
15
16
  function Wrapper({
16
17
  children
17
18
  }) {
18
19
  return _$createComponent(TestNamespace, {
19
- get children() {
20
- return _$createComponent(SourceFile, {
21
- path: "Test.cs",
22
- children: children
23
- });
24
- }
20
+ children: children
25
21
  });
26
22
  }
27
23
  it("declares class with no members", () => {
@@ -76,6 +72,27 @@ describe("modifiers", () => {
76
72
  public abstract partial class TestClass;
77
73
  `);
78
74
  });
75
+ it("places visibility, attributes, and modifiers in the correct order", () => {
76
+ expect(_$createComponent(TestNamespace, {
77
+ get children() {
78
+ return _$createComponent(ClassDeclaration, {
79
+ partial: true,
80
+ "public": true,
81
+ abstract: true,
82
+ sealed: true,
83
+ name: "TestClass",
84
+ get attributes() {
85
+ return [_$createComponent(Attribute, {
86
+ name: "Test"
87
+ })];
88
+ }
89
+ });
90
+ }
91
+ })).toRenderTo(`
92
+ [Test]
93
+ public abstract sealed partial class TestClass;
94
+ `);
95
+ });
79
96
  });
80
97
  describe("base", () => {
81
98
  it("define base class", () => {
@@ -117,63 +134,65 @@ describe("base", () => {
117
134
  });
118
135
  });
119
136
  it("declares class with some members", () => {
120
- const res = toSourceText(_$createComponent(ClassDeclaration, {
121
- "public": true,
122
- name: "TestClass",
137
+ const tree = _$createComponent(TestNamespace, {
123
138
  get children() {
124
- return _$createComponent(List, {
139
+ return _$createComponent(ClassDeclaration, {
140
+ "public": true,
141
+ name: "TestClass",
125
142
  get children() {
126
- return [_$createComponent(Field, {
127
- "public": true,
128
- name: "MemberOne",
129
- type: "string"
130
- }), _$createComponent(Field, {
131
- "public": true,
132
- name: "MemberTwo",
133
- type: "int"
134
- })];
143
+ return _$createComponent(List, {
144
+ get children() {
145
+ return [_$createComponent(Field, {
146
+ "public": true,
147
+ name: "MemberOne",
148
+ type: "string"
149
+ }), _$createComponent(Field, {
150
+ "public": true,
151
+ name: "MemberTwo",
152
+ type: "int"
153
+ })];
154
+ }
155
+ });
135
156
  }
136
157
  });
137
158
  }
138
- }));
139
- expect(res).toBe(coretest.d`
140
- namespace TestCode
159
+ });
160
+ expect(tree).toRenderTo(coretest.d`
161
+ public class TestClass
141
162
  {
142
- public class TestClass
143
- {
144
- public string MemberOne;
145
- public int MemberTwo;
146
- }
163
+ public string MemberOne;
164
+ public int MemberTwo;
147
165
  }
148
166
  `);
149
167
  });
150
168
  it("declares class with some methods", () => {
151
- const res = toSourceText(_$createComponent(ClassDeclaration, {
152
- "public": true,
153
- name: "TestClass",
169
+ const tree = _$createComponent(TestNamespace, {
154
170
  get children() {
155
- return _$createComponent(List, {
171
+ return _$createComponent(ClassDeclaration, {
172
+ "public": true,
173
+ name: "TestClass",
156
174
  get children() {
157
- return [_$createComponent(Method, {
158
- "public": true,
159
- name: "MethodOne"
160
- }), _$createComponent(Method, {
161
- "private": true,
162
- virtual: true,
163
- name: "MethodTwo"
164
- })];
175
+ return _$createComponent(List, {
176
+ get children() {
177
+ return [_$createComponent(Method, {
178
+ "public": true,
179
+ name: "MethodOne"
180
+ }), _$createComponent(Method, {
181
+ "private": true,
182
+ virtual: true,
183
+ name: "MethodTwo"
184
+ })];
185
+ }
186
+ });
165
187
  }
166
188
  });
167
189
  }
168
- }));
169
- expect(res).toBe(coretest.d`
170
- namespace TestCode
190
+ });
191
+ expect(tree).toRenderTo(coretest.d`
192
+ public class TestClass
171
193
  {
172
- public class TestClass
173
- {
174
- public void MethodOne() {}
175
- private virtual void MethodTwo() {}
176
- }
194
+ public void MethodOne() {}
195
+ private virtual void MethodTwo() {}
177
196
  }
178
197
  `);
179
198
  });
@@ -193,79 +212,71 @@ it("uses refkeys for members, params, and return type", () => {
193
212
  return createCSharpNamePolicy();
194
213
  },
195
214
  get children() {
196
- return _$createComponent(Namespace, {
197
- name: "TestCode",
215
+ return _$createComponent(SourceFile, {
216
+ path: "Test.cs",
198
217
  get children() {
199
- return _$createComponent(SourceFile, {
200
- path: "Test.cs",
218
+ return [_$createComponent(EnumDeclaration, {
219
+ "public": true,
220
+ name: "TestEnum",
221
+ refkey: enumTypeRefkey,
201
222
  get children() {
202
- return [_$createComponent(EnumDeclaration, {
203
- "public": true,
204
- name: "TestEnum",
205
- refkey: enumTypeRefkey,
223
+ return _$createComponent(List, {
224
+ comma: true,
225
+ hardline: true,
206
226
  get children() {
207
- return _$createComponent(List, {
208
- comma: true,
209
- hardline: true,
210
- get children() {
211
- return [_$createComponent(EnumMember, {
212
- name: "One"
213
- }), _$createComponent(EnumMember, {
214
- name: "Two"
215
- })];
216
- }
217
- });
227
+ return [_$createComponent(EnumMember, {
228
+ name: "One"
229
+ }), _$createComponent(EnumMember, {
230
+ name: "Two"
231
+ })];
218
232
  }
219
- }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
220
- "public": true,
221
- name: "TestInput",
222
- refkey: inputTypeRefkey
223
- }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
224
- "public": true,
225
- name: "TestResult",
226
- refkey: testResultTypeRefkey
227
- }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
233
+ });
234
+ }
235
+ }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
236
+ "public": true,
237
+ name: "TestInput",
238
+ refkey: inputTypeRefkey
239
+ }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
240
+ "public": true,
241
+ name: "TestResult",
242
+ refkey: testResultTypeRefkey
243
+ }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
244
+ "public": true,
245
+ name: "TestClass",
246
+ get children() {
247
+ return [_$createComponent(Field, {
248
+ "private": true,
249
+ name: "MemberOne",
250
+ type: enumTypeRefkey
251
+ }), _$createIntrinsic("hbr", {}), _$createComponent(Method, {
228
252
  "public": true,
229
- name: "TestClass",
253
+ name: "MethodOne",
254
+ parameters: params,
255
+ returns: testResultTypeRefkey,
230
256
  get children() {
231
- return [_$createComponent(Field, {
232
- "private": true,
233
- name: "MemberOne",
234
- type: enumTypeRefkey
235
- }), _$createIntrinsic("hbr", {}), _$createComponent(Method, {
236
- "public": true,
237
- name: "MethodOne",
238
- parameters: params,
239
- returns: testResultTypeRefkey,
240
- get children() {
241
- return ["return new ", testResultTypeRefkey, "();"];
242
- }
243
- })];
257
+ return ["return new ", testResultTypeRefkey, "();"];
244
258
  }
245
259
  })];
246
260
  }
247
- });
261
+ })];
248
262
  }
249
263
  });
250
264
  }
251
265
  }));
252
266
  expect(findFile(res, "Test.cs").contents).toBe(coretest.d`
253
- namespace TestCode
267
+ public enum TestEnum
254
268
  {
255
- public enum TestEnum
256
- {
257
- One,
258
- Two
259
- }
260
- public class TestInput;
261
- public class TestResult;
262
- public class TestClass
269
+ One,
270
+ Two
271
+ }
272
+ public class TestInput;
273
+ public class TestResult;
274
+ public class TestClass
275
+ {
276
+ private TestEnum _memberOne;
277
+ public TestResult MethodOne(int intParam, TestInput bodyParam)
263
278
  {
264
- private TestEnum _memberOne;
265
- public TestResult MethodOne(int intParam, TestInput bodyParam)
266
- {
267
- return new TestResult();
268
- }
279
+ return new TestResult();
269
280
  }
270
281
  }
271
282
  `);
@@ -281,46 +292,38 @@ describe("with type parameters", () => {
281
292
  }];
282
293
  expect(_$createComponent(TestNamespace, {
283
294
  get children() {
284
- return _$createComponent(SourceFile, {
285
- path: "Test.cs",
295
+ return _$createComponent(ClassDeclaration, {
296
+ "public": true,
297
+ name: "TestClass",
298
+ typeParameters: typeParameters,
286
299
  get children() {
287
- return _$createComponent(ClassDeclaration, {
288
- "public": true,
289
- name: "TestClass",
290
- typeParameters: typeParameters,
300
+ return _$createComponent(List, {
291
301
  get children() {
292
- return _$createComponent(List, {
293
- get children() {
294
- return [_$createComponent(Property, {
295
- name: "PropA",
296
- get type() {
297
- return typeParameters[0].refkey;
298
- },
299
- get: true,
300
- set: true
301
- }), _$createComponent(Property, {
302
- name: "PropB",
303
- get type() {
304
- return typeParameters[1].refkey;
305
- },
306
- get: true,
307
- set: true
308
- })];
309
- }
310
- });
302
+ return [_$createComponent(Property, {
303
+ name: "PropA",
304
+ get type() {
305
+ return typeParameters[0].refkey;
306
+ },
307
+ get: true,
308
+ set: true
309
+ }), _$createComponent(Property, {
310
+ name: "PropB",
311
+ get type() {
312
+ return typeParameters[1].refkey;
313
+ },
314
+ get: true,
315
+ set: true
316
+ })];
311
317
  }
312
318
  });
313
319
  }
314
320
  });
315
321
  }
316
322
  })).toRenderTo(`
317
- namespace TestCode
323
+ public class TestClass<T, U>
318
324
  {
319
- public class TestClass<T, U>
320
- {
321
- T PropA { get; set; }
322
- U PropB { get; set; }
323
- }
325
+ T PropA { get; set; }
326
+ U PropB { get; set; }
324
327
  }
325
328
  `);
326
329
  });
@@ -343,10 +346,10 @@ describe("with type parameters", () => {
343
346
  }
344
347
  })).toRenderTo(`
345
348
  public class TestClass<T, U>
346
- where T : IFoo
347
- where U : IBar
349
+ where T : IFoo
350
+ where U : IBar
348
351
  {
349
- // Body
352
+ // Body
350
353
  }
351
354
  `);
352
355
  });
@@ -363,26 +366,27 @@ it("declares class with invalid members", () => {
363
366
  })];
364
367
  }
365
368
  });
366
- expect(() => toSourceText(decl)).toThrow("can't define an enum member outside of an enum-decl scope");
369
+ expect(() => toSourceText(decl)).toThrow("EnumMember must be used within an EnumDeclaration.");
367
370
  });
368
371
  describe("constructor", () => {
369
372
  it("declares with constructor", () => {
370
- const res = toSourceText(_$createComponent(ClassDeclaration, {
371
- "public": true,
372
- name: "TestClass",
373
+ const tree = _$createComponent(TestNamespace, {
373
374
  get children() {
374
- return _$createComponent(Constructor, {
375
- "public": true
375
+ return _$createComponent(ClassDeclaration, {
376
+ "public": true,
377
+ name: "TestClass",
378
+ get children() {
379
+ return _$createComponent(Constructor, {
380
+ "public": true
381
+ });
382
+ }
376
383
  });
377
384
  }
378
- }));
379
- expect(res).toBe(coretest.d`
380
- namespace TestCode
385
+ });
386
+ expect(tree).toRenderTo(coretest.d`
387
+ public class TestClass
381
388
  {
382
- public class TestClass
383
- {
384
- public TestClass() {}
385
- }
389
+ public TestClass() {}
386
390
  }
387
391
  `);
388
392
  });
@@ -400,44 +404,45 @@ describe("constructor", () => {
400
404
  type: "int",
401
405
  refkey: paramSizeRefkey
402
406
  }];
403
- const res = toSourceText(_$createComponent(ClassDeclaration, {
404
- "public": true,
405
- name: "TestClass",
407
+ const tree = _$createComponent(TestNamespace, {
406
408
  get children() {
407
- return [_$createComponent(Field, {
408
- "private": true,
409
- name: "name",
410
- type: "string",
411
- refkey: thisNameRefkey
412
- }), _$createIntrinsic("hbr", {}), _$createComponent(Field, {
413
- "private": true,
414
- name: "size",
415
- type: "int",
416
- refkey: thisSizeRefkey
417
- }), _$createIntrinsic("hbr", {}), _$createComponent(Constructor, {
409
+ return _$createComponent(ClassDeclaration, {
418
410
  "public": true,
419
- parameters: ctorParams,
411
+ name: "TestClass",
420
412
  get children() {
421
- return [thisNameRefkey, " = ", paramNameRefkey, ";", _$createIntrinsic("hbr", {}), thisSizeRefkey, " = ", paramSizeRefkey, ";"];
413
+ return [_$createComponent(Field, {
414
+ "private": true,
415
+ name: "name",
416
+ type: "string",
417
+ refkey: thisNameRefkey
418
+ }), _$createIntrinsic("hbr", {}), _$createComponent(Field, {
419
+ "private": true,
420
+ name: "size",
421
+ type: "int",
422
+ refkey: thisSizeRefkey
423
+ }), _$createIntrinsic("hbr", {}), _$createComponent(Constructor, {
424
+ "public": true,
425
+ parameters: ctorParams,
426
+ get children() {
427
+ return [thisNameRefkey, " = ", paramNameRefkey, ";", _$createIntrinsic("hbr", {}), thisSizeRefkey, " = ", paramSizeRefkey, ";"];
428
+ }
429
+ })];
422
430
  }
423
- })];
431
+ });
424
432
  }
425
- }));
433
+ });
426
434
 
427
435
  // TODO: assignments to members should have this. prefix
428
436
  // e.g. this.name = name;
429
- expect(res).toBe(coretest.d`
430
- namespace TestCode
437
+ expect(tree).toRenderTo(coretest.d`
438
+ public class TestClass
431
439
  {
432
- public class TestClass
440
+ private string _name;
441
+ private int _size;
442
+ public TestClass(string name, int size)
433
443
  {
434
- private string _name;
435
- private int _size;
436
- public TestClass(string name, int size)
437
- {
438
- _name = name;
439
- _size = size;
440
- }
444
+ _name = name;
445
+ _size = size;
441
446
  }
442
447
  }
443
448
  `);
@@ -471,12 +476,9 @@ describe("constructor", () => {
471
476
  });
472
477
  }
473
478
  })).toRenderTo(`
474
- namespace TestCode
479
+ public class TestClass(string name, int size)
475
480
  {
476
- public class TestClass(string name, int size)
477
- {
478
- string PrettyName { get; } = $"{name} {size}";
479
- }
481
+ string PrettyName { get; } = $"{name} {size}";
480
482
  }
481
483
  `);
482
484
  });
@@ -507,12 +509,9 @@ describe("constructor", () => {
507
509
  });
508
510
  }
509
511
  })).toRenderTo(`
510
- namespace TestCode
512
+ public class TestClass(string name)
511
513
  {
512
- public class TestClass(string name)
513
- {
514
- string name_2;
515
- }
514
+ string name_2;
516
515
  }
517
516
  `);
518
517
  });
@@ -550,8 +549,8 @@ it("supports class member doc comments", () => {
550
549
  /// This is a test
551
550
  class Test
552
551
  {
553
- /// This is a member
554
- public int Member;
552
+ /// This is a member
553
+ public int Member;
555
554
  }
556
555
  `);
557
556
  });
@@ -1 +1 @@
1
- {"version":3,"file":"constructor.d.ts","sourceRoot":"","sources":["../../../../src/components/constructor/constructor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EAGP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EACL,eAAe,EAGhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,cAAc,EAAc,MAAM,8BAA8B,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,6BAA6B;IAC7B,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAE9B,aAAa;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,uBAAuB;IACvB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YAiClD"}
1
+ {"version":3,"file":"constructor.d.ts","sourceRoot":"","sources":["../../../../src/components/constructor/constructor.tsx"],"names":[],"mappings":"AACA,OAAO,EAAwC,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EACL,eAAe,EAGhB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,cAAc,EAAc,MAAM,8BAA8B,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,6BAA6B;IAC7B,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAE9B,aAAa;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,uBAAuB;IACvB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YAqBlD"}
@@ -1,9 +1,9 @@
1
1
  import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { Block, Declaration, Name, refkey, Scope } from "@alloy-js/core";
2
+ import { MethodScope } from "#components/method-scope.js";
3
+ import { Block, MemberDeclaration, MemberName } from "@alloy-js/core";
3
4
  import { computeModifiersPrefix, getAccessModifier } from "../../modifiers.js";
4
- import { useCSharpNamePolicy } from "../../name-policy.js";
5
- import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
6
- import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
5
+ import { useNamedTypeScope } from "../../scopes/contexts.js";
6
+ import { MethodSymbol } from "../../symbols/method.js";
7
7
  import { Parameters } from "../parameters/parameters.js";
8
8
 
9
9
  /**
@@ -11,26 +11,18 @@ import { Parameters } from "../parameters/parameters.js";
11
11
  */
12
12
 
13
13
  export function Constructor(props) {
14
- const scope = useCSharpScope();
15
- if (scope.kind !== "member" || scope.name !== "class-decl" && scope.name !== "struct-decl") {
16
- throw new Error("can't define a class method outside of a class or struct scope");
17
- }
18
- const name = useCSharpNamePolicy().getName(scope.owner.name, "class-method");
19
- const ctorSymbol = new CSharpOutputSymbol(name, {
20
- scope,
21
- refkeys: props.refkey ?? refkey(name)
22
- });
23
- const ctorDeclScope = new CSharpMemberScope("constructor-decl", {
24
- owner: ctorSymbol
14
+ const scope = useNamedTypeScope();
15
+ const name = scope.ownerSymbol.name;
16
+ const ctorSymbol = new MethodSymbol(name, scope.members, "constructor", {
17
+ refkeys: props.refkey
25
18
  });
26
19
  const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
27
- return _$createComponent(Declaration, {
20
+ return _$createComponent(MemberDeclaration, {
28
21
  symbol: ctorSymbol,
29
22
  get children() {
30
- return _$createComponent(Scope, {
31
- value: ctorDeclScope,
23
+ return _$createComponent(MethodScope, {
32
24
  get children() {
33
- return [modifiers, _$createComponent(Name, {}), _$createComponent(Parameters, {
25
+ return [modifiers, _$createComponent(MemberName, {}), _$createComponent(Parameters, {
34
26
  get parameters() {
35
27
  return props.parameters;
36
28
  }
@@ -3,7 +3,6 @@ import { refkey } from "@alloy-js/core";
3
3
  import { expect, it } from "vitest";
4
4
  import { TestNamespace } from "../../../test/utils.js";
5
5
  import { ClassDeclaration } from "../class/declaration.js";
6
- import { SourceFile } from "../SourceFile.js";
7
6
  import { Constructor } from "./constructor.js";
8
7
  it("reference constructor parameters in body", () => {
9
8
  const paramNameRefkey = refkey();
@@ -19,35 +18,27 @@ it("reference constructor parameters in body", () => {
19
18
  }];
20
19
  expect(_$createComponent(TestNamespace, {
21
20
  get children() {
22
- return _$createComponent(SourceFile, {
23
- path: "Test.cs",
21
+ return _$createComponent(ClassDeclaration, {
22
+ "public": true,
23
+ name: "TestClass",
24
24
  get children() {
25
- return _$createComponent(ClassDeclaration, {
25
+ return _$createComponent(Constructor, {
26
26
  "public": true,
27
- name: "TestClass",
27
+ parameters: ctorParams,
28
28
  get children() {
29
- return _$createComponent(Constructor, {
30
- "public": true,
31
- parameters: ctorParams,
32
- get children() {
33
- return [paramNameRefkey, ";", _$createIntrinsic("hbr", {}), paramSizeRefkey, ";"];
34
- }
35
- });
29
+ return [paramNameRefkey, ";", _$createIntrinsic("hbr", {}), paramSizeRefkey, ";"];
36
30
  }
37
31
  });
38
32
  }
39
33
  });
40
34
  }
41
35
  })).toRenderTo(`
42
- namespace TestCode
36
+ public class TestClass
43
37
  {
44
- public class TestClass
38
+ public TestClass(string name, int size)
45
39
  {
46
- public TestClass(string name, int size)
47
- {
48
- name;
49
- size;
50
- }
40
+ name;
41
+ size;
51
42
  }
52
43
  }
53
44
  `);
@@ -1,9 +1,9 @@
1
- import * as core from "@alloy-js/core";
2
- import { AccessModifiers } from "../modifiers.js";
1
+ import { Children, Refkey } from "@alloy-js/core";
2
+ import { AccessModifiers } from "../../modifiers.js";
3
3
  export interface EnumDeclarationProps extends AccessModifiers {
4
4
  name: string;
5
- refkey?: core.Refkey;
6
- children?: core.Children;
5
+ refkey?: Refkey | Refkey[];
6
+ children?: Children;
7
7
  }
8
8
  /**
9
9
  * A C# enum declaration
@@ -25,10 +25,5 @@ export interface EnumDeclarationProps extends AccessModifiers {
25
25
  * }
26
26
  * ```
27
27
  */
28
- export declare function EnumDeclaration(props: EnumDeclarationProps): core.Children;
29
- export interface EnumMemberProps {
30
- name: string;
31
- refkey?: core.Refkey;
32
- }
33
- export declare function EnumMember(props: EnumMemberProps): core.Children;
34
- //# sourceMappingURL=EnumDeclaration.d.ts.map
28
+ export declare function EnumDeclaration(props: EnumDeclarationProps): Children;
29
+ //# sourceMappingURL=declaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/enum/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,MAAM,EACP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAGhB,MAAM,oBAAoB,CAAC;AAO5B,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YAoB1D"}