@alloy-js/csharp 0.20.0-dev.3 → 0.20.0-dev.5

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 (346) 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 +5 -14
  4. package/dist/src/components/Declaration.js.map +1 -0
  5. package/dist/src/components/Name.js +2 -1
  6. package/dist/src/components/Name.js.map +1 -0
  7. package/dist/src/components/ProjectDirectory.js +2 -1
  8. package/dist/src/components/ProjectDirectory.js.map +1 -0
  9. package/dist/src/components/Reference.d.ts.map +1 -1
  10. package/dist/src/components/Reference.js +7 -2
  11. package/dist/src/components/Reference.js.map +1 -0
  12. package/dist/src/components/SourceFile.d.ts +8 -9
  13. package/dist/src/components/SourceFile.d.ts.map +1 -1
  14. package/dist/src/components/SourceFile.js +71 -46
  15. package/dist/src/components/SourceFile.js.map +1 -0
  16. package/dist/src/components/UsingDirective.d.ts +5 -1
  17. package/dist/src/components/UsingDirective.d.ts.map +1 -1
  18. package/dist/src/components/UsingDirective.js +5 -2
  19. package/dist/src/components/UsingDirective.js.map +1 -0
  20. package/dist/src/components/attributes/attributes.js +2 -1
  21. package/dist/src/components/attributes/attributes.js.map +1 -0
  22. package/dist/src/components/attributes/attributes.test.js +2 -1
  23. package/dist/src/components/attributes/attributes.test.js.map +1 -0
  24. package/dist/src/components/class/declaration.d.ts +2 -2
  25. package/dist/src/components/class/declaration.d.ts.map +1 -1
  26. package/dist/src/components/class/declaration.js +20 -33
  27. package/dist/src/components/class/declaration.js.map +1 -0
  28. package/dist/src/components/class/declaration.test.js +173 -194
  29. package/dist/src/components/class/declaration.test.js.map +1 -0
  30. package/dist/src/components/constructor/constructor.d.ts.map +1 -1
  31. package/dist/src/components/constructor/constructor.js +13 -17
  32. package/dist/src/components/constructor/constructor.js.map +1 -0
  33. package/dist/src/components/constructor/constructor.test.js +12 -20
  34. package/dist/src/components/constructor/constructor.test.js.map +1 -0
  35. package/dist/src/components/doc/comment.js +2 -1
  36. package/dist/src/components/doc/comment.js.map +1 -0
  37. package/dist/src/components/doc/comment.test.js +2 -1
  38. package/dist/src/components/doc/comment.test.js.map +1 -0
  39. package/dist/src/components/doc/from-markdown.js +2 -1
  40. package/dist/src/components/doc/from-markdown.js.map +1 -0
  41. package/dist/src/components/doc/from-markdown.test.js +2 -1
  42. package/dist/src/components/doc/from-markdown.test.js.map +1 -0
  43. package/dist/src/components/{EnumDeclaration.d.ts → enum/declaration.d.ts} +6 -11
  44. package/dist/src/components/enum/declaration.d.ts.map +1 -0
  45. package/dist/src/components/enum/declaration.js +55 -0
  46. package/dist/src/components/enum/declaration.js.map +1 -0
  47. package/dist/src/components/enum/declaration.ref.test.d.ts +2 -0
  48. package/dist/src/components/enum/declaration.ref.test.d.ts.map +1 -0
  49. package/dist/src/components/enum/declaration.ref.test.js +121 -0
  50. package/dist/src/components/enum/declaration.ref.test.js.map +1 -0
  51. package/dist/src/components/enum/declaration.test.d.ts +2 -0
  52. package/dist/src/components/enum/declaration.test.d.ts.map +1 -0
  53. package/dist/src/components/enum/declaration.test.js +40 -0
  54. package/dist/src/components/enum/declaration.test.js.map +1 -0
  55. package/dist/src/components/enum/member.d.ts +7 -0
  56. package/dist/src/components/enum/member.d.ts.map +1 -0
  57. package/dist/src/components/enum/member.js +30 -0
  58. package/dist/src/components/enum/member.js.map +1 -0
  59. package/dist/src/components/enum/member.test.d.ts +2 -0
  60. package/dist/src/components/enum/member.test.d.ts.map +1 -0
  61. package/dist/src/components/enum/member.test.js +29 -0
  62. package/dist/src/components/enum/member.test.js.map +1 -0
  63. package/dist/src/components/field/field.d.ts.map +1 -1
  64. package/dist/src/components/field/field.js +11 -15
  65. package/dist/src/components/field/field.js.map +1 -0
  66. package/dist/src/components/field/field.test.js +9 -8
  67. package/dist/src/components/field/field.test.js.map +1 -0
  68. package/dist/src/components/index.d.ts +5 -2
  69. package/dist/src/components/index.d.ts.map +1 -1
  70. package/dist/src/components/index.js +7 -3
  71. package/dist/src/components/index.js.map +1 -0
  72. package/dist/src/components/interface/declaration.d.ts.map +1 -1
  73. package/dist/src/components/interface/declaration.js +21 -22
  74. package/dist/src/components/interface/declaration.js.map +1 -0
  75. package/dist/src/components/interface/declaration.test.js +28 -36
  76. package/dist/src/components/interface/declaration.test.js.map +1 -0
  77. package/dist/src/components/interface/method.d.ts.map +1 -1
  78. package/dist/src/components/interface/method.js +9 -16
  79. package/dist/src/components/interface/method.js.map +1 -0
  80. package/dist/src/components/interface/method.test.js +40 -48
  81. package/dist/src/components/interface/method.test.js.map +1 -0
  82. package/dist/src/components/interface/property.d.ts.map +1 -1
  83. package/dist/src/components/interface/property.js +23 -37
  84. package/dist/src/components/interface/property.js.map +1 -0
  85. package/dist/src/components/interface/property.test.js +13 -12
  86. package/dist/src/components/interface/property.test.js.map +1 -0
  87. package/dist/src/components/lexical-scope.d.ts +8 -0
  88. package/dist/src/components/lexical-scope.d.ts.map +1 -0
  89. package/dist/src/components/lexical-scope.js +25 -0
  90. package/dist/src/components/lexical-scope.js.map +1 -0
  91. package/dist/src/components/method/method.d.ts +5 -2
  92. package/dist/src/components/method/method.d.ts.map +1 -1
  93. package/dist/src/components/method/method.js +9 -14
  94. package/dist/src/components/method/method.js.map +1 -0
  95. package/dist/src/components/method/method.test.js +13 -12
  96. package/dist/src/components/method/method.test.js.map +1 -0
  97. package/dist/src/components/method-scope.d.ts +8 -0
  98. package/dist/src/components/method-scope.d.ts.map +1 -0
  99. package/dist/src/components/method-scope.js +25 -0
  100. package/dist/src/components/method-scope.js.map +1 -0
  101. package/dist/src/components/namespace-scopes.d.ts +13 -0
  102. package/dist/src/components/namespace-scopes.d.ts.map +1 -0
  103. package/dist/src/components/namespace-scopes.js +45 -0
  104. package/dist/src/components/namespace-scopes.js.map +1 -0
  105. package/dist/src/components/namespace.d.ts +7 -0
  106. package/dist/src/components/namespace.d.ts.map +1 -0
  107. package/dist/src/components/namespace.js +47 -0
  108. package/dist/src/components/namespace.js.map +1 -0
  109. package/dist/src/components/namespace.ref.test.d.ts +2 -0
  110. package/dist/src/components/namespace.ref.test.d.ts.map +1 -0
  111. package/dist/src/components/namespace.ref.test.js +182 -0
  112. package/dist/src/components/namespace.ref.test.js.map +1 -0
  113. package/dist/src/components/namespace.test.d.ts.map +1 -0
  114. package/dist/src/components/namespace.test.js +79 -0
  115. package/dist/src/components/namespace.test.js.map +1 -0
  116. package/dist/src/components/parameters/parameters.d.ts +2 -2
  117. package/dist/src/components/parameters/parameters.d.ts.map +1 -1
  118. package/dist/src/components/parameters/parameters.js +14 -12
  119. package/dist/src/components/parameters/parameters.js.map +1 -0
  120. package/dist/src/components/parameters/parameters.test.d.ts +2 -0
  121. package/dist/src/components/parameters/parameters.test.d.ts.map +1 -0
  122. package/dist/src/components/parameters/parameters.test.js +88 -0
  123. package/dist/src/components/parameters/parameters.test.js.map +1 -0
  124. package/dist/src/components/property/property.d.ts.map +1 -1
  125. package/dist/src/components/property/property.js +23 -37
  126. package/dist/src/components/property/property.js.map +1 -0
  127. package/dist/src/components/property/property.test.js +16 -15
  128. package/dist/src/components/property/property.test.js.map +1 -0
  129. package/dist/src/components/record/declaration.d.ts.map +1 -1
  130. package/dist/src/components/record/declaration.js +10 -13
  131. package/dist/src/components/record/declaration.js.map +1 -0
  132. package/dist/src/components/record/declaration.test.js +8 -14
  133. package/dist/src/components/record/declaration.test.js.map +1 -0
  134. package/dist/src/components/stc/index.js +2 -1
  135. package/dist/src/components/stc/index.js.map +1 -0
  136. package/dist/src/components/struct/declaration.d.ts.map +1 -1
  137. package/dist/src/components/struct/declaration.js +6 -7
  138. package/dist/src/components/struct/declaration.js.map +1 -0
  139. package/dist/src/components/struct/declaration.test.js +32 -40
  140. package/dist/src/components/struct/declaration.test.js.map +1 -0
  141. package/dist/src/components/type-parameters/type-parameter-constraints.js +2 -1
  142. package/dist/src/components/type-parameters/type-parameter-constraints.js.map +1 -0
  143. package/dist/src/components/type-parameters/type-parameter-constraints.test.js +2 -1
  144. package/dist/src/components/type-parameters/type-parameter-constraints.test.js.map +1 -0
  145. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -1
  146. package/dist/src/components/type-parameters/type-parameter.js +9 -11
  147. package/dist/src/components/type-parameters/type-parameter.js.map +1 -0
  148. package/dist/src/components/type-parameters/type-parameters.js +2 -1
  149. package/dist/src/components/type-parameters/type-parameters.js.map +1 -0
  150. package/dist/src/components/type-parameters/type-parameters.test.js +5 -4
  151. package/dist/src/components/type-parameters/type-parameters.test.js.map +1 -0
  152. package/dist/src/components/var/declaration.d.ts.map +1 -1
  153. package/dist/src/components/var/declaration.js +8 -9
  154. package/dist/src/components/var/declaration.js.map +1 -0
  155. package/dist/src/components/var/declaration.test.js +13 -21
  156. package/dist/src/components/var/declaration.test.js.map +1 -0
  157. package/dist/src/contexts/global-namespace.d.ts +5 -0
  158. package/dist/src/contexts/global-namespace.d.ts.map +1 -0
  159. package/dist/src/contexts/global-namespace.js +25 -0
  160. package/dist/src/contexts/global-namespace.js.map +1 -0
  161. package/dist/src/contexts/namespace.d.ts +8 -0
  162. package/dist/src/contexts/namespace.d.ts.map +1 -0
  163. package/dist/src/contexts/namespace.js +6 -0
  164. package/dist/src/contexts/namespace.js.map +1 -0
  165. package/dist/src/index.d.ts +1 -0
  166. package/dist/src/index.d.ts.map +1 -1
  167. package/dist/src/index.js +3 -1
  168. package/dist/src/index.js.map +1 -0
  169. package/dist/src/modifiers.d.ts +11 -0
  170. package/dist/src/modifiers.d.ts.map +1 -1
  171. package/dist/src/modifiers.js +2 -1
  172. package/dist/src/modifiers.js.map +1 -0
  173. package/dist/src/name-policy.js +2 -1
  174. package/dist/src/name-policy.js.map +1 -0
  175. package/dist/src/scopes/class.d.ts +10 -0
  176. package/dist/src/scopes/class.d.ts.map +1 -0
  177. package/dist/src/scopes/class.js +11 -0
  178. package/dist/src/scopes/class.js.map +1 -0
  179. package/dist/src/scopes/contexts.d.ts +9 -0
  180. package/dist/src/scopes/contexts.d.ts.map +1 -0
  181. package/dist/src/scopes/contexts.js +34 -0
  182. package/dist/src/scopes/contexts.js.map +1 -0
  183. package/dist/src/scopes/csharp.d.ts +8 -0
  184. package/dist/src/scopes/csharp.d.ts.map +1 -0
  185. package/dist/src/scopes/csharp.js +12 -0
  186. package/dist/src/scopes/csharp.js.map +1 -0
  187. package/dist/src/scopes/factories.d.ts +9 -0
  188. package/dist/src/scopes/factories.d.ts.map +1 -0
  189. package/dist/src/scopes/factories.js +24 -0
  190. package/dist/src/scopes/factories.js.map +1 -0
  191. package/dist/src/scopes/index.d.ts +10 -0
  192. package/dist/src/scopes/index.d.ts.map +1 -0
  193. package/dist/src/scopes/index.js +10 -0
  194. package/dist/src/scopes/index.js.map +1 -0
  195. package/dist/src/scopes/lexical.d.ts +7 -0
  196. package/dist/src/scopes/lexical.d.ts.map +1 -0
  197. package/dist/src/scopes/lexical.js +8 -0
  198. package/dist/src/scopes/lexical.js.map +1 -0
  199. package/dist/src/scopes/method.d.ts +9 -0
  200. package/dist/src/scopes/method.d.ts.map +1 -0
  201. package/dist/src/scopes/method.js +14 -0
  202. package/dist/src/scopes/method.js.map +1 -0
  203. package/dist/src/scopes/named-type.d.ts +22 -0
  204. package/dist/src/scopes/named-type.d.ts.map +1 -0
  205. package/dist/src/scopes/named-type.js +33 -0
  206. package/dist/src/scopes/named-type.js.map +1 -0
  207. package/dist/src/scopes/namespace.d.ts +11 -0
  208. package/dist/src/scopes/namespace.d.ts.map +1 -0
  209. package/dist/src/scopes/namespace.js +39 -0
  210. package/dist/src/scopes/namespace.js.map +1 -0
  211. package/dist/src/scopes/source-file.d.ts +16 -0
  212. package/dist/src/scopes/source-file.d.ts.map +1 -0
  213. package/dist/src/scopes/source-file.js +44 -0
  214. package/dist/src/scopes/source-file.js.map +1 -0
  215. package/dist/src/symbols/csharp.d.ts +76 -0
  216. package/dist/src/symbols/csharp.d.ts.map +1 -0
  217. package/dist/src/symbols/csharp.js +223 -0
  218. package/dist/src/symbols/csharp.js.map +1 -0
  219. package/dist/src/symbols/factories.d.ts +25 -0
  220. package/dist/src/symbols/factories.d.ts.map +1 -0
  221. package/dist/src/symbols/factories.js +87 -0
  222. package/dist/src/symbols/factories.js.map +1 -0
  223. package/dist/src/symbols/index.d.ts +5 -2
  224. package/dist/src/symbols/index.d.ts.map +1 -1
  225. package/dist/src/symbols/index.js +6 -2
  226. package/dist/src/symbols/index.js.map +1 -0
  227. package/dist/src/symbols/method.d.ts +13 -0
  228. package/dist/src/symbols/method.d.ts.map +1 -0
  229. package/dist/src/symbols/method.js +16 -0
  230. package/dist/src/symbols/method.js.map +1 -0
  231. package/dist/src/symbols/named-type.d.ts +19 -0
  232. package/dist/src/symbols/named-type.d.ts.map +1 -0
  233. package/dist/src/symbols/named-type.js +31 -0
  234. package/dist/src/symbols/named-type.js.map +1 -0
  235. package/dist/src/symbols/namespace.d.ts +22 -0
  236. package/dist/src/symbols/namespace.d.ts.map +1 -0
  237. package/dist/src/symbols/namespace.js +45 -0
  238. package/dist/src/symbols/namespace.js.map +1 -0
  239. package/dist/src/symbols/reference.d.ts +2 -2
  240. package/dist/src/symbols/reference.d.ts.map +1 -1
  241. package/dist/src/symbols/reference.js +38 -44
  242. package/dist/src/symbols/reference.js.map +1 -0
  243. package/dist/test/project-directory.test.js +14 -17
  244. package/dist/test/project-directory.test.js.map +1 -0
  245. package/dist/test/sourcefile.test.js +8 -19
  246. package/dist/test/sourcefile.test.js.map +1 -0
  247. package/dist/test/using.test.js +20 -17
  248. package/dist/test/using.test.js.map +1 -0
  249. package/dist/test/utils.js +4 -3
  250. package/dist/test/utils.js.map +1 -0
  251. package/dist/test/vitest.setup.js +2 -1
  252. package/dist/test/vitest.setup.js.map +1 -0
  253. package/dist/tsconfig.tsbuildinfo +1 -1
  254. package/package.json +9 -3
  255. package/src/components/Declaration.tsx +3 -6
  256. package/src/components/Reference.tsx +3 -1
  257. package/src/components/SourceFile.tsx +68 -55
  258. package/src/components/UsingDirective.tsx +12 -2
  259. package/src/components/class/declaration.test.tsx +120 -143
  260. package/src/components/class/declaration.tsx +19 -32
  261. package/src/components/constructor/constructor.test.tsx +10 -16
  262. package/src/components/constructor/constructor.tsx +13 -27
  263. package/src/components/enum/declaration.ref.test.tsx +93 -0
  264. package/src/components/enum/declaration.test.tsx +34 -0
  265. package/src/components/enum/declaration.tsx +65 -0
  266. package/src/components/enum/member.test.tsx +24 -0
  267. package/src/components/enum/member.tsx +36 -0
  268. package/src/components/field/field.test.tsx +7 -7
  269. package/src/components/field/field.tsx +12 -14
  270. package/src/components/index.ts +5 -2
  271. package/src/components/interface/declaration.test.tsx +26 -32
  272. package/src/components/interface/declaration.tsx +16 -18
  273. package/src/components/interface/method.test.tsx +38 -44
  274. package/src/components/interface/method.tsx +7 -19
  275. package/src/components/interface/property.test.tsx +11 -11
  276. package/src/components/interface/property.tsx +15 -33
  277. package/src/components/lexical-scope.tsx +29 -0
  278. package/src/components/method/method.test.tsx +11 -11
  279. package/src/components/method/method.tsx +12 -18
  280. package/src/components/method-scope.tsx +27 -0
  281. package/src/components/namespace-scopes.tsx +44 -0
  282. package/src/components/namespace.ref.test.tsx +139 -0
  283. package/src/components/namespace.test.tsx +52 -0
  284. package/src/components/namespace.tsx +45 -0
  285. package/src/components/parameters/parameters.test.tsx +71 -0
  286. package/src/components/parameters/parameters.tsx +9 -16
  287. package/src/components/property/property.test.tsx +14 -14
  288. package/src/components/property/property.tsx +17 -38
  289. package/src/components/record/declaration.test.tsx +5 -12
  290. package/src/components/record/declaration.tsx +10 -11
  291. package/src/components/struct/declaration.test.tsx +16 -22
  292. package/src/components/struct/declaration.tsx +4 -6
  293. package/src/components/type-parameters/type-parameter.tsx +14 -11
  294. package/src/components/type-parameters/type-parameters.test.tsx +4 -4
  295. package/src/components/var/declaration.test.tsx +8 -14
  296. package/src/components/var/declaration.tsx +12 -6
  297. package/src/contexts/global-namespace.ts +29 -0
  298. package/src/contexts/namespace.ts +13 -0
  299. package/src/index.ts +1 -0
  300. package/src/modifiers.ts +14 -0
  301. package/src/scopes/class.ts +12 -0
  302. package/src/scopes/contexts.ts +45 -0
  303. package/src/scopes/csharp.ts +18 -0
  304. package/src/scopes/factories.ts +45 -0
  305. package/src/scopes/index.ts +9 -0
  306. package/src/scopes/lexical.ts +10 -0
  307. package/src/scopes/method.ts +22 -0
  308. package/src/scopes/named-type.ts +44 -0
  309. package/src/scopes/namespace.ts +59 -0
  310. package/src/scopes/source-file.ts +67 -0
  311. package/src/symbols/csharp.ts +307 -0
  312. package/src/symbols/factories.ts +199 -0
  313. package/src/symbols/index.ts +5 -2
  314. package/src/symbols/method.ts +26 -0
  315. package/src/symbols/named-type.ts +54 -0
  316. package/src/symbols/namespace.ts +62 -0
  317. package/src/symbols/reference.ts +47 -50
  318. package/temp/api.json +6251 -2454
  319. package/test/project-directory.test.tsx +12 -16
  320. package/test/sourcefile.test.tsx +7 -21
  321. package/test/using.test.tsx +18 -16
  322. package/test/utils.tsx +1 -1
  323. package/tsconfig.json +4 -1
  324. package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
  325. package/dist/src/components/EnumDeclaration.js +0 -82
  326. package/dist/src/components/Namespace.d.ts +0 -11
  327. package/dist/src/components/Namespace.d.ts.map +0 -1
  328. package/dist/src/components/Namespace.js +0 -33
  329. package/dist/src/symbols/csharp-output-symbol.d.ts +0 -8
  330. package/dist/src/symbols/csharp-output-symbol.d.ts.map +0 -1
  331. package/dist/src/symbols/csharp-output-symbol.js +0 -19
  332. package/dist/src/symbols/scopes.d.ts +0 -20
  333. package/dist/src/symbols/scopes.d.ts.map +0 -1
  334. package/dist/src/symbols/scopes.js +0 -42
  335. package/dist/test/enum.test.d.ts +0 -2
  336. package/dist/test/enum.test.d.ts.map +0 -1
  337. package/dist/test/enum.test.js +0 -178
  338. package/dist/test/namespace.test.d.ts.map +0 -1
  339. package/dist/test/namespace.test.js +0 -81
  340. package/src/components/EnumDeclaration.tsx +0 -98
  341. package/src/components/Namespace.tsx +0 -35
  342. package/src/symbols/csharp-output-symbol.ts +0 -22
  343. package/src/symbols/scopes.ts +0 -61
  344. package/test/enum.test.tsx +0 -149
  345. package/test/namespace.test.tsx +0 -55
  346. /package/dist/{test → src/components}/namespace.test.d.ts +0 -0
@@ -1,18 +1,15 @@
1
1
  import * as core from "@alloy-js/core";
2
- import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
3
2
 
4
3
  // properties for creating a declaration
5
4
  export interface DeclarationProps {
6
5
  name: string;
7
- refkey?: core.Refkey;
6
+ refkey?: core.Refkey | core.Refkey[];
8
7
  children?: core.Children;
9
8
  }
10
9
 
11
10
  // declares a symbol in the program (class, enum, interface etc)
12
11
  export function Declaration(props: DeclarationProps) {
13
- const sym = new CSharpOutputSymbol(props.name, {
14
- refkeys: props.refkey,
15
- });
12
+ throw new Error("Not supported");
16
13
 
17
- return <core.Declaration symbol={sym}>{props.children}</core.Declaration>;
14
+ //return <core.Declaration symbol={sym}>{props.children}</core.Declaration>;
18
15
  }
@@ -8,6 +8,8 @@ export interface ReferenceProps {
8
8
  // used to resolve refkey references within source files
9
9
  export function Reference({ refkey }: ReferenceProps) {
10
10
  const reference = ref(refkey);
11
+ const symbolRef = core.computed(() => reference()[1]);
11
12
 
12
- return <>{reference}</>;
13
+ core.emitSymbol(symbolRef);
14
+ return <>{reference()[0]}</>;
13
15
  }
@@ -1,78 +1,91 @@
1
- import * as core from "@alloy-js/core";
2
- import { useNamespace } from "./Namespace.jsx";
1
+ import {
2
+ Children,
3
+ computed,
4
+ SourceFile as CoreSourceFile,
5
+ Scope,
6
+ Show,
7
+ useBinder,
8
+ } from "@alloy-js/core";
9
+ import { getGlobalNamespace } from "../contexts/global-namespace.js";
10
+ import { useNamespaceContext } from "../contexts/namespace.js";
11
+ import { CSharpSourceFileScope } from "../scopes/source-file.js";
12
+ import { NamespaceSymbol } from "../symbols/namespace.js";
13
+ import { NamespaceScope, NamespaceScopes } from "./namespace-scopes.jsx";
3
14
  import { Reference } from "./Reference.jsx";
4
15
  import { UsingDirective } from "./UsingDirective.jsx";
5
16
 
6
- // contains the info for the current source file
7
- export interface SourceFileContext {
8
- // adds a namespace to the array of using statements
9
- addUsing(namespace: string): void;
10
- }
11
-
12
- const SourceFileContext = core.createContext<SourceFileContext>();
13
-
14
- // returns the current source file
15
- export function useSourceFile(): SourceFileContext | undefined {
16
- return core.useContext(SourceFileContext) as SourceFileContext;
17
- }
18
-
19
17
  export interface SourceFileProps {
20
18
  /** Path of the source file */
21
19
  path: string;
22
20
 
23
- /** A list of namespaces to use */
24
- using?: Array<string>;
21
+ children?: Children;
25
22
 
26
- children?: core.Children;
23
+ /**
24
+ * A list of using directives to explicitly include. Note that providing
25
+ * explicit usings is not necessary when referencing symbols via refkeys.
26
+ */
27
+ using?: string[];
27
28
  }
28
29
 
29
30
  // a C# source file. exists within the context of a namespace
30
31
  // contains using statements and declarations
31
32
  export function SourceFile(props: SourceFileProps) {
32
- const namespaceCtx = useNamespace();
33
-
34
- if (!namespaceCtx) {
35
- throw new Error("SourceFile must be declared inside a namespace");
36
- }
37
-
38
- const using: Array<string> = core.reactive(new Array<string>());
39
- if (props.using) {
40
- using.push(...props.using);
41
- }
42
-
43
- // adds the specified namespace to the array of using statements.
44
- // called via SourceFileContext.addUsing when resolving refkeys.
45
- function addUsing(namespace: string): void {
46
- if (!using.includes(namespace)) {
47
- using.push(namespace);
48
- }
49
- }
50
-
51
- const sourceFileCtx: SourceFileContext = {
52
- addUsing,
53
- };
33
+ const sourceFileScope = new CSharpSourceFileScope(props.path);
54
34
 
35
+ const nsContext = useNamespaceContext();
36
+ const globalNs = getGlobalNamespace(useBinder());
37
+ const nsSymbol = nsContext ? nsContext.symbol : globalNs;
38
+ const nsRef = nsContext ? nsContext.symbol.name : undefined;
39
+ const usings = computed(() => {
40
+ return (
41
+ Array.from(sourceFileScope.usings) as (NamespaceSymbol | string)[]
42
+ ).concat(props.using ?? []);
43
+ });
55
44
  return (
56
- <core.SourceFile
45
+ <CoreSourceFile
57
46
  path={props.path}
58
47
  filetype="cs"
59
48
  reference={Reference}
60
49
  tabWidth={4}
61
50
  printWidth={120}
62
51
  >
63
- <SourceFileContext.Provider value={sourceFileCtx}>
64
- <core.Scope name={props.path} kind="source-file">
65
- {using.length > 0 && (
66
- <>
67
- <UsingDirective namespaces={using} />
68
- <hbr />
69
- <hbr />
70
- </>
71
- )}
72
- namespace {namespaceCtx.name}
73
- <core.Block newline>{props.children}</core.Block>
74
- </core.Scope>
75
- </SourceFileContext.Provider>
76
- </core.SourceFile>
52
+ <Scope value={sourceFileScope}>
53
+ {(sourceFileScope.usings.size > 0 ||
54
+ (props.using && props.using.length > 0)) && (
55
+ <>
56
+ <UsingDirective namespaces={usings.value} />
57
+ <hbr />
58
+ <hbr />
59
+ </>
60
+ )}
61
+ <Show when={!!nsContext && nsSymbol !== globalNs}>
62
+ <Show when={sourceFileScope.hasBlockNamespace}>
63
+ namespace {nsRef}
64
+ {" {"}
65
+ <hbr />
66
+ {" "}
67
+ </Show>
68
+
69
+ <Show when={!sourceFileScope.hasBlockNamespace}>
70
+ namespace {nsRef};<hbr />
71
+ <hbr />
72
+ </Show>
73
+ <align width={sourceFileScope.hasBlockNamespace ? 4 : 0}>
74
+ <NamespaceScopes symbol={nsContext!.symbol}>
75
+ {props.children}
76
+ </NamespaceScopes>
77
+ </align>
78
+ <Show when={sourceFileScope.hasBlockNamespace}>
79
+ <hbr />
80
+ {"}"}
81
+ </Show>
82
+ </Show>
83
+ <Show when={!nsContext || nsSymbol === globalNs}>
84
+ <NamespaceScope symbol={getGlobalNamespace(useBinder())}>
85
+ {props.children}
86
+ </NamespaceScope>
87
+ </Show>
88
+ </Scope>
89
+ </CoreSourceFile>
77
90
  );
78
91
  }
@@ -1,13 +1,23 @@
1
1
  import * as core from "@alloy-js/core";
2
+ import { NamespaceSymbol } from "../symbols/namespace.js";
2
3
 
3
4
  export interface UsingDirectiveProps {
4
- namespaces: Array<string>;
5
+ /**
6
+ * Namespace symbols or namespace names to use to generate using statements.
7
+ */
8
+ namespaces?: (NamespaceSymbol | string)[];
5
9
  }
6
10
 
7
11
  // one ore more C# using directives
8
12
  export function UsingDirective(props: UsingDirectiveProps) {
9
13
  const sortedNamespaces = core.computed(() => {
10
- return props.namespaces.sort();
14
+ return props
15
+ .namespaces!.map((ns) =>
16
+ typeof ns === "string" ? ns : (
17
+ ns.getFullyQualifiedName({ omitGlobal: true })
18
+ ),
19
+ )
20
+ .sort((n1, n2) => n1.localeCompare(n2));
11
21
  });
12
22
 
13
23
  return (
@@ -1,3 +1,6 @@
1
+ import { Constructor } from "#components/constructor/constructor.jsx";
2
+ import { EnumDeclaration } from "#components/enum/declaration.jsx";
3
+ import { EnumMember } from "#components/enum/member.jsx";
1
4
  import {
2
5
  Children,
3
6
  code,
@@ -15,19 +18,13 @@ import { createCSharpNamePolicy } from "../../name-policy.js";
15
18
  import { Attribute } from "../attributes/attributes.jsx";
16
19
  import { Field } from "../field/field.jsx";
17
20
  import { Method } from "../method/method.jsx";
18
- import { Namespace } from "../Namespace.jsx";
19
21
  import { Property } from "../property/property.jsx";
20
22
  import { SourceFile } from "../SourceFile.jsx";
21
- import { Constructor, EnumDeclaration, EnumMember } from "../stc/index.js";
22
23
  import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
23
24
  import { ClassDeclaration } from "./declaration.jsx";
24
25
 
25
26
  function Wrapper({ children }: { children: Children }) {
26
- return (
27
- <TestNamespace>
28
- <SourceFile path="Test.cs">{children}</SourceFile>
29
- </TestNamespace>
30
- );
27
+ return <TestNamespace>{children}</TestNamespace>;
31
28
  }
32
29
 
33
30
  it("declares class with no members", () => {
@@ -127,45 +124,43 @@ describe("base", () => {
127
124
  });
128
125
 
129
126
  it("declares class with some members", () => {
130
- const res = toSourceText(
131
- <ClassDeclaration public name="TestClass">
132
- <List>
133
- <Field public name="MemberOne" type="string" />
134
- <Field public name="MemberTwo" type="int" />
135
- </List>
136
- </ClassDeclaration>,
127
+ const tree = (
128
+ <TestNamespace>
129
+ <ClassDeclaration public name="TestClass">
130
+ <List>
131
+ <Field public name="MemberOne" type="string" />
132
+ <Field public name="MemberTwo" type="int" />
133
+ </List>
134
+ </ClassDeclaration>
135
+ </TestNamespace>
137
136
  );
138
137
 
139
- expect(res).toBe(coretest.d`
140
- namespace TestCode
138
+ expect(tree).toRenderTo(coretest.d`
139
+ public class TestClass
141
140
  {
142
- public class TestClass
143
- {
144
- public string MemberOne;
145
- public int MemberTwo;
146
- }
141
+ public string MemberOne;
142
+ public int MemberTwo;
147
143
  }
148
144
  `);
149
145
  });
150
146
 
151
147
  it("declares class with some methods", () => {
152
- const res = toSourceText(
153
- <ClassDeclaration public name="TestClass">
154
- <List>
155
- <Method public name="MethodOne" />
156
- <Method private virtual name="MethodTwo" />
157
- </List>
158
- </ClassDeclaration>,
148
+ const tree = (
149
+ <TestNamespace>
150
+ <ClassDeclaration public name="TestClass">
151
+ <List>
152
+ <Method public name="MethodOne" />
153
+ <Method private virtual name="MethodTwo" />
154
+ </List>
155
+ </ClassDeclaration>
156
+ </TestNamespace>
159
157
  );
160
158
 
161
- expect(res).toBe(coretest.d`
162
- namespace TestCode
159
+ expect(tree).toRenderTo(coretest.d`
160
+ public class TestClass
163
161
  {
164
- public class TestClass
165
- {
166
- public void MethodOne() {}
167
- private virtual void MethodTwo() {}
168
- }
162
+ public void MethodOne() {}
163
+ private virtual void MethodTwo() {}
169
164
  }
170
165
  `);
171
166
  });
@@ -188,57 +183,52 @@ it("uses refkeys for members, params, and return type", () => {
188
183
 
189
184
  const res = render(
190
185
  <Output namePolicy={createCSharpNamePolicy()}>
191
- <Namespace name="TestCode">
192
- <SourceFile path="Test.cs">
193
- <EnumDeclaration public name="TestEnum" refkey={enumTypeRefkey}>
194
- <List comma hardline>
195
- <EnumMember name="One" />
196
- <EnumMember name="Two" />
197
- </List>
198
- </EnumDeclaration>
199
- <hbr />
200
- <ClassDeclaration public name="TestInput" refkey={inputTypeRefkey} />
186
+ <SourceFile path="Test.cs">
187
+ <EnumDeclaration public name="TestEnum" refkey={enumTypeRefkey}>
188
+ <List comma hardline>
189
+ <EnumMember name="One" />
190
+ <EnumMember name="Two" />
191
+ </List>
192
+ </EnumDeclaration>
193
+ <hbr />
194
+ <ClassDeclaration public name="TestInput" refkey={inputTypeRefkey} />
195
+ <hbr />
196
+ <ClassDeclaration
197
+ public
198
+ name="TestResult"
199
+ refkey={testResultTypeRefkey}
200
+ />
201
+ <hbr />
202
+ <ClassDeclaration public name="TestClass">
203
+ <Field private name="MemberOne" type={enumTypeRefkey} />
201
204
  <hbr />
202
- <ClassDeclaration
205
+ <Method
203
206
  public
204
- name="TestResult"
205
- refkey={testResultTypeRefkey}
206
- />
207
- <hbr />
208
- <ClassDeclaration public name="TestClass">
209
- <Field private name="MemberOne" type={enumTypeRefkey} />
210
- <hbr />
211
- <Method
212
- public
213
- name="MethodOne"
214
- parameters={params}
215
- returns={testResultTypeRefkey}
216
- >
217
- return new {testResultTypeRefkey}();
218
- </Method>
219
- </ClassDeclaration>
220
- </SourceFile>
221
- </Namespace>
207
+ name="MethodOne"
208
+ parameters={params}
209
+ returns={testResultTypeRefkey}
210
+ >
211
+ return new {testResultTypeRefkey}();
212
+ </Method>
213
+ </ClassDeclaration>
214
+ </SourceFile>
222
215
  </Output>,
223
216
  );
224
217
 
225
218
  expect(findFile(res, "Test.cs").contents).toBe(coretest.d`
226
- namespace TestCode
219
+ public enum TestEnum
227
220
  {
228
- public enum TestEnum
229
- {
230
- One,
231
- Two
232
- }
233
- public class TestInput;
234
- public class TestResult;
235
- public class TestClass
221
+ One,
222
+ Two
223
+ }
224
+ public class TestInput;
225
+ public class TestResult;
226
+ public class TestClass
227
+ {
228
+ private TestEnum _memberOne;
229
+ public TestResult MethodOne(int intParam, TestInput bodyParam)
236
230
  {
237
- private TestEnum _memberOne;
238
- public TestResult MethodOne(int intParam, TestInput bodyParam)
239
- {
240
- return new TestResult();
241
- }
231
+ return new TestResult();
242
232
  }
243
233
  }
244
234
  `);
@@ -259,27 +249,22 @@ describe("with type parameters", () => {
259
249
 
260
250
  expect(
261
251
  <TestNamespace>
262
- <SourceFile path="Test.cs">
263
- <ClassDeclaration
264
- public
265
- name="TestClass"
266
- typeParameters={typeParameters}
267
- >
268
- <List>
269
- <Property name="PropA" type={typeParameters[0].refkey} get set />
270
- <Property name="PropB" type={typeParameters[1].refkey} get set />
271
- </List>
272
- </ClassDeclaration>
273
- </SourceFile>
252
+ <ClassDeclaration
253
+ public
254
+ name="TestClass"
255
+ typeParameters={typeParameters}
256
+ >
257
+ <List>
258
+ <Property name="PropA" type={typeParameters[0].refkey} get set />
259
+ <Property name="PropB" type={typeParameters[1].refkey} get set />
260
+ </List>
261
+ </ClassDeclaration>
274
262
  </TestNamespace>,
275
263
  ).toRenderTo(`
276
- namespace TestCode
264
+ public class TestClass<T, U>
277
265
  {
278
- public class TestClass<T, U>
279
- {
280
- T PropA { get; set; }
281
- U PropB { get; set; }
282
- }
266
+ T PropA { get; set; }
267
+ U PropB { get; set; }
283
268
  }
284
269
  `);
285
270
  });
@@ -308,10 +293,10 @@ describe("with type parameters", () => {
308
293
  </TestNamespace>,
309
294
  ).toRenderTo(`
310
295
  public class TestClass<T, U>
311
- where T : IFoo
312
- where U : IBar
296
+ where T : IFoo
297
+ where U : IBar
313
298
  {
314
- // Body
299
+ // Body
315
300
  }
316
301
  `);
317
302
  });
@@ -326,25 +311,24 @@ it("declares class with invalid members", () => {
326
311
  );
327
312
 
328
313
  expect(() => toSourceText(decl)).toThrow(
329
- "Can't define a EnumMember outside of a enum-decl scope",
314
+ "EnumMember must be used within an EnumDeclaration.",
330
315
  );
331
316
  });
332
317
 
333
318
  describe("constructor", () => {
334
319
  it("declares with constructor", () => {
335
- const res = toSourceText(
336
- <ClassDeclaration public name="TestClass">
337
- <Constructor public />
338
- </ClassDeclaration>,
320
+ const tree = (
321
+ <TestNamespace>
322
+ <ClassDeclaration public name="TestClass">
323
+ <Constructor public />
324
+ </ClassDeclaration>
325
+ </TestNamespace>
339
326
  );
340
327
 
341
- expect(res).toBe(coretest.d`
342
- namespace TestCode
328
+ expect(tree).toRenderTo(coretest.d`
329
+ public class TestClass
343
330
  {
344
- public class TestClass
345
- {
346
- public TestClass() {}
347
- }
331
+ public TestClass() {}
348
332
  }
349
333
  `);
350
334
  });
@@ -368,33 +352,32 @@ describe("constructor", () => {
368
352
  },
369
353
  ];
370
354
 
371
- const res = toSourceText(
372
- <ClassDeclaration public name="TestClass">
373
- <Field private name="name" type="string" refkey={thisNameRefkey} />
374
- <hbr />
375
- <Field private name="size" type="int" refkey={thisSizeRefkey} />
376
- <hbr />
377
- <Constructor public parameters={ctorParams}>
378
- {thisNameRefkey} = {paramNameRefkey};<hbr />
379
- {thisSizeRefkey} = {paramSizeRefkey};
380
- </Constructor>
381
- </ClassDeclaration>,
355
+ const tree = (
356
+ <TestNamespace>
357
+ <ClassDeclaration public name="TestClass">
358
+ <Field private name="name" type="string" refkey={thisNameRefkey} />
359
+ <hbr />
360
+ <Field private name="size" type="int" refkey={thisSizeRefkey} />
361
+ <hbr />
362
+ <Constructor public parameters={ctorParams}>
363
+ {thisNameRefkey} = {paramNameRefkey};<hbr />
364
+ {thisSizeRefkey} = {paramSizeRefkey};
365
+ </Constructor>
366
+ </ClassDeclaration>
367
+ </TestNamespace>
382
368
  );
383
369
 
384
370
  // TODO: assignments to members should have this. prefix
385
371
  // e.g. this.name = name;
386
- expect(res).toBe(coretest.d`
387
- namespace TestCode
372
+ expect(tree).toRenderTo(coretest.d`
373
+ public class TestClass
388
374
  {
389
- public class TestClass
375
+ private string _name;
376
+ private int _size;
377
+ public TestClass(string name, int size)
390
378
  {
391
- private string _name;
392
- private int _size;
393
- public TestClass(string name, int size)
394
- {
395
- _name = name;
396
- _size = size;
397
- }
379
+ _name = name;
380
+ _size = size;
398
381
  }
399
382
  }
400
383
  `);
@@ -433,12 +416,9 @@ describe("constructor", () => {
433
416
  </ClassDeclaration>
434
417
  </Wrapper>,
435
418
  ).toRenderTo(`
436
- namespace TestCode
419
+ public class TestClass(string name, int size)
437
420
  {
438
- public class TestClass(string name, int size)
439
- {
440
- string PrettyName { get; } = $"{name} {size}";
441
- }
421
+ string PrettyName { get; } = $"{name} {size}";
442
422
  }
443
423
  `);
444
424
  });
@@ -459,12 +439,9 @@ describe("constructor", () => {
459
439
  </NamePolicyContext.Provider>
460
440
  </Wrapper>,
461
441
  ).toRenderTo(`
462
- namespace TestCode
442
+ public class TestClass(string name)
463
443
  {
464
- public class TestClass(string name)
465
- {
466
- string name_2;
467
- }
444
+ string name_2;
468
445
  }
469
446
  `);
470
447
  });
@@ -492,8 +469,8 @@ it("supports class member doc comments", () => {
492
469
  /// This is a test
493
470
  class Test
494
471
  {
495
- /// This is a member
496
- public int Member;
472
+ /// This is a member
473
+ public int Member;
497
474
  }
498
475
  `);
499
476
  });
@@ -5,6 +5,7 @@ import {
5
5
  DeclarationProps,
6
6
  join,
7
7
  Name,
8
+ Namekey,
8
9
  Refkey,
9
10
  Scope,
10
11
  } from "@alloy-js/core";
@@ -14,9 +15,8 @@ import {
14
15
  getAccessModifier,
15
16
  makeModifiers,
16
17
  } from "../../modifiers.js";
17
- import { useCSharpNamePolicy } from "../../name-policy.js";
18
- import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
19
- import { CSharpMemberScope } from "../../symbols/scopes.js";
18
+ import { createClassScope } from "../../scopes/factories.js";
19
+ import { createNamedTypeSymbol } from "../../symbols/factories.js";
20
20
  import { AttributeList, AttributesProp } from "../attributes/attributes.jsx";
21
21
  import { DocWhen } from "../doc/comment.jsx";
22
22
  import { ParameterProps, Parameters } from "../parameters/parameters.jsx";
@@ -43,7 +43,7 @@ export interface ClassDeclarationProps
43
43
  extends Omit<DeclarationProps, "nameKind">,
44
44
  AccessModifiers,
45
45
  ClassModifiers {
46
- name: string;
46
+ name: string | Namekey;
47
47
  /** Doc comment */
48
48
  doc?: Children;
49
49
  refkey?: Refkey;
@@ -130,19 +130,10 @@ export interface ClassDeclarationProps
130
130
  * ```
131
131
  */
132
132
  export function ClassDeclaration(props: ClassDeclarationProps) {
133
- const name = useCSharpNamePolicy().getName(props.name!, "class");
134
-
135
- const thisClassSymbol = new CSharpOutputSymbol(name, {
133
+ const thisClassSymbol = createNamedTypeSymbol(props.name, "class", {
136
134
  refkeys: props.refkey,
137
135
  });
138
-
139
- // this creates a new scope for the class definition.
140
- // members will automatically "inherit" this scope so
141
- // that refkeys to them will produce the fully-qualified
142
- // name e.g. Foo.Bar.
143
- const thisClassScope = new CSharpMemberScope("class-decl", {
144
- owner: thisClassSymbol,
145
- });
136
+ const thisClassScope = createClassScope(thisClassSymbol);
146
137
 
147
138
  const bases = [
148
139
  ...(props.baseType ? [props.baseType] : []),
@@ -159,24 +150,20 @@ export function ClassDeclaration(props: ClassDeclarationProps) {
159
150
  <DocWhen doc={props.doc} />
160
151
  <AttributeList attributes={props.attributes} endline />
161
152
  {modifiers}class <Name />
162
- {props.typeParameters && (
163
- <TypeParameters parameters={props.typeParameters} />
164
- )}
165
- {props.primaryConstructor && (
166
- <Scope value={thisClassScope}>
153
+ <Scope value={thisClassScope}>
154
+ {props.typeParameters && (
155
+ <TypeParameters parameters={props.typeParameters} />
156
+ )}
157
+ {props.primaryConstructor && (
167
158
  <Parameters parameters={props.primaryConstructor} />
168
- </Scope>
169
- )}
170
- {base}
171
- {props.typeParameters && (
172
- <TypeParameterConstraints parameters={props.typeParameters} />
173
- )}
174
- {!props.children && ";"}
175
- {props.children && (
176
- <Block newline>
177
- <Scope value={thisClassScope}>{props.children}</Scope>
178
- </Block>
179
- )}
159
+ )}
160
+ {base}
161
+ {props.typeParameters && (
162
+ <TypeParameterConstraints parameters={props.typeParameters} />
163
+ )}
164
+ {!props.children && ";"}
165
+ {props.children && <Block newline>{props.children}</Block>}
166
+ </Scope>
180
167
  </Declaration>
181
168
  );
182
169
  }