@typespec/emitter-framework 0.11.0-dev.6 → 0.11.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/index.js +2 -1
- package/dist/src/core/components/index.js.map +1 -0
- package/dist/src/core/components/output.js +2 -1
- package/dist/src/core/components/output.js.map +1 -0
- package/dist/src/core/components/overrides/component-overrides.js +2 -1
- package/dist/src/core/components/overrides/component-overrides.js.map +1 -0
- package/dist/src/core/components/overrides/config.js +2 -1
- package/dist/src/core/components/overrides/config.js.map +1 -0
- package/dist/src/core/components/overrides/context.js +2 -1
- package/dist/src/core/components/overrides/context.js.map +1 -0
- package/dist/src/core/context/index.js +2 -1
- package/dist/src/core/context/index.js.map +1 -0
- package/dist/src/core/context/name-policy-context.js +2 -1
- package/dist/src/core/context/name-policy-context.js.map +1 -0
- package/dist/src/core/context/tsp-context.js +2 -1
- package/dist/src/core/context/tsp-context.js.map +1 -0
- package/dist/src/core/index.js +2 -1
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/transport-name-policy.js +2 -1
- package/dist/src/core/transport-name-policy.js.map +1 -0
- package/dist/src/core/write-output.js +2 -1
- package/dist/src/core/write-output.js.map +1 -0
- package/dist/src/csharp/components/class/declaration.d.ts.map +1 -1
- package/dist/src/csharp/components/class/declaration.js +9 -1
- package/dist/src/csharp/components/class/declaration.js.map +1 -0
- package/dist/src/csharp/components/class/declaration.test.js +62 -105
- package/dist/src/csharp/components/class/declaration.test.js.map +1 -0
- package/dist/src/csharp/components/enum/declaration.js +2 -1
- package/dist/src/csharp/components/enum/declaration.js.map +1 -0
- package/dist/src/csharp/components/enum/declaration.test.js +52 -88
- package/dist/src/csharp/components/enum/declaration.test.js.map +1 -0
- package/dist/src/csharp/components/index.js +2 -1
- package/dist/src/csharp/components/index.js.map +1 -0
- package/dist/src/csharp/components/property/property.d.ts.map +1 -1
- package/dist/src/csharp/components/property/property.js +31 -2
- package/dist/src/csharp/components/property/property.js.map +1 -0
- package/dist/src/csharp/components/property/property.test.js +91 -39
- package/dist/src/csharp/components/property/property.test.js.map +1 -0
- package/dist/src/csharp/components/type-expression.js +2 -1
- package/dist/src/csharp/components/type-expression.js.map +1 -0
- package/dist/src/csharp/components/type-expression.test.js +43 -74
- package/dist/src/csharp/components/type-expression.test.js.map +1 -0
- package/dist/src/csharp/components/utils/doc-comments.js +2 -1
- package/dist/src/csharp/components/utils/doc-comments.js.map +1 -0
- package/dist/src/csharp/components/utils/nullable-util.js +2 -1
- package/dist/src/csharp/components/utils/nullable-util.js.map +1 -0
- package/dist/src/csharp/components/utils/refkey.js +2 -1
- package/dist/src/csharp/components/utils/refkey.js.map +1 -0
- package/dist/src/csharp/index.js +2 -1
- package/dist/src/csharp/index.js.map +1 -0
- package/dist/src/lib.js +2 -1
- package/dist/src/lib.js.map +1 -0
- package/dist/src/testing/index.js +2 -1
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.js +2 -1
- package/dist/src/testing/scenario-test/code-block-expectation.js.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.js +2 -1
- package/dist/src/testing/scenario-test/code-block-expectation.test.js.map +1 -0
- package/dist/src/testing/scenario-test/harness.js +2 -1
- package/dist/src/testing/scenario-test/harness.js.map +1 -0
- package/dist/src/testing/scenario-test/index.js +2 -1
- package/dist/src/testing/scenario-test/index.js.map +1 -0
- package/dist/src/testing/scenario-test/snippet-extractor.js +2 -1
- package/dist/src/testing/scenario-test/snippet-extractor.js.map +1 -0
- package/dist/src/typescript/components/array-expression.js +2 -1
- package/dist/src/typescript/components/array-expression.js.map +1 -0
- package/dist/src/typescript/components/arrow-function.js +2 -1
- package/dist/src/typescript/components/arrow-function.js.map +1 -0
- package/dist/src/typescript/components/class-method.js +2 -1
- package/dist/src/typescript/components/class-method.js.map +1 -0
- package/dist/src/typescript/components/enum-declaration.js +2 -1
- package/dist/src/typescript/components/enum-declaration.js.map +1 -0
- package/dist/src/typescript/components/function-declaration.js +2 -1
- package/dist/src/typescript/components/function-declaration.js.map +1 -0
- package/dist/src/typescript/components/function-expression.js +2 -1
- package/dist/src/typescript/components/function-expression.js.map +1 -0
- package/dist/src/typescript/components/function-type.js +2 -1
- package/dist/src/typescript/components/function-type.js.map +1 -0
- package/dist/src/typescript/components/index.js +2 -1
- package/dist/src/typescript/components/index.js.map +1 -0
- package/dist/src/typescript/components/interface-declaration.js +2 -1
- package/dist/src/typescript/components/interface-declaration.js.map +1 -0
- package/dist/src/typescript/components/interface-member.js +2 -1
- package/dist/src/typescript/components/interface-member.js.map +1 -0
- package/dist/src/typescript/components/interface-method.js +2 -1
- package/dist/src/typescript/components/interface-method.js.map +1 -0
- package/dist/src/typescript/components/record-expression.js +2 -1
- package/dist/src/typescript/components/record-expression.js.map +1 -0
- package/dist/src/typescript/components/static-serializers.js +2 -1
- package/dist/src/typescript/components/static-serializers.js.map +1 -0
- package/dist/src/typescript/components/type-alias-declaration.js +2 -1
- package/dist/src/typescript/components/type-alias-declaration.js.map +1 -0
- package/dist/src/typescript/components/type-declaration.js +2 -1
- package/dist/src/typescript/components/type-declaration.js.map +1 -0
- package/dist/src/typescript/components/type-expression.js +2 -1
- package/dist/src/typescript/components/type-expression.js.map +1 -0
- package/dist/src/typescript/components/type-transform.js +2 -1
- package/dist/src/typescript/components/type-transform.js.map +1 -0
- package/dist/src/typescript/components/union/declaration.js +2 -1
- package/dist/src/typescript/components/union/declaration.js.map +1 -0
- package/dist/src/typescript/components/union/declaration.test.js +2 -1
- package/dist/src/typescript/components/union/declaration.test.js.map +1 -0
- package/dist/src/typescript/components/union/expression.js +2 -1
- package/dist/src/typescript/components/union/expression.js.map +1 -0
- package/dist/src/typescript/components/union/expression.test.js +2 -1
- package/dist/src/typescript/components/union/expression.test.js.map +1 -0
- package/dist/src/typescript/components/value-expression.js +2 -1
- package/dist/src/typescript/components/value-expression.js.map +1 -0
- package/dist/src/typescript/index.js +2 -1
- package/dist/src/typescript/index.js.map +1 -0
- package/dist/src/typescript/lib.js +2 -1
- package/dist/src/typescript/lib.js.map +1 -0
- package/dist/src/typescript/utils/index.js +2 -1
- package/dist/src/typescript/utils/index.js.map +1 -0
- package/dist/src/typescript/utils/operation.js +2 -1
- package/dist/src/typescript/utils/operation.js.map +1 -0
- package/dist/src/typescript/utils/refkey.js +2 -1
- package/dist/src/typescript/utils/refkey.js.map +1 -0
- package/dist/test/test-host.js +2 -1
- package/dist/test/test-host.js.map +1 -0
- package/dist/test/testing/snippet-extractor-csharp.test.js +2 -1
- package/dist/test/testing/snippet-extractor-csharp.test.js.map +1 -0
- package/dist/test/testing/snippet-extractor-java.test.js +2 -1
- package/dist/test/testing/snippet-extractor-java.test.js.map +1 -0
- package/dist/test/testing/snippet-extractor-python.test.js +2 -1
- package/dist/test/testing/snippet-extractor-python.test.js.map +1 -0
- package/dist/test/testing/snippet-extractor-typescript.test.js +2 -1
- package/dist/test/testing/snippet-extractor-typescript.test.js.map +1 -0
- package/dist/test/typescript/components/arrow-function.test.js +9 -14
- package/dist/test/typescript/components/arrow-function.test.js.map +1 -0
- package/dist/test/typescript/components/component-override.test.js +2 -1
- package/dist/test/typescript/components/component-override.test.js.map +1 -0
- package/dist/test/typescript/components/enum-declaration.test.js +2 -1
- package/dist/test/typescript/components/enum-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/function-declaration.test.js +2 -1
- package/dist/test/typescript/components/function-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/function-expression.test.js +9 -14
- package/dist/test/typescript/components/function-expression.test.js.map +1 -0
- package/dist/test/typescript/components/function-type.test.js +9 -14
- package/dist/test/typescript/components/function-type.test.js.map +1 -0
- package/dist/test/typescript/components/interface-declaration.test.js +2 -1
- package/dist/test/typescript/components/interface-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/interface-method.test.js +19 -29
- package/dist/test/typescript/components/interface-method.test.js.map +1 -0
- package/dist/test/typescript/components/member-expression.test.js +2 -1
- package/dist/test/typescript/components/member-expression.test.js.map +1 -0
- package/dist/test/typescript/components/type-alias-declaration.test.js +2 -1
- package/dist/test/typescript/components/type-alias-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/type-transform.test.js +2 -1
- package/dist/test/typescript/components/type-transform.test.js.map +1 -0
- package/dist/test/typescript/components/value-expression.test.js +2 -1
- package/dist/test/typescript/components/value-expression.test.js.map +1 -0
- package/dist/test/typescript/test-host.js +2 -1
- package/dist/test/typescript/test-host.js.map +1 -0
- package/dist/test/typescript/utils.js +2 -1
- package/dist/test/typescript/utils.js.map +1 -0
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +5 -2
- package/dist/test/utils.js.map +1 -0
- package/dist/test/vitest.setup.js +2 -1
- package/dist/test/vitest.setup.js.map +1 -0
- package/package.json +7 -7
- package/src/csharp/components/class/declaration.test.tsx +61 -102
- package/src/csharp/components/class/declaration.tsx +6 -0
- package/src/csharp/components/enum/declaration.test.tsx +47 -78
- package/src/csharp/components/property/property.test.tsx +74 -35
- package/src/csharp/components/property/property.tsx +34 -1
- package/src/csharp/components/type-expression.test.tsx +41 -93
- package/test/typescript/components/arrow-function.test.tsx +10 -28
- package/test/typescript/components/function-expression.test.tsx +10 -28
- package/test/typescript/components/function-type.test.tsx +10 -28
- package/test/typescript/components/interface-method.test.tsx +25 -68
- package/test/utils.ts +3 -1
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { render } from "@alloy-js/core";
|
|
2
|
-
import { d } from "@alloy-js/core/testing";
|
|
3
1
|
import { InterfaceDeclaration, SourceFile } from "@alloy-js/typescript";
|
|
4
2
|
import type { Operation } from "@typespec/compiler";
|
|
5
3
|
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
|
-
import { beforeEach, describe, it } from "vitest";
|
|
4
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
7
5
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
8
6
|
import { InterfaceMethod } from "../../../src/typescript/components/interface-method.jsx";
|
|
9
|
-
import { assertFileContents } from "../../utils.js";
|
|
10
7
|
import { createEmitterFrameworkTestRunner, getProgram } from "../test-host.js";
|
|
11
8
|
|
|
12
9
|
describe("interface methods with a `type` prop", () => {
|
|
@@ -21,7 +18,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
21
18
|
@test op getName(id: string): string;
|
|
22
19
|
`)) as { getName: Operation };
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
expect(
|
|
25
22
|
<Output program={runner.program}>
|
|
26
23
|
<SourceFile path="test.ts">
|
|
27
24
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -29,16 +26,11 @@ describe("interface methods with a `type` prop", () => {
|
|
|
29
26
|
</InterfaceDeclaration>
|
|
30
27
|
</SourceFile>
|
|
31
28
|
</Output>,
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
assertFileContents(
|
|
35
|
-
res,
|
|
36
|
-
d`
|
|
29
|
+
).toRenderTo(`
|
|
37
30
|
interface basicInterface {
|
|
38
31
|
getName(id: string): string
|
|
39
32
|
}
|
|
40
|
-
|
|
41
|
-
);
|
|
33
|
+
`);
|
|
42
34
|
});
|
|
43
35
|
|
|
44
36
|
it("creates an async interface function", async () => {
|
|
@@ -46,7 +38,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
46
38
|
@test op getName(id: string): string;
|
|
47
39
|
`)) as { getName: Operation };
|
|
48
40
|
|
|
49
|
-
|
|
41
|
+
expect(
|
|
50
42
|
<Output program={runner.program}>
|
|
51
43
|
<SourceFile path="test.ts">
|
|
52
44
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -54,16 +46,11 @@ describe("interface methods with a `type` prop", () => {
|
|
|
54
46
|
</InterfaceDeclaration>
|
|
55
47
|
</SourceFile>
|
|
56
48
|
</Output>,
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
assertFileContents(
|
|
60
|
-
res,
|
|
61
|
-
d`
|
|
49
|
+
).toRenderTo(`
|
|
62
50
|
interface basicInterface {
|
|
63
51
|
getName(id: string): Promise<string>
|
|
64
52
|
}
|
|
65
|
-
|
|
66
|
-
);
|
|
53
|
+
`);
|
|
67
54
|
});
|
|
68
55
|
|
|
69
56
|
it("can append extra parameters with raw params provided", async () => {
|
|
@@ -71,7 +58,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
71
58
|
@test op getName(id: string): string;
|
|
72
59
|
`)) as { getName: Operation };
|
|
73
60
|
|
|
74
|
-
|
|
61
|
+
expect(
|
|
75
62
|
<Output program={runner.program}>
|
|
76
63
|
<SourceFile path="test.ts">
|
|
77
64
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -83,16 +70,11 @@ describe("interface methods with a `type` prop", () => {
|
|
|
83
70
|
</InterfaceDeclaration>
|
|
84
71
|
</SourceFile>
|
|
85
72
|
</Output>,
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
assertFileContents(
|
|
89
|
-
res,
|
|
90
|
-
d`
|
|
73
|
+
).toRenderTo(`
|
|
91
74
|
interface basicInterface {
|
|
92
75
|
getName(id: string, foo: string): string
|
|
93
76
|
}
|
|
94
|
-
|
|
95
|
-
);
|
|
77
|
+
`);
|
|
96
78
|
});
|
|
97
79
|
|
|
98
80
|
it("can prepend extra parameters with raw params provided", async () => {
|
|
@@ -100,7 +82,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
100
82
|
@test op getName(id: string): string;
|
|
101
83
|
`)) as { getName: Operation };
|
|
102
84
|
|
|
103
|
-
|
|
85
|
+
expect(
|
|
104
86
|
<Output program={runner.program}>
|
|
105
87
|
<SourceFile path="test.ts">
|
|
106
88
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -112,16 +94,11 @@ describe("interface methods with a `type` prop", () => {
|
|
|
112
94
|
</InterfaceDeclaration>
|
|
113
95
|
</SourceFile>
|
|
114
96
|
</Output>,
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
assertFileContents(
|
|
118
|
-
res,
|
|
119
|
-
d`
|
|
97
|
+
).toRenderTo(`
|
|
120
98
|
interface basicInterface {
|
|
121
99
|
getName(foo: string, id: string): string
|
|
122
100
|
}
|
|
123
|
-
|
|
124
|
-
);
|
|
101
|
+
`);
|
|
125
102
|
});
|
|
126
103
|
|
|
127
104
|
it("can replace parameters with raw params provided", async () => {
|
|
@@ -129,7 +106,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
129
106
|
@test op getName(id: string): string;
|
|
130
107
|
`)) as { getName: Operation };
|
|
131
108
|
|
|
132
|
-
|
|
109
|
+
expect(
|
|
133
110
|
<Output program={runner.program}>
|
|
134
111
|
<SourceFile path="test.ts">
|
|
135
112
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -144,16 +121,11 @@ describe("interface methods with a `type` prop", () => {
|
|
|
144
121
|
</InterfaceDeclaration>
|
|
145
122
|
</SourceFile>
|
|
146
123
|
</Output>,
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
assertFileContents(
|
|
150
|
-
res,
|
|
151
|
-
d`
|
|
124
|
+
).toRenderTo(`
|
|
152
125
|
interface basicInterface {
|
|
153
126
|
getName(foo: string, bar: number): string
|
|
154
127
|
}
|
|
155
|
-
|
|
156
|
-
);
|
|
128
|
+
`);
|
|
157
129
|
});
|
|
158
130
|
|
|
159
131
|
it("can override return type", async () => {
|
|
@@ -161,7 +133,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
161
133
|
@test op getName(id: string): string;
|
|
162
134
|
`)) as { getName: Operation };
|
|
163
135
|
|
|
164
|
-
|
|
136
|
+
expect(
|
|
165
137
|
<Output program={runner.program}>
|
|
166
138
|
<SourceFile path="test.ts">
|
|
167
139
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -169,16 +141,11 @@ describe("interface methods with a `type` prop", () => {
|
|
|
169
141
|
</InterfaceDeclaration>
|
|
170
142
|
</SourceFile>
|
|
171
143
|
</Output>,
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
assertFileContents(
|
|
175
|
-
res,
|
|
176
|
-
d`
|
|
144
|
+
).toRenderTo(`
|
|
177
145
|
interface basicInterface {
|
|
178
146
|
getName(id: string): Promise<Record<string, unknown>>
|
|
179
147
|
}
|
|
180
|
-
|
|
181
|
-
);
|
|
148
|
+
`);
|
|
182
149
|
});
|
|
183
150
|
|
|
184
151
|
it("can override method name", async () => {
|
|
@@ -186,7 +153,7 @@ describe("interface methods with a `type` prop", () => {
|
|
|
186
153
|
@test op getName(id: string): string;
|
|
187
154
|
`)) as { getName: Operation };
|
|
188
155
|
|
|
189
|
-
|
|
156
|
+
expect(
|
|
190
157
|
<Output program={runner.program}>
|
|
191
158
|
<SourceFile path="test.ts">
|
|
192
159
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -194,23 +161,18 @@ describe("interface methods with a `type` prop", () => {
|
|
|
194
161
|
</InterfaceDeclaration>
|
|
195
162
|
</SourceFile>
|
|
196
163
|
</Output>,
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
assertFileContents(
|
|
200
|
-
res,
|
|
201
|
-
d`
|
|
164
|
+
).toRenderTo(`
|
|
202
165
|
interface basicInterface {
|
|
203
166
|
getNameCustom(id: string): string
|
|
204
167
|
}
|
|
205
|
-
|
|
206
|
-
);
|
|
168
|
+
`);
|
|
207
169
|
});
|
|
208
170
|
});
|
|
209
171
|
|
|
210
172
|
describe("interface methods without a `type` prop", () => {
|
|
211
173
|
it("renders a plain interface method", async () => {
|
|
212
174
|
const program = await getProgram("");
|
|
213
|
-
|
|
175
|
+
expect(
|
|
214
176
|
<Output program={program}>
|
|
215
177
|
<SourceFile path="test.ts">
|
|
216
178
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -222,15 +184,10 @@ describe("interface methods without a `type` prop", () => {
|
|
|
222
184
|
</InterfaceDeclaration>
|
|
223
185
|
</SourceFile>
|
|
224
186
|
</Output>,
|
|
225
|
-
)
|
|
226
|
-
|
|
227
|
-
assertFileContents(
|
|
228
|
-
res,
|
|
229
|
-
d`
|
|
187
|
+
).toRenderTo(`
|
|
230
188
|
interface basicInterface {
|
|
231
189
|
plainMethod(param1: string): number
|
|
232
190
|
}
|
|
233
|
-
|
|
234
|
-
);
|
|
191
|
+
`);
|
|
235
192
|
});
|
|
236
193
|
});
|
package/test/utils.ts
CHANGED
|
@@ -8,7 +8,9 @@ import { getProgram } from "./typescript/test-host.js";
|
|
|
8
8
|
export async function getEmitOutput(tspCode: string, cb: (program: Program) => Children) {
|
|
9
9
|
const program = await getProgram(tspCode);
|
|
10
10
|
|
|
11
|
-
const res = render(Output().children(SourceFile({ path: "test.ts" }).children(cb(program)))
|
|
11
|
+
const res = render(Output().children(SourceFile({ path: "test.ts" }).children(cb(program))), {
|
|
12
|
+
insertFinalNewLine: false,
|
|
13
|
+
});
|
|
12
14
|
const testFile = res.contents.find((file) => file.path === "test.ts")!;
|
|
13
15
|
assert("contents" in testFile, "test.ts file does not have contents");
|
|
14
16
|
return testFile.contents;
|