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

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 (73) hide show
  1. package/dist/src/components/SourceFile.d.ts +5 -0
  2. package/dist/src/components/SourceFile.d.ts.map +1 -1
  3. package/dist/src/components/SourceFile.js +18 -58
  4. package/dist/src/components/SourceFile.js.map +1 -1
  5. package/dist/src/components/access-expression/access-expression.d.ts +54 -0
  6. package/dist/src/components/access-expression/access-expression.d.ts.map +1 -0
  7. package/dist/src/components/access-expression/access-expression.js +277 -0
  8. package/dist/src/components/access-expression/access-expression.js.map +1 -0
  9. package/dist/src/components/access-expression/access-expression.test.d.ts +2 -0
  10. package/dist/src/components/access-expression/access-expression.test.d.ts.map +1 -0
  11. package/dist/src/components/access-expression/access-expression.test.js +336 -0
  12. package/dist/src/components/access-expression/access-expression.test.js.map +1 -0
  13. package/dist/src/components/access-expression/part-descriptors.d.ts +32 -0
  14. package/dist/src/components/access-expression/part-descriptors.d.ts.map +1 -0
  15. package/dist/src/components/access-expression/part-descriptors.js +99 -0
  16. package/dist/src/components/access-expression/part-descriptors.js.map +1 -0
  17. package/dist/src/components/class/declaration.d.ts.map +1 -1
  18. package/dist/src/components/class/declaration.js.map +1 -1
  19. package/dist/src/components/index.d.ts +1 -0
  20. package/dist/src/components/index.d.ts.map +1 -1
  21. package/dist/src/components/index.js +1 -0
  22. package/dist/src/components/index.js.map +1 -1
  23. package/dist/src/components/invocation-expression/invocation-expression.d.ts +29 -0
  24. package/dist/src/components/invocation-expression/invocation-expression.d.ts.map +1 -0
  25. package/dist/src/components/invocation-expression/invocation-expression.js +70 -0
  26. package/dist/src/components/invocation-expression/invocation-expression.js.map +1 -0
  27. package/dist/src/components/invocation-expression/invocation-expression.test.d.ts +2 -0
  28. package/dist/src/components/invocation-expression/invocation-expression.test.d.ts.map +1 -0
  29. package/dist/src/components/invocation-expression/invocation-expression.test.js +105 -0
  30. package/dist/src/components/invocation-expression/invocation-expression.test.js.map +1 -0
  31. package/dist/src/components/parameters/parameters.d.ts +1 -2
  32. package/dist/src/components/parameters/parameters.d.ts.map +1 -1
  33. package/dist/src/components/parameters/parameters.js +2 -1
  34. package/dist/src/components/parameters/parameters.js.map +1 -1
  35. package/dist/src/components/parameters/parameters.test.js +66 -0
  36. package/dist/src/components/parameters/parameters.test.js.map +1 -1
  37. package/dist/src/components/property/property.d.ts +2 -2
  38. package/dist/src/components/property/property.d.ts.map +1 -1
  39. package/dist/src/components/property/property.js +10 -3
  40. package/dist/src/components/property/property.js.map +1 -1
  41. package/dist/src/scopes/csharp.d.ts +2 -0
  42. package/dist/src/scopes/csharp.d.ts.map +1 -1
  43. package/dist/src/scopes/csharp.js +3 -0
  44. package/dist/src/scopes/csharp.js.map +1 -1
  45. package/dist/src/symbols/csharp.d.ts +11 -0
  46. package/dist/src/symbols/csharp.d.ts.map +1 -1
  47. package/dist/src/symbols/csharp.js +23 -0
  48. package/dist/src/symbols/csharp.js.map +1 -1
  49. package/dist/src/symbols/factories.d.ts.map +1 -1
  50. package/dist/src/symbols/factories.js +12 -6
  51. package/dist/src/symbols/factories.js.map +1 -1
  52. package/dist/src/symbols/reference.d.ts +2 -2
  53. package/dist/src/symbols/reference.d.ts.map +1 -1
  54. package/dist/src/symbols/reference.js +17 -5
  55. package/dist/src/symbols/reference.js.map +1 -1
  56. package/dist/tsconfig.tsbuildinfo +1 -1
  57. package/package.json +2 -2
  58. package/src/components/SourceFile.tsx +27 -30
  59. package/src/components/access-expression/access-expression.test.tsx +284 -0
  60. package/src/components/access-expression/access-expression.tsx +375 -0
  61. package/src/components/access-expression/part-descriptors.ts +175 -0
  62. package/src/components/class/declaration.tsx +1 -0
  63. package/src/components/index.ts +1 -0
  64. package/src/components/invocation-expression/invocation-expression.test.tsx +101 -0
  65. package/src/components/invocation-expression/invocation-expression.tsx +60 -0
  66. package/src/components/parameters/parameters.test.tsx +46 -0
  67. package/src/components/parameters/parameters.tsx +2 -2
  68. package/src/components/property/property.tsx +8 -2
  69. package/src/scopes/csharp.ts +5 -0
  70. package/src/symbols/csharp.ts +32 -0
  71. package/src/symbols/factories.ts +31 -15
  72. package/src/symbols/{reference.ts → reference.tsx} +11 -9
  73. package/temp/api.json +271 -36
@@ -1,23 +1,27 @@
1
1
  import {
2
+ Block,
2
3
  Children,
3
4
  computed,
4
5
  SourceFile as CoreSourceFile,
5
6
  Scope,
6
- Show,
7
7
  useBinder,
8
8
  } from "@alloy-js/core";
9
9
  import { getGlobalNamespace } from "../contexts/global-namespace.js";
10
10
  import { useNamespaceContext } from "../contexts/namespace.js";
11
11
  import { CSharpSourceFileScope } from "../scopes/source-file.js";
12
12
  import { NamespaceSymbol } from "../symbols/namespace.js";
13
- import { NamespaceScope, NamespaceScopes } from "./namespace-scopes.jsx";
13
+ import { NamespaceScopes } from "./namespace-scopes.jsx";
14
14
  import { Reference } from "./Reference.jsx";
15
15
  import { UsingDirective } from "./UsingDirective.jsx";
16
16
 
17
+ /**
18
+ * Props for {@link SourceFile} component
19
+ */
17
20
  export interface SourceFileProps {
18
21
  /** Path of the source file */
19
22
  path: string;
20
23
 
24
+ /** Source file content */
21
25
  children?: Children;
22
26
 
23
27
  /**
@@ -27,8 +31,7 @@ export interface SourceFileProps {
27
31
  using?: string[];
28
32
  }
29
33
 
30
- // a C# source file. exists within the context of a namespace
31
- // contains using statements and declarations
34
+ /** A C# source file exists within the context of a namespace contains using statements and declarations */
32
35
  export function SourceFile(props: SourceFileProps) {
33
36
  const sourceFileScope = new CSharpSourceFileScope(props.path);
34
37
 
@@ -41,6 +44,10 @@ export function SourceFile(props: SourceFileProps) {
41
44
  Array.from(sourceFileScope.usings) as (NamespaceSymbol | string)[]
42
45
  ).concat(props.using ?? []);
43
46
  });
47
+
48
+ const content = computed(() => (
49
+ <NamespaceScopes symbol={nsSymbol}>{props.children}</NamespaceScopes>
50
+ ));
44
51
  return (
45
52
  <CoreSourceFile
46
53
  path={props.path}
@@ -58,33 +65,23 @@ export function SourceFile(props: SourceFileProps) {
58
65
  <hbr />
59
66
  </>
60
67
  )}
61
- <Show when={!!nsContext && nsSymbol !== globalNs}>
62
- <Show when={sourceFileScope.hasBlockNamespace}>
68
+ {nsSymbol === globalNs ?
69
+ content
70
+ : <>
63
71
  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>
72
+ {sourceFileScope.hasBlockNamespace ?
73
+ <>
74
+ {" "}
75
+ <Block>{content}</Block>
76
+ </>
77
+ : <>
78
+ ;<hbr />
79
+ <hbr />
80
+ {content}
81
+ </>
82
+ }
83
+ </>
84
+ }
88
85
  </Scope>
89
86
  </CoreSourceFile>
90
87
  );
@@ -0,0 +1,284 @@
1
+ import { ClassDeclaration } from "#components/class/declaration.jsx";
2
+ import { Method } from "#components/method/method.jsx";
3
+ import { TestNamespace } from "#test/utils.jsx";
4
+ import { List, namekey, printTree, renderTree } from "@alloy-js/core";
5
+ import { describe, expect, it } from "vitest";
6
+ import { CSharpSymbol } from "../../symbols/csharp.js";
7
+ import { AccessExpression } from "./access-expression.jsx";
8
+
9
+ it("makes a member access expression", () => {
10
+ const template = (
11
+ <AccessExpression>
12
+ <AccessExpression.Part id="Foo" />
13
+ <AccessExpression.Part id="Bar" />
14
+ </AccessExpression>
15
+ );
16
+ expect(template).toRenderTo(`Foo.Bar`);
17
+ });
18
+
19
+ it("makes an element access expression", () => {
20
+ const template = (
21
+ <AccessExpression>
22
+ <AccessExpression.Part id="Foo" />
23
+ <AccessExpression.Part index={1} />
24
+ </AccessExpression>
25
+ );
26
+ expect(template).toRenderTo(`Foo[1]`);
27
+ });
28
+
29
+ it("makes a call expression", () => {
30
+ const template = (
31
+ <AccessExpression>
32
+ <AccessExpression.Part id="Foo" />
33
+ <AccessExpression.Part args={[1, 2, 3]} />
34
+ </AccessExpression>
35
+ );
36
+ expect(template).toRenderTo(`Foo(1, 2, 3)`);
37
+ });
38
+
39
+ it("makes an id part from a symbol", () => {
40
+ const symbol = new CSharpSymbol("Symbol", undefined);
41
+ const template = (
42
+ <AccessExpression>
43
+ <AccessExpression.Part id="Foo" />
44
+ <AccessExpression.Part symbol={symbol} />
45
+ </AccessExpression>
46
+ );
47
+ expect(template).toRenderTo(`Foo.Symbol`);
48
+ });
49
+
50
+ it("makes an id part from a symbol reactively", () => {
51
+ const symbol = new CSharpSymbol("Symbol", undefined);
52
+ const tree = renderTree(
53
+ <AccessExpression>
54
+ <AccessExpression.Part id="Foo" />
55
+ <AccessExpression.Part symbol={symbol} />
56
+ </AccessExpression>,
57
+ );
58
+ expect(printTree(tree)).toEqual("Foo.Symbol");
59
+ symbol.name = "Bar";
60
+ expect(printTree(tree)).toEqual("Foo.Bar");
61
+ });
62
+
63
+ it("makes an id part from refkey, where the first part is a full reference, and subsequent parts are just the id", () => {
64
+ const methodKey = namekey("method");
65
+ const template = (
66
+ <TestNamespace>
67
+ <List>
68
+ <ClassDeclaration name="MyClass">
69
+ <Method name={methodKey} />
70
+ </ClassDeclaration>
71
+ <AccessExpression>
72
+ <AccessExpression.Part refkey={methodKey} />
73
+ <AccessExpression.Part refkey={methodKey} />
74
+ </AccessExpression>
75
+ </List>
76
+ </TestNamespace>
77
+ );
78
+
79
+ expect(template).toRenderTo(`
80
+ class MyClass
81
+ {
82
+ void Method() {}
83
+ }
84
+ MyClass.Method.Method
85
+ `);
86
+ });
87
+
88
+ it("takes type args", () => {
89
+ const template = (
90
+ <AccessExpression>
91
+ <AccessExpression.Part id="Foo" typeArgs={["Foo", "Bar"]} />
92
+ </AccessExpression>
93
+ );
94
+ expect(template).toRenderTo(`Foo<Foo, Bar>`);
95
+ });
96
+
97
+ it("takes multiple indexer arguments", () => {
98
+ const template = (
99
+ <AccessExpression>
100
+ <AccessExpression.Part id="Foo" />
101
+ <AccessExpression.Part indexerArgs={["arg1", "arg2"]} />
102
+ </AccessExpression>
103
+ );
104
+ expect(template).toRenderTo(`Foo[arg1, arg2]`);
105
+ });
106
+
107
+ it("allows nullable member access", () => {
108
+ const template = (
109
+ <AccessExpression>
110
+ <AccessExpression.Part id="Foo" nullable />
111
+ <AccessExpression.Part id="Bar" />
112
+ </AccessExpression>
113
+ );
114
+ expect(template).toRenderTo(`Foo?.Bar`);
115
+ });
116
+
117
+ it("allows conditional member access", () => {
118
+ const template = (
119
+ <AccessExpression>
120
+ <AccessExpression.Part id="Foo" />
121
+ <AccessExpression.Part id="Bar" conditional />
122
+ </AccessExpression>
123
+ );
124
+ expect(template).toRenderTo(`Foo?.Bar`);
125
+ });
126
+
127
+ it("allows nullable element access", () => {
128
+ const template = (
129
+ <AccessExpression>
130
+ <AccessExpression.Part id="Foo" nullable />
131
+ <AccessExpression.Part index={1} />
132
+ </AccessExpression>
133
+ );
134
+ expect(template).toRenderTo(`Foo?[1]`);
135
+ });
136
+
137
+ it("allows conditional element access", () => {
138
+ const template = (
139
+ <AccessExpression>
140
+ <AccessExpression.Part id="Foo" />
141
+ <AccessExpression.Part index={1} conditional />
142
+ </AccessExpression>
143
+ );
144
+ expect(template).toRenderTo(`Foo?[1]`);
145
+ });
146
+
147
+ it("uses symbol information for nullability", () => {
148
+ const symbol = new CSharpSymbol("Symbol", undefined, { isNullable: true });
149
+
150
+ const typeSymbol = new CSharpSymbol("SomeType", undefined, {
151
+ isNullable: true,
152
+ });
153
+
154
+ const typedSymbol = new CSharpSymbol("SomeValue", undefined, {
155
+ type: typeSymbol,
156
+ });
157
+
158
+ const template = (
159
+ <AccessExpression>
160
+ <AccessExpression.Part symbol={symbol} />
161
+ <AccessExpression.Part symbol={typedSymbol} />
162
+ <AccessExpression.Part id="Foo" />
163
+ </AccessExpression>
164
+ );
165
+ expect(template).toRenderTo(`Symbol?.SomeValue?.Foo`);
166
+ });
167
+
168
+ describe("formatting", () => {
169
+ it("breaks long identifier chains", () => {
170
+ const template = (
171
+ <AccessExpression>
172
+ <AccessExpression.Part id="Foo" />
173
+ <AccessExpression.Part id="Foo" />
174
+ <AccessExpression.Part id="Foo" />
175
+ <AccessExpression.Part id="Foo" />
176
+ <AccessExpression.Part id="Foo" />
177
+ <AccessExpression.Part id="Foo" />
178
+ </AccessExpression>
179
+ );
180
+ expect(template).toRenderTo(
181
+ `
182
+ Foo.Foo
183
+ .Foo.Foo
184
+ .Foo.Foo
185
+ `,
186
+ { printWidth: 10 },
187
+ );
188
+ });
189
+ it("breaks long call expressions", () => {
190
+ const template = (
191
+ <AccessExpression>
192
+ <AccessExpression.Part id="Foo" />
193
+ <AccessExpression.Part id="Bar" />
194
+ <AccessExpression.Part args={["variable1", "variable2", "variable3"]} />
195
+ </AccessExpression>
196
+ );
197
+ expect(template).toRenderTo(
198
+ `
199
+ Foo.Bar(
200
+ variable1,
201
+ variable2,
202
+ variable3
203
+ )
204
+ `,
205
+ { printWidth: 10 },
206
+ );
207
+ });
208
+
209
+ it("breaks long type args", () => {
210
+ const template = (
211
+ <AccessExpression>
212
+ <AccessExpression.Part
213
+ id="Foo"
214
+ typeArgs={["Foo", "Bar", "Baz", "Qux"]}
215
+ />
216
+ </AccessExpression>
217
+ );
218
+ expect(template).toRenderTo(
219
+ `
220
+ Foo<
221
+ Foo,
222
+ Bar,
223
+ Baz,
224
+ Qux
225
+ >
226
+ `,
227
+ { printWidth: 10 },
228
+ );
229
+ });
230
+
231
+ it("breaks long type args for second member", () => {
232
+ const template = (
233
+ <AccessExpression>
234
+ <AccessExpression.Part id="Foo" />
235
+ <AccessExpression.Part
236
+ id="Bar"
237
+ typeArgs={["Foo", "Bar", "Baz", "Qux"]}
238
+ />
239
+ </AccessExpression>
240
+ );
241
+ expect(template).toRenderTo(
242
+ `
243
+ Foo
244
+ .Bar<
245
+ Foo,
246
+ Bar,
247
+ Baz,
248
+ Qux
249
+ >
250
+ `,
251
+ { printWidth: 10 },
252
+ );
253
+ });
254
+
255
+ it("formats builder pattern", () => {
256
+ const template = (
257
+ <AccessExpression>
258
+ <AccessExpression.Part id="Foo" />
259
+ <AccessExpression.Part id="Bar" />
260
+ <AccessExpression.Part id="Baz" />
261
+ <AccessExpression.Part args />
262
+ <AccessExpression.Part id="Qux" />
263
+ <AccessExpression.Part id="Quux" typeArgs={["TTypeOne", "TTypeTwo"]} />
264
+ <AccessExpression.Part indexerArgs={["arg1", "arg2"]} />
265
+ <AccessExpression.Part args />
266
+ </AccessExpression>
267
+ );
268
+ expect(template).toRenderTo(
269
+ `
270
+ Foo.Bar
271
+ .Baz()
272
+ .Qux
273
+ .Quux<
274
+ TTypeOne,
275
+ TTypeTwo
276
+ >[
277
+ arg1,
278
+ arg2
279
+ ]()
280
+ `,
281
+ { printWidth: 10 },
282
+ );
283
+ });
284
+ });