@typespec/emitter-framework 0.6.0-dev.6 → 0.6.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.
- 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 +1 -1
- 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 { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/
|
|
|
2
2
|
import { List, refkey, StatementList } from "@alloy-js/core";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
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
|
describe("Typescript Enum Declaration", () => {
|
|
@@ -15,8 +16,15 @@ describe("Typescript Enum Declaration", () => {
|
|
|
15
16
|
`;
|
|
16
17
|
const output = await getEmitOutput(code, program => {
|
|
17
18
|
const Foo = program.resolveTypeReference("Foo")[0];
|
|
18
|
-
return _$createComponent(
|
|
19
|
-
|
|
19
|
+
return _$createComponent(TspContext.Provider, {
|
|
20
|
+
value: {
|
|
21
|
+
program
|
|
22
|
+
},
|
|
23
|
+
get children() {
|
|
24
|
+
return _$createComponent(EnumDeclaration, {
|
|
25
|
+
type: Foo
|
|
26
|
+
});
|
|
27
|
+
}
|
|
20
28
|
});
|
|
21
29
|
});
|
|
22
30
|
expect(output).toBe(d`
|
|
@@ -37,8 +45,15 @@ describe("Typescript Enum Declaration", () => {
|
|
|
37
45
|
`;
|
|
38
46
|
const output = await getEmitOutput(code, program => {
|
|
39
47
|
const Foo = program.resolveTypeReference("Foo")[0];
|
|
40
|
-
return _$createComponent(
|
|
41
|
-
|
|
48
|
+
return _$createComponent(TspContext.Provider, {
|
|
49
|
+
value: {
|
|
50
|
+
program
|
|
51
|
+
},
|
|
52
|
+
get children() {
|
|
53
|
+
return _$createComponent(EnumDeclaration, {
|
|
54
|
+
type: Foo
|
|
55
|
+
});
|
|
56
|
+
}
|
|
42
57
|
});
|
|
43
58
|
});
|
|
44
59
|
expect(output).toBe(d`
|
|
@@ -59,16 +74,23 @@ describe("Typescript Enum Declaration", () => {
|
|
|
59
74
|
`;
|
|
60
75
|
const output = await getEmitOutput(code, program => {
|
|
61
76
|
const Foo = program.resolveTypeReference("Foo")[0];
|
|
62
|
-
return _$createComponent(
|
|
63
|
-
|
|
77
|
+
return _$createComponent(TspContext.Provider, {
|
|
78
|
+
value: {
|
|
79
|
+
program
|
|
80
|
+
},
|
|
64
81
|
get children() {
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
}), _$createComponent(StatementList, {
|
|
82
|
+
return _$createComponent(List, {
|
|
83
|
+
hardline: true,
|
|
68
84
|
get children() {
|
|
69
|
-
return [_$
|
|
85
|
+
return [_$createComponent(EnumDeclaration, {
|
|
86
|
+
type: Foo
|
|
87
|
+
}), _$createComponent(StatementList, {
|
|
88
|
+
get children() {
|
|
89
|
+
return [_$memo(() => refkey(Foo)), _$memo(() => refkey(Foo.members.get("one")))];
|
|
90
|
+
}
|
|
91
|
+
})];
|
|
70
92
|
}
|
|
71
|
-
})
|
|
93
|
+
});
|
|
72
94
|
}
|
|
73
95
|
});
|
|
74
96
|
});
|
|
@@ -92,16 +114,23 @@ describe("Typescript Enum Declaration", () => {
|
|
|
92
114
|
`;
|
|
93
115
|
const output = await getEmitOutput(code, program => {
|
|
94
116
|
const Foo = program.resolveTypeReference("Foo")[0];
|
|
95
|
-
return _$createComponent(
|
|
96
|
-
|
|
117
|
+
return _$createComponent(TspContext.Provider, {
|
|
118
|
+
value: {
|
|
119
|
+
program
|
|
120
|
+
},
|
|
97
121
|
get children() {
|
|
98
|
-
return
|
|
99
|
-
|
|
100
|
-
}), _$createComponent(StatementList, {
|
|
122
|
+
return _$createComponent(List, {
|
|
123
|
+
hardline: true,
|
|
101
124
|
get children() {
|
|
102
|
-
return [_$
|
|
125
|
+
return [_$createComponent(EnumDeclaration, {
|
|
126
|
+
type: Foo
|
|
127
|
+
}), _$createComponent(StatementList, {
|
|
128
|
+
get children() {
|
|
129
|
+
return [_$memo(() => refkey(Foo)), _$memo(() => refkey(Foo.variants.get("one")))];
|
|
130
|
+
}
|
|
131
|
+
})];
|
|
103
132
|
}
|
|
104
|
-
})
|
|
133
|
+
});
|
|
105
134
|
}
|
|
106
135
|
});
|
|
107
136
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { render } from "@alloy-js/core";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
4
|
import { SourceFile } from "@alloy-js/typescript";
|
|
5
5
|
import { format } from "prettier";
|
|
6
6
|
import { assert, describe, expect, it } from "vitest";
|
|
7
|
+
import { Output } from "../../../src/core/components/output.js";
|
|
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", () => {
|
|
@@ -17,6 +18,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
17
18
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
18
19
|
const operation = Array.from(namespace.operations.values())[0];
|
|
19
20
|
const res = render(_$createComponent(Output, {
|
|
21
|
+
program: program,
|
|
20
22
|
get children() {
|
|
21
23
|
return _$createComponent(SourceFile, {
|
|
22
24
|
path: "test.ts",
|
|
@@ -46,6 +48,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
46
48
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
47
49
|
const operation = Array.from(namespace.operations.values())[0];
|
|
48
50
|
const res = render(_$createComponent(Output, {
|
|
51
|
+
program: program,
|
|
49
52
|
get children() {
|
|
50
53
|
return _$createComponent(SourceFile, {
|
|
51
54
|
path: "test.ts",
|
|
@@ -79,6 +82,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
79
82
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
80
83
|
const operation = Array.from(namespace.operations.values())[0];
|
|
81
84
|
const res = render(_$createComponent(Output, {
|
|
85
|
+
program: program,
|
|
82
86
|
get children() {
|
|
83
87
|
return _$createComponent(SourceFile, {
|
|
84
88
|
path: "test.ts",
|
|
@@ -109,6 +113,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
109
113
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
110
114
|
const operation = Array.from(namespace.operations.values())[0];
|
|
111
115
|
const res = render(_$createComponent(Output, {
|
|
116
|
+
program: program,
|
|
112
117
|
get children() {
|
|
113
118
|
return _$createComponent(SourceFile, {
|
|
114
119
|
path: "test.ts",
|
|
@@ -139,6 +144,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
139
144
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
140
145
|
const operation = Array.from(namespace.operations.values())[0];
|
|
141
146
|
const res = render(_$createComponent(Output, {
|
|
147
|
+
program: program,
|
|
142
148
|
get children() {
|
|
143
149
|
return _$createComponent(SourceFile, {
|
|
144
150
|
path: "test.ts",
|
|
@@ -181,6 +187,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
181
187
|
const operation = Array.from(namespace.operations.values())[0];
|
|
182
188
|
const model = Array.from(namespace.models.values())[0];
|
|
183
189
|
const res = render(_$createComponent(Output, {
|
|
190
|
+
program: program,
|
|
184
191
|
get children() {
|
|
185
192
|
return _$createComponent(SourceFile, {
|
|
186
193
|
path: "test.ts",
|
|
@@ -215,6 +222,7 @@ describe("Typescript Function Declaration", () => {
|
|
|
215
222
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
216
223
|
const operation = Array.from(namespace.operations.values())[0];
|
|
217
224
|
const res = render(_$createComponent(Output, {
|
|
225
|
+
program: program,
|
|
218
226
|
get children() {
|
|
219
227
|
return _$createComponent(SourceFile, {
|
|
220
228
|
path: "test.ts",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { render } from "@alloy-js/core";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
4
|
import { SourceFile } from "@alloy-js/typescript";
|
|
5
5
|
import { beforeEach, describe, it } from "vitest";
|
|
6
|
+
import { Output } from "../../../src/core/components/output.js";
|
|
6
7
|
import { FunctionExpression } from "../../../src/typescript/components/function-expression.js";
|
|
7
8
|
import { assertFileContents } from "../../utils.js";
|
|
8
9
|
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
@@ -18,6 +19,9 @@ describe("function expressions with a `type` prop", () => {
|
|
|
18
19
|
@test op getName(id: string): string;
|
|
19
20
|
`);
|
|
20
21
|
const res = render(_$createComponent(Output, {
|
|
22
|
+
get program() {
|
|
23
|
+
return runner.program;
|
|
24
|
+
},
|
|
21
25
|
get children() {
|
|
22
26
|
return _$createComponent(SourceFile, {
|
|
23
27
|
path: "test.ts",
|
|
@@ -43,6 +47,9 @@ describe("function expressions with a `type` prop", () => {
|
|
|
43
47
|
@test op getName(id: string): string;
|
|
44
48
|
`);
|
|
45
49
|
const res = render(_$createComponent(Output, {
|
|
50
|
+
get program() {
|
|
51
|
+
return runner.program;
|
|
52
|
+
},
|
|
46
53
|
get children() {
|
|
47
54
|
return _$createComponent(SourceFile, {
|
|
48
55
|
path: "test.ts",
|
|
@@ -66,6 +73,9 @@ describe("function expressions with a `type` prop", () => {
|
|
|
66
73
|
@test op getName(id: string): string;
|
|
67
74
|
`);
|
|
68
75
|
const res = render(_$createComponent(Output, {
|
|
76
|
+
get program() {
|
|
77
|
+
return runner.program;
|
|
78
|
+
},
|
|
69
79
|
get children() {
|
|
70
80
|
return _$createComponent(SourceFile, {
|
|
71
81
|
path: "test.ts",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { render } from "@alloy-js/core";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
4
|
import { SourceFile } from "@alloy-js/typescript";
|
|
5
5
|
import { beforeEach, describe, it } from "vitest";
|
|
6
|
+
import { Output } from "../../../src/core/components/output.js";
|
|
6
7
|
import { FunctionType } from "../../../src/typescript/index.js";
|
|
7
8
|
import { assertFileContents } from "../../utils.js";
|
|
8
9
|
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
@@ -18,6 +19,9 @@ describe("function types with a `type` prop", () => {
|
|
|
18
19
|
@test op getName(id: string): string;
|
|
19
20
|
`);
|
|
20
21
|
const res = render(_$createComponent(Output, {
|
|
22
|
+
get program() {
|
|
23
|
+
return runner.program;
|
|
24
|
+
},
|
|
21
25
|
get children() {
|
|
22
26
|
return _$createComponent(SourceFile, {
|
|
23
27
|
path: "test.ts",
|
|
@@ -40,6 +44,9 @@ describe("function types with a `type` prop", () => {
|
|
|
40
44
|
@test op getName(id: string): string;
|
|
41
45
|
`);
|
|
42
46
|
const res = render(_$createComponent(Output, {
|
|
47
|
+
get program() {
|
|
48
|
+
return runner.program;
|
|
49
|
+
},
|
|
43
50
|
get children() {
|
|
44
51
|
return _$createComponent(SourceFile, {
|
|
45
52
|
path: "test.ts",
|
|
@@ -63,6 +70,9 @@ describe("function types with a `type` prop", () => {
|
|
|
63
70
|
@test op getName(id: string): string;
|
|
64
71
|
`);
|
|
65
72
|
const res = render(_$createComponent(Output, {
|
|
73
|
+
get program() {
|
|
74
|
+
return runner.program;
|
|
75
|
+
},
|
|
66
76
|
get children() {
|
|
67
77
|
return _$createComponent(SourceFile, {
|
|
68
78
|
path: "test.ts",
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { For, List, Output, render } from "@alloy-js/core";
|
|
2
|
+
import { For, List, render } from "@alloy-js/core";
|
|
4
3
|
import { SourceFile } from "@alloy-js/typescript";
|
|
5
4
|
import { format } from "prettier";
|
|
6
5
|
import { assert, describe, expect, it } from "vitest";
|
|
6
|
+
import { Output } from "../../../src/core/components/output.js";
|
|
7
|
+
import { InterfaceDeclaration } from "../../../src/typescript/components/interface-declaration.js";
|
|
7
8
|
import { getProgram } from "../test-host.js";
|
|
8
9
|
describe("Typescript Interface", () => {
|
|
9
10
|
describe("Interface bound to Typespec Types", () => {
|
|
@@ -20,6 +21,7 @@ describe("Typescript Interface", () => {
|
|
|
20
21
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
21
22
|
const models = Array.from(namespace.models.values());
|
|
22
23
|
const res = render(_$createComponent(Output, {
|
|
24
|
+
program: program,
|
|
23
25
|
get children() {
|
|
24
26
|
return _$createComponent(SourceFile, {
|
|
25
27
|
path: "test.ts",
|
|
@@ -61,6 +63,7 @@ describe("Typescript Interface", () => {
|
|
|
61
63
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
62
64
|
const models = namespace.models;
|
|
63
65
|
const res = render(_$createComponent(Output, {
|
|
66
|
+
program: program,
|
|
64
67
|
get children() {
|
|
65
68
|
return _$createComponent(SourceFile, {
|
|
66
69
|
path: "test.ts",
|
|
@@ -99,6 +102,7 @@ describe("Typescript Interface", () => {
|
|
|
99
102
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
100
103
|
const models = namespace.models;
|
|
101
104
|
const res = render(_$createComponent(Output, {
|
|
105
|
+
program: program,
|
|
102
106
|
get children() {
|
|
103
107
|
return _$createComponent(SourceFile, {
|
|
104
108
|
path: "test.ts",
|
|
@@ -141,6 +145,7 @@ describe("Typescript Interface", () => {
|
|
|
141
145
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
142
146
|
const models = namespace.models;
|
|
143
147
|
const res = render(_$createComponent(Output, {
|
|
148
|
+
program: program,
|
|
144
149
|
get children() {
|
|
145
150
|
return _$createComponent(SourceFile, {
|
|
146
151
|
path: "test.ts",
|
|
@@ -193,6 +198,7 @@ describe("Typescript Interface", () => {
|
|
|
193
198
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
194
199
|
const models = namespace.models;
|
|
195
200
|
const res = render(_$createComponent(Output, {
|
|
201
|
+
program: program,
|
|
196
202
|
get children() {
|
|
197
203
|
return _$createComponent(SourceFile, {
|
|
198
204
|
path: "test.ts",
|
|
@@ -244,6 +250,7 @@ describe("Typescript Interface", () => {
|
|
|
244
250
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
245
251
|
const models = Array.from(namespace.models.values());
|
|
246
252
|
const res = render(_$createComponent(Output, {
|
|
253
|
+
program: program,
|
|
247
254
|
get children() {
|
|
248
255
|
return _$createComponent(SourceFile, {
|
|
249
256
|
path: "test.ts",
|
|
@@ -289,6 +296,7 @@ describe("Typescript Interface", () => {
|
|
|
289
296
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
290
297
|
const models = Array.from(namespace.models.values());
|
|
291
298
|
const res = render(_$createComponent(Output, {
|
|
299
|
+
program: program,
|
|
292
300
|
get children() {
|
|
293
301
|
return _$createComponent(SourceFile, {
|
|
294
302
|
path: "test.ts",
|
|
@@ -329,6 +337,7 @@ describe("Typescript Interface", () => {
|
|
|
329
337
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
330
338
|
const models = Array.from(namespace.models.values());
|
|
331
339
|
const res = render(_$createComponent(Output, {
|
|
340
|
+
program: program,
|
|
332
341
|
get children() {
|
|
333
342
|
return _$createComponent(SourceFile, {
|
|
334
343
|
path: "test.ts",
|
|
@@ -367,6 +376,7 @@ describe("Typescript Interface", () => {
|
|
|
367
376
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
368
377
|
const models = Array.from(namespace.models.values());
|
|
369
378
|
const res = render(_$createComponent(Output, {
|
|
379
|
+
program: program,
|
|
370
380
|
get children() {
|
|
371
381
|
return _$createComponent(SourceFile, {
|
|
372
382
|
path: "test.ts",
|
|
@@ -405,6 +415,7 @@ describe("Typescript Interface", () => {
|
|
|
405
415
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
406
416
|
const models = Array.from(namespace.models.values());
|
|
407
417
|
const res = render(_$createComponent(Output, {
|
|
418
|
+
program: program,
|
|
408
419
|
get children() {
|
|
409
420
|
return _$createComponent(SourceFile, {
|
|
410
421
|
path: "test.ts",
|
|
@@ -447,6 +458,7 @@ describe("Typescript Interface", () => {
|
|
|
447
458
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
448
459
|
const models = Array.from(namespace.models.values());
|
|
449
460
|
const res = render(_$createComponent(Output, {
|
|
461
|
+
program: program,
|
|
450
462
|
get children() {
|
|
451
463
|
return _$createComponent(SourceFile, {
|
|
452
464
|
path: "test.ts",
|
|
@@ -492,6 +504,7 @@ describe("Typescript Interface", () => {
|
|
|
492
504
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
493
505
|
const models = Array.from(namespace.models.values());
|
|
494
506
|
const res = render(_$createComponent(Output, {
|
|
507
|
+
program: program,
|
|
495
508
|
get children() {
|
|
496
509
|
return _$createComponent(SourceFile, {
|
|
497
510
|
path: "test.ts",
|
|
@@ -539,6 +552,7 @@ describe("Typescript Interface", () => {
|
|
|
539
552
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
540
553
|
const models = Array.from(namespace.models.values());
|
|
541
554
|
const res = render(_$createComponent(Output, {
|
|
555
|
+
program: program,
|
|
542
556
|
get children() {
|
|
543
557
|
return _$createComponent(SourceFile, {
|
|
544
558
|
path: "test.ts",
|
|
@@ -582,6 +596,7 @@ describe("Typescript Interface", () => {
|
|
|
582
596
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
583
597
|
const interfaces = Array.from(namespace.interfaces.values());
|
|
584
598
|
const res = render(_$createComponent(Output, {
|
|
599
|
+
program: program,
|
|
585
600
|
get children() {
|
|
586
601
|
return _$createComponent(SourceFile, {
|
|
587
602
|
path: "test.ts",
|
|
@@ -625,6 +640,7 @@ describe("Typescript Interface", () => {
|
|
|
625
640
|
const interfaces = Array.from(namespace.interfaces.values());
|
|
626
641
|
const models = Array.from(namespace.models.values());
|
|
627
642
|
const res = render(_$createComponent(Output, {
|
|
643
|
+
program: program,
|
|
628
644
|
get children() {
|
|
629
645
|
return _$createComponent(SourceFile, {
|
|
630
646
|
path: "test.ts",
|
|
@@ -679,6 +695,7 @@ describe("Typescript Interface", () => {
|
|
|
679
695
|
const interfaces = Array.from(namespace.interfaces.values());
|
|
680
696
|
const models = Array.from(namespace.models.values());
|
|
681
697
|
const res = render(_$createComponent(Output, {
|
|
698
|
+
program: program,
|
|
682
699
|
get children() {
|
|
683
700
|
return _$createComponent(SourceFile, {
|
|
684
701
|
path: "test.ts",
|
|
@@ -735,6 +752,7 @@ describe("Typescript Interface", () => {
|
|
|
735
752
|
const interfaces = Array.from(namespace.interfaces.values());
|
|
736
753
|
const models = Array.from(namespace.models.values());
|
|
737
754
|
const res = render(_$createComponent(Output, {
|
|
755
|
+
program: program,
|
|
738
756
|
get children() {
|
|
739
757
|
return _$createComponent(SourceFile, {
|
|
740
758
|
path: "test.ts",
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { render } from "@alloy-js/core";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
4
|
import { InterfaceDeclaration, SourceFile } from "@alloy-js/typescript";
|
|
5
5
|
import { beforeEach, describe, it } from "vitest";
|
|
6
|
+
import { Output } from "../../../src/core/components/output.js";
|
|
6
7
|
import { InterfaceMethod } from "../../../src/typescript/components/interface-method.js";
|
|
7
8
|
import { assertFileContents } from "../../utils.js";
|
|
8
|
-
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
9
|
+
import { createEmitterFrameworkTestRunner, getProgram } from "../test-host.js";
|
|
9
10
|
describe("interface methods with a `type` prop", () => {
|
|
10
11
|
let runner;
|
|
11
12
|
beforeEach(async () => {
|
|
@@ -18,6 +19,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
18
19
|
@test op getName(id: string): string;
|
|
19
20
|
`);
|
|
20
21
|
const res = render(_$createComponent(Output, {
|
|
22
|
+
get program() {
|
|
23
|
+
return runner.program;
|
|
24
|
+
},
|
|
21
25
|
get children() {
|
|
22
26
|
return _$createComponent(SourceFile, {
|
|
23
27
|
path: "test.ts",
|
|
@@ -50,6 +54,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
50
54
|
@test op getName(id: string): string;
|
|
51
55
|
`);
|
|
52
56
|
const res = render(_$createComponent(Output, {
|
|
57
|
+
get program() {
|
|
58
|
+
return runner.program;
|
|
59
|
+
},
|
|
53
60
|
get children() {
|
|
54
61
|
return _$createComponent(SourceFile, {
|
|
55
62
|
path: "test.ts",
|
|
@@ -80,6 +87,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
80
87
|
@test op getName(id: string): string;
|
|
81
88
|
`);
|
|
82
89
|
const res = render(_$createComponent(Output, {
|
|
90
|
+
get program() {
|
|
91
|
+
return runner.program;
|
|
92
|
+
},
|
|
83
93
|
get children() {
|
|
84
94
|
return _$createComponent(SourceFile, {
|
|
85
95
|
path: "test.ts",
|
|
@@ -114,6 +124,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
114
124
|
@test op getName(id: string): string;
|
|
115
125
|
`);
|
|
116
126
|
const res = render(_$createComponent(Output, {
|
|
127
|
+
get program() {
|
|
128
|
+
return runner.program;
|
|
129
|
+
},
|
|
117
130
|
get children() {
|
|
118
131
|
return _$createComponent(SourceFile, {
|
|
119
132
|
path: "test.ts",
|
|
@@ -148,6 +161,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
148
161
|
@test op getName(id: string): string;
|
|
149
162
|
`);
|
|
150
163
|
const res = render(_$createComponent(Output, {
|
|
164
|
+
get program() {
|
|
165
|
+
return runner.program;
|
|
166
|
+
},
|
|
151
167
|
get children() {
|
|
152
168
|
return _$createComponent(SourceFile, {
|
|
153
169
|
path: "test.ts",
|
|
@@ -185,6 +201,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
185
201
|
@test op getName(id: string): string;
|
|
186
202
|
`);
|
|
187
203
|
const res = render(_$createComponent(Output, {
|
|
204
|
+
get program() {
|
|
205
|
+
return runner.program;
|
|
206
|
+
},
|
|
188
207
|
get children() {
|
|
189
208
|
return _$createComponent(SourceFile, {
|
|
190
209
|
path: "test.ts",
|
|
@@ -215,6 +234,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
215
234
|
@test op getName(id: string): string;
|
|
216
235
|
`);
|
|
217
236
|
const res = render(_$createComponent(Output, {
|
|
237
|
+
get program() {
|
|
238
|
+
return runner.program;
|
|
239
|
+
},
|
|
218
240
|
get children() {
|
|
219
241
|
return _$createComponent(SourceFile, {
|
|
220
242
|
path: "test.ts",
|
|
@@ -241,7 +263,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
241
263
|
});
|
|
242
264
|
describe("interface methods without a `type` prop", () => {
|
|
243
265
|
it("renders a plain interface method", async () => {
|
|
266
|
+
const program = await getProgram("");
|
|
244
267
|
const res = render(_$createComponent(Output, {
|
|
268
|
+
program: program,
|
|
245
269
|
get children() {
|
|
246
270
|
return _$createComponent(SourceFile, {
|
|
247
271
|
path: "test.ts",
|
|
@@ -2,6 +2,7 @@ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime
|
|
|
2
2
|
import * as ay from "@alloy-js/core";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
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";
|
|
@@ -20,16 +21,23 @@ describe("Typescript Enum Member Expression", () => {
|
|
|
20
21
|
`;
|
|
21
22
|
const output = await getEmitOutput(code, program => {
|
|
22
23
|
const Bar = program.resolveTypeReference("Bar")[0];
|
|
23
|
-
return _$createComponent(
|
|
24
|
-
|
|
24
|
+
return _$createComponent(TspContext.Provider, {
|
|
25
|
+
value: {
|
|
26
|
+
program
|
|
27
|
+
},
|
|
25
28
|
get children() {
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
return _$createComponent(ay.List, {
|
|
30
|
+
hardline: true,
|
|
31
|
+
get children() {
|
|
32
|
+
return [_$createComponent(EnumDeclaration, {
|
|
33
|
+
get type() {
|
|
34
|
+
return program.resolveTypeReference("Foo")[0];
|
|
35
|
+
}
|
|
36
|
+
}), _$createComponent(InterfaceDeclaration, {
|
|
37
|
+
type: Bar
|
|
38
|
+
})];
|
|
29
39
|
}
|
|
30
|
-
})
|
|
31
|
-
type: Bar
|
|
32
|
-
})];
|
|
40
|
+
});
|
|
33
41
|
}
|
|
34
42
|
});
|
|
35
43
|
});
|
|
@@ -58,16 +66,23 @@ describe("Typescript Enum Member Expression", () => {
|
|
|
58
66
|
`;
|
|
59
67
|
const output = await getEmitOutput(code, program => {
|
|
60
68
|
const Bar = program.resolveTypeReference("Bar")[0];
|
|
61
|
-
return _$createComponent(
|
|
62
|
-
|
|
69
|
+
return _$createComponent(TspContext.Provider, {
|
|
70
|
+
value: {
|
|
71
|
+
program
|
|
72
|
+
},
|
|
63
73
|
get children() {
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
return _$createComponent(ay.List, {
|
|
75
|
+
hardline: true,
|
|
76
|
+
get children() {
|
|
77
|
+
return [_$createComponent(EnumDeclaration, {
|
|
78
|
+
get type() {
|
|
79
|
+
return program.resolveTypeReference("Foo")[0];
|
|
80
|
+
}
|
|
81
|
+
}), _$createComponent(InterfaceDeclaration, {
|
|
82
|
+
type: Bar
|
|
83
|
+
})];
|
|
67
84
|
}
|
|
68
|
-
})
|
|
69
|
-
type: Bar
|
|
70
|
-
})];
|
|
85
|
+
});
|
|
71
86
|
}
|
|
72
87
|
});
|
|
73
88
|
});
|
|
@@ -98,16 +113,23 @@ describe("Typescript Union Member Expression", () => {
|
|
|
98
113
|
`;
|
|
99
114
|
const output = await getEmitOutput(code, program => {
|
|
100
115
|
const Bar = program.resolveTypeReference("Bar")[0];
|
|
101
|
-
return _$createComponent(
|
|
102
|
-
|
|
116
|
+
return _$createComponent(TspContext.Provider, {
|
|
117
|
+
value: {
|
|
118
|
+
program
|
|
119
|
+
},
|
|
103
120
|
get children() {
|
|
104
|
-
return
|
|
105
|
-
|
|
106
|
-
|
|
121
|
+
return _$createComponent(ay.List, {
|
|
122
|
+
hardline: true,
|
|
123
|
+
get children() {
|
|
124
|
+
return [_$createComponent(UnionDeclaration, {
|
|
125
|
+
get type() {
|
|
126
|
+
return program.resolveTypeReference("Foo")[0];
|
|
127
|
+
}
|
|
128
|
+
}), _$createComponent(InterfaceDeclaration, {
|
|
129
|
+
type: Bar
|
|
130
|
+
})];
|
|
107
131
|
}
|
|
108
|
-
})
|
|
109
|
-
type: Bar
|
|
110
|
-
})];
|
|
132
|
+
});
|
|
111
133
|
}
|
|
112
134
|
});
|
|
113
135
|
});
|
|
@@ -132,16 +154,23 @@ describe("Typescript Union Member Expression", () => {
|
|
|
132
154
|
`;
|
|
133
155
|
const output = await getEmitOutput(code, program => {
|
|
134
156
|
const Bar = program.resolveTypeReference("Bar")[0];
|
|
135
|
-
return _$createComponent(
|
|
136
|
-
|
|
157
|
+
return _$createComponent(TspContext.Provider, {
|
|
158
|
+
value: {
|
|
159
|
+
program
|
|
160
|
+
},
|
|
137
161
|
get children() {
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
162
|
+
return _$createComponent(ay.List, {
|
|
163
|
+
hardline: true,
|
|
164
|
+
get children() {
|
|
165
|
+
return [_$createComponent(UnionDeclaration, {
|
|
166
|
+
get type() {
|
|
167
|
+
return program.resolveTypeReference("Foo")[0];
|
|
168
|
+
}
|
|
169
|
+
}), _$createComponent(InterfaceDeclaration, {
|
|
170
|
+
type: Bar
|
|
171
|
+
})];
|
|
141
172
|
}
|
|
142
|
-
})
|
|
143
|
-
type: Bar
|
|
144
|
-
})];
|
|
173
|
+
});
|
|
145
174
|
}
|
|
146
175
|
});
|
|
147
176
|
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { render } from "@alloy-js/core";
|
|
3
3
|
import { SourceFile } from "@alloy-js/typescript";
|
|
4
4
|
import { format } from "prettier";
|
|
5
5
|
import { assert, describe, expect, it } from "vitest";
|
|
6
|
+
import { Output } from "../../../src/core/components/output.js";
|
|
6
7
|
import { TypeAliasDeclaration } from "../../../src/typescript/components/type-alias-declaration.js";
|
|
7
8
|
import { assertFileContents } from "../../utils.js";
|
|
8
9
|
import { createEmitterFrameworkTestRunner, getProgram } from "../test-host.js";
|
|
@@ -17,6 +18,7 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
17
18
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
18
19
|
const scalar = Array.from(namespace.scalars.values())[0];
|
|
19
20
|
const res = render(_$createComponent(Output, {
|
|
21
|
+
program: program,
|
|
20
22
|
get children() {
|
|
21
23
|
return _$createComponent(SourceFile, {
|
|
22
24
|
path: "test.ts",
|
|
@@ -47,6 +49,7 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
47
49
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
48
50
|
const scalar = Array.from(namespace.scalars.values())[0];
|
|
49
51
|
const res = render(_$createComponent(Output, {
|
|
52
|
+
program: program,
|
|
50
53
|
get children() {
|
|
51
54
|
return _$createComponent(SourceFile, {
|
|
52
55
|
path: "test.ts",
|
|
@@ -77,6 +80,7 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
77
80
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
78
81
|
const scalar = Array.from(namespace.scalars.values())[0];
|
|
79
82
|
const res = render(_$createComponent(Output, {
|
|
83
|
+
program: program,
|
|
80
84
|
get children() {
|
|
81
85
|
return _$createComponent(SourceFile, {
|
|
82
86
|
path: "test.ts",
|
|
@@ -107,6 +111,7 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
107
111
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
108
112
|
const scalar = Array.from(namespace.scalars.values())[0];
|
|
109
113
|
const res = render(_$createComponent(Output, {
|
|
114
|
+
program: program,
|
|
110
115
|
get children() {
|
|
111
116
|
return _$createComponent(SourceFile, {
|
|
112
117
|
path: "test.ts",
|
|
@@ -139,6 +144,9 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
139
144
|
@test op getName(id: string): string;
|
|
140
145
|
`);
|
|
141
146
|
const res = render(_$createComponent(Output, {
|
|
147
|
+
get program() {
|
|
148
|
+
return runner.program;
|
|
149
|
+
},
|
|
142
150
|
get children() {
|
|
143
151
|
return _$createComponent(SourceFile, {
|
|
144
152
|
path: "test.ts",
|