@alloy-js/csharp 0.19.0-dev.1 → 0.19.0-dev.2

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.
Files changed (32) hide show
  1. package/dist/src/components/ClassMethod.d.ts +14 -0
  2. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  3. package/dist/src/components/ClassMethod.js +1 -1
  4. package/dist/src/components/index.d.ts +1 -0
  5. package/dist/src/components/index.d.ts.map +1 -1
  6. package/dist/src/components/index.js +1 -0
  7. package/dist/src/components/property/property.d.ts.map +1 -1
  8. package/dist/src/components/property/property.js +1 -1
  9. package/dist/src/components/stc/index.d.ts +1 -0
  10. package/dist/src/components/stc/index.d.ts.map +1 -1
  11. package/dist/src/components/stc/index.js +2 -1
  12. package/dist/src/components/struct/declaration.d.ts +68 -0
  13. package/dist/src/components/struct/declaration.d.ts.map +1 -0
  14. package/dist/src/components/struct/declaration.js +78 -0
  15. package/dist/src/components/struct/declaration.test.d.ts +2 -0
  16. package/dist/src/components/struct/declaration.test.d.ts.map +1 -0
  17. package/dist/src/components/struct/declaration.test.js +171 -0
  18. package/dist/src/name-policy.d.ts +1 -1
  19. package/dist/src/name-policy.d.ts.map +1 -1
  20. package/dist/src/name-policy.js +1 -0
  21. package/dist/test/class-method.test.js +23 -0
  22. package/dist/tsconfig.tsbuildinfo +1 -1
  23. package/package.json +2 -2
  24. package/src/components/ClassMethod.tsx +23 -1
  25. package/src/components/index.ts +1 -0
  26. package/src/components/property/property.tsx +3 -1
  27. package/src/components/stc/index.ts +1 -0
  28. package/src/components/struct/declaration.test.tsx +137 -0
  29. package/src/components/struct/declaration.tsx +129 -0
  30. package/src/name-policy.ts +2 -0
  31. package/temp/api.json +419 -1
  32. package/test/class-method.test.tsx +18 -0
@@ -52,6 +52,20 @@ export interface ClassMethodProps extends AccessModifiers, ClassMethodModifiers
52
52
  * ```
53
53
  */
54
54
  attributes?: AttributesProp;
55
+ /**
56
+ * Use expression syntax for the method.
57
+ * @example
58
+ * ```tsx
59
+ * <ClassMethod name="MyMethod" lambda>
60
+ * this.MyProperty.Value;
61
+ * </ClassMethod>
62
+ * ```
63
+ * This will produce:
64
+ * ```csharp
65
+ * public void MyMethod() => this.MyProperty.Value;
66
+ * ```
67
+ */
68
+ expression?: boolean;
55
69
  }
56
70
  export declare function ClassMethod(props: ClassMethodProps): Children;
57
71
  //# sourceMappingURL=ClassMethod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ClassMethod.d.ts","sourceRoot":"","sources":["../../../src/components/ClassMethod.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAKhB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAiB,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE5E,OAAO,EAAE,cAAc,EAAc,MAAM,6BAA6B,CAAC;AAEzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAG1E,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAUD,MAAM,WAAW,gBACf,SAAQ,eAAe,EACrB,oBAAoB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACnC,OAAO,CAAC,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,kBAAkB;IAClB,GAAG,CAAC,EAAE,QA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AE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;IAEjD;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;IAE5B;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YAkDlD"}
@@ -62,7 +62,7 @@ export function ClassMethod(props) {
62
62
  get parameters() {
63
63
  return props.typeParameters;
64
64
  }
65
- })), _$memo(() => _$memo(() => !!props.abstract)() ? ";" : _$createComponent(Block, {
65
+ })), _$memo(() => _$memo(() => !!props.abstract)() ? ";" : _$memo(() => !!props.expression)() ? [" => ", _$memo(() => props.children)] : _$createComponent(Block, {
66
66
  newline: true,
67
67
  get children() {
68
68
  return props.children;
@@ -16,6 +16,7 @@ export * from "./property/property.jsx";
16
16
  export * from "./record/declaration.js";
17
17
  export * from "./Reference.js";
18
18
  export * from "./SourceFile.js";
19
+ export * from "./struct/declaration.jsx";
19
20
  export type { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
20
21
  export * from "./UsingDirective.js";
21
22
  export * from "./var/declaration.jsx";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,YAAY,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,YAAY,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
@@ -16,6 +16,7 @@ export * from "./property/property.js";
16
16
  export * from "./record/declaration.js";
17
17
  export * from "./Reference.js";
18
18
  export * from "./SourceFile.js";
19
+ export * from "./struct/declaration.js";
19
20
  export * from "./UsingDirective.js";
20
21
  export * from "./var/declaration.js";
21
22
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../src/components/property/property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAKR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB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E,QAAQ,CAAC;IAEvB;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,YAsD5C"}
@@ -25,7 +25,7 @@ const getModifiers = makeModifiers(["new", "static", "virtual", "sealed", "overr
25
25
  export function Property(props) {
26
26
  const name = useCSharpNamePolicy().getName(props.name, "class-property");
27
27
  const scope = useCSharpScope();
28
- if (scope.kind !== "member" || scope.name !== "class-decl" && scope.name !== "record-decl") {
28
+ if (scope.kind !== "member" || scope.name !== "class-decl" && scope.name !== "record-decl" && scope.name !== "struct-decl") {
29
29
  throw new Error("can't define an interface method outside of an interface scope");
30
30
  }
31
31
  const propertySymbol = new CSharpOutputSymbol(name, {
@@ -10,4 +10,5 @@ export declare const Parameter: core.StcSignature<base.ParameterProps>;
10
10
  export declare const Parameters: core.StcSignature<base.ParametersProps>;
11
11
  export declare const ProjectDirectory: core.StcSignature<base.ProjectDirectoryProps>;
12
12
  export declare const UsingDirective: core.StcSignature<base.UsingDirectiveProps>;
13
+ export declare const StructDeclaration: core.StcSignature<base.StructDeclarationProps>;
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/stc/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,eAAe,8CAAiC,CAAC;AAC9D,eAAO,MAAM,UAAU,yCAA4B,CAAC;AACpD,eAAO,MAAM,SAAS,wCAA2B,CAAC;AAClD,eAAO,MAAM,UAAU,yCAA4B,CAAC;AACpD,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,cAAc,6CAAgC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/stc/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,eAAe,8CAAiC,CAAC;AAC9D,eAAO,MAAM,UAAU,yCAA4B,CAAC;AACpD,eAAO,MAAM,SAAS,wCAA2B,CAAC;AAClD,eAAO,MAAM,UAAU,yCAA4B,CAAC;AACpD,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,cAAc,6CAAgC,CAAC;AAC5D,eAAO,MAAM,iBAAiB,gDAAmC,CAAC"}
@@ -9,4 +9,5 @@ export const EnumMember = core.stc(base.EnumMember);
9
9
  export const Parameter = core.stc(base.Parameter);
10
10
  export const Parameters = core.stc(base.Parameters);
11
11
  export const ProjectDirectory = core.stc(base.ProjectDirectory);
12
- export const UsingDirective = core.stc(base.UsingDirective);
12
+ export const UsingDirective = core.stc(base.UsingDirective);
13
+ export const StructDeclaration = core.stc(base.StructDeclaration);
@@ -0,0 +1,68 @@
1
+ import * as core from "@alloy-js/core";
2
+ import { AccessModifiers } from "../../modifiers.js";
3
+ import { AttributesProp } from "../attributes/attributes.jsx";
4
+ import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
5
+ export interface StructModifiers {
6
+ readonly new?: boolean;
7
+ readonly readonly?: boolean;
8
+ readonly ref?: boolean;
9
+ readonly partial?: boolean;
10
+ }
11
+ export interface StructDeclarationProps extends Omit<core.DeclarationProps, "nameKind">, AccessModifiers, StructModifiers {
12
+ name: string;
13
+ /** Doc comment */
14
+ doc?: core.Children;
15
+ refkey?: core.Refkey;
16
+ /**
17
+ * Type parameters for the struct
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * <StructDeclaration name="IList" typeParameters={["T"]} />
22
+ * ```
23
+ * This will produce:
24
+ * ```csharp
25
+ * public struct IList<T>
26
+ * ```
27
+ */
28
+ typeParameters?: (TypeParameterProps | string)[];
29
+ /**
30
+ * Define attributes to attach
31
+ * @example
32
+ * ```tsx
33
+ * <StructDeclaration name="MyStruct" attributes={[
34
+ * <Attribute name="Test" />
35
+ * <Attribute name="Test2" args={["arg1", "arg2"]} />
36
+ * ]} />
37
+ * ```
38
+ * This will produce:
39
+ * ```csharp
40
+ * [Test]
41
+ * [Test2("arg1", "arg2")]
42
+ * public struct MyStruct
43
+ * ```
44
+ */
45
+ attributes?: AttributesProp;
46
+ }
47
+ /**
48
+ * CSharp struct declaration.
49
+ * @example
50
+ * ```tsx
51
+ * <StructDeclaration public name="IMyStruct">
52
+ * <StructMember public name="MyProperty" type="int" />
53
+ * <StructMethod public name="MyMethod" returnType="void">
54
+ * <Parameter name="value" type="int" />
55
+ * </StructMethod>
56
+ * </StructDeclaration>
57
+ * ```
58
+ * This will produce:
59
+ * ```csharp
60
+ * public struct MyIface
61
+ * {
62
+ * public int MyProperty { get; set; }
63
+ * public void MyMethod(int value);
64
+ * }
65
+ * ```
66
+ */
67
+ export declare function StructDeclaration(props: StructDeclarationProps): core.Children;
68
+ //# sourceMappingURL=declaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/struct/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAI7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAG3E,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAUD,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,eAAe;IACjB,IAAI,EAAE,MAAM,CAAC;IAEb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IAErB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;IAEjD;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,iBAiC9D"}
@@ -0,0 +1,78 @@
1
+ import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import * as core from "@alloy-js/core";
3
+ import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../modifiers.js";
4
+ import { useCSharpNamePolicy } from "../../name-policy.js";
5
+ import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
6
+ import { CSharpMemberScope } from "../../symbols/scopes.js";
7
+ import { AttributeList } from "../attributes/attributes.js";
8
+ import { DocWhen } from "../doc/comment.js";
9
+ import { Name } from "../Name.js";
10
+ import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
11
+ import { TypeParameters } from "../type-parameters/type-parameters.js";
12
+ const getStructModifiers = makeModifiers(["new", "readonly", "ref", "partial"]);
13
+
14
+ // properties for creating a class
15
+
16
+ /**
17
+ * CSharp struct declaration.
18
+ * @example
19
+ * ```tsx
20
+ * <StructDeclaration public name="IMyStruct">
21
+ * <StructMember public name="MyProperty" type="int" />
22
+ * <StructMethod public name="MyMethod" returnType="void">
23
+ * <Parameter name="value" type="int" />
24
+ * </StructMethod>
25
+ * </StructDeclaration>
26
+ * ```
27
+ * This will produce:
28
+ * ```csharp
29
+ * public struct MyIface
30
+ * {
31
+ * public int MyProperty { get; set; }
32
+ * public void MyMethod(int value);
33
+ * }
34
+ * ```
35
+ */
36
+ export function StructDeclaration(props) {
37
+ const name = useCSharpNamePolicy().getName(props.name, "struct");
38
+ const thisStructSymbol = new CSharpOutputSymbol(name, {
39
+ refkeys: props.refkey
40
+ });
41
+ const thisStructScope = new CSharpMemberScope("struct-decl", {
42
+ owner: thisStructSymbol
43
+ });
44
+ const modifiers = computeModifiersPrefix([getAccessModifier(props), getStructModifiers(props)]);
45
+ return _$createComponent(core.Declaration, {
46
+ symbol: thisStructSymbol,
47
+ get children() {
48
+ return [_$createComponent(DocWhen, {
49
+ get doc() {
50
+ return props.doc;
51
+ }
52
+ }), _$createComponent(AttributeList, {
53
+ get attributes() {
54
+ return props.attributes;
55
+ },
56
+ endline: true
57
+ }), modifiers, "struct ", _$createComponent(Name, {}), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
58
+ get parameters() {
59
+ return props.typeParameters;
60
+ }
61
+ })), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
62
+ get parameters() {
63
+ return props.typeParameters;
64
+ }
65
+ })), _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(core.Block, {
66
+ newline: true,
67
+ get children() {
68
+ return _$createComponent(core.Scope, {
69
+ value: thisStructScope,
70
+ get children() {
71
+ return props.children;
72
+ }
73
+ });
74
+ }
75
+ }) : ";")];
76
+ }
77
+ });
78
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=declaration.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration.test.d.ts","sourceRoot":"","sources":["../../../../src/components/struct/declaration.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,171 @@
1
+ import { createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { List, refkey } from "@alloy-js/core";
3
+ import { describe, expect, it } from "vitest";
4
+ import { TestNamespace } from "../../../test/utils.js";
5
+ import { Attribute } from "../attributes/attributes.js";
6
+ import { Property } from "../property/property.js";
7
+ import { SourceFile } from "../SourceFile.js";
8
+ import { StructDeclaration } from "./declaration.js";
9
+ it("declares struct with no members", () => {
10
+ expect(_$createComponent(TestNamespace, {
11
+ get children() {
12
+ return _$createComponent(StructDeclaration, {
13
+ name: "Test"
14
+ });
15
+ }
16
+ })).toRenderTo(`
17
+ struct Test;
18
+ `);
19
+ });
20
+ describe("modifiers", () => {
21
+ it.each(["public", "private", "internal"])("%s", mod => {
22
+ expect(_$createComponent(TestNamespace, {
23
+ get children() {
24
+ return _$createComponent(StructDeclaration, _$mergeProps({
25
+ [mod]: true
26
+ }, {
27
+ name: "Test"
28
+ }));
29
+ }
30
+ })).toRenderTo(`
31
+ ${mod} struct Test;
32
+ `);
33
+ });
34
+ it.each(["partial"])("%s", mod => {
35
+ expect(_$createComponent(TestNamespace, {
36
+ get children() {
37
+ return _$createComponent(StructDeclaration, _$mergeProps({
38
+ [mod]: true
39
+ }, {
40
+ name: "Test"
41
+ }));
42
+ }
43
+ })).toRenderTo(`
44
+ ${mod} struct Test;
45
+ `);
46
+ });
47
+ it("combines modifiers", () => {
48
+ expect(_$createComponent(TestNamespace, {
49
+ get children() {
50
+ return _$createComponent(StructDeclaration, {
51
+ "public": true,
52
+ partial: true,
53
+ name: "Test"
54
+ });
55
+ }
56
+ })).toRenderTo(`
57
+ public partial struct Test;
58
+ `);
59
+ });
60
+ });
61
+ it("specify doc comment", () => {
62
+ expect(_$createComponent(TestNamespace, {
63
+ get children() {
64
+ return _$createComponent(StructDeclaration, {
65
+ name: "Test",
66
+ doc: "This is a test"
67
+ });
68
+ }
69
+ })).toRenderTo(`
70
+ /// This is a test
71
+ struct Test;
72
+ `);
73
+ });
74
+ describe("with type parameters", () => {
75
+ it("reference parameters", () => {
76
+ const typeParameters = [{
77
+ name: "T",
78
+ refkey: refkey()
79
+ }, {
80
+ name: "U",
81
+ refkey: refkey()
82
+ }];
83
+ expect(_$createComponent(TestNamespace, {
84
+ get children() {
85
+ return _$createComponent(SourceFile, {
86
+ path: "Test.cs",
87
+ get children() {
88
+ return _$createComponent(StructDeclaration, {
89
+ "public": true,
90
+ name: "Test",
91
+ typeParameters: typeParameters,
92
+ get children() {
93
+ return _$createComponent(List, {
94
+ get children() {
95
+ return [_$createComponent(Property, {
96
+ name: "PropA",
97
+ get type() {
98
+ return typeParameters[0].refkey;
99
+ },
100
+ get: true,
101
+ set: true
102
+ }), _$createComponent(Property, {
103
+ name: "PropB",
104
+ get type() {
105
+ return typeParameters[1].refkey;
106
+ },
107
+ get: true,
108
+ set: true
109
+ })];
110
+ }
111
+ });
112
+ }
113
+ });
114
+ }
115
+ });
116
+ }
117
+ })).toRenderTo(`
118
+ namespace TestCode
119
+ {
120
+ public struct Test<T, U>
121
+ {
122
+ T PropA { get; set; }
123
+ U PropB { get; set; }
124
+ }
125
+ }
126
+ `);
127
+ });
128
+ it("defines with constraints", () => {
129
+ const typeParameters = [{
130
+ name: "T",
131
+ constraints: "IFoo"
132
+ }, {
133
+ name: "U",
134
+ constraints: "IBar"
135
+ }];
136
+ expect(_$createComponent(TestNamespace, {
137
+ get children() {
138
+ return _$createComponent(StructDeclaration, {
139
+ "public": true,
140
+ name: "Test",
141
+ typeParameters: typeParameters,
142
+ children: "// Body"
143
+ });
144
+ }
145
+ })).toRenderTo(`
146
+ public struct Test<T, U>
147
+ where T : IFoo
148
+ where U : IBar
149
+ {
150
+ // Body
151
+ }
152
+ `);
153
+ });
154
+ });
155
+ it("specify attributes", () => {
156
+ expect(_$createComponent(TestNamespace, {
157
+ get children() {
158
+ return _$createComponent(StructDeclaration, {
159
+ name: "Test",
160
+ get attributes() {
161
+ return [_$createComponent(Attribute, {
162
+ name: "Test"
163
+ })];
164
+ }
165
+ });
166
+ }
167
+ })).toRenderTo(`
168
+ [Test]
169
+ struct Test;
170
+ `);
171
+ });
@@ -1,5 +1,5 @@
1
1
  import * as core from "@alloy-js/core";
2
- export type CSharpElements = "class" | "constant" | "variable" | "enum" | "enum-member" | "function" | "interface" | "record" | "class-member-private" | "class-member-public" | "class-method" | "class-property" | "parameter" | "type-parameter";
2
+ export type CSharpElements = "class" | "constant" | "variable" | "struct" | "enum" | "enum-member" | "function" | "interface" | "record" | "class-member-private" | "class-member-public" | "class-method" | "class-property" | "parameter" | "type-parameter";
3
3
  export declare function createCSharpNamePolicy(): core.NamePolicy<CSharpElements>;
4
4
  export declare function useCSharpNamePolicy(): core.NamePolicy<CSharpElements>;
5
5
  //# sourceMappingURL=name-policy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"name-policy.d.ts","sourceRoot":"","sources":["../../src/name-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAIvC,MAAM,MAAM,cAAc,GACtB,OAAO,GACP,UAAU,GACV,UAAU,GACV,MAAM,GACN,aAAa,GACb,UAAU,GACV,WAAW,GACX,QAAQ,GACR,sBAAsB,GACtB,qBAAqB,GACrB,cAAc,GACd,gBAAgB,GAChB,WAAW,GACX,gBAAgB,CAAC;AAGrB,wBAAgB,sBAAsB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAmBxE;AAGD,wBAAgB,mBAAmB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAErE"}
1
+ {"version":3,"file":"name-policy.d.ts","sourceRoot":"","sources":["../../src/name-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAIvC,MAAM,MAAM,cAAc,GACtB,OAAO,GACP,UAAU,GACV,UAAU,GACV,QAAQ,GACR,MAAM,GACN,aAAa,GACb,UAAU,GACV,WAAW,GACX,QAAQ,GACR,sBAAsB,GACtB,qBAAqB,GACrB,cAAc,GACd,gBAAgB,GAChB,WAAW,GACX,gBAAgB,CAAC;AAGrB,wBAAgB,sBAAsB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAoBxE;AAGD,wBAAgB,mBAAmB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAErE"}
@@ -8,6 +8,7 @@ export function createCSharpNamePolicy() {
8
8
  return core.createNamePolicy((name, element) => {
9
9
  switch (element) {
10
10
  case "class":
11
+ case "struct":
11
12
  case "enum":
12
13
  case "enum-member":
13
14
  case "interface":
@@ -158,4 +158,27 @@ it("specify doc comment", () => {
158
158
  void Method() {}
159
159
  }
160
160
  `);
161
+ });
162
+ it("use expression body form", () => {
163
+ expect(_$createComponent(TestNamespace, {
164
+ get children() {
165
+ return _$createComponent(ClassDeclaration, {
166
+ name: "Test",
167
+ get children() {
168
+ return _$createComponent(ClassMethod, {
169
+ name: "Method",
170
+ doc: "This is a test",
171
+ expression: true,
172
+ children: "this.MyProperty.Value;"
173
+ });
174
+ }
175
+ });
176
+ }
177
+ })).toRenderTo(`
178
+ class Test
179
+ {
180
+ /// This is a test
181
+ void Method() => this.MyProperty.Value;
182
+ }
183
+ `);
161
184
  });