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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/src/components/ClassMethod.d.ts +9 -2
  2. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  3. package/dist/src/components/ClassMethod.js +5 -1
  4. package/dist/src/components/index.d.ts +3 -1
  5. package/dist/src/components/index.d.ts.map +1 -1
  6. package/dist/src/components/index.js +3 -1
  7. package/dist/src/components/interface/declaration.d.ts +32 -0
  8. package/dist/src/components/interface/declaration.d.ts.map +1 -0
  9. package/dist/src/components/interface/declaration.js +85 -0
  10. package/dist/src/components/interface/declaration.test.d.ts +2 -0
  11. package/dist/src/components/interface/declaration.test.d.ts.map +1 -0
  12. package/dist/src/components/interface/declaration.test.js +56 -0
  13. package/dist/src/components/interface/method.d.ts +16 -0
  14. package/dist/src/components/interface/method.d.ts.map +1 -0
  15. package/dist/src/components/interface/method.js +54 -0
  16. package/dist/src/components/interface/method.test.d.ts +2 -0
  17. package/dist/src/components/interface/method.test.d.ts.map +1 -0
  18. package/dist/src/components/interface/method.test.js +110 -0
  19. package/dist/src/components/interface/property.d.ts +19 -0
  20. package/dist/src/components/interface/property.d.ts.map +1 -0
  21. package/dist/src/components/interface/property.js +54 -0
  22. package/dist/src/components/interface/property.test.d.ts +2 -0
  23. package/dist/src/components/interface/property.test.d.ts.map +1 -0
  24. package/dist/src/components/interface/property.test.js +141 -0
  25. package/dist/src/modifiers.d.ts +0 -8
  26. package/dist/src/modifiers.d.ts.map +1 -1
  27. package/dist/src/modifiers.js +0 -4
  28. package/dist/src/name-policy.d.ts +1 -1
  29. package/dist/src/name-policy.d.ts.map +1 -1
  30. package/dist/src/name-policy.js +1 -0
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +2 -2
  33. package/src/components/ClassMethod.tsx +19 -3
  34. package/src/components/index.ts +3 -1
  35. package/src/components/interface/declaration.test.tsx +45 -0
  36. package/src/components/interface/declaration.tsx +104 -0
  37. package/src/components/interface/method.test.tsx +104 -0
  38. package/src/components/interface/method.tsx +77 -0
  39. package/src/components/interface/property.test.tsx +122 -0
  40. package/src/components/interface/property.tsx +85 -0
  41. package/src/modifiers.ts +0 -15
  42. package/src/name-policy.ts +2 -0
  43. package/temp/api.json +607 -101
@@ -1,7 +1,14 @@
1
1
  import { Children, Refkey } from "@alloy-js/core";
2
- import { AccessModifiers, MethodModifiers } from "../modifiers.js";
2
+ import { AccessModifiers } from "../modifiers.js";
3
3
  import { ParameterProps } from "./Parameters.jsx";
4
- export interface ClassMethodProps extends AccessModifiers, MethodModifiers {
4
+ /** Method modifiers. Can only be one. */
5
+ export interface ClassMethodModifiers {
6
+ readonly abstract?: boolean;
7
+ readonly sealed?: boolean;
8
+ readonly static?: boolean;
9
+ readonly virtual?: boolean;
10
+ }
11
+ export interface ClassMethodProps extends AccessModifiers, ClassMethodModifiers {
5
12
  name: string;
6
13
  refkey?: Refkey;
7
14
  children?: Children;
@@ -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,EAKf,eAAe,EAChB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAE,cAAc,EAAc,MAAM,kBAAkB,CAAC;AAG9D,MAAM,WAAW,gBAAiB,SAAQ,eAAe,EAAE,eAAe;IACxE,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;CACjB;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YAoClD"}
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,EAAE,cAAc,EAAc,MAAM,kBAAkB,CAAC;AAE9D,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;CACjB;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YAoClD"}
@@ -1,11 +1,15 @@
1
1
  import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
2
  import { Block, MemberDeclaration, refkey, Scope } from "@alloy-js/core";
3
- import { computeModifiersPrefix, getAccessModifier, getAsyncModifier, getMethodModifier } from "../modifiers.js";
3
+ import { computeModifiersPrefix, getAccessModifier, getAsyncModifier, makeModifiers } from "../modifiers.js";
4
4
  import { useCSharpNamePolicy } from "../name-policy.js";
5
5
  import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
6
6
  import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
7
7
  import { Parameters } from "./Parameters.js";
8
8
 
9
+ /** Method modifiers. Can only be one. */
10
+
11
+ const getMethodModifier = makeModifiers(["abstract", "sealed", "static", "virtual"]);
12
+
9
13
  // properties for creating a method
10
14
 
11
15
  // a C# class method
@@ -1,7 +1,9 @@
1
1
  export * from "./ClassDeclaration.jsx";
2
- export { ClassMethod, type ClassMethodProps } from "./ClassMethod.jsx";
2
+ export * from "./ClassMethod.jsx";
3
3
  export * from "./Declaration.js";
4
4
  export * from "./EnumDeclaration.jsx";
5
+ export * from "./interface/declaration.js";
6
+ export * from "./interface/method.js";
5
7
  export * from "./Name.js";
6
8
  export * from "./Namespace.js";
7
9
  export * from "./Parameters.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACvE,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
@@ -1,7 +1,9 @@
1
1
  export * from "./ClassDeclaration.js";
2
- export { ClassMethod } from "./ClassMethod.js";
2
+ export * from "./ClassMethod.js";
3
3
  export * from "./Declaration.js";
4
4
  export * from "./EnumDeclaration.js";
5
+ export * from "./interface/declaration.js";
6
+ export * from "./interface/method.js";
5
7
  export * from "./Name.js";
6
8
  export * from "./Namespace.js";
7
9
  export * from "./Parameters.js";
@@ -0,0 +1,32 @@
1
+ import * as core from "@alloy-js/core";
2
+ import { AccessModifiers } from "../../modifiers.js";
3
+ export interface InterfaceModifiers {
4
+ readonly partial?: boolean;
5
+ }
6
+ export interface InterfaceDeclarationProps extends Omit<core.DeclarationProps, "nameKind">, AccessModifiers, InterfaceModifiers {
7
+ name: string;
8
+ refkey?: core.Refkey;
9
+ typeParameters?: Record<string, core.Refkey>;
10
+ }
11
+ /**
12
+ * CSharp interface declaration.
13
+ * @example
14
+ * ```tsx
15
+ * <InterfaceDeclaration public name="IMyInterface">
16
+ * <InterfaceMember public name="MyProperty" type="int" />
17
+ * <InterfaceMethod public name="MyMethod" returnType="void">
18
+ * <Parameter name="value" type="int" />
19
+ * </InterfaceMethod>
20
+ * </InterfaceDeclaration>
21
+ * ```
22
+ * This will produce:
23
+ * ```csharp
24
+ * public interface MyIface
25
+ * {
26
+ * public int MyProperty { get; set; }
27
+ * public void MyMethod(int value);
28
+ * }
29
+ * ```
30
+ */
31
+ export declare function InterfaceDeclaration(props: InterfaceDeclarationProps): core.Children;
32
+ //# sourceMappingURL=declaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAM5B,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAKD,MAAM,WAAW,yBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,kBAAkB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,iBAuDpE"}
@@ -0,0 +1,85 @@
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 { Name } from "../Name.js";
8
+ const getInterfaceModifiers = makeModifiers(["partial"]);
9
+
10
+ // properties for creating a class
11
+
12
+ /**
13
+ * CSharp interface declaration.
14
+ * @example
15
+ * ```tsx
16
+ * <InterfaceDeclaration public name="IMyInterface">
17
+ * <InterfaceMember public name="MyProperty" type="int" />
18
+ * <InterfaceMethod public name="MyMethod" returnType="void">
19
+ * <Parameter name="value" type="int" />
20
+ * </InterfaceMethod>
21
+ * </InterfaceDeclaration>
22
+ * ```
23
+ * This will produce:
24
+ * ```csharp
25
+ * public interface MyIface
26
+ * {
27
+ * public int MyProperty { get; set; }
28
+ * public void MyMethod(int value);
29
+ * }
30
+ * ```
31
+ */
32
+ export function InterfaceDeclaration(props) {
33
+ const name = useCSharpNamePolicy().getName(props.name, "interface");
34
+ const thisInterfaceSymbol = new CSharpOutputSymbol(name, {
35
+ refkeys: props.refkey
36
+ });
37
+
38
+ // this creates a new scope for the interface definition.
39
+ // members will automatically "inherit" this scope so
40
+ // that refkeys to them will produce the fully-qualified
41
+ // name e.g. Foo.Bar.
42
+ const thisInterfaceScope = new CSharpMemberScope("interface-decl", {
43
+ owner: thisInterfaceSymbol
44
+ });
45
+ let typeParams;
46
+ if (props.typeParameters) {
47
+ const typeParamNames = new Array();
48
+ for (const entry of Object.entries(props.typeParameters)) {
49
+ typeParamNames.push(useCSharpNamePolicy().getName(entry[0], "type-parameter"));
50
+ // create a symbol for each type param so its
51
+ // refkey resolves to the type param's name
52
+ new CSharpOutputSymbol(entry[0], {
53
+ scope: thisInterfaceScope,
54
+ refkeys: entry[1]
55
+ });
56
+ }
57
+ typeParams = _$createIntrinsic("group", {
58
+ get children() {
59
+ return ["<", _$createComponent(core.For, {
60
+ each: typeParamNames,
61
+ comma: true,
62
+ line: true,
63
+ children: name => name
64
+ }), ">"];
65
+ }
66
+ });
67
+ }
68
+ const modifiers = computeModifiersPrefix([getAccessModifier(props), getInterfaceModifiers(props)]);
69
+ return _$createComponent(core.Declaration, {
70
+ symbol: thisInterfaceSymbol,
71
+ get children() {
72
+ return [modifiers, "interface ", _$createComponent(Name, {}), typeParams, _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(core.Block, {
73
+ newline: true,
74
+ get children() {
75
+ return _$createComponent(core.Scope, {
76
+ value: thisInterfaceScope,
77
+ get children() {
78
+ return props.children;
79
+ }
80
+ });
81
+ }
82
+ }) : ";")];
83
+ }
84
+ });
85
+ }
@@ -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,56 @@
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
+ });
@@ -0,0 +1,16 @@
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
+ }
15
+ export declare function InterfaceMethod(props: InterfaceMethodProps): Children;
16
+ //# 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;AAE/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;CACpB;AAGD,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YAsC1D"}
@@ -0,0 +1,54 @@
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
+
9
+ /** Method modifiers. Can only be one. */
10
+
11
+ const getMethodModifier = makeModifiers(["new"]);
12
+
13
+ // properties for creating a method
14
+
15
+ // a C# interface method
16
+ export function InterfaceMethod(props) {
17
+ const name = useCSharpNamePolicy().getName(props.name, "class-method");
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 methodSymbol = new CSharpOutputSymbol(name, {
23
+ scope,
24
+ refkeys: props.refkey ?? refkey(props.name)
25
+ });
26
+
27
+ // scope for method declaration
28
+ const methodScope = new CSharpMemberScope("method-decl", {
29
+ owner: methodSymbol
30
+ });
31
+ const params = props.parameters ? _$createComponent(Parameters, {
32
+ get parameters() {
33
+ return props.parameters;
34
+ }
35
+ }) : "";
36
+ const modifiers = computeModifiersPrefix([getAccessModifier(props), getMethodModifier(props)]);
37
+ // note that scope wraps the method decl so that the params get the correct scope
38
+ return _$createComponent(MemberDeclaration, {
39
+ symbol: methodSymbol,
40
+ get children() {
41
+ return _$createComponent(Scope, {
42
+ value: methodScope,
43
+ get children() {
44
+ return [modifiers, _$memo(() => props.returns ?? "void"), " ", name, "(", params, ")", _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(Block, {
45
+ newline: true,
46
+ get children() {
47
+ return props.children;
48
+ }
49
+ }) : ";")];
50
+ }
51
+ });
52
+ }
53
+ });
54
+ }
@@ -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,110 @@
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
+ });
@@ -0,0 +1,19 @@
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
+ }
18
+ export declare function InterfaceProperty(props: InterfacePropertyProps): Children;
19
+ //# 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;AAK5B,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;CACf;AAGD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,YAsC9D"}
@@ -0,0 +1,54 @@
1
+ import { memo as _$memo, createComponent as _$createComponent } 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
+
8
+ /** Method modifiers. Can only be one. */
9
+
10
+ export const getMethodModifier = makeModifiers(["new"]);
11
+
12
+ // properties for creating a method
13
+
14
+ // a C# interface property
15
+ export function InterfaceProperty(props) {
16
+ const name = useCSharpNamePolicy().getName(props.name, "class-property");
17
+ const scope = useCSharpScope();
18
+ if (scope.kind !== "member" || scope.name !== "interface-decl") {
19
+ throw new Error("can't define an interface method outside of an interface scope");
20
+ }
21
+ const propertySymbol = new CSharpOutputSymbol(name, {
22
+ scope,
23
+ refkeys: props.refkey ?? refkey(props.name)
24
+ });
25
+
26
+ // scope for property declaration
27
+ const propertyScope = new CSharpMemberScope("property-decl", {
28
+ owner: propertySymbol
29
+ });
30
+ const modifiers = computeModifiersPrefix([getAccessModifier(props), getMethodModifier(props)]);
31
+ // note that scope wraps the method decl so that the params get the correct scope
32
+ return _$createComponent(MemberDeclaration, {
33
+ symbol: propertySymbol,
34
+ get children() {
35
+ return _$createComponent(Scope, {
36
+ value: propertyScope,
37
+ get children() {
38
+ return [modifiers, _$memo(() => props.type), " ", name, " ", _$createComponent(Block, {
39
+ newline: true,
40
+ inline: true,
41
+ get children() {
42
+ return _$createComponent(List, {
43
+ joiner: " ",
44
+ get children() {
45
+ return [_$memo(() => props.get && "get;"), _$memo(() => props.set && "set;")];
46
+ }
47
+ });
48
+ }
49
+ })];
50
+ }
51
+ });
52
+ }
53
+ });
54
+ }
@@ -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":""}