@typespec/emitter-framework 0.9.0-dev.3 → 0.9.0-dev.7

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 (175) hide show
  1. package/dist/src/core/components/output.d.ts +4 -4
  2. package/dist/src/core/components/output.d.ts.map +1 -1
  3. package/dist/src/core/components/output.js +3 -3
  4. package/dist/src/core/context/name-policy-context.d.ts +2 -2
  5. package/dist/src/core/context/name-policy-context.d.ts.map +1 -1
  6. package/dist/src/core/context/tsp-context.d.ts +2 -2
  7. package/dist/src/core/context/tsp-context.d.ts.map +1 -1
  8. package/dist/src/core/transport-name-policy.d.ts +1 -1
  9. package/dist/src/core/transport-name-policy.d.ts.map +1 -1
  10. package/dist/src/core/write-output.d.ts +2 -2
  11. package/dist/src/core/write-output.d.ts.map +1 -1
  12. package/dist/src/csharp/components/class/declaration.d.ts +13 -0
  13. package/dist/src/csharp/components/class/declaration.d.ts.map +1 -0
  14. package/dist/src/csharp/components/class/declaration.js +91 -0
  15. package/dist/src/csharp/components/class/declaration.test.d.ts +2 -0
  16. package/dist/src/csharp/components/class/declaration.test.d.ts.map +1 -0
  17. package/dist/src/csharp/components/class/declaration.test.js +392 -0
  18. package/dist/src/csharp/components/enum-declaration.d.ts +4 -4
  19. package/dist/src/csharp/components/enum-declaration.d.ts.map +1 -1
  20. package/dist/src/csharp/components/enum-declaration.js +14 -11
  21. package/dist/src/csharp/components/index.d.ts +2 -1
  22. package/dist/src/csharp/components/index.d.ts.map +1 -1
  23. package/dist/src/csharp/components/index.js +2 -1
  24. package/dist/src/csharp/components/property/property.d.ts +15 -0
  25. package/dist/src/csharp/components/property/property.d.ts.map +1 -0
  26. package/dist/src/csharp/components/property/property.js +85 -0
  27. package/dist/src/csharp/components/property/property.test.d.ts +2 -0
  28. package/dist/src/csharp/components/property/property.test.d.ts.map +1 -0
  29. package/dist/src/csharp/components/property/property.test.js +117 -0
  30. package/dist/src/csharp/components/type-expression.d.ts +3 -3
  31. package/dist/src/csharp/components/type-expression.d.ts.map +1 -1
  32. package/dist/src/csharp/components/type-expression.js +15 -1
  33. package/dist/src/csharp/components/type-expression.test.d.ts +2 -0
  34. package/dist/src/csharp/components/type-expression.test.d.ts.map +1 -0
  35. package/dist/src/csharp/components/type-expression.test.js +128 -0
  36. package/dist/src/csharp/components/utils/doc-comments.d.ts +14 -0
  37. package/dist/src/csharp/components/utils/doc-comments.d.ts.map +1 -0
  38. package/dist/src/csharp/components/utils/doc-comments.js +67 -0
  39. package/dist/src/testing/index.d.ts +1 -1
  40. package/dist/src/testing/index.d.ts.map +1 -1
  41. package/dist/src/testing/scenario-test/harness.d.ts +2 -2
  42. package/dist/src/testing/scenario-test/harness.d.ts.map +1 -1
  43. package/dist/src/testing/scenario-test/test-host.d.ts +2 -2
  44. package/dist/src/testing/scenario-test/test-host.d.ts.map +1 -1
  45. package/dist/src/typescript/components/array-expression.d.ts +2 -3
  46. package/dist/src/typescript/components/array-expression.d.ts.map +1 -1
  47. package/dist/src/typescript/components/array-expression.js +2 -2
  48. package/dist/src/typescript/components/arrow-function.d.ts +2 -2
  49. package/dist/src/typescript/components/arrow-function.d.ts.map +1 -1
  50. package/dist/src/typescript/components/arrow-function.js +2 -1
  51. package/dist/src/typescript/components/class-method.d.ts +1 -1
  52. package/dist/src/typescript/components/class-method.d.ts.map +1 -1
  53. package/dist/src/typescript/components/enum-declaration.d.ts +6 -6
  54. package/dist/src/typescript/components/enum-declaration.d.ts.map +1 -1
  55. package/dist/src/typescript/components/enum-declaration.js +2 -2
  56. package/dist/src/typescript/components/function-declaration.d.ts +1 -1
  57. package/dist/src/typescript/components/function-declaration.d.ts.map +1 -1
  58. package/dist/src/typescript/components/function-expression.d.ts +2 -2
  59. package/dist/src/typescript/components/function-expression.d.ts.map +1 -1
  60. package/dist/src/typescript/components/function-expression.js +2 -1
  61. package/dist/src/typescript/components/function-type.d.ts +2 -2
  62. package/dist/src/typescript/components/function-type.d.ts.map +1 -1
  63. package/dist/src/typescript/components/function-type.js +2 -1
  64. package/dist/src/typescript/components/interface-declaration.d.ts +4 -4
  65. package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
  66. package/dist/src/typescript/components/interface-declaration.js +3 -4
  67. package/dist/src/typescript/components/interface-member.d.ts +2 -2
  68. package/dist/src/typescript/components/interface-member.d.ts.map +1 -1
  69. package/dist/src/typescript/components/interface-method.d.ts +2 -2
  70. package/dist/src/typescript/components/interface-method.d.ts.map +1 -1
  71. package/dist/src/typescript/components/record-expression.d.ts +1 -1
  72. package/dist/src/typescript/components/record-expression.d.ts.map +1 -1
  73. package/dist/src/typescript/components/type-alias-declaration.d.ts +1 -1
  74. package/dist/src/typescript/components/type-alias-declaration.d.ts.map +1 -1
  75. package/dist/src/typescript/components/type-declaration.d.ts +1 -1
  76. package/dist/src/typescript/components/type-declaration.d.ts.map +1 -1
  77. package/dist/src/typescript/components/type-expression.d.ts +1 -1
  78. package/dist/src/typescript/components/type-expression.d.ts.map +1 -1
  79. package/dist/src/typescript/components/type-transform.d.ts +2 -2
  80. package/dist/src/typescript/components/type-transform.d.ts.map +1 -1
  81. package/dist/src/typescript/components/union-declaration.d.ts +2 -2
  82. package/dist/src/typescript/components/union-declaration.d.ts.map +1 -1
  83. package/dist/src/typescript/components/union-expression.d.ts +3 -4
  84. package/dist/src/typescript/components/union-expression.d.ts.map +1 -1
  85. package/dist/src/typescript/components/union-expression.js +3 -3
  86. package/dist/src/typescript/components/value-expression.d.ts +2 -2
  87. package/dist/src/typescript/components/value-expression.d.ts.map +1 -1
  88. package/dist/src/typescript/utils/operation.d.ts +2 -2
  89. package/dist/src/typescript/utils/operation.d.ts.map +1 -1
  90. package/dist/test/csharp/components/enum-declaration.test.js +57 -9
  91. package/dist/test/csharp/test-host.d.ts +1 -1
  92. package/dist/test/csharp/test-host.d.ts.map +1 -1
  93. package/dist/test/csharp/utils.d.ts +1 -1
  94. package/dist/test/csharp/utils.d.ts.map +1 -1
  95. package/dist/test/test-host.d.ts +2 -0
  96. package/dist/test/test-host.d.ts.map +1 -0
  97. package/dist/test/test-host.js +5 -0
  98. package/dist/test/typescript/components/member-expression.test.js +5 -5
  99. package/dist/test/typescript/test-host.d.ts +1 -1
  100. package/dist/test/typescript/test-host.d.ts.map +1 -1
  101. package/dist/test/utils.d.ts +2 -2
  102. package/dist/test/utils.d.ts.map +1 -1
  103. package/dist/test/vitest.setup.d.ts +2 -0
  104. package/dist/test/vitest.setup.d.ts.map +1 -0
  105. package/dist/test/vitest.setup.js +1 -0
  106. package/package.json +10 -7
  107. package/src/core/components/output.tsx +9 -5
  108. package/src/core/context/name-policy-context.ts +2 -2
  109. package/src/core/context/tsp-context.ts +2 -2
  110. package/src/core/transport-name-policy.ts +1 -1
  111. package/src/core/write-output.ts +2 -2
  112. package/src/csharp/components/class/declaration.test.tsx +401 -0
  113. package/src/csharp/components/class/declaration.tsx +86 -0
  114. package/src/csharp/components/enum-declaration.tsx +26 -18
  115. package/src/csharp/components/index.ts +2 -1
  116. package/src/csharp/components/property/property.test.tsx +97 -0
  117. package/src/csharp/components/property/property.tsx +62 -0
  118. package/src/csharp/components/type-expression.test.tsx +133 -0
  119. package/src/csharp/components/type-expression.tsx +11 -4
  120. package/src/csharp/components/utils/doc-comments.tsx +58 -0
  121. package/src/testing/index.ts +1 -1
  122. package/src/testing/scenario-test/harness.ts +2 -2
  123. package/src/testing/scenario-test/test-host.ts +4 -4
  124. package/src/typescript/components/array-expression.tsx +3 -3
  125. package/src/typescript/components/arrow-function.tsx +2 -2
  126. package/src/typescript/components/class-method.tsx +1 -1
  127. package/src/typescript/components/enum-declaration.tsx +6 -6
  128. package/src/typescript/components/function-declaration.tsx +1 -1
  129. package/src/typescript/components/function-expression.tsx +2 -2
  130. package/src/typescript/components/function-type.tsx +2 -2
  131. package/src/typescript/components/interface-declaration.tsx +11 -12
  132. package/src/typescript/components/interface-member.tsx +2 -2
  133. package/src/typescript/components/interface-method.tsx +2 -2
  134. package/src/typescript/components/record-expression.tsx +1 -1
  135. package/src/typescript/components/type-alias-declaration.tsx +1 -1
  136. package/src/typescript/components/type-declaration.tsx +1 -1
  137. package/src/typescript/components/type-expression.tsx +2 -2
  138. package/src/typescript/components/type-transform.tsx +3 -3
  139. package/src/typescript/components/union-declaration.tsx +2 -2
  140. package/src/typescript/components/union-expression.tsx +12 -7
  141. package/src/typescript/components/value-expression.tsx +2 -2
  142. package/src/typescript/utils/operation.ts +2 -2
  143. package/test/csharp/components/enum-declaration.test.tsx +52 -11
  144. package/test/csharp/test-host.ts +2 -2
  145. package/test/csharp/utils.ts +1 -1
  146. package/test/test-host.ts +4 -0
  147. package/test/testing/snippet-extractor-csharp.test.ts +1 -1
  148. package/test/testing/snippet-extractor-java.test.ts +1 -1
  149. package/test/testing/snippet-extractor-python.test.ts +1 -1
  150. package/test/testing/snippet-extractor-typescript.test.ts +1 -1
  151. package/test/typescript/components/arrow-function.test.tsx +2 -2
  152. package/test/typescript/components/enum-declaration.test.tsx +1 -1
  153. package/test/typescript/components/function-declaration.test.tsx +1 -1
  154. package/test/typescript/components/function-expression.test.tsx +2 -2
  155. package/test/typescript/components/function-type.test.tsx +2 -2
  156. package/test/typescript/components/interface-declaration.test.tsx +1 -1
  157. package/test/typescript/components/interface-method.test.tsx +2 -2
  158. package/test/typescript/components/member-expression.test.tsx +10 -10
  159. package/test/typescript/components/type-alias-declaration.test.tsx +1 -1
  160. package/test/typescript/components/type-transform.test.tsx +2 -2
  161. package/test/typescript/components/union-declaration.test.tsx +2 -2
  162. package/test/typescript/components/value-expression.test.tsx +6 -6
  163. package/test/typescript/test-host.ts +1 -1
  164. package/test/utils.ts +2 -2
  165. package/test/vitest.setup.ts +1 -0
  166. package/tsconfig.json +3 -1
  167. package/vitest.config.ts +2 -1
  168. package/dist/src/csharp/components/class-declaration.d.ts +0 -9
  169. package/dist/src/csharp/components/class-declaration.d.ts.map +0 -1
  170. package/dist/src/csharp/components/class-declaration.js +0 -97
  171. package/dist/test/csharp/components/class-declaration.test.d.ts +0 -2
  172. package/dist/test/csharp/components/class-declaration.test.d.ts.map +0 -1
  173. package/dist/test/csharp/components/class-declaration.test.js +0 -421
  174. package/src/csharp/components/class-declaration.tsx +0 -87
  175. package/test/csharp/components/class-declaration.test.tsx +0 -344
@@ -1,4 +1,5 @@
1
- export * from "./class-declaration.jsx";
1
+ export * from "./class/declaration.js";
2
2
  export * from "./enum-declaration.jsx";
3
+ export * from "./property/property.jsx";
3
4
  export * from "./type-expression.jsx";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/csharp/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/csharp/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC"}
@@ -1,3 +1,4 @@
1
- export * from "./class-declaration.js";
1
+ export * from "./class/declaration.js";
2
2
  export * from "./enum-declaration.js";
3
+ export * from "./property/property.js";
3
4
  export * from "./type-expression.js";
@@ -0,0 +1,15 @@
1
+ import { type Children } from "@alloy-js/core";
2
+ import { type ModelProperty } from "@typespec/compiler";
3
+ export interface PropertyProps {
4
+ type: ModelProperty;
5
+ /** If set the property will add the json serialization attributes(using System.Text.Json). */
6
+ jsonAttributes?: boolean;
7
+ }
8
+ /**
9
+ * Create a C# property declaration from a TypeSpec property type.
10
+ */
11
+ export declare function Property(props: PropertyProps): Children;
12
+ export interface JsonNameAttributeProps {
13
+ type: ModelProperty;
14
+ }
15
+ //# sourceMappingURL=property.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../../src/csharp/components/property/property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C,OAAO,EAAE,KAAK,aAAa,EAAiC,MAAM,oBAAoB,CAAC;AAKvF,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,aAAa,CAAC;IACpB,8FAA8F;IAC9F,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,QAAQ,CAiBvD;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,aAAa,CAAC;CACrB"}
@@ -0,0 +1,85 @@
1
+ import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import * as cs from "@alloy-js/csharp";
3
+ import { Attribute } from "@alloy-js/csharp";
4
+ import { resolveEncodedName } from "@typespec/compiler";
5
+ import { useTsp } from "../../../core/index.js";
6
+ import { TypeExpression } from "../type-expression.js";
7
+ import { getDocComments } from "../utils/doc-comments.js";
8
+ /**
9
+ * Create a C# property declaration from a TypeSpec property type.
10
+ */
11
+ export function Property(props) {
12
+ const result = preprocessPropertyType(props.type.type);
13
+ const {
14
+ $
15
+ } = useTsp();
16
+ return _$createComponent(cs.Property, {
17
+ get name() {
18
+ return props.type.name;
19
+ },
20
+ get type() {
21
+ return _$createComponent(TypeExpression, {
22
+ get type() {
23
+ return result.type;
24
+ }
25
+ });
26
+ },
27
+ "public": true,
28
+ get required() {
29
+ return !props.type.optional;
30
+ },
31
+ get nullable() {
32
+ return result.nullable;
33
+ },
34
+ get doc() {
35
+ return getDocComments($, props.type);
36
+ },
37
+ get attributes() {
38
+ return _$memo(() => !!props.jsonAttributes)() ? [_$createComponent(JsonNameAttribute, {
39
+ get type() {
40
+ return props.type;
41
+ }
42
+ })] : undefined;
43
+ },
44
+ get: true,
45
+ set: true
46
+ });
47
+ }
48
+ function JsonNameAttribute(props) {
49
+ const {
50
+ program
51
+ } = useTsp();
52
+ const jsonName = resolveEncodedName(program, props.type, "application/json");
53
+ return _$createComponent(Attribute, {
54
+ name: "System.Text.Json.JsonPropertyName",
55
+ get args() {
56
+ return [JSON.stringify(jsonName)];
57
+ }
58
+ });
59
+ }
60
+ function preprocessPropertyType(type) {
61
+ const {
62
+ $
63
+ } = useTsp();
64
+ if (type.kind === "Union") {
65
+ const variants = type.variants;
66
+ const nonNullVariant = [...variants.values()].find(v => v.type !== $.intrinsic.null);
67
+ const nullVariant = [...variants.values()].find(v => v.type !== $.intrinsic.null);
68
+ if (nonNullVariant && nullVariant && variants.size === 2) {
69
+ return {
70
+ type: nonNullVariant.type,
71
+ nullable: true
72
+ };
73
+ } else {
74
+ return {
75
+ type,
76
+ nullable: false
77
+ };
78
+ }
79
+ } else {
80
+ return {
81
+ type,
82
+ nullable: false
83
+ };
84
+ }
85
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=property.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property.test.d.ts","sourceRoot":"","sources":["../../../../../src/csharp/components/property/property.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,117 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { Tester } from "#test/test-host.js";
3
+ import { ClassDeclaration, createCSharpNamePolicy, Namespace, SourceFile } from "@alloy-js/csharp";
4
+ import { t } from "@typespec/compiler/testing";
5
+ import { beforeEach, describe, expect, it } from "vitest";
6
+ import { Output } from "../../../core/components/output.js";
7
+ import { Property } from "./property.js";
8
+ let tester;
9
+ beforeEach(async () => {
10
+ tester = await Tester.createInstance();
11
+ });
12
+ function Wrapper(props) {
13
+ const policy = createCSharpNamePolicy();
14
+ return _$createComponent(Output, {
15
+ get program() {
16
+ return tester.program;
17
+ },
18
+ namePolicy: policy,
19
+ get children() {
20
+ return _$createComponent(Namespace, {
21
+ name: "TestNamespace",
22
+ get children() {
23
+ return _$createComponent(SourceFile, {
24
+ path: "test.cs",
25
+ get children() {
26
+ return _$createComponent(ClassDeclaration, {
27
+ name: "Test",
28
+ get children() {
29
+ return props.children;
30
+ }
31
+ });
32
+ }
33
+ });
34
+ }
35
+ });
36
+ }
37
+ });
38
+ }
39
+ it("maps prop: string | null to nullable property", async () => {
40
+ const {
41
+ prop1
42
+ } = await tester.compile(t.code`
43
+ model TestModel {
44
+ ${t.modelProperty("prop1")}: string | null;
45
+ }
46
+ `);
47
+ expect(_$createComponent(Wrapper, {
48
+ get children() {
49
+ return _$createComponent(Property, {
50
+ type: prop1
51
+ });
52
+ }
53
+ })).toRenderTo(`
54
+ namespace TestNamespace
55
+ {
56
+ class Test
57
+ {
58
+ public required string? Prop1 { get; set; }
59
+ }
60
+ }
61
+ `);
62
+ });
63
+ describe("jsonAttributes", () => {
64
+ it("adds [JsonNameAttribute]", async () => {
65
+ const {
66
+ prop1
67
+ } = await tester.compile(t.code`
68
+ model TestModel {
69
+ ${t.modelProperty("prop1")}: string;
70
+ }
71
+ `);
72
+ expect(_$createComponent(Wrapper, {
73
+ get children() {
74
+ return _$createComponent(Property, {
75
+ type: prop1,
76
+ jsonAttributes: true
77
+ });
78
+ }
79
+ })).toRenderTo(`
80
+ namespace TestNamespace
81
+ {
82
+ class Test
83
+ {
84
+ [System.Text.Json.JsonPropertyName("prop1")]
85
+ public required string Prop1 { get; set; }
86
+ }
87
+ }
88
+ `);
89
+ });
90
+ it("adds [JsonNameAttribute] respecting encodedName", async () => {
91
+ const {
92
+ prop1
93
+ } = await tester.compile(t.code`
94
+ model TestModel {
95
+ @encodedName("application/json", "prop_1")
96
+ ${t.modelProperty("prop1")}: string;
97
+ }
98
+ `);
99
+ expect(_$createComponent(Wrapper, {
100
+ get children() {
101
+ return _$createComponent(Property, {
102
+ type: prop1,
103
+ jsonAttributes: true
104
+ });
105
+ }
106
+ })).toRenderTo(`
107
+ namespace TestNamespace
108
+ {
109
+ class Test
110
+ {
111
+ [System.Text.Json.JsonPropertyName("prop_1")]
112
+ public required string Prop1 { get; set; }
113
+ }
114
+ }
115
+ `);
116
+ });
117
+ });
@@ -1,6 +1,6 @@
1
- import { Children } from "@alloy-js/core";
2
- import { IntrinsicType, Scalar, Type } from "@typespec/compiler";
3
- import { Typekit } from "@typespec/compiler/typekit";
1
+ import { type Children } from "@alloy-js/core";
2
+ import { type IntrinsicType, type Scalar, type Type } from "@typespec/compiler";
3
+ import type { Typekit } from "@typespec/compiler/typekit";
4
4
  export interface TypeExpressionProps {
5
5
  type: Type;
6
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"type-expression.d.ts","sourceRoot":"","sources":["../../../../src/csharp/components/type-expression.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAKrD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,IAAI,CAAC;CACZ;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,QAAQ,CASnE;AAED,QAAA,MAAM,yBAAyB,4BAqC7B,CAAC;AAEH,wBAAgB,4BAA4B,CAC1C,CAAC,EAAE,OAAO,EACV,IAAI,EAAE,MAAM,GAAG,aAAa,GAC3B,MAAM,GAAG,IAAI,CAoBf;AA0BD,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
1
+ {"version":3,"file":"type-expression.d.ts","sourceRoot":"","sources":["../../../../src/csharp/components/type-expression.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAQ,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAe,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,KAAK,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC7F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAK1D,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,IAAI,CAAC;CACZ;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,QAAQ,CAgBnE;AAED,QAAA,MAAM,yBAAyB,4BAqC7B,CAAC;AAEH,wBAAgB,4BAA4B,CAC1C,CAAC,EAAE,OAAO,EACV,IAAI,EAAE,MAAM,GAAG,aAAa,GAC3B,MAAM,GAAG,IAAI,CAoBf;AA0BD,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
@@ -1,5 +1,7 @@
1
1
  import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { code } from "@alloy-js/core";
2
3
  import { Reference } from "@alloy-js/csharp";
4
+ import { getTypeName } from "@typespec/compiler";
3
5
  import { useTsp } from "../../core/index.js";
4
6
  import { reportTypescriptDiagnostic } from "../../typescript/lib.js";
5
7
  import { efRefkey } from "./utils/refkey.js";
@@ -16,8 +18,20 @@ export function TypeExpression(props) {
16
18
  }
17
19
  if ($.scalar.is(props.type)) {
18
20
  return getScalarIntrinsicExpression($, props.type);
21
+ } else if ($.array.is(props.type)) {
22
+ return code`${_$createComponent(TypeExpression, {
23
+ get type() {
24
+ return props.type.indexer.value;
25
+ }
26
+ })}[]`;
27
+ } else if ($.record.is(props.type)) {
28
+ return code`IDictionary<string, ${_$createComponent(TypeExpression, {
29
+ get type() {
30
+ return props.type.indexer.value;
31
+ }
32
+ })}>`;
19
33
  }
20
- throw new Error("not implemented");
34
+ throw new Error(`Unsupported type for TypeExpression: ${props.type.kind} (${getTypeName(props.type)})`);
21
35
  }
22
36
  const intrinsicNameToCSharpType = new Map([
23
37
  // Core types
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type-expression.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-expression.test.d.ts","sourceRoot":"","sources":["../../../../src/csharp/components/type-expression.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,128 @@
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { render } from "@alloy-js/core";
3
+ import { d } from "@alloy-js/core/testing";
4
+ import { Namespace, SourceFile } from "@alloy-js/csharp";
5
+ import { beforeEach, describe, it } from "vitest";
6
+ import { createEmitterFrameworkTestRunner } from "../../../test/typescript/test-host.js";
7
+ import { assertFileContents } from "../../../test/utils.js";
8
+ import { Output } from "../../core/index.js";
9
+ import { ClassDeclaration } from "./class/declaration.js";
10
+ import { TypeExpression } from "./type-expression.js";
11
+ let runner;
12
+ beforeEach(async () => {
13
+ runner = await createEmitterFrameworkTestRunner();
14
+ });
15
+ function Wrapper(props) {
16
+ return _$createComponent(Output, {
17
+ get program() {
18
+ return runner.program;
19
+ },
20
+ get children() {
21
+ return _$createComponent(Namespace, {
22
+ name: "TestNamespace",
23
+ get children() {
24
+ return _$createComponent(SourceFile, {
25
+ path: "test.ts",
26
+ get children() {
27
+ return props.children;
28
+ }
29
+ });
30
+ }
31
+ });
32
+ }
33
+ });
34
+ }
35
+ async function compileType(ref) {
36
+ const {
37
+ test
38
+ } = await runner.compile(`
39
+ model Test {
40
+ @test test: ${ref};
41
+ }
42
+ `);
43
+ return test.type;
44
+ }
45
+ describe("map scalar to c# built-in types", () => {
46
+ it.each([["string", "string"], ["int32", "int"], ["int64", "long"]])("%s => %s", async (tspType, csType) => {
47
+ const type = await compileType(tspType);
48
+ const res = render(_$createComponent(Wrapper, {
49
+ get children() {
50
+ return _$createComponent(TypeExpression, {
51
+ type: type
52
+ });
53
+ }
54
+ }));
55
+ assertFileContents(res, d`
56
+ namespace TestNamespace
57
+ {
58
+ ${csType}
59
+ }
60
+ `);
61
+ });
62
+ });
63
+ it("maps array to c# array", async () => {
64
+ const type = await compileType("int32[]");
65
+ const res = render(_$createComponent(Wrapper, {
66
+ get children() {
67
+ return _$createComponent(TypeExpression, {
68
+ type: type
69
+ });
70
+ }
71
+ }));
72
+ assertFileContents(res, d`
73
+ namespace TestNamespace
74
+ {
75
+ int[]
76
+ }
77
+ `);
78
+ });
79
+ describe("Record map to IDictionary", () => {
80
+ it("for primitive types", async () => {
81
+ const type = await compileType("Record<int32>");
82
+ const res = render(_$createComponent(Wrapper, {
83
+ get children() {
84
+ return _$createComponent(TypeExpression, {
85
+ type: type
86
+ });
87
+ }
88
+ }));
89
+ assertFileContents(res, d`
90
+ namespace TestNamespace
91
+ {
92
+ IDictionary<string, int>
93
+ }
94
+ `);
95
+ });
96
+ it("for models", async () => {
97
+ const {
98
+ test,
99
+ Pet
100
+ } = await runner.compile(`
101
+ model Test {
102
+ @test test: Record<Pet>;
103
+ }
104
+ @test model Pet {}
105
+ `);
106
+ const res = render(_$createComponent(Wrapper, {
107
+ get children() {
108
+ return [_$createComponent(ClassDeclaration, {
109
+ type: Pet
110
+ }), _$createIntrinsic("hbr", {}), _$createComponent(TypeExpression, {
111
+ get type() {
112
+ return test.type;
113
+ }
114
+ })];
115
+ }
116
+ }));
117
+ assertFileContents(res, d`
118
+ namespace TestNamespace
119
+ {
120
+ class Pet
121
+ {
122
+
123
+ }
124
+ IDictionary<string, Pet>
125
+ }
126
+ `);
127
+ });
128
+ });
@@ -0,0 +1,14 @@
1
+ import { type Children } from "@alloy-js/core";
2
+ import { type Type } from "@typespec/compiler";
3
+ import type { Typekit } from "@typespec/compiler/typekit";
4
+ /**
5
+ * Helper to render a doc string for a given TypeSpec type.
6
+ *
7
+ * This is not a JSX component as it needs to return undefined if there is no doc.
8
+ *
9
+ * @param $ The Typekit instance
10
+ * @param type The TypeSpec type to generate documentation for
11
+ * @returns A DocSummary component containing the rendered doc string, or undefined if no doc is available.
12
+ */
13
+ export declare function getDocComments($: Typekit, type: Type): Children;
14
+ //# sourceMappingURL=doc-comments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doc-comments.d.ts","sourceRoot":"","sources":["../../../../../src/csharp/components/utils/doc-comments.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAQ,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAiB,KAAK,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAE1D;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,QAAQ,CA2C/D"}
@@ -0,0 +1,67 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { List } from "@alloy-js/core";
3
+ import * as cs from "@alloy-js/csharp";
4
+ import { getReturnsDoc } from "@typespec/compiler";
5
+ /**
6
+ * Helper to render a doc string for a given TypeSpec type.
7
+ *
8
+ * This is not a JSX component as it needs to return undefined if there is no doc.
9
+ *
10
+ * @param $ The Typekit instance
11
+ * @param type The TypeSpec type to generate documentation for
12
+ * @returns A DocSummary component containing the rendered doc string, or undefined if no doc is available.
13
+ */
14
+ export function getDocComments($, type) {
15
+ const typeDoc = $.type.getDoc(type);
16
+ if (!typeDoc) {
17
+ return undefined;
18
+ }
19
+ const docElements = [];
20
+
21
+ // Add main type documentation
22
+ docElements.push(_$createComponent(cs.DocSummary, {
23
+ get children() {
24
+ return _$createComponent(cs.DocFromMarkdown, {
25
+ markdown: typeDoc
26
+ });
27
+ }
28
+ }));
29
+
30
+ // Add operation-specific documentation if applicable
31
+ if ($.operation.is(type)) {
32
+ // Add parameter documentation
33
+ const paramDocs = [];
34
+ for (const param of type.parameters.properties.values()) {
35
+ const paramDoc = $.type.getDoc(param);
36
+ if (paramDoc) {
37
+ paramDocs.push(_$createComponent(cs.DocParam, {
38
+ get name() {
39
+ return param.name;
40
+ },
41
+ get children() {
42
+ return _$createComponent(cs.DocFromMarkdown, {
43
+ markdown: paramDoc
44
+ });
45
+ }
46
+ }));
47
+ }
48
+ }
49
+ docElements.push(...paramDocs);
50
+
51
+ // Add return documentation
52
+ const returnDoc = getReturnsDoc($.program, type);
53
+ if (returnDoc) {
54
+ docElements.push(_$createComponent(cs.DocReturns, {
55
+ get children() {
56
+ return _$createComponent(cs.DocFromMarkdown, {
57
+ markdown: returnDoc
58
+ });
59
+ }
60
+ }));
61
+ }
62
+ }
63
+ return _$createComponent(List, {
64
+ doubleHardline: true,
65
+ children: docElements
66
+ });
67
+ }
@@ -1,4 +1,4 @@
1
- import { TypeSpecTestLibrary } from "@typespec/compiler/testing";
1
+ import { type TypeSpecTestLibrary } from "@typespec/compiler/testing";
2
2
  export declare const EmitterFrameworkTestLibrary: TypeSpecTestLibrary;
3
3
  export * from "./scenario-test/index.js";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/testing/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGpF,eAAO,MAAM,2BAA2B,EAAE,mBAGxC,CAAC;AAEH,cAAc,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/testing/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGzF,eAAO,MAAM,2BAA2B,EAAE,mBAGxC,CAAC;AAEH,cAAc,0BAA0B,CAAC"}
@@ -1,4 +1,4 @@
1
- import { TypeSpecTestLibrary } from "@typespec/compiler/testing";
2
- import { LanguageConfiguration, SnippetExtractor } from "./snippet-extractor.js";
1
+ import type { TypeSpecTestLibrary } from "@typespec/compiler/testing";
2
+ import type { LanguageConfiguration, SnippetExtractor } from "./snippet-extractor.js";
3
3
  export declare function executeScenarios(testLibrary: TypeSpecTestLibrary, languageConfiguration: LanguageConfiguration, scenariosLocation: string, emitterOutputDir: string, snippetExtractor: SnippetExtractor): Promise<void>;
4
4
  //# sourceMappingURL=harness.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../../../src/testing/scenario-test/harness.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAMjE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AA+HjF,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,mBAAmB,EAChC,qBAAqB,EAAE,qBAAqB,EAC5C,iBAAiB,EAAE,MAAM,EACzB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,gBAAgB,iBAkBnC"}
1
+ {"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../../../src/testing/scenario-test/harness.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAMtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AA+HtF,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,mBAAmB,EAChC,qBAAqB,EAAE,qBAAqB,EAC5C,iBAAiB,EAAE,MAAM,EACzB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,gBAAgB,iBAkBnC"}
@@ -1,5 +1,5 @@
1
- import { Diagnostic } from "@typespec/compiler";
2
- import { TypeSpecTestLibrary } from "@typespec/compiler/testing";
1
+ import type { Diagnostic } from "@typespec/compiler";
2
+ import { type TypeSpecTestLibrary } from "@typespec/compiler/testing";
3
3
  export interface EmittedFile {
4
4
  path: string;
5
5
  content: string;
@@ -1 +1 @@
1
- {"version":3,"file":"test-host.d.ts","sourceRoot":"","sources":["../../../../src/testing/scenario-test/test-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAKL,mBAAmB,EACpB,MAAM,4BAA4B,CAAC;AAKpC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AA4BD,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,mBAAmB,EAChC,gBAAgB,EAAE,MAAM,EACxB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,SAAS,UAAU,EAAE,CAAC,CAAC,CAOjD"}
1
+ {"version":3,"file":"test-host.d.ts","sourceRoot":"","sources":["../../../../src/testing/scenario-test/test-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAKL,KAAK,mBAAmB,EACzB,MAAM,4BAA4B,CAAC;AAKpC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AA4BD,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,mBAAmB,EAChC,gBAAgB,EAAE,MAAM,EACxB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,SAAS,UAAU,EAAE,CAAC,CAAC,CAOjD"}
@@ -1,7 +1,6 @@
1
- import * as ay from "@alloy-js/core";
2
- import { Type } from "@typespec/compiler";
1
+ import type { Type } from "@typespec/compiler";
3
2
  export interface ArrayExpressionProps {
4
3
  elementType: Type;
5
4
  }
6
- export declare function ArrayExpression({ elementType }: ArrayExpressionProps): ay.Children;
5
+ export declare function ArrayExpression({ elementType }: ArrayExpressionProps): import("@alloy-js/core").Children;
7
6
  //# sourceMappingURL=array-expression.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"array-expression.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/array-expression.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,IAAI,CAAC;CACnB;AAED,wBAAgB,eAAe,CAAC,EAAE,WAAW,EAAE,EAAE,oBAAoB,eAEpE"}
1
+ {"version":3,"file":"array-expression.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/array-expression.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG/C,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,IAAI,CAAC;CACnB;AAED,wBAAgB,eAAe,CAAC,EAAE,WAAW,EAAE,EAAE,oBAAoB,qCAEpE"}
@@ -1,10 +1,10 @@
1
1
  import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import * as ay from "@alloy-js/core";
2
+ import { code } from "@alloy-js/core";
3
3
  import { TypeExpression } from "./type-expression.js";
4
4
  export function ArrayExpression({
5
5
  elementType
6
6
  }) {
7
- return ay.code`Array<${_$createComponent(TypeExpression, {
7
+ return code`Array<${_$createComponent(TypeExpression, {
8
8
  type: elementType
9
9
  })}>`;
10
10
  }
@@ -1,5 +1,5 @@
1
1
  import * as ts from "@alloy-js/typescript";
2
- import { Operation } from "@typespec/compiler";
2
+ import type { Operation } from "@typespec/compiler";
3
3
  export interface ArrowFunctionProps extends ts.ArrowFunctionProps {
4
4
  type?: Operation;
5
5
  /**
@@ -13,5 +13,5 @@ export interface ArrowFunctionProps extends ts.ArrowFunctionProps {
13
13
  * function by converting from a TypeSpec Operation. Any other props provided
14
14
  * will take precedence.
15
15
  */
16
- export declare function ArrowFunction(props: Readonly<ArrowFunctionProps>): import("@alloy-js/core/jsx-runtime").Children;
16
+ export declare function ArrowFunction(props: Readonly<ArrowFunctionProps>): import("@alloy-js/core").Children;
17
17
  //# sourceMappingURL=arrow-function.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"arrow-function.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/arrow-function.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,MAAM,WAAW,kBAAmB,SAAQ,EAAE,CAAC,kBAAkB;IAC/D,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;;OAGG;IACH,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;CACnD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,kBAAkB,CAAC,iDAkBhE"}
1
+ {"version":3,"file":"arrow-function.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/arrow-function.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAIpD,MAAM,WAAW,kBAAmB,SAAQ,EAAE,CAAC,kBAAkB;IAC/D,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;;OAGG;IACH,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;CACnD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,kBAAkB,CAAC,qCAkBhE"}
@@ -1,4 +1,5 @@
1
- import { splitProps, mergeProps as _$mergeProps, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
1
+ import { mergeProps as _$mergeProps, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { splitProps } from "@alloy-js/core";
2
3
  import * as ts from "@alloy-js/typescript";
3
4
  import { buildParameterDescriptors, getReturnType } from "../utils/operation.js";
4
5
  import { TypeExpression } from "./type-expression.js";
@@ -1,5 +1,5 @@
1
1
  import * as ts from "@alloy-js/typescript";
2
- import { Operation } from "@typespec/compiler";
2
+ import type { Operation } from "@typespec/compiler";
3
3
  export interface ClassMethodPropsWithType extends Omit<ts.ClassMethodProps, "name"> {
4
4
  type: Operation;
5
5
  name?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"class-method.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/class-method.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CAAC,EAAE,CAAC,gBAAgB,EAAE,MAAM,CAAC;IACjF,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;CACnD;AAED,MAAM,MAAM,gBAAgB,GAAG,wBAAwB,GAAG,EAAE,CAAC,gBAAgB,CAAC;AAE9E,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,qCAuBlD"}
1
+ {"version":3,"file":"class-method.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/class-method.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAIpD,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CAAC,EAAE,CAAC,gBAAgB,EAAE,MAAM,CAAC;IACjF,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;CACnD;AAED,MAAM,MAAM,gBAAgB,GAAG,wBAAwB,GAAG,EAAE,CAAC,gBAAgB,CAAC;AAE9E,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,qCAuBlD"}