@typespec/emitter-framework 0.6.0-dev.6 → 0.7.0-dev.0
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/CHANGELOG.md +17 -0
- package/dist/src/core/components/index.d.ts +2 -0
- package/dist/src/core/components/index.d.ts.map +1 -0
- package/dist/src/core/components/index.js +1 -0
- package/dist/src/core/components/output.d.ts +10 -0
- package/dist/src/core/components/output.d.ts.map +1 -0
- package/dist/src/core/components/output.js +16 -0
- package/dist/src/core/context/index.d.ts +1 -0
- package/dist/src/core/context/index.d.ts.map +1 -1
- package/dist/src/core/context/index.js +2 -1
- package/dist/src/core/context/tsp-context.d.ts +13 -0
- package/dist/src/core/context/tsp-context.d.ts.map +1 -0
- package/dist/src/core/context/tsp-context.js +13 -0
- package/dist/src/core/index.d.ts +1 -0
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +1 -0
- package/dist/src/core/write-output.d.ts +2 -1
- package/dist/src/core/write-output.d.ts.map +1 -1
- package/dist/src/core/write-output.js +5 -6
- package/dist/src/typescript/components/enum-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/enum-declaration.js +4 -1
- package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-declaration.js +9 -3
- package/dist/src/typescript/components/interface-member.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-member.js +4 -1
- package/dist/src/typescript/components/type-alias-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/type-alias-declaration.js +4 -1
- package/dist/src/typescript/components/type-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/type-expression.js +8 -5
- package/dist/src/typescript/components/type-transform.d.ts.map +1 -1
- package/dist/src/typescript/components/type-transform.js +26 -5
- package/dist/src/typescript/components/union-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/union-declaration.js +4 -1
- package/dist/src/typescript/components/union-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/union-expression.js +4 -1
- package/dist/src/typescript/utils/operation.d.ts.map +1 -1
- package/dist/src/typescript/utils/operation.js +7 -1
- package/dist/test/typescript/components/arrow-function.test.js +11 -1
- package/dist/test/typescript/components/enum-declaration.test.js +47 -18
- package/dist/test/typescript/components/function-declaration.test.js +9 -1
- package/dist/test/typescript/components/function-expression.test.js +11 -1
- package/dist/test/typescript/components/function-type.test.js +11 -1
- package/dist/test/typescript/components/interface-declaration.test.js +20 -2
- package/dist/test/typescript/components/interface-method.test.js +26 -2
- package/dist/test/typescript/components/member-expression.test.js +61 -32
- package/dist/test/typescript/components/type-alias-declaration.test.js +9 -1
- package/dist/test/typescript/components/union-declaration.test.js +9 -1
- package/dist/test/typescript/components/value-expression.test.js +9 -7
- package/package.json +7 -7
- package/src/core/components/index.tsx +1 -0
- package/src/core/components/output.tsx +19 -0
- package/src/core/context/index.ts +1 -0
- package/src/core/context/tsp-context.ts +30 -0
- package/src/core/index.ts +1 -0
- package/src/core/write-output.ts +14 -7
- package/src/typescript/components/enum-declaration.tsx +2 -1
- package/src/typescript/components/interface-declaration.tsx +7 -3
- package/src/typescript/components/interface-member.tsx +2 -1
- package/src/typescript/components/type-alias-declaration.tsx +2 -1
- package/src/typescript/components/type-expression.tsx +7 -5
- package/src/typescript/components/type-transform.tsx +17 -5
- package/src/typescript/components/union-declaration.tsx +2 -1
- package/src/typescript/components/union-expression.tsx +2 -1
- package/src/typescript/utils/operation.ts +3 -1
- package/test/typescript/components/arrow-function.test.tsx +5 -4
- package/test/typescript/components/enum-declaration.test.tsx +29 -16
- package/test/typescript/components/function-declaration.test.tsx +9 -8
- package/test/typescript/components/function-expression.test.tsx +5 -4
- package/test/typescript/components/function-type.test.tsx +5 -4
- package/test/typescript/components/interface-declaration.test.tsx +20 -20
- package/test/typescript/components/interface-method.test.tsx +12 -10
- package/test/typescript/components/member-expression.test.tsx +25 -16
- package/test/typescript/components/type-alias-declaration.test.tsx +7 -6
- package/test/typescript/components/union-declaration.test.tsx +9 -7
- package/test/typescript/components/value-expression.test.tsx +22 -8
|
@@ -2,6 +2,7 @@ import { List, refkey, StatementList } from "@alloy-js/core";
|
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { Enum, Union } from "@typespec/compiler";
|
|
4
4
|
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { TspContext } from "../../../src/core/index.js";
|
|
5
6
|
import { EnumDeclaration } from "../../../src/typescript/components/enum-declaration.js";
|
|
6
7
|
import { getEmitOutput } from "../../utils.js";
|
|
7
8
|
|
|
@@ -16,7 +17,11 @@ describe("Typescript Enum Declaration", () => {
|
|
|
16
17
|
`;
|
|
17
18
|
const output = await getEmitOutput(code, (program) => {
|
|
18
19
|
const Foo = program.resolveTypeReference("Foo")[0]! as Enum;
|
|
19
|
-
return
|
|
20
|
+
return (
|
|
21
|
+
<TspContext.Provider value={{ program }}>
|
|
22
|
+
<EnumDeclaration type={Foo} />
|
|
23
|
+
</TspContext.Provider>
|
|
24
|
+
);
|
|
20
25
|
});
|
|
21
26
|
|
|
22
27
|
expect(output).toBe(d`
|
|
@@ -38,7 +43,11 @@ describe("Typescript Enum Declaration", () => {
|
|
|
38
43
|
`;
|
|
39
44
|
const output = await getEmitOutput(code, (program) => {
|
|
40
45
|
const Foo = program.resolveTypeReference("Foo")[0]! as Union;
|
|
41
|
-
return
|
|
46
|
+
return (
|
|
47
|
+
<TspContext.Provider value={{ program }}>
|
|
48
|
+
<EnumDeclaration type={Foo} />
|
|
49
|
+
</TspContext.Provider>
|
|
50
|
+
);
|
|
42
51
|
});
|
|
43
52
|
|
|
44
53
|
expect(output).toBe(d`
|
|
@@ -62,13 +71,15 @@ describe("Typescript Enum Declaration", () => {
|
|
|
62
71
|
const output = await getEmitOutput(code, (program) => {
|
|
63
72
|
const Foo = program.resolveTypeReference("Foo")[0]! as Enum;
|
|
64
73
|
return (
|
|
65
|
-
<
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
<TspContext.Provider value={{ program }}>
|
|
75
|
+
<List hardline>
|
|
76
|
+
<EnumDeclaration type={Foo} />
|
|
77
|
+
<StatementList>
|
|
78
|
+
{refkey(Foo)}
|
|
79
|
+
{refkey(Foo.members.get("one"))}
|
|
80
|
+
</StatementList>
|
|
81
|
+
</List>
|
|
82
|
+
</TspContext.Provider>
|
|
72
83
|
);
|
|
73
84
|
});
|
|
74
85
|
|
|
@@ -95,13 +106,15 @@ describe("Typescript Enum Declaration", () => {
|
|
|
95
106
|
const output = await getEmitOutput(code, (program) => {
|
|
96
107
|
const Foo = program.resolveTypeReference("Foo")[0]! as Union;
|
|
97
108
|
return (
|
|
98
|
-
<
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
109
|
+
<TspContext.Provider value={{ program }}>
|
|
110
|
+
<List hardline>
|
|
111
|
+
<EnumDeclaration type={Foo} />
|
|
112
|
+
<StatementList>
|
|
113
|
+
{refkey(Foo)}
|
|
114
|
+
{refkey(Foo.variants.get("one"))}
|
|
115
|
+
</StatementList>
|
|
116
|
+
</List>
|
|
117
|
+
</TspContext.Provider>
|
|
105
118
|
);
|
|
106
119
|
});
|
|
107
120
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { SourceFile } from "@alloy-js/typescript";
|
|
4
4
|
import { Namespace } from "@typespec/compiler";
|
|
5
5
|
import { format } from "prettier";
|
|
6
6
|
import { assert, describe, expect, it } from "vitest";
|
|
7
|
+
import { Output } from "../../../src/core/components/output.jsx";
|
|
7
8
|
import { FunctionDeclaration } from "../../../src/typescript/components/function-declaration.js";
|
|
8
9
|
import { getProgram } from "../test-host.js";
|
|
9
10
|
describe("Typescript Function Declaration", () => {
|
|
@@ -19,7 +20,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
19
20
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
20
21
|
|
|
21
22
|
const res = render(
|
|
22
|
-
<Output>
|
|
23
|
+
<Output program={program}>
|
|
23
24
|
<SourceFile path="test.ts">
|
|
24
25
|
<FunctionDeclaration type={operation} />
|
|
25
26
|
</SourceFile>
|
|
@@ -45,7 +46,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
45
46
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
46
47
|
|
|
47
48
|
const res = render(
|
|
48
|
-
<Output>
|
|
49
|
+
<Output program={program}>
|
|
49
50
|
<SourceFile path="test.ts">
|
|
50
51
|
<FunctionDeclaration async type={operation} />
|
|
51
52
|
</SourceFile>
|
|
@@ -77,7 +78,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
77
78
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
78
79
|
|
|
79
80
|
const res = render(
|
|
80
|
-
<Output>
|
|
81
|
+
<Output program={program}>
|
|
81
82
|
<SourceFile path="test.ts">
|
|
82
83
|
<FunctionDeclaration export type={operation} />
|
|
83
84
|
</SourceFile>
|
|
@@ -103,7 +104,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
103
104
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
104
105
|
|
|
105
106
|
const res = render(
|
|
106
|
-
<Output>
|
|
107
|
+
<Output program={program}>
|
|
107
108
|
<SourceFile path="test.ts">
|
|
108
109
|
<FunctionDeclaration name="newName" type={operation} />
|
|
109
110
|
</SourceFile>
|
|
@@ -129,7 +130,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
129
130
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
130
131
|
|
|
131
132
|
const res = render(
|
|
132
|
-
<Output>
|
|
133
|
+
<Output program={program}>
|
|
133
134
|
<SourceFile path="test.ts">
|
|
134
135
|
<FunctionDeclaration
|
|
135
136
|
type={operation}
|
|
@@ -170,7 +171,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
170
171
|
const model = Array.from((namespace as Namespace).models.values())[0];
|
|
171
172
|
|
|
172
173
|
const res = render(
|
|
173
|
-
<Output>
|
|
174
|
+
<Output program={program}>
|
|
174
175
|
<SourceFile path="test.ts">
|
|
175
176
|
<FunctionDeclaration type={operation}>
|
|
176
177
|
<FunctionDeclaration.Parameters type={model} />
|
|
@@ -201,7 +202,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
201
202
|
const operation = Array.from((namespace as Namespace).operations.values())[0];
|
|
202
203
|
|
|
203
204
|
const res = render(
|
|
204
|
-
<Output>
|
|
205
|
+
<Output program={program}>
|
|
205
206
|
<SourceFile path="test.ts">
|
|
206
207
|
<FunctionDeclaration export type={operation}>
|
|
207
208
|
const message = "Hello World!"; console.log(message);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { SourceFile } from "@alloy-js/typescript";
|
|
4
4
|
import { Operation } from "@typespec/compiler";
|
|
5
5
|
import { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
6
|
import { beforeEach, describe, it } from "vitest";
|
|
7
|
+
import { Output } from "../../../src/core/components/output.jsx";
|
|
7
8
|
import { FunctionExpression } from "../../../src/typescript/components/function-expression.jsx";
|
|
8
9
|
import { assertFileContents } from "../../utils.js";
|
|
9
10
|
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
@@ -21,7 +22,7 @@ describe("function expressions with a `type` prop", () => {
|
|
|
21
22
|
`)) as { getName: Operation };
|
|
22
23
|
|
|
23
24
|
const res = render(
|
|
24
|
-
<Output>
|
|
25
|
+
<Output program={runner.program}>
|
|
25
26
|
<SourceFile path="test.ts">
|
|
26
27
|
<FunctionExpression type={getName}>console.log("Hello!");</FunctionExpression>
|
|
27
28
|
</SourceFile>
|
|
@@ -44,7 +45,7 @@ describe("function expressions with a `type` prop", () => {
|
|
|
44
45
|
`)) as { getName: Operation };
|
|
45
46
|
|
|
46
47
|
const res = render(
|
|
47
|
-
<Output>
|
|
48
|
+
<Output program={runner.program}>
|
|
48
49
|
<SourceFile path="test.ts">
|
|
49
50
|
<FunctionExpression async type={getName} />
|
|
50
51
|
</SourceFile>
|
|
@@ -65,7 +66,7 @@ describe("function expressions with a `type` prop", () => {
|
|
|
65
66
|
`)) as { getName: Operation };
|
|
66
67
|
|
|
67
68
|
const res = render(
|
|
68
|
-
<Output>
|
|
69
|
+
<Output program={runner.program}>
|
|
69
70
|
<SourceFile path="test.ts">
|
|
70
71
|
<FunctionExpression
|
|
71
72
|
type={getName}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { SourceFile } from "@alloy-js/typescript";
|
|
4
4
|
import { Operation } from "@typespec/compiler";
|
|
5
5
|
import { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
6
|
import { beforeEach, describe, it } from "vitest";
|
|
7
|
+
import { Output } from "../../../src/core/components/output.jsx";
|
|
7
8
|
import { FunctionType } from "../../../src/typescript/index.js";
|
|
8
9
|
import { assertFileContents } from "../../utils.js";
|
|
9
10
|
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
@@ -21,7 +22,7 @@ describe("function types with a `type` prop", () => {
|
|
|
21
22
|
`)) as { getName: Operation };
|
|
22
23
|
|
|
23
24
|
const res = render(
|
|
24
|
-
<Output>
|
|
25
|
+
<Output program={runner.program}>
|
|
25
26
|
<SourceFile path="test.ts">
|
|
26
27
|
<FunctionType type={getName} />
|
|
27
28
|
</SourceFile>
|
|
@@ -42,7 +43,7 @@ describe("function types with a `type` prop", () => {
|
|
|
42
43
|
`)) as { getName: Operation };
|
|
43
44
|
|
|
44
45
|
const res = render(
|
|
45
|
-
<Output>
|
|
46
|
+
<Output program={runner.program}>
|
|
46
47
|
<SourceFile path="test.ts">
|
|
47
48
|
<FunctionType async type={getName} />
|
|
48
49
|
</SourceFile>
|
|
@@ -63,7 +64,7 @@ describe("function types with a `type` prop", () => {
|
|
|
63
64
|
`)) as { getName: Operation };
|
|
64
65
|
|
|
65
66
|
const res = render(
|
|
66
|
-
<Output>
|
|
67
|
+
<Output program={runner.program}>
|
|
67
68
|
<SourceFile path="test.ts">
|
|
68
69
|
<FunctionType type={getName} parameters={[{ name: "additionalParam", type: "number" }]} />
|
|
69
70
|
</SourceFile>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { For, List, Output, render } from "@alloy-js/core";
|
|
1
|
+
import { For, List, render } from "@alloy-js/core";
|
|
4
2
|
import { SourceFile } from "@alloy-js/typescript";
|
|
5
3
|
import { Namespace } from "@typespec/compiler";
|
|
6
4
|
import { format } from "prettier";
|
|
7
5
|
import { assert, describe, expect, it } from "vitest";
|
|
6
|
+
import { Output } from "../../../src/core/components/output.jsx";
|
|
7
|
+
import { InterfaceDeclaration } from "../../../src/typescript/components/interface-declaration.js";
|
|
8
8
|
import { getProgram } from "../test-host.js";
|
|
9
9
|
|
|
10
10
|
describe("Typescript Interface", () => {
|
|
@@ -24,7 +24,7 @@ describe("Typescript Interface", () => {
|
|
|
24
24
|
const models = Array.from((namespace as Namespace).models.values());
|
|
25
25
|
|
|
26
26
|
const res = render(
|
|
27
|
-
<Output>
|
|
27
|
+
<Output program={program}>
|
|
28
28
|
<SourceFile path="test.ts">
|
|
29
29
|
<List hardline>
|
|
30
30
|
{models.map((model) => (
|
|
@@ -63,7 +63,7 @@ describe("Typescript Interface", () => {
|
|
|
63
63
|
const models = (namespace as Namespace).models;
|
|
64
64
|
|
|
65
65
|
const res = render(
|
|
66
|
-
<Output>
|
|
66
|
+
<Output program={program}>
|
|
67
67
|
<SourceFile path="test.ts">
|
|
68
68
|
<For each={Array.from(models.values())} hardline>
|
|
69
69
|
{(model) => <InterfaceDeclaration export type={model} />}
|
|
@@ -97,7 +97,7 @@ describe("Typescript Interface", () => {
|
|
|
97
97
|
const models = (namespace as Namespace).models;
|
|
98
98
|
|
|
99
99
|
const res = render(
|
|
100
|
-
<Output>
|
|
100
|
+
<Output program={program}>
|
|
101
101
|
<SourceFile path="test.ts">
|
|
102
102
|
<For each={Array.from(models.values())} hardline>
|
|
103
103
|
{(model) => <InterfaceDeclaration export type={model} />}
|
|
@@ -135,7 +135,7 @@ describe("Typescript Interface", () => {
|
|
|
135
135
|
const models = (namespace as Namespace).models;
|
|
136
136
|
|
|
137
137
|
const res = render(
|
|
138
|
-
<Output>
|
|
138
|
+
<Output program={program}>
|
|
139
139
|
<SourceFile path="test.ts">
|
|
140
140
|
<For each={Array.from(models.values())} hardline>
|
|
141
141
|
{(model) => <InterfaceDeclaration export type={model} />}
|
|
@@ -183,7 +183,7 @@ describe("Typescript Interface", () => {
|
|
|
183
183
|
const models = (namespace as Namespace).models;
|
|
184
184
|
|
|
185
185
|
const res = render(
|
|
186
|
-
<Output>
|
|
186
|
+
<Output program={program}>
|
|
187
187
|
<SourceFile path="test.ts">
|
|
188
188
|
<For each={Array.from(models.values())} hardline>
|
|
189
189
|
{(model) => <InterfaceDeclaration export type={model} />}
|
|
@@ -230,7 +230,7 @@ describe("Typescript Interface", () => {
|
|
|
230
230
|
const models = Array.from((namespace as Namespace).models.values());
|
|
231
231
|
|
|
232
232
|
const res = render(
|
|
233
|
-
<Output>
|
|
233
|
+
<Output program={program}>
|
|
234
234
|
<SourceFile path="test.ts">
|
|
235
235
|
{models.map((model) => (
|
|
236
236
|
<InterfaceDeclaration export type={model} />
|
|
@@ -277,7 +277,7 @@ describe("Typescript Interface", () => {
|
|
|
277
277
|
const models = Array.from((namespace as Namespace).models.values());
|
|
278
278
|
|
|
279
279
|
const res = render(
|
|
280
|
-
<Output>
|
|
280
|
+
<Output program={program}>
|
|
281
281
|
<SourceFile path="test.ts">
|
|
282
282
|
<InterfaceDeclaration type={models[0]} />
|
|
283
283
|
</SourceFile>
|
|
@@ -314,7 +314,7 @@ describe("Typescript Interface", () => {
|
|
|
314
314
|
const models = Array.from((namespace as Namespace).models.values());
|
|
315
315
|
|
|
316
316
|
const res = render(
|
|
317
|
-
<Output>
|
|
317
|
+
<Output program={program}>
|
|
318
318
|
<SourceFile path="test.ts">
|
|
319
319
|
<InterfaceDeclaration type={models[0]} />
|
|
320
320
|
</SourceFile>
|
|
@@ -350,7 +350,7 @@ describe("Typescript Interface", () => {
|
|
|
350
350
|
const models = Array.from((namespace as Namespace).models.values());
|
|
351
351
|
|
|
352
352
|
const res = render(
|
|
353
|
-
<Output>
|
|
353
|
+
<Output program={program}>
|
|
354
354
|
<SourceFile path="test.ts">
|
|
355
355
|
<InterfaceDeclaration export type={models[0]} />
|
|
356
356
|
</SourceFile>
|
|
@@ -385,7 +385,7 @@ describe("Typescript Interface", () => {
|
|
|
385
385
|
const models = Array.from((namespace as Namespace).models.values());
|
|
386
386
|
|
|
387
387
|
const res = render(
|
|
388
|
-
<Output>
|
|
388
|
+
<Output program={program}>
|
|
389
389
|
<SourceFile path="test.ts">
|
|
390
390
|
<InterfaceDeclaration export name="MyOperations" type={models[0]} />
|
|
391
391
|
</SourceFile>
|
|
@@ -423,7 +423,7 @@ describe("Typescript Interface", () => {
|
|
|
423
423
|
const models = Array.from((namespace as Namespace).models.values());
|
|
424
424
|
|
|
425
425
|
const res = render(
|
|
426
|
-
<Output>
|
|
426
|
+
<Output program={program}>
|
|
427
427
|
<SourceFile path="test.ts">
|
|
428
428
|
<InterfaceDeclaration export name="MyOperations" type={models[0]}>
|
|
429
429
|
customProperty: string; customMethod(): void;
|
|
@@ -465,7 +465,7 @@ describe("Typescript Interface", () => {
|
|
|
465
465
|
const models = Array.from((namespace as Namespace).models.values());
|
|
466
466
|
|
|
467
467
|
const res = render(
|
|
468
|
-
<Output>
|
|
468
|
+
<Output program={program}>
|
|
469
469
|
<SourceFile path="test.ts">
|
|
470
470
|
<InterfaceDeclaration export name="MyModel" type={models[0]} />
|
|
471
471
|
</SourceFile>
|
|
@@ -508,7 +508,7 @@ describe("Typescript Interface", () => {
|
|
|
508
508
|
const models = Array.from((namespace as Namespace).models.values());
|
|
509
509
|
|
|
510
510
|
const res = render(
|
|
511
|
-
<Output>
|
|
511
|
+
<Output program={program}>
|
|
512
512
|
<SourceFile path="test.ts">
|
|
513
513
|
{models.map((model) => (
|
|
514
514
|
<InterfaceDeclaration export type={model} />
|
|
@@ -552,7 +552,7 @@ describe("Typescript Interface", () => {
|
|
|
552
552
|
const interfaces = Array.from((namespace as Namespace).interfaces.values());
|
|
553
553
|
|
|
554
554
|
const res = render(
|
|
555
|
-
<Output>
|
|
555
|
+
<Output program={program}>
|
|
556
556
|
<SourceFile path="test.ts">
|
|
557
557
|
<InterfaceDeclaration export type={interfaces[0]} />
|
|
558
558
|
</SourceFile>
|
|
@@ -592,7 +592,7 @@ describe("Typescript Interface", () => {
|
|
|
592
592
|
const models = Array.from((namespace as Namespace).models.values());
|
|
593
593
|
|
|
594
594
|
const res = render(
|
|
595
|
-
<Output>
|
|
595
|
+
<Output program={program}>
|
|
596
596
|
<SourceFile path="test.ts">
|
|
597
597
|
<InterfaceDeclaration export type={interfaces[0]} />
|
|
598
598
|
<InterfaceDeclaration export type={models[0]} />
|
|
@@ -639,7 +639,7 @@ describe("Typescript Interface", () => {
|
|
|
639
639
|
const models = Array.from((namespace as Namespace).models.values());
|
|
640
640
|
|
|
641
641
|
const res = render(
|
|
642
|
-
<Output>
|
|
642
|
+
<Output program={program}>
|
|
643
643
|
<SourceFile path="test.ts">
|
|
644
644
|
<InterfaceDeclaration export type={interfaces[0]} />
|
|
645
645
|
{models.map((model) => (
|
|
@@ -692,7 +692,7 @@ describe("Typescript Interface", () => {
|
|
|
692
692
|
const models = Array.from((namespace as Namespace).models.values());
|
|
693
693
|
|
|
694
694
|
const res = render(
|
|
695
|
-
<Output>
|
|
695
|
+
<Output program={program}>
|
|
696
696
|
<SourceFile path="test.ts">
|
|
697
697
|
<InterfaceDeclaration export type={interfaces[1]} />
|
|
698
698
|
{models.map((model) => (
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { InterfaceDeclaration, SourceFile } from "@alloy-js/typescript";
|
|
4
4
|
import { Operation } from "@typespec/compiler";
|
|
5
5
|
import { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
6
|
import { beforeEach, describe, it } from "vitest";
|
|
7
|
+
import { Output } from "../../../src/core/components/output.jsx";
|
|
7
8
|
import { InterfaceMethod } from "../../../src/typescript/components/interface-method.jsx";
|
|
8
9
|
import { assertFileContents } from "../../utils.js";
|
|
9
|
-
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
10
|
+
import { createEmitterFrameworkTestRunner, getProgram } from "../test-host.js";
|
|
10
11
|
|
|
11
12
|
describe("interface methods with a `type` prop", () => {
|
|
12
13
|
let runner: BasicTestRunner;
|
|
@@ -21,7 +22,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
21
22
|
`)) as { getName: Operation };
|
|
22
23
|
|
|
23
24
|
const res = render(
|
|
24
|
-
<Output>
|
|
25
|
+
<Output program={runner.program}>
|
|
25
26
|
<SourceFile path="test.ts">
|
|
26
27
|
<InterfaceDeclaration name="basicInterface">
|
|
27
28
|
<InterfaceMethod type={getName} name={getName.name} />
|
|
@@ -46,7 +47,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
46
47
|
`)) as { getName: Operation };
|
|
47
48
|
|
|
48
49
|
const res = render(
|
|
49
|
-
<Output>
|
|
50
|
+
<Output program={runner.program}>
|
|
50
51
|
<SourceFile path="test.ts">
|
|
51
52
|
<InterfaceDeclaration name="basicInterface">
|
|
52
53
|
<InterfaceMethod async type={getName} />
|
|
@@ -71,7 +72,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
71
72
|
`)) as { getName: Operation };
|
|
72
73
|
|
|
73
74
|
const res = render(
|
|
74
|
-
<Output>
|
|
75
|
+
<Output program={runner.program}>
|
|
75
76
|
<SourceFile path="test.ts">
|
|
76
77
|
<InterfaceDeclaration name="basicInterface">
|
|
77
78
|
<InterfaceMethod
|
|
@@ -100,7 +101,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
100
101
|
`)) as { getName: Operation };
|
|
101
102
|
|
|
102
103
|
const res = render(
|
|
103
|
-
<Output>
|
|
104
|
+
<Output program={runner.program}>
|
|
104
105
|
<SourceFile path="test.ts">
|
|
105
106
|
<InterfaceDeclaration name="basicInterface">
|
|
106
107
|
<InterfaceMethod
|
|
@@ -129,7 +130,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
129
130
|
`)) as { getName: Operation };
|
|
130
131
|
|
|
131
132
|
const res = render(
|
|
132
|
-
<Output>
|
|
133
|
+
<Output program={runner.program}>
|
|
133
134
|
<SourceFile path="test.ts">
|
|
134
135
|
<InterfaceDeclaration name="basicInterface">
|
|
135
136
|
<InterfaceMethod
|
|
@@ -161,7 +162,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
161
162
|
`)) as { getName: Operation };
|
|
162
163
|
|
|
163
164
|
const res = render(
|
|
164
|
-
<Output>
|
|
165
|
+
<Output program={runner.program}>
|
|
165
166
|
<SourceFile path="test.ts">
|
|
166
167
|
<InterfaceDeclaration name="basicInterface">
|
|
167
168
|
<InterfaceMethod type={getName} returnType="Promise<Record<string, unknown>>" />
|
|
@@ -186,7 +187,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
186
187
|
`)) as { getName: Operation };
|
|
187
188
|
|
|
188
189
|
const res = render(
|
|
189
|
-
<Output>
|
|
190
|
+
<Output program={runner.program}>
|
|
190
191
|
<SourceFile path="test.ts">
|
|
191
192
|
<InterfaceDeclaration name="basicInterface">
|
|
192
193
|
<InterfaceMethod type={getName} name="getNameCustom" />
|
|
@@ -208,8 +209,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
208
209
|
|
|
209
210
|
describe("interface methods without a `type` prop", () => {
|
|
210
211
|
it("renders a plain interface method", async () => {
|
|
212
|
+
const program = await getProgram("");
|
|
211
213
|
const res = render(
|
|
212
|
-
<Output>
|
|
214
|
+
<Output program={program}>
|
|
213
215
|
<SourceFile path="test.ts">
|
|
214
216
|
<InterfaceDeclaration name="basicInterface">
|
|
215
217
|
<InterfaceMethod
|
|
@@ -2,6 +2,7 @@ import * as ay from "@alloy-js/core";
|
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { Enum, Model, Union } from "@typespec/compiler";
|
|
4
4
|
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { TspContext } from "../../../src/core/index.js";
|
|
5
6
|
import { EnumDeclaration } from "../../../src/typescript/components/enum-declaration.js";
|
|
6
7
|
import { InterfaceDeclaration, UnionDeclaration } from "../../../src/typescript/index.js";
|
|
7
8
|
import { getEmitOutput } from "../../utils.js";
|
|
@@ -22,10 +23,12 @@ describe("Typescript Enum Member Expression", () => {
|
|
|
22
23
|
const output = await getEmitOutput(code, (program) => {
|
|
23
24
|
const Bar = program.resolveTypeReference("Bar")[0]! as Model;
|
|
24
25
|
return (
|
|
25
|
-
<
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
<TspContext.Provider value={{ program }}>
|
|
27
|
+
<ay.List hardline>
|
|
28
|
+
<EnumDeclaration type={program.resolveTypeReference("Foo")[0]! as Enum} />
|
|
29
|
+
<InterfaceDeclaration type={Bar} />
|
|
30
|
+
</ay.List>
|
|
31
|
+
</TspContext.Provider>
|
|
29
32
|
);
|
|
30
33
|
});
|
|
31
34
|
|
|
@@ -56,10 +59,12 @@ describe("Typescript Enum Member Expression", () => {
|
|
|
56
59
|
const output = await getEmitOutput(code, (program) => {
|
|
57
60
|
const Bar = program.resolveTypeReference("Bar")[0]! as Model;
|
|
58
61
|
return (
|
|
59
|
-
<
|
|
60
|
-
<
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
<TspContext.Provider value={{ program }}>
|
|
63
|
+
<ay.List hardline>
|
|
64
|
+
<EnumDeclaration type={program.resolveTypeReference("Foo")[0]! as Enum} />
|
|
65
|
+
<InterfaceDeclaration type={Bar} />
|
|
66
|
+
</ay.List>
|
|
67
|
+
</TspContext.Provider>
|
|
63
68
|
);
|
|
64
69
|
});
|
|
65
70
|
|
|
@@ -92,10 +97,12 @@ describe("Typescript Union Member Expression", () => {
|
|
|
92
97
|
const output = await getEmitOutput(code, (program) => {
|
|
93
98
|
const Bar = program.resolveTypeReference("Bar")[0]! as Model;
|
|
94
99
|
return (
|
|
95
|
-
<
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
<TspContext.Provider value={{ program }}>
|
|
101
|
+
<ay.List hardline>
|
|
102
|
+
<UnionDeclaration type={program.resolveTypeReference("Foo")[0]! as Union} />
|
|
103
|
+
<InterfaceDeclaration type={Bar} />
|
|
104
|
+
</ay.List>
|
|
105
|
+
</TspContext.Provider>
|
|
99
106
|
);
|
|
100
107
|
});
|
|
101
108
|
|
|
@@ -122,10 +129,12 @@ describe("Typescript Union Member Expression", () => {
|
|
|
122
129
|
const output = await getEmitOutput(code, (program) => {
|
|
123
130
|
const Bar = program.resolveTypeReference("Bar")[0]! as Model;
|
|
124
131
|
return (
|
|
125
|
-
<
|
|
126
|
-
<
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
<TspContext.Provider value={{ program }}>
|
|
133
|
+
<ay.List hardline>
|
|
134
|
+
<UnionDeclaration type={program.resolveTypeReference("Foo")[0]! as Union} />
|
|
135
|
+
<InterfaceDeclaration type={Bar} />
|
|
136
|
+
</ay.List>
|
|
137
|
+
</TspContext.Provider>
|
|
129
138
|
);
|
|
130
139
|
});
|
|
131
140
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from "@alloy-js/core";
|
|
2
2
|
import { SourceFile } from "@alloy-js/typescript";
|
|
3
3
|
import { Namespace, Operation } from "@typespec/compiler";
|
|
4
4
|
import { format } from "prettier";
|
|
5
5
|
import { assert, describe, expect, it } from "vitest";
|
|
6
|
+
import { Output } from "../../../src/core/components/output.jsx";
|
|
6
7
|
import { TypeAliasDeclaration } from "../../../src/typescript/components/type-alias-declaration.jsx";
|
|
7
8
|
import { assertFileContents } from "../../utils.js";
|
|
8
9
|
import { createEmitterFrameworkTestRunner, getProgram } from "../test-host.js";
|
|
@@ -20,7 +21,7 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
20
21
|
const scalar = Array.from((namespace as Namespace).scalars.values())[0];
|
|
21
22
|
|
|
22
23
|
const res = render(
|
|
23
|
-
<Output>
|
|
24
|
+
<Output program={program}>
|
|
24
25
|
<SourceFile path="test.ts">
|
|
25
26
|
<TypeAliasDeclaration type={scalar} />
|
|
26
27
|
</SourceFile>
|
|
@@ -47,7 +48,7 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
47
48
|
const scalar = Array.from((namespace as Namespace).scalars.values())[0];
|
|
48
49
|
|
|
49
50
|
const res = render(
|
|
50
|
-
<Output>
|
|
51
|
+
<Output program={program}>
|
|
51
52
|
<SourceFile path="test.ts">
|
|
52
53
|
<TypeAliasDeclaration type={scalar} />
|
|
53
54
|
</SourceFile>
|
|
@@ -74,7 +75,7 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
74
75
|
const scalar = Array.from((namespace as Namespace).scalars.values())[0];
|
|
75
76
|
|
|
76
77
|
const res = render(
|
|
77
|
-
<Output>
|
|
78
|
+
<Output program={program}>
|
|
78
79
|
<SourceFile path="test.ts">
|
|
79
80
|
<TypeAliasDeclaration type={scalar} />
|
|
80
81
|
</SourceFile>
|
|
@@ -101,7 +102,7 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
101
102
|
const scalar = Array.from((namespace as Namespace).scalars.values())[0];
|
|
102
103
|
|
|
103
104
|
const res = render(
|
|
104
|
-
<Output>
|
|
105
|
+
<Output program={program}>
|
|
105
106
|
<SourceFile path="test.ts">
|
|
106
107
|
<TypeAliasDeclaration export type={scalar} />
|
|
107
108
|
</SourceFile>
|
|
@@ -126,7 +127,7 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
126
127
|
`)) as { getName: Operation };
|
|
127
128
|
|
|
128
129
|
const res = render(
|
|
129
|
-
<Output>
|
|
130
|
+
<Output program={runner.program}>
|
|
130
131
|
<SourceFile path="test.ts">
|
|
131
132
|
<TypeAliasDeclaration type={getName} />
|
|
132
133
|
</SourceFile>
|