@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
@@ -0,0 +1,97 @@
1
+ import { Tester } from "#test/test-host.js";
2
+ import { type Children } from "@alloy-js/core";
3
+ import { ClassDeclaration, createCSharpNamePolicy, Namespace, SourceFile } from "@alloy-js/csharp";
4
+ import { t, type TesterInstance } from "@typespec/compiler/testing";
5
+ import { beforeEach, describe, expect, it } from "vitest";
6
+ import { Output } from "../../../core/components/output.jsx";
7
+ import { Property } from "./property.jsx";
8
+
9
+ let tester: TesterInstance;
10
+
11
+ beforeEach(async () => {
12
+ tester = await Tester.createInstance();
13
+ });
14
+
15
+ function Wrapper(props: { children: Children }) {
16
+ const policy = createCSharpNamePolicy();
17
+ return (
18
+ <Output program={tester.program} namePolicy={policy}>
19
+ <Namespace name="TestNamespace">
20
+ <SourceFile path="test.cs">
21
+ <ClassDeclaration name="Test">{props.children}</ClassDeclaration>
22
+ </SourceFile>
23
+ </Namespace>
24
+ </Output>
25
+ );
26
+ }
27
+
28
+ it("maps prop: string | null to nullable property", async () => {
29
+ const { prop1 } = await tester.compile(t.code`
30
+ model TestModel {
31
+ ${t.modelProperty("prop1")}: string | null;
32
+ }
33
+ `);
34
+
35
+ expect(
36
+ <Wrapper>
37
+ <Property type={prop1} />
38
+ </Wrapper>,
39
+ ).toRenderTo(`
40
+ namespace TestNamespace
41
+ {
42
+ class Test
43
+ {
44
+ public required string? Prop1 { get; set; }
45
+ }
46
+ }
47
+ `);
48
+ });
49
+
50
+ describe("jsonAttributes", () => {
51
+ it("adds [JsonNameAttribute]", async () => {
52
+ const { prop1 } = await tester.compile(t.code`
53
+ model TestModel {
54
+ ${t.modelProperty("prop1")}: string;
55
+ }
56
+ `);
57
+
58
+ expect(
59
+ <Wrapper>
60
+ <Property type={prop1} jsonAttributes />
61
+ </Wrapper>,
62
+ ).toRenderTo(`
63
+ namespace TestNamespace
64
+ {
65
+ class Test
66
+ {
67
+ [System.Text.Json.JsonPropertyName("prop1")]
68
+ public required string Prop1 { get; set; }
69
+ }
70
+ }
71
+ `);
72
+ });
73
+
74
+ it("adds [JsonNameAttribute] respecting encodedName", async () => {
75
+ const { prop1 } = await tester.compile(t.code`
76
+ model TestModel {
77
+ @encodedName("application/json", "prop_1")
78
+ ${t.modelProperty("prop1")}: string;
79
+ }
80
+ `);
81
+
82
+ expect(
83
+ <Wrapper>
84
+ <Property type={prop1} jsonAttributes />
85
+ </Wrapper>,
86
+ ).toRenderTo(`
87
+ namespace TestNamespace
88
+ {
89
+ class Test
90
+ {
91
+ [System.Text.Json.JsonPropertyName("prop_1")]
92
+ public required string Prop1 { get; set; }
93
+ }
94
+ }
95
+ `);
96
+ });
97
+ });
@@ -0,0 +1,62 @@
1
+ import { type Children } from "@alloy-js/core";
2
+ import * as cs from "@alloy-js/csharp";
3
+ import { Attribute } from "@alloy-js/csharp";
4
+ import { type ModelProperty, resolveEncodedName, type Type } from "@typespec/compiler";
5
+ import { useTsp } from "../../../core/index.js";
6
+ import { TypeExpression } from "../type-expression.jsx";
7
+ import { getDocComments } from "../utils/doc-comments.jsx";
8
+
9
+ export interface PropertyProps {
10
+ type: ModelProperty;
11
+ /** If set the property will add the json serialization attributes(using System.Text.Json). */
12
+ jsonAttributes?: boolean;
13
+ }
14
+
15
+ /**
16
+ * Create a C# property declaration from a TypeSpec property type.
17
+ */
18
+ export function Property(props: PropertyProps): Children {
19
+ const result = preprocessPropertyType(props.type.type);
20
+ const { $ } = useTsp();
21
+
22
+ return (
23
+ <cs.Property
24
+ name={props.type.name}
25
+ type={<TypeExpression type={result.type} />}
26
+ public
27
+ required={!props.type.optional}
28
+ nullable={result.nullable}
29
+ doc={getDocComments($, props.type)}
30
+ attributes={props.jsonAttributes ? [<JsonNameAttribute type={props.type} />] : undefined}
31
+ get
32
+ set
33
+ />
34
+ );
35
+ }
36
+
37
+ export interface JsonNameAttributeProps {
38
+ type: ModelProperty;
39
+ }
40
+
41
+ function JsonNameAttribute(props: JsonNameAttributeProps): Children {
42
+ const { program } = useTsp();
43
+ const jsonName = resolveEncodedName(program, props.type, "application/json");
44
+ return <Attribute name="System.Text.Json.JsonPropertyName" args={[JSON.stringify(jsonName)]} />;
45
+ }
46
+
47
+ function preprocessPropertyType(type: Type): { type: Type; nullable: boolean } {
48
+ const { $ } = useTsp();
49
+
50
+ if (type.kind === "Union") {
51
+ const variants = type.variants;
52
+ const nonNullVariant = [...variants.values()].find((v) => v.type !== $.intrinsic.null);
53
+ const nullVariant = [...variants.values()].find((v) => v.type !== $.intrinsic.null);
54
+ if (nonNullVariant && nullVariant && variants.size === 2) {
55
+ return { type: nonNullVariant.type, nullable: true };
56
+ } else {
57
+ return { type, nullable: false };
58
+ }
59
+ } else {
60
+ return { type, nullable: false };
61
+ }
62
+ }
@@ -0,0 +1,133 @@
1
+ import { type Children, render } from "@alloy-js/core";
2
+ import { d } from "@alloy-js/core/testing";
3
+ import { Namespace, SourceFile } from "@alloy-js/csharp";
4
+ import type { Model, ModelProperty } from "@typespec/compiler";
5
+ import type { BasicTestRunner } from "@typespec/compiler/testing";
6
+ import { beforeEach, describe, it } from "vitest";
7
+ import { createEmitterFrameworkTestRunner } from "../../../test/typescript/test-host.js";
8
+ import { assertFileContents } from "../../../test/utils.js";
9
+ import { Output } from "../../core/index.js";
10
+ import { ClassDeclaration } from "./class/declaration.js";
11
+ import { TypeExpression } from "./type-expression.jsx";
12
+
13
+ let runner: BasicTestRunner;
14
+
15
+ beforeEach(async () => {
16
+ runner = await createEmitterFrameworkTestRunner();
17
+ });
18
+
19
+ function Wrapper(props: { children: Children }) {
20
+ return (
21
+ <Output program={runner.program}>
22
+ <Namespace name="TestNamespace">
23
+ <SourceFile path="test.ts">{props.children}</SourceFile>
24
+ </Namespace>
25
+ </Output>
26
+ );
27
+ }
28
+
29
+ async function compileType(ref: string) {
30
+ const { test } = await runner.compile(`
31
+ model Test {
32
+ @test test: ${ref};
33
+ }
34
+ `);
35
+
36
+ return (test as ModelProperty).type;
37
+ }
38
+
39
+ describe("map scalar to c# built-in types", () => {
40
+ it.each([
41
+ ["string", "string"],
42
+ ["int32", "int"],
43
+ ["int64", "long"],
44
+ ])("%s => %s", async (tspType, csType) => {
45
+ const type = await compileType(tspType);
46
+ const res = render(
47
+ <Wrapper>
48
+ <TypeExpression type={type} />
49
+ </Wrapper>,
50
+ );
51
+
52
+ assertFileContents(
53
+ res,
54
+ d`
55
+ namespace TestNamespace
56
+ {
57
+ ${csType}
58
+ }
59
+ `,
60
+ );
61
+ });
62
+ });
63
+
64
+ it("maps array to c# array", async () => {
65
+ const type = await compileType("int32[]");
66
+ const res = render(
67
+ <Wrapper>
68
+ <TypeExpression type={type} />
69
+ </Wrapper>,
70
+ );
71
+
72
+ assertFileContents(
73
+ res,
74
+ d`
75
+ namespace TestNamespace
76
+ {
77
+ int[]
78
+ }
79
+ `,
80
+ );
81
+ });
82
+
83
+ describe("Record map to IDictionary", () => {
84
+ it("for primitive types", async () => {
85
+ const type = await compileType("Record<int32>");
86
+ const res = render(
87
+ <Wrapper>
88
+ <TypeExpression type={type} />
89
+ </Wrapper>,
90
+ );
91
+
92
+ assertFileContents(
93
+ res,
94
+ d`
95
+ namespace TestNamespace
96
+ {
97
+ IDictionary<string, int>
98
+ }
99
+ `,
100
+ );
101
+ });
102
+
103
+ it("for models", async () => {
104
+ const { test, Pet } = (await runner.compile(`
105
+ model Test {
106
+ @test test: Record<Pet>;
107
+ }
108
+ @test model Pet {}
109
+ `)) as { test: ModelProperty; Pet: Model };
110
+
111
+ const res = render(
112
+ <Wrapper>
113
+ <ClassDeclaration type={Pet} />
114
+ <hbr />
115
+ <TypeExpression type={test.type} />
116
+ </Wrapper>,
117
+ );
118
+
119
+ assertFileContents(
120
+ res,
121
+ d`
122
+ namespace TestNamespace
123
+ {
124
+ class Pet
125
+ {
126
+
127
+ }
128
+ IDictionary<string, Pet>
129
+ }
130
+ `,
131
+ );
132
+ });
133
+ });
@@ -1,7 +1,7 @@
1
- import { Children } from "@alloy-js/core";
1
+ import { type Children, code } from "@alloy-js/core";
2
2
  import { Reference } from "@alloy-js/csharp";
3
- import { IntrinsicType, Scalar, Type } from "@typespec/compiler";
4
- import { Typekit } from "@typespec/compiler/typekit";
3
+ import { getTypeName, type IntrinsicType, type Scalar, type Type } from "@typespec/compiler";
4
+ import type { Typekit } from "@typespec/compiler/typekit";
5
5
  import { useTsp } from "../../core/index.js";
6
6
  import { reportTypescriptDiagnostic } from "../../typescript/lib.js";
7
7
  import { efRefkey } from "./utils/refkey.js";
@@ -17,8 +17,15 @@ export function TypeExpression(props: TypeExpressionProps): Children {
17
17
  }
18
18
  if ($.scalar.is(props.type)) {
19
19
  return getScalarIntrinsicExpression($, props.type);
20
+ } else if ($.array.is(props.type)) {
21
+ return code`${(<TypeExpression type={props.type.indexer.value} />)}[]`;
22
+ } else if ($.record.is(props.type)) {
23
+ return code`IDictionary<string, ${(<TypeExpression type={props.type.indexer.value} />)}>`;
20
24
  }
21
- throw new Error("not implemented");
25
+
26
+ throw new Error(
27
+ `Unsupported type for TypeExpression: ${props.type.kind} (${getTypeName(props.type)})`,
28
+ );
22
29
  }
23
30
 
24
31
  const intrinsicNameToCSharpType = new Map<string, string | null>([
@@ -0,0 +1,58 @@
1
+ import { type Children, List } from "@alloy-js/core";
2
+ import * as cs from "@alloy-js/csharp";
3
+ import { getReturnsDoc, type Type } from "@typespec/compiler";
4
+ import type { Typekit } from "@typespec/compiler/typekit";
5
+
6
+ /**
7
+ * Helper to render a doc string for a given TypeSpec type.
8
+ *
9
+ * This is not a JSX component as it needs to return undefined if there is no doc.
10
+ *
11
+ * @param $ The Typekit instance
12
+ * @param type The TypeSpec type to generate documentation for
13
+ * @returns A DocSummary component containing the rendered doc string, or undefined if no doc is available.
14
+ */
15
+ export function getDocComments($: Typekit, type: Type): Children {
16
+ const typeDoc = $.type.getDoc(type);
17
+ if (!typeDoc) {
18
+ return undefined;
19
+ }
20
+
21
+ const docElements: Children[] = [];
22
+
23
+ // Add main type documentation
24
+ docElements.push(
25
+ <cs.DocSummary>
26
+ <cs.DocFromMarkdown markdown={typeDoc} />
27
+ </cs.DocSummary>,
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(
38
+ <cs.DocParam name={param.name}>
39
+ <cs.DocFromMarkdown markdown={paramDoc} />
40
+ </cs.DocParam>,
41
+ );
42
+ }
43
+ }
44
+ docElements.push(...paramDocs);
45
+
46
+ // Add return documentation
47
+ const returnDoc = getReturnsDoc($.program, type);
48
+ if (returnDoc) {
49
+ docElements.push(
50
+ <cs.DocReturns>
51
+ <cs.DocFromMarkdown markdown={returnDoc} />
52
+ </cs.DocReturns>,
53
+ );
54
+ }
55
+ }
56
+
57
+ return <List doubleHardline>{docElements}</List>;
58
+ }
@@ -1,5 +1,5 @@
1
1
  import { resolvePath } from "@typespec/compiler";
2
- import { createTestLibrary, TypeSpecTestLibrary } from "@typespec/compiler/testing";
2
+ import { createTestLibrary, type TypeSpecTestLibrary } from "@typespec/compiler/testing";
3
3
  import { fileURLToPath } from "url";
4
4
 
5
5
  export const EmitterFrameworkTestLibrary: TypeSpecTestLibrary = createTestLibrary({
@@ -1,11 +1,11 @@
1
1
  import { normalizePath } from "@typespec/compiler";
2
- import { TypeSpecTestLibrary } from "@typespec/compiler/testing";
2
+ import type { TypeSpecTestLibrary } from "@typespec/compiler/testing";
3
3
  import { readdirSync, readFileSync, statSync, writeFileSync } from "fs";
4
4
  import minimist from "minimist";
5
5
  import path from "path";
6
6
  import { format } from "prettier";
7
7
  import { afterAll, describe, expect, it } from "vitest";
8
- import { LanguageConfiguration, SnippetExtractor } from "./snippet-extractor.js";
8
+ import type { LanguageConfiguration, SnippetExtractor } from "./snippet-extractor.js";
9
9
  import { emitWithDiagnostics } from "./test-host.js";
10
10
 
11
11
  const rawArgs = process.env.TEST_ARGS ? process.env.TEST_ARGS.split(" ") : [];
@@ -1,10 +1,10 @@
1
- import { CompilerOptions, Diagnostic } from "@typespec/compiler";
1
+ import type { CompilerOptions, Diagnostic } from "@typespec/compiler";
2
2
  import {
3
- BasicTestRunner,
3
+ type BasicTestRunner,
4
4
  createTestHost,
5
5
  createTestWrapper,
6
- TestHostConfig,
7
- TypeSpecTestLibrary,
6
+ type TestHostConfig,
7
+ type TypeSpecTestLibrary,
8
8
  } from "@typespec/compiler/testing";
9
9
  import { HttpTestLibrary } from "@typespec/http/testing";
10
10
  import { RestTestLibrary } from "@typespec/rest/testing";
@@ -1,5 +1,5 @@
1
- import * as ay from "@alloy-js/core";
2
- import { Type } from "@typespec/compiler";
1
+ import { code } from "@alloy-js/core";
2
+ import type { Type } from "@typespec/compiler";
3
3
  import { TypeExpression } from "./type-expression.js";
4
4
 
5
5
  export interface ArrayExpressionProps {
@@ -7,5 +7,5 @@ export interface ArrayExpressionProps {
7
7
  }
8
8
 
9
9
  export function ArrayExpression({ elementType }: ArrayExpressionProps) {
10
- return ay.code`Array<${(<TypeExpression type={elementType} />)}>`;
10
+ return code`Array<${(<TypeExpression type={elementType} />)}>`;
11
11
  }
@@ -1,6 +1,6 @@
1
- import { splitProps } from "@alloy-js/core/jsx-runtime";
1
+ import { splitProps } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { Operation } from "@typespec/compiler";
3
+ import type { Operation } from "@typespec/compiler";
4
4
  import { buildParameterDescriptors, getReturnType } from "../utils/operation.js";
5
5
  import { TypeExpression } from "./type-expression.jsx";
6
6
 
@@ -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
  import { buildParameterDescriptors, getReturnType } from "../utils/operation.js";
4
4
  import { TypeExpression } from "./type-expression.jsx";
5
5
 
@@ -1,6 +1,6 @@
1
- import * as ay from "@alloy-js/core";
1
+ import { type Children, For, type Refkey } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { Enum, EnumMember as TspEnumMember, Union } from "@typespec/compiler";
3
+ import type { Enum, EnumMember as TspEnumMember, Union } from "@typespec/compiler";
4
4
  import { useTsp } from "../../core/context/tsp-context.js";
5
5
  import { reportDiagnostic } from "../../lib.js";
6
6
  import { declarationRefkeys, efRefkey } from "../utils/refkey.js";
@@ -38,7 +38,7 @@ export function EnumDeclaration(props: EnumDeclarationProps) {
38
38
  default={props.default}
39
39
  export={props.export}
40
40
  >
41
- <ay.For each={members} joiner={",\n"}>
41
+ <For each={members} joiner={",\n"}>
42
42
  {([key, value]) => {
43
43
  const memberDoc = $.type.getDoc(value);
44
44
  return (
@@ -51,15 +51,15 @@ export function EnumDeclaration(props: EnumDeclarationProps) {
51
51
  />
52
52
  );
53
53
  }}
54
- </ay.For>
54
+ </For>
55
55
  </ts.EnumDeclaration>
56
56
  );
57
57
  }
58
58
 
59
59
  export interface EnumMemberProps {
60
60
  type: TspEnumMember;
61
- doc?: ay.Children;
62
- refkey?: ay.Refkey;
61
+ doc?: Children;
62
+ refkey?: Refkey;
63
63
  }
64
64
 
65
65
  export function EnumMember(props: EnumMemberProps) {
@@ -1,5 +1,5 @@
1
1
  import * as ts from "@alloy-js/typescript";
2
- import { Model, Operation } from "@typespec/compiler";
2
+ import type { Model, Operation } from "@typespec/compiler";
3
3
  import { useTsp } from "../../core/index.js";
4
4
  import { buildParameterDescriptors, getReturnType } from "../utils/operation.js";
5
5
  import { declarationRefkeys } from "../utils/refkey.js";
@@ -1,6 +1,6 @@
1
- import { splitProps } from "@alloy-js/core/jsx-runtime";
1
+ import { splitProps } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { Operation } from "@typespec/compiler";
3
+ import type { Operation } from "@typespec/compiler";
4
4
  import { buildParameterDescriptors, getReturnType } from "../utils/operation.js";
5
5
  import { TypeExpression } from "./type-expression.jsx";
6
6
 
@@ -1,6 +1,6 @@
1
- import { splitProps } from "@alloy-js/core/jsx-runtime";
1
+ import { splitProps } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { Operation } from "@typespec/compiler";
3
+ import type { Operation } from "@typespec/compiler";
4
4
  import { buildParameterDescriptors, getReturnType } from "../utils/operation.js";
5
5
  import { TypeExpression } from "./type-expression.jsx";
6
6
 
@@ -1,15 +1,14 @@
1
- import * as ay from "@alloy-js/core";
2
- import { Children, mapJoin } from "@alloy-js/core";
1
+ import { Block, type Children, For, mapJoin } from "@alloy-js/core";
3
2
  import * as ts from "@alloy-js/typescript";
4
3
  import {
5
- Interface,
4
+ type Interface,
6
5
  isNeverType,
7
- Model,
8
- ModelProperty,
9
- Operation,
10
- RekeyableMap,
6
+ type Model,
7
+ type ModelProperty,
8
+ type Operation,
9
+ type RekeyableMap,
11
10
  } from "@typespec/compiler";
12
- import { Typekit } from "@typespec/compiler/typekit";
11
+ import type { Typekit } from "@typespec/compiler/typekit";
13
12
  import { createRekeyableMap } from "@typespec/compiler/utils";
14
13
  import { useTsp } from "../../core/context/tsp-context.js";
15
14
  import { reportDiagnostic } from "../../lib.js";
@@ -74,9 +73,9 @@ export interface InterfaceExpressionProps extends ts.InterfaceExpressionProps {
74
73
 
75
74
  export function InterfaceExpression(props: InterfaceExpressionProps) {
76
75
  return (
77
- <ay.Block>
76
+ <Block>
78
77
  <InterfaceBody {...props} />
79
- </ay.Block>
78
+ </Block>
80
79
  );
81
80
  }
82
81
 
@@ -156,11 +155,11 @@ function InterfaceBody(props: TypedInterfaceDeclarationProps): Children {
156
155
 
157
156
  return (
158
157
  <>
159
- <ay.For each={validTypeMembers} semicolon line {...enderProp}>
158
+ <For each={validTypeMembers} semicolon line {...enderProp}>
160
159
  {(typeMember) => {
161
160
  return <InterfaceMember type={typeMember} />;
162
161
  }}
163
- </ay.For>
162
+ </For>
164
163
  {props.children}
165
164
  </>
166
165
  );
@@ -1,6 +1,6 @@
1
- import { Children } from "@alloy-js/core";
1
+ import { type Children } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { isNeverType, ModelProperty, Operation } from "@typespec/compiler";
3
+ import { isNeverType, type ModelProperty, type Operation } from "@typespec/compiler";
4
4
  import { getHttpPart } from "@typespec/http";
5
5
  import { useTsp } from "../../core/context/tsp-context.js";
6
6
  import { InterfaceMethod } from "./interface-method.jsx";
@@ -1,6 +1,6 @@
1
- import { Children, splitProps } from "@alloy-js/core";
1
+ import { type Children, splitProps } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { Operation } from "@typespec/compiler";
3
+ import type { Operation } from "@typespec/compiler";
4
4
  import { useTsp } from "../../core/index.js";
5
5
  import { buildParameterDescriptors, getReturnType } from "../utils/operation.js";
6
6
  import { TypeExpression } from "./type-expression.jsx";
@@ -1,5 +1,5 @@
1
1
  import { code } from "@alloy-js/core";
2
- import { Type } from "@typespec/compiler";
2
+ import type { Type } from "@typespec/compiler";
3
3
  import { TypeExpression } from "./type-expression.js";
4
4
 
5
5
  export interface RecordExpressionProps {
@@ -1,5 +1,5 @@
1
1
  import * as ts from "@alloy-js/typescript";
2
- import { Type } from "@typespec/compiler";
2
+ import type { Type } from "@typespec/compiler";
3
3
  import { useTsp } from "../../core/context/tsp-context.js";
4
4
  import { reportDiagnostic } from "../../lib.js";
5
5
  import { declarationRefkeys } from "../utils/refkey.js";
@@ -1,5 +1,5 @@
1
1
  import * as ts from "@alloy-js/typescript";
2
- import { Type } from "@typespec/compiler";
2
+ import type { Type } from "@typespec/compiler";
3
3
  import { useTsp } from "../../core/index.js";
4
4
  import { declarationRefkeys } from "../utils/refkey.js";
5
5
  import { EnumDeclaration } from "./enum-declaration.js";
@@ -1,7 +1,7 @@
1
1
  import { For } from "@alloy-js/core";
2
2
  import { Reference, ValueExpression } from "@alloy-js/typescript";
3
- import { IntrinsicType, Model, Scalar, Type } from "@typespec/compiler";
4
- import { Typekit } from "@typespec/compiler/typekit";
3
+ import type { IntrinsicType, Model, Scalar, Type } from "@typespec/compiler";
4
+ import type { Typekit } from "@typespec/compiler/typekit";
5
5
  import "@typespec/http/experimental/typekit";
6
6
  import { useTsp } from "../../core/context/tsp-context.js";
7
7
  import { reportTypescriptDiagnostic } from "../../typescript/lib.js";
@@ -1,6 +1,6 @@
1
- import { Children, code, For, mapJoin, Refkey } from "@alloy-js/core";
1
+ import { type Children, code, For, mapJoin, type Refkey } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import {
3
+ import type {
4
4
  Discriminator,
5
5
  Model,
6
6
  ModelProperty,
@@ -9,7 +9,7 @@ import {
9
9
  Type,
10
10
  Union,
11
11
  } from "@typespec/compiler";
12
- import { Typekit } from "@typespec/compiler/typekit";
12
+ import type { Typekit } from "@typespec/compiler/typekit";
13
13
  import { createRekeyableMap } from "@typespec/compiler/utils";
14
14
  import { useTsp } from "../../core/context/tsp-context.js";
15
15
  import { reportDiagnostic } from "../../lib.js";
@@ -1,6 +1,6 @@
1
- import { Children } from "@alloy-js/core";
1
+ import { type Children } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { Enum, Union } from "@typespec/compiler";
3
+ import type { Enum, Union } from "@typespec/compiler";
4
4
  import { useTsp } from "../../core/context/tsp-context.js";
5
5
  import { reportDiagnostic } from "../../lib.js";
6
6
  import { declarationRefkeys } from "../utils/refkey.js";