@typespec/emitter-framework 0.9.0-dev.3 → 0.9.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/output.d.ts +4 -4
- package/dist/src/core/components/output.d.ts.map +1 -1
- package/dist/src/core/components/output.js +3 -3
- package/dist/src/core/context/name-policy-context.d.ts +2 -2
- package/dist/src/core/context/name-policy-context.d.ts.map +1 -1
- package/dist/src/core/context/tsp-context.d.ts +2 -2
- package/dist/src/core/context/tsp-context.d.ts.map +1 -1
- package/dist/src/core/transport-name-policy.d.ts +1 -1
- package/dist/src/core/transport-name-policy.d.ts.map +1 -1
- package/dist/src/core/write-output.d.ts +2 -2
- package/dist/src/core/write-output.d.ts.map +1 -1
- package/dist/src/csharp/components/class/declaration.d.ts +13 -0
- package/dist/src/csharp/components/class/declaration.d.ts.map +1 -0
- package/dist/src/csharp/components/class/declaration.js +91 -0
- package/dist/src/csharp/components/class/declaration.test.d.ts +2 -0
- package/dist/src/csharp/components/class/declaration.test.d.ts.map +1 -0
- package/dist/src/csharp/components/class/declaration.test.js +392 -0
- package/dist/src/csharp/components/enum-declaration.d.ts +4 -4
- package/dist/src/csharp/components/enum-declaration.d.ts.map +1 -1
- package/dist/src/csharp/components/enum-declaration.js +14 -11
- package/dist/src/csharp/components/index.d.ts +2 -1
- package/dist/src/csharp/components/index.d.ts.map +1 -1
- package/dist/src/csharp/components/index.js +2 -1
- package/dist/src/csharp/components/property/property.d.ts +15 -0
- package/dist/src/csharp/components/property/property.d.ts.map +1 -0
- package/dist/src/csharp/components/property/property.js +85 -0
- package/dist/src/csharp/components/property/property.test.d.ts +2 -0
- package/dist/src/csharp/components/property/property.test.d.ts.map +1 -0
- package/dist/src/csharp/components/property/property.test.js +117 -0
- package/dist/src/csharp/components/type-expression.d.ts +3 -3
- package/dist/src/csharp/components/type-expression.d.ts.map +1 -1
- package/dist/src/csharp/components/type-expression.js +15 -1
- package/dist/src/csharp/components/type-expression.test.d.ts +2 -0
- package/dist/src/csharp/components/type-expression.test.d.ts.map +1 -0
- package/dist/src/csharp/components/type-expression.test.js +128 -0
- package/dist/src/csharp/components/utils/doc-comments.d.ts +14 -0
- package/dist/src/csharp/components/utils/doc-comments.d.ts.map +1 -0
- package/dist/src/csharp/components/utils/doc-comments.js +67 -0
- package/dist/src/testing/index.d.ts +1 -1
- package/dist/src/testing/index.d.ts.map +1 -1
- package/dist/src/testing/scenario-test/harness.d.ts +2 -2
- package/dist/src/testing/scenario-test/harness.d.ts.map +1 -1
- package/dist/src/testing/scenario-test/test-host.d.ts +2 -2
- package/dist/src/testing/scenario-test/test-host.d.ts.map +1 -1
- package/dist/src/typescript/components/array-expression.d.ts +2 -3
- package/dist/src/typescript/components/array-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/array-expression.js +2 -2
- package/dist/src/typescript/components/arrow-function.d.ts +2 -2
- package/dist/src/typescript/components/arrow-function.d.ts.map +1 -1
- package/dist/src/typescript/components/arrow-function.js +2 -1
- package/dist/src/typescript/components/class-method.d.ts +1 -1
- package/dist/src/typescript/components/class-method.d.ts.map +1 -1
- package/dist/src/typescript/components/enum-declaration.d.ts +6 -6
- package/dist/src/typescript/components/enum-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/enum-declaration.js +2 -2
- package/dist/src/typescript/components/function-declaration.d.ts +1 -1
- package/dist/src/typescript/components/function-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/function-expression.d.ts +2 -2
- package/dist/src/typescript/components/function-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/function-expression.js +2 -1
- package/dist/src/typescript/components/function-type.d.ts +2 -2
- package/dist/src/typescript/components/function-type.d.ts.map +1 -1
- package/dist/src/typescript/components/function-type.js +2 -1
- package/dist/src/typescript/components/interface-declaration.d.ts +4 -4
- package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-declaration.js +3 -4
- package/dist/src/typescript/components/interface-member.d.ts +2 -2
- package/dist/src/typescript/components/interface-member.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-method.d.ts +2 -2
- package/dist/src/typescript/components/interface-method.d.ts.map +1 -1
- package/dist/src/typescript/components/record-expression.d.ts +1 -1
- package/dist/src/typescript/components/record-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/type-alias-declaration.d.ts +1 -1
- package/dist/src/typescript/components/type-alias-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/type-declaration.d.ts +1 -1
- package/dist/src/typescript/components/type-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/type-expression.d.ts +1 -1
- package/dist/src/typescript/components/type-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/type-transform.d.ts +2 -2
- package/dist/src/typescript/components/type-transform.d.ts.map +1 -1
- package/dist/src/typescript/components/union-declaration.d.ts +2 -2
- package/dist/src/typescript/components/union-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/union-expression.d.ts +3 -4
- package/dist/src/typescript/components/union-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/union-expression.js +3 -3
- package/dist/src/typescript/components/value-expression.d.ts +2 -2
- package/dist/src/typescript/components/value-expression.d.ts.map +1 -1
- package/dist/src/typescript/utils/operation.d.ts +2 -2
- package/dist/src/typescript/utils/operation.d.ts.map +1 -1
- package/dist/test/csharp/components/enum-declaration.test.js +57 -9
- package/dist/test/csharp/test-host.d.ts +1 -1
- package/dist/test/csharp/test-host.d.ts.map +1 -1
- package/dist/test/csharp/utils.d.ts +1 -1
- package/dist/test/csharp/utils.d.ts.map +1 -1
- package/dist/test/test-host.d.ts +2 -0
- package/dist/test/test-host.d.ts.map +1 -0
- package/dist/test/test-host.js +5 -0
- package/dist/test/typescript/components/member-expression.test.js +5 -5
- package/dist/test/typescript/test-host.d.ts +1 -1
- package/dist/test/typescript/test-host.d.ts.map +1 -1
- package/dist/test/utils.d.ts +2 -2
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/vitest.setup.d.ts +2 -0
- package/dist/test/vitest.setup.d.ts.map +1 -0
- package/dist/test/vitest.setup.js +1 -0
- package/package.json +10 -7
- package/src/core/components/output.tsx +9 -5
- package/src/core/context/name-policy-context.ts +2 -2
- package/src/core/context/tsp-context.ts +2 -2
- package/src/core/transport-name-policy.ts +1 -1
- package/src/core/write-output.ts +2 -2
- package/src/csharp/components/class/declaration.test.tsx +401 -0
- package/src/csharp/components/class/declaration.tsx +86 -0
- package/src/csharp/components/enum-declaration.tsx +26 -18
- package/src/csharp/components/index.ts +2 -1
- package/src/csharp/components/property/property.test.tsx +97 -0
- package/src/csharp/components/property/property.tsx +62 -0
- package/src/csharp/components/type-expression.test.tsx +133 -0
- package/src/csharp/components/type-expression.tsx +11 -4
- package/src/csharp/components/utils/doc-comments.tsx +58 -0
- package/src/testing/index.ts +1 -1
- package/src/testing/scenario-test/harness.ts +2 -2
- package/src/testing/scenario-test/test-host.ts +4 -4
- package/src/typescript/components/array-expression.tsx +3 -3
- package/src/typescript/components/arrow-function.tsx +2 -2
- package/src/typescript/components/class-method.tsx +1 -1
- package/src/typescript/components/enum-declaration.tsx +6 -6
- package/src/typescript/components/function-declaration.tsx +1 -1
- package/src/typescript/components/function-expression.tsx +2 -2
- package/src/typescript/components/function-type.tsx +2 -2
- package/src/typescript/components/interface-declaration.tsx +11 -12
- package/src/typescript/components/interface-member.tsx +2 -2
- package/src/typescript/components/interface-method.tsx +2 -2
- package/src/typescript/components/record-expression.tsx +1 -1
- package/src/typescript/components/type-alias-declaration.tsx +1 -1
- package/src/typescript/components/type-declaration.tsx +1 -1
- package/src/typescript/components/type-expression.tsx +2 -2
- package/src/typescript/components/type-transform.tsx +3 -3
- package/src/typescript/components/union-declaration.tsx +2 -2
- package/src/typescript/components/union-expression.tsx +12 -7
- package/src/typescript/components/value-expression.tsx +2 -2
- package/src/typescript/utils/operation.ts +2 -2
- package/test/csharp/components/enum-declaration.test.tsx +52 -11
- package/test/csharp/test-host.ts +2 -2
- package/test/csharp/utils.ts +1 -1
- package/test/test-host.ts +4 -0
- package/test/testing/snippet-extractor-csharp.test.ts +1 -1
- package/test/testing/snippet-extractor-java.test.ts +1 -1
- package/test/testing/snippet-extractor-python.test.ts +1 -1
- package/test/testing/snippet-extractor-typescript.test.ts +1 -1
- package/test/typescript/components/arrow-function.test.tsx +2 -2
- package/test/typescript/components/enum-declaration.test.tsx +1 -1
- package/test/typescript/components/function-declaration.test.tsx +1 -1
- package/test/typescript/components/function-expression.test.tsx +2 -2
- package/test/typescript/components/function-type.test.tsx +2 -2
- package/test/typescript/components/interface-declaration.test.tsx +1 -1
- package/test/typescript/components/interface-method.test.tsx +2 -2
- package/test/typescript/components/member-expression.test.tsx +10 -10
- package/test/typescript/components/type-alias-declaration.test.tsx +1 -1
- package/test/typescript/components/type-transform.test.tsx +2 -2
- package/test/typescript/components/union-declaration.test.tsx +2 -2
- package/test/typescript/components/value-expression.test.tsx +6 -6
- package/test/typescript/test-host.ts +1 -1
- package/test/utils.ts +2 -2
- package/test/vitest.setup.ts +1 -0
- package/tsconfig.json +3 -1
- package/vitest.config.ts +2 -1
- package/dist/src/csharp/components/class-declaration.d.ts +0 -9
- package/dist/src/csharp/components/class-declaration.d.ts.map +0 -1
- package/dist/src/csharp/components/class-declaration.js +0 -97
- package/dist/test/csharp/components/class-declaration.test.d.ts +0 -2
- package/dist/test/csharp/components/class-declaration.test.d.ts.map +0 -1
- package/dist/test/csharp/components/class-declaration.test.js +0 -421
- package/src/csharp/components/class-declaration.tsx +0 -87
- package/test/csharp/components/class-declaration.test.tsx +0 -344
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Children } from "@alloy-js/core";
|
|
1
|
+
import { type Children, For, List } from "@alloy-js/core";
|
|
3
2
|
import * as ts from "@alloy-js/typescript";
|
|
4
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
compilerAssert,
|
|
5
|
+
type Enum,
|
|
6
|
+
type EnumMember,
|
|
7
|
+
type Union,
|
|
8
|
+
type UnionVariant,
|
|
9
|
+
} from "@typespec/compiler";
|
|
5
10
|
import { useTsp } from "../../core/context/tsp-context.js";
|
|
6
11
|
import { efRefkey } from "../utils/refkey.js";
|
|
7
12
|
import { TypeExpression } from "./type-expression.jsx";
|
|
@@ -19,7 +24,7 @@ export function UnionExpression({ type, children }: UnionExpressionProps) {
|
|
|
19
24
|
>;
|
|
20
25
|
|
|
21
26
|
const variants = (
|
|
22
|
-
<
|
|
27
|
+
<For joiner={" | "} each={items}>
|
|
23
28
|
{(_, type) => {
|
|
24
29
|
if ($.enumMember.is(type)) {
|
|
25
30
|
return <ts.ValueExpression jsValue={type.value ?? type.name} />;
|
|
@@ -46,7 +51,7 @@ export function UnionExpression({ type, children }: UnionExpressionProps) {
|
|
|
46
51
|
return <TypeExpression type={type.type} />;
|
|
47
52
|
}
|
|
48
53
|
}}
|
|
49
|
-
</
|
|
54
|
+
</For>
|
|
50
55
|
);
|
|
51
56
|
|
|
52
57
|
if (children || (Array.isArray(children) && children.length)) {
|
|
@@ -121,7 +126,7 @@ function NoneEnvelope(props: NoneEnvelopeProps) {
|
|
|
121
126
|
}
|
|
122
127
|
|
|
123
128
|
return (
|
|
124
|
-
<
|
|
129
|
+
<List joiner={" & "}>
|
|
125
130
|
<ts.ObjectExpression>
|
|
126
131
|
<ts.ObjectProperty
|
|
127
132
|
name={props.discriminatorPropertyName}
|
|
@@ -129,6 +134,6 @@ function NoneEnvelope(props: NoneEnvelopeProps) {
|
|
|
129
134
|
/>
|
|
130
135
|
</ts.ObjectExpression>
|
|
131
136
|
<>{efRefkey(props.type.type)}</>
|
|
132
|
-
</
|
|
137
|
+
</List>
|
|
133
138
|
);
|
|
134
139
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Children } from "@alloy-js/core";
|
|
1
|
+
import { type Children } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
|
-
import { compilerAssert, Value } from "@typespec/compiler";
|
|
3
|
+
import { compilerAssert, type Value } from "@typespec/compiler";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Properties for the {@link ValueExpression} component.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { refkey, Refkey } from "@alloy-js/core";
|
|
1
|
+
import { refkey, type Refkey } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
|
-
import { Model, ModelProperty, Operation, Type } from "@typespec/compiler";
|
|
3
|
+
import type { Model, ModelProperty, Operation, Type } from "@typespec/compiler";
|
|
4
4
|
import { useTsp } from "../../core/index.js";
|
|
5
5
|
import { TypeExpression } from "../components/type-expression.jsx";
|
|
6
6
|
import { efRefkey } from "./refkey.js";
|
|
@@ -2,8 +2,8 @@ import { render } from "@alloy-js/core";
|
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import * as cs from "@alloy-js/csharp";
|
|
4
4
|
import { Namespace, SourceFile } from "@alloy-js/csharp";
|
|
5
|
-
import { Enum } from "@typespec/compiler";
|
|
6
|
-
import { BasicTestRunner } from "@typespec/compiler/testing";
|
|
5
|
+
import type { Enum } from "@typespec/compiler";
|
|
6
|
+
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
7
7
|
import { beforeEach, it } from "vitest";
|
|
8
8
|
import { Output } from "../../../src/core/index.js";
|
|
9
9
|
import { EnumDeclaration } from "../../../src/csharp/index.js";
|
|
@@ -40,7 +40,7 @@ it("renders a basic enum declaration", async () => {
|
|
|
40
40
|
d`
|
|
41
41
|
namespace TestNamespace
|
|
42
42
|
{
|
|
43
|
-
|
|
43
|
+
enum TestEnum
|
|
44
44
|
{
|
|
45
45
|
Value1,
|
|
46
46
|
Value2,
|
|
@@ -71,7 +71,7 @@ it("renders an empty enum declaration", async () => {
|
|
|
71
71
|
d`
|
|
72
72
|
namespace TestNamespace
|
|
73
73
|
{
|
|
74
|
-
|
|
74
|
+
enum TestEnum
|
|
75
75
|
{
|
|
76
76
|
|
|
77
77
|
}
|
|
@@ -103,7 +103,7 @@ it("can override enum name", async () => {
|
|
|
103
103
|
d`
|
|
104
104
|
namespace TestNamespace
|
|
105
105
|
{
|
|
106
|
-
|
|
106
|
+
enum CustomEnumName
|
|
107
107
|
{
|
|
108
108
|
Value1,
|
|
109
109
|
Value2
|
|
@@ -125,7 +125,7 @@ it("renders an enum with access modifiers", async () => {
|
|
|
125
125
|
<Output program={runner.program}>
|
|
126
126
|
<Namespace name="TestNamespace">
|
|
127
127
|
<SourceFile path="test.cs">
|
|
128
|
-
<EnumDeclaration type={TestEnum}
|
|
128
|
+
<EnumDeclaration type={TestEnum} internal />
|
|
129
129
|
</SourceFile>
|
|
130
130
|
</Namespace>
|
|
131
131
|
</Output>,
|
|
@@ -170,7 +170,7 @@ it("renders enum with C# naming conventions", async () => {
|
|
|
170
170
|
d`
|
|
171
171
|
namespace TestNamespace
|
|
172
172
|
{
|
|
173
|
-
|
|
173
|
+
enum TestEnum
|
|
174
174
|
{
|
|
175
175
|
ValueOne,
|
|
176
176
|
ValueTwo,
|
|
@@ -203,7 +203,7 @@ it("renders enum with single value", async () => {
|
|
|
203
203
|
d`
|
|
204
204
|
namespace TestNamespace
|
|
205
205
|
{
|
|
206
|
-
|
|
206
|
+
enum TestEnum
|
|
207
207
|
{
|
|
208
208
|
OnlyValue
|
|
209
209
|
}
|
|
@@ -237,7 +237,7 @@ it("renders enum with numeric-like member names", async () => {
|
|
|
237
237
|
d`
|
|
238
238
|
namespace TestNamespace
|
|
239
239
|
{
|
|
240
|
-
|
|
240
|
+
enum TestEnum
|
|
241
241
|
{
|
|
242
242
|
Value0,
|
|
243
243
|
Value1,
|
|
@@ -279,12 +279,12 @@ it("renders multiple enums in the same namespace", async () => {
|
|
|
279
279
|
d`
|
|
280
280
|
namespace TestNamespace
|
|
281
281
|
{
|
|
282
|
-
|
|
282
|
+
enum TestEnum1
|
|
283
283
|
{
|
|
284
284
|
Value1,
|
|
285
285
|
Value2
|
|
286
286
|
}
|
|
287
|
-
|
|
287
|
+
enum TestEnum2
|
|
288
288
|
{
|
|
289
289
|
OptionA,
|
|
290
290
|
OptionB,
|
|
@@ -294,3 +294,44 @@ it("renders multiple enums in the same namespace", async () => {
|
|
|
294
294
|
`,
|
|
295
295
|
);
|
|
296
296
|
});
|
|
297
|
+
|
|
298
|
+
it("renders an enum with doc comments", async () => {
|
|
299
|
+
const { TestEnum } = (await runner.compile(`
|
|
300
|
+
@test enum TestEnum {
|
|
301
|
+
@doc("This is value one")
|
|
302
|
+
Value1;
|
|
303
|
+
/** This is value two */
|
|
304
|
+
Value2;
|
|
305
|
+
}
|
|
306
|
+
`)) as { TestEnum: Enum };
|
|
307
|
+
|
|
308
|
+
const res = render(
|
|
309
|
+
<Output program={runner.program}>
|
|
310
|
+
<Namespace name="TestNamespace">
|
|
311
|
+
<SourceFile path="test.cs">
|
|
312
|
+
<EnumDeclaration type={TestEnum} />
|
|
313
|
+
</SourceFile>
|
|
314
|
+
</Namespace>
|
|
315
|
+
</Output>,
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
assertFileContents(
|
|
319
|
+
res,
|
|
320
|
+
d`
|
|
321
|
+
namespace TestNamespace
|
|
322
|
+
{
|
|
323
|
+
enum TestEnum
|
|
324
|
+
{
|
|
325
|
+
/// <summary>
|
|
326
|
+
/// This is value one
|
|
327
|
+
/// </summary>
|
|
328
|
+
Value1,
|
|
329
|
+
/// <summary>
|
|
330
|
+
/// This is value two
|
|
331
|
+
/// </summary>
|
|
332
|
+
Value2
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
`,
|
|
336
|
+
);
|
|
337
|
+
});
|
package/test/csharp/test-host.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Program } from "@typespec/compiler";
|
|
1
|
+
import type { Program } from "@typespec/compiler";
|
|
2
2
|
import {
|
|
3
3
|
createTestHost,
|
|
4
4
|
createTestWrapper,
|
|
5
5
|
expectDiagnosticEmpty,
|
|
6
|
-
TypeSpecTestLibrary,
|
|
6
|
+
type TypeSpecTestLibrary,
|
|
7
7
|
} from "@typespec/compiler/testing";
|
|
8
8
|
import { HttpTestLibrary } from "@typespec/http/testing";
|
|
9
9
|
|
package/test/csharp/utils.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { beforeEach, describe, expect, it } from "vitest";
|
|
|
3
3
|
import {
|
|
4
4
|
createCSharpExtractorConfig,
|
|
5
5
|
createSnipperExtractor,
|
|
6
|
-
SnippetExtractor,
|
|
6
|
+
type SnippetExtractor,
|
|
7
7
|
} from "../../src/testing/index.js";
|
|
8
8
|
describe("C# Snippet Extractor", () => {
|
|
9
9
|
let extractor: SnippetExtractor;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
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
|
-
import { Operation } from "@typespec/compiler";
|
|
5
|
-
import { BasicTestRunner } from "@typespec/compiler/testing";
|
|
4
|
+
import type { Operation } from "@typespec/compiler";
|
|
5
|
+
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
6
|
import { beforeEach, describe, it } from "vitest";
|
|
7
7
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
8
8
|
import { ArrowFunction } from "../../../src/typescript/components/arrow-function.jsx";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { List, StatementList } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
|
-
import { Enum, Union } from "@typespec/compiler";
|
|
3
|
+
import type { Enum, Union } from "@typespec/compiler";
|
|
4
4
|
import { describe, expect, it } from "vitest";
|
|
5
5
|
import { TspContext } from "../../../src/core/index.js";
|
|
6
6
|
import { EnumDeclaration } from "../../../src/typescript/components/enum-declaration.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
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
|
-
import { Namespace } from "@typespec/compiler";
|
|
4
|
+
import type { Namespace } from "@typespec/compiler";
|
|
5
5
|
import { format } from "prettier";
|
|
6
6
|
import { assert, describe, expect, it } from "vitest";
|
|
7
7
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
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
|
-
import { Operation } from "@typespec/compiler";
|
|
5
|
-
import { BasicTestRunner } from "@typespec/compiler/testing";
|
|
4
|
+
import type { Operation } from "@typespec/compiler";
|
|
5
|
+
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
6
|
import { beforeEach, describe, it } from "vitest";
|
|
7
7
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
8
8
|
import { FunctionExpression } from "../../../src/typescript/components/function-expression.jsx";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
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
|
-
import { Operation } from "@typespec/compiler";
|
|
5
|
-
import { BasicTestRunner } from "@typespec/compiler/testing";
|
|
4
|
+
import type { Operation } from "@typespec/compiler";
|
|
5
|
+
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
6
|
import { beforeEach, describe, it } from "vitest";
|
|
7
7
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
8
8
|
import { FunctionType } from "../../../src/typescript/index.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { For, List, render } from "@alloy-js/core";
|
|
2
2
|
import { SourceFile } from "@alloy-js/typescript";
|
|
3
|
-
import { Namespace } from "@typespec/compiler";
|
|
3
|
+
import type { Namespace } from "@typespec/compiler";
|
|
4
4
|
import { format } from "prettier";
|
|
5
5
|
import { assert, describe, expect, it } from "vitest";
|
|
6
6
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
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
|
-
import { Operation } from "@typespec/compiler";
|
|
5
|
-
import { BasicTestRunner } from "@typespec/compiler/testing";
|
|
4
|
+
import type { Operation } from "@typespec/compiler";
|
|
5
|
+
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
6
|
import { beforeEach, describe, it } from "vitest";
|
|
7
7
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
8
8
|
import { InterfaceMethod } from "../../../src/typescript/components/interface-method.jsx";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { List } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
|
-
import { Enum, Model, Union } from "@typespec/compiler";
|
|
3
|
+
import type { Enum, Model, Union } from "@typespec/compiler";
|
|
4
4
|
import { describe, expect, it } from "vitest";
|
|
5
5
|
import { TspContext } from "../../../src/core/index.js";
|
|
6
6
|
import { EnumDeclaration } from "../../../src/typescript/components/enum-declaration.js";
|
|
@@ -24,10 +24,10 @@ describe("Typescript Enum Member Expression", () => {
|
|
|
24
24
|
const Bar = program.resolveTypeReference("Bar")[0]! as Model;
|
|
25
25
|
return (
|
|
26
26
|
<TspContext.Provider value={{ program }}>
|
|
27
|
-
<
|
|
27
|
+
<List hardline>
|
|
28
28
|
<EnumDeclaration type={program.resolveTypeReference("Foo")[0]! as Enum} />
|
|
29
29
|
<InterfaceDeclaration type={Bar} />
|
|
30
|
-
</
|
|
30
|
+
</List>
|
|
31
31
|
</TspContext.Provider>
|
|
32
32
|
);
|
|
33
33
|
});
|
|
@@ -60,10 +60,10 @@ describe("Typescript Enum Member Expression", () => {
|
|
|
60
60
|
const Bar = program.resolveTypeReference("Bar")[0]! as Model;
|
|
61
61
|
return (
|
|
62
62
|
<TspContext.Provider value={{ program }}>
|
|
63
|
-
<
|
|
63
|
+
<List hardline>
|
|
64
64
|
<EnumDeclaration type={program.resolveTypeReference("Foo")[0]! as Enum} />
|
|
65
65
|
<InterfaceDeclaration type={Bar} />
|
|
66
|
-
</
|
|
66
|
+
</List>
|
|
67
67
|
</TspContext.Provider>
|
|
68
68
|
);
|
|
69
69
|
});
|
|
@@ -98,10 +98,10 @@ describe("Typescript Union Member Expression", () => {
|
|
|
98
98
|
const Bar = program.resolveTypeReference("Bar")[0]! as Model;
|
|
99
99
|
return (
|
|
100
100
|
<TspContext.Provider value={{ program }}>
|
|
101
|
-
<
|
|
101
|
+
<List hardline>
|
|
102
102
|
<UnionDeclaration type={program.resolveTypeReference("Foo")[0]! as Union} />
|
|
103
103
|
<InterfaceDeclaration type={Bar} />
|
|
104
|
-
</
|
|
104
|
+
</List>
|
|
105
105
|
</TspContext.Provider>
|
|
106
106
|
);
|
|
107
107
|
});
|
|
@@ -130,10 +130,10 @@ describe("Typescript Union Member Expression", () => {
|
|
|
130
130
|
const Bar = program.resolveTypeReference("Bar")[0]! as Model;
|
|
131
131
|
return (
|
|
132
132
|
<TspContext.Provider value={{ program }}>
|
|
133
|
-
<
|
|
133
|
+
<List hardline>
|
|
134
134
|
<UnionDeclaration type={program.resolveTypeReference("Foo")[0]! as Union} />
|
|
135
135
|
<InterfaceDeclaration type={Bar} />
|
|
136
|
-
</
|
|
136
|
+
</List>
|
|
137
137
|
</TspContext.Provider>
|
|
138
138
|
);
|
|
139
139
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { render } from "@alloy-js/core";
|
|
2
2
|
import { SourceFile } from "@alloy-js/typescript";
|
|
3
|
-
import { Namespace, Operation } from "@typespec/compiler";
|
|
3
|
+
import type { Namespace, Operation } from "@typespec/compiler";
|
|
4
4
|
import { format } from "prettier";
|
|
5
5
|
import { assert, describe, expect, it } from "vitest";
|
|
6
6
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
@@ -2,8 +2,8 @@ import { code, Output, render } from "@alloy-js/core";
|
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import * as ts from "@alloy-js/typescript";
|
|
4
4
|
import { SourceFile } from "@alloy-js/typescript";
|
|
5
|
-
import { Model } from "@typespec/compiler";
|
|
6
|
-
import { BasicTestRunner } from "@typespec/compiler/testing";
|
|
5
|
+
import type { Model } from "@typespec/compiler";
|
|
6
|
+
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
7
7
|
import { assert, beforeEach, describe, expect, it } from "vitest";
|
|
8
8
|
import {
|
|
9
9
|
ArraySerializer,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
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
|
-
import { Enum, Model, Union } from "@typespec/compiler";
|
|
5
|
-
import { BasicTestRunner } from "@typespec/compiler/testing";
|
|
4
|
+
import type { Enum, Model, Union } from "@typespec/compiler";
|
|
5
|
+
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
6
|
import { beforeEach, describe, it } from "vitest";
|
|
7
7
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
8
8
|
import { UnionDeclaration } from "../../../src/typescript/components/union-declaration.js";
|
|
@@ -2,13 +2,13 @@ import { Output, render } from "@alloy-js/core";
|
|
|
2
2
|
import { dedent } from "@alloy-js/core/testing";
|
|
3
3
|
import { SourceFile } from "@alloy-js/typescript";
|
|
4
4
|
import {
|
|
5
|
-
EnumValue,
|
|
6
|
-
Model,
|
|
7
|
-
Namespace,
|
|
5
|
+
type EnumValue,
|
|
6
|
+
type Model,
|
|
7
|
+
type Namespace,
|
|
8
8
|
Numeric,
|
|
9
|
-
NumericValue,
|
|
10
|
-
Program,
|
|
11
|
-
Value,
|
|
9
|
+
type NumericValue,
|
|
10
|
+
type Program,
|
|
11
|
+
type Value,
|
|
12
12
|
} from "@typespec/compiler";
|
|
13
13
|
import { $ } from "@typespec/compiler/typekit";
|
|
14
14
|
import { assert, beforeAll, describe, expect, it } from "vitest";
|
package/test/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Children, OutputDirectory, render } from "@alloy-js/core";
|
|
1
|
+
import { type Children, type OutputDirectory, render } from "@alloy-js/core";
|
|
2
2
|
import { Output } from "@alloy-js/core/stc";
|
|
3
3
|
import { SourceFile } from "@alloy-js/typescript/stc";
|
|
4
|
-
import { Program } from "@typespec/compiler";
|
|
4
|
+
import type { Program } from "@typespec/compiler";
|
|
5
5
|
import { assert } from "vitest";
|
|
6
6
|
import { getProgram } from "./typescript/test-host.js";
|
|
7
7
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@alloy-js/core/testing";
|
package/tsconfig.json
CHANGED
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
"jsxImportSource": "@alloy-js/core",
|
|
15
15
|
"emitDeclarationOnly": true,
|
|
16
16
|
"outDir": "dist",
|
|
17
|
-
"rootDir": "./"
|
|
17
|
+
"rootDir": "./",
|
|
18
|
+
"verbatimModuleSyntax": true,
|
|
19
|
+
"types": ["@alloy-js/core/testing/matchers"]
|
|
18
20
|
},
|
|
19
21
|
"include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "test/**/*.tsx"],
|
|
20
22
|
"exclude": ["node_modules", "dist"]
|
package/vitest.config.ts
CHANGED
|
@@ -6,8 +6,9 @@ export default mergeConfig(
|
|
|
6
6
|
defaultTypeSpecVitestConfig,
|
|
7
7
|
defineConfig({
|
|
8
8
|
test: {
|
|
9
|
-
include: ["test/**/*.test.ts", "test/**/*.test.tsx"],
|
|
9
|
+
include: ["src/**/*.test.ts", "src/**/*.test.tsx", "test/**/*.test.ts", "test/**/*.test.tsx"],
|
|
10
10
|
passWithNoTests: true,
|
|
11
|
+
setupFiles: ["./test/vitest.setup.ts"],
|
|
11
12
|
},
|
|
12
13
|
esbuild: {
|
|
13
14
|
jsx: "preserve",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as ay from "@alloy-js/core";
|
|
2
|
-
import * as cs from "@alloy-js/csharp";
|
|
3
|
-
import { Interface, Model } from "@typespec/compiler";
|
|
4
|
-
export interface ClassDeclarationProps extends Omit<cs.ClassProps, "name"> {
|
|
5
|
-
name?: string;
|
|
6
|
-
type: Model | Interface;
|
|
7
|
-
}
|
|
8
|
-
export declare function ClassDeclaration(props: ClassDeclarationProps): ay.Children;
|
|
9
|
-
//# sourceMappingURL=class-declaration.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"class-declaration.d.ts","sourceRoot":"","sources":["../../../../src/csharp/components/class-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAKtD,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC;IACxE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;CACzB;AAUD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,EAAE,CAAC,QAAQ,CAgB1E"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import * as ay from "@alloy-js/core";
|
|
3
|
-
import * as cs from "@alloy-js/csharp";
|
|
4
|
-
import { useTsp } from "../../core/index.js";
|
|
5
|
-
import { TypeExpression } from "./type-expression.js";
|
|
6
|
-
import { declarationRefkeys } from "./utils/refkey.js";
|
|
7
|
-
export function ClassDeclaration(props) {
|
|
8
|
-
const {
|
|
9
|
-
$
|
|
10
|
-
} = useTsp();
|
|
11
|
-
const namePolicy = cs.useCSharpNamePolicy();
|
|
12
|
-
const className = props.name ?? namePolicy.getName(props.type.name, "class");
|
|
13
|
-
const refkeys = declarationRefkeys(props.refkey, props.type)[0]; // TODO: support multiple refkeys for declarations in alloy
|
|
14
|
-
|
|
15
|
-
return [_$createComponent(cs.Class, {
|
|
16
|
-
name: className,
|
|
17
|
-
get accessModifier() {
|
|
18
|
-
return props.accessModifier;
|
|
19
|
-
},
|
|
20
|
-
refkey: refkeys,
|
|
21
|
-
get children() {
|
|
22
|
-
return [_$memo(() => _$memo(() => !!$.model.is(props.type))() && _$createComponent(ClassProperties, {
|
|
23
|
-
get type() {
|
|
24
|
-
return props.type;
|
|
25
|
-
}
|
|
26
|
-
})), _$memo(() => _$memo(() => props.type.kind === "Interface")() && _$createComponent(ClassMethods, {
|
|
27
|
-
get type() {
|
|
28
|
-
return props.type;
|
|
29
|
-
}
|
|
30
|
-
}))];
|
|
31
|
-
}
|
|
32
|
-
})];
|
|
33
|
-
}
|
|
34
|
-
function ClassProperties(props) {
|
|
35
|
-
const namePolicy = cs.useCSharpNamePolicy();
|
|
36
|
-
const classProperties = [];
|
|
37
|
-
for (const [name, prop] of props.type.properties) {
|
|
38
|
-
classProperties.push([_$createComponent(cs.ClassMember, {
|
|
39
|
-
get name() {
|
|
40
|
-
return namePolicy.getName(name, "class-member-public");
|
|
41
|
-
},
|
|
42
|
-
get type() {
|
|
43
|
-
return _$createComponent(TypeExpression, {
|
|
44
|
-
get type() {
|
|
45
|
-
return prop.type;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
accessModifier: "public"
|
|
50
|
-
}), " ", _$createComponent(ay.Block, {
|
|
51
|
-
newline: true,
|
|
52
|
-
get children() {
|
|
53
|
-
return _$createComponent(ay.StatementList, {
|
|
54
|
-
children: ["get", "set"]
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
})]);
|
|
58
|
-
}
|
|
59
|
-
return _$createComponent(ay.For, {
|
|
60
|
-
each: classProperties,
|
|
61
|
-
hardline: true,
|
|
62
|
-
children: c => c
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
function ClassMethods(props) {
|
|
66
|
-
const namePolicy = cs.useCSharpNamePolicy();
|
|
67
|
-
const abstractMethods = [];
|
|
68
|
-
for (const [name, prop] of props.type.operations) {
|
|
69
|
-
abstractMethods.push(_$createComponent(cs.ClassMethod, {
|
|
70
|
-
get name() {
|
|
71
|
-
return namePolicy.getName(name, "class-method");
|
|
72
|
-
},
|
|
73
|
-
methodModifier: "abstract",
|
|
74
|
-
get parameters() {
|
|
75
|
-
return [...prop.parameters.properties.entries()].map(([name, prop]) => {
|
|
76
|
-
return {
|
|
77
|
-
name: namePolicy.getName(name, "type-parameter"),
|
|
78
|
-
type: _$createComponent(TypeExpression, {
|
|
79
|
-
get type() {
|
|
80
|
-
return prop.type;
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
};
|
|
84
|
-
});
|
|
85
|
-
},
|
|
86
|
-
accessModifier: "public",
|
|
87
|
-
get returns() {
|
|
88
|
-
return _$createComponent(TypeExpression, {
|
|
89
|
-
get type() {
|
|
90
|
-
return prop.returnType;
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}));
|
|
95
|
-
}
|
|
96
|
-
return [abstractMethods];
|
|
97
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"class-declaration.test.d.ts","sourceRoot":"","sources":["../../../../test/csharp/components/class-declaration.test.tsx"],"names":[],"mappings":""}
|