@alloy-js/csharp 0.20.0-dev.3 → 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 (249) 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 +18 -32
  15. package/dist/src/components/class/declaration.test.js +171 -193
  16. package/dist/src/components/constructor/constructor.d.ts.map +1 -1
  17. package/dist/src/components/constructor/constructor.js +11 -16
  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 -14
  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 -15
  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 -36
  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 -13
  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 -11
  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 -36
  78. package/dist/src/components/property/property.test.js +14 -14
  79. package/dist/src/components/record/declaration.d.ts.map +1 -1
  80. package/dist/src/components/record/declaration.js +8 -12
  81. package/dist/src/components/record/declaration.test.js +6 -13
  82. package/dist/src/components/struct/declaration.d.ts.map +1 -1
  83. package/dist/src/components/struct/declaration.js +4 -6
  84. package/dist/src/components/struct/declaration.test.js +30 -39
  85. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -1
  86. package/dist/src/components/type-parameters/type-parameter.js +7 -10
  87. package/dist/src/components/type-parameters/type-parameters.test.js +3 -3
  88. package/dist/src/components/var/declaration.d.ts.map +1 -1
  89. package/dist/src/components/var/declaration.js +6 -8
  90. package/dist/src/components/var/declaration.test.js +11 -20
  91. package/dist/src/contexts/global-namespace.d.ts +5 -0
  92. package/dist/src/contexts/global-namespace.d.ts.map +1 -0
  93. package/dist/src/contexts/global-namespace.js +24 -0
  94. package/dist/src/contexts/namespace.d.ts +8 -0
  95. package/dist/src/contexts/namespace.d.ts.map +1 -0
  96. package/dist/src/contexts/namespace.js +5 -0
  97. package/dist/src/index.d.ts +1 -0
  98. package/dist/src/index.d.ts.map +1 -1
  99. package/dist/src/index.js +1 -0
  100. package/dist/src/modifiers.d.ts +11 -0
  101. package/dist/src/modifiers.d.ts.map +1 -1
  102. package/dist/src/scopes/class.d.ts +10 -0
  103. package/dist/src/scopes/class.d.ts.map +1 -0
  104. package/dist/src/scopes/class.js +10 -0
  105. package/dist/src/scopes/contexts.d.ts +9 -0
  106. package/dist/src/scopes/contexts.d.ts.map +1 -0
  107. package/dist/src/scopes/contexts.js +33 -0
  108. package/dist/src/scopes/csharp.d.ts +8 -0
  109. package/dist/src/scopes/csharp.d.ts.map +1 -0
  110. package/dist/src/scopes/csharp.js +11 -0
  111. package/dist/src/scopes/factories.d.ts +9 -0
  112. package/dist/src/scopes/factories.d.ts.map +1 -0
  113. package/dist/src/scopes/factories.js +23 -0
  114. package/dist/src/scopes/index.d.ts +10 -0
  115. package/dist/src/scopes/index.d.ts.map +1 -0
  116. package/dist/src/scopes/index.js +9 -0
  117. package/dist/src/scopes/lexical.d.ts +7 -0
  118. package/dist/src/scopes/lexical.d.ts.map +1 -0
  119. package/dist/src/scopes/lexical.js +7 -0
  120. package/dist/src/scopes/method.d.ts +9 -0
  121. package/dist/src/scopes/method.d.ts.map +1 -0
  122. package/dist/src/scopes/method.js +13 -0
  123. package/dist/src/scopes/named-type.d.ts +22 -0
  124. package/dist/src/scopes/named-type.d.ts.map +1 -0
  125. package/dist/src/scopes/named-type.js +32 -0
  126. package/dist/src/scopes/namespace.d.ts +11 -0
  127. package/dist/src/scopes/namespace.d.ts.map +1 -0
  128. package/dist/src/scopes/namespace.js +38 -0
  129. package/dist/src/scopes/source-file.d.ts +16 -0
  130. package/dist/src/scopes/source-file.d.ts.map +1 -0
  131. package/dist/src/scopes/source-file.js +43 -0
  132. package/dist/src/symbols/csharp.d.ts +76 -0
  133. package/dist/src/symbols/csharp.d.ts.map +1 -0
  134. package/dist/src/symbols/csharp.js +222 -0
  135. package/dist/src/symbols/factories.d.ts +25 -0
  136. package/dist/src/symbols/factories.d.ts.map +1 -0
  137. package/dist/src/symbols/factories.js +86 -0
  138. package/dist/src/symbols/index.d.ts +5 -2
  139. package/dist/src/symbols/index.d.ts.map +1 -1
  140. package/dist/src/symbols/index.js +6 -3
  141. package/dist/src/symbols/method.d.ts +13 -0
  142. package/dist/src/symbols/method.d.ts.map +1 -0
  143. package/dist/src/symbols/method.js +15 -0
  144. package/dist/src/symbols/named-type.d.ts +19 -0
  145. package/dist/src/symbols/named-type.d.ts.map +1 -0
  146. package/dist/src/symbols/named-type.js +30 -0
  147. package/dist/src/symbols/namespace.d.ts +22 -0
  148. package/dist/src/symbols/namespace.d.ts.map +1 -0
  149. package/dist/src/symbols/namespace.js +44 -0
  150. package/dist/src/symbols/reference.d.ts +2 -2
  151. package/dist/src/symbols/reference.d.ts.map +1 -1
  152. package/dist/src/symbols/reference.js +36 -43
  153. package/dist/test/project-directory.test.js +12 -16
  154. package/dist/test/sourcefile.test.js +7 -19
  155. package/dist/test/using.test.js +18 -16
  156. package/dist/test/utils.js +2 -2
  157. package/dist/tsconfig.tsbuildinfo +1 -1
  158. package/package.json +6 -2
  159. package/src/components/Declaration.tsx +3 -6
  160. package/src/components/Reference.tsx +3 -1
  161. package/src/components/SourceFile.tsx +68 -55
  162. package/src/components/UsingDirective.tsx +12 -2
  163. package/src/components/class/declaration.test.tsx +120 -143
  164. package/src/components/class/declaration.tsx +19 -32
  165. package/src/components/constructor/constructor.test.tsx +10 -16
  166. package/src/components/constructor/constructor.tsx +13 -27
  167. package/src/components/enum/declaration.ref.test.tsx +93 -0
  168. package/src/components/enum/declaration.test.tsx +34 -0
  169. package/src/components/enum/declaration.tsx +65 -0
  170. package/src/components/enum/member.test.tsx +24 -0
  171. package/src/components/enum/member.tsx +36 -0
  172. package/src/components/field/field.test.tsx +7 -7
  173. package/src/components/field/field.tsx +12 -14
  174. package/src/components/index.ts +5 -2
  175. package/src/components/interface/declaration.test.tsx +26 -32
  176. package/src/components/interface/declaration.tsx +16 -18
  177. package/src/components/interface/method.test.tsx +38 -44
  178. package/src/components/interface/method.tsx +7 -19
  179. package/src/components/interface/property.test.tsx +11 -11
  180. package/src/components/interface/property.tsx +15 -33
  181. package/src/components/lexical-scope.tsx +29 -0
  182. package/src/components/method/method.test.tsx +11 -11
  183. package/src/components/method/method.tsx +12 -18
  184. package/src/components/method-scope.tsx +27 -0
  185. package/src/components/namespace-scopes.tsx +44 -0
  186. package/src/components/namespace.ref.test.tsx +139 -0
  187. package/src/components/namespace.test.tsx +52 -0
  188. package/src/components/namespace.tsx +45 -0
  189. package/src/components/parameters/parameters.test.tsx +71 -0
  190. package/src/components/parameters/parameters.tsx +9 -16
  191. package/src/components/property/property.test.tsx +14 -14
  192. package/src/components/property/property.tsx +17 -38
  193. package/src/components/record/declaration.test.tsx +5 -12
  194. package/src/components/record/declaration.tsx +10 -11
  195. package/src/components/struct/declaration.test.tsx +16 -22
  196. package/src/components/struct/declaration.tsx +4 -6
  197. package/src/components/type-parameters/type-parameter.tsx +14 -11
  198. package/src/components/type-parameters/type-parameters.test.tsx +4 -4
  199. package/src/components/var/declaration.test.tsx +8 -14
  200. package/src/components/var/declaration.tsx +12 -6
  201. package/src/contexts/global-namespace.ts +29 -0
  202. package/src/contexts/namespace.ts +13 -0
  203. package/src/index.ts +1 -0
  204. package/src/modifiers.ts +14 -0
  205. package/src/scopes/class.ts +12 -0
  206. package/src/scopes/contexts.ts +45 -0
  207. package/src/scopes/csharp.ts +18 -0
  208. package/src/scopes/factories.ts +45 -0
  209. package/src/scopes/index.ts +9 -0
  210. package/src/scopes/lexical.ts +10 -0
  211. package/src/scopes/method.ts +22 -0
  212. package/src/scopes/named-type.ts +44 -0
  213. package/src/scopes/namespace.ts +59 -0
  214. package/src/scopes/source-file.ts +67 -0
  215. package/src/symbols/csharp.ts +307 -0
  216. package/src/symbols/factories.ts +199 -0
  217. package/src/symbols/index.ts +5 -2
  218. package/src/symbols/method.ts +26 -0
  219. package/src/symbols/named-type.ts +54 -0
  220. package/src/symbols/namespace.ts +62 -0
  221. package/src/symbols/reference.ts +47 -50
  222. package/temp/api.json +6251 -2454
  223. package/test/project-directory.test.tsx +12 -16
  224. package/test/sourcefile.test.tsx +7 -21
  225. package/test/using.test.tsx +18 -16
  226. package/test/utils.tsx +1 -1
  227. package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
  228. package/dist/src/components/EnumDeclaration.js +0 -82
  229. package/dist/src/components/Namespace.d.ts +0 -11
  230. package/dist/src/components/Namespace.d.ts.map +0 -1
  231. package/dist/src/components/Namespace.js +0 -33
  232. package/dist/src/symbols/csharp-output-symbol.d.ts +0 -8
  233. package/dist/src/symbols/csharp-output-symbol.d.ts.map +0 -1
  234. package/dist/src/symbols/csharp-output-symbol.js +0 -19
  235. package/dist/src/symbols/scopes.d.ts +0 -20
  236. package/dist/src/symbols/scopes.d.ts.map +0 -1
  237. package/dist/src/symbols/scopes.js +0 -42
  238. package/dist/test/enum.test.d.ts +0 -2
  239. package/dist/test/enum.test.d.ts.map +0 -1
  240. package/dist/test/enum.test.js +0 -178
  241. package/dist/test/namespace.test.d.ts.map +0 -1
  242. package/dist/test/namespace.test.js +0 -81
  243. package/src/components/EnumDeclaration.tsx +0 -98
  244. package/src/components/Namespace.tsx +0 -35
  245. package/src/symbols/csharp-output-symbol.ts +0 -22
  246. package/src/symbols/scopes.ts +0 -61
  247. package/test/enum.test.tsx +0 -149
  248. package/test/namespace.test.tsx +0 -55
  249. /package/dist/{test → src/components}/namespace.test.d.ts +0 -0
@@ -46,19 +46,17 @@ it("defines a project directory file with multiple source files", () => {
46
46
  expect(srcDir.contents[0].path).equals("~/projects/TestProject/src/Test1.cs");
47
47
  expect((srcDir.contents[0] as core.ContentOutputFile).contents)
48
48
  .toBe(coretest.d`
49
- namespace TestCode
50
- {
51
- public class TestClass1;
52
- }
49
+ namespace TestCode;
50
+
51
+ public class TestClass1;
53
52
  `);
54
53
 
55
54
  expect(srcDir.contents[1].path).equals("~/projects/TestProject/src/Test2.cs");
56
55
  expect((srcDir.contents[1] as core.ContentOutputFile).contents)
57
56
  .toBe(coretest.d`
58
- namespace TestCode
59
- {
60
- public class TestClass2;
61
- }
57
+ namespace TestCode;
58
+
59
+ public class TestClass2;
62
60
  `);
63
61
  });
64
62
 
@@ -106,18 +104,16 @@ it("defines a project directory file with multiple source files and a custom TFM
106
104
  expect(srcDir.contents[0].path).equals("~/projects/TestProject/src/Test1.cs");
107
105
  expect((srcDir.contents[0] as core.ContentOutputFile).contents)
108
106
  .toBe(coretest.d`
109
- namespace TestCode
110
- {
111
- public class TestClass1;
112
- }
107
+ namespace TestCode;
108
+
109
+ public class TestClass1;
113
110
  `);
114
111
 
115
112
  expect(srcDir.contents[1].path).equals("~/projects/TestProject/src/Test2.cs");
116
113
  expect((srcDir.contents[1] as core.ContentOutputFile).contents)
117
114
  .toBe(coretest.d`
118
- namespace TestCode
119
- {
120
- public class TestClass2;
121
- }
115
+ namespace TestCode;
116
+
117
+ public class TestClass2;
122
118
  `);
123
119
  });
@@ -1,6 +1,6 @@
1
1
  import * as core from "@alloy-js/core";
2
2
  import * as coretest from "@alloy-js/core/testing";
3
- import { expect, it } from "vitest";
3
+ import { it } from "vitest";
4
4
  import * as csharp from "../src/index.js";
5
5
  import { assertFileContents } from "./utils.jsx";
6
6
 
@@ -20,28 +20,14 @@ it("defines multiple source files with unique content", () => {
20
20
 
21
21
  assertFileContents(res, {
22
22
  "Test1.cs": coretest.d`
23
- namespace TestCode
24
- {
25
- public class TestClass1;
26
- }
23
+ namespace TestCode;
24
+
25
+ public class TestClass1;
27
26
  `,
28
27
  "Test2.cs": coretest.d`
29
- namespace TestCode
30
- {
31
- public class TestClass2;
32
- }
28
+ namespace TestCode;
29
+
30
+ public class TestClass2;
33
31
  `,
34
32
  });
35
33
  });
36
-
37
- it("throws when declaring a source file outside a namespace", () => {
38
- const decl = (
39
- <core.Output>
40
- <csharp.SourceFile path="Test.cs" />
41
- </core.Output>
42
- );
43
-
44
- expect(() => core.render(decl)).toThrow(
45
- "SourceFile must be declared inside a namespace",
46
- );
47
- });
@@ -16,7 +16,9 @@ it("uses a single namespace", () => {
16
16
  expect(findFile(res, "Test1.cs").contents).toBe(coretest.d`
17
17
  using Foo;
18
18
 
19
- namespace TestCode {}
19
+ namespace TestCode;
20
+
21
+
20
22
  `);
21
23
  });
22
24
 
@@ -33,7 +35,9 @@ it("uses multiple namespaces", () => {
33
35
  using Bar.Baz;
34
36
  using Foo;
35
37
 
36
- namespace TestCode {}
38
+ namespace TestCode;
39
+
40
+
37
41
  `);
38
42
  });
39
43
 
@@ -90,29 +94,27 @@ it("adds using statement across namespaces", () => {
90
94
 
91
95
  assertFileContents(res, {
92
96
  "Models.cs": coretest.d`
93
- namespace Models
97
+ namespace Models;
98
+
99
+ public class Input;
100
+ public class Output;
101
+ public enum TestEnum
94
102
  {
95
- public class Input;
96
- public class Output;
97
- public enum TestEnum
98
- {
99
- One,
100
- Two
101
- }
103
+ One,
104
+ Two
102
105
  }
103
106
  `,
104
107
  "Client.cs": coretest.d`
105
108
  using Models;
106
109
  using System;
107
110
 
108
- namespace Client
111
+ namespace Client;
112
+
113
+ public class Client
109
114
  {
110
- public class Client
111
- {
112
- public Output MethodOne(Input bodyParam) {}
113
- }
114
- TestEnum.Two;
115
+ public Output MethodOne(Input bodyParam) {}
115
116
  }
117
+ TestEnum.Two;
116
118
  `,
117
119
  });
118
120
  });
package/test/utils.tsx CHANGED
@@ -8,7 +8,7 @@ export function TestNamespace(props: {
8
8
  }): core.Children {
9
9
  return (
10
10
  <core.Output namePolicy={csharp.createCSharpNamePolicy()}>
11
- <csharp.Namespace name="TestCode">{props.children}</csharp.Namespace>
11
+ <csharp.SourceFile path="Test.cs">{props.children}</csharp.SourceFile>
12
12
  </core.Output>
13
13
  );
14
14
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"EnumDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/EnumDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAGhB,MAAM,iBAAiB,CAAC;AAWzB,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,iBAgC1D;AAGD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;CACtB;AAGD,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,iBAchD"}
@@ -1,82 +0,0 @@
1
- import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
- import * as core from "@alloy-js/core";
3
- import { computeModifiersPrefix, getAccessModifier } from "../modifiers.js";
4
- import { useCSharpNamePolicy } from "../name-policy.js";
5
- import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
6
- import { CSharpMemberScope, useCSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
7
- import { Name } from "./Name.js";
8
-
9
- // properties for creating an enum
10
-
11
- /**
12
- * A C# enum declaration
13
- * @example
14
- * ```tsx
15
- * <EnumDeclaration public name="Color">
16
- * <EnumMember name="Red" />
17
- * <EnumMember name="Green" />
18
- * <EnumMember name="Blue" />
19
- * </EnumDeclaration>
20
- * ```
21
- * This will produce:
22
- * ```csharp
23
- * public enum Color
24
- * {
25
- * Red,
26
- * Green,
27
- * Blue
28
- * }
29
- * ```
30
- */
31
- export function EnumDeclaration(props) {
32
- const name = useCSharpNamePolicy().getName(props.name, "enum");
33
- const scope = useCSharpScope();
34
- const thisEnumSymbol = new CSharpOutputSymbol(name, {
35
- scope,
36
- refkeys: props.refkey ?? core.refkey(props.name)
37
- });
38
-
39
- // this creates a new scope for the enum definition.
40
- // members will automatically "inherit" this scope so
41
- // that refkeys to them will produce the fully-qualified
42
- // name e.g. Foo.Bar.
43
- const thisEnumScope = new CSharpMemberScope("enum-decl", {
44
- parent: scope,
45
- owner: thisEnumSymbol
46
- });
47
- const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
48
- if (thisEnumScope.owner) return _$createComponent(core.Declaration, {
49
- symbol: thisEnumSymbol,
50
- get children() {
51
- return [modifiers, "enum ", _$createComponent(Name, {}), _$memo(() => !props.children && ";"), _$memo(() => _$memo(() => !!props.children)() && _$createComponent(core.Scope, {
52
- value: thisEnumScope,
53
- get children() {
54
- return _$createComponent(core.Block, {
55
- newline: true,
56
- get children() {
57
- return props.children;
58
- }
59
- });
60
- }
61
- }))];
62
- }
63
- });
64
- }
65
-
66
- // properties for creating a C# enum member
67
-
68
- // a member within a C# enum
69
- export function EnumMember(props) {
70
- const scope = useCSharpMemberScope(["enum-decl"]);
71
- const name = useCSharpNamePolicy().getName(props.name, "enum-member");
72
- const thisEnumValueSymbol = new CSharpOutputSymbol(name, {
73
- scope,
74
- refkeys: props.refkey ?? core.refkey(props.name)
75
- });
76
- return _$createComponent(core.Declaration, {
77
- symbol: thisEnumValueSymbol,
78
- get children() {
79
- return _$createComponent(Name, {});
80
- }
81
- });
82
- }
@@ -1,11 +0,0 @@
1
- import * as core from "@alloy-js/core";
2
- export interface NamespaceContext {
3
- name: string;
4
- }
5
- export declare function useNamespace(): NamespaceContext | undefined;
6
- export interface NamespaceProps {
7
- name: string;
8
- children?: core.Children;
9
- }
10
- export declare function Namespace(props: NamespaceProps): core.Children;
11
- //# sourceMappingURL=Namespace.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Namespace.d.ts","sourceRoot":"","sources":["../../../src/components/Namespace.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAIvC,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;CACd;AAKD,wBAAgB,YAAY,IAAI,gBAAgB,GAAG,SAAS,CAE3D;AAGD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;CAC1B;AAGD,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,iBAY9C"}
@@ -1,33 +0,0 @@
1
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import * as core from "@alloy-js/core";
3
- import { CSharpNamespaceScope } from "../symbols/scopes.js";
4
-
5
- // contains the info for the current namespace
6
-
7
- const NamespaceContext = core.createContext();
8
-
9
- // returns the current namespace
10
- export function useNamespace() {
11
- return core.useContext(NamespaceContext);
12
- }
13
-
14
- // properties for creating a C# namespace
15
-
16
- // a C# namespace. contains one or more source files
17
- export function Namespace(props) {
18
- const scope = new CSharpNamespaceScope(props.name);
19
- const namespaceCtx = {
20
- name: props.name
21
- };
22
- return _$createComponent(NamespaceContext.Provider, {
23
- value: namespaceCtx,
24
- get children() {
25
- return _$createComponent(core.Scope, {
26
- value: scope,
27
- get children() {
28
- return props.children;
29
- }
30
- });
31
- }
32
- });
33
- }
@@ -1,8 +0,0 @@
1
- import * as core from "@alloy-js/core";
2
- import { CSharpOutputScope } from "./scopes.js";
3
- export declare class CSharpOutputSymbol extends core.OutputSymbol {
4
- get scope(): CSharpOutputScope;
5
- set scope(value: CSharpOutputScope);
6
- constructor(name: string, options?: core.OutputSymbolOptions);
7
- }
8
- //# sourceMappingURL=csharp-output-symbol.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"csharp-output-symbol.d.ts","sourceRoot":"","sources":["../../../src/symbols/csharp-output-symbol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIhD,qBAAa,kBAAmB,SAAQ,IAAI,CAAC,YAAY;IACvD,IAAI,KAAK,IAGQ,iBAAiB,CADjC;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,iBAAiB,EAEjC;gBAEW,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB;CAO7D"}
@@ -1,19 +0,0 @@
1
- import * as core from "@alloy-js/core";
2
- import { useNamespace } from "../components/Namespace.js";
3
- // represents a symbol from a .cs file. Class, enum, interface etc.
4
-
5
- export class CSharpOutputSymbol extends core.OutputSymbol {
6
- get scope() {
7
- return super.scope;
8
- }
9
- set scope(value) {
10
- super.scope = value;
11
- }
12
- constructor(name, options) {
13
- const namespaceCtx = useNamespace();
14
- if (!namespaceCtx) {
15
- throw new Error("symbol must be declared inside a namespace");
16
- }
17
- super(name, options);
18
- }
19
- }
@@ -1,20 +0,0 @@
1
- import * as core from "@alloy-js/core";
2
- import { CSharpOutputSymbol } from "./csharp-output-symbol.js";
3
- export declare class CSharpNamespaceScope extends core.OutputScope {
4
- get kind(): string;
5
- }
6
- export type CSharpMemberScopeName = "class-decl" | "constructor-decl" | "enum-decl" | "method-decl";
7
- export declare class CSharpMemberScope extends core.OutputScope {
8
- get kind(): string;
9
- get name(): CSharpMemberScopeName;
10
- get owner(): CSharpOutputSymbol;
11
- }
12
- export type CSharpOutputScope = CSharpMemberScope | CSharpNamespaceScope;
13
- export declare function useCSharpScope(): CSharpOutputScope;
14
- export declare function useCSharpMemberScope<T extends unknown[]>(names: T): CSharpMemberScope & {
15
- name: T[number];
16
- };
17
- export declare function assertMemberOfScope<T extends unknown[]>(scope: CSharpOutputScope, names: T): asserts scope is CSharpMemberScope & {
18
- name: T[number];
19
- };
20
- //# sourceMappingURL=scopes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../../src/symbols/scopes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAG/D,qBAAa,oBAAqB,SAAQ,IAAI,CAAC,WAAW;IACxD,IAAI,IAAI,WAEP;CACF;AAGD,MAAM,MAAM,qBAAqB,GAC7B,YAAY,GACZ,kBAAkB,GAClB,WAAW,GACX,aAAa,CAAC;AAKlB,qBAAa,iBAAkB,SAAQ,IAAI,CAAC,WAAW;IACrD,IAAI,IAAI,WAEP;IAED,IAAI,IAAI,IACe,qBAAqB,CAC3C;IAED,IAAI,KAAK,IACe,kBAAkB,CACzC;CACF;AAGD,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,oBAAoB,CAAC;AAGzE,wBAAgB,cAAc,IAAI,iBAAiB,CAElD;AAED,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,OAAO,EAAE,EACtD,KAAK,EAAE,CAAC,GACP,iBAAiB,GAAG;IAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;CAAE,CAIzC;AAED,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,OAAO,EAAE,EACrD,KAAK,EAAE,iBAAiB,EACxB,KAAK,EAAE,CAAC,GACP,OAAO,CAAC,KAAK,IAAI,iBAAiB,GAAG;IAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;CAAE,CAO1D"}
@@ -1,42 +0,0 @@
1
- import * as core from "@alloy-js/core";
2
- // indicates that the scope for a symbols is at the namespace level
3
- export class CSharpNamespaceScope extends core.OutputScope {
4
- get kind() {
5
- return "namespace";
6
- }
7
- }
8
-
9
- // the kind of member scope. i.e. are we in an enum, class, etc
10
-
11
- // indicates that the scope for a symbol resides within a type
12
- // e.g. for an enum value, class field etc, these would have
13
- // member scope where the owner is the containing type.
14
- export class CSharpMemberScope extends core.OutputScope {
15
- get kind() {
16
- return "member";
17
- }
18
- get name() {
19
- return super.name;
20
- }
21
- get owner() {
22
- return super.owner;
23
- }
24
- }
25
-
26
- // contains the possible scopes where a declaration can reside
27
-
28
- // returns the current C# scope
29
- export function useCSharpScope() {
30
- return core.useScope();
31
- }
32
- export function useCSharpMemberScope(names) {
33
- const scope = useCSharpScope();
34
- assertMemberOfScope(scope, names);
35
- return scope;
36
- }
37
- export function assertMemberOfScope(scope, names) {
38
- if (scope.kind !== "member" || !names.includes(scope.name)) {
39
- const context = core.getContext();
40
- throw new Error(`Can't define a ${context?.componentOwner?.component.name} outside of a ${names.join(" or ")} scope`);
41
- }
42
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=enum.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enum.test.d.ts","sourceRoot":"","sources":["../../test/enum.test.tsx"],"names":[],"mappings":""}
@@ -1,178 +0,0 @@
1
- import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
- import * as core from "@alloy-js/core";
3
- import * as coretest from "@alloy-js/core/testing";
4
- import { expect, it } from "vitest";
5
- import * as csharp from "../src/index.js";
6
- import * as utils from "./utils.js";
7
- import { findFile } from "./utils.js";
8
- it("declares enum with no members", () => {
9
- const res = utils.toSourceText(_$createComponent(csharp.EnumDeclaration, {
10
- "public": true,
11
- name: "TestEnum"
12
- }));
13
- expect(res).toBe(coretest.d`
14
- namespace TestCode
15
- {
16
- public enum TestEnum;
17
- }
18
- `);
19
- });
20
- it("declares enum with members", () => {
21
- const res = utils.toSourceText(_$createComponent(csharp.EnumDeclaration, {
22
- "public": true,
23
- name: "TestEnum",
24
- get children() {
25
- return [_$createComponent(csharp.EnumMember, {
26
- name: "One"
27
- }), ",", _$createIntrinsic("hbr", {}), _$createComponent(csharp.EnumMember, {
28
- name: "Two"
29
- })];
30
- }
31
- }));
32
- expect(res).toBe(coretest.d`
33
- namespace TestCode
34
- {
35
- public enum TestEnum
36
- {
37
- One,
38
- Two
39
- }
40
- }
41
- `);
42
- });
43
- it("applies naming policy to enum and members", () => {
44
- const res = utils.toSourceText(_$createComponent(csharp.EnumDeclaration, {
45
- "public": true,
46
- name: "testEnum",
47
- get children() {
48
- return [_$createComponent(csharp.EnumMember, {
49
- name: "one"
50
- }), ",", _$createIntrinsic("hbr", {}), _$createComponent(csharp.EnumMember, {
51
- name: "two"
52
- })];
53
- }
54
- }));
55
- expect(res).toBe(coretest.d`
56
- namespace TestCode
57
- {
58
- public enum TestEnum
59
- {
60
- One,
61
- Two
62
- }
63
- }
64
- `);
65
- });
66
- it("can reference things by refkey", () => {
67
- const enumRK = core.refkey();
68
- const twoRK = core.refkey();
69
- const res = core.render(_$createComponent(core.Output, {
70
- get children() {
71
- return _$createComponent(csharp.Namespace, {
72
- name: "TestCode",
73
- get children() {
74
- return _$createComponent(csharp.SourceFile, {
75
- path: "Test.cs",
76
- get children() {
77
- return [_$createComponent(csharp.EnumDeclaration, {
78
- "public": true,
79
- name: "TestEnum",
80
- refkey: enumRK,
81
- get children() {
82
- return [_$createComponent(csharp.EnumMember, {
83
- name: "One"
84
- }), ",", _$createIntrinsic("hbr", {}), _$createComponent(csharp.EnumMember, {
85
- name: "Two",
86
- refkey: twoRK
87
- })];
88
- }
89
- }), _$createIntrinsic("hbr", {}), enumRK, ";", _$createIntrinsic("hbr", {}), twoRK, ";"];
90
- }
91
- });
92
- }
93
- });
94
- }
95
- }));
96
- expect(findFile(res, "Test.cs").contents).toBe(coretest.d`
97
- namespace TestCode
98
- {
99
- public enum TestEnum
100
- {
101
- One,
102
- Two
103
- }
104
- TestEnum;
105
- TestEnum.Two;
106
- }
107
- `);
108
- });
109
- it("can reference things by refkey across files", () => {
110
- const enumRK = core.refkey();
111
- const barRK = core.refkey();
112
- const res = core.render(_$createComponent(core.Output, {
113
- get children() {
114
- return _$createComponent(csharp.Namespace, {
115
- name: "TestCode",
116
- get children() {
117
- return [_$createComponent(csharp.SourceFile, {
118
- path: "Test.cs",
119
- get children() {
120
- return [_$createComponent(csharp.EnumDeclaration, {
121
- "public": true,
122
- name: "TestEnum",
123
- get children() {
124
- return [_$createComponent(csharp.EnumMember, {
125
- name: "One"
126
- }), ",", _$createIntrinsic("hbr", {}), _$createComponent(csharp.EnumMember, {
127
- name: "Two"
128
- })];
129
- }
130
- }), _$createIntrinsic("hbr", {}), enumRK, ";", _$createIntrinsic("hbr", {}), barRK, ";"];
131
- }
132
- }), _$createComponent(csharp.SourceFile, {
133
- path: "Other.cs",
134
- get children() {
135
- return [_$createComponent(csharp.EnumDeclaration, {
136
- "public": true,
137
- name: "OtherEnum",
138
- refkey: enumRK,
139
- get children() {
140
- return [_$createComponent(csharp.EnumMember, {
141
- name: "Foo"
142
- }), ",", _$createIntrinsic("hbr", {}), _$createComponent(csharp.EnumMember, {
143
- name: "Bar",
144
- refkey: barRK
145
- })];
146
- }
147
- }), _$createIntrinsic("hbr", {}), enumRK, ";", _$createIntrinsic("hbr", {}), barRK, ";"];
148
- }
149
- })];
150
- }
151
- });
152
- }
153
- }));
154
- expect(findFile(res, "Test.cs").contents).toBe(coretest.d`
155
- namespace TestCode
156
- {
157
- public enum TestEnum
158
- {
159
- One,
160
- Two
161
- }
162
- OtherEnum;
163
- OtherEnum.Bar;
164
- }
165
- `);
166
- expect(findFile(res, "Other.cs").contents).toBe(coretest.d`
167
- namespace TestCode
168
- {
169
- public enum OtherEnum
170
- {
171
- Foo,
172
- Bar
173
- }
174
- OtherEnum;
175
- OtherEnum.Bar;
176
- }
177
- `);
178
- });
@@ -1 +0,0 @@
1
- {"version":3,"file":"namespace.test.d.ts","sourceRoot":"","sources":["../../test/namespace.test.tsx"],"names":[],"mappings":""}
@@ -1,81 +0,0 @@
1
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import * as core from "@alloy-js/core";
3
- import * as coretest from "@alloy-js/core/testing";
4
- import { it } from "vitest";
5
- import * as csharp from "../src/index.js";
6
- import { assertFileContents } from "./utils.js";
7
- it("defines multiple namespaces and source files with unique content", () => {
8
- const res = core.render(_$createComponent(core.Output, {
9
- get children() {
10
- return [_$createComponent(csharp.Namespace, {
11
- name: "Namespace1",
12
- get children() {
13
- return [_$createComponent(csharp.SourceFile, {
14
- path: "Model1.cs",
15
- get children() {
16
- return _$createComponent(csharp.ClassDeclaration, {
17
- "public": true,
18
- name: "Model1"
19
- });
20
- }
21
- }), _$createComponent(csharp.SourceFile, {
22
- path: "Model2.cs",
23
- get children() {
24
- return _$createComponent(csharp.ClassDeclaration, {
25
- "public": true,
26
- name: "Model2"
27
- });
28
- }
29
- })];
30
- }
31
- }), _$createComponent(csharp.Namespace, {
32
- name: "Namespace2",
33
- get children() {
34
- return [_$createComponent(csharp.SourceFile, {
35
- path: "Model3.cs",
36
- get children() {
37
- return _$createComponent(csharp.ClassDeclaration, {
38
- "public": true,
39
- name: "Model3"
40
- });
41
- }
42
- }), _$createComponent(csharp.SourceFile, {
43
- path: "Model4.cs",
44
- get children() {
45
- return _$createComponent(csharp.ClassDeclaration, {
46
- "public": true,
47
- name: "Model4"
48
- });
49
- }
50
- })];
51
- }
52
- })];
53
- }
54
- }));
55
- assertFileContents(res, {
56
- "Model1.cs": coretest.d`
57
- namespace Namespace1
58
- {
59
- public class Model1;
60
- }
61
- `,
62
- "Model2.cs": coretest.d`
63
- namespace Namespace1
64
- {
65
- public class Model2;
66
- }
67
- `,
68
- "Model3.cs": coretest.d`
69
- namespace Namespace2
70
- {
71
- public class Model3;
72
- }
73
- `,
74
- "Model4.cs": coretest.d`
75
- namespace Namespace2
76
- {
77
- public class Model4;
78
- }
79
- `
80
- });
81
- });