@alloy-js/csharp 0.18.0-dev.14 → 0.18.0-dev.16
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.
- package/dist/src/components/index.d.ts +2 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +2 -1
- package/dist/src/components/{class → property}/property.d.ts +8 -6
- package/dist/src/components/property/property.d.ts.map +1 -0
- package/dist/src/components/{class → property}/property.js +8 -5
- package/dist/src/components/property/property.test.d.ts.map +1 -0
- package/dist/src/components/{class → property}/property.test.js +29 -12
- package/dist/src/components/record/declaration.d.ts +1 -0
- package/dist/src/components/record/declaration.d.ts.map +1 -1
- package/dist/src/components/record/declaration.js +1 -1
- package/dist/src/components/record/declaration.test.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/index.ts +2 -1
- package/src/components/{class → property}/property.test.tsx +24 -17
- package/src/components/{class → property}/property.tsx +18 -10
- package/src/components/record/declaration.test.tsx +2 -2
- package/src/components/record/declaration.tsx +1 -1
- package/temp/api.json +2445 -2131
- package/dist/src/components/class/property.d.ts.map +0 -1
- package/dist/src/components/class/property.test.d.ts.map +0 -1
- /package/dist/src/components/{class → property}/property.test.d.ts +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from "./class/property.js";
|
|
2
1
|
export * from "./ClassDeclaration.jsx";
|
|
3
2
|
export * from "./ClassMethod.jsx";
|
|
4
3
|
export * from "./Declaration.js";
|
|
@@ -12,6 +11,8 @@ export * from "./Name.js";
|
|
|
12
11
|
export * from "./Namespace.js";
|
|
13
12
|
export * from "./Parameters.js";
|
|
14
13
|
export * from "./ProjectDirectory.js";
|
|
14
|
+
export * from "./property/property.jsx";
|
|
15
|
+
export * from "./record/declaration.js";
|
|
15
16
|
export * from "./Reference.js";
|
|
16
17
|
export * from "./SourceFile.js";
|
|
17
18
|
export * from "./UsingDirective.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,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,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from "./class/property.js";
|
|
2
1
|
export * from "./ClassDeclaration.js";
|
|
3
2
|
export * from "./ClassMethod.js";
|
|
4
3
|
export * from "./Declaration.js";
|
|
@@ -12,6 +11,8 @@ export * from "./Name.js";
|
|
|
12
11
|
export * from "./Namespace.js";
|
|
13
12
|
export * from "./Parameters.js";
|
|
14
13
|
export * from "./ProjectDirectory.js";
|
|
14
|
+
export * from "./property/property.js";
|
|
15
|
+
export * from "./record/declaration.js";
|
|
15
16
|
export * from "./Reference.js";
|
|
16
17
|
export * from "./SourceFile.js";
|
|
17
18
|
export * from "./UsingDirective.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Children, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
-
/**
|
|
4
|
-
export interface
|
|
3
|
+
/** Property modifiers. */
|
|
4
|
+
export interface PropertyModifiers {
|
|
5
5
|
readonly new?: boolean;
|
|
6
6
|
readonly static?: boolean;
|
|
7
7
|
readonly virtual?: boolean;
|
|
@@ -11,8 +11,8 @@ export interface ClassPropertyModifiers {
|
|
|
11
11
|
readonly extern?: boolean;
|
|
12
12
|
readonly readonly?: boolean;
|
|
13
13
|
}
|
|
14
|
-
/** Properties for {@link
|
|
15
|
-
export interface
|
|
14
|
+
/** Properties for {@link Property} component */
|
|
15
|
+
export interface PropertyProps extends AccessModifiers, PropertyModifiers {
|
|
16
16
|
name: string;
|
|
17
17
|
refkey?: Refkey;
|
|
18
18
|
/** Property type */
|
|
@@ -21,6 +21,8 @@ export interface ClassPropertyProps extends AccessModifiers, ClassPropertyModifi
|
|
|
21
21
|
get?: boolean;
|
|
22
22
|
/** If property should have a setter */
|
|
23
23
|
set?: boolean;
|
|
24
|
+
/** If property should only be set on the type creation */
|
|
25
|
+
init?: boolean;
|
|
24
26
|
/** Doc comment */
|
|
25
27
|
doc?: Children;
|
|
26
28
|
/**
|
|
@@ -40,7 +42,7 @@ export interface ClassPropertyProps extends AccessModifiers, ClassPropertyModifi
|
|
|
40
42
|
* int My { get; set; } = 42;
|
|
41
43
|
* ```
|
|
42
44
|
*/
|
|
43
|
-
|
|
45
|
+
initializer?: Children;
|
|
44
46
|
}
|
|
45
47
|
/**
|
|
46
48
|
* Render a C# class property.
|
|
@@ -51,5 +53,5 @@ export interface ClassPropertyProps extends AccessModifiers, ClassPropertyModifi
|
|
|
51
53
|
* public int My { get; set; };
|
|
52
54
|
* ```
|
|
53
55
|
*/
|
|
54
|
-
export declare function
|
|
56
|
+
export declare function Property(props: PropertyProps): Children;
|
|
55
57
|
//# sourceMappingURL=property.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,CA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../doc/comment.js";
|
|
8
8
|
|
|
9
|
-
/**
|
|
9
|
+
/** Property modifiers. */
|
|
10
10
|
|
|
11
11
|
const getModifiers = makeModifiers(["new", "static", "virtual", "sealed", "override", "abstract", "extern", "readonly"]);
|
|
12
12
|
|
|
13
|
-
/** Properties for {@link
|
|
13
|
+
/** Properties for {@link Property} component */
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Render a C# class property.
|
|
@@ -21,7 +21,7 @@ const getModifiers = makeModifiers(["new", "static", "virtual", "sealed", "overr
|
|
|
21
21
|
* public int My { get; set; };
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
export function
|
|
24
|
+
export function Property(props) {
|
|
25
25
|
const name = useCSharpNamePolicy().getName(props.name, "class-property");
|
|
26
26
|
const scope = useCSharpScope();
|
|
27
27
|
if (scope.kind !== "member" || scope.name !== "class-decl" && scope.name !== "record-decl") {
|
|
@@ -37,6 +37,9 @@ export function ClassProperty(props) {
|
|
|
37
37
|
owner: propertySymbol
|
|
38
38
|
});
|
|
39
39
|
const modifiers = computeModifiersPrefix([getAccessModifier(props), getModifiers(props)]);
|
|
40
|
+
if (props.init && props.set) {
|
|
41
|
+
throw new Error(`Cannot use 'init' and 'set' together on property '${name}'`);
|
|
42
|
+
}
|
|
40
43
|
// note that scope wraps the method decl so that the params get the correct scope
|
|
41
44
|
return _$createComponent(MemberDeclaration, {
|
|
42
45
|
symbol: propertySymbol,
|
|
@@ -55,11 +58,11 @@ export function ClassProperty(props) {
|
|
|
55
58
|
return _$createComponent(List, {
|
|
56
59
|
joiner: " ",
|
|
57
60
|
get children() {
|
|
58
|
-
return [_$memo(() => props.get && "get;"), _$memo(() => props.set && "set;")];
|
|
61
|
+
return [_$memo(() => props.get && "get;"), _$memo(() => props.set && "set;"), _$memo(() => props.init && "init;")];
|
|
59
62
|
}
|
|
60
63
|
});
|
|
61
64
|
}
|
|
62
|
-
}), _$memo(() => props.
|
|
65
|
+
}), _$memo(() => props.initializer && code` = ${props.initializer};`)];
|
|
63
66
|
}
|
|
64
67
|
});
|
|
65
68
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property.test.d.ts","sourceRoot":"","sources":["../../../../src/components/property/property.test.tsx"],"names":[],"mappings":""}
|
|
@@ -2,7 +2,7 @@ import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$m
|
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
import { TestNamespace } from "../../../test/utils.js";
|
|
4
4
|
import { ClassDeclaration } from "../ClassDeclaration.js";
|
|
5
|
-
import {
|
|
5
|
+
import { Property } from "./property.js";
|
|
6
6
|
const Wrapper = props => _$createComponent(TestNamespace, {
|
|
7
7
|
get children() {
|
|
8
8
|
return _$createComponent(ClassDeclaration, {
|
|
@@ -19,7 +19,7 @@ describe("modifiers", () => {
|
|
|
19
19
|
it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
|
|
20
20
|
expect(_$createComponent(Wrapper, {
|
|
21
21
|
get children() {
|
|
22
|
-
return _$createComponent(
|
|
22
|
+
return _$createComponent(Property, _$mergeProps({
|
|
23
23
|
[accessModifier]: true
|
|
24
24
|
}, {
|
|
25
25
|
name: "TestProp",
|
|
@@ -39,7 +39,7 @@ describe("modifiers", () => {
|
|
|
39
39
|
it.each(["new", "static", "virtual", "sealed", "override", "abstract", "extern", "readonly"])("%s", methodModifier => {
|
|
40
40
|
expect(_$createComponent(Wrapper, {
|
|
41
41
|
get children() {
|
|
42
|
-
return _$createComponent(
|
|
42
|
+
return _$createComponent(Property, _$mergeProps({
|
|
43
43
|
[methodModifier]: true
|
|
44
44
|
}, {
|
|
45
45
|
name: "TestProp",
|
|
@@ -58,7 +58,7 @@ describe("modifiers", () => {
|
|
|
58
58
|
it("combine modifiers", () => {
|
|
59
59
|
expect(_$createComponent(Wrapper, {
|
|
60
60
|
get children() {
|
|
61
|
-
return _$createComponent(
|
|
61
|
+
return _$createComponent(Property, {
|
|
62
62
|
"public": true,
|
|
63
63
|
"new": true,
|
|
64
64
|
name: "TestProp",
|
|
@@ -77,7 +77,7 @@ describe("modifiers", () => {
|
|
|
77
77
|
it("applies PascalCase naming policy", () => {
|
|
78
78
|
expect(_$createComponent(Wrapper, {
|
|
79
79
|
get children() {
|
|
80
|
-
return _$createComponent(
|
|
80
|
+
return _$createComponent(Property, {
|
|
81
81
|
name: "test_prop",
|
|
82
82
|
type: "string",
|
|
83
83
|
get: true
|
|
@@ -93,7 +93,7 @@ it("applies PascalCase naming policy", () => {
|
|
|
93
93
|
it("has getter only", () => {
|
|
94
94
|
expect(_$createComponent(Wrapper, {
|
|
95
95
|
get children() {
|
|
96
|
-
return _$createComponent(
|
|
96
|
+
return _$createComponent(Property, {
|
|
97
97
|
name: "TestProp",
|
|
98
98
|
type: "string",
|
|
99
99
|
get: true
|
|
@@ -109,7 +109,7 @@ it("has getter only", () => {
|
|
|
109
109
|
it("has setter only", () => {
|
|
110
110
|
expect(_$createComponent(Wrapper, {
|
|
111
111
|
get children() {
|
|
112
|
-
return _$createComponent(
|
|
112
|
+
return _$createComponent(Property, {
|
|
113
113
|
name: "TestProp",
|
|
114
114
|
type: "string",
|
|
115
115
|
set: true
|
|
@@ -125,7 +125,7 @@ it("has setter only", () => {
|
|
|
125
125
|
it("has getter and setter", () => {
|
|
126
126
|
expect(_$createComponent(Wrapper, {
|
|
127
127
|
get children() {
|
|
128
|
-
return _$createComponent(
|
|
128
|
+
return _$createComponent(Property, {
|
|
129
129
|
name: "TestProp",
|
|
130
130
|
type: "string",
|
|
131
131
|
get: true,
|
|
@@ -139,13 +139,30 @@ it("has getter and setter", () => {
|
|
|
139
139
|
}
|
|
140
140
|
`);
|
|
141
141
|
});
|
|
142
|
+
it("has getter and init", () => {
|
|
143
|
+
expect(_$createComponent(Wrapper, {
|
|
144
|
+
get children() {
|
|
145
|
+
return _$createComponent(Property, {
|
|
146
|
+
name: "TestProp",
|
|
147
|
+
type: "string",
|
|
148
|
+
get: true,
|
|
149
|
+
init: true
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
})).toRenderTo(`
|
|
153
|
+
public class TestClass
|
|
154
|
+
{
|
|
155
|
+
string TestProp { get; init; }
|
|
156
|
+
}
|
|
157
|
+
`);
|
|
158
|
+
});
|
|
142
159
|
it("specify doc comment", () => {
|
|
143
160
|
expect(_$createComponent(TestNamespace, {
|
|
144
161
|
get children() {
|
|
145
162
|
return _$createComponent(ClassDeclaration, {
|
|
146
163
|
name: "Test",
|
|
147
164
|
get children() {
|
|
148
|
-
return _$createComponent(
|
|
165
|
+
return _$createComponent(Property, {
|
|
149
166
|
name: "Method",
|
|
150
167
|
type: "string",
|
|
151
168
|
get: true,
|
|
@@ -166,7 +183,7 @@ it("specify doc comment", () => {
|
|
|
166
183
|
it("specify nullable property", () => {
|
|
167
184
|
expect(_$createComponent(Wrapper, {
|
|
168
185
|
get children() {
|
|
169
|
-
return _$createComponent(
|
|
186
|
+
return _$createComponent(Property, {
|
|
170
187
|
name: "TestProp",
|
|
171
188
|
type: "string",
|
|
172
189
|
nullable: true,
|
|
@@ -184,12 +201,12 @@ it("specify nullable property", () => {
|
|
|
184
201
|
it("specify initializer", () => {
|
|
185
202
|
expect(_$createComponent(Wrapper, {
|
|
186
203
|
get children() {
|
|
187
|
-
return _$createComponent(
|
|
204
|
+
return _$createComponent(Property, {
|
|
188
205
|
name: "TestProp",
|
|
189
206
|
type: "string",
|
|
190
207
|
get: true,
|
|
191
208
|
set: true,
|
|
192
|
-
|
|
209
|
+
initializer: `"abc"`
|
|
193
210
|
});
|
|
194
211
|
}
|
|
195
212
|
})).toRenderTo(`
|
|
@@ -3,6 +3,7 @@ import { AccessModifiers } from "../../modifiers.js";
|
|
|
3
3
|
export interface RecordModifiers {
|
|
4
4
|
readonly partial?: boolean;
|
|
5
5
|
}
|
|
6
|
+
/** Props to use the {@link RecordDeclaration} component */
|
|
6
7
|
export interface RecordDeclarationProps extends Omit<core.DeclarationProps, "nameKind">, AccessModifiers, RecordModifiers {
|
|
7
8
|
name: string;
|
|
8
9
|
/** Doc comment */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/record/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAO5B,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;
|
|
1
|
+
{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/record/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAO5B,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAID,2DAA2D;AAC3D,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,eAAe;IACjB,IAAI,EAAE,MAAM,CAAC;IAEb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,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,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,iBAwD9D"}
|
|
@@ -8,7 +8,7 @@ import { DocWhen } from "../doc/comment.js";
|
|
|
8
8
|
import { Name } from "../Name.js";
|
|
9
9
|
const getRecordModifiers = makeModifiers(["partial"]);
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/** Props to use the {@link RecordDeclaration} component */
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* CSharp record declaration.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
import { TestNamespace } from "../../../test/utils.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Property } from "../property/property.js";
|
|
5
5
|
import { RecordDeclaration } from "./declaration.js";
|
|
6
6
|
it("declares class with no members", () => {
|
|
7
7
|
expect(_$createComponent(TestNamespace, {
|
|
@@ -75,7 +75,7 @@ it("specify class property inside", () => {
|
|
|
75
75
|
name: "TestRecord",
|
|
76
76
|
doc: "This is a test",
|
|
77
77
|
get children() {
|
|
78
|
-
return _$createComponent(
|
|
78
|
+
return _$createComponent(Property, {
|
|
79
79
|
name: "Prop",
|
|
80
80
|
get: true,
|
|
81
81
|
set: true,
|