@alloy-js/csharp 0.17.0 → 0.18.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.
Files changed (109) hide show
  1. package/dist/src/components/ClassDeclaration.d.ts +57 -0
  2. package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
  3. package/dist/src/components/{Class.js → ClassDeclaration.js} +42 -53
  4. package/dist/src/components/ClassMethod.d.ts +25 -0
  5. package/dist/src/components/ClassMethod.d.ts.map +1 -0
  6. package/dist/src/components/ClassMethod.js +60 -0
  7. package/dist/src/components/EnumDeclaration.d.ts +34 -0
  8. package/dist/src/components/EnumDeclaration.d.ts.map +1 -0
  9. package/dist/src/components/{Enum.js → EnumDeclaration.js} +25 -5
  10. package/dist/src/components/doc/comment.d.ts +70 -0
  11. package/dist/src/components/doc/comment.d.ts.map +1 -0
  12. package/dist/src/components/doc/comment.js +88 -0
  13. package/dist/src/components/doc/comment.test.d.ts +2 -0
  14. package/dist/src/components/doc/comment.test.d.ts.map +1 -0
  15. package/dist/src/components/doc/comment.test.js +348 -0
  16. package/dist/src/components/doc/from-markdown.d.ts +6 -0
  17. package/dist/src/components/doc/from-markdown.d.ts.map +1 -0
  18. package/dist/src/components/doc/from-markdown.js +58 -0
  19. package/dist/src/components/doc/from-markdown.test.d.ts +2 -0
  20. package/dist/src/components/doc/from-markdown.test.d.ts.map +1 -0
  21. package/dist/src/components/doc/from-markdown.test.js +83 -0
  22. package/dist/src/components/index.d.ts +7 -2
  23. package/dist/src/components/index.d.ts.map +1 -1
  24. package/dist/src/components/index.js +7 -2
  25. package/dist/src/components/interface/declaration.d.ts +34 -0
  26. package/dist/src/components/interface/declaration.d.ts.map +1 -0
  27. package/dist/src/components/interface/declaration.js +90 -0
  28. package/dist/src/components/interface/declaration.test.d.ts +2 -0
  29. package/dist/src/components/interface/declaration.test.d.ts.map +1 -0
  30. package/dist/src/components/interface/declaration.test.js +69 -0
  31. package/dist/src/components/interface/method.d.ts +18 -0
  32. package/dist/src/components/interface/method.d.ts.map +1 -0
  33. package/dist/src/components/interface/method.js +59 -0
  34. package/dist/src/components/interface/method.test.d.ts +2 -0
  35. package/dist/src/components/interface/method.test.d.ts.map +1 -0
  36. package/dist/src/components/interface/method.test.js +131 -0
  37. package/dist/src/components/interface/property.d.ts +21 -0
  38. package/dist/src/components/interface/property.d.ts.map +1 -0
  39. package/dist/src/components/interface/property.js +59 -0
  40. package/dist/src/components/interface/property.test.d.ts +2 -0
  41. package/dist/src/components/interface/property.test.d.ts.map +1 -0
  42. package/dist/src/components/interface/property.test.js +165 -0
  43. package/dist/src/components/stc/index.d.ts +2 -2
  44. package/dist/src/components/stc/index.d.ts.map +1 -1
  45. package/dist/src/components/stc/index.js +2 -2
  46. package/dist/src/modifiers.d.ts +13 -4
  47. package/dist/src/modifiers.d.ts.map +1 -1
  48. package/dist/src/modifiers.js +13 -27
  49. package/dist/src/name-policy.d.ts +1 -1
  50. package/dist/src/name-policy.d.ts.map +1 -1
  51. package/dist/src/name-policy.js +1 -0
  52. package/dist/test/class-declaration.test.d.ts +2 -0
  53. package/dist/test/class-declaration.test.d.ts.map +1 -0
  54. package/dist/test/{class.test.js → class-declaration.test.js} +123 -73
  55. package/dist/test/class-method.test.d.ts +2 -0
  56. package/dist/test/class-method.test.d.ts.map +1 -0
  57. package/dist/test/class-method.test.js +161 -0
  58. package/dist/test/enum.test.js +12 -12
  59. package/dist/test/namespace.test.js +8 -8
  60. package/dist/test/project-directory.test.d.ts +2 -0
  61. package/dist/test/project-directory.test.d.ts.map +1 -0
  62. package/dist/test/{projectdirectory.test.js → project-directory.test.js} +8 -8
  63. package/dist/test/sourcefile.test.js +4 -4
  64. package/dist/test/using.test.js +9 -9
  65. package/dist/test/utils.d.ts +3 -0
  66. package/dist/test/utils.d.ts.map +1 -1
  67. package/dist/test/utils.js +15 -0
  68. package/dist/test/vitest.setup.d.ts +2 -0
  69. package/dist/test/vitest.setup.d.ts.map +1 -0
  70. package/dist/test/vitest.setup.js +1 -0
  71. package/dist/tsconfig.tsbuildinfo +1 -1
  72. package/package.json +7 -6
  73. package/src/components/{Class.tsx → ClassDeclaration.tsx} +68 -66
  74. package/src/components/ClassMethod.tsx +94 -0
  75. package/src/components/{Enum.tsx → EnumDeclaration.tsx} +30 -6
  76. package/src/components/doc/comment.test.tsx +337 -0
  77. package/src/components/doc/comment.tsx +152 -0
  78. package/src/components/doc/from-markdown.test.tsx +103 -0
  79. package/src/components/doc/from-markdown.tsx +58 -0
  80. package/src/components/index.ts +7 -2
  81. package/src/components/interface/declaration.test.tsx +56 -0
  82. package/src/components/interface/declaration.tsx +109 -0
  83. package/src/components/interface/method.test.tsx +120 -0
  84. package/src/components/interface/method.tsx +82 -0
  85. package/src/components/interface/property.test.tsx +144 -0
  86. package/src/components/interface/property.tsx +90 -0
  87. package/src/components/stc/index.ts +2 -2
  88. package/src/modifiers.ts +32 -37
  89. package/src/name-policy.ts +2 -0
  90. package/temp/api.json +3275 -298
  91. package/test/{class.test.tsx → class-declaration.test.tsx} +103 -99
  92. package/test/class-method.test.tsx +147 -0
  93. package/test/enum.test.tsx +11 -11
  94. package/test/namespace.test.tsx +4 -4
  95. package/test/{projectdirectory.test.tsx → project-directory.test.tsx} +4 -4
  96. package/test/sourcefile.test.tsx +2 -2
  97. package/test/using.test.tsx +9 -9
  98. package/test/utils.tsx +9 -0
  99. package/test/vitest.setup.ts +1 -0
  100. package/tsconfig.json +2 -1
  101. package/vitest.config.ts +3 -0
  102. package/dist/src/components/Class.d.ts +0 -36
  103. package/dist/src/components/Class.d.ts.map +0 -1
  104. package/dist/src/components/Enum.d.ts +0 -15
  105. package/dist/src/components/Enum.d.ts.map +0 -1
  106. package/dist/test/class.test.d.ts +0 -2
  107. package/dist/test/class.test.d.ts.map +0 -1
  108. package/dist/test/projectdirectory.test.d.ts +0 -2
  109. package/dist/test/projectdirectory.test.d.ts.map +0 -1
@@ -0,0 +1,69 @@
1
+ import { createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { describe, expect, it } from "vitest";
3
+ import { TestNamespace } from "../../../test/utils.js";
4
+ import { InterfaceDeclaration } from "./declaration.js";
5
+ it("declares class with no members", () => {
6
+ expect(_$createComponent(TestNamespace, {
7
+ get children() {
8
+ return _$createComponent(InterfaceDeclaration, {
9
+ name: "TestInterface"
10
+ });
11
+ }
12
+ })).toRenderTo(`
13
+ interface TestInterface;
14
+ `);
15
+ });
16
+ describe("modifiers", () => {
17
+ it.each(["public", "private", "internal"])("%s", mod => {
18
+ expect(_$createComponent(TestNamespace, {
19
+ get children() {
20
+ return _$createComponent(InterfaceDeclaration, _$mergeProps({
21
+ [mod]: true
22
+ }, {
23
+ name: "TestInterface"
24
+ }));
25
+ }
26
+ })).toRenderTo(`
27
+ ${mod} interface TestInterface;
28
+ `);
29
+ });
30
+ it.each(["partial"])("%s", mod => {
31
+ expect(_$createComponent(TestNamespace, {
32
+ get children() {
33
+ return _$createComponent(InterfaceDeclaration, _$mergeProps({
34
+ [mod]: true
35
+ }, {
36
+ name: "TestInterface"
37
+ }));
38
+ }
39
+ })).toRenderTo(`
40
+ ${mod} interface TestInterface;
41
+ `);
42
+ });
43
+ it("combines modifiers", () => {
44
+ expect(_$createComponent(TestNamespace, {
45
+ get children() {
46
+ return _$createComponent(InterfaceDeclaration, {
47
+ "public": true,
48
+ partial: true,
49
+ name: "TestInterface"
50
+ });
51
+ }
52
+ })).toRenderTo(`
53
+ public partial interface TestInterface;
54
+ `);
55
+ });
56
+ });
57
+ it("specify doc comment", () => {
58
+ expect(_$createComponent(TestNamespace, {
59
+ get children() {
60
+ return _$createComponent(InterfaceDeclaration, {
61
+ name: "TestInterface",
62
+ doc: "This is a test"
63
+ });
64
+ }
65
+ })).toRenderTo(`
66
+ /// This is a test
67
+ interface TestInterface;
68
+ `);
69
+ });
@@ -0,0 +1,18 @@
1
+ import { Children, Refkey } from "@alloy-js/core";
2
+ import { AccessModifiers } from "../../modifiers.js";
3
+ import { ParameterProps } from "../Parameters.jsx";
4
+ /** Method modifiers. Can only be one. */
5
+ export interface InterfaceMethodModifiers {
6
+ readonly new?: boolean;
7
+ }
8
+ export interface InterfaceMethodProps extends AccessModifiers, InterfaceMethodModifiers {
9
+ name: string;
10
+ refkey?: Refkey;
11
+ children?: Children;
12
+ parameters?: Array<ParameterProps>;
13
+ returns?: Children;
14
+ /** Doc comment */
15
+ doc?: Children;
16
+ }
17
+ export declare function InterfaceMethod(props: InterfaceMethodProps): Children;
18
+ //# sourceMappingURL=method.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/method.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,cAAc,EAAc,MAAM,mBAAmB,CAAC;AAG/D,yCAAyC;AACzC,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAKD,MAAM,WAAW,oBACf,SAAQ,eAAe,EACrB,wBAAwB;IAC1B,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,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAGD,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YAuC1D"}
@@ -0,0 +1,59 @@
1
+ import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import { Block, MemberDeclaration, refkey, Scope } 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, useCSharpScope } from "../../symbols/scopes.js";
7
+ import { Parameters } from "../Parameters.js";
8
+ import { DocWhen } from "../doc/comment.js";
9
+
10
+ /** Method modifiers. Can only be one. */
11
+
12
+ const getMethodModifier = makeModifiers(["new"]);
13
+
14
+ // properties for creating a method
15
+
16
+ // a C# interface method
17
+ export function InterfaceMethod(props) {
18
+ const name = useCSharpNamePolicy().getName(props.name, "class-method");
19
+ const scope = useCSharpScope();
20
+ if (scope.kind !== "member" || scope.name !== "interface-decl") {
21
+ throw new Error("can't define an interface method outside of an interface scope");
22
+ }
23
+ const methodSymbol = new CSharpOutputSymbol(name, {
24
+ scope,
25
+ refkeys: props.refkey ?? refkey(props.name)
26
+ });
27
+
28
+ // scope for method declaration
29
+ const methodScope = new CSharpMemberScope("method-decl", {
30
+ owner: methodSymbol
31
+ });
32
+ const params = props.parameters ? _$createComponent(Parameters, {
33
+ get parameters() {
34
+ return props.parameters;
35
+ }
36
+ }) : "";
37
+ const modifiers = computeModifiersPrefix([getAccessModifier(props), getMethodModifier(props)]);
38
+ // note that scope wraps the method decl so that the params get the correct scope
39
+ return _$createComponent(MemberDeclaration, {
40
+ symbol: methodSymbol,
41
+ get children() {
42
+ return _$createComponent(Scope, {
43
+ value: methodScope,
44
+ get children() {
45
+ return [_$createComponent(DocWhen, {
46
+ get doc() {
47
+ return props.doc;
48
+ }
49
+ }), modifiers, _$memo(() => props.returns ?? "void"), " ", name, "(", params, ")", _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(Block, {
50
+ newline: true,
51
+ get children() {
52
+ return props.children;
53
+ }
54
+ }) : ";")];
55
+ }
56
+ });
57
+ }
58
+ });
59
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=method.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"method.test.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/method.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,131 @@
1
+ import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { describe, expect, it } from "vitest";
3
+ import { TestNamespace } from "../../../test/utils.js";
4
+ import { InterfaceDeclaration } from "./declaration.js";
5
+ import { InterfaceMethod } from "./method.js";
6
+ const Wrapper = props => _$createComponent(TestNamespace, {
7
+ get children() {
8
+ return _$createComponent(InterfaceDeclaration, {
9
+ "public": true,
10
+ name: "TestInterface",
11
+ get children() {
12
+ return props.children;
13
+ }
14
+ });
15
+ }
16
+ });
17
+ describe("modifiers", () => {
18
+ describe("access modifiers", () => {
19
+ it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
20
+ expect(_$createComponent(Wrapper, {
21
+ get children() {
22
+ return _$createComponent(InterfaceMethod, _$mergeProps({
23
+ [accessModifier]: true
24
+ }, {
25
+ name: "MethodOne"
26
+ }));
27
+ }
28
+ })).toRenderTo(`
29
+ public interface TestInterface
30
+ {
31
+ ${accessModifier} void MethodOne();
32
+ }
33
+ `);
34
+ });
35
+ });
36
+ describe("method modifiers", () => {
37
+ it.each(["new"])("%s", methodModifier => {
38
+ expect(_$createComponent(Wrapper, {
39
+ get children() {
40
+ return _$createComponent(InterfaceMethod, _$mergeProps({
41
+ [methodModifier]: true
42
+ }, {
43
+ name: "MethodOne"
44
+ }));
45
+ }
46
+ })).toRenderTo(`
47
+ public interface TestInterface
48
+ {
49
+ ${methodModifier} void MethodOne();
50
+ }
51
+ `);
52
+ });
53
+ });
54
+ it("combine modifiers", () => {
55
+ expect(_$createComponent(Wrapper, {
56
+ get children() {
57
+ return _$createComponent(InterfaceMethod, {
58
+ returns: "Task",
59
+ "public": true,
60
+ "new": true,
61
+ name: "MethodOne"
62
+ });
63
+ }
64
+ })).toRenderTo(`
65
+ public interface TestInterface
66
+ {
67
+ public new Task MethodOne();
68
+ }
69
+ `);
70
+ });
71
+ });
72
+ it("applies PascalCase naming policy", () => {
73
+ expect(_$createComponent(Wrapper, {
74
+ get children() {
75
+ return _$createComponent(InterfaceMethod, {
76
+ name: "method_one"
77
+ });
78
+ }
79
+ })).toRenderTo(`
80
+ public interface TestInterface
81
+ {
82
+ void MethodOne();
83
+ }
84
+ `);
85
+ });
86
+ it("defines params and return type", () => {
87
+ const params = [{
88
+ name: "intParam",
89
+ type: "int"
90
+ }, {
91
+ name: "stringParam",
92
+ type: "string"
93
+ }];
94
+ const res = _$createComponent(Wrapper, {
95
+ get children() {
96
+ return _$createComponent(InterfaceMethod, {
97
+ "public": true,
98
+ name: "MethodOne",
99
+ parameters: params,
100
+ returns: "string"
101
+ });
102
+ }
103
+ });
104
+ expect(res).toRenderTo(`
105
+ public interface TestInterface
106
+ {
107
+ public string MethodOne(int intParam, string stringParam);
108
+ }
109
+ `);
110
+ });
111
+ it("specify doc comment", () => {
112
+ expect(_$createComponent(TestNamespace, {
113
+ get children() {
114
+ return _$createComponent(InterfaceDeclaration, {
115
+ name: "Test",
116
+ get children() {
117
+ return _$createComponent(InterfaceMethod, {
118
+ name: "Method",
119
+ doc: "This is a test"
120
+ });
121
+ }
122
+ });
123
+ }
124
+ })).toRenderTo(`
125
+ interface Test
126
+ {
127
+ /// This is a test
128
+ void Method();
129
+ }
130
+ `);
131
+ });
@@ -0,0 +1,21 @@
1
+ import { Children, Refkey } from "@alloy-js/core";
2
+ import { AccessModifiers } from "../../modifiers.js";
3
+ /** Method modifiers. Can only be one. */
4
+ export interface InterfacePropertyModifiers {
5
+ readonly new?: boolean;
6
+ }
7
+ export declare const getMethodModifier: (data: InterfacePropertyModifiers) => string;
8
+ export interface InterfacePropertyProps extends AccessModifiers, InterfacePropertyModifiers {
9
+ name: string;
10
+ refkey?: Refkey;
11
+ /** Property type */
12
+ type: Children;
13
+ /** If property should have a getter */
14
+ get?: boolean;
15
+ /** If property should have a setter */
16
+ set?: boolean;
17
+ /** Doc comment */
18
+ doc?: Children;
19
+ }
20
+ export declare function InterfaceProperty(props: InterfacePropertyProps): Children;
21
+ //# sourceMappingURL=property.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAIR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAM5B,yCAAyC;AACzC,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,eAAO,MAAM,iBAAiB,8CAE5B,CAAC;AAGH,MAAM,WAAW,sBACf,SAAQ,eAAe,EACrB,0BAA0B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,oBAAoB;IACpB,IAAI,EAAE,QAAQ,CAAC;IAEf,uCAAuC;IACvC,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,uCAAuC;IACvC,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAGD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,YAuC9D"}
@@ -0,0 +1,59 @@
1
+ import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import { Block, List, MemberDeclaration, refkey, Scope } 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, useCSharpScope } from "../../symbols/scopes.js";
7
+ import { DocWhen } from "../doc/comment.js";
8
+
9
+ /** Method modifiers. Can only be one. */
10
+
11
+ export const getMethodModifier = makeModifiers(["new"]);
12
+
13
+ // properties for creating a method
14
+
15
+ // a C# interface property
16
+ export function InterfaceProperty(props) {
17
+ const name = useCSharpNamePolicy().getName(props.name, "class-property");
18
+ const scope = useCSharpScope();
19
+ if (scope.kind !== "member" || scope.name !== "interface-decl") {
20
+ throw new Error("can't define an interface method outside of an interface scope");
21
+ }
22
+ const propertySymbol = new CSharpOutputSymbol(name, {
23
+ scope,
24
+ refkeys: props.refkey ?? refkey(props.name)
25
+ });
26
+
27
+ // scope for property declaration
28
+ const propertyScope = new CSharpMemberScope("property-decl", {
29
+ owner: propertySymbol
30
+ });
31
+ const modifiers = computeModifiersPrefix([getAccessModifier(props), getMethodModifier(props)]);
32
+ // note that scope wraps the method decl so that the params get the correct scope
33
+ return _$createComponent(MemberDeclaration, {
34
+ symbol: propertySymbol,
35
+ get children() {
36
+ return _$createComponent(Scope, {
37
+ value: propertyScope,
38
+ get children() {
39
+ return [_$createComponent(DocWhen, {
40
+ get doc() {
41
+ return props.doc;
42
+ }
43
+ }), modifiers, _$memo(() => props.type), " ", name, " ", _$createComponent(Block, {
44
+ newline: true,
45
+ inline: true,
46
+ get children() {
47
+ return _$createComponent(List, {
48
+ joiner: " ",
49
+ get children() {
50
+ return [_$memo(() => props.get && "get;"), _$memo(() => props.set && "set;")];
51
+ }
52
+ });
53
+ }
54
+ })];
55
+ }
56
+ });
57
+ }
58
+ });
59
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=property.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property.test.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/property.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,165 @@
1
+ import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { describe, expect, it } from "vitest";
3
+ import { TestNamespace } from "../../../test/utils.js";
4
+ import { InterfaceDeclaration } from "./declaration.js";
5
+ import { InterfaceProperty } from "./property.js";
6
+ const Wrapper = props => _$createComponent(TestNamespace, {
7
+ get children() {
8
+ return _$createComponent(InterfaceDeclaration, {
9
+ "public": true,
10
+ name: "TestInterface",
11
+ get children() {
12
+ return props.children;
13
+ }
14
+ });
15
+ }
16
+ });
17
+ describe("modifiers", () => {
18
+ describe("access modifiers", () => {
19
+ it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
20
+ expect(_$createComponent(Wrapper, {
21
+ get children() {
22
+ return _$createComponent(InterfaceProperty, _$mergeProps({
23
+ [accessModifier]: true
24
+ }, {
25
+ name: "TestProp",
26
+ type: "string",
27
+ get: true
28
+ }));
29
+ }
30
+ })).toRenderTo(`
31
+ public interface TestInterface
32
+ {
33
+ ${accessModifier} string TestProp { get; }
34
+ }
35
+ `);
36
+ });
37
+ });
38
+ describe("method modifiers", () => {
39
+ it.each(["new"])("%s", methodModifier => {
40
+ expect(_$createComponent(Wrapper, {
41
+ get children() {
42
+ return _$createComponent(InterfaceProperty, _$mergeProps({
43
+ [methodModifier]: true
44
+ }, {
45
+ name: "TestProp",
46
+ type: "string",
47
+ get: true
48
+ }));
49
+ }
50
+ })).toRenderTo(`
51
+ public interface TestInterface
52
+ {
53
+ ${methodModifier} string TestProp { get; }
54
+ }
55
+ `);
56
+ });
57
+ });
58
+ it("combine modifiers", () => {
59
+ expect(_$createComponent(Wrapper, {
60
+ get children() {
61
+ return _$createComponent(InterfaceProperty, {
62
+ "public": true,
63
+ "new": true,
64
+ name: "TestProp",
65
+ type: "string",
66
+ get: true
67
+ });
68
+ }
69
+ })).toRenderTo(`
70
+ public interface TestInterface
71
+ {
72
+ public new string TestProp { get; }
73
+ }
74
+ `);
75
+ });
76
+ });
77
+ it("applies PascalCase naming policy", () => {
78
+ expect(_$createComponent(Wrapper, {
79
+ get children() {
80
+ return _$createComponent(InterfaceProperty, {
81
+ name: "test_prop",
82
+ type: "string",
83
+ get: true
84
+ });
85
+ }
86
+ })).toRenderTo(`
87
+ public interface TestInterface
88
+ {
89
+ string TestProp { get; }
90
+ }
91
+ `);
92
+ });
93
+ it("has getter only", () => {
94
+ expect(_$createComponent(Wrapper, {
95
+ get children() {
96
+ return _$createComponent(InterfaceProperty, {
97
+ name: "TestProp",
98
+ type: "string",
99
+ get: true
100
+ });
101
+ }
102
+ })).toRenderTo(`
103
+ public interface TestInterface
104
+ {
105
+ string TestProp { get; }
106
+ }
107
+ `);
108
+ });
109
+ it("has setter only", () => {
110
+ expect(_$createComponent(Wrapper, {
111
+ get children() {
112
+ return _$createComponent(InterfaceProperty, {
113
+ name: "TestProp",
114
+ type: "string",
115
+ set: true
116
+ });
117
+ }
118
+ })).toRenderTo(`
119
+ public interface TestInterface
120
+ {
121
+ string TestProp { set; }
122
+ }
123
+ `);
124
+ });
125
+ it("has getter and setter", () => {
126
+ expect(_$createComponent(Wrapper, {
127
+ get children() {
128
+ return _$createComponent(InterfaceProperty, {
129
+ name: "TestProp",
130
+ type: "string",
131
+ get: true,
132
+ set: true
133
+ });
134
+ }
135
+ })).toRenderTo(`
136
+ public interface TestInterface
137
+ {
138
+ string TestProp { get; set; }
139
+ }
140
+ `);
141
+ });
142
+ it("specify doc comment", () => {
143
+ expect(_$createComponent(TestNamespace, {
144
+ get children() {
145
+ return _$createComponent(InterfaceDeclaration, {
146
+ name: "Test",
147
+ get children() {
148
+ return _$createComponent(InterfaceProperty, {
149
+ name: "Method",
150
+ type: "string",
151
+ get: true,
152
+ set: true,
153
+ doc: "This is a test"
154
+ });
155
+ }
156
+ });
157
+ }
158
+ })).toRenderTo(`
159
+ interface Test
160
+ {
161
+ /// This is a test
162
+ string Method { get; set; }
163
+ }
164
+ `);
165
+ });
@@ -1,10 +1,10 @@
1
1
  import * as core from "@alloy-js/core";
2
2
  import * as base from "../index.js";
3
- export declare const Class: core.StcSignature<base.ClassProps>;
3
+ export declare const ClassDeclaration: core.StcSignature<base.ClassDeclarationProps>;
4
4
  export declare const ClassConstructor: core.StcSignature<base.ClassConstructorProps>;
5
5
  export declare const ClassMember: core.StcSignature<base.ClassMemberProps>;
6
6
  export declare const ClassMethod: core.StcSignature<base.ClassMethodProps>;
7
- export declare const Enum: core.StcSignature<base.EnumProps>;
7
+ export declare const EnumDeclaration: core.StcSignature<base.EnumDeclarationProps>;
8
8
  export declare const EnumMember: core.StcSignature<base.EnumMemberProps>;
9
9
  export declare const Parameter: core.StcSignature<base.ParameterProps>;
10
10
  export declare const Parameters: core.StcSignature<base.ParametersProps>;
@@ -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,KAAK,oCAAuB,CAAC;AAC1C,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,IAAI,mCAAsB,CAAC;AACxC,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"}
@@ -1,10 +1,10 @@
1
1
  import * as core from "@alloy-js/core";
2
2
  import * as base from "../index.js";
3
- export const Class = core.stc(base.Class);
3
+ export const ClassDeclaration = core.stc(base.ClassDeclaration);
4
4
  export const ClassConstructor = core.stc(base.ClassConstructor);
5
5
  export const ClassMember = core.stc(base.ClassMember);
6
6
  export const ClassMethod = core.stc(base.ClassMethod);
7
- export const Enum = core.stc(base.Enum);
7
+ export const EnumDeclaration = core.stc(base.EnumDeclaration);
8
8
  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);
@@ -1,5 +1,14 @@
1
- export type AccessModifier = "public" | "protected" | "private" | "internal" | "protected-internal" | "private-protected" | "file";
2
- export declare function getAccessModifier(accessModifier?: AccessModifier): string;
3
- export type MethodModifier = "abstract" | "sealed" | "static" | "virtual";
4
- export declare function getMethodModifier(methodModifier?: MethodModifier): string;
1
+ /** Access modifiers. */
2
+ export interface AccessModifiers {
3
+ readonly public?: boolean;
4
+ readonly protected?: boolean;
5
+ readonly private?: boolean;
6
+ readonly internal?: boolean;
7
+ readonly file?: boolean;
8
+ }
9
+ export declare const getAccessModifier: (data: AccessModifiers) => string;
10
+ export declare function getAsyncModifier(async?: boolean): string;
11
+ /** Resolve the modifier prefix */
12
+ export declare function computeModifiersPrefix(modifiers: Array<string | undefined>): string;
13
+ export declare function makeModifiers<T>(obj: Array<keyof T>): (data: T) => string;
5
14
  //# sourceMappingURL=modifiers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"modifiers.d.ts","sourceRoot":"","sources":["../../src/modifiers.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,cAAc,GACtB,QAAQ,GACR,WAAW,GACX,SAAS,GACT,UAAU,GACV,oBAAoB,GACpB,mBAAmB,GACnB,MAAM,CAAC;AAgBX,wBAAgB,iBAAiB,CAAC,cAAc,CAAC,EAAE,cAAc,GAAG,MAAM,CAEzE;AAED,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAa1E,wBAAgB,iBAAiB,CAAC,cAAc,CAAC,EAAE,cAAc,GAAG,MAAM,CAEzE"}
1
+ {"version":3,"file":"modifiers.d.ts","sourceRoot":"","sources":["../../src/modifiers.ts"],"names":[],"mappings":"AAGA,yBAAyB;AACzB,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,eAAO,MAAM,iBAAiB,mCAM5B,CAAC;AAEH,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAExD;AAED,kCAAkC;AAClC,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,GACnC,MAAM,CAGR;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,IAC1C,MAAM,CAAC,YAMhB"}
@@ -1,34 +1,20 @@
1
1
  // the possible C# access modifiers
2
2
  // https://learn.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers
3
3
 
4
- // maps the above access modifier value to its C# syntax.
5
- // note that the C# keyword includes a trailing space
6
- const accessModifierLookup = {
7
- public: "public ",
8
- protected: "protected ",
9
- private: "private ",
10
- internal: "internal ",
11
- "protected-internal": "protected internal ",
12
- "private-protected": "private protected ",
13
- file: "file "
14
- };
4
+ /** Access modifiers. */
15
5
 
16
- // returns the C# syntax for the specified access modifier.
17
- // if no access modifier is specified, the empty string is returned.
18
- export function getAccessModifier(accessModifier) {
19
- return accessModifier ? accessModifierLookup[accessModifier] : "";
6
+ export const getAccessModifier = makeModifiers(["public", "protected", "private", "internal", "file"]);
7
+ export function getAsyncModifier(async) {
8
+ return async ? "async" : "";
20
9
  }
21
- // maps the above method modifier value to its C# syntax.
22
- // note that the C# keyword includes a trailing space
23
- const methodModifierLookup = {
24
- abstract: "abstract ",
25
- sealed: "sealed ",
26
- static: "static ",
27
- virtual: "virtual "
28
- };
29
10
 
30
- // returns the C# syntax for the specified method modifier.
31
- // if no method modifier is specified, the empty string is returned.
32
- export function getMethodModifier(methodModifier) {
33
- return methodModifier ? methodModifierLookup[methodModifier] : "";
11
+ /** Resolve the modifier prefix */
12
+ export function computeModifiersPrefix(modifiers) {
13
+ const resolved = modifiers.filter(x => x);
14
+ return resolved.length > 0 ? resolved.join(" ") + " " : "";
15
+ }
16
+ export function makeModifiers(obj) {
17
+ return data => {
18
+ return obj.map(key => data[key] ? key : undefined).filter(x => x).join(" ");
19
+ };
34
20
  }
@@ -1,5 +1,5 @@
1
1
  import * as core from "@alloy-js/core";
2
- export type CSharpElements = "class" | "constant" | "enum" | "enum-member" | "function" | "interface" | "class-member-private" | "class-member-public" | "class-method" | "parameter" | "type-parameter";
2
+ export type CSharpElements = "class" | "constant" | "enum" | "enum-member" | "function" | "interface" | "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