@alloy-js/csharp 0.18.0-dev.5 → 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 (54) hide show
  1. package/dist/src/components/ClassDeclaration.d.ts +8 -2
  2. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  3. package/dist/src/components/ClassDeclaration.js +3 -2
  4. package/dist/src/components/ClassMethod.d.ts +9 -2
  5. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  6. package/dist/src/components/ClassMethod.js +5 -1
  7. package/dist/src/components/EnumDeclaration.d.ts +2 -2
  8. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  9. package/dist/src/components/index.d.ts +3 -1
  10. package/dist/src/components/index.d.ts.map +1 -1
  11. package/dist/src/components/index.js +3 -1
  12. package/dist/src/components/interface/declaration.d.ts +32 -0
  13. package/dist/src/components/interface/declaration.d.ts.map +1 -0
  14. package/dist/src/components/interface/declaration.js +85 -0
  15. package/dist/src/components/interface/declaration.test.d.ts +2 -0
  16. package/dist/src/components/interface/declaration.test.d.ts.map +1 -0
  17. package/dist/src/components/interface/declaration.test.js +56 -0
  18. package/dist/src/components/interface/method.d.ts +16 -0
  19. package/dist/src/components/interface/method.d.ts.map +1 -0
  20. package/dist/src/components/interface/method.js +54 -0
  21. package/dist/src/components/interface/method.test.d.ts +2 -0
  22. package/dist/src/components/interface/method.test.d.ts.map +1 -0
  23. package/dist/src/components/interface/method.test.js +110 -0
  24. package/dist/src/components/interface/property.d.ts +19 -0
  25. package/dist/src/components/interface/property.d.ts.map +1 -0
  26. package/dist/src/components/interface/property.js +54 -0
  27. package/dist/src/components/interface/property.test.d.ts +2 -0
  28. package/dist/src/components/interface/property.test.d.ts.map +1 -0
  29. package/dist/src/components/interface/property.test.js +141 -0
  30. package/dist/src/components/stc/index.d.ts +2 -2
  31. package/dist/src/components/stc/index.d.ts.map +1 -1
  32. package/dist/src/modifiers.d.ts +2 -9
  33. package/dist/src/modifiers.d.ts.map +1 -1
  34. package/dist/src/modifiers.js +6 -9
  35. package/dist/src/name-policy.d.ts +1 -1
  36. package/dist/src/name-policy.d.ts.map +1 -1
  37. package/dist/src/name-policy.js +1 -0
  38. package/dist/test/class.test.js +52 -10
  39. package/dist/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +2 -2
  41. package/src/components/ClassDeclaration.tsx +23 -4
  42. package/src/components/ClassMethod.tsx +19 -3
  43. package/src/components/EnumDeclaration.tsx +2 -2
  44. package/src/components/index.ts +3 -1
  45. package/src/components/interface/declaration.test.tsx +45 -0
  46. package/src/components/interface/declaration.tsx +104 -0
  47. package/src/components/interface/method.test.tsx +104 -0
  48. package/src/components/interface/method.tsx +77 -0
  49. package/src/components/interface/property.test.tsx +122 -0
  50. package/src/components/interface/property.tsx +85 -0
  51. package/src/modifiers.ts +16 -30
  52. package/src/name-policy.ts +2 -0
  53. package/temp/api.json +977 -277
  54. package/test/class.test.tsx +40 -10
@@ -0,0 +1,141 @@
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
+ });
@@ -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 ClassDeclaration: 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 EnumDeclaration: 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,gBAAgB,oCAAkC,CAAC;AAChE,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,eAAe,mCAAiC,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"}
@@ -6,16 +6,9 @@ export interface AccessModifiers {
6
6
  readonly internal?: boolean;
7
7
  readonly file?: boolean;
8
8
  }
9
- export declare function 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 function getMethodModifier(data: MethodModifiers): string;
9
+ export declare const getAccessModifier: (data: AccessModifiers) => 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;
13
+ export declare function makeModifiers<T>(obj: Array<keyof T>): (data: T) => string;
21
14
  //# sourceMappingURL=modifiers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"modifiers.d.ts","sourceRoot":"","sources":["../../src/modif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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"}
@@ -3,15 +3,7 @@
3
3
 
4
4
  /** Access modifiers. */
5
5
 
6
- export function getAccessModifier(data) {
7
- return [data.public && "public", data.protected && "protected", data.private && "private", data.internal && "internal", data.file && "file"].filter(x => x).join(" ");
8
- }
9
-
10
- /** Method modifiers. Can only be one. */
11
-
12
- export function getMethodModifier(data) {
13
- return [data.abstract && "abstract", data.sealed && "sealed", data.static && "static", data.virtual && "virtual"].filter(x => x).join(" ");
14
- }
6
+ export const getAccessModifier = makeModifiers(["public", "protected", "private", "internal", "file"]);
15
7
  export function getAsyncModifier(async) {
16
8
  return async ? "async" : "";
17
9
  }
@@ -20,4 +12,9 @@ export function getAsyncModifier(async) {
20
12
  export function computeModifiersPrefix(modifiers) {
21
13
  const resolved = modifiers.filter(x => x);
22
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
+ };
23
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
@@ -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,MAAM,GACN,aAAa,GACb,UAAU,GACV,WAAW,GACX,sBAAsB,GACtB,qBAAqB,GACrB,cAAc,GACd,WAAW,GACX,gBAAgB,CAAC;AAGrB,wBAAgB,sBAAsB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAiBxE;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,MAAM,GACN,aAAa,GACb,UAAU,GACV,WAAW,GACX,sBAAsB,GACtB,qBAAqB,GACrB,cAAc,GACd,gBAAgB,GAChB,WAAW,GACX,gBAAgB,CAAC;AAGrB,wBAAgB,sBAAsB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAkBxE;AAGD,wBAAgB,mBAAmB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAErE"}
@@ -14,6 +14,7 @@ export function createCSharpNamePolicy() {
14
14
  case "class-member-public":
15
15
  case "class-method":
16
16
  case "type-parameter":
17
+ case "class-property":
17
18
  return changecase.pascalCase(name);
18
19
  case "constant":
19
20
  return changecase.constantCase(name);
@@ -1,21 +1,63 @@
1
- import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
1
+ import { createComponent as _$createComponent, mergeProps as _$mergeProps, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
2
  import * as core from "@alloy-js/core";
3
3
  import * as coretest from "@alloy-js/core/testing";
4
- import { expect, it } from "vitest";
4
+ import { describe, expect, it } from "vitest";
5
5
  import * as csharp from "../src/index.js";
6
+ import { ClassDeclaration } from "../src/index.js";
6
7
  import * as utils from "./utils.js";
7
8
  it("declares class with no members", () => {
8
- const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
9
- "public": true,
10
- name: "TestClass"
11
- }));
12
- expect(res).toBe(coretest.d`
13
- namespace TestCode
14
- {
15
- public class TestClass;
9
+ expect(_$createComponent(utils.TestNamespace, {
10
+ get children() {
11
+ return _$createComponent(ClassDeclaration, {
12
+ name: "TestClass"
13
+ });
16
14
  }
15
+ })).toRenderTo(`
16
+ class TestClass;
17
17
  `);
18
18
  });
19
+ describe("modifiers", () => {
20
+ it.each(["public", "private"])("%s", mod => {
21
+ expect(_$createComponent(utils.TestNamespace, {
22
+ get children() {
23
+ return _$createComponent(ClassDeclaration, _$mergeProps({
24
+ [mod]: true
25
+ }, {
26
+ name: "TestClass"
27
+ }));
28
+ }
29
+ })).toRenderTo(`
30
+ ${mod} class TestClass;
31
+ `);
32
+ });
33
+ it.each(["partial", "abstract", "static", "sealed"])("%s", mod => {
34
+ expect(_$createComponent(utils.TestNamespace, {
35
+ get children() {
36
+ return _$createComponent(ClassDeclaration, _$mergeProps({
37
+ [mod]: true
38
+ }, {
39
+ name: "TestClass"
40
+ }));
41
+ }
42
+ })).toRenderTo(`
43
+ ${mod} class TestClass;
44
+ `);
45
+ });
46
+ it("combines modifiers", () => {
47
+ expect(_$createComponent(utils.TestNamespace, {
48
+ get children() {
49
+ return _$createComponent(ClassDeclaration, {
50
+ "public": true,
51
+ abstract: true,
52
+ partial: true,
53
+ name: "TestClass"
54
+ });
55
+ }
56
+ })).toRenderTo(`
57
+ public abstract partial class TestClass;
58
+ `);
59
+ });
60
+ });
19
61
  it("declares class with some members", () => {
20
62
  const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
21
63
  "public": true,