@typespec/emitter-framework 0.9.0-dev.6 → 0.9.0-dev.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core/components/output.d.ts +4 -4
- package/dist/src/core/components/output.d.ts.map +1 -1
- package/dist/src/core/components/output.js +3 -3
- package/dist/src/core/context/name-policy-context.d.ts +2 -2
- package/dist/src/core/context/name-policy-context.d.ts.map +1 -1
- package/dist/src/core/context/tsp-context.d.ts +2 -2
- package/dist/src/core/context/tsp-context.d.ts.map +1 -1
- package/dist/src/core/transport-name-policy.d.ts +1 -1
- package/dist/src/core/transport-name-policy.d.ts.map +1 -1
- package/dist/src/core/write-output.d.ts +2 -2
- package/dist/src/core/write-output.d.ts.map +1 -1
- package/dist/src/csharp/components/class/declaration.d.ts +3 -3
- package/dist/src/csharp/components/class/declaration.d.ts.map +1 -1
- package/dist/src/csharp/components/class/declaration.js +2 -2
- package/dist/src/csharp/components/class/declaration.test.js +100 -115
- package/dist/src/csharp/components/{enum-declaration.d.ts → enum/declaration.d.ts} +4 -4
- package/dist/src/csharp/components/enum/declaration.d.ts.map +1 -0
- package/dist/src/csharp/components/{enum-declaration.js → enum/declaration.js} +6 -6
- package/dist/src/csharp/components/enum/declaration.test.d.ts +2 -0
- package/dist/src/csharp/components/enum/declaration.test.d.ts.map +1 -0
- package/dist/src/csharp/components/enum/declaration.test.js +309 -0
- package/dist/src/csharp/components/index.d.ts +1 -1
- package/dist/src/csharp/components/index.js +1 -1
- package/dist/src/csharp/components/property/property.d.ts +2 -2
- package/dist/src/csharp/components/property/property.d.ts.map +1 -1
- package/dist/src/csharp/components/property/property.test.js +14 -14
- package/dist/src/csharp/components/type-expression.d.ts +3 -3
- package/dist/src/csharp/components/type-expression.d.ts.map +1 -1
- package/dist/src/csharp/components/utils/doc-comments.d.ts +4 -4
- package/dist/src/csharp/components/utils/doc-comments.d.ts.map +1 -1
- package/dist/src/csharp/components/utils/doc-comments.js +2 -2
- package/dist/src/testing/index.d.ts +1 -1
- package/dist/src/testing/index.d.ts.map +1 -1
- package/dist/src/testing/scenario-test/harness.d.ts +2 -2
- package/dist/src/testing/scenario-test/harness.d.ts.map +1 -1
- package/dist/src/testing/scenario-test/test-host.d.ts +2 -2
- package/dist/src/testing/scenario-test/test-host.d.ts.map +1 -1
- package/dist/src/typescript/components/array-expression.d.ts +2 -3
- package/dist/src/typescript/components/array-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/array-expression.js +2 -2
- package/dist/src/typescript/components/arrow-function.d.ts +1 -1
- package/dist/src/typescript/components/arrow-function.d.ts.map +1 -1
- package/dist/src/typescript/components/class-method.d.ts +1 -1
- package/dist/src/typescript/components/class-method.d.ts.map +1 -1
- package/dist/src/typescript/components/enum-declaration.d.ts +6 -6
- package/dist/src/typescript/components/enum-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/enum-declaration.js +2 -2
- package/dist/src/typescript/components/function-declaration.d.ts +1 -1
- package/dist/src/typescript/components/function-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/function-expression.d.ts +1 -1
- package/dist/src/typescript/components/function-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/function-type.d.ts +1 -1
- package/dist/src/typescript/components/function-type.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-declaration.d.ts +4 -4
- package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-declaration.js +3 -4
- package/dist/src/typescript/components/interface-member.d.ts +2 -2
- package/dist/src/typescript/components/interface-member.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-method.d.ts +2 -2
- package/dist/src/typescript/components/interface-method.d.ts.map +1 -1
- package/dist/src/typescript/components/record-expression.d.ts +1 -1
- package/dist/src/typescript/components/record-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/type-alias-declaration.d.ts +1 -1
- package/dist/src/typescript/components/type-alias-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/type-declaration.d.ts +1 -1
- package/dist/src/typescript/components/type-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/type-expression.d.ts +1 -1
- package/dist/src/typescript/components/type-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/type-transform.d.ts +2 -2
- package/dist/src/typescript/components/type-transform.d.ts.map +1 -1
- package/dist/src/typescript/components/union-declaration.d.ts +2 -2
- package/dist/src/typescript/components/union-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/union-expression.d.ts +3 -4
- package/dist/src/typescript/components/union-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/union-expression.js +3 -3
- package/dist/src/typescript/components/value-expression.d.ts +2 -2
- package/dist/src/typescript/components/value-expression.d.ts.map +1 -1
- package/dist/src/typescript/utils/operation.d.ts +2 -2
- package/dist/src/typescript/utils/operation.d.ts.map +1 -1
- package/dist/test/typescript/components/member-expression.test.js +5 -5
- package/dist/test/typescript/test-host.d.ts +1 -1
- package/dist/test/typescript/test-host.d.ts.map +1 -1
- package/dist/test/utils.d.ts +2 -2
- package/dist/test/utils.d.ts.map +1 -1
- package/package.json +7 -4
- package/src/core/components/output.tsx +9 -5
- package/src/core/context/name-policy-context.ts +2 -2
- package/src/core/context/tsp-context.ts +2 -2
- package/src/core/transport-name-policy.ts +1 -1
- package/src/core/write-output.ts +2 -2
- package/src/csharp/components/class/declaration.test.tsx +107 -169
- package/src/csharp/components/class/declaration.tsx +8 -8
- package/src/csharp/components/enum/declaration.test.tsx +267 -0
- package/src/csharp/components/{enum-declaration.tsx → enum/declaration.tsx} +9 -9
- package/src/csharp/components/index.ts +1 -1
- package/src/csharp/components/property/property.test.tsx +16 -16
- package/src/csharp/components/property/property.tsx +2 -2
- package/src/csharp/components/type-expression.test.tsx +3 -3
- package/src/csharp/components/type-expression.tsx +3 -3
- package/src/csharp/components/utils/doc-comments.tsx +6 -6
- package/src/testing/index.ts +1 -1
- package/src/testing/scenario-test/harness.ts +2 -2
- package/src/testing/scenario-test/test-host.ts +4 -4
- package/src/typescript/components/array-expression.tsx +3 -3
- package/src/typescript/components/arrow-function.tsx +1 -1
- package/src/typescript/components/class-method.tsx +1 -1
- package/src/typescript/components/enum-declaration.tsx +6 -6
- package/src/typescript/components/function-declaration.tsx +1 -1
- package/src/typescript/components/function-expression.tsx +1 -1
- package/src/typescript/components/function-type.tsx +1 -1
- package/src/typescript/components/interface-declaration.tsx +11 -12
- package/src/typescript/components/interface-member.tsx +2 -2
- package/src/typescript/components/interface-method.tsx +2 -2
- package/src/typescript/components/record-expression.tsx +1 -1
- package/src/typescript/components/type-alias-declaration.tsx +1 -1
- package/src/typescript/components/type-declaration.tsx +1 -1
- package/src/typescript/components/type-expression.tsx +2 -2
- package/src/typescript/components/type-transform.tsx +3 -3
- package/src/typescript/components/union-declaration.tsx +2 -2
- package/src/typescript/components/union-expression.tsx +12 -7
- package/src/typescript/components/value-expression.tsx +2 -2
- package/src/typescript/utils/operation.ts +2 -2
- package/test/testing/snippet-extractor-csharp.test.ts +1 -1
- package/test/testing/snippet-extractor-java.test.ts +1 -1
- package/test/testing/snippet-extractor-python.test.ts +1 -1
- package/test/testing/snippet-extractor-typescript.test.ts +1 -1
- package/test/typescript/components/arrow-function.test.tsx +2 -2
- package/test/typescript/components/enum-declaration.test.tsx +1 -1
- package/test/typescript/components/function-declaration.test.tsx +1 -1
- package/test/typescript/components/function-expression.test.tsx +2 -2
- package/test/typescript/components/function-type.test.tsx +2 -2
- package/test/typescript/components/interface-declaration.test.tsx +1 -1
- package/test/typescript/components/interface-method.test.tsx +2 -2
- package/test/typescript/components/member-expression.test.tsx +10 -10
- package/test/typescript/components/type-alias-declaration.test.tsx +1 -1
- package/test/typescript/components/type-transform.test.tsx +2 -2
- package/test/typescript/components/union-declaration.test.tsx +2 -2
- package/test/typescript/components/value-expression.test.tsx +6 -6
- package/test/typescript/test-host.ts +1 -1
- package/test/utils.ts +2 -2
- package/tsconfig.json +1 -0
- package/dist/src/csharp/components/enum-declaration.d.ts.map +0 -1
- package/dist/test/csharp/components/enum-declaration.test.d.ts +0 -2
- package/dist/test/csharp/components/enum-declaration.test.d.ts.map +0 -1
- package/dist/test/csharp/components/enum-declaration.test.js +0 -403
- package/dist/test/csharp/test-host.d.ts +0 -11
- package/dist/test/csharp/test-host.d.ts.map +0 -1
- package/dist/test/csharp/test-host.js +0 -32
- package/dist/test/csharp/utils.d.ts +0 -3
- package/dist/test/csharp/utils.d.ts.map +0 -1
- package/dist/test/csharp/utils.js +0 -6
- package/test/csharp/components/enum-declaration.test.tsx +0 -337
- package/test/csharp/test-host.ts +0 -42
- package/test/csharp/utils.ts +0 -8
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { Tester } from "#test/test-host.js";
|
|
2
|
+
import { type Children } from "@alloy-js/core";
|
|
3
|
+
import { createCSharpNamePolicy, Namespace, SourceFile } from "@alloy-js/csharp";
|
|
4
|
+
import { t, type TesterInstance } from "@typespec/compiler/testing";
|
|
5
|
+
import { beforeEach, expect, it } from "vitest";
|
|
6
|
+
import { Output } from "../../../core/index.js";
|
|
7
|
+
import { EnumDeclaration } from "../../index.js";
|
|
8
|
+
|
|
9
|
+
let runner: TesterInstance;
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
runner = await Tester.createInstance();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
function Wrapper(props: { children: Children }) {
|
|
16
|
+
const policy = createCSharpNamePolicy();
|
|
17
|
+
return (
|
|
18
|
+
<Output program={runner.program} namePolicy={policy}>
|
|
19
|
+
<Namespace name="TestNamespace">
|
|
20
|
+
<SourceFile path="test.cs">{props.children}</SourceFile>
|
|
21
|
+
</Namespace>
|
|
22
|
+
</Output>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
it("renders a basic enum declaration", async () => {
|
|
27
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
28
|
+
@test enum ${t.enum("TestEnum")} {
|
|
29
|
+
Value1;
|
|
30
|
+
Value2;
|
|
31
|
+
Value3;
|
|
32
|
+
}
|
|
33
|
+
`);
|
|
34
|
+
|
|
35
|
+
expect(
|
|
36
|
+
<Wrapper>
|
|
37
|
+
<EnumDeclaration type={TestEnum} />
|
|
38
|
+
</Wrapper>,
|
|
39
|
+
).toRenderTo(`
|
|
40
|
+
namespace TestNamespace
|
|
41
|
+
{
|
|
42
|
+
enum TestEnum
|
|
43
|
+
{
|
|
44
|
+
Value1,
|
|
45
|
+
Value2,
|
|
46
|
+
Value3
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
`);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("renders an empty enum declaration", async () => {
|
|
53
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
54
|
+
@test enum ${t.enum("TestEnum")} {}
|
|
55
|
+
`);
|
|
56
|
+
|
|
57
|
+
expect(
|
|
58
|
+
<Wrapper>
|
|
59
|
+
<EnumDeclaration type={TestEnum} />
|
|
60
|
+
</Wrapper>,
|
|
61
|
+
).toRenderTo(`
|
|
62
|
+
namespace TestNamespace
|
|
63
|
+
{
|
|
64
|
+
enum TestEnum
|
|
65
|
+
{
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
`);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("can override enum name", async () => {
|
|
73
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
74
|
+
@test enum ${t.enum("TestEnum")} {
|
|
75
|
+
Value1;
|
|
76
|
+
Value2;
|
|
77
|
+
}
|
|
78
|
+
`);
|
|
79
|
+
|
|
80
|
+
expect(
|
|
81
|
+
<Wrapper>
|
|
82
|
+
<EnumDeclaration type={TestEnum} name="CustomEnumName" />
|
|
83
|
+
</Wrapper>,
|
|
84
|
+
).toRenderTo(`
|
|
85
|
+
namespace TestNamespace
|
|
86
|
+
{
|
|
87
|
+
enum CustomEnumName
|
|
88
|
+
{
|
|
89
|
+
Value1,
|
|
90
|
+
Value2
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
`);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("renders an enum with access modifiers", async () => {
|
|
97
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
98
|
+
@test enum ${t.enum("TestEnum")} {
|
|
99
|
+
Value1;
|
|
100
|
+
Value2;
|
|
101
|
+
}
|
|
102
|
+
`);
|
|
103
|
+
|
|
104
|
+
expect(
|
|
105
|
+
<Wrapper>
|
|
106
|
+
<EnumDeclaration type={TestEnum} internal />
|
|
107
|
+
</Wrapper>,
|
|
108
|
+
).toRenderTo(`
|
|
109
|
+
namespace TestNamespace
|
|
110
|
+
{
|
|
111
|
+
internal enum TestEnum
|
|
112
|
+
{
|
|
113
|
+
Value1,
|
|
114
|
+
Value2
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
`);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("renders enum with C# naming conventions", async () => {
|
|
121
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
122
|
+
@test enum ${t.enum("TestEnum")} {
|
|
123
|
+
value_one;
|
|
124
|
+
value_two;
|
|
125
|
+
value_three;
|
|
126
|
+
}
|
|
127
|
+
`);
|
|
128
|
+
|
|
129
|
+
expect(
|
|
130
|
+
<Output program={runner.program} namePolicy={createCSharpNamePolicy()}>
|
|
131
|
+
<Namespace name="TestNamespace">
|
|
132
|
+
<SourceFile path="test.cs">
|
|
133
|
+
<EnumDeclaration type={TestEnum} />
|
|
134
|
+
</SourceFile>
|
|
135
|
+
</Namespace>
|
|
136
|
+
</Output>,
|
|
137
|
+
).toRenderTo(`
|
|
138
|
+
namespace TestNamespace
|
|
139
|
+
{
|
|
140
|
+
enum TestEnum
|
|
141
|
+
{
|
|
142
|
+
ValueOne,
|
|
143
|
+
ValueTwo,
|
|
144
|
+
ValueThree
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
`);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("renders enum with single value", async () => {
|
|
151
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
152
|
+
@test enum ${t.enum("TestEnum")} {
|
|
153
|
+
OnlyValue;
|
|
154
|
+
}
|
|
155
|
+
`);
|
|
156
|
+
|
|
157
|
+
expect(
|
|
158
|
+
<Wrapper>
|
|
159
|
+
<EnumDeclaration type={TestEnum} />
|
|
160
|
+
</Wrapper>,
|
|
161
|
+
).toRenderTo(`
|
|
162
|
+
namespace TestNamespace
|
|
163
|
+
{
|
|
164
|
+
enum TestEnum
|
|
165
|
+
{
|
|
166
|
+
OnlyValue
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
`);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("renders enum with numeric-like member names", async () => {
|
|
173
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
174
|
+
@test enum ${t.enum("TestEnum")} {
|
|
175
|
+
Value0;
|
|
176
|
+
Value1;
|
|
177
|
+
Value10;
|
|
178
|
+
Value100;
|
|
179
|
+
}
|
|
180
|
+
`);
|
|
181
|
+
|
|
182
|
+
expect(
|
|
183
|
+
<Wrapper>
|
|
184
|
+
<EnumDeclaration type={TestEnum} />
|
|
185
|
+
</Wrapper>,
|
|
186
|
+
).toRenderTo(`
|
|
187
|
+
namespace TestNamespace
|
|
188
|
+
{
|
|
189
|
+
enum TestEnum
|
|
190
|
+
{
|
|
191
|
+
Value0,
|
|
192
|
+
Value1,
|
|
193
|
+
Value10,
|
|
194
|
+
Value100
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
`);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("renders multiple enums in the same namespace", async () => {
|
|
201
|
+
const { TestEnum1, TestEnum2 } = await runner.compile(t.code`
|
|
202
|
+
@test enum ${t.enum("TestEnum1")} {
|
|
203
|
+
Value1;
|
|
204
|
+
Value2;
|
|
205
|
+
}
|
|
206
|
+
@test enum ${t.enum("TestEnum2")} {
|
|
207
|
+
OptionA;
|
|
208
|
+
OptionB;
|
|
209
|
+
OptionC;
|
|
210
|
+
}
|
|
211
|
+
`);
|
|
212
|
+
|
|
213
|
+
expect(
|
|
214
|
+
<Wrapper>
|
|
215
|
+
<EnumDeclaration type={TestEnum1} />
|
|
216
|
+
<hbr />
|
|
217
|
+
<EnumDeclaration type={TestEnum2} />
|
|
218
|
+
</Wrapper>,
|
|
219
|
+
).toRenderTo(`
|
|
220
|
+
namespace TestNamespace
|
|
221
|
+
{
|
|
222
|
+
enum TestEnum1
|
|
223
|
+
{
|
|
224
|
+
Value1,
|
|
225
|
+
Value2
|
|
226
|
+
}
|
|
227
|
+
enum TestEnum2
|
|
228
|
+
{
|
|
229
|
+
OptionA,
|
|
230
|
+
OptionB,
|
|
231
|
+
OptionC
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
`);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("renders an enum with doc comments", async () => {
|
|
238
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
239
|
+
@test enum ${t.enum("TestEnum")} {
|
|
240
|
+
@doc("This is value one")
|
|
241
|
+
Value1;
|
|
242
|
+
/** This is value two */
|
|
243
|
+
Value2;
|
|
244
|
+
}
|
|
245
|
+
`);
|
|
246
|
+
|
|
247
|
+
expect(
|
|
248
|
+
<Wrapper>
|
|
249
|
+
<EnumDeclaration type={TestEnum} />
|
|
250
|
+
</Wrapper>,
|
|
251
|
+
).toRenderTo(`
|
|
252
|
+
namespace TestNamespace
|
|
253
|
+
{
|
|
254
|
+
enum TestEnum
|
|
255
|
+
{
|
|
256
|
+
/// <summary>
|
|
257
|
+
/// This is value one
|
|
258
|
+
/// </summary>
|
|
259
|
+
Value1,
|
|
260
|
+
/// <summary>
|
|
261
|
+
/// This is value two
|
|
262
|
+
/// </summary>
|
|
263
|
+
Value2
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
`);
|
|
267
|
+
});
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useTsp } from "#core/context/tsp-context.js";
|
|
2
|
+
import { type Children, For } from "@alloy-js/core";
|
|
2
3
|
import * as cs from "@alloy-js/csharp";
|
|
3
|
-
import { Enum, Union } from "@typespec/compiler";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { declarationRefkeys, efRefkey } from "./utils/refkey.js";
|
|
4
|
+
import type { Enum, Union } from "@typespec/compiler";
|
|
5
|
+
import { reportDiagnostic } from "../../../lib.js";
|
|
6
|
+
import { getDocComments } from "../utils/doc-comments.jsx";
|
|
7
|
+
import { declarationRefkeys, efRefkey } from "../utils/refkey.js";
|
|
8
8
|
|
|
9
9
|
export interface EnumDeclarationProps extends Omit<cs.EnumDeclarationProps, "name"> {
|
|
10
10
|
name?: string;
|
|
11
11
|
type: Union | Enum;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export function EnumDeclaration(props: EnumDeclarationProps):
|
|
14
|
+
export function EnumDeclaration(props: EnumDeclarationProps): Children {
|
|
15
15
|
const { $ } = useTsp();
|
|
16
16
|
let type: Enum;
|
|
17
17
|
if ($.union.is(props.type)) {
|
|
@@ -33,7 +33,7 @@ export function EnumDeclaration(props: EnumDeclarationProps): ay.Children {
|
|
|
33
33
|
return (
|
|
34
34
|
<>
|
|
35
35
|
<cs.EnumDeclaration name={name} refkey={refkeys} {...props}>
|
|
36
|
-
<
|
|
36
|
+
<For each={members} joiner={",\n"}>
|
|
37
37
|
{([key, value]) => {
|
|
38
38
|
return (
|
|
39
39
|
<>
|
|
@@ -49,7 +49,7 @@ export function EnumDeclaration(props: EnumDeclarationProps): ay.Children {
|
|
|
49
49
|
</>
|
|
50
50
|
);
|
|
51
51
|
}}
|
|
52
|
-
</
|
|
52
|
+
</For>
|
|
53
53
|
</cs.EnumDeclaration>
|
|
54
54
|
</>
|
|
55
55
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Tester } from "#test/test-host.js";
|
|
2
|
-
import { Children } from "@alloy-js/core";
|
|
2
|
+
import { type Children } from "@alloy-js/core";
|
|
3
3
|
import { ClassDeclaration, createCSharpNamePolicy, Namespace, SourceFile } from "@alloy-js/csharp";
|
|
4
|
-
import { t, TesterInstance } from "@typespec/compiler/testing";
|
|
4
|
+
import { t, type TesterInstance } from "@typespec/compiler/testing";
|
|
5
5
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
6
6
|
import { Output } from "../../../core/components/output.jsx";
|
|
7
7
|
import { Property } from "./property.jsx";
|
|
@@ -39,10 +39,10 @@ it("maps prop: string | null to nullable property", async () => {
|
|
|
39
39
|
).toRenderTo(`
|
|
40
40
|
namespace TestNamespace
|
|
41
41
|
{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
class Test
|
|
43
|
+
{
|
|
44
|
+
public required string? Prop1 { get; set; }
|
|
45
|
+
}
|
|
46
46
|
}
|
|
47
47
|
`);
|
|
48
48
|
});
|
|
@@ -62,11 +62,11 @@ describe("jsonAttributes", () => {
|
|
|
62
62
|
).toRenderTo(`
|
|
63
63
|
namespace TestNamespace
|
|
64
64
|
{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
class Test
|
|
66
|
+
{
|
|
67
|
+
[System.Text.Json.JsonPropertyName("prop1")]
|
|
68
|
+
public required string Prop1 { get; set; }
|
|
69
|
+
}
|
|
70
70
|
}
|
|
71
71
|
`);
|
|
72
72
|
});
|
|
@@ -86,11 +86,11 @@ describe("jsonAttributes", () => {
|
|
|
86
86
|
).toRenderTo(`
|
|
87
87
|
namespace TestNamespace
|
|
88
88
|
{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
class Test
|
|
90
|
+
{
|
|
91
|
+
[System.Text.Json.JsonPropertyName("prop_1")]
|
|
92
|
+
public required string Prop1 { get; set; }
|
|
93
|
+
}
|
|
94
94
|
}
|
|
95
95
|
`);
|
|
96
96
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Children } from "@alloy-js/core";
|
|
1
|
+
import { type Children } from "@alloy-js/core";
|
|
2
2
|
import * as cs from "@alloy-js/csharp";
|
|
3
3
|
import { Attribute } from "@alloy-js/csharp";
|
|
4
|
-
import { ModelProperty, resolveEncodedName, Type } from "@typespec/compiler";
|
|
4
|
+
import { type ModelProperty, resolveEncodedName, type Type } from "@typespec/compiler";
|
|
5
5
|
import { useTsp } from "../../../core/index.js";
|
|
6
6
|
import { TypeExpression } from "../type-expression.jsx";
|
|
7
7
|
import { getDocComments } from "../utils/doc-comments.jsx";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Children, render } from "@alloy-js/core";
|
|
1
|
+
import { type Children, render } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { Namespace, SourceFile } from "@alloy-js/csharp";
|
|
4
|
-
import { Model, ModelProperty } from "@typespec/compiler";
|
|
5
|
-
import { BasicTestRunner } from "@typespec/compiler/testing";
|
|
4
|
+
import type { Model, ModelProperty } from "@typespec/compiler";
|
|
5
|
+
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
6
|
import { beforeEach, describe, it } from "vitest";
|
|
7
7
|
import { createEmitterFrameworkTestRunner } from "../../../test/typescript/test-host.js";
|
|
8
8
|
import { assertFileContents } from "../../../test/utils.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Children, code } from "@alloy-js/core";
|
|
1
|
+
import { type Children, code } from "@alloy-js/core";
|
|
2
2
|
import { Reference } from "@alloy-js/csharp";
|
|
3
|
-
import { getTypeName, 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";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type Children, List } from "@alloy-js/core";
|
|
2
2
|
import * as cs from "@alloy-js/csharp";
|
|
3
|
-
import { getReturnsDoc, Type } from "@typespec/compiler";
|
|
4
|
-
import { Typekit } from "@typespec/compiler/typekit";
|
|
3
|
+
import { getReturnsDoc, type Type } from "@typespec/compiler";
|
|
4
|
+
import type { Typekit } from "@typespec/compiler/typekit";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Helper to render a doc string for a given TypeSpec type.
|
|
@@ -12,13 +12,13 @@ import { Typekit } from "@typespec/compiler/typekit";
|
|
|
12
12
|
* @param type The TypeSpec type to generate documentation for
|
|
13
13
|
* @returns A DocSummary component containing the rendered doc string, or undefined if no doc is available.
|
|
14
14
|
*/
|
|
15
|
-
export function getDocComments($: Typekit, type: Type):
|
|
15
|
+
export function getDocComments($: Typekit, type: Type): Children {
|
|
16
16
|
const typeDoc = $.type.getDoc(type);
|
|
17
17
|
if (!typeDoc) {
|
|
18
18
|
return undefined;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const docElements:
|
|
21
|
+
const docElements: Children[] = [];
|
|
22
22
|
|
|
23
23
|
// Add main type documentation
|
|
24
24
|
docElements.push(
|
|
@@ -54,5 +54,5 @@ export function getDocComments($: Typekit, type: Type): ay.Children {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
return <
|
|
57
|
+
return <List doubleHardline>{docElements}</List>;
|
|
58
58
|
}
|
package/src/testing/index.ts
CHANGED
|
@@ -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
|
|
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
|
|
10
|
+
return code`Array<${(<TypeExpression type={elementType} />)}>`;
|
|
11
11
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
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
|
|
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
|
-
<
|
|
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
|
-
</
|
|
54
|
+
</For>
|
|
55
55
|
</ts.EnumDeclaration>
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
export interface EnumMemberProps {
|
|
60
60
|
type: TspEnumMember;
|
|
61
|
-
doc?:
|
|
62
|
-
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
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
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
|
|
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
|
-
<
|
|
76
|
+
<Block>
|
|
78
77
|
<InterfaceBody {...props} />
|
|
79
|
-
</
|
|
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
|
-
<
|
|
158
|
+
<For each={validTypeMembers} semicolon line {...enderProp}>
|
|
160
159
|
{(typeMember) => {
|
|
161
160
|
return <InterfaceMember type={typeMember} />;
|
|
162
161
|
}}
|
|
163
|
-
</
|
|
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 * 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";
|