@alloy-js/csharp 0.2.0 → 0.4.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alloy-js/csharp",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "change-case": "^5.4.4",
20
20
  "pathe": "^1.1.2",
21
- "@alloy-js/core": "~0.2.0"
21
+ "@alloy-js/core": "~0.4.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@babel/cli": "^7.24.7",
@@ -28,12 +28,9 @@
28
28
  "@rollup/plugin-typescript": "^11.1.6",
29
29
  "concurrently": "^8.2.2",
30
30
  "typescript": "^5.5.4",
31
- "vitest": "^2.0.5",
31
+ "vitest": "^3.0.4",
32
32
  "@alloy-js/babel-preset": "~0.1.1"
33
33
  },
34
- "overrides": {
35
- "esbuild": "0.23"
36
- },
37
34
  "type": "module",
38
35
  "scripts": {
39
36
  "build-src": "babel src -d dist/src --extensions .ts,.tsx",
@@ -49,18 +49,18 @@ export function SourceFile(props: SourceFileProps) {
49
49
  addUsing,
50
50
  };
51
51
 
52
- return <core.SourceFile path={props.path} filetype="cs" reference={Reference}>
52
+ return <core.SourceFile path={props.path} filetype="cs" reference={Reference} indent=" ">
53
53
  <SourceFileContext.Provider value={sourceFileCtx}>
54
54
  <core.Scope name={props.path} kind="source-file">
55
55
  {using.length > 0 ? (
56
56
  <>
57
- <UsingDirective namespaces={using} />{"\n"}
57
+ <UsingDirective namespaces={using} />{"\n\n"}
58
58
  </>
59
- ) : undefined}namespace {namespaceCtx.name}{!props.children && " {}"}{props.children &&
59
+ ) : undefined}namespace {namespaceCtx.name}{!props.children && " {}\n"}{props.children &&
60
60
  <>
61
61
  {"\n{"}
62
62
  {props.children}
63
- {"}"}
63
+ {"}\n"}
64
64
  </>
65
65
  }
66
66
  </core.Scope>
@@ -12,8 +12,9 @@ it("declares class with no members", () => {
12
12
  expect(res).toBe(coretest.d`
13
13
  namespace TestCode
14
14
  {
15
- public class TestClass;
15
+ public class TestClass;
16
16
  }
17
+
17
18
  `);
18
19
  });
19
20
 
@@ -28,12 +29,13 @@ it("declares class with some members", () => {
28
29
  expect(res).toBe(coretest.d`
29
30
  namespace TestCode
30
31
  {
31
- public class TestClass
32
- {
33
- public string MemberOne;
34
- private int memberTwo;
35
- }
32
+ public class TestClass
33
+ {
34
+ public string MemberOne;
35
+ private int memberTwo;
36
+ }
36
37
  }
38
+
37
39
  `);
38
40
  });
39
41
 
@@ -48,12 +50,13 @@ it("declares class with some methods", () => {
48
50
  expect(res).toBe(coretest.d`
49
51
  namespace TestCode
50
52
  {
51
- public class TestClass
52
- {
53
- public void MethodOne() {}
54
- private virtual void MethodTwo() {}
55
- }
53
+ public class TestClass
54
+ {
55
+ public void MethodOne() {}
56
+ private virtual void MethodTwo() {}
57
+ }
56
58
  }
59
+
57
60
  `);
58
61
  });
59
62
 
@@ -77,11 +80,12 @@ it("declares class with params and return type", () => {
77
80
  expect(res).toBe(coretest.d`
78
81
  namespace TestCode
79
82
  {
80
- public class TestClass
81
- {
82
- public string MethodOne(int intParam, string stringParam) {}
83
- }
83
+ public class TestClass
84
+ {
85
+ public string MethodOne(int intParam, string stringParam) {}
86
+ }
84
87
  }
88
+
85
89
  `);
86
90
  });
87
91
 
@@ -125,22 +129,23 @@ it("uses refkeys for members, params, and return type", () => {
125
129
  expect(res.contents[0].contents).toBe(coretest.d`
126
130
  namespace TestCode
127
131
  {
128
- public enum TestEnum
129
- {
130
- One,
131
- Two
132
- }
133
- public class TestInput;
134
- public class TestResult;
135
- public class TestClass
136
- {
137
- private TestEnum memberOne;
138
- public TestResult MethodOne(int intParam, TestInput bodyParam)
132
+ public enum TestEnum
139
133
  {
140
- return new TestResult();
134
+ One,
135
+ Two
136
+ }
137
+ public class TestInput;
138
+ public class TestResult;
139
+ public class TestClass
140
+ {
141
+ private TestEnum memberOne;
142
+ public TestResult MethodOne(int intParam, TestInput bodyParam)
143
+ {
144
+ return new TestResult();
145
+ }
141
146
  }
142
- }
143
147
  }
148
+
144
149
  `);
145
150
  });
146
151
 
@@ -160,12 +165,13 @@ it("declares class with generic parameters", () => {
160
165
  expect(res).toBe(coretest.d`
161
166
  namespace TestCode
162
167
  {
163
- public class TestClass<T, U>
164
- {
165
- public T MemberOne;
166
- private U memberTwo;
167
- }
168
+ public class TestClass<T, U>
169
+ {
170
+ public T MemberOne;
171
+ private U memberTwo;
172
+ }
168
173
  }
174
+
169
175
  `);
170
176
  });
171
177
 
@@ -191,11 +197,12 @@ it("declares class with constructor", () => {
191
197
  expect(res).toBe(coretest.d`
192
198
  namespace TestCode
193
199
  {
194
- public class TestClass
195
- {
196
- public TestClass() {}
197
- }
200
+ public class TestClass
201
+ {
202
+ public TestClass() {}
203
+ }
198
204
  }
205
+
199
206
  `);
200
207
  });
201
208
 
@@ -234,16 +241,17 @@ it("declares class with constructor params and assigns values to fields", () =>
234
241
  expect(res).toBe(coretest.d`
235
242
  namespace TestCode
236
243
  {
237
- public class TestClass
238
- {
239
- private string name;
240
- private int size;
241
- public TestClass(string name, int size)
244
+ public class TestClass
242
245
  {
243
- name = name;
244
- size = size;
246
+ private string name;
247
+ private int size;
248
+ public TestClass(string name, int size)
249
+ {
250
+ name = name;
251
+ size = size;
252
+ }
245
253
  }
246
- }
247
254
  }
255
+
248
256
  `);
249
257
  });
@@ -12,8 +12,9 @@ it("declares enum with no members", () => {
12
12
  expect(res).toBe(coretest.d`
13
13
  namespace TestCode
14
14
  {
15
- public enum TestEnum;
15
+ public enum TestEnum;
16
16
  }
17
+
17
18
  `);
18
19
  });
19
20
 
@@ -28,12 +29,13 @@ it("declares enum with members", () => {
28
29
  expect(res).toBe(coretest.d`
29
30
  namespace TestCode
30
31
  {
31
- public enum TestEnum
32
- {
33
- One,
34
- Two
35
- }
32
+ public enum TestEnum
33
+ {
34
+ One,
35
+ Two
36
+ }
36
37
  }
38
+
37
39
  `);
38
40
  });
39
41
 
@@ -48,12 +50,13 @@ it("applies naming policy to enum and members", () => {
48
50
  expect(res).toBe(coretest.d`
49
51
  namespace TestCode
50
52
  {
51
- public enum TestEnum
52
- {
53
- One,
54
- Two
55
- }
53
+ public enum TestEnum
54
+ {
55
+ One,
56
+ Two
57
+ }
56
58
  }
59
+
57
60
  `);
58
61
  });
59
62
 
@@ -79,14 +82,15 @@ it("can reference things by refkey", () => {
79
82
  expect(res.contents[0].contents).toBe(coretest.d`
80
83
  namespace TestCode
81
84
  {
82
- public enum TestEnum
83
- {
84
- One,
85
- Two
86
- }
87
- TestEnum;
88
- TestEnum.Two;
85
+ public enum TestEnum
86
+ {
87
+ One,
88
+ Two
89
+ }
90
+ TestEnum;
91
+ TestEnum.Two;
89
92
  }
93
+
90
94
  `);
91
95
  });
92
96
 
@@ -121,27 +125,29 @@ it("can reference things by refkey across files", () => {
121
125
  expect(res.contents[0].contents).toBe(coretest.d`
122
126
  namespace TestCode
123
127
  {
124
- public enum TestEnum
125
- {
126
- One,
127
- Two
128
- }
129
- OtherEnum;
130
- OtherEnum.Bar;
128
+ public enum TestEnum
129
+ {
130
+ One,
131
+ Two
132
+ }
133
+ OtherEnum;
134
+ OtherEnum.Bar;
131
135
  }
136
+
132
137
  `);
133
138
 
134
139
  expect(res.contents[1].path).toBe("Other.cs");
135
140
  expect(res.contents[1].contents).toBe(coretest.d`
136
141
  namespace TestCode
137
142
  {
138
- public enum OtherEnum
139
- {
140
- Foo,
141
- Bar
142
- }
143
- OtherEnum;
144
- OtherEnum.Bar;
143
+ public enum OtherEnum
144
+ {
145
+ Foo,
146
+ Bar
147
+ }
148
+ OtherEnum;
149
+ OtherEnum.Bar;
145
150
  }
151
+
146
152
  `);
147
153
  });
@@ -29,31 +29,35 @@ it("defines multiple namespaces and source files with unique content", () => {
29
29
  expect(res.contents[0].contents).toBe(coretest.d`
30
30
  namespace Namespace1
31
31
  {
32
- public class Model1;
32
+ public class Model1;
33
33
  }
34
+
34
35
  `);
35
36
 
36
37
  expect(res.contents[1].path).equals("Model2.cs");
37
38
  expect(res.contents[1].contents).toBe(coretest.d`
38
39
  namespace Namespace1
39
40
  {
40
- public class Model2;
41
+ public class Model2;
41
42
  }
43
+
42
44
  `);
43
45
 
44
46
  expect(res.contents[2].path).equals("Model3.cs");
45
47
  expect(res.contents[2].contents).toBe(coretest.d`
46
48
  namespace Namespace2
47
49
  {
48
- public class Model3;
50
+ public class Model3;
49
51
  }
52
+
50
53
  `);
51
54
 
52
55
  expect(res.contents[3].path).equals("Model4.cs");
53
56
  expect(res.contents[3].contents).toBe(coretest.d`
54
57
  namespace Namespace2
55
58
  {
56
- public class Model4;
59
+ public class Model4;
57
60
  }
61
+
58
62
  `);
59
63
  });
@@ -41,16 +41,18 @@ it("defines a project directory file with multiple source files", () => {
41
41
  expect(srcDir.contents[0].contents).toBe(coretest.d`
42
42
  namespace TestCode
43
43
  {
44
- public class TestClass1;
44
+ public class TestClass1;
45
45
  }
46
+
46
47
  `);
47
48
 
48
49
  expect(srcDir.contents[1].path).equals("~/projects/TestProject/src/Test2.cs");
49
50
  expect(srcDir.contents[1].contents).toBe(coretest.d`
50
51
  namespace TestCode
51
52
  {
52
- public class TestClass2;
53
+ public class TestClass2;
53
54
  }
55
+
54
56
  `);
55
57
  });
56
58
 
@@ -92,15 +94,17 @@ it("defines a project directory file with multiple source files and a custom TFM
92
94
  expect(srcDir.contents[0].contents).toBe(coretest.d`
93
95
  namespace TestCode
94
96
  {
95
- public class TestClass1;
97
+ public class TestClass1;
96
98
  }
99
+
97
100
  `);
98
101
 
99
102
  expect(srcDir.contents[1].path).equals("~/projects/TestProject/src/Test2.cs");
100
103
  expect(srcDir.contents[1].contents).toBe(coretest.d`
101
104
  namespace TestCode
102
105
  {
103
- public class TestClass2;
106
+ public class TestClass2;
104
107
  }
108
+
105
109
  `);
106
110
  });
@@ -21,16 +21,18 @@ it("defines multiple source files with unique content", () => {
21
21
  expect(res.contents[0].contents).toBe(coretest.d`
22
22
  namespace TestCode
23
23
  {
24
- public class TestClass1;
24
+ public class TestClass1;
25
25
  }
26
+
26
27
  `);
27
28
 
28
29
  expect(res.contents[1].path).equals("Test2.cs");
29
30
  expect(res.contents[1].contents).toBe(coretest.d`
30
31
  namespace TestCode
31
32
  {
32
- public class TestClass2;
33
+ public class TestClass2;
33
34
  }
35
+
34
36
  `);
35
37
  });
36
38
 
@@ -14,7 +14,9 @@ it("uses a single namespace", () => {
14
14
 
15
15
  expect(res.contents[0].contents).toBe(coretest.d`
16
16
  using Foo;
17
+
17
18
  namespace TestCode {}
19
+
18
20
  `);
19
21
  });
20
22
 
@@ -30,7 +32,9 @@ it("uses multiple namespaces", () => {
30
32
  expect(res.contents[0].contents).toBe(coretest.d`
31
33
  using Bar.Baz;
32
34
  using Foo;
35
+
33
36
  namespace TestCode {}
37
+
34
38
  `);
35
39
  });
36
40
 
@@ -72,26 +76,29 @@ it("adds using statement across namespaces", () => {
72
76
  expect(res.contents[0].contents).toBe(coretest.d`
73
77
  namespace Models
74
78
  {
75
- public class Input;
76
- public class Output;
77
- public enum TestEnum
78
- {
79
- One,
80
- Two
81
- }
79
+ public class Input;
80
+ public class Output;
81
+ public enum TestEnum
82
+ {
83
+ One,
84
+ Two
85
+ }
82
86
  }
87
+
83
88
  `);
84
89
 
85
90
  expect(res.contents[1].contents).toBe(coretest.d`
86
91
  using Models;
87
92
  using System;
93
+
88
94
  namespace Client
89
95
  {
90
- public class Client
91
- {
92
- public Output MethodOne(Input bodyParam) {}
93
- }
94
- TestEnum.Two;
96
+ public class Client
97
+ {
98
+ public Output MethodOne(Input bodyParam) {}
99
+ }
100
+ TestEnum.Two;
95
101
  }
102
+
96
103
  `);
97
104
  });