@alloy-js/csharp 0.18.0-dev.17 → 0.18.0-dev.18

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 (49) hide show
  1. package/dist/src/components/ClassDeclaration.d.ts +14 -1
  2. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  3. package/dist/src/components/ClassDeclaration.js +12 -25
  4. package/dist/src/components/ClassMethod.d.ts +14 -0
  5. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  6. package/dist/src/components/ClassMethod.js +11 -1
  7. package/dist/src/components/index.d.ts +1 -0
  8. package/dist/src/components/index.d.ts.map +1 -1
  9. package/dist/src/components/index.js +2 -1
  10. package/dist/src/components/interface/declaration.d.ts +14 -1
  11. package/dist/src/components/interface/declaration.d.ts.map +1 -1
  12. package/dist/src/components/interface/declaration.js +12 -25
  13. package/dist/src/components/interface/declaration.test.js +84 -0
  14. package/dist/src/components/interface/method.d.ts +14 -0
  15. package/dist/src/components/interface/method.d.ts.map +1 -1
  16. package/dist/src/components/interface/method.js +11 -1
  17. package/dist/src/components/interface/method.test.js +79 -0
  18. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +8 -0
  19. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +1 -0
  20. package/dist/src/components/type-parameters/type-parameter-constraints.js +44 -0
  21. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +2 -0
  22. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +1 -0
  23. package/dist/src/components/type-parameters/type-parameter-constraints.test.js +67 -0
  24. package/dist/src/components/type-parameters/type-parameter.d.ts +20 -0
  25. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -0
  26. package/dist/src/components/type-parameters/type-parameter.js +22 -0
  27. package/dist/src/components/type-parameters/type-parameters.d.ts +17 -0
  28. package/dist/src/components/type-parameters/type-parameters.d.ts.map +1 -0
  29. package/dist/src/components/type-parameters/type-parameters.js +65 -0
  30. package/dist/src/components/type-parameters/type-parameters.test.d.ts +2 -0
  31. package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +1 -0
  32. package/dist/src/components/type-parameters/type-parameters.test.js +26 -0
  33. package/dist/test/class-declaration.test.js +79 -33
  34. package/dist/tsconfig.tsbuildinfo +1 -1
  35. package/package.json +1 -1
  36. package/src/components/ClassDeclaration.tsx +23 -27
  37. package/src/components/ClassMethod.tsx +25 -1
  38. package/src/components/index.ts +1 -0
  39. package/src/components/interface/declaration.test.tsx +87 -0
  40. package/src/components/interface/declaration.tsx +23 -27
  41. package/src/components/interface/method.test.tsx +78 -0
  42. package/src/components/interface/method.tsx +24 -1
  43. package/src/components/type-parameters/type-parameter-constraints.test.tsx +93 -0
  44. package/src/components/type-parameters/type-parameter-constraints.tsx +46 -0
  45. package/src/components/type-parameters/type-parameter.tsx +35 -0
  46. package/src/components/type-parameters/type-parameters.test.tsx +19 -0
  47. package/src/components/type-parameters/type-parameters.tsx +72 -0
  48. package/temp/api.json +211 -22
  49. package/test/class-declaration.test.tsx +75 -25
package/temp/api.json CHANGED
@@ -777,29 +777,24 @@
777
777
  {
778
778
  "kind": "PropertySignature",
779
779
  "canonicalReference": "@alloy-js/csharp!ClassDeclarationProps#typeParameters:member",
780
- "docComment": "",
780
+ "docComment": "/**\n * Type parameters for the class\n *\n * @example\n * ```tsx\n * <ClassDeclaration name=\"MyClass\" typeParameters={[\"T\"]} />\n * ```\n *\n * This will produce:\n * ```csharp\n * public class MyClass<T>\n * ```\n *\n */\n",
781
781
  "excerptTokens": [
782
782
  {
783
783
  "kind": "Content",
784
784
  "text": "typeParameters?: "
785
785
  },
786
- {
787
- "kind": "Reference",
788
- "text": "Record",
789
- "canonicalReference": "!Record:type"
790
- },
791
786
  {
792
787
  "kind": "Content",
793
- "text": "<string, "
788
+ "text": "(string | "
794
789
  },
795
790
  {
796
791
  "kind": "Reference",
797
- "text": "core.Refkey",
798
- "canonicalReference": "@alloy-js/core!Refkey:type"
792
+ "text": "TypeParameterProps",
793
+ "canonicalReference": "@alloy-js/csharp!TypeParameterProps:interface"
799
794
  },
800
795
  {
801
796
  "kind": "Content",
802
- "text": ">"
797
+ "text": ")[]"
803
798
  },
804
799
  {
805
800
  "kind": "Content",
@@ -812,7 +807,7 @@
812
807
  "name": "typeParameters",
813
808
  "propertyTypeTokenRange": {
814
809
  "startIndex": 1,
815
- "endIndex": 5
810
+ "endIndex": 4
816
811
  }
817
812
  }
818
813
  ],
@@ -1433,6 +1428,42 @@
1433
1428
  "startIndex": 1,
1434
1429
  "endIndex": 2
1435
1430
  }
1431
+ },
1432
+ {
1433
+ "kind": "PropertySignature",
1434
+ "canonicalReference": "@alloy-js/csharp!ClassMethodProps#typeParameters:member",
1435
+ "docComment": "/**\n * Type parameters for the method\n *\n * @example\n * ```tsx\n * <InterfaceMethod name=\"Test\" typeParameters={[\"T\"]} />\n * ```\n *\n * This will produce:\n * ```csharp\n * public void Test<T>()\n * ```\n *\n */\n",
1436
+ "excerptTokens": [
1437
+ {
1438
+ "kind": "Content",
1439
+ "text": "typeParameters?: "
1440
+ },
1441
+ {
1442
+ "kind": "Content",
1443
+ "text": "("
1444
+ },
1445
+ {
1446
+ "kind": "Reference",
1447
+ "text": "TypeParameterProps",
1448
+ "canonicalReference": "@alloy-js/csharp!TypeParameterProps:interface"
1449
+ },
1450
+ {
1451
+ "kind": "Content",
1452
+ "text": " | string)[]"
1453
+ },
1454
+ {
1455
+ "kind": "Content",
1456
+ "text": ";"
1457
+ }
1458
+ ],
1459
+ "isReadonly": false,
1460
+ "isOptional": true,
1461
+ "releaseTag": "Public",
1462
+ "name": "typeParameters",
1463
+ "propertyTypeTokenRange": {
1464
+ "startIndex": 1,
1465
+ "endIndex": 4
1466
+ }
1436
1467
  }
1437
1468
  ],
1438
1469
  "extendsTokenRanges": [
@@ -4525,29 +4556,24 @@
4525
4556
  {
4526
4557
  "kind": "PropertySignature",
4527
4558
  "canonicalReference": "@alloy-js/csharp!InterfaceDeclarationProps#typeParameters:member",
4528
- "docComment": "",
4559
+ "docComment": "/**\n * Type parameters for the interface\n *\n * @example\n * ```tsx\n * <InterfaceDeclaration name=\"IList\" typeParameters={[\"T\"]} />\n * ```\n *\n * This will produce:\n * ```csharp\n * public interface IList<T>\n * ```\n *\n */\n",
4529
4560
  "excerptTokens": [
4530
4561
  {
4531
4562
  "kind": "Content",
4532
4563
  "text": "typeParameters?: "
4533
4564
  },
4534
- {
4535
- "kind": "Reference",
4536
- "text": "Record",
4537
- "canonicalReference": "!Record:type"
4538
- },
4539
4565
  {
4540
4566
  "kind": "Content",
4541
- "text": "<string, "
4567
+ "text": "("
4542
4568
  },
4543
4569
  {
4544
4570
  "kind": "Reference",
4545
- "text": "core.Refkey",
4546
- "canonicalReference": "@alloy-js/core!Refkey:type"
4571
+ "text": "TypeParameterProps",
4572
+ "canonicalReference": "@alloy-js/csharp!TypeParameterProps:interface"
4547
4573
  },
4548
4574
  {
4549
4575
  "kind": "Content",
4550
- "text": ">"
4576
+ "text": " | string)[]"
4551
4577
  },
4552
4578
  {
4553
4579
  "kind": "Content",
@@ -4560,7 +4586,7 @@
4560
4586
  "name": "typeParameters",
4561
4587
  "propertyTypeTokenRange": {
4562
4588
  "startIndex": 1,
4563
- "endIndex": 5
4589
+ "endIndex": 4
4564
4590
  }
4565
4591
  }
4566
4592
  ],
@@ -4883,6 +4909,42 @@
4883
4909
  "startIndex": 1,
4884
4910
  "endIndex": 2
4885
4911
  }
4912
+ },
4913
+ {
4914
+ "kind": "PropertySignature",
4915
+ "canonicalReference": "@alloy-js/csharp!InterfaceMethodProps#typeParameters:member",
4916
+ "docComment": "/**\n * Type parameters for the method\n *\n * @example\n * ```tsx\n * <InterfaceMethod name=\"Test\" typeParameters={[\"T\"]} />\n * ```\n *\n * This will produce:\n * ```csharp\n * public void Test<T>()\n * ```\n *\n */\n",
4917
+ "excerptTokens": [
4918
+ {
4919
+ "kind": "Content",
4920
+ "text": "typeParameters?: "
4921
+ },
4922
+ {
4923
+ "kind": "Content",
4924
+ "text": "("
4925
+ },
4926
+ {
4927
+ "kind": "Reference",
4928
+ "text": "TypeParameterProps",
4929
+ "canonicalReference": "@alloy-js/csharp!TypeParameterProps:interface"
4930
+ },
4931
+ {
4932
+ "kind": "Content",
4933
+ "text": " | string)[]"
4934
+ },
4935
+ {
4936
+ "kind": "Content",
4937
+ "text": ";"
4938
+ }
4939
+ ],
4940
+ "isReadonly": false,
4941
+ "isOptional": true,
4942
+ "releaseTag": "Public",
4943
+ "name": "typeParameters",
4944
+ "propertyTypeTokenRange": {
4945
+ "startIndex": 1,
4946
+ "endIndex": 4
4947
+ }
4886
4948
  }
4887
4949
  ],
4888
4950
  "extendsTokenRanges": [
@@ -7437,6 +7499,133 @@
7437
7499
  ],
7438
7500
  "extendsTokenRanges": []
7439
7501
  },
7502
+ {
7503
+ "kind": "Interface",
7504
+ "canonicalReference": "@alloy-js/csharp!TypeParameterProps:interface",
7505
+ "docComment": "/**\n * Information for a TypeScript generic type parameter.\n */\n",
7506
+ "excerptTokens": [
7507
+ {
7508
+ "kind": "Content",
7509
+ "text": "export interface TypeParameterProps "
7510
+ }
7511
+ ],
7512
+ "fileUrlPath": "src/components/type-parameters/type-parameter.tsx",
7513
+ "releaseTag": "Public",
7514
+ "name": "TypeParameterProps",
7515
+ "preserveMemberOrder": false,
7516
+ "members": [
7517
+ {
7518
+ "kind": "PropertySignature",
7519
+ "canonicalReference": "@alloy-js/csharp!TypeParameterProps#constraints:member",
7520
+ "docComment": "/**\n * The parameter constraint\n */\n",
7521
+ "excerptTokens": [
7522
+ {
7523
+ "kind": "Content",
7524
+ "text": "readonly constraints?: "
7525
+ },
7526
+ {
7527
+ "kind": "Reference",
7528
+ "text": "Children",
7529
+ "canonicalReference": "@alloy-js/core!Children:type"
7530
+ },
7531
+ {
7532
+ "kind": "Content",
7533
+ "text": " | "
7534
+ },
7535
+ {
7536
+ "kind": "Reference",
7537
+ "text": "Children",
7538
+ "canonicalReference": "@alloy-js/core!Children:type"
7539
+ },
7540
+ {
7541
+ "kind": "Content",
7542
+ "text": "[]"
7543
+ },
7544
+ {
7545
+ "kind": "Content",
7546
+ "text": ";"
7547
+ }
7548
+ ],
7549
+ "isReadonly": true,
7550
+ "isOptional": true,
7551
+ "releaseTag": "Public",
7552
+ "name": "constraints",
7553
+ "propertyTypeTokenRange": {
7554
+ "startIndex": 1,
7555
+ "endIndex": 5
7556
+ }
7557
+ },
7558
+ {
7559
+ "kind": "PropertySignature",
7560
+ "canonicalReference": "@alloy-js/csharp!TypeParameterProps#name:member",
7561
+ "docComment": "/**\n * The name of the type parameter.\n */\n",
7562
+ "excerptTokens": [
7563
+ {
7564
+ "kind": "Content",
7565
+ "text": "readonly name: "
7566
+ },
7567
+ {
7568
+ "kind": "Content",
7569
+ "text": "string"
7570
+ },
7571
+ {
7572
+ "kind": "Content",
7573
+ "text": ";"
7574
+ }
7575
+ ],
7576
+ "isReadonly": true,
7577
+ "isOptional": false,
7578
+ "releaseTag": "Public",
7579
+ "name": "name",
7580
+ "propertyTypeTokenRange": {
7581
+ "startIndex": 1,
7582
+ "endIndex": 2
7583
+ }
7584
+ },
7585
+ {
7586
+ "kind": "PropertySignature",
7587
+ "canonicalReference": "@alloy-js/csharp!TypeParameterProps#refkey:member",
7588
+ "docComment": "/**\n * A refkey or array of refkeys for this type parameter.\n */\n",
7589
+ "excerptTokens": [
7590
+ {
7591
+ "kind": "Content",
7592
+ "text": "readonly refkey?: "
7593
+ },
7594
+ {
7595
+ "kind": "Reference",
7596
+ "text": "Refkey",
7597
+ "canonicalReference": "@alloy-js/core!Refkey:type"
7598
+ },
7599
+ {
7600
+ "kind": "Content",
7601
+ "text": " | "
7602
+ },
7603
+ {
7604
+ "kind": "Reference",
7605
+ "text": "Refkey",
7606
+ "canonicalReference": "@alloy-js/core!Refkey:type"
7607
+ },
7608
+ {
7609
+ "kind": "Content",
7610
+ "text": "[]"
7611
+ },
7612
+ {
7613
+ "kind": "Content",
7614
+ "text": ";"
7615
+ }
7616
+ ],
7617
+ "isReadonly": true,
7618
+ "isOptional": true,
7619
+ "releaseTag": "Public",
7620
+ "name": "refkey",
7621
+ "propertyTypeTokenRange": {
7622
+ "startIndex": 1,
7623
+ "endIndex": 5
7624
+ }
7625
+ }
7626
+ ],
7627
+ "extendsTokenRanges": []
7628
+ },
7440
7629
  {
7441
7630
  "kind": "Function",
7442
7631
  "canonicalReference": "@alloy-js/csharp!useCSharpNamePolicy:function(1)",
@@ -1,8 +1,15 @@
1
1
  import * as core from "@alloy-js/core";
2
+ import { List, refkey } from "@alloy-js/core";
2
3
  import * as coretest from "@alloy-js/core/testing";
3
4
  import { describe, expect, it } from "vitest";
5
+ import { TypeParameterProps } from "../src/components/type-parameters/type-parameter.jsx";
4
6
  import * as csharp from "../src/index.js";
5
- import { ClassDeclaration, ClassMember } from "../src/index.js";
7
+ import {
8
+ ClassDeclaration,
9
+ ClassMember,
10
+ Property,
11
+ SourceFile,
12
+ } from "../src/index.js";
6
13
  import * as utils from "./utils.jsx";
7
14
 
8
15
  it("declares class with no members", () => {
@@ -217,34 +224,77 @@ it("uses refkeys for members, params, and return type", () => {
217
224
  `);
218
225
  });
219
226
 
220
- it("declares class with generic parameters", () => {
221
- const typeParameters = {
222
- T: core.refkey(),
223
- U: core.refkey(),
224
- };
227
+ describe("with type parameters", () => {
228
+ it("reference parameters", () => {
229
+ const typeParameters: TypeParameterProps[] = [
230
+ {
231
+ name: "T",
232
+ refkey: refkey(),
233
+ },
234
+ {
235
+ name: "U",
236
+ refkey: refkey(),
237
+ },
238
+ ];
225
239
 
226
- const res = utils.toSourceText(
227
- <csharp.ClassDeclaration
228
- public
229
- name="TestClass"
230
- typeParameters={typeParameters}
231
- >
232
- <csharp.ClassMember public name="memberOne" type={typeParameters.T} />
233
- ;<hbr />
234
- <csharp.ClassMember private name="memberTwo" type={typeParameters.U} />;
235
- </csharp.ClassDeclaration>,
236
- );
237
-
238
- expect(res).toBe(coretest.d`
239
- namespace TestCode
240
- {
240
+ expect(
241
+ <utils.TestNamespace>
242
+ <SourceFile path="Test.cs">
243
+ <ClassDeclaration
244
+ public
245
+ name="TestClass"
246
+ typeParameters={typeParameters}
247
+ >
248
+ <List>
249
+ <Property name="PropA" type={typeParameters[0].refkey} get set />
250
+ <Property name="PropB" type={typeParameters[1].refkey} get set />
251
+ </List>
252
+ </ClassDeclaration>
253
+ </SourceFile>
254
+ </utils.TestNamespace>,
255
+ ).toRenderTo(`
256
+ namespace TestCode
257
+ {
241
258
  public class TestClass<T, U>
242
259
  {
243
- public T MemberOne;
244
- private U memberTwo;
260
+ T PropA { get; set; }
261
+ U PropB { get; set; }
245
262
  }
246
- }
247
- `);
263
+ }
264
+ `);
265
+ });
266
+
267
+ it("defines with constraints", () => {
268
+ const typeParameters: TypeParameterProps[] = [
269
+ {
270
+ name: "T",
271
+ constraints: "IFoo",
272
+ },
273
+ {
274
+ name: "U",
275
+ constraints: "IBar",
276
+ },
277
+ ];
278
+
279
+ expect(
280
+ <utils.TestNamespace>
281
+ <ClassDeclaration
282
+ public
283
+ name="TestClass"
284
+ typeParameters={typeParameters}
285
+ >
286
+ // Body
287
+ </ClassDeclaration>
288
+ </utils.TestNamespace>,
289
+ ).toRenderTo(`
290
+ public class TestClass<T, U>
291
+ where T : IFoo
292
+ where U : IBar
293
+ {
294
+ // Body
295
+ }
296
+ `);
297
+ });
248
298
  });
249
299
 
250
300
  it("declares class with invalid members", () => {