@alloy-js/csharp 0.18.0-dev.24 → 0.18.0-dev.3

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 (168) hide show
  1. package/dist/src/components/Class.d.ts +26 -0
  2. package/dist/src/components/Class.d.ts.map +1 -0
  3. package/dist/src/components/{ClassDeclaration.js → Class.js} +38 -70
  4. package/dist/src/components/ClassMethod.d.ts +5 -44
  5. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  6. package/dist/src/components/ClassMethod.js +9 -33
  7. package/dist/src/components/Enum.d.ts +15 -0
  8. package/dist/src/components/Enum.d.ts.map +1 -0
  9. package/dist/src/components/{EnumDeclaration.js → Enum.js} +5 -25
  10. package/dist/src/components/Parameters.d.ts +13 -0
  11. package/dist/src/components/Parameters.d.ts.map +1 -0
  12. package/dist/src/components/Parameters.js +34 -0
  13. package/dist/src/components/SourceFile.d.ts.map +1 -1
  14. package/dist/src/components/SourceFile.js +0 -1
  15. package/dist/src/components/index.d.ts +4 -14
  16. package/dist/src/components/index.d.ts.map +1 -1
  17. package/dist/src/components/index.js +5 -15
  18. package/dist/src/components/stc/index.d.ts +2 -2
  19. package/dist/src/components/stc/index.d.ts.map +1 -1
  20. package/dist/src/components/stc/index.js +2 -2
  21. package/dist/src/modifiers.d.ts +4 -10
  22. package/dist/src/modifiers.d.ts.map +1 -1
  23. package/dist/src/modifiers.js +32 -9
  24. package/dist/src/name-policy.d.ts +1 -1
  25. package/dist/src/name-policy.d.ts.map +1 -1
  26. package/dist/src/name-policy.js +0 -2
  27. package/dist/test/class-method.test.js +14 -37
  28. package/dist/test/class.test.d.ts +2 -0
  29. package/dist/test/class.test.d.ts.map +1 -0
  30. package/dist/test/class.test.js +298 -0
  31. package/dist/test/enum.test.js +12 -12
  32. package/dist/test/namespace.test.js +8 -8
  33. package/dist/test/projectdirectory.test.d.ts +2 -0
  34. package/dist/test/projectdirectory.test.d.ts.map +1 -0
  35. package/dist/test/{project-directory.test.js → projectdirectory.test.js} +8 -8
  36. package/dist/test/sourcefile.test.js +4 -4
  37. package/dist/test/using.test.js +9 -9
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +3 -4
  40. package/src/components/Class.tsx +149 -0
  41. package/src/components/ClassMethod.tsx +15 -74
  42. package/src/components/{EnumDeclaration.tsx → Enum.tsx} +6 -30
  43. package/src/components/Parameters.tsx +51 -0
  44. package/src/components/SourceFile.tsx +0 -1
  45. package/src/components/index.ts +4 -14
  46. package/src/components/stc/index.ts +2 -2
  47. package/src/modifiers.ts +42 -25
  48. package/src/name-policy.ts +0 -5
  49. package/temp/api.json +1298 -6463
  50. package/test/class-method.test.tsx +14 -24
  51. package/test/class.test.tsx +292 -0
  52. package/test/enum.test.tsx +11 -11
  53. package/test/namespace.test.tsx +4 -4
  54. package/test/{project-directory.test.tsx → projectdirectory.test.tsx} +4 -4
  55. package/test/sourcefile.test.tsx +2 -2
  56. package/test/using.test.tsx +9 -9
  57. package/vitest.config.ts +0 -3
  58. package/dist/src/components/ClassDeclaration.d.ts +0 -92
  59. package/dist/src/components/ClassDeclaration.d.ts.map +0 -1
  60. package/dist/src/components/EnumDeclaration.d.ts +0 -34
  61. package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
  62. package/dist/src/components/attributes/attributes.d.ts +0 -39
  63. package/dist/src/components/attributes/attributes.d.ts.map +0 -1
  64. package/dist/src/components/attributes/attributes.js +0 -62
  65. package/dist/src/components/attributes/attributes.test.d.ts +0 -2
  66. package/dist/src/components/attributes/attributes.test.d.ts.map +0 -1
  67. package/dist/src/components/attributes/attributes.test.js +0 -75
  68. package/dist/src/components/doc/comment.d.ts +0 -70
  69. package/dist/src/components/doc/comment.d.ts.map +0 -1
  70. package/dist/src/components/doc/comment.js +0 -88
  71. package/dist/src/components/doc/comment.test.d.ts +0 -2
  72. package/dist/src/components/doc/comment.test.d.ts.map +0 -1
  73. package/dist/src/components/doc/comment.test.js +0 -348
  74. package/dist/src/components/doc/from-markdown.d.ts +0 -6
  75. package/dist/src/components/doc/from-markdown.d.ts.map +0 -1
  76. package/dist/src/components/doc/from-markdown.js +0 -58
  77. package/dist/src/components/doc/from-markdown.test.d.ts +0 -2
  78. package/dist/src/components/doc/from-markdown.test.d.ts.map +0 -1
  79. package/dist/src/components/doc/from-markdown.test.js +0 -83
  80. package/dist/src/components/interface/declaration.d.ts +0 -65
  81. package/dist/src/components/interface/declaration.d.ts.map +0 -1
  82. package/dist/src/components/interface/declaration.js +0 -83
  83. package/dist/src/components/interface/declaration.test.d.ts +0 -2
  84. package/dist/src/components/interface/declaration.test.d.ts.map +0 -1
  85. package/dist/src/components/interface/declaration.test.js +0 -171
  86. package/dist/src/components/interface/method.d.ts +0 -50
  87. package/dist/src/components/interface/method.d.ts.map +0 -1
  88. package/dist/src/components/interface/method.js +0 -74
  89. package/dist/src/components/interface/method.test.d.ts +0 -2
  90. package/dist/src/components/interface/method.test.d.ts.map +0 -1
  91. package/dist/src/components/interface/method.test.js +0 -300
  92. package/dist/src/components/interface/property.d.ts +0 -56
  93. package/dist/src/components/interface/property.d.ts.map +0 -1
  94. package/dist/src/components/interface/property.js +0 -73
  95. package/dist/src/components/interface/property.test.d.ts +0 -2
  96. package/dist/src/components/interface/property.test.d.ts.map +0 -1
  97. package/dist/src/components/interface/property.test.js +0 -189
  98. package/dist/src/components/parameters/parameters.d.ts +0 -19
  99. package/dist/src/components/parameters/parameters.d.ts.map +0 -1
  100. package/dist/src/components/parameters/parameters.js +0 -43
  101. package/dist/src/components/property/property.d.ts +0 -80
  102. package/dist/src/components/property/property.d.ts.map +0 -1
  103. package/dist/src/components/property/property.js +0 -76
  104. package/dist/src/components/property/property.test.d.ts +0 -2
  105. package/dist/src/components/property/property.test.d.ts.map +0 -1
  106. package/dist/src/components/property/property.test.js +0 -242
  107. package/dist/src/components/record/declaration.d.ts +0 -35
  108. package/dist/src/components/record/declaration.d.ts.map +0 -1
  109. package/dist/src/components/record/declaration.js +0 -90
  110. package/dist/src/components/record/declaration.test.d.ts +0 -2
  111. package/dist/src/components/record/declaration.test.d.ts.map +0 -1
  112. package/dist/src/components/record/declaration.test.js +0 -94
  113. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +0 -8
  114. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +0 -1
  115. package/dist/src/components/type-parameters/type-parameter-constraints.js +0 -44
  116. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +0 -2
  117. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +0 -1
  118. package/dist/src/components/type-parameters/type-parameter-constraints.test.js +0 -67
  119. package/dist/src/components/type-parameters/type-parameter.d.ts +0 -20
  120. package/dist/src/components/type-parameters/type-parameter.d.ts.map +0 -1
  121. package/dist/src/components/type-parameters/type-parameter.js +0 -22
  122. package/dist/src/components/type-parameters/type-parameters.d.ts +0 -17
  123. package/dist/src/components/type-parameters/type-parameters.d.ts.map +0 -1
  124. package/dist/src/components/type-parameters/type-parameters.js +0 -54
  125. package/dist/src/components/type-parameters/type-parameters.test.d.ts +0 -2
  126. package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +0 -1
  127. package/dist/src/components/type-parameters/type-parameters.test.js +0 -48
  128. package/dist/src/components/var/declaration.d.ts +0 -35
  129. package/dist/src/components/var/declaration.d.ts.map +0 -1
  130. package/dist/src/components/var/declaration.js +0 -40
  131. package/dist/src/components/var/declaration.test.d.ts +0 -2
  132. package/dist/src/components/var/declaration.test.d.ts.map +0 -1
  133. package/dist/src/components/var/declaration.test.js +0 -73
  134. package/dist/test/class-declaration.test.d.ts +0 -2
  135. package/dist/test/class-declaration.test.d.ts.map +0 -1
  136. package/dist/test/class-declaration.test.js +0 -481
  137. package/dist/test/project-directory.test.d.ts +0 -2
  138. package/dist/test/project-directory.test.d.ts.map +0 -1
  139. package/dist/test/vitest.setup.d.ts +0 -2
  140. package/dist/test/vitest.setup.d.ts.map +0 -1
  141. package/dist/test/vitest.setup.js +0 -1
  142. package/src/components/ClassDeclaration.tsx +0 -233
  143. package/src/components/attributes/attributes.test.tsx +0 -61
  144. package/src/components/attributes/attributes.tsx +0 -100
  145. package/src/components/doc/comment.test.tsx +0 -337
  146. package/src/components/doc/comment.tsx +0 -152
  147. package/src/components/doc/from-markdown.test.tsx +0 -103
  148. package/src/components/doc/from-markdown.tsx +0 -58
  149. package/src/components/interface/declaration.test.tsx +0 -158
  150. package/src/components/interface/declaration.tsx +0 -125
  151. package/src/components/interface/method.test.tsx +0 -293
  152. package/src/components/interface/method.tsx +0 -122
  153. package/src/components/interface/property.test.tsx +0 -165
  154. package/src/components/interface/property.tsx +0 -127
  155. package/src/components/parameters/parameters.tsx +0 -74
  156. package/src/components/property/property.test.tsx +0 -209
  157. package/src/components/property/property.tsx +0 -172
  158. package/src/components/record/declaration.test.tsx +0 -73
  159. package/src/components/record/declaration.tsx +0 -109
  160. package/src/components/type-parameters/type-parameter-constraints.test.tsx +0 -93
  161. package/src/components/type-parameters/type-parameter-constraints.tsx +0 -46
  162. package/src/components/type-parameters/type-parameter.tsx +0 -35
  163. package/src/components/type-parameters/type-parameters.test.tsx +0 -46
  164. package/src/components/type-parameters/type-parameters.tsx +0 -63
  165. package/src/components/var/declaration.test.tsx +0 -59
  166. package/src/components/var/declaration.tsx +0 -47
  167. package/test/class-declaration.test.tsx +0 -430
  168. package/test/vitest.setup.ts +0 -1
@@ -1,73 +0,0 @@
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 { AttributeList } from "../attributes/attributes.js";
8
- import { DocWhen } from "../doc/comment.js";
9
-
10
- /** Method modifiers. Can only be one. */
11
-
12
- const getModifiers = makeModifiers(["new"]);
13
-
14
- // properties for creating a method
15
-
16
- /**
17
- * Render a C# interface property.
18
- *
19
- * @example `<InterfaceProperty public name="My" get set />`
20
- *
21
- * ```cs
22
- * public int My { get; set; };
23
- * ```
24
- */
25
- export function InterfaceProperty(props) {
26
- const name = useCSharpNamePolicy().getName(props.name, "class-property");
27
- const scope = useCSharpScope();
28
- if (scope.kind !== "member" || scope.name !== "interface-decl") {
29
- throw new Error("can't define an interface method outside of an interface scope");
30
- }
31
- const propertySymbol = new CSharpOutputSymbol(name, {
32
- scope,
33
- refkeys: props.refkey ?? refkey(props.name)
34
- });
35
-
36
- // scope for property declaration
37
- const propertyScope = new CSharpMemberScope("property-decl", {
38
- owner: propertySymbol
39
- });
40
- const modifiers = computeModifiersPrefix([getAccessModifier(props), getModifiers(props)]);
41
- // note that scope wraps the method decl so that the params get the correct scope
42
- return _$createComponent(MemberDeclaration, {
43
- symbol: propertySymbol,
44
- get children() {
45
- return _$createComponent(Scope, {
46
- value: propertyScope,
47
- get children() {
48
- return [_$createComponent(DocWhen, {
49
- get doc() {
50
- return props.doc;
51
- }
52
- }), _$createComponent(AttributeList, {
53
- get attributes() {
54
- return props.attributes;
55
- },
56
- endline: true
57
- }), modifiers, _$memo(() => props.type), _$memo(() => props.nullable && "?"), " ", name, " ", _$createComponent(Block, {
58
- newline: true,
59
- inline: true,
60
- get children() {
61
- return _$createComponent(List, {
62
- joiner: " ",
63
- get children() {
64
- return [_$memo(() => props.get && "get;"), _$memo(() => props.set && "set;")];
65
- }
66
- });
67
- }
68
- })];
69
- }
70
- });
71
- }
72
- });
73
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=property.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"property.test.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/property.test.tsx"],"names":[],"mappings":""}
@@ -1,189 +0,0 @@
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 { Attribute } from "../attributes/attributes.js";
5
- import { InterfaceDeclaration } from "./declaration.js";
6
- import { InterfaceProperty } from "./property.js";
7
- const Wrapper = props => _$createComponent(TestNamespace, {
8
- get children() {
9
- return _$createComponent(InterfaceDeclaration, {
10
- "public": true,
11
- name: "TestInterface",
12
- get children() {
13
- return props.children;
14
- }
15
- });
16
- }
17
- });
18
- describe("modifiers", () => {
19
- describe("access modifiers", () => {
20
- it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
21
- expect(_$createComponent(Wrapper, {
22
- get children() {
23
- return _$createComponent(InterfaceProperty, _$mergeProps({
24
- [accessModifier]: true
25
- }, {
26
- name: "TestProp",
27
- type: "string",
28
- get: true
29
- }));
30
- }
31
- })).toRenderTo(`
32
- public interface TestInterface
33
- {
34
- ${accessModifier} string TestProp { get; }
35
- }
36
- `);
37
- });
38
- });
39
- describe("method modifiers", () => {
40
- it.each(["new"])("%s", methodModifier => {
41
- expect(_$createComponent(Wrapper, {
42
- get children() {
43
- return _$createComponent(InterfaceProperty, _$mergeProps({
44
- [methodModifier]: true
45
- }, {
46
- name: "TestProp",
47
- type: "string",
48
- get: true
49
- }));
50
- }
51
- })).toRenderTo(`
52
- public interface TestInterface
53
- {
54
- ${methodModifier} string TestProp { get; }
55
- }
56
- `);
57
- });
58
- });
59
- it("combine modifiers", () => {
60
- expect(_$createComponent(Wrapper, {
61
- get children() {
62
- return _$createComponent(InterfaceProperty, {
63
- "public": true,
64
- "new": true,
65
- name: "TestProp",
66
- type: "string",
67
- get: true
68
- });
69
- }
70
- })).toRenderTo(`
71
- public interface TestInterface
72
- {
73
- public new string TestProp { get; }
74
- }
75
- `);
76
- });
77
- });
78
- it("applies PascalCase naming policy", () => {
79
- expect(_$createComponent(Wrapper, {
80
- get children() {
81
- return _$createComponent(InterfaceProperty, {
82
- name: "test_prop",
83
- type: "string",
84
- get: true
85
- });
86
- }
87
- })).toRenderTo(`
88
- public interface TestInterface
89
- {
90
- string TestProp { get; }
91
- }
92
- `);
93
- });
94
- it("has getter only", () => {
95
- expect(_$createComponent(Wrapper, {
96
- get children() {
97
- return _$createComponent(InterfaceProperty, {
98
- name: "TestProp",
99
- type: "string",
100
- get: true
101
- });
102
- }
103
- })).toRenderTo(`
104
- public interface TestInterface
105
- {
106
- string TestProp { get; }
107
- }
108
- `);
109
- });
110
- it("has setter only", () => {
111
- expect(_$createComponent(Wrapper, {
112
- get children() {
113
- return _$createComponent(InterfaceProperty, {
114
- name: "TestProp",
115
- type: "string",
116
- set: true
117
- });
118
- }
119
- })).toRenderTo(`
120
- public interface TestInterface
121
- {
122
- string TestProp { set; }
123
- }
124
- `);
125
- });
126
- it("has getter and setter", () => {
127
- expect(_$createComponent(Wrapper, {
128
- get children() {
129
- return _$createComponent(InterfaceProperty, {
130
- name: "TestProp",
131
- type: "string",
132
- get: true,
133
- set: true
134
- });
135
- }
136
- })).toRenderTo(`
137
- public interface TestInterface
138
- {
139
- string TestProp { get; set; }
140
- }
141
- `);
142
- });
143
- it("specify doc comment", () => {
144
- expect(_$createComponent(TestNamespace, {
145
- get children() {
146
- return _$createComponent(InterfaceDeclaration, {
147
- name: "Test",
148
- get children() {
149
- return _$createComponent(InterfaceProperty, {
150
- name: "Method",
151
- type: "string",
152
- get: true,
153
- set: true,
154
- doc: "This is a test"
155
- });
156
- }
157
- });
158
- }
159
- })).toRenderTo(`
160
- interface Test
161
- {
162
- /// This is a test
163
- string Method { get; set; }
164
- }
165
- `);
166
- });
167
- it("specify attributes", () => {
168
- expect(_$createComponent(Wrapper, {
169
- get children() {
170
- return _$createComponent(InterfaceProperty, {
171
- name: "Test",
172
- type: "int",
173
- get attributes() {
174
- return [_$createComponent(Attribute, {
175
- name: "Test"
176
- })];
177
- },
178
- get: true,
179
- set: true
180
- });
181
- }
182
- })).toRenderTo(`
183
- public interface TestInterface
184
- {
185
- [Test]
186
- int Test { get; set; }
187
- }
188
- `);
189
- });
@@ -1,19 +0,0 @@
1
- import { Children, OutputSymbol, Refkey } from "@alloy-js/core";
2
- export interface ParameterProps {
3
- name: string;
4
- type: Children;
5
- /** If the parmaeter is optional(without default value) */
6
- optional?: boolean;
7
- /** Default value for the parameter */
8
- default?: Children;
9
- refkey?: Refkey;
10
- symbol?: OutputSymbol;
11
- }
12
- /** Define a parameter to be used in class or interface method. */
13
- export declare function Parameter(props: ParameterProps): Children;
14
- export interface ParametersProps {
15
- parameters: ParameterProps[] | undefined;
16
- }
17
- /** Render a collection of parameters */
18
- export declare function Parameters(props: ParametersProps): Children;
19
- //# sourceMappingURL=parameters.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parameters.d.ts","sourceRoot":"","sources":["../../../../src/components/parameters/parameters.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAKR,YAAY,EAEZ,MAAM,EACP,MAAM,gBAAgB,CAAC;AAMxB,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sCAAsC;IACtC,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,YAwB9C;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;CAC1C;AAED,wCAAwC;AACxC,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,YAehD"}
@@ -1,43 +0,0 @@
1
- import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
- import { code, Declaration, For, Indent, refkey } from "@alloy-js/core";
3
- import { useCSharpNamePolicy } from "../../name-policy.js";
4
- import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
5
- import { useCSharpScope } from "../../symbols/scopes.js";
6
- import { Name } from "../Name.js";
7
- /** Define a parameter to be used in class or interface method. */
8
- export function Parameter(props) {
9
- const name = useCSharpNamePolicy().getName(props.name, "parameter");
10
- const scope = useCSharpScope();
11
- if (scope.kind !== "member" || scope.name !== "constructor-decl" && scope.name !== "method-decl") {
12
- throw new Error("can't define a parameter outside of a constructor-decl or method-decl scope");
13
- }
14
- const memberSymbol = new CSharpOutputSymbol(name, {
15
- scope,
16
- refkeys: props.refkey ?? refkey(props.name)
17
- });
18
- return _$createComponent(Declaration, {
19
- symbol: memberSymbol,
20
- get children() {
21
- return [_$memo(() => props.type), _$memo(() => props.optional ? "?" : ""), " ", _$createComponent(Name, {}), _$memo(() => props.default ? code` = ${props.default}` : "")];
22
- }
23
- });
24
- }
25
- /** Render a collection of parameters */
26
- export function Parameters(props) {
27
- return _$createIntrinsic("group", {
28
- get children() {
29
- return ["(", _$memo(() => _$memo(() => !!props.parameters)() && _$createComponent(Indent, {
30
- softline: true,
31
- get children() {
32
- return _$createComponent(For, {
33
- get each() {
34
- return props.parameters;
35
- },
36
- joiner: ", ",
37
- children: param => _$createComponent(Parameter, param)
38
- });
39
- }
40
- })), _$createIntrinsic("softline", {}), ")"];
41
- }
42
- });
43
- }
@@ -1,80 +0,0 @@
1
- import { Children, Refkey } from "@alloy-js/core";
2
- import { AccessModifiers } from "../../modifiers.js";
3
- import { AttributesProp } from "../attributes/attributes.jsx";
4
- /** Property modifiers. */
5
- export interface PropertyModifiers {
6
- readonly new?: boolean;
7
- readonly static?: boolean;
8
- readonly virtual?: boolean;
9
- readonly sealed?: boolean;
10
- readonly override?: boolean;
11
- readonly abstract?: boolean;
12
- readonly extern?: boolean;
13
- readonly readonly?: boolean;
14
- /**
15
- * Set required modifier on property
16
- * https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/required
17
- */
18
- readonly required?: boolean;
19
- }
20
- /** Properties for {@link Property} component */
21
- export interface PropertyProps extends AccessModifiers, PropertyModifiers {
22
- name: string;
23
- refkey?: Refkey;
24
- /** Property type */
25
- type: Children;
26
- /** If property should have a getter */
27
- get?: boolean;
28
- /** If property should have a setter */
29
- set?: boolean;
30
- /** If property should only be set on the type creation */
31
- init?: boolean;
32
- /** Doc comment */
33
- doc?: Children;
34
- /**
35
- * Property initializer
36
- * @example `<ClassProperty name="My" get set nullable />`
37
- *
38
- * ```cs
39
- * int? My { get; set; };
40
- * ```
41
- */
42
- nullable?: boolean;
43
- /**
44
- * Property initializer
45
- * @example `<ClassProperty name="My" get set init={42} />`
46
- *
47
- * ```cs
48
- * int My { get; set; } = 42;
49
- * ```
50
- */
51
- initializer?: Children;
52
- /**
53
- * Define attributes to attach
54
- * @example
55
- * ```tsx
56
- * <Property name="MyProp" attributes={[
57
- * <Attribute name="Test" />
58
- * <Attribute name="Test2" args={["arg1", "arg2"]} />
59
- * ]} />
60
- * ```
61
- * This will produce:
62
- * ```csharp
63
- * [Test]
64
- * [Test2("arg1", "arg2")]
65
- * int MyProp { get; set; }
66
- * ```
67
- */
68
- attributes?: AttributesProp;
69
- }
70
- /**
71
- * Render a C# class property.
72
- *
73
- * @example `<ClassProperty public name="My" get set />`
74
- *
75
- * ```cs
76
- * public int My { get; set; };
77
- * ```
78
- */
79
- export declare function Property(props: PropertyProps): Children;
80
- //# sourceMappingURL=property.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../src/components/property/property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAKR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG7E,0BAA0B;AAC1B,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAcD,gDAAgD;AAChD,MAAM,WAAW,aAAc,SAAQ,eAAe,EAAE,iBAAiB;IACvE,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,0DAA0D;IAC1D,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;IAEf;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,QAAQ,CAAC;IAEvB;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,YAoD5C"}
@@ -1,76 +0,0 @@
1
- import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
- import { Block, code, 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 { AttributeList } from "../attributes/attributes.js";
8
- import { DocWhen } from "../doc/comment.js";
9
-
10
- /** Property modifiers. */
11
-
12
- const getModifiers = makeModifiers(["new", "static", "virtual", "sealed", "override", "abstract", "extern", "readonly", "required"]);
13
-
14
- /** Properties for {@link Property} component */
15
-
16
- /**
17
- * Render a C# class property.
18
- *
19
- * @example `<ClassProperty public name="My" get set />`
20
- *
21
- * ```cs
22
- * public int My { get; set; };
23
- * ```
24
- */
25
- export function Property(props) {
26
- const name = useCSharpNamePolicy().getName(props.name, "class-property");
27
- const scope = useCSharpScope();
28
- if (scope.kind !== "member" || scope.name !== "class-decl" && scope.name !== "record-decl") {
29
- throw new Error("can't define an interface method outside of an interface scope");
30
- }
31
- const propertySymbol = new CSharpOutputSymbol(name, {
32
- scope,
33
- refkeys: props.refkey ?? refkey(props.name)
34
- });
35
-
36
- // scope for property declaration
37
- const propertyScope = new CSharpMemberScope("property-decl", {
38
- owner: propertySymbol
39
- });
40
- const modifiers = computeModifiersPrefix([getAccessModifier(props), getModifiers(props)]);
41
- if (props.init && props.set) {
42
- throw new Error(`Cannot use 'init' and 'set' together on property '${name}'`);
43
- }
44
- // note that scope wraps the method decl so that the params get the correct scope
45
- return _$createComponent(MemberDeclaration, {
46
- symbol: propertySymbol,
47
- get children() {
48
- return _$createComponent(Scope, {
49
- value: propertyScope,
50
- get children() {
51
- return [_$createComponent(DocWhen, {
52
- get doc() {
53
- return props.doc;
54
- }
55
- }), _$createComponent(AttributeList, {
56
- get attributes() {
57
- return props.attributes;
58
- },
59
- endline: true
60
- }), modifiers, _$memo(() => props.type), _$memo(() => props.nullable && "?"), " ", name, " ", _$createComponent(Block, {
61
- newline: true,
62
- inline: true,
63
- get children() {
64
- return _$createComponent(List, {
65
- joiner: " ",
66
- get children() {
67
- return [_$memo(() => props.get && "get;"), _$memo(() => props.set && "set;"), _$memo(() => props.init && "init;")];
68
- }
69
- });
70
- }
71
- }), _$memo(() => props.initializer && code` = ${props.initializer};`)];
72
- }
73
- });
74
- }
75
- });
76
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=property.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"property.test.d.ts","sourceRoot":"","sources":["../../../../src/components/property/property.test.tsx"],"names":[],"mappings":""}