@alloy-js/csharp 0.20.0-dev.2 → 0.20.0-dev.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/dist/src/components/Declaration.d.ts +2 -2
  2. package/dist/src/components/Declaration.d.ts.map +1 -1
  3. package/dist/src/components/Declaration.js +3 -13
  4. package/dist/src/components/Reference.d.ts.map +1 -1
  5. package/dist/src/components/Reference.js +5 -1
  6. package/dist/src/components/SourceFile.d.ts +8 -9
  7. package/dist/src/components/SourceFile.d.ts.map +1 -1
  8. package/dist/src/components/SourceFile.js +69 -45
  9. package/dist/src/components/UsingDirective.d.ts +5 -1
  10. package/dist/src/components/UsingDirective.d.ts.map +1 -1
  11. package/dist/src/components/UsingDirective.js +3 -1
  12. package/dist/src/components/class/declaration.d.ts +2 -2
  13. package/dist/src/components/class/declaration.d.ts.map +1 -1
  14. package/dist/src/components/class/declaration.js +19 -33
  15. package/dist/src/components/class/declaration.test.js +192 -193
  16. package/dist/src/components/constructor/constructor.d.ts.map +1 -1
  17. package/dist/src/components/constructor/constructor.js +11 -19
  18. package/dist/src/components/constructor/constructor.test.js +10 -19
  19. package/dist/src/components/{EnumDeclaration.d.ts → enum/declaration.d.ts} +6 -11
  20. package/dist/src/components/enum/declaration.d.ts.map +1 -0
  21. package/dist/src/components/enum/declaration.js +54 -0
  22. package/dist/src/components/enum/declaration.ref.test.d.ts +2 -0
  23. package/dist/src/components/enum/declaration.ref.test.d.ts.map +1 -0
  24. package/dist/src/components/enum/declaration.ref.test.js +120 -0
  25. package/dist/src/components/enum/declaration.test.d.ts +2 -0
  26. package/dist/src/components/enum/declaration.test.d.ts.map +1 -0
  27. package/dist/src/components/enum/declaration.test.js +39 -0
  28. package/dist/src/components/enum/member.d.ts +7 -0
  29. package/dist/src/components/enum/member.d.ts.map +1 -0
  30. package/dist/src/components/enum/member.js +29 -0
  31. package/dist/src/components/enum/member.test.d.ts +2 -0
  32. package/dist/src/components/enum/member.test.d.ts.map +1 -0
  33. package/dist/src/components/enum/member.test.js +28 -0
  34. package/dist/src/components/field/field.d.ts.map +1 -1
  35. package/dist/src/components/field/field.js +9 -17
  36. package/dist/src/components/field/field.test.js +7 -7
  37. package/dist/src/components/index.d.ts +5 -2
  38. package/dist/src/components/index.d.ts.map +1 -1
  39. package/dist/src/components/index.js +5 -2
  40. package/dist/src/components/interface/declaration.d.ts.map +1 -1
  41. package/dist/src/components/interface/declaration.js +19 -21
  42. package/dist/src/components/interface/declaration.test.js +26 -35
  43. package/dist/src/components/interface/method.d.ts.map +1 -1
  44. package/dist/src/components/interface/method.js +7 -18
  45. package/dist/src/components/interface/method.test.js +38 -47
  46. package/dist/src/components/interface/property.d.ts.map +1 -1
  47. package/dist/src/components/interface/property.js +21 -39
  48. package/dist/src/components/interface/property.test.js +11 -11
  49. package/dist/src/components/lexical-scope.d.ts +8 -0
  50. package/dist/src/components/lexical-scope.d.ts.map +1 -0
  51. package/dist/src/components/lexical-scope.js +24 -0
  52. package/dist/src/components/method/method.d.ts +5 -2
  53. package/dist/src/components/method/method.d.ts.map +1 -1
  54. package/dist/src/components/method/method.js +7 -16
  55. package/dist/src/components/method/method.test.js +11 -11
  56. package/dist/src/components/method-scope.d.ts +8 -0
  57. package/dist/src/components/method-scope.d.ts.map +1 -0
  58. package/dist/src/components/method-scope.js +24 -0
  59. package/dist/src/components/namespace-scopes.d.ts +13 -0
  60. package/dist/src/components/namespace-scopes.d.ts.map +1 -0
  61. package/dist/src/components/namespace-scopes.js +44 -0
  62. package/dist/src/components/namespace.d.ts +7 -0
  63. package/dist/src/components/namespace.d.ts.map +1 -0
  64. package/dist/src/components/namespace.js +46 -0
  65. package/dist/src/components/namespace.ref.test.d.ts +2 -0
  66. package/dist/src/components/namespace.ref.test.d.ts.map +1 -0
  67. package/dist/src/components/namespace.ref.test.js +181 -0
  68. package/dist/src/components/namespace.test.d.ts.map +1 -0
  69. package/dist/src/components/namespace.test.js +78 -0
  70. package/dist/src/components/parameters/parameters.d.ts +2 -2
  71. package/dist/src/components/parameters/parameters.d.ts.map +1 -1
  72. package/dist/src/components/parameters/parameters.js +12 -14
  73. package/dist/src/components/parameters/parameters.test.d.ts +2 -0
  74. package/dist/src/components/parameters/parameters.test.d.ts.map +1 -0
  75. package/dist/src/components/parameters/parameters.test.js +87 -0
  76. package/dist/src/components/property/property.d.ts.map +1 -1
  77. package/dist/src/components/property/property.js +21 -39
  78. package/dist/src/components/property/property.test.js +14 -14
  79. package/dist/src/components/record/declaration.d.ts +18 -0
  80. package/dist/src/components/record/declaration.d.ts.map +1 -1
  81. package/dist/src/components/record/declaration.js +19 -13
  82. package/dist/src/components/record/declaration.test.js +50 -3
  83. package/dist/src/components/struct/declaration.d.ts.map +1 -1
  84. package/dist/src/components/struct/declaration.js +4 -6
  85. package/dist/src/components/struct/declaration.test.js +30 -39
  86. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -1
  87. package/dist/src/components/type-parameters/type-parameter.js +7 -10
  88. package/dist/src/components/type-parameters/type-parameters.test.js +3 -3
  89. package/dist/src/components/var/declaration.d.ts.map +1 -1
  90. package/dist/src/components/var/declaration.js +6 -8
  91. package/dist/src/components/var/declaration.test.js +11 -20
  92. package/dist/src/contexts/global-namespace.d.ts +5 -0
  93. package/dist/src/contexts/global-namespace.d.ts.map +1 -0
  94. package/dist/src/contexts/global-namespace.js +24 -0
  95. package/dist/src/contexts/namespace.d.ts +8 -0
  96. package/dist/src/contexts/namespace.d.ts.map +1 -0
  97. package/dist/src/contexts/namespace.js +5 -0
  98. package/dist/src/index.d.ts +1 -0
  99. package/dist/src/index.d.ts.map +1 -1
  100. package/dist/src/index.js +1 -0
  101. package/dist/src/modifiers.d.ts +11 -0
  102. package/dist/src/modifiers.d.ts.map +1 -1
  103. package/dist/src/scopes/class.d.ts +10 -0
  104. package/dist/src/scopes/class.d.ts.map +1 -0
  105. package/dist/src/scopes/class.js +10 -0
  106. package/dist/src/scopes/contexts.d.ts +9 -0
  107. package/dist/src/scopes/contexts.d.ts.map +1 -0
  108. package/dist/src/scopes/contexts.js +33 -0
  109. package/dist/src/scopes/csharp.d.ts +8 -0
  110. package/dist/src/scopes/csharp.d.ts.map +1 -0
  111. package/dist/src/scopes/csharp.js +11 -0
  112. package/dist/src/scopes/factories.d.ts +9 -0
  113. package/dist/src/scopes/factories.d.ts.map +1 -0
  114. package/dist/src/scopes/factories.js +23 -0
  115. package/dist/src/scopes/index.d.ts +10 -0
  116. package/dist/src/scopes/index.d.ts.map +1 -0
  117. package/dist/src/scopes/index.js +9 -0
  118. package/dist/src/scopes/lexical.d.ts +7 -0
  119. package/dist/src/scopes/lexical.d.ts.map +1 -0
  120. package/dist/src/scopes/lexical.js +7 -0
  121. package/dist/src/scopes/method.d.ts +9 -0
  122. package/dist/src/scopes/method.d.ts.map +1 -0
  123. package/dist/src/scopes/method.js +13 -0
  124. package/dist/src/scopes/named-type.d.ts +22 -0
  125. package/dist/src/scopes/named-type.d.ts.map +1 -0
  126. package/dist/src/scopes/named-type.js +32 -0
  127. package/dist/src/scopes/namespace.d.ts +11 -0
  128. package/dist/src/scopes/namespace.d.ts.map +1 -0
  129. package/dist/src/scopes/namespace.js +38 -0
  130. package/dist/src/scopes/source-file.d.ts +16 -0
  131. package/dist/src/scopes/source-file.d.ts.map +1 -0
  132. package/dist/src/scopes/source-file.js +43 -0
  133. package/dist/src/symbols/csharp.d.ts +76 -0
  134. package/dist/src/symbols/csharp.d.ts.map +1 -0
  135. package/dist/src/symbols/csharp.js +222 -0
  136. package/dist/src/symbols/factories.d.ts +25 -0
  137. package/dist/src/symbols/factories.d.ts.map +1 -0
  138. package/dist/src/symbols/factories.js +86 -0
  139. package/dist/src/symbols/index.d.ts +5 -2
  140. package/dist/src/symbols/index.d.ts.map +1 -1
  141. package/dist/src/symbols/index.js +6 -3
  142. package/dist/src/symbols/method.d.ts +13 -0
  143. package/dist/src/symbols/method.d.ts.map +1 -0
  144. package/dist/src/symbols/method.js +15 -0
  145. package/dist/src/symbols/named-type.d.ts +19 -0
  146. package/dist/src/symbols/named-type.d.ts.map +1 -0
  147. package/dist/src/symbols/named-type.js +30 -0
  148. package/dist/src/symbols/namespace.d.ts +22 -0
  149. package/dist/src/symbols/namespace.d.ts.map +1 -0
  150. package/dist/src/symbols/namespace.js +44 -0
  151. package/dist/src/symbols/reference.d.ts +2 -2
  152. package/dist/src/symbols/reference.d.ts.map +1 -1
  153. package/dist/src/symbols/reference.js +36 -43
  154. package/dist/test/project-directory.test.js +12 -16
  155. package/dist/test/sourcefile.test.js +7 -19
  156. package/dist/test/using.test.js +18 -16
  157. package/dist/test/utils.js +2 -2
  158. package/dist/tsconfig.tsbuildinfo +1 -1
  159. package/package.json +8 -4
  160. package/src/components/Declaration.tsx +3 -6
  161. package/src/components/Reference.tsx +3 -1
  162. package/src/components/SourceFile.tsx +68 -55
  163. package/src/components/UsingDirective.tsx +12 -2
  164. package/src/components/class/declaration.test.tsx +138 -143
  165. package/src/components/class/declaration.tsx +20 -33
  166. package/src/components/constructor/constructor.test.tsx +10 -16
  167. package/src/components/constructor/constructor.tsx +13 -32
  168. package/src/components/enum/declaration.ref.test.tsx +93 -0
  169. package/src/components/enum/declaration.test.tsx +34 -0
  170. package/src/components/enum/declaration.tsx +65 -0
  171. package/src/components/enum/member.test.tsx +24 -0
  172. package/src/components/enum/member.tsx +36 -0
  173. package/src/components/field/field.test.tsx +7 -7
  174. package/src/components/field/field.tsx +12 -22
  175. package/src/components/index.ts +5 -2
  176. package/src/components/interface/declaration.test.tsx +26 -32
  177. package/src/components/interface/declaration.tsx +16 -18
  178. package/src/components/interface/method.test.tsx +38 -44
  179. package/src/components/interface/method.tsx +7 -20
  180. package/src/components/interface/property.test.tsx +11 -11
  181. package/src/components/interface/property.tsx +15 -34
  182. package/src/components/lexical-scope.tsx +29 -0
  183. package/src/components/method/method.test.tsx +11 -11
  184. package/src/components/method/method.tsx +12 -23
  185. package/src/components/method-scope.tsx +27 -0
  186. package/src/components/namespace-scopes.tsx +44 -0
  187. package/src/components/namespace.ref.test.tsx +139 -0
  188. package/src/components/namespace.test.tsx +52 -0
  189. package/src/components/namespace.tsx +45 -0
  190. package/src/components/parameters/parameters.test.tsx +71 -0
  191. package/src/components/parameters/parameters.tsx +9 -21
  192. package/src/components/property/property.test.tsx +14 -14
  193. package/src/components/property/property.tsx +17 -41
  194. package/src/components/record/declaration.test.tsx +47 -3
  195. package/src/components/record/declaration.tsx +34 -11
  196. package/src/components/struct/declaration.test.tsx +16 -22
  197. package/src/components/struct/declaration.tsx +4 -6
  198. package/src/components/type-parameters/type-parameter.tsx +14 -11
  199. package/src/components/type-parameters/type-parameters.test.tsx +4 -4
  200. package/src/components/var/declaration.test.tsx +8 -14
  201. package/src/components/var/declaration.tsx +12 -6
  202. package/src/contexts/global-namespace.ts +29 -0
  203. package/src/contexts/namespace.ts +13 -0
  204. package/src/index.ts +1 -0
  205. package/src/modifiers.ts +14 -0
  206. package/src/scopes/class.ts +12 -0
  207. package/src/scopes/contexts.ts +45 -0
  208. package/src/scopes/csharp.ts +18 -0
  209. package/src/scopes/factories.ts +45 -0
  210. package/src/scopes/index.ts +9 -0
  211. package/src/scopes/lexical.ts +10 -0
  212. package/src/scopes/method.ts +22 -0
  213. package/src/scopes/named-type.ts +44 -0
  214. package/src/scopes/namespace.ts +59 -0
  215. package/src/scopes/source-file.ts +67 -0
  216. package/src/symbols/csharp.ts +307 -0
  217. package/src/symbols/factories.ts +199 -0
  218. package/src/symbols/index.ts +5 -2
  219. package/src/symbols/method.ts +26 -0
  220. package/src/symbols/named-type.ts +54 -0
  221. package/src/symbols/namespace.ts +62 -0
  222. package/src/symbols/reference.ts +47 -50
  223. package/temp/api.json +6152 -2151
  224. package/test/project-directory.test.tsx +12 -16
  225. package/test/sourcefile.test.tsx +7 -21
  226. package/test/using.test.tsx +18 -16
  227. package/test/utils.tsx +1 -1
  228. package/tsdoc-metadata.json +1 -1
  229. package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
  230. package/dist/src/components/EnumDeclaration.js +0 -85
  231. package/dist/src/components/Namespace.d.ts +0 -11
  232. package/dist/src/components/Namespace.d.ts.map +0 -1
  233. package/dist/src/components/Namespace.js +0 -33
  234. package/dist/src/symbols/csharp-output-symbol.d.ts +0 -8
  235. package/dist/src/symbols/csharp-output-symbol.d.ts.map +0 -1
  236. package/dist/src/symbols/csharp-output-symbol.js +0 -19
  237. package/dist/src/symbols/scopes.d.ts +0 -14
  238. package/dist/src/symbols/scopes.d.ts.map +0 -1
  239. package/dist/src/symbols/scopes.js +0 -31
  240. package/dist/test/enum.test.d.ts +0 -2
  241. package/dist/test/enum.test.d.ts.map +0 -1
  242. package/dist/test/enum.test.js +0 -178
  243. package/dist/test/namespace.test.d.ts.map +0 -1
  244. package/dist/test/namespace.test.js +0 -81
  245. package/src/components/EnumDeclaration.tsx +0 -99
  246. package/src/components/Namespace.tsx +0 -35
  247. package/src/symbols/csharp-output-symbol.ts +0 -22
  248. package/src/symbols/scopes.ts +0 -41
  249. package/test/enum.test.tsx +0 -149
  250. package/test/namespace.test.tsx +0 -55
  251. /package/dist/{test → src/components}/namespace.test.d.ts +0 -0
@@ -0,0 +1,62 @@
1
+ import { OutputSymbolOptions } from "@alloy-js/core";
2
+ import { NamedTypeSymbol } from "./named-type.js";
3
+
4
+ export interface NamespaceSymbolOptions extends OutputSymbolOptions {
5
+ isGlobal?: boolean;
6
+ }
7
+
8
+ /**
9
+ * A symbol for a namespace in C#.
10
+ */
11
+ export class NamespaceSymbol extends NamedTypeSymbol {
12
+ public readonly symbolKind = "namespace";
13
+ constructor(
14
+ name: string,
15
+ parentNamespace?: NamespaceSymbol,
16
+ options?: NamespaceSymbolOptions,
17
+ ) {
18
+ const space = parentNamespace?.members;
19
+
20
+ super(name, space, "namespace", options);
21
+
22
+ this.#isGlobal = !!options?.isGlobal;
23
+ }
24
+
25
+ #isGlobal: boolean;
26
+ /**
27
+ * Whether this symbol is the global namespace symbol.
28
+ */
29
+ get isGlobal() {
30
+ return this.#isGlobal;
31
+ }
32
+
33
+ getFullyQualifiedName(options: { omitGlobal?: boolean } = {}): string {
34
+ const parts = [];
35
+
36
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
37
+ let current: NamespaceSymbol | undefined = this;
38
+
39
+ while (current && !current.isGlobal) {
40
+ parts.unshift(current.name);
41
+ current = current.ownerSymbol as NamespaceSymbol | undefined;
42
+ }
43
+
44
+ const idPart = parts.join(".");
45
+
46
+ if (options.omitGlobal) {
47
+ return idPart;
48
+ } else {
49
+ return `global::${idPart}`;
50
+ }
51
+ }
52
+
53
+ copy() {
54
+ const options = this.getCopyOptions();
55
+ const copy = new NamespaceSymbol(this.name, undefined, {
56
+ ...options,
57
+ isGlobal: this.#isGlobal,
58
+ });
59
+ this.initializeCopy(copy);
60
+ return copy;
61
+ }
62
+ }
@@ -1,65 +1,62 @@
1
- import * as core from "@alloy-js/core";
2
- import { useNamespace } from "../components/Namespace.jsx";
3
- import { useSourceFile } from "../components/SourceFile.jsx";
4
- import { CSharpOutputSymbol } from "./csharp-output-symbol.js";
5
- import { CSharpOutputScope } from "./scopes.js";
6
-
7
- // when resolving references across source files, the last element
8
- // in pathDown will be the containing source file. we only need this
9
- // here so we can find and remove this scope as it's not useful
10
- // when building the reference
11
- interface SourceFileScope extends core.OutputScope {
12
- kind: "source-file";
13
- }
14
-
15
- type ReferenceScope = CSharpOutputScope | SourceFileScope;
1
+ import { memo, OutputSymbol, Refkey, resolve } from "@alloy-js/core";
2
+ import { CSharpScope } from "../scopes/csharp.js";
3
+ import { CSharpNamespaceScope } from "../scopes/namespace.js";
4
+ import { useSourceFileScope } from "../scopes/source-file.js";
5
+ import { CSharpSymbol } from "./csharp.js";
6
+ import { NamespaceSymbol } from "./namespace.js";
16
7
 
17
8
  // converts a refkey to its fully qualified name
18
9
  // e.g. if refkey is for bar in enum type foo, and
19
10
  // foo is in the same namespace as the refkey, then
20
11
  // the result would be foo.bar.
21
- export function ref(refkey: core.Refkey): () => string {
22
- const targetNamespaceCtx = useNamespace();
23
- const resolveResult = core.resolve<ReferenceScope, CSharpOutputSymbol>(
24
- refkey as core.Refkey,
25
- );
12
+ export function ref(refkey: Refkey): () => [string, OutputSymbol | undefined] {
13
+ const refSfScope = useSourceFileScope()!;
14
+ const resolveResult = resolve<CSharpScope, CSharpSymbol>(refkey as Refkey);
26
15
 
27
- return core.memo(() => {
16
+ return memo(() => {
28
17
  if (resolveResult.value === undefined) {
29
- return "<Unresolved Symbol>";
18
+ return ["<Unresolved Symbol>", undefined];
30
19
  }
31
20
 
32
- // targetDeclaration is the symbol with the refkey
33
- // pathDown is an array of scopes to that symbol and can be empty.
34
- // the entries are top-down, so namespace, source-file, member
35
- // - referencing a type within the same namespace will have an empty path
36
- // - referencing a member (e.g. enum value) within the same namespace will
37
- // have a single path entry that contains the owning type
38
- // - referencing a type within the same namespace but in a different source
39
- // file will have at least a source-file entry
40
- // - referencing a symbol outside the current namespace will have at least
41
- // two entries, namespace, source-file
42
- const { targetDeclaration, pathDown } = resolveResult.value;
21
+ const result = resolveResult.value;
22
+ const { commonScope, pathDown, memberPath } = result;
23
+ let { lexicalDeclaration } = result;
24
+
25
+ const parts = [];
26
+ if (!commonScope) {
27
+ // this shouldn't be possible in csharp.
28
+ return ["<Unresolved Symbol>", undefined];
29
+ }
43
30
 
44
- const sourceNamespace = pathDown.find((v) => {
45
- return v.kind === "namespace";
46
- });
47
- if (sourceNamespace && sourceNamespace.name !== targetNamespaceCtx!.name) {
48
- // the source symbol is in a different namespace that the target refkey.
49
- // add the applicable using statement to the target's source file.
50
- const targetSrc = useSourceFile();
51
- targetSrc!.addUsing(sourceNamespace.name);
31
+ if (
32
+ commonScope instanceof CSharpNamespaceScope &&
33
+ commonScope.ownerSymbol.isGlobal &&
34
+ lexicalDeclaration.symbolKind === "namespace" &&
35
+ memberPath.length > 0
36
+ ) {
37
+ // we need to using the namespace
38
+ let nsToUse: NamespaceSymbol;
39
+ while (
40
+ lexicalDeclaration.symbolKind === "namespace" &&
41
+ memberPath.length > 0
42
+ ) {
43
+ nsToUse = lexicalDeclaration as NamespaceSymbol;
44
+ lexicalDeclaration = memberPath.shift()!;
45
+ }
46
+
47
+ refSfScope.addUsing(nsToUse!);
52
48
  }
53
49
 
54
- // we only need to build the fully-qualified name for members
55
- // TODO: possibly a subset of members
56
- const syms = (pathDown as ReferenceScope[])
57
- .filter((v) => {
58
- return v.kind === "member";
59
- })
60
- .map((s) => s.owner!);
61
- syms.push(targetDeclaration);
50
+ for (const nsScope of pathDown) {
51
+ parts.push(nsScope.ownerSymbol!.name);
52
+ }
53
+
54
+ parts.push(lexicalDeclaration.name);
55
+
56
+ for (const member of memberPath) {
57
+ parts.push(member.name);
58
+ }
62
59
 
63
- return syms.map((sym) => sym.name).join(".");
60
+ return [parts.join("."), result.symbol];
64
61
  });
65
62
  }