@alloy-js/csharp 0.17.0 → 0.18.0-dev.11
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/ClassDeclaration.d.ts +57 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
- package/dist/src/components/{Class.js → ClassDeclaration.js} +42 -53
- package/dist/src/components/ClassMethod.d.ts +25 -0
- package/dist/src/components/ClassMethod.d.ts.map +1 -0
- package/dist/src/components/ClassMethod.js +60 -0
- package/dist/src/components/EnumDeclaration.d.ts +34 -0
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -0
- package/dist/src/components/{Enum.js → EnumDeclaration.js} +25 -5
- package/dist/src/components/class/property.d.ts +55 -0
- package/dist/src/components/class/property.d.ts.map +1 -0
- package/dist/src/components/class/property.js +67 -0
- package/dist/src/components/class/property.test.d.ts +2 -0
- package/dist/src/components/class/property.test.d.ts.map +1 -0
- package/dist/src/components/class/property.test.js +201 -0
- package/dist/src/components/doc/comment.d.ts +70 -0
- package/dist/src/components/doc/comment.d.ts.map +1 -0
- package/dist/src/components/doc/comment.js +88 -0
- package/dist/src/components/doc/comment.test.d.ts +2 -0
- package/dist/src/components/doc/comment.test.d.ts.map +1 -0
- package/dist/src/components/doc/comment.test.js +348 -0
- package/dist/src/components/doc/from-markdown.d.ts +6 -0
- package/dist/src/components/doc/from-markdown.d.ts.map +1 -0
- package/dist/src/components/doc/from-markdown.js +58 -0
- package/dist/src/components/doc/from-markdown.test.d.ts +2 -0
- package/dist/src/components/doc/from-markdown.test.d.ts.map +1 -0
- package/dist/src/components/doc/from-markdown.test.js +83 -0
- package/dist/src/components/index.d.ts +9 -2
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +9 -2
- package/dist/src/components/interface/declaration.d.ts +34 -0
- package/dist/src/components/interface/declaration.d.ts.map +1 -0
- package/dist/src/components/interface/declaration.js +90 -0
- package/dist/src/components/interface/declaration.test.d.ts +2 -0
- package/dist/src/components/interface/declaration.test.d.ts.map +1 -0
- package/dist/src/components/interface/declaration.test.js +69 -0
- package/dist/src/components/interface/method.d.ts +18 -0
- package/dist/src/components/interface/method.d.ts.map +1 -0
- package/dist/src/components/interface/method.js +59 -0
- package/dist/src/components/interface/method.test.d.ts +2 -0
- package/dist/src/components/interface/method.test.d.ts.map +1 -0
- package/dist/src/components/interface/method.test.js +131 -0
- package/dist/src/components/interface/property.d.ts +38 -0
- package/dist/src/components/interface/property.d.ts.map +1 -0
- package/dist/src/components/interface/property.js +67 -0
- package/dist/src/components/interface/property.test.d.ts +2 -0
- package/dist/src/components/interface/property.test.d.ts.map +1 -0
- package/dist/src/components/interface/property.test.js +165 -0
- package/dist/src/components/stc/index.d.ts +2 -2
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +2 -2
- package/dist/src/modifiers.d.ts +13 -4
- package/dist/src/modifiers.d.ts.map +1 -1
- package/dist/src/modifiers.js +13 -27
- package/dist/src/name-policy.d.ts +1 -1
- package/dist/src/name-policy.d.ts.map +1 -1
- package/dist/src/name-policy.js +1 -0
- package/dist/test/class-declaration.test.d.ts +2 -0
- package/dist/test/class-declaration.test.d.ts.map +1 -0
- package/dist/test/{class.test.js → class-declaration.test.js} +123 -73
- package/dist/test/class-method.test.d.ts +2 -0
- package/dist/test/class-method.test.d.ts.map +1 -0
- package/dist/test/class-method.test.js +161 -0
- package/dist/test/enum.test.js +12 -12
- package/dist/test/namespace.test.js +8 -8
- package/dist/test/project-directory.test.d.ts +2 -0
- package/dist/test/project-directory.test.d.ts.map +1 -0
- package/dist/test/{projectdirectory.test.js → project-directory.test.js} +8 -8
- package/dist/test/sourcefile.test.js +4 -4
- package/dist/test/using.test.js +9 -9
- package/dist/test/utils.d.ts +3 -0
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +15 -0
- package/dist/test/vitest.setup.d.ts +2 -0
- package/dist/test/vitest.setup.d.ts.map +1 -0
- package/dist/test/vitest.setup.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -6
- package/src/components/{Class.tsx → ClassDeclaration.tsx} +68 -66
- package/src/components/ClassMethod.tsx +94 -0
- package/src/components/{Enum.tsx → EnumDeclaration.tsx} +30 -6
- package/src/components/class/property.test.tsx +180 -0
- package/src/components/class/property.tsx +135 -0
- package/src/components/doc/comment.test.tsx +337 -0
- package/src/components/doc/comment.tsx +152 -0
- package/src/components/doc/from-markdown.test.tsx +103 -0
- package/src/components/doc/from-markdown.tsx +58 -0
- package/src/components/index.ts +9 -2
- package/src/components/interface/declaration.test.tsx +56 -0
- package/src/components/interface/declaration.tsx +109 -0
- package/src/components/interface/method.test.tsx +120 -0
- package/src/components/interface/method.tsx +82 -0
- package/src/components/interface/property.test.tsx +144 -0
- package/src/components/interface/property.tsx +107 -0
- package/src/components/stc/index.ts +2 -2
- package/src/modifiers.ts +32 -37
- package/src/name-policy.ts +2 -0
- package/temp/api.json +4419 -567
- package/test/{class.test.tsx → class-declaration.test.tsx} +103 -99
- package/test/class-method.test.tsx +147 -0
- package/test/enum.test.tsx +11 -11
- package/test/namespace.test.tsx +4 -4
- package/test/{projectdirectory.test.tsx → project-directory.test.tsx} +4 -4
- package/test/sourcefile.test.tsx +2 -2
- package/test/using.test.tsx +9 -9
- package/test/utils.tsx +9 -0
- package/test/vitest.setup.ts +1 -0
- package/tsconfig.json +2 -1
- package/vitest.config.ts +3 -0
- package/dist/src/components/Class.d.ts +0 -36
- package/dist/src/components/Class.d.ts.map +0 -1
- package/dist/src/components/Enum.d.ts +0 -15
- package/dist/src/components/Enum.d.ts.map +0 -1
- package/dist/test/class.test.d.ts +0 -2
- package/dist/test/class.test.d.ts.map +0 -1
- package/dist/test/projectdirectory.test.d.ts +0 -2
- package/dist/test/projectdirectory.test.d.ts.map +0 -1
|
@@ -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 @@
|
|
|
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,38 @@
|
|
|
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 interface InterfacePropertyProps extends AccessModifiers, InterfacePropertyModifiers {
|
|
8
|
+
name: string;
|
|
9
|
+
refkey?: Refkey;
|
|
10
|
+
/** Property type */
|
|
11
|
+
type: Children;
|
|
12
|
+
/** If property should have a getter */
|
|
13
|
+
get?: boolean;
|
|
14
|
+
/** If property should have a setter */
|
|
15
|
+
set?: boolean;
|
|
16
|
+
/** Doc comment */
|
|
17
|
+
doc?: Children;
|
|
18
|
+
/**
|
|
19
|
+
* Property initializer
|
|
20
|
+
* @example `<ClassProperty name="My" get set nullable />`
|
|
21
|
+
*
|
|
22
|
+
* ```cs
|
|
23
|
+
* int? My { get; set; };
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
nullable?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Render a C# interface property.
|
|
30
|
+
*
|
|
31
|
+
* @example `<InterfaceProperty public name="My" get set />`
|
|
32
|
+
*
|
|
33
|
+
* ```cs
|
|
34
|
+
* public int My { get; set; };
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function InterfaceProperty(props: InterfacePropertyProps): Children;
|
|
38
|
+
//# 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;AAKD,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;IAEf;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,YAwC9D"}
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
const getModifiers = makeModifiers(["new"]);
|
|
12
|
+
|
|
13
|
+
// properties for creating a method
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Render a C# interface property.
|
|
17
|
+
*
|
|
18
|
+
* @example `<InterfaceProperty public name="My" get set />`
|
|
19
|
+
*
|
|
20
|
+
* ```cs
|
|
21
|
+
* public int My { get; set; };
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function InterfaceProperty(props) {
|
|
25
|
+
const name = useCSharpNamePolicy().getName(props.name, "class-property");
|
|
26
|
+
const scope = useCSharpScope();
|
|
27
|
+
if (scope.kind !== "member" || scope.name !== "interface-decl") {
|
|
28
|
+
throw new Error("can't define an interface method outside of an interface scope");
|
|
29
|
+
}
|
|
30
|
+
const propertySymbol = new CSharpOutputSymbol(name, {
|
|
31
|
+
scope,
|
|
32
|
+
refkeys: props.refkey ?? refkey(props.name)
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// scope for property declaration
|
|
36
|
+
const propertyScope = new CSharpMemberScope("property-decl", {
|
|
37
|
+
owner: propertySymbol
|
|
38
|
+
});
|
|
39
|
+
const modifiers = computeModifiersPrefix([getAccessModifier(props), getModifiers(props)]);
|
|
40
|
+
// note that scope wraps the method decl so that the params get the correct scope
|
|
41
|
+
return _$createComponent(MemberDeclaration, {
|
|
42
|
+
symbol: propertySymbol,
|
|
43
|
+
get children() {
|
|
44
|
+
return _$createComponent(Scope, {
|
|
45
|
+
value: propertyScope,
|
|
46
|
+
get children() {
|
|
47
|
+
return [_$createComponent(DocWhen, {
|
|
48
|
+
get doc() {
|
|
49
|
+
return props.doc;
|
|
50
|
+
}
|
|
51
|
+
}), modifiers, _$memo(() => props.type), _$memo(() => props.nullable && "?"), " ", name, " ", _$createComponent(Block, {
|
|
52
|
+
newline: true,
|
|
53
|
+
inline: true,
|
|
54
|
+
get children() {
|
|
55
|
+
return _$createComponent(List, {
|
|
56
|
+
joiner: " ",
|
|
57
|
+
get children() {
|
|
58
|
+
return [_$memo(() => props.get && "get;"), _$memo(() => props.set && "set;")];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
})];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -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
|
+
});
|
|
@@ -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
|
|
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
|
|
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,
|
|
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"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
2
|
import * as base from "../index.js";
|
|
3
|
-
export const
|
|
3
|
+
export const ClassDeclaration = core.stc(base.ClassDeclaration);
|
|
4
4
|
export const ClassConstructor = core.stc(base.ClassConstructor);
|
|
5
5
|
export const ClassMember = core.stc(base.ClassMember);
|
|
6
6
|
export const ClassMethod = core.stc(base.ClassMethod);
|
|
7
|
-
export const
|
|
7
|
+
export const EnumDeclaration = core.stc(base.EnumDeclaration);
|
|
8
8
|
export const EnumMember = core.stc(base.EnumMember);
|
|
9
9
|
export const Parameter = core.stc(base.Parameter);
|
|
10
10
|
export const Parameters = core.stc(base.Parameters);
|
package/dist/src/modifiers.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/** Access modifiers. */
|
|
2
|
+
export interface AccessModifiers {
|
|
3
|
+
readonly public?: boolean;
|
|
4
|
+
readonly protected?: boolean;
|
|
5
|
+
readonly private?: boolean;
|
|
6
|
+
readonly internal?: boolean;
|
|
7
|
+
readonly file?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const getAccessModifier: (data: AccessModifiers) => string;
|
|
10
|
+
export declare function getAsyncModifier(async?: boolean): string;
|
|
11
|
+
/** Resolve the modifier prefix */
|
|
12
|
+
export declare function computeModifiersPrefix(modifiers: Array<string | undefined>): string;
|
|
13
|
+
export declare function makeModifiers<T>(obj: Array<keyof T>): (data: T) => string;
|
|
5
14
|
//# sourceMappingURL=modifiers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modifiers.d.ts","sourceRoot":"","sources":["../../src/modifiers.ts"],"names":[],"mappings":"
|
|
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"}
|