@typespec/emitter-framework 0.10.0-dev.2 → 0.10.0-dev.3
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/write-output.js +10 -6
- package/dist/src/csharp/components/class/declaration.d.ts.map +1 -1
- package/dist/src/csharp/components/class/declaration.js +2 -1
- package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-declaration.js +2 -2
- package/dist/src/typescript/components/union/expression.test.js +3 -3
- package/dist/test/typescript/components/function-declaration.test.js +31 -112
- package/dist/test/typescript/components/interface-declaration.test.js +146 -308
- package/dist/test/typescript/components/type-alias-declaration.test.js +17 -75
- package/dist/test/typescript/components/type-transform.test.js +32 -83
- package/dist/test/typescript/components/value-expression.test.js +3 -6
- package/dist/test/typescript/utils.d.ts +7 -0
- package/dist/test/typescript/utils.d.ts.map +1 -0
- package/dist/test/typescript/utils.js +18 -0
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +2 -0
- package/package.json +7 -7
- package/src/core/write-output.ts +10 -6
- package/src/csharp/components/class/declaration.tsx +2 -1
- package/src/typescript/components/interface-declaration.tsx +3 -3
- package/src/typescript/components/union/expression.test.tsx +5 -5
- package/test/typescript/components/function-declaration.test.tsx +31 -121
- package/test/typescript/components/interface-declaration.test.tsx +123 -342
- package/test/typescript/components/type-alias-declaration.test.tsx +17 -76
- package/test/typescript/components/type-transform.test.tsx +32 -93
- package/test/typescript/components/value-expression.test.tsx +4 -12
- package/test/typescript/utils.tsx +12 -0
- package/test/utils.ts +2 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Children, For, mapJoin } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import {
|
|
4
4
|
type Interface,
|
|
@@ -73,9 +73,9 @@ export interface InterfaceExpressionProps extends ts.InterfaceExpressionProps {
|
|
|
73
73
|
|
|
74
74
|
export function InterfaceExpression(props: InterfaceExpressionProps) {
|
|
75
75
|
return (
|
|
76
|
-
<
|
|
76
|
+
<ts.InterfaceExpression>
|
|
77
77
|
<InterfaceBody {...props} />
|
|
78
|
-
</
|
|
78
|
+
</ts.InterfaceExpression>
|
|
79
79
|
);
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Output } from "#core/index.js";
|
|
2
1
|
import { Tester } from "#test/test-host.js";
|
|
2
|
+
import { TestFile } from "#test/typescript/utils.jsx";
|
|
3
3
|
import { t } from "@typespec/compiler/testing";
|
|
4
4
|
import { expect, it } from "vitest";
|
|
5
5
|
import { UnionExpression } from "./expression.jsx";
|
|
@@ -13,9 +13,9 @@ it("renders a union expression", async () => {
|
|
|
13
13
|
`);
|
|
14
14
|
|
|
15
15
|
expect(
|
|
16
|
-
<
|
|
16
|
+
<TestFile program={program}>
|
|
17
17
|
<UnionExpression type={TestUnion} />
|
|
18
|
-
</
|
|
18
|
+
</TestFile>,
|
|
19
19
|
).toRenderTo(`"one" | "two"`);
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -28,9 +28,9 @@ it("renders a union expression without conflicting names", async () => {
|
|
|
28
28
|
`);
|
|
29
29
|
|
|
30
30
|
expect(
|
|
31
|
-
<
|
|
31
|
+
<TestFile program={program}>
|
|
32
32
|
<UnionExpression type={TestUnion} />
|
|
33
|
-
</
|
|
33
|
+
</TestFile>,
|
|
34
34
|
).toRenderTo(`
|
|
35
35
|
{
|
|
36
36
|
common: "one";
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { code } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { SourceFile } from "@alloy-js/typescript";
|
|
4
4
|
import type { Namespace } from "@typespec/compiler";
|
|
5
|
-
import {
|
|
6
|
-
import { assert, describe, expect, it } from "vitest";
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
7
6
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
8
7
|
import { FunctionDeclaration } from "../../../src/typescript/components/function-declaration.js";
|
|
9
8
|
import { getProgram } from "../test-host.js";
|
|
@@ -19,21 +18,13 @@ describe("Typescript Function Declaration", () => {
|
|
|
19
18
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
20
19
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
expect(
|
|
23
22
|
<Output program={program}>
|
|
24
23
|
<SourceFile path="test.ts">
|
|
25
24
|
<FunctionDeclaration type={operation} />
|
|
26
25
|
</SourceFile>
|
|
27
26
|
</Output>,
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
31
|
-
assert(testFile, "test.ts file not rendered");
|
|
32
|
-
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
33
|
-
const expectedContent = await format(`function getName(id: string): string{}`, {
|
|
34
|
-
parser: "typescript",
|
|
35
|
-
});
|
|
36
|
-
expect(actualContent).toBe(expectedContent);
|
|
27
|
+
).toRenderTo(`function getName(id: string): string {}`);
|
|
37
28
|
});
|
|
38
29
|
|
|
39
30
|
it("creates a function with JSDoc", async () => {
|
|
@@ -50,31 +41,20 @@ describe("Typescript Function Declaration", () => {
|
|
|
50
41
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
51
42
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
52
43
|
|
|
53
|
-
|
|
44
|
+
expect(
|
|
54
45
|
<Output program={program}>
|
|
55
46
|
<SourceFile path="test.ts">
|
|
56
47
|
<FunctionDeclaration type={operation} />
|
|
57
48
|
</SourceFile>
|
|
58
49
|
</Output>,
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
62
|
-
assert(testFile, "test.ts file not rendered");
|
|
63
|
-
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
64
|
-
const expectedContent = await format(
|
|
65
|
-
`
|
|
50
|
+
).toRenderTo(`
|
|
66
51
|
/**
|
|
67
52
|
* This is a test function
|
|
68
|
-
*
|
|
53
|
+
*
|
|
69
54
|
* @param {string} id - This is the id
|
|
70
55
|
* @param {string} name
|
|
71
56
|
*/
|
|
72
|
-
function getName(id: string, name: string): string{}
|
|
73
|
-
{
|
|
74
|
-
parser: "typescript",
|
|
75
|
-
},
|
|
76
|
-
);
|
|
77
|
-
expect(actualContent).toBe(expectedContent);
|
|
57
|
+
function getName(id: string, name: string): string {}`);
|
|
78
58
|
});
|
|
79
59
|
|
|
80
60
|
it("creates a function with overridden JSDoc", async () => {
|
|
@@ -88,30 +68,19 @@ describe("Typescript Function Declaration", () => {
|
|
|
88
68
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
89
69
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
90
70
|
|
|
91
|
-
|
|
71
|
+
expect(
|
|
92
72
|
<Output program={program}>
|
|
93
73
|
<SourceFile path="test.ts">
|
|
94
74
|
<FunctionDeclaration doc={["This is a custom description"]} type={operation} />
|
|
95
75
|
</SourceFile>
|
|
96
76
|
</Output>,
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
100
|
-
assert(testFile, "test.ts file not rendered");
|
|
101
|
-
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
102
|
-
const expectedContent = await format(
|
|
103
|
-
`
|
|
77
|
+
).toRenderTo(`
|
|
104
78
|
/**
|
|
105
79
|
* This is a custom description
|
|
106
80
|
*
|
|
107
81
|
* @param {string} id
|
|
108
82
|
*/
|
|
109
|
-
function getName(id: string): string{}
|
|
110
|
-
{
|
|
111
|
-
parser: "typescript",
|
|
112
|
-
},
|
|
113
|
-
);
|
|
114
|
-
expect(actualContent).toBe(expectedContent);
|
|
83
|
+
function getName(id: string): string {}`);
|
|
115
84
|
});
|
|
116
85
|
|
|
117
86
|
it("creates an async function", async () => {
|
|
@@ -123,27 +92,13 @@ describe("Typescript Function Declaration", () => {
|
|
|
123
92
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
124
93
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
125
94
|
|
|
126
|
-
|
|
95
|
+
expect(
|
|
127
96
|
<Output program={program}>
|
|
128
97
|
<SourceFile path="test.ts">
|
|
129
98
|
<FunctionDeclaration async type={operation} />
|
|
130
99
|
</SourceFile>
|
|
131
100
|
</Output>,
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
135
|
-
assert(testFile, "test.ts file not rendered");
|
|
136
|
-
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
137
|
-
const expectedContent = await format(
|
|
138
|
-
d`async function getName(id: string): Promise<string> {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}`,
|
|
142
|
-
{
|
|
143
|
-
parser: "typescript",
|
|
144
|
-
},
|
|
145
|
-
);
|
|
146
|
-
expect(actualContent).toBe(expectedContent);
|
|
101
|
+
).toRenderTo(d`async function getName(id: string): Promise<string> {}`);
|
|
147
102
|
});
|
|
148
103
|
|
|
149
104
|
it("exports a function", async () => {
|
|
@@ -155,21 +110,13 @@ describe("Typescript Function Declaration", () => {
|
|
|
155
110
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
156
111
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
157
112
|
|
|
158
|
-
|
|
113
|
+
expect(
|
|
159
114
|
<Output program={program}>
|
|
160
115
|
<SourceFile path="test.ts">
|
|
161
116
|
<FunctionDeclaration export type={operation} />
|
|
162
117
|
</SourceFile>
|
|
163
118
|
</Output>,
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
167
|
-
assert(testFile, "test.ts file not rendered");
|
|
168
|
-
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
169
|
-
const expectedContent = await format(`export function getName(id: string): string{}`, {
|
|
170
|
-
parser: "typescript",
|
|
171
|
-
});
|
|
172
|
-
expect(actualContent).toBe(expectedContent);
|
|
119
|
+
).toRenderTo(`export function getName(id: string): string {}`);
|
|
173
120
|
});
|
|
174
121
|
|
|
175
122
|
it("can override name", async () => {
|
|
@@ -181,21 +128,13 @@ describe("Typescript Function Declaration", () => {
|
|
|
181
128
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
182
129
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
183
130
|
|
|
184
|
-
|
|
131
|
+
expect(
|
|
185
132
|
<Output program={program}>
|
|
186
133
|
<SourceFile path="test.ts">
|
|
187
134
|
<FunctionDeclaration name="newName" type={operation} />
|
|
188
135
|
</SourceFile>
|
|
189
136
|
</Output>,
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
193
|
-
assert(testFile, "test.ts file not rendered");
|
|
194
|
-
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
195
|
-
const expectedContent = await format(`function newName(id: string): string{}`, {
|
|
196
|
-
parser: "typescript",
|
|
197
|
-
});
|
|
198
|
-
expect(actualContent).toBe(expectedContent);
|
|
137
|
+
).toRenderTo(`function newName(id: string): string {}`);
|
|
199
138
|
});
|
|
200
139
|
|
|
201
140
|
it("can append extra parameters with raw params provided", async () => {
|
|
@@ -207,7 +146,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
207
146
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
208
147
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
209
148
|
|
|
210
|
-
|
|
149
|
+
expect(
|
|
211
150
|
<Output program={program}>
|
|
212
151
|
<SourceFile path="test.ts">
|
|
213
152
|
<FunctionDeclaration
|
|
@@ -219,18 +158,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
219
158
|
/>
|
|
220
159
|
</SourceFile>
|
|
221
160
|
</Output>,
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
225
|
-
assert(testFile, "test.ts file not rendered");
|
|
226
|
-
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
227
|
-
const expectedContent = await format(
|
|
228
|
-
`function createPerson(name: string, age: number, id: string): string{}`,
|
|
229
|
-
{
|
|
230
|
-
parser: "typescript",
|
|
231
|
-
},
|
|
232
|
-
);
|
|
233
|
-
expect(actualContent).toBe(expectedContent);
|
|
161
|
+
).toRenderTo(`function createPerson(name: string, age: number, id: string): string {}`);
|
|
234
162
|
});
|
|
235
163
|
|
|
236
164
|
it.skip("can override parameters with an array of ModelProperties", async () => {
|
|
@@ -248,7 +176,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
248
176
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
249
177
|
const model = Array.from((namespace as Namespace).models.values())[0];
|
|
250
178
|
|
|
251
|
-
|
|
179
|
+
expect(
|
|
252
180
|
<Output program={program}>
|
|
253
181
|
<SourceFile path="test.ts">
|
|
254
182
|
<FunctionDeclaration type={operation}>
|
|
@@ -256,18 +184,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
256
184
|
</FunctionDeclaration>
|
|
257
185
|
</SourceFile>
|
|
258
186
|
</Output>,
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
262
|
-
assert(testFile, "test.ts file not rendered");
|
|
263
|
-
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
264
|
-
|
|
265
|
-
const expectedContent = await format(
|
|
266
|
-
`function createPerson(name: string, age: number): string{}`,
|
|
267
|
-
{ parser: "typescript" },
|
|
268
|
-
);
|
|
269
|
-
|
|
270
|
-
expect(actualContent).toBe(expectedContent);
|
|
187
|
+
).toRenderTo(`function createPerson(name: string, age: number): string {}`);
|
|
271
188
|
});
|
|
272
189
|
|
|
273
190
|
it("can render function body", async () => {
|
|
@@ -279,29 +196,22 @@ describe("Typescript Function Declaration", () => {
|
|
|
279
196
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
280
197
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
281
198
|
|
|
282
|
-
|
|
199
|
+
expect(
|
|
283
200
|
<Output program={program}>
|
|
284
201
|
<SourceFile path="test.ts">
|
|
285
202
|
<FunctionDeclaration export type={operation}>
|
|
286
|
-
|
|
203
|
+
{code`
|
|
204
|
+
const message = "Hello World!";
|
|
205
|
+
console.log(message);
|
|
206
|
+
`}
|
|
287
207
|
</FunctionDeclaration>
|
|
288
208
|
</SourceFile>
|
|
289
209
|
</Output>,
|
|
290
|
-
)
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const expectedContent = await format(
|
|
297
|
-
`export function createPerson(id: string): string {
|
|
298
|
-
const message = "Hello World!";
|
|
299
|
-
console.log(message);
|
|
300
|
-
}`,
|
|
301
|
-
{ parser: "typescript" },
|
|
302
|
-
);
|
|
303
|
-
|
|
304
|
-
expect(actualContent).toBe(expectedContent);
|
|
210
|
+
).toRenderTo(`
|
|
211
|
+
export function createPerson(id: string): string {
|
|
212
|
+
const message = "Hello World!";
|
|
213
|
+
console.log(message);
|
|
214
|
+
}`);
|
|
305
215
|
});
|
|
306
216
|
});
|
|
307
217
|
});
|