@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
@@ -0,0 +1,25 @@
1
+ import { Namekey, OutputSymbolOptions } from "@alloy-js/core";
2
+ import { CSharpMethodScope } from "../scopes/method.js";
3
+ import { CSharpNamedTypeScope } from "../scopes/named-type.js";
4
+ import { CSharpSymbol, CSharpSymbolOptions } from "./csharp.js";
5
+ import { MethodKinds, MethodSymbol } from "./method.js";
6
+ import { NamedTypeSymbol, NamedTypeTypeKind } from "./named-type.js";
7
+ import { NamespaceSymbol } from "./namespace.js";
8
+ /**
9
+ * Create a symbol for a parameter in the current method scope.
10
+ */
11
+ export declare function createParameterSymbol(originalName: string | Namekey, options?: CSharpSymbolOptions): CSharpSymbol;
12
+ export interface CreateTypeParameterSymbolOptions extends CSharpSymbolOptions {
13
+ scope?: CSharpMethodScope | CSharpNamedTypeScope;
14
+ }
15
+ export declare function createTypeParameterSymbol(originalName: string | Namekey, options?: CreateTypeParameterSymbolOptions): CSharpSymbol;
16
+ export declare function createFieldSymbol(originalName: string | Namekey, options?: CSharpSymbolOptions): CSharpSymbol;
17
+ export declare function createNamedTypeSymbol(name: string | Namekey, kind: NamedTypeTypeKind, options?: OutputSymbolOptions): NamedTypeSymbol;
18
+ export declare function createNamespaceSymbol(name: string): NamespaceSymbol;
19
+ export interface CreateMethodSymbolOptions extends CSharpSymbolOptions {
20
+ methodKind?: MethodKinds;
21
+ }
22
+ export declare function createMethodSymbol(originalName: string | Namekey, options?: CreateMethodSymbolOptions): MethodSymbol;
23
+ export declare function createPropertySymbol(name: string | Namekey, options: CSharpSymbolOptions): CSharpSymbol;
24
+ export declare function createVariableSymbol(originalName: string | Namekey, options?: CSharpSymbolOptions): CSharpSymbol;
25
+ //# sourceMappingURL=factories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factories.d.ts","sourceRoot":"","sources":["../../../src/symbols/factories.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,mBAAmB,EAEpB,MAAM,gBAAgB,CAAC;AAOxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAM/D,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,GAAG,OAAO,EAC9B,OAAO,GAAE,mBAAwB,gBAgBlC;AAED,MAAM,WAAW,gCAAiC,SAAQ,mBAAmB;IAC3E,KAAK,CAAC,EAAE,iBAAiB,GAAG,oBAAoB,CAAC;CAClD;AACD,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,GAAG,OAAO,EAC9B,OAAO,GAAE,gCAAqC,gBAiB/C;AAED,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,GAAG,OAAO,EAC9B,OAAO,GAAE,mBAAwB,gBA0BlC;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,GAAG,OAAO,EACtB,IAAI,EAAE,iBAAiB,EACvB,OAAO,CAAC,EAAE,mBAAmB,mBAI9B;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,mBAOjD;AAED,MAAM,WAAW,yBAA0B,SAAQ,mBAAmB;IACpE,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,MAAM,GAAG,OAAO,EAC9B,OAAO,GAAE,yBAA8B,gBAoBxC;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,GAAG,OAAO,EACtB,OAAO,EAAE,mBAAmB,gBAQ7B;AAED,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,GAAG,OAAO,EAC9B,OAAO,GAAE,mBAAwB,gBA2BlC"}
@@ -0,0 +1,86 @@
1
+ import { useBinder } from "@alloy-js/core";
2
+ import { getGlobalNamespace } from "../contexts/global-namespace.js";
3
+ import { useCSharpNamePolicy } from "../name-policy.js";
4
+ import { CSharpClassScope } from "../scopes/class.js";
5
+ import { useCSharpScope, useNamedTypeScope } from "../scopes/contexts.js";
6
+ import { CSharpLexicalScope } from "../scopes/lexical.js";
7
+ import { CSharpMethodScope } from "../scopes/method.js";
8
+ import { CSharpNamedTypeScope } from "../scopes/named-type.js";
9
+ import { CSharpNamespaceScope, useEnclosingNamespaceScope } from "../scopes/namespace.js";
10
+ import { CSharpSourceFileScope } from "../scopes/source-file.js";
11
+ import { CSharpSymbol } from "./csharp.js";
12
+ import { MethodSymbol } from "./method.js";
13
+ import { NamedTypeSymbol } from "./named-type.js";
14
+ import { NamespaceSymbol } from "./namespace.js";
15
+
16
+ /**
17
+ * Create a symbol for a parameter in the current method scope.
18
+ */
19
+ export function createParameterSymbol(originalName, options = {}) {
20
+ const scope = useCSharpScope();
21
+ if (!(scope instanceof CSharpMethodScope) && !(scope instanceof CSharpClassScope)) {
22
+ throw new Error(`Can't create parameter symbol outside of a method or class scope.`);
23
+ }
24
+ return new CSharpSymbol(originalName, scope.parameters, withNamePolicy(options, "parameter"));
25
+ }
26
+ export function createTypeParameterSymbol(originalName, options = {}) {
27
+ const scope = options.scope ?? useCSharpScope();
28
+ if (!(scope instanceof CSharpMethodScope) && !(scope instanceof CSharpNamedTypeScope)) {
29
+ throw new Error("Can't create a type parameter symbol outside of a method or named type scope.");
30
+ }
31
+ return new CSharpSymbol(originalName, scope.typeParameters, withNamePolicy(options, "type-parameter"));
32
+ }
33
+ export function createFieldSymbol(originalName, options = {}) {
34
+ let nameElement = "class-member-private";
35
+ if (options.accessibility === "public" || options.accessibility === "internal" || options.accessibility === "protected") {
36
+ nameElement = "class-member-public";
37
+ }
38
+ const scope = useNamedTypeScope();
39
+ if (scope.ownerSymbol.typeKind !== "class" && scope.ownerSymbol.typeKind !== "struct") {
40
+ throw new Error(`Can't define a field outside of a class or struct.`);
41
+ }
42
+ return new CSharpSymbol(originalName, scope.members, withNamePolicy(options, nameElement));
43
+ }
44
+ export function createNamedTypeSymbol(name, kind, options) {
45
+ const scope = useNamedTypeScope();
46
+ return new NamedTypeSymbol(name, scope.ownerSymbol.members, kind, options);
47
+ }
48
+ export function createNamespaceSymbol(name) {
49
+ const scope = useEnclosingNamespaceScope();
50
+ const nsSymbol = scope?.ownerSymbol ?? getGlobalNamespace(useBinder());
51
+ if (nsSymbol.members.symbolNames.has(name)) {
52
+ return nsSymbol.members.symbolNames.get(name);
53
+ }
54
+ return new NamespaceSymbol(name, nsSymbol);
55
+ }
56
+ export function createMethodSymbol(originalName, options = {}) {
57
+ const scope = useNamedTypeScope();
58
+ if (scope.ownerSymbol.typeKind !== "class" && scope.ownerSymbol.typeKind !== "interface" && scope.ownerSymbol.typeKind !== "struct") {
59
+ throw new Error(`Can't define a method outside of a class, interface, or struct.`);
60
+ }
61
+ return new MethodSymbol(originalName, scope.members, options.methodKind ?? "ordinary", withNamePolicy(options, "class-method"));
62
+ }
63
+ export function createPropertySymbol(name, options) {
64
+ const scope = useNamedTypeScope();
65
+ return new CSharpSymbol(name, scope.members, withNamePolicy(options, "class-property"));
66
+ }
67
+ export function createVariableSymbol(originalName, options = {}) {
68
+ let scope = useCSharpScope();
69
+ if (scope instanceof CSharpNamespaceScope && scope.ownerSymbol === getGlobalNamespace(scope.ownerSymbol.binder)) {
70
+ // allow top-level variables in the global namespace, which are local to the source file.
71
+ scope = scope.parent;
72
+ if (!(scope instanceof CSharpSourceFileScope)) {
73
+ throw new Error("Variable declarations must be in the global namespace or within a lexical scope.");
74
+ }
75
+ }
76
+ if (!(scope instanceof CSharpLexicalScope)) {
77
+ throw new Error(`Can't create variable symbol outside of a lexical scope, got a ${scope.constructor.name}.`);
78
+ }
79
+ return new CSharpSymbol(originalName, scope.localVariables, withNamePolicy(options, "variable"));
80
+ }
81
+ function withNamePolicy(options, elementType) {
82
+ return {
83
+ ...options,
84
+ namePolicy: options.namePolicy ?? useCSharpNamePolicy().for(elementType)
85
+ };
86
+ }
@@ -1,4 +1,7 @@
1
- export * from "./csharp-output-symbol.js";
1
+ export * from "./csharp.js";
2
+ export * from "./factories.js";
3
+ export * from "./method.js";
4
+ export * from "./named-type.js";
5
+ export * from "./namespace.js";
2
6
  export * from "./reference.js";
3
- export * from "./scopes.js";
4
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/symbols/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/symbols/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
@@ -1,3 +1,6 @@
1
- export * from "./csharp-output-symbol.js";
2
- export * from "./reference.js";
3
- export * from "./scopes.js";
1
+ export * from "./csharp.js";
2
+ export * from "./factories.js";
3
+ export * from "./method.js";
4
+ export * from "./named-type.js";
5
+ export * from "./namespace.js";
6
+ export * from "./reference.js";
@@ -0,0 +1,13 @@
1
+ import { Namekey, OutputSpace } from "@alloy-js/core";
2
+ import { CSharpSymbol, CSharpSymbolOptions } from "./csharp.js";
3
+ export type MethodKinds = "ordinary" | "constructor";
4
+ /**
5
+ * A symbol for a method or constructor of a class, interface, or struct.
6
+ */
7
+ export declare class MethodSymbol extends CSharpSymbol {
8
+ #private;
9
+ readonly symbolKind = "method";
10
+ get methodKind(): MethodKinds;
11
+ constructor(name: string | Namekey, spaces: OutputSpace | undefined, kind: MethodKinds, options?: CSharpSymbolOptions);
12
+ }
13
+ //# sourceMappingURL=method.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../../src/symbols/method.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEhE,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,aAAa,CAAC;AAErD;;GAEG;AACH,qBAAa,YAAa,SAAQ,YAAY;;IAC5C,SAAgB,UAAU,YAAY;IAGtC,IAAI,UAAU,gBAEb;gBAGC,IAAI,EAAE,MAAM,GAAG,OAAO,EACtB,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,IAAI,EAAE,WAAW,EACjB,OAAO,GAAE,mBAAwB;CAKpC"}
@@ -0,0 +1,15 @@
1
+ import { CSharpSymbol } from "./csharp.js";
2
+ /**
3
+ * A symbol for a method or constructor of a class, interface, or struct.
4
+ */
5
+ export class MethodSymbol extends CSharpSymbol {
6
+ symbolKind = "method";
7
+ #methodKind;
8
+ get methodKind() {
9
+ return this.#methodKind;
10
+ }
11
+ constructor(name, spaces, kind, options = {}) {
12
+ super(name, spaces, options);
13
+ this.#methodKind = kind;
14
+ }
15
+ }
@@ -0,0 +1,19 @@
1
+ import { Namekey, OutputSpace, OutputSymbolOptions } from "@alloy-js/core";
2
+ import { CSharpSymbol } from "./csharp.js";
3
+ export type NamedTypeTypeKind = "class" | "interface" | "enum" | "namespace" | "struct" | "record";
4
+ export type NamedTypeSymbolKind = "named-type" | "namespace";
5
+ /**
6
+ * A symbol for a named type in C# such as a class, interface, enum, and so
7
+ * forth. Named types are generally defined in a namespace, and can have members
8
+ * of their own.
9
+ */
10
+ export declare class NamedTypeSymbol extends CSharpSymbol {
11
+ #private;
12
+ readonly symbolKind: NamedTypeSymbolKind;
13
+ static readonly memberSpaces: string[];
14
+ constructor(name: string | Namekey, spaces: OutputSpace[] | OutputSpace | undefined, kind: NamedTypeTypeKind, options?: OutputSymbolOptions);
15
+ get typeKind(): NamedTypeTypeKind;
16
+ copy(): NamedTypeSymbol;
17
+ get members(): import("@alloy-js/core").OutputMemberSpace;
18
+ }
19
+ //# sourceMappingURL=named-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"named-type.d.ts","sourceRoot":"","sources":["../../../src/symbols/named-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,MAAM,MAAM,iBAAiB,GACzB,OAAO,GACP,WAAW,GACX,MAAM,GACN,WAAW,GACX,QAAQ,GACR,QAAQ,CAAC;AACb,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG,WAAW,CAAC;AAE7D;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,YAAY;;IAC/C,SAAgB,UAAU,EAAE,mBAAmB,CAAgB;IAC/D,gBAAuB,YAAY,WAAe;gBAGhD,IAAI,EAAE,MAAM,GAAG,OAAO,EACtB,MAAM,EAAE,WAAW,EAAE,GAAG,WAAW,GAAG,SAAS,EAC/C,IAAI,EAAE,iBAAiB,EACvB,OAAO,CAAC,EAAE,mBAAmB;IAO/B,IAAI,QAAQ,sBAEX;IAED,IAAI;IAYJ,IAAI,OAAO,+CAEV;CACF"}
@@ -0,0 +1,30 @@
1
+ import { CSharpSymbol } from "./csharp.js";
2
+
3
+ // represents a symbol from a .cs file. Class, enum, interface etc.
4
+
5
+ /**
6
+ * A symbol for a named type in C# such as a class, interface, enum, and so
7
+ * forth. Named types are generally defined in a namespace, and can have members
8
+ * of their own.
9
+ */
10
+ export class NamedTypeSymbol extends CSharpSymbol {
11
+ symbolKind = "named-type";
12
+ static memberSpaces = ["members"];
13
+ constructor(name, spaces, kind, options) {
14
+ super(name, spaces, options);
15
+ this.#typeKind = kind;
16
+ }
17
+ #typeKind;
18
+ get typeKind() {
19
+ return this.#typeKind;
20
+ }
21
+ copy() {
22
+ const options = this.getCopyOptions();
23
+ const copy = new NamedTypeSymbol(this.name, undefined, this.#typeKind, options);
24
+ this.initializeCopy(copy);
25
+ return copy;
26
+ }
27
+ get members() {
28
+ return this.memberSpaceFor("members");
29
+ }
30
+ }
@@ -0,0 +1,22 @@
1
+ import { OutputSymbolOptions } from "@alloy-js/core";
2
+ import { NamedTypeSymbol } from "./named-type.js";
3
+ export interface NamespaceSymbolOptions extends OutputSymbolOptions {
4
+ isGlobal?: boolean;
5
+ }
6
+ /**
7
+ * A symbol for a namespace in C#.
8
+ */
9
+ export declare class NamespaceSymbol extends NamedTypeSymbol {
10
+ #private;
11
+ readonly symbolKind = "namespace";
12
+ constructor(name: string, parentNamespace?: NamespaceSymbol, options?: NamespaceSymbolOptions);
13
+ /**
14
+ * Whether this symbol is the global namespace symbol.
15
+ */
16
+ get isGlobal(): boolean;
17
+ getFullyQualifiedName(options?: {
18
+ omitGlobal?: boolean;
19
+ }): string;
20
+ copy(): NamespaceSymbol;
21
+ }
22
+ //# sourceMappingURL=namespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../../src/symbols/namespace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,WAAW,sBAAuB,SAAQ,mBAAmB;IACjE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,eAAe;;IAClD,SAAgB,UAAU,eAAe;gBAEvC,IAAI,EAAE,MAAM,EACZ,eAAe,CAAC,EAAE,eAAe,EACjC,OAAO,CAAC,EAAE,sBAAsB;IAUlC;;OAEG;IACH,IAAI,QAAQ,YAEX;IAED,qBAAqB,CAAC,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,MAAM;IAoBrE,IAAI;CASL"}
@@ -0,0 +1,44 @@
1
+ import { NamedTypeSymbol } from "./named-type.js";
2
+ /**
3
+ * A symbol for a namespace in C#.
4
+ */
5
+ export class NamespaceSymbol extends NamedTypeSymbol {
6
+ symbolKind = "namespace";
7
+ constructor(name, parentNamespace, options) {
8
+ const space = parentNamespace?.members;
9
+ super(name, space, "namespace", options);
10
+ this.#isGlobal = !!options?.isGlobal;
11
+ }
12
+ #isGlobal;
13
+ /**
14
+ * Whether this symbol is the global namespace symbol.
15
+ */
16
+ get isGlobal() {
17
+ return this.#isGlobal;
18
+ }
19
+ getFullyQualifiedName(options = {}) {
20
+ const parts = [];
21
+
22
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
23
+ let current = this;
24
+ while (current && !current.isGlobal) {
25
+ parts.unshift(current.name);
26
+ current = current.ownerSymbol;
27
+ }
28
+ const idPart = parts.join(".");
29
+ if (options.omitGlobal) {
30
+ return idPart;
31
+ } else {
32
+ return `global::${idPart}`;
33
+ }
34
+ }
35
+ copy() {
36
+ const options = this.getCopyOptions();
37
+ const copy = new NamespaceSymbol(this.name, undefined, {
38
+ ...options,
39
+ isGlobal: this.#isGlobal
40
+ });
41
+ this.initializeCopy(copy);
42
+ return copy;
43
+ }
44
+ }
@@ -1,3 +1,3 @@
1
- import * as core from "@alloy-js/core";
2
- export declare function ref(refkey: core.Refkey): () => string;
1
+ import { OutputSymbol, Refkey } from "@alloy-js/core";
2
+ export declare function ref(refkey: Refkey): () => [string, OutputSymbol | undefined];
3
3
  //# sourceMappingURL=reference.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/symbols/reference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAoBvC,wBAAgB,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,MAAM,MAAM,CA4CrD"}
1
+ {"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/symbols/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,YAAY,EAAE,MAAM,EAAW,MAAM,gBAAgB,CAAC;AAWrE,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,CAAC,CAkD5E"}
@@ -1,54 +1,47 @@
1
- import * as core from "@alloy-js/core";
2
- import { useNamespace } from "../components/Namespace.js";
3
- import { useSourceFile } from "../components/SourceFile.js";
4
-
5
- // when resolving references across source files, the last element
6
- // in pathDown will be the containing source file. we only need this
7
- // here so we can find and remove this scope as it's not useful
8
- // when building the reference
9
-
1
+ import { memo, resolve } from "@alloy-js/core";
2
+ import { CSharpNamespaceScope } from "../scopes/namespace.js";
3
+ import { useSourceFileScope } from "../scopes/source-file.js";
10
4
  // converts a refkey to its fully qualified name
11
5
  // e.g. if refkey is for bar in enum type foo, and
12
6
  // foo is in the same namespace as the refkey, then
13
7
  // the result would be foo.bar.
14
8
  export function ref(refkey) {
15
- const targetNamespaceCtx = useNamespace();
16
- const resolveResult = core.resolve(refkey);
17
- return core.memo(() => {
9
+ const refSfScope = useSourceFileScope();
10
+ const resolveResult = resolve(refkey);
11
+ return memo(() => {
18
12
  if (resolveResult.value === undefined) {
19
- return "<Unresolved Symbol>";
13
+ return ["<Unresolved Symbol>", undefined];
20
14
  }
21
-
22
- // targetDeclaration is the symbol with the refkey
23
- // pathDown is an array of scopes to that symbol and can be empty.
24
- // the entries are top-down, so namespace, source-file, member
25
- // - referencing a type within the same namespace will have an empty path
26
- // - referencing a member (e.g. enum value) within the same namespace will
27
- // have a single path entry that contains the owning type
28
- // - referencing a type within the same namespace but in a different source
29
- // file will have at least a source-file entry
30
- // - referencing a symbol outside the current namespace will have at least
31
- // two entries, namespace, source-file
15
+ const result = resolveResult.value;
32
16
  const {
33
- targetDeclaration,
34
- pathDown
35
- } = resolveResult.value;
36
- const sourceNamespace = pathDown.find(v => {
37
- return v.kind === "namespace";
38
- });
39
- if (sourceNamespace && sourceNamespace.name !== targetNamespaceCtx.name) {
40
- // the source symbol is in a different namespace that the target refkey.
41
- // add the applicable using statement to the target's source file.
42
- const targetSrc = useSourceFile();
43
- targetSrc.addUsing(sourceNamespace.name);
17
+ commonScope,
18
+ pathDown,
19
+ memberPath
20
+ } = result;
21
+ let {
22
+ lexicalDeclaration
23
+ } = result;
24
+ const parts = [];
25
+ if (!commonScope) {
26
+ // this shouldn't be possible in csharp.
27
+ return ["<Unresolved Symbol>", undefined];
44
28
  }
45
-
46
- // we only need to build the fully-qualified name for members
47
- // TODO: possibly a subset of members
48
- const syms = pathDown.filter(v => {
49
- return v.kind === "member";
50
- }).map(s => s.owner);
51
- syms.push(targetDeclaration);
52
- return syms.map(sym => sym.name).join(".");
29
+ if (commonScope instanceof CSharpNamespaceScope && commonScope.ownerSymbol.isGlobal && lexicalDeclaration.symbolKind === "namespace" && memberPath.length > 0) {
30
+ // we need to using the namespace
31
+ let nsToUse;
32
+ while (lexicalDeclaration.symbolKind === "namespace" && memberPath.length > 0) {
33
+ nsToUse = lexicalDeclaration;
34
+ lexicalDeclaration = memberPath.shift();
35
+ }
36
+ refSfScope.addUsing(nsToUse);
37
+ }
38
+ for (const nsScope of pathDown) {
39
+ parts.push(nsScope.ownerSymbol.name);
40
+ }
41
+ parts.push(lexicalDeclaration.name);
42
+ for (const member of memberPath) {
43
+ parts.push(member.name);
44
+ }
45
+ return [parts.join("."), result.symbol];
53
46
  });
54
47
  }
@@ -53,17 +53,15 @@ it("defines a project directory file with multiple source files", () => {
53
53
  const srcDir = projDir.contents[1];
54
54
  expect(srcDir.contents[0].path).equals("~/projects/TestProject/src/Test1.cs");
55
55
  expect(srcDir.contents[0].contents).toBe(coretest.d`
56
- namespace TestCode
57
- {
58
- public class TestClass1;
59
- }
56
+ namespace TestCode;
57
+
58
+ public class TestClass1;
60
59
  `);
61
60
  expect(srcDir.contents[1].path).equals("~/projects/TestProject/src/Test2.cs");
62
61
  expect(srcDir.contents[1].contents).toBe(coretest.d`
63
- namespace TestCode
64
- {
65
- public class TestClass2;
66
- }
62
+ namespace TestCode;
63
+
64
+ public class TestClass2;
67
65
  `);
68
66
  });
69
67
  it("defines a project directory file with multiple source files and a custom TFM", () => {
@@ -117,16 +115,14 @@ it("defines a project directory file with multiple source files and a custom TFM
117
115
  const srcDir = projDir.contents[1];
118
116
  expect(srcDir.contents[0].path).equals("~/projects/TestProject/src/Test1.cs");
119
117
  expect(srcDir.contents[0].contents).toBe(coretest.d`
120
- namespace TestCode
121
- {
122
- public class TestClass1;
123
- }
118
+ namespace TestCode;
119
+
120
+ public class TestClass1;
124
121
  `);
125
122
  expect(srcDir.contents[1].path).equals("~/projects/TestProject/src/Test2.cs");
126
123
  expect(srcDir.contents[1].contents).toBe(coretest.d`
127
- namespace TestCode
128
- {
129
- public class TestClass2;
130
- }
124
+ namespace TestCode;
125
+
126
+ public class TestClass2;
131
127
  `);
132
128
  });
@@ -1,7 +1,7 @@
1
1
  import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
2
  import * as core from "@alloy-js/core";
3
3
  import * as coretest from "@alloy-js/core/testing";
4
- import { expect, it } from "vitest";
4
+ import { it } from "vitest";
5
5
  import * as csharp from "../src/index.js";
6
6
  import { assertFileContents } from "./utils.js";
7
7
  it("defines multiple source files with unique content", () => {
@@ -33,26 +33,14 @@ it("defines multiple source files with unique content", () => {
33
33
  }));
34
34
  assertFileContents(res, {
35
35
  "Test1.cs": coretest.d`
36
- namespace TestCode
37
- {
38
- public class TestClass1;
39
- }
36
+ namespace TestCode;
37
+
38
+ public class TestClass1;
40
39
  `,
41
40
  "Test2.cs": coretest.d`
42
- namespace TestCode
43
- {
44
- public class TestClass2;
45
- }
41
+ namespace TestCode;
42
+
43
+ public class TestClass2;
46
44
  `
47
45
  });
48
- });
49
- it("throws when declaring a source file outside a namespace", () => {
50
- const decl = _$createComponent(core.Output, {
51
- get children() {
52
- return _$createComponent(csharp.SourceFile, {
53
- path: "Test.cs"
54
- });
55
- }
56
- });
57
- expect(() => core.render(decl)).toThrow("SourceFile must be declared inside a namespace");
58
46
  });
@@ -21,7 +21,9 @@ it("uses a single namespace", () => {
21
21
  expect(findFile(res, "Test1.cs").contents).toBe(coretest.d`
22
22
  using Foo;
23
23
 
24
- namespace TestCode {}
24
+ namespace TestCode;
25
+
26
+
25
27
  `);
26
28
  });
27
29
  it("uses multiple namespaces", () => {
@@ -42,7 +44,9 @@ it("uses multiple namespaces", () => {
42
44
  using Bar.Baz;
43
45
  using Foo;
44
46
 
45
- namespace TestCode {}
47
+ namespace TestCode;
48
+
49
+
46
50
  `);
47
51
  });
48
52
  it("adds using statement across namespaces", () => {
@@ -114,29 +118,27 @@ it("adds using statement across namespaces", () => {
114
118
  }));
115
119
  assertFileContents(res, {
116
120
  "Models.cs": coretest.d`
117
- namespace Models
121
+ namespace Models;
122
+
123
+ public class Input;
124
+ public class Output;
125
+ public enum TestEnum
118
126
  {
119
- public class Input;
120
- public class Output;
121
- public enum TestEnum
122
- {
123
- One,
124
- Two
125
- }
127
+ One,
128
+ Two
126
129
  }
127
130
  `,
128
131
  "Client.cs": coretest.d`
129
132
  using Models;
130
133
  using System;
131
134
 
132
- namespace Client
135
+ namespace Client;
136
+
137
+ public class Client
133
138
  {
134
- public class Client
135
- {
136
- public Output MethodOne(Input bodyParam) {}
137
- }
138
- TestEnum.Two;
139
+ public Output MethodOne(Input bodyParam) {}
139
140
  }
141
+ TestEnum.Two;
140
142
  `
141
143
  });
142
144
  });
@@ -9,8 +9,8 @@ export function TestNamespace(props) {
9
9
  return csharp.createCSharpNamePolicy();
10
10
  },
11
11
  get children() {
12
- return _$createComponent(csharp.Namespace, {
13
- name: "TestCode",
12
+ return _$createComponent(csharp.SourceFile, {
13
+ path: "Test.cs",
14
14
  get children() {
15
15
  return props.children;
16
16
  }