@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
@@ -2,7 +2,6 @@ import { refkey } from "@alloy-js/core";
2
2
  import { expect, it } from "vitest";
3
3
  import { TestNamespace } from "../../../test/utils.jsx";
4
4
  import { ClassDeclaration } from "../class/declaration.jsx";
5
- import { SourceFile } from "../SourceFile.jsx";
6
5
  import { Constructor } from "./constructor.jsx";
7
6
 
8
7
  it("reference constructor parameters in body", () => {
@@ -16,25 +15,20 @@ it("reference constructor parameters in body", () => {
16
15
 
17
16
  expect(
18
17
  <TestNamespace>
19
- <SourceFile path="Test.cs">
20
- <ClassDeclaration public name="TestClass">
21
- <Constructor public parameters={ctorParams}>
22
- {paramNameRefkey};<hbr />
23
- {paramSizeRefkey};
24
- </Constructor>
25
- </ClassDeclaration>
26
- </SourceFile>
18
+ <ClassDeclaration public name="TestClass">
19
+ <Constructor public parameters={ctorParams}>
20
+ {paramNameRefkey};<hbr />
21
+ {paramSizeRefkey};
22
+ </Constructor>
23
+ </ClassDeclaration>
27
24
  </TestNamespace>,
28
25
  ).toRenderTo(`
29
- namespace TestCode
26
+ public class TestClass
30
27
  {
31
- public class TestClass
28
+ public TestClass(string name, int size)
32
29
  {
33
- public TestClass(string name, int size)
34
- {
35
- name;
36
- size;
37
- }
30
+ name;
31
+ size;
38
32
  }
39
33
  }
40
34
  `);
@@ -1,23 +1,13 @@
1
- import {
2
- Block,
3
- Declaration,
4
- Name,
5
- Refkey,
6
- refkey,
7
- Scope,
8
- } from "@alloy-js/core";
1
+ import { MethodScope } from "#components/method-scope.jsx";
2
+ import { Block, MemberDeclaration, MemberName, Refkey } from "@alloy-js/core";
9
3
  import { Children } from "@alloy-js/core/jsx-runtime";
10
4
  import {
11
5
  AccessModifiers,
12
6
  computeModifiersPrefix,
13
7
  getAccessModifier,
14
8
  } from "../../modifiers.js";
15
- import { useCSharpNamePolicy } from "../../name-policy.js";
16
- import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
17
- import {
18
- CSharpMemberScope,
19
- useCSharpMemberScope,
20
- } from "../../symbols/scopes.js";
9
+ import { useNamedTypeScope } from "../../scopes/contexts.js";
10
+ import { MethodSymbol } from "../../symbols/method.js";
21
11
  import { ParameterProps, Parameters } from "../parameters/parameters.jsx";
22
12
 
23
13
  /**
@@ -35,28 +25,24 @@ export interface ConstructorProps extends AccessModifiers {
35
25
  }
36
26
 
37
27
  export function Constructor(props: ConstructorProps) {
38
- const scope = useCSharpMemberScope(["class-decl", "struct-decl"]);
28
+ const scope = useNamedTypeScope();
39
29
 
40
- const name = useCSharpNamePolicy().getName(scope.owner!.name, "class-method");
41
- const ctorSymbol = new CSharpOutputSymbol(name, {
42
- scope,
43
- refkeys: props.refkey ?? refkey(name),
44
- });
30
+ const name = scope.ownerSymbol.name;
45
31
 
46
- const ctorDeclScope = new CSharpMemberScope("constructor-decl", {
47
- owner: ctorSymbol,
32
+ const ctorSymbol = new MethodSymbol(name, scope.members, "constructor", {
33
+ refkeys: props.refkey,
48
34
  });
49
35
 
50
36
  const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
51
37
 
52
38
  return (
53
- <Declaration symbol={ctorSymbol}>
54
- <Scope value={ctorDeclScope}>
39
+ <MemberDeclaration symbol={ctorSymbol}>
40
+ <MethodScope>
55
41
  {modifiers}
56
- <Name />
42
+ <MemberName />
57
43
  <Parameters parameters={props.parameters} />
58
44
  <Block newline>{props.children}</Block>
59
- </Scope>
60
- </Declaration>
45
+ </MethodScope>
46
+ </MemberDeclaration>
61
47
  );
62
48
  }
@@ -0,0 +1,93 @@
1
+ import { Namespace } from "#components/namespace.jsx";
2
+ import { SourceFile } from "#components/SourceFile.jsx";
3
+ import { Output, refkey } from "@alloy-js/core";
4
+ import { d } from "@alloy-js/core/testing";
5
+ import { expect, it } from "vitest";
6
+ import { EnumDeclaration } from "./declaration.jsx";
7
+ import { EnumMember } from "./member.jsx";
8
+
9
+ it("can reference things by refkey", () => {
10
+ const enumRK = refkey();
11
+ const twoRK = refkey();
12
+
13
+ const tree = (
14
+ <Output>
15
+ <Namespace name="TestCode">
16
+ <SourceFile path="Test.cs">
17
+ <EnumDeclaration public name="TestEnum" refkey={enumRK}>
18
+ <EnumMember name="One" />,<hbr />
19
+ <EnumMember name="Two" refkey={twoRK} />
20
+ </EnumDeclaration>
21
+ <hbr />
22
+ {enumRK};<hbr />
23
+ {twoRK};
24
+ </SourceFile>
25
+ </Namespace>
26
+ </Output>
27
+ );
28
+ expect(tree).toRenderTo(d`
29
+ namespace TestCode;
30
+
31
+ public enum TestEnum
32
+ {
33
+ One,
34
+ Two
35
+ }
36
+ TestEnum;
37
+ TestEnum.Two;
38
+ `);
39
+ });
40
+
41
+ it("can reference things by refkey across files", () => {
42
+ const enumRK = refkey();
43
+ const barRK = refkey();
44
+
45
+ const tree = (
46
+ <Output>
47
+ <Namespace name="TestCode">
48
+ <SourceFile path="Test.cs">
49
+ <EnumDeclaration public name="TestEnum">
50
+ <EnumMember name="One" />,<hbr />
51
+ <EnumMember name="Two" />
52
+ </EnumDeclaration>
53
+ <hbr />
54
+ {enumRK};<hbr />
55
+ {barRK};
56
+ </SourceFile>
57
+ <SourceFile path="Other.cs">
58
+ <EnumDeclaration public name="OtherEnum" refkey={enumRK}>
59
+ <EnumMember name="Foo" />,<hbr />
60
+ <EnumMember name="Bar" refkey={barRK} />
61
+ </EnumDeclaration>
62
+ <hbr />
63
+ {enumRK};<hbr />
64
+ {barRK};
65
+ </SourceFile>
66
+ </Namespace>
67
+ </Output>
68
+ );
69
+ expect(tree).toRenderTo({
70
+ "Test.cs": d`
71
+ namespace TestCode;
72
+
73
+ public enum TestEnum
74
+ {
75
+ One,
76
+ Two
77
+ }
78
+ OtherEnum;
79
+ OtherEnum.Bar;
80
+ `,
81
+ "Other.cs": d`
82
+ namespace TestCode;
83
+
84
+ public enum OtherEnum
85
+ {
86
+ Foo,
87
+ Bar
88
+ }
89
+ OtherEnum;
90
+ OtherEnum.Bar;
91
+ `,
92
+ });
93
+ });
@@ -0,0 +1,34 @@
1
+ import { toSourceText } from "#test/utils.jsx";
2
+ import { d } from "@alloy-js/core/testing";
3
+ import { expect, it } from "vitest";
4
+ import { EnumDeclaration } from "./declaration.jsx";
5
+ import { EnumMember } from "./member.jsx";
6
+
7
+ it("declares enum with no members", () => {
8
+ const res = toSourceText(<EnumDeclaration public name="TestEnum" />);
9
+
10
+ expect(res).toBe(d`
11
+ namespace TestCode;
12
+
13
+ public enum TestEnum;
14
+ `);
15
+ });
16
+
17
+ it("applies naming policy to enum and members", () => {
18
+ const res = toSourceText(
19
+ <EnumDeclaration public name="testEnum">
20
+ <EnumMember name="one" />,<hbr />
21
+ <EnumMember name="two" />
22
+ </EnumDeclaration>,
23
+ );
24
+
25
+ expect(res).toBe(d`
26
+ namespace TestCode;
27
+
28
+ public enum TestEnum
29
+ {
30
+ One,
31
+ Two
32
+ }
33
+ `);
34
+ });
@@ -0,0 +1,65 @@
1
+ import {
2
+ Block,
3
+ Children,
4
+ Declaration,
5
+ MemberScope,
6
+ Refkey,
7
+ } from "@alloy-js/core";
8
+ import {
9
+ AccessModifiers,
10
+ computeModifiersPrefix,
11
+ getAccessModifier,
12
+ } from "../../modifiers.js";
13
+ import { useCSharpNamePolicy } from "../../name-policy.js";
14
+ import { createNamedTypeScope } from "../../scopes/factories.js";
15
+ import { createNamedTypeSymbol } from "../../symbols/factories.js";
16
+ import { Name } from "../Name.jsx";
17
+
18
+ // properties for creating an enum
19
+ export interface EnumDeclarationProps extends AccessModifiers {
20
+ name: string;
21
+ refkey?: Refkey | Refkey[];
22
+ children?: Children;
23
+ }
24
+
25
+ /**
26
+ * A C# enum declaration
27
+ * @example
28
+ * ```tsx
29
+ * <EnumDeclaration public name="Color">
30
+ * <EnumMember name="Red" />
31
+ * <EnumMember name="Green" />
32
+ * <EnumMember name="Blue" />
33
+ * </EnumDeclaration>
34
+ * ```
35
+ * This will produce:
36
+ * ```csharp
37
+ * public enum Color
38
+ * {
39
+ * Red,
40
+ * Green,
41
+ * Blue
42
+ * }
43
+ * ```
44
+ */
45
+ export function EnumDeclaration(props: EnumDeclarationProps) {
46
+ const name = useCSharpNamePolicy().getName(props.name!, "enum");
47
+ const symbol = createNamedTypeSymbol(name, "enum", {
48
+ refkeys: props.refkey,
49
+ });
50
+ const scope = createNamedTypeScope(symbol);
51
+
52
+ const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
53
+
54
+ return (
55
+ <Declaration symbol={symbol}>
56
+ {modifiers}enum <Name />
57
+ {!props.children && ";"}
58
+ {props.children && (
59
+ <MemberScope value={scope}>
60
+ <Block newline>{props.children}</Block>
61
+ </MemberScope>
62
+ )}
63
+ </Declaration>
64
+ );
65
+ }
@@ -0,0 +1,24 @@
1
+ import { toSourceText } from "#test/utils.jsx";
2
+ import { d } from "@alloy-js/core/testing";
3
+ import { expect, it } from "vitest";
4
+ import { EnumDeclaration } from "./declaration.jsx";
5
+ import { EnumMember } from "./member.jsx";
6
+
7
+ it("declares enum with members", () => {
8
+ const res = toSourceText(
9
+ <EnumDeclaration public name="TestEnum">
10
+ <EnumMember name="One" />,<hbr />
11
+ <EnumMember name="Two" />
12
+ </EnumDeclaration>,
13
+ );
14
+
15
+ expect(res).toBe(d`
16
+ namespace TestCode;
17
+
18
+ public enum TestEnum
19
+ {
20
+ One,
21
+ Two
22
+ }
23
+ `);
24
+ });
@@ -0,0 +1,36 @@
1
+ import { MemberDeclaration, MemberName, Refkey } from "@alloy-js/core";
2
+ import { useCSharpNamePolicy } from "../../name-policy.js";
3
+ import { useNamedTypeScope } from "../../scopes/contexts.js";
4
+ import { CSharpSymbol } from "../../symbols/csharp.js";
5
+
6
+ // properties for creating a C# enum member
7
+ export interface EnumMemberProps {
8
+ name: string;
9
+ refkey?: Refkey;
10
+ }
11
+
12
+ // a member within a C# enum
13
+ export function EnumMember(props: EnumMemberProps) {
14
+ const scope = useNamedTypeScope();
15
+
16
+ if (!scope) {
17
+ throw new Error("EnumMember must be used within an EnumDeclaration.");
18
+ }
19
+
20
+ const symbol = scope.ownerSymbol;
21
+
22
+ if (symbol.typeKind !== "enum") {
23
+ throw new Error("EnumMember must be used within an EnumDeclaration.");
24
+ }
25
+
26
+ const name = useCSharpNamePolicy().getName(props.name, "enum-member");
27
+ const thisEnumValueSymbol = new CSharpSymbol(name, symbol.members, {
28
+ refkeys: props.refkey,
29
+ });
30
+
31
+ return (
32
+ <MemberDeclaration symbol={thisEnumValueSymbol}>
33
+ <MemberName />
34
+ </MemberDeclaration>
35
+ );
36
+ }
@@ -24,8 +24,8 @@ it("declares multiple fields", () => {
24
24
  ).toRenderTo(`
25
25
  public class TestClass
26
26
  {
27
- public string MemberOne;
28
- public int MemberTwo;
27
+ public string MemberOne;
28
+ public int MemberTwo;
29
29
  }
30
30
  `);
31
31
  });
@@ -46,7 +46,7 @@ describe("modifiers", () => {
46
46
  ).toRenderTo(`
47
47
  public class TestClass
48
48
  {
49
- ${accessModifier} string ${accessModifier === "private" ? "_testProp" : "TestProp"};
49
+ ${accessModifier} string ${accessModifier === "private" ? "_testProp" : "TestProp"};
50
50
  }
51
51
  `);
52
52
  },
@@ -68,7 +68,7 @@ describe("modifiers", () => {
68
68
  ).toRenderTo(`
69
69
  public class TestClass
70
70
  {
71
- ${methodModifier} string _testField;
71
+ ${methodModifier} string _testField;
72
72
  }
73
73
  `);
74
74
  },
@@ -83,7 +83,7 @@ describe("modifiers", () => {
83
83
  ).toRenderTo(`
84
84
  public class TestClass
85
85
  {
86
- public new string TestField;
86
+ public new string TestField;
87
87
  }
88
88
  `);
89
89
  });
@@ -100,7 +100,7 @@ describe("naming", () => {
100
100
  ).toRenderTo(`
101
101
  public class TestClass
102
102
  {
103
- public string MemberOne;
103
+ public string MemberOne;
104
104
  }
105
105
  `);
106
106
  });
@@ -115,7 +115,7 @@ describe("naming", () => {
115
115
  ).toRenderTo(`
116
116
  public class TestClass
117
117
  {
118
- private string _memberOne;
118
+ private string _memberOne;
119
119
  }
120
120
  `);
121
121
  });
@@ -1,13 +1,15 @@
1
- import { Children, Declaration, Name, refkey, Refkey } from "@alloy-js/core";
1
+ import { Children, Declaration, Name, Refkey } from "@alloy-js/core";
2
2
  import {
3
3
  AccessModifiers,
4
4
  computeModifiersPrefix,
5
5
  getAccessModifier,
6
6
  makeModifiers,
7
7
  } from "../../modifiers.js";
8
- import { CSharpElements, useCSharpNamePolicy } from "../../name-policy.js";
9
- import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
10
- import { useCSharpMemberScope } from "../../symbols/scopes.js";
8
+ import {
9
+ accessibilityFromProps,
10
+ nonAccessibilityFromProps,
11
+ } from "../../symbols/csharp.js";
12
+ import { createFieldSymbol } from "../../symbols/factories.js";
11
13
  import { DocWhen } from "../doc/comment.jsx";
12
14
 
13
15
  /** Field modifiers. */
@@ -35,17 +37,13 @@ export interface FieldProps extends AccessModifiers, FieldModifiers {
35
37
 
36
38
  /** Render a c# field */
37
39
  export function Field(props: FieldProps) {
38
- let nameElement: CSharpElements = "class-member-private";
39
- if (props.public || props.protected || props.internal) {
40
- nameElement = "class-member-public";
41
- }
42
- const name = useCSharpNamePolicy().getName(props.name, nameElement);
43
- const scope = useCSharpMemberScope(["class-decl", "struct-decl"]);
40
+ const options = {
41
+ accessibility: accessibilityFromProps(props),
42
+ refkeys: props.refkey,
43
+ ...nonAccessibilityFromProps(props),
44
+ };
44
45
 
45
- const memberSymbol = new CSharpOutputSymbol(name, {
46
- scope,
47
- refkeys: props.refkey ?? refkey(props.name),
48
- });
46
+ const memberSymbol = createFieldSymbol(props.name, options);
49
47
 
50
48
  const modifiers = computeModifiersPrefix([
51
49
  getAccessModifier(props),
@@ -4,14 +4,17 @@ export * from "./constructor/constructor.jsx";
4
4
  export * from "./Declaration.js";
5
5
  export * from "./doc/comment.jsx";
6
6
  export * from "./doc/from-markdown.jsx";
7
- export * from "./EnumDeclaration.jsx";
7
+ export * from "./enum/declaration.jsx";
8
+ export * from "./enum/member.jsx";
8
9
  export * from "./field/field.jsx";
9
10
  export * from "./interface/declaration.js";
10
11
  export * from "./interface/method.js";
11
12
  export * from "./interface/property.js";
13
+ export * from "./lexical-scope.jsx";
14
+ export * from "./method-scope.jsx";
12
15
  export * from "./method/method.jsx";
13
16
  export * from "./Name.js";
14
- export * from "./Namespace.js";
17
+ export * from "./namespace.js";
15
18
  export * from "./parameters/parameters.jsx";
16
19
  export * from "./ProjectDirectory.js";
17
20
  export * from "./property/property.jsx";
@@ -2,7 +2,6 @@ import { List, refkey } from "@alloy-js/core";
2
2
  import { describe, expect, it } from "vitest";
3
3
  import { TestNamespace } from "../../../test/utils.jsx";
4
4
  import { Attribute } from "../attributes/attributes.jsx";
5
- import { SourceFile } from "../SourceFile.jsx";
6
5
  import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
7
6
  import { InterfaceDeclaration } from "./declaration.jsx";
8
7
  import { InterfaceProperty } from "./property.jsx";
@@ -75,37 +74,32 @@ describe("with type parameters", () => {
75
74
 
76
75
  expect(
77
76
  <TestNamespace>
78
- <SourceFile path="Test.cs">
79
- <InterfaceDeclaration
80
- public
81
- name="Test"
82
- typeParameters={typeParameters}
83
- >
84
- <List>
85
- <InterfaceProperty
86
- name="PropA"
87
- type={typeParameters[0].refkey}
88
- get
89
- set
90
- />
91
- <InterfaceProperty
92
- name="PropB"
93
- type={typeParameters[1].refkey}
94
- get
95
- set
96
- />
97
- </List>
98
- </InterfaceDeclaration>
99
- </SourceFile>
77
+ <InterfaceDeclaration
78
+ public
79
+ name="Test"
80
+ typeParameters={typeParameters}
81
+ >
82
+ <List>
83
+ <InterfaceProperty
84
+ name="PropA"
85
+ type={typeParameters[0].refkey}
86
+ get
87
+ set
88
+ />
89
+ <InterfaceProperty
90
+ name="PropB"
91
+ type={typeParameters[1].refkey}
92
+ get
93
+ set
94
+ />
95
+ </List>
96
+ </InterfaceDeclaration>
100
97
  </TestNamespace>,
101
98
  ).toRenderTo(`
102
- namespace TestCode
99
+ public interface Test<T, U>
103
100
  {
104
- public interface Test<T, U>
105
- {
106
- T PropA { get; set; }
107
- U PropB { get; set; }
108
- }
101
+ T PropA { get; set; }
102
+ U PropB { get; set; }
109
103
  }
110
104
  `);
111
105
  });
@@ -134,10 +128,10 @@ describe("with type parameters", () => {
134
128
  </TestNamespace>,
135
129
  ).toRenderTo(`
136
130
  public interface Test<T, U>
137
- where T : IFoo
138
- where U : IBar
131
+ where T : IFoo
132
+ where U : IBar
139
133
  {
140
- // Body
134
+ // Body
141
135
  }
142
136
  `);
143
137
  });
@@ -6,8 +6,8 @@ import {
6
6
  makeModifiers,
7
7
  } from "../../modifiers.js";
8
8
  import { useCSharpNamePolicy } from "../../name-policy.js";
9
- import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
10
- import { CSharpMemberScope } from "../../symbols/scopes.js";
9
+ import { createNamedTypeScope } from "../../scopes/factories.js";
10
+ import { createNamedTypeSymbol } from "../../symbols/factories.js";
11
11
  import { AttributeList, AttributesProp } from "../attributes/attributes.jsx";
12
12
  import { DocWhen } from "../doc/comment.jsx";
13
13
  import { Name } from "../Name.jsx";
@@ -88,7 +88,7 @@ export interface InterfaceDeclarationProps
88
88
  export function InterfaceDeclaration(props: InterfaceDeclarationProps) {
89
89
  const name = useCSharpNamePolicy().getName(props.name!, "interface");
90
90
 
91
- const thisInterfaceSymbol = new CSharpOutputSymbol(name, {
91
+ const symbol = createNamedTypeSymbol(name, "interface", {
92
92
  refkeys: props.refkey,
93
93
  });
94
94
 
@@ -96,30 +96,28 @@ export function InterfaceDeclaration(props: InterfaceDeclarationProps) {
96
96
  // members will automatically "inherit" this scope so
97
97
  // that refkeys to them will produce the fully-qualified
98
98
  // name e.g. Foo.Bar.
99
- const thisInterfaceScope = new CSharpMemberScope("interface-decl", {
100
- owner: thisInterfaceSymbol,
101
- });
99
+ const thisInterfaceScope = createNamedTypeScope(symbol);
102
100
 
103
101
  const modifiers = computeModifiersPrefix([
104
102
  getAccessModifier(props),
105
103
  getInterfaceModifiers(props),
106
104
  ]);
107
105
  return (
108
- <core.Declaration symbol={thisInterfaceSymbol}>
106
+ <core.Declaration symbol={symbol}>
109
107
  <DocWhen doc={props.doc} />
110
108
  <AttributeList attributes={props.attributes} endline />
111
109
  {modifiers}interface <Name />
112
- {props.typeParameters && (
113
- <TypeParameters parameters={props.typeParameters} />
114
- )}
115
- {props.typeParameters && (
116
- <TypeParameterConstraints parameters={props.typeParameters} />
117
- )}
118
- {props.children ?
119
- <core.Block newline>
120
- <core.Scope value={thisInterfaceScope}>{props.children}</core.Scope>
121
- </core.Block>
122
- : ";"}
110
+ <core.Scope value={thisInterfaceScope}>
111
+ {props.typeParameters && (
112
+ <TypeParameters parameters={props.typeParameters} />
113
+ )}
114
+ {props.typeParameters && (
115
+ <TypeParameterConstraints parameters={props.typeParameters} />
116
+ )}
117
+ {props.children ?
118
+ <core.Block newline>{props.children}</core.Block>
119
+ : ";"}
120
+ </core.Scope>
123
121
  </core.Declaration>
124
122
  );
125
123
  }