@typespec/emitter-framework 0.9.0-dev.0 → 0.9.0-dev.10
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 +377 -0
- package/dist/src/csharp/components/enum/declaration.d.ts +9 -0
- package/dist/src/csharp/components/enum/declaration.d.ts.map +1 -0
- package/dist/src/csharp/components/enum/declaration.js +55 -0
- package/dist/src/csharp/components/enum/declaration.test.d.ts +2 -0
- package/dist/src/csharp/components/enum/declaration.test.d.ts.map +1 -0
- package/dist/src/csharp/components/enum/declaration.test.js +309 -0
- package/dist/src/csharp/components/index.d.ts +5 -0
- package/dist/src/csharp/components/index.d.ts.map +1 -0
- package/dist/src/csharp/components/index.js +4 -0
- 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 +11 -0
- package/dist/src/csharp/components/type-expression.d.ts.map +1 -0
- package/dist/src/csharp/components/type-expression.js +143 -0
- 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/csharp/components/utils/refkey.d.ts +23 -0
- package/dist/src/csharp/components/utils/refkey.d.ts.map +1 -0
- package/dist/src/csharp/components/utils/refkey.js +35 -0
- package/dist/src/csharp/index.d.ts +2 -0
- package/dist/src/csharp/index.d.ts.map +1 -0
- package/dist/src/csharp/index.js +1 -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/code-block-expectation.d.ts +33 -0
- package/dist/src/testing/scenario-test/code-block-expectation.d.ts.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.js +69 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.d.ts +2 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.d.ts.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.js +80 -0
- package/dist/src/testing/scenario-test/harness.d.ts +3 -3
- package/dist/src/testing/scenario-test/harness.d.ts.map +1 -1
- package/dist/src/testing/scenario-test/harness.js +69 -158
- package/dist/src/testing/scenario-test/index.d.ts +0 -1
- package/dist/src/testing/scenario-test/index.d.ts.map +1 -1
- package/dist/src/testing/scenario-test/index.js +1 -2
- package/dist/src/testing/scenario-test/snippet-extractor.d.ts +1 -1
- package/dist/src/testing/scenario-test/snippet-extractor.js +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/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/testing/snippet-extractor-csharp.test.js +3 -3
- package/dist/test/testing/snippet-extractor-java.test.js +3 -3
- package/dist/test/testing/snippet-extractor-python.test.js +2 -2
- package/dist/test/testing/snippet-extractor-typescript.test.js +3 -3
- 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 +30 -8
- 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 +339 -0
- package/src/csharp/components/class/declaration.tsx +86 -0
- package/src/csharp/components/enum/declaration.test.tsx +267 -0
- package/src/csharp/components/enum/declaration.tsx +56 -0
- package/src/csharp/components/index.ts +4 -0
- 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 +119 -0
- package/src/csharp/components/utils/doc-comments.tsx +58 -0
- package/src/csharp/components/utils/refkey.ts +36 -0
- package/src/csharp/index.ts +1 -0
- package/src/testing/index.ts +1 -1
- package/src/testing/scenario-test/code-block-expectation.test.ts +95 -0
- package/src/testing/scenario-test/code-block-expectation.ts +115 -0
- package/src/testing/scenario-test/harness.ts +92 -237
- package/src/testing/scenario-test/index.ts +0 -1
- package/src/testing/scenario-test/snippet-extractor.ts +1 -1
- 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/test-host.ts +4 -0
- package/test/testing/snippet-extractor-csharp.test.ts +4 -4
- package/test/testing/snippet-extractor-java.test.ts +4 -4
- package/test/testing/snippet-extractor-python.test.ts +3 -3
- package/test/testing/snippet-extractor-typescript.test.ts +4 -4
- 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/testing/scenario-test/test-host.d.ts +0 -8
- package/dist/src/testing/scenario-test/test-host.d.ts.map +0 -1
- package/dist/src/testing/scenario-test/test-host.js +0 -49
- package/src/testing/scenario-test/test-host.ts +0 -83
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Program } from "@typespec/compiler";
|
|
3
|
-
export interface OutputProps extends
|
|
1
|
+
import { type OutputProps as CoreOutputProps } from "@alloy-js/core";
|
|
2
|
+
import type { Program } from "@typespec/compiler";
|
|
3
|
+
export interface OutputProps extends CoreOutputProps {
|
|
4
4
|
/**
|
|
5
5
|
* TypeSpec program.
|
|
6
6
|
*/
|
|
7
7
|
program: Program;
|
|
8
8
|
}
|
|
9
|
-
export declare function Output(props: OutputProps):
|
|
9
|
+
export declare function Output(props: OutputProps): import("@alloy-js/core").Children;
|
|
10
10
|
//# sourceMappingURL=output.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../../src/core/components/output.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../../src/core/components/output.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,WAAW,IAAI,eAAe,EACpC,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD,MAAM,WAAW,WAAY,SAAQ,eAAe;IAClD;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,qCAOxC"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import { Output as CoreOutput, splitProps } from "@alloy-js/core";
|
|
3
3
|
import { TspContext } from "../context/tsp-context.js";
|
|
4
4
|
export function Output(props) {
|
|
5
5
|
const [{
|
|
6
6
|
program
|
|
7
|
-
}, rest] =
|
|
7
|
+
}, rest] = splitProps(props, ["program"]);
|
|
8
8
|
return _$createComponent(TspContext.Provider, {
|
|
9
9
|
value: {
|
|
10
10
|
program
|
|
11
11
|
},
|
|
12
12
|
get children() {
|
|
13
|
-
return _$createComponent(
|
|
13
|
+
return _$createComponent(CoreOutput, rest);
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ComponentContext } from "@alloy-js/core";
|
|
2
|
-
import { TransformNamePolicy } from "../transport-name-policy.js";
|
|
1
|
+
import { type ComponentContext } from "@alloy-js/core";
|
|
2
|
+
import type { TransformNamePolicy } from "../transport-name-policy.js";
|
|
3
3
|
export declare const TransformNamePolicyContext: ComponentContext<TransformNamePolicy>;
|
|
4
4
|
export declare function useTransformNamePolicy(): TransformNamePolicy;
|
|
5
5
|
//# sourceMappingURL=name-policy-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"name-policy-context.d.ts","sourceRoot":"","sources":["../../../../src/core/context/name-policy-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAkC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"name-policy-context.d.ts","sourceRoot":"","sources":["../../../../src/core/context/name-policy-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAkC,MAAM,gBAAgB,CAAC;AACvF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAEvE,eAAO,MAAM,0BAA0B,EAAE,gBAAgB,CAAC,mBAAmB,CAQzE,CAAC;AAEL,wBAAgB,sBAAsB,wBAErC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ComponentContext } from "@alloy-js/core";
|
|
2
|
-
import { Program } from "@typespec/compiler";
|
|
1
|
+
import { type ComponentContext } from "@alloy-js/core";
|
|
2
|
+
import type { Program } from "@typespec/compiler";
|
|
3
3
|
import { type Typekit } from "@typespec/compiler/typekit";
|
|
4
4
|
export type TspContext = {
|
|
5
5
|
program: Program;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsp-context.d.ts","sourceRoot":"","sources":["../../../../src/core/context/tsp-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAkC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"tsp-context.d.ts","sourceRoot":"","sources":["../../../../src/core/context/tsp-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAkC,MAAM,gBAAgB,CAAC;AACvF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAK,KAAK,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,CAAC,EAAE,OAAO,CAAC;CACZ,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,gBAAgB,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,CAAC,CAAC,EAAE,OAAO,CAAA;CAAE,CAG3D,CAAC;AAEjB,wBAAgB,MAAM,IAaF,UAAU,CAC7B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Type } from "@typespec/compiler";
|
|
1
|
+
import type { Type } from "@typespec/compiler";
|
|
2
2
|
/**
|
|
3
3
|
* A type that extends `Type` and includes a `name` property that can either be a `string` or `symbol`.
|
|
4
4
|
* This type is used to represent objects that have a `name` of type `string` or `symbol`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport-name-policy.d.ts","sourceRoot":"","sources":["../../../src/core/transport-name-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"transport-name-policy.d.ts","sourceRoot":"","sources":["../../../src/core/transport-name-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAEpE;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;OAMG;IACH,gBAAgB,CAAC,CAAC,SAAS,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC;IAE3D;;;;;;OAMG;IACH,kBAAkB,CAAC,CAAC,SAAS,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC;CAC9D;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE;IAC/C,cAAc,EAAE,CAAC,CAAC,SAAS,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;IAC7D,gBAAgB,EAAE,CAAC,CAAC,SAAS,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;CAChE,GAAG,mBAAmB,CAsBtB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Children } from "@alloy-js/core";
|
|
2
|
-
import { Program } from "@typespec/compiler";
|
|
1
|
+
import { type Children } from "@alloy-js/core";
|
|
2
|
+
import { type Program } from "@typespec/compiler";
|
|
3
3
|
export declare function writeOutput(program: Program, rootComponent: Children, emitterOutputDir: string): Promise<void>;
|
|
4
4
|
//# sourceMappingURL=write-output.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-output.d.ts","sourceRoot":"","sources":["../../../src/core/write-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"write-output.d.ts","sourceRoot":"","sources":["../../../src/core/write-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAgC,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAuB,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEvE,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,QAAQ,EACvB,gBAAgB,EAAE,MAAM,iBAIzB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Children } from "@alloy-js/core";
|
|
2
|
+
import * as cs from "@alloy-js/csharp";
|
|
3
|
+
import type { Interface, Model } from "@typespec/compiler";
|
|
4
|
+
export interface ClassDeclarationProps extends Omit<cs.ClassDeclarationProps, "name"> {
|
|
5
|
+
/** Set an alternative name for the class. Otherwise default to the type name. */
|
|
6
|
+
name?: string;
|
|
7
|
+
/** Type to use to create this class. */
|
|
8
|
+
type: Model | Interface;
|
|
9
|
+
/** If set the property will add the json serialization attributes(using System.Text.Json). */
|
|
10
|
+
jsonAttributes?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function ClassDeclaration(props: ClassDeclarationProps): Children;
|
|
13
|
+
//# sourceMappingURL=declaration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../../src/csharp/components/class/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAO,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAO3D,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,EAAE,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACnF,iFAAiF;IACjF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;IACxB,8FAA8F;IAC9F,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAYD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,QAAQ,CAuBvE"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { memo as _$memo, mergeProps as _$mergeProps, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { For } from "@alloy-js/core";
|
|
3
|
+
import * as cs from "@alloy-js/csharp";
|
|
4
|
+
import { useTsp } from "../../../core/index.js";
|
|
5
|
+
import { Property } from "../property/property.js";
|
|
6
|
+
import { TypeExpression } from "../type-expression.js";
|
|
7
|
+
import { getDocComments } from "../utils/doc-comments.js";
|
|
8
|
+
import { declarationRefkeys } from "../utils/refkey.js";
|
|
9
|
+
export function ClassDeclaration(props) {
|
|
10
|
+
const {
|
|
11
|
+
$
|
|
12
|
+
} = useTsp();
|
|
13
|
+
const namePolicy = cs.useCSharpNamePolicy();
|
|
14
|
+
const className = props.name ?? namePolicy.getName(props.type.name, "class");
|
|
15
|
+
const refkeys = declarationRefkeys(props.refkey, props.type)[0]; // TODO: support multiple refkeys for declarations in alloy
|
|
16
|
+
|
|
17
|
+
return [_$createComponent(cs.ClassDeclaration, _$mergeProps(props, {
|
|
18
|
+
name: className,
|
|
19
|
+
refkey: refkeys,
|
|
20
|
+
get doc() {
|
|
21
|
+
return getDocComments($, props.type);
|
|
22
|
+
},
|
|
23
|
+
get children() {
|
|
24
|
+
return [_$memo(() => _$memo(() => props.type.kind === "Model")() && _$createComponent(ClassProperties, {
|
|
25
|
+
get type() {
|
|
26
|
+
return props.type;
|
|
27
|
+
},
|
|
28
|
+
get jsonAttributes() {
|
|
29
|
+
return props.jsonAttributes;
|
|
30
|
+
}
|
|
31
|
+
})), _$memo(() => _$memo(() => props.type.kind === "Interface")() && _$createComponent(ClassMethods, {
|
|
32
|
+
get type() {
|
|
33
|
+
return props.type;
|
|
34
|
+
}
|
|
35
|
+
}))];
|
|
36
|
+
}
|
|
37
|
+
}))];
|
|
38
|
+
}
|
|
39
|
+
function ClassProperties(props) {
|
|
40
|
+
return _$createComponent(For, {
|
|
41
|
+
get each() {
|
|
42
|
+
return props.type.properties.entries();
|
|
43
|
+
},
|
|
44
|
+
hardline: true,
|
|
45
|
+
children: ([name, property]) => _$createComponent(Property, {
|
|
46
|
+
type: property,
|
|
47
|
+
get jsonAttributes() {
|
|
48
|
+
return props.jsonAttributes;
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function ClassMethods(props) {
|
|
54
|
+
const {
|
|
55
|
+
$
|
|
56
|
+
} = useTsp();
|
|
57
|
+
const namePolicy = cs.useCSharpNamePolicy();
|
|
58
|
+
const abstractMethods = [];
|
|
59
|
+
for (const [name, method] of props.type.operations) {
|
|
60
|
+
abstractMethods.push(_$createComponent(cs.ClassMethod, {
|
|
61
|
+
get name() {
|
|
62
|
+
return namePolicy.getName(name, "class-method");
|
|
63
|
+
},
|
|
64
|
+
abstract: true,
|
|
65
|
+
get parameters() {
|
|
66
|
+
return [...method.parameters.properties.entries()].map(([name, prop]) => {
|
|
67
|
+
return {
|
|
68
|
+
name: namePolicy.getName(name, "type-parameter"),
|
|
69
|
+
type: _$createComponent(TypeExpression, {
|
|
70
|
+
get type() {
|
|
71
|
+
return prop.type;
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
"public": true,
|
|
78
|
+
get doc() {
|
|
79
|
+
return getDocComments($, method);
|
|
80
|
+
},
|
|
81
|
+
get returns() {
|
|
82
|
+
return _$createComponent(TypeExpression, {
|
|
83
|
+
get type() {
|
|
84
|
+
return method.returnType;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
return [abstractMethods];
|
|
91
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declaration.test.d.ts","sourceRoot":"","sources":["../../../../../src/csharp/components/class/declaration.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Tester } from "#test/test-host.js";
|
|
3
|
+
import { createCSharpNamePolicy, Namespace, SourceFile } from "@alloy-js/csharp";
|
|
4
|
+
import { t } from "@typespec/compiler/testing";
|
|
5
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
6
|
+
import { Output } from "../../../core/index.js";
|
|
7
|
+
import { ClassDeclaration, EnumDeclaration } from "../../index.js";
|
|
8
|
+
let runner;
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
runner = await Tester.createInstance();
|
|
11
|
+
});
|
|
12
|
+
function Wrapper(props) {
|
|
13
|
+
const policy = createCSharpNamePolicy();
|
|
14
|
+
return _$createComponent(Output, {
|
|
15
|
+
get program() {
|
|
16
|
+
return runner.program;
|
|
17
|
+
},
|
|
18
|
+
namePolicy: policy,
|
|
19
|
+
get children() {
|
|
20
|
+
return _$createComponent(Namespace, {
|
|
21
|
+
name: "TestNamespace",
|
|
22
|
+
get children() {
|
|
23
|
+
return _$createComponent(SourceFile, {
|
|
24
|
+
path: "test.cs",
|
|
25
|
+
get children() {
|
|
26
|
+
return props.children;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
it("renders an empty class declaration", async () => {
|
|
35
|
+
const {
|
|
36
|
+
TestModel
|
|
37
|
+
} = await runner.compile(t.code`
|
|
38
|
+
model ${t.model("TestModel")} {}
|
|
39
|
+
`);
|
|
40
|
+
expect(_$createComponent(Wrapper, {
|
|
41
|
+
get children() {
|
|
42
|
+
return _$createComponent(ClassDeclaration, {
|
|
43
|
+
type: TestModel
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
})).toRenderTo(`
|
|
47
|
+
namespace TestNamespace
|
|
48
|
+
{
|
|
49
|
+
class TestModel
|
|
50
|
+
{
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
`);
|
|
55
|
+
});
|
|
56
|
+
it("renders a class declaration with properties", async () => {
|
|
57
|
+
const {
|
|
58
|
+
TestModel
|
|
59
|
+
} = await runner.compile(t.code`
|
|
60
|
+
model ${t.model("TestModel")} {
|
|
61
|
+
@test Prop1: string;
|
|
62
|
+
@test Prop2: int32;
|
|
63
|
+
}
|
|
64
|
+
`);
|
|
65
|
+
expect(_$createComponent(Wrapper, {
|
|
66
|
+
get children() {
|
|
67
|
+
return _$createComponent(ClassDeclaration, {
|
|
68
|
+
type: TestModel
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
})).toRenderTo(`
|
|
72
|
+
namespace TestNamespace
|
|
73
|
+
{
|
|
74
|
+
class TestModel
|
|
75
|
+
{
|
|
76
|
+
public required string Prop1 { get; set; }
|
|
77
|
+
public required int Prop2 { get; set; }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
`);
|
|
81
|
+
});
|
|
82
|
+
it("can override class name", async () => {
|
|
83
|
+
const {
|
|
84
|
+
TestModel
|
|
85
|
+
} = await runner.compile(t.code`
|
|
86
|
+
model ${t.model("TestModel")} {}
|
|
87
|
+
`);
|
|
88
|
+
expect(_$createComponent(Wrapper, {
|
|
89
|
+
get children() {
|
|
90
|
+
return _$createComponent(ClassDeclaration, {
|
|
91
|
+
type: TestModel,
|
|
92
|
+
name: "CustomClassName"
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
})).toRenderTo(`
|
|
96
|
+
namespace TestNamespace
|
|
97
|
+
{
|
|
98
|
+
class CustomClassName
|
|
99
|
+
{
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
`);
|
|
104
|
+
});
|
|
105
|
+
it("renders a class with access modifiers", async () => {
|
|
106
|
+
const {
|
|
107
|
+
TestModel
|
|
108
|
+
} = await runner.compile(t.code`
|
|
109
|
+
model ${t.model("TestModel")} {
|
|
110
|
+
}
|
|
111
|
+
`);
|
|
112
|
+
expect(_$createComponent(Wrapper, {
|
|
113
|
+
get children() {
|
|
114
|
+
return _$createComponent(ClassDeclaration, {
|
|
115
|
+
type: TestModel,
|
|
116
|
+
"protected": true
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
})).toRenderTo(`
|
|
120
|
+
namespace TestNamespace
|
|
121
|
+
{
|
|
122
|
+
protected class TestModel
|
|
123
|
+
{
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
`);
|
|
128
|
+
});
|
|
129
|
+
describe("from an interface", () => {
|
|
130
|
+
it("renders an empty class", async () => {
|
|
131
|
+
const {
|
|
132
|
+
TestInterface
|
|
133
|
+
} = await runner.compile(t.code`
|
|
134
|
+
interface ${t.interface("TestInterface")} {
|
|
135
|
+
}
|
|
136
|
+
`);
|
|
137
|
+
expect(_$createComponent(Wrapper, {
|
|
138
|
+
get children() {
|
|
139
|
+
return _$createComponent(ClassDeclaration, {
|
|
140
|
+
type: TestInterface
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
})).toRenderTo(`
|
|
144
|
+
namespace TestNamespace
|
|
145
|
+
{
|
|
146
|
+
class TestInterface
|
|
147
|
+
{
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
`);
|
|
152
|
+
});
|
|
153
|
+
it("renders a class with operations", async () => {
|
|
154
|
+
const {
|
|
155
|
+
TestInterface
|
|
156
|
+
} = await runner.compile(t.code`
|
|
157
|
+
interface ${t.interface("TestInterface")} {
|
|
158
|
+
op getName(id: string): string;
|
|
159
|
+
}
|
|
160
|
+
`);
|
|
161
|
+
expect(_$createComponent(Wrapper, {
|
|
162
|
+
get children() {
|
|
163
|
+
return _$createComponent(ClassDeclaration, {
|
|
164
|
+
type: TestInterface
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
})).toRenderTo(`
|
|
168
|
+
namespace TestNamespace
|
|
169
|
+
{
|
|
170
|
+
class TestInterface
|
|
171
|
+
{
|
|
172
|
+
public abstract string GetName(string id);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
`);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
it("renders a class with model members", async () => {
|
|
179
|
+
const {
|
|
180
|
+
TestModel,
|
|
181
|
+
TestReference
|
|
182
|
+
} = await runner.compile(t.code`
|
|
183
|
+
model ${t.model("TestReference")} { }
|
|
184
|
+
model ${t.model("TestModel")} {
|
|
185
|
+
prop1: TestReference;
|
|
186
|
+
}
|
|
187
|
+
`);
|
|
188
|
+
expect(_$createComponent(Wrapper, {
|
|
189
|
+
get children() {
|
|
190
|
+
return [_$createComponent(ClassDeclaration, {
|
|
191
|
+
type: TestReference
|
|
192
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
|
|
193
|
+
type: TestModel
|
|
194
|
+
})];
|
|
195
|
+
}
|
|
196
|
+
})).toRenderTo(`
|
|
197
|
+
namespace TestNamespace
|
|
198
|
+
{
|
|
199
|
+
class TestReference
|
|
200
|
+
{
|
|
201
|
+
|
|
202
|
+
}
|
|
203
|
+
class TestModel
|
|
204
|
+
{
|
|
205
|
+
public required TestReference Prop1 { get; set; }
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
`);
|
|
209
|
+
});
|
|
210
|
+
it("renders a class with enum members", async () => {
|
|
211
|
+
const {
|
|
212
|
+
TestModel,
|
|
213
|
+
TestEnum
|
|
214
|
+
} = await runner.compile(t.code`
|
|
215
|
+
@test enum ${t.enum("TestEnum")} {
|
|
216
|
+
Value1;
|
|
217
|
+
Value2;
|
|
218
|
+
}
|
|
219
|
+
model ${t.model("TestModel")} {
|
|
220
|
+
@test prop1: TestEnum;
|
|
221
|
+
}
|
|
222
|
+
`);
|
|
223
|
+
expect(_$createComponent(Wrapper, {
|
|
224
|
+
get children() {
|
|
225
|
+
return [_$createComponent(EnumDeclaration, {
|
|
226
|
+
type: TestEnum
|
|
227
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
|
|
228
|
+
type: TestModel
|
|
229
|
+
})];
|
|
230
|
+
}
|
|
231
|
+
})).toRenderTo(`
|
|
232
|
+
namespace TestNamespace
|
|
233
|
+
{
|
|
234
|
+
enum TestEnum
|
|
235
|
+
{
|
|
236
|
+
Value1,
|
|
237
|
+
Value2
|
|
238
|
+
}
|
|
239
|
+
class TestModel
|
|
240
|
+
{
|
|
241
|
+
public required TestEnum Prop1 { get; set; }
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
`);
|
|
245
|
+
});
|
|
246
|
+
it("maps prop: string | null to nullable property", async () => {
|
|
247
|
+
const {
|
|
248
|
+
TestModel
|
|
249
|
+
} = await runner.compile(t.code`
|
|
250
|
+
model ${t.model("TestModel")} {
|
|
251
|
+
prop1: string | null;
|
|
252
|
+
}
|
|
253
|
+
`);
|
|
254
|
+
expect(_$createComponent(Wrapper, {
|
|
255
|
+
get children() {
|
|
256
|
+
return _$createComponent(ClassDeclaration, {
|
|
257
|
+
type: TestModel
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
})).toRenderTo(`
|
|
261
|
+
namespace TestNamespace
|
|
262
|
+
{
|
|
263
|
+
class TestModel
|
|
264
|
+
{
|
|
265
|
+
public required string? Prop1 { get; set; }
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
`);
|
|
269
|
+
});
|
|
270
|
+
it("renders a class with string enums", async () => {
|
|
271
|
+
const {
|
|
272
|
+
TestModel,
|
|
273
|
+
TestEnum
|
|
274
|
+
} = await runner.compile(t.code`
|
|
275
|
+
@test enum ${t.enum("TestEnum")} {
|
|
276
|
+
Value1;
|
|
277
|
+
Value2;
|
|
278
|
+
}
|
|
279
|
+
model ${t.model("TestModel")} {
|
|
280
|
+
@test prop1: TestEnum;
|
|
281
|
+
}
|
|
282
|
+
`);
|
|
283
|
+
expect(_$createComponent(Wrapper, {
|
|
284
|
+
get children() {
|
|
285
|
+
return [_$createComponent(EnumDeclaration, {
|
|
286
|
+
type: TestEnum
|
|
287
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
|
|
288
|
+
type: TestModel
|
|
289
|
+
})];
|
|
290
|
+
}
|
|
291
|
+
})).toRenderTo(`
|
|
292
|
+
namespace TestNamespace
|
|
293
|
+
{
|
|
294
|
+
enum TestEnum
|
|
295
|
+
{
|
|
296
|
+
Value1,
|
|
297
|
+
Value2
|
|
298
|
+
}
|
|
299
|
+
class TestModel
|
|
300
|
+
{
|
|
301
|
+
public required TestEnum Prop1 { get; set; }
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
`);
|
|
305
|
+
});
|
|
306
|
+
describe("with doc comments", () => {
|
|
307
|
+
it("renders a model with docs", async () => {
|
|
308
|
+
const {
|
|
309
|
+
TestModel
|
|
310
|
+
} = await runner.compile(t.code`
|
|
311
|
+
@doc("This is a test model")
|
|
312
|
+
model ${t.model("TestModel")} {
|
|
313
|
+
@doc("This is a test property")
|
|
314
|
+
prop1: string;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
`);
|
|
318
|
+
expect(_$createComponent(Wrapper, {
|
|
319
|
+
get children() {
|
|
320
|
+
return _$createComponent(ClassDeclaration, {
|
|
321
|
+
type: TestModel
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
})).toRenderTo(`
|
|
325
|
+
namespace TestNamespace
|
|
326
|
+
{
|
|
327
|
+
/// <summary>
|
|
328
|
+
/// This is a test model
|
|
329
|
+
/// </summary>
|
|
330
|
+
class TestModel
|
|
331
|
+
{
|
|
332
|
+
/// <summary>
|
|
333
|
+
/// This is a test property
|
|
334
|
+
/// </summary>
|
|
335
|
+
public required string Prop1 { get; set; }
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
`);
|
|
339
|
+
});
|
|
340
|
+
it("renders an interface with docs", async () => {
|
|
341
|
+
const {
|
|
342
|
+
TestInterface
|
|
343
|
+
} = await runner.compile(t.code`
|
|
344
|
+
@doc("This is a test interface")
|
|
345
|
+
@test interface ${t.interface("TestInterface")} {
|
|
346
|
+
@doc("This is a test operation")
|
|
347
|
+
@returnsDoc("The name of the item")
|
|
348
|
+
op getName(id: string): string;
|
|
349
|
+
}
|
|
350
|
+
`);
|
|
351
|
+
expect(_$createComponent(Wrapper, {
|
|
352
|
+
get children() {
|
|
353
|
+
return _$createComponent(ClassDeclaration, {
|
|
354
|
+
type: TestInterface
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
})).toRenderTo(`
|
|
358
|
+
namespace TestNamespace
|
|
359
|
+
{
|
|
360
|
+
/// <summary>
|
|
361
|
+
/// This is a test interface
|
|
362
|
+
/// </summary>
|
|
363
|
+
class TestInterface
|
|
364
|
+
{
|
|
365
|
+
/// <summary>
|
|
366
|
+
/// This is a test operation
|
|
367
|
+
/// </summary>
|
|
368
|
+
///
|
|
369
|
+
/// <returns>
|
|
370
|
+
/// The name of the item
|
|
371
|
+
/// </returns>
|
|
372
|
+
public abstract string GetName(string id);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
`);
|
|
376
|
+
});
|
|
377
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Children } from "@alloy-js/core";
|
|
2
|
+
import * as cs from "@alloy-js/csharp";
|
|
3
|
+
import type { Enum, Union } from "@typespec/compiler";
|
|
4
|
+
export interface EnumDeclarationProps extends Omit<cs.EnumDeclarationProps, "name"> {
|
|
5
|
+
name?: string;
|
|
6
|
+
type: Union | Enum;
|
|
7
|
+
}
|
|
8
|
+
export declare function EnumDeclaration(props: EnumDeclarationProps): Children;
|
|
9
|
+
//# sourceMappingURL=declaration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../../src/csharp/components/enum/declaration.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAO,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAKtD,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACjF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,QAAQ,CA0CrE"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, mergeProps as _$mergeProps, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { useTsp } from "#core/context/tsp-context.js";
|
|
3
|
+
import { For } from "@alloy-js/core";
|
|
4
|
+
import * as cs from "@alloy-js/csharp";
|
|
5
|
+
import { reportDiagnostic } from "../../../lib.js";
|
|
6
|
+
import { getDocComments } from "../utils/doc-comments.js";
|
|
7
|
+
import { declarationRefkeys, efRefkey } from "../utils/refkey.js";
|
|
8
|
+
export function EnumDeclaration(props) {
|
|
9
|
+
const {
|
|
10
|
+
$
|
|
11
|
+
} = useTsp();
|
|
12
|
+
let type;
|
|
13
|
+
if ($.union.is(props.type)) {
|
|
14
|
+
if (!$.union.isValidEnum(props.type)) {
|
|
15
|
+
throw new Error("The provided union type cannot be represented as an enum");
|
|
16
|
+
}
|
|
17
|
+
type = $.enum.createFromUnion(props.type);
|
|
18
|
+
} else {
|
|
19
|
+
type = props.type;
|
|
20
|
+
}
|
|
21
|
+
if (!props.type.name) {
|
|
22
|
+
reportDiagnostic($.program, {
|
|
23
|
+
code: "type-declaration-missing-name",
|
|
24
|
+
target: props.type
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const refkeys = declarationRefkeys(props.refkey, props.type)[0]; // TODO: support multiple refkeys for declarations in alloy
|
|
28
|
+
const name = props.name ?? cs.useCSharpNamePolicy().getName(props.type.name, "enum");
|
|
29
|
+
const members = Array.from(type.members.entries());
|
|
30
|
+
return [_$createComponent(cs.EnumDeclaration, _$mergeProps({
|
|
31
|
+
name: name,
|
|
32
|
+
refkey: refkeys
|
|
33
|
+
}, props, {
|
|
34
|
+
get children() {
|
|
35
|
+
return _$createComponent(For, {
|
|
36
|
+
each: members,
|
|
37
|
+
joiner: ",\n",
|
|
38
|
+
children: ([key, value]) => {
|
|
39
|
+
return [_$createComponent(cs.DocWhen, {
|
|
40
|
+
get doc() {
|
|
41
|
+
return getDocComments($, value);
|
|
42
|
+
}
|
|
43
|
+
}), _$createComponent(cs.EnumMember, {
|
|
44
|
+
get name() {
|
|
45
|
+
return cs.useCSharpNamePolicy().getName(key, "enum-member");
|
|
46
|
+
},
|
|
47
|
+
get refkey() {
|
|
48
|
+
return _$memo(() => !!$.union.is(props.type))() ? efRefkey(props.type.variants.get(key)) : efRefkey(value);
|
|
49
|
+
}
|
|
50
|
+
})];
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}))];
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declaration.test.d.ts","sourceRoot":"","sources":["../../../../../src/csharp/components/enum/declaration.test.tsx"],"names":[],"mappings":""}
|