@alloy-js/csharp 0.18.0-dev.6 → 0.18.0-dev.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/src/components/ClassDeclaration.d.ts +2 -0
  2. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  3. package/dist/src/components/ClassDeclaration.js +6 -1
  4. package/dist/src/components/ClassMethod.d.ts +11 -2
  5. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  6. package/dist/src/components/ClassMethod.js +11 -2
  7. package/dist/src/components/doc/comment.d.ts +69 -0
  8. package/dist/src/components/doc/comment.d.ts.map +1 -0
  9. package/dist/src/components/doc/comment.js +71 -0
  10. package/dist/src/components/doc/comment.test.d.ts +2 -0
  11. package/dist/src/components/doc/comment.test.d.ts.map +1 -0
  12. package/dist/src/components/doc/comment.test.js +338 -0
  13. package/dist/src/components/index.d.ts +3 -1
  14. package/dist/src/components/index.d.ts.map +1 -1
  15. package/dist/src/components/index.js +3 -1
  16. package/dist/src/components/interface/declaration.d.ts +34 -0
  17. package/dist/src/components/interface/declaration.d.ts.map +1 -0
  18. package/dist/src/components/interface/declaration.js +90 -0
  19. package/dist/src/components/interface/declaration.test.d.ts +2 -0
  20. package/dist/src/components/interface/declaration.test.d.ts.map +1 -0
  21. package/dist/src/components/interface/declaration.test.js +69 -0
  22. package/dist/src/components/interface/method.d.ts +18 -0
  23. package/dist/src/components/interface/method.d.ts.map +1 -0
  24. package/dist/src/components/interface/method.js +59 -0
  25. package/dist/src/components/interface/method.test.d.ts +2 -0
  26. package/dist/src/components/interface/method.test.d.ts.map +1 -0
  27. package/dist/src/components/interface/method.test.js +131 -0
  28. package/dist/src/components/interface/property.d.ts +21 -0
  29. package/dist/src/components/interface/property.d.ts.map +1 -0
  30. package/dist/src/components/interface/property.js +59 -0
  31. package/dist/src/components/interface/property.test.d.ts +2 -0
  32. package/dist/src/components/interface/property.test.d.ts.map +1 -0
  33. package/dist/src/components/interface/property.test.js +165 -0
  34. package/dist/src/modifiers.d.ts +0 -8
  35. package/dist/src/modifiers.d.ts.map +1 -1
  36. package/dist/src/modifiers.js +0 -4
  37. package/dist/src/name-policy.d.ts +1 -1
  38. package/dist/src/name-policy.d.ts.map +1 -1
  39. package/dist/src/name-policy.js +1 -0
  40. package/dist/test/class-method.test.js +21 -0
  41. package/dist/test/class.test.js +13 -0
  42. package/dist/test/vitest.setup.d.ts +2 -0
  43. package/dist/test/vitest.setup.d.ts.map +1 -0
  44. package/dist/test/vitest.setup.js +1 -0
  45. package/dist/tsconfig.tsbuildinfo +1 -1
  46. package/package.json +2 -2
  47. package/src/components/ClassDeclaration.tsx +4 -0
  48. package/src/components/ClassMethod.tsx +24 -3
  49. package/src/components/doc/comment.test.tsx +336 -0
  50. package/src/components/doc/comment.tsx +122 -0
  51. package/src/components/index.ts +3 -1
  52. package/src/components/interface/declaration.test.tsx +56 -0
  53. package/src/components/interface/declaration.tsx +109 -0
  54. package/src/components/interface/method.test.tsx +120 -0
  55. package/src/components/interface/method.tsx +82 -0
  56. package/src/components/interface/property.test.tsx +144 -0
  57. package/src/components/interface/property.tsx +90 -0
  58. package/src/modifiers.ts +0 -15
  59. package/src/name-policy.ts +2 -0
  60. package/temp/api.json +699 -81
  61. package/test/class-method.test.tsx +16 -0
  62. package/test/class.test.tsx +11 -0
  63. package/test/vitest.setup.ts +1 -0
  64. package/vitest.config.ts +3 -0
@@ -0,0 +1,90 @@
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, 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 { DocWhen } from "../doc/comment.js";
8
+ import { Name } from "../Name.js";
9
+ const getInterfaceModifiers = makeModifiers(["partial"]);
10
+
11
+ // properties for creating a class
12
+
13
+ /**
14
+ * CSharp interface declaration.
15
+ * @example
16
+ * ```tsx
17
+ * <InterfaceDeclaration public name="IMyInterface">
18
+ * <InterfaceMember public name="MyProperty" type="int" />
19
+ * <InterfaceMethod public name="MyMethod" returnType="void">
20
+ * <Parameter name="value" type="int" />
21
+ * </InterfaceMethod>
22
+ * </InterfaceDeclaration>
23
+ * ```
24
+ * This will produce:
25
+ * ```csharp
26
+ * public interface MyIface
27
+ * {
28
+ * public int MyProperty { get; set; }
29
+ * public void MyMethod(int value);
30
+ * }
31
+ * ```
32
+ */
33
+ export function InterfaceDeclaration(props) {
34
+ const name = useCSharpNamePolicy().getName(props.name, "interface");
35
+ const thisInterfaceSymbol = new CSharpOutputSymbol(name, {
36
+ refkeys: props.refkey
37
+ });
38
+
39
+ // this creates a new scope for the interface definition.
40
+ // members will automatically "inherit" this scope so
41
+ // that refkeys to them will produce the fully-qualified
42
+ // name e.g. Foo.Bar.
43
+ const thisInterfaceScope = new CSharpMemberScope("interface-decl", {
44
+ owner: thisInterfaceSymbol
45
+ });
46
+ let typeParams;
47
+ if (props.typeParameters) {
48
+ const typeParamNames = new Array();
49
+ for (const entry of Object.entries(props.typeParameters)) {
50
+ typeParamNames.push(useCSharpNamePolicy().getName(entry[0], "type-parameter"));
51
+ // create a symbol for each type param so its
52
+ // refkey resolves to the type param's name
53
+ new CSharpOutputSymbol(entry[0], {
54
+ scope: thisInterfaceScope,
55
+ refkeys: entry[1]
56
+ });
57
+ }
58
+ typeParams = _$createIntrinsic("group", {
59
+ get children() {
60
+ return ["<", _$createComponent(core.For, {
61
+ each: typeParamNames,
62
+ comma: true,
63
+ line: true,
64
+ children: name => name
65
+ }), ">"];
66
+ }
67
+ });
68
+ }
69
+ const modifiers = computeModifiersPrefix([getAccessModifier(props), getInterfaceModifiers(props)]);
70
+ return _$createComponent(core.Declaration, {
71
+ symbol: thisInterfaceSymbol,
72
+ get children() {
73
+ return [_$createComponent(DocWhen, {
74
+ get doc() {
75
+ return props.doc;
76
+ }
77
+ }), modifiers, "interface ", _$createComponent(Name, {}), typeParams, _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(core.Block, {
78
+ newline: true,
79
+ get children() {
80
+ return _$createComponent(core.Scope, {
81
+ value: thisInterfaceScope,
82
+ get children() {
83
+ return props.children;
84
+ }
85
+ });
86
+ }
87
+ }) : ";")];
88
+ }
89
+ });
90
+ }
@@ -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/interface/declaration.test.tsx"],"names":[],"mappings":""}
@@ -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
+ });
@@ -7,14 +7,6 @@ export interface AccessModifiers {
7
7
  readonly file?: boolean;
8
8
  }
9
9
  export declare const getAccessModifier: (data: AccessModifiers) => string;
10
- /** Method modifiers. Can only be one. */
11
- export interface MethodModifiers {
12
- readonly abstract?: boolean;
13
- readonly sealed?: boolean;
14
- readonly static?: boolean;
15
- readonly virtual?: boolean;
16
- }
17
- export declare const getMethodModifier: (data: MethodModifiers) => string;
18
10
  export declare function getAsyncModifier(async?: boolean): string;
19
11
  /** Resolve the modifier prefix */
20
12
  export declare function computeModifiersPrefix(modifiers: Array<string | undefined>): string;
@@ -1 +1 @@
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,yCAAyC;AACzC,MAAM,WAAW,eAAe;IAC9B,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;AAED,eAAO,MAAM,iBAAiB,mCAK5B,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
+ {"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"}
@@ -4,10 +4,6 @@
4
4
  /** Access modifiers. */
5
5
 
6
6
  export const getAccessModifier = makeModifiers(["public", "protected", "private", "internal", "file"]);
7
-
8
- /** Method modifiers. Can only be one. */
9
-
10
- export const getMethodModifier = makeModifiers(["abstract", "sealed", "static", "virtual"]);
11
7
  export function getAsyncModifier(async) {
12
8
  return async ? "async" : "";
13
9
  }