@alloy-js/csharp 0.18.0-dev.8 → 0.18.0
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/CHANGELOG.md +31 -0
- package/dist/src/components/ClassDeclaration.d.ts +39 -2
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +35 -34
- package/dist/src/components/ClassMethod.d.ts +33 -1
- package/dist/src/components/ClassMethod.d.ts.map +1 -1
- package/dist/src/components/ClassMethod.js +22 -7
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +1 -0
- package/dist/src/components/attributes/attributes.d.ts +39 -0
- package/dist/src/components/attributes/attributes.d.ts.map +1 -0
- package/dist/src/components/attributes/attributes.js +62 -0
- package/dist/src/components/attributes/attributes.test.d.ts +2 -0
- package/dist/src/components/attributes/attributes.test.d.ts.map +1 -0
- package/dist/src/components/attributes/attributes.test.js +75 -0
- package/dist/src/components/doc/comment.d.ts +12 -11
- package/dist/src/components/doc/comment.d.ts.map +1 -1
- package/dist/src/components/doc/comment.js +27 -10
- package/dist/src/components/doc/comment.test.js +98 -88
- 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 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +10 -2
- package/dist/src/components/interface/declaration.d.ts +32 -1
- package/dist/src/components/interface/declaration.d.ts.map +1 -1
- package/dist/src/components/interface/declaration.js +18 -25
- package/dist/src/components/interface/declaration.test.js +102 -0
- package/dist/src/components/interface/method.d.ts +33 -1
- package/dist/src/components/interface/method.d.ts.map +1 -1
- package/dist/src/components/interface/method.js +22 -7
- package/dist/src/components/interface/method.test.js +169 -0
- package/dist/src/components/interface/property.d.ts +36 -1
- package/dist/src/components/interface/property.d.ts.map +1 -1
- package/dist/src/components/interface/property.js +18 -4
- package/dist/src/components/interface/property.test.js +24 -0
- package/dist/src/components/parameters/parameters.d.ts +19 -0
- package/dist/src/components/parameters/parameters.d.ts.map +1 -0
- package/dist/src/components/parameters/parameters.js +43 -0
- package/dist/src/components/property/property.d.ts +80 -0
- package/dist/src/components/property/property.d.ts.map +1 -0
- package/dist/src/components/property/property.js +76 -0
- package/dist/src/components/property/property.test.d.ts +2 -0
- package/dist/src/components/property/property.test.d.ts.map +1 -0
- package/dist/src/components/property/property.test.js +242 -0
- package/dist/src/components/record/declaration.d.ts +35 -0
- package/dist/src/components/record/declaration.d.ts.map +1 -0
- package/dist/src/components/record/declaration.js +90 -0
- package/dist/src/components/record/declaration.test.d.ts +2 -0
- package/dist/src/components/record/declaration.test.d.ts.map +1 -0
- package/dist/src/components/record/declaration.test.js +94 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +8 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.js +44 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +2 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.test.js +67 -0
- package/dist/src/components/type-parameters/type-parameter.d.ts +20 -0
- package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameter.js +22 -0
- package/dist/src/components/type-parameters/type-parameters.d.ts +17 -0
- package/dist/src/components/type-parameters/type-parameters.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameters.js +54 -0
- package/dist/src/components/type-parameters/type-parameters.test.d.ts +2 -0
- package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +1 -0
- package/dist/src/components/type-parameters/type-parameters.test.js +48 -0
- package/dist/src/components/var/declaration.d.ts +35 -0
- package/dist/src/components/var/declaration.d.ts.map +1 -0
- package/dist/src/components/var/declaration.js +40 -0
- package/dist/src/components/var/declaration.test.d.ts +2 -0
- package/dist/src/components/var/declaration.test.d.ts.map +1 -0
- package/dist/src/components/var/declaration.test.js +73 -0
- 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} +161 -33
- package/dist/test/project-directory.test.d.ts +2 -0
- package/dist/test/project-directory.test.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -6
- package/src/components/ClassDeclaration.tsx +65 -33
- package/src/components/ClassMethod.tsx +46 -4
- package/src/components/SourceFile.tsx +1 -0
- package/src/components/attributes/attributes.test.tsx +61 -0
- package/src/components/attributes/attributes.tsx +100 -0
- package/src/components/doc/comment.test.tsx +80 -79
- package/src/components/doc/comment.tsx +44 -14
- 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 -1
- package/src/components/interface/declaration.test.tsx +102 -0
- package/src/components/interface/declaration.tsx +43 -27
- package/src/components/interface/method.test.tsx +173 -0
- package/src/components/interface/method.tsx +45 -5
- package/src/components/interface/property.test.tsx +21 -0
- package/src/components/interface/property.tsx +43 -6
- package/src/components/parameters/parameters.tsx +74 -0
- package/src/components/property/property.test.tsx +209 -0
- package/src/components/property/property.tsx +172 -0
- package/src/components/record/declaration.test.tsx +73 -0
- package/src/components/record/declaration.tsx +109 -0
- package/src/components/type-parameters/type-parameter-constraints.test.tsx +93 -0
- package/src/components/type-parameters/type-parameter-constraints.tsx +46 -0
- package/src/components/type-parameters/type-parameter.tsx +35 -0
- package/src/components/type-parameters/type-parameters.test.tsx +46 -0
- package/src/components/type-parameters/type-parameters.tsx +63 -0
- package/src/components/var/declaration.test.tsx +59 -0
- package/src/components/var/declaration.tsx +47 -0
- package/src/name-policy.ts +3 -0
- package/temp/api.json +5838 -1626
- package/test/{class.test.tsx → class-declaration.test.tsx} +144 -26
- package/dist/src/components/Parameters.d.ts +0 -13
- package/dist/src/components/Parameters.d.ts.map +0 -1
- package/dist/src/components/Parameters.js +0 -34
- 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
- package/src/components/Parameters.tsx +0 -51
- /package/dist/test/{projectdirectory.test.js → project-directory.test.js} +0 -0
- /package/test/{projectdirectory.test.tsx → project-directory.test.tsx} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
|
+
import { join } from "@alloy-js/core";
|
|
2
3
|
import {
|
|
3
4
|
AccessModifiers,
|
|
4
5
|
computeModifiersPrefix,
|
|
@@ -8,9 +9,13 @@ import {
|
|
|
8
9
|
import { CSharpElements, useCSharpNamePolicy } from "../name-policy.js";
|
|
9
10
|
import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
|
|
10
11
|
import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
|
|
11
|
-
import {
|
|
12
|
-
import { ParameterProps, Parameters } from "./Parameters.jsx";
|
|
12
|
+
import { AttributeList, AttributesProp } from "./attributes/attributes.jsx";
|
|
13
13
|
import { DocWhen } from "./doc/comment.jsx";
|
|
14
|
+
import { Name } from "./Name.jsx";
|
|
15
|
+
import { ParameterProps, Parameters } from "./parameters/parameters.jsx";
|
|
16
|
+
import { TypeParameterConstraints } from "./type-parameters/type-parameter-constraints.jsx";
|
|
17
|
+
import { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
|
|
18
|
+
import { TypeParameters } from "./type-parameters/type-parameters.jsx";
|
|
14
19
|
|
|
15
20
|
export interface ClassModifiers {
|
|
16
21
|
readonly abstract?: boolean;
|
|
@@ -35,7 +40,44 @@ export interface ClassDeclarationProps
|
|
|
35
40
|
/** Doc comment */
|
|
36
41
|
doc?: core.Children;
|
|
37
42
|
refkey?: core.Refkey;
|
|
38
|
-
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Type parameters for the class
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```tsx
|
|
49
|
+
* <ClassDeclaration name="MyClass" typeParameters={["T"]} />
|
|
50
|
+
* ```
|
|
51
|
+
* This will produce:
|
|
52
|
+
* ```csharp
|
|
53
|
+
* public class MyClass<T>
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
typeParameters?: (string | TypeParameterProps)[];
|
|
57
|
+
|
|
58
|
+
/** Base class that this class extends */
|
|
59
|
+
baseType?: core.Children;
|
|
60
|
+
|
|
61
|
+
/** Interfaces this class implements */
|
|
62
|
+
interfaceTypes?: core.Children[];
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Define attributes to attach
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* <ClassDeclaration name="MyClass" attributes={[
|
|
69
|
+
* <Attribute name="Test" />
|
|
70
|
+
* <Attribute name="Test2" args={["arg1", "arg2"]} />
|
|
71
|
+
* ]}>
|
|
72
|
+
* ```
|
|
73
|
+
* This will produce:
|
|
74
|
+
* ```csharp
|
|
75
|
+
* [Test]
|
|
76
|
+
* [Test2("arg1", "arg2")]
|
|
77
|
+
* public class MyClass
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
attributes?: AttributesProp;
|
|
39
81
|
}
|
|
40
82
|
|
|
41
83
|
/**
|
|
@@ -77,31 +119,12 @@ export function ClassDeclaration(props: ClassDeclarationProps) {
|
|
|
77
119
|
owner: thisClassSymbol,
|
|
78
120
|
});
|
|
79
121
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
);
|
|
87
|
-
// create a symbol for each type param so its
|
|
88
|
-
// refkey resolves to the type param's name
|
|
89
|
-
new CSharpOutputSymbol(entry[0], {
|
|
90
|
-
scope: thisClassScope,
|
|
91
|
-
refkeys: entry[1],
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
typeParams = (
|
|
95
|
-
<group>
|
|
96
|
-
{"<"}
|
|
97
|
-
<core.For each={typeParamNames} comma line>
|
|
98
|
-
{(name) => name}
|
|
99
|
-
</core.For>
|
|
100
|
-
{">"}
|
|
101
|
-
</group>
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
122
|
+
const bases = [
|
|
123
|
+
...(props.baseType ? [props.baseType] : []),
|
|
124
|
+
...(props.interfaceTypes || []),
|
|
125
|
+
];
|
|
126
|
+
const base =
|
|
127
|
+
bases.length > 0 ? <> : {join(bases, { joiner: ", " })}</> : null;
|
|
105
128
|
const modifiers = computeModifiersPrefix([
|
|
106
129
|
getAccessModifier(props),
|
|
107
130
|
getClassModifiers(props),
|
|
@@ -109,8 +132,15 @@ export function ClassDeclaration(props: ClassDeclarationProps) {
|
|
|
109
132
|
return (
|
|
110
133
|
<core.Declaration symbol={thisClassSymbol}>
|
|
111
134
|
<DocWhen doc={props.doc} />
|
|
135
|
+
<AttributeList attributes={props.attributes} endline />
|
|
112
136
|
{modifiers}class <Name />
|
|
113
|
-
{
|
|
137
|
+
{props.typeParameters && (
|
|
138
|
+
<TypeParameters parameters={props.typeParameters} />
|
|
139
|
+
)}
|
|
140
|
+
{base}
|
|
141
|
+
{props.typeParameters && (
|
|
142
|
+
<TypeParameterConstraints parameters={props.typeParameters} />
|
|
143
|
+
)}
|
|
114
144
|
{!props.children && ";"}
|
|
115
145
|
{props.children && (
|
|
116
146
|
<core.Block newline>
|
|
@@ -151,15 +181,14 @@ export function ClassConstructor(props: ClassConstructorProps) {
|
|
|
151
181
|
|
|
152
182
|
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
153
183
|
|
|
154
|
-
const params =
|
|
155
|
-
props.parameters ? <Parameters parameters={props.parameters} /> : "";
|
|
156
|
-
|
|
157
184
|
// note that scope wraps the ctor decl so that the params get the correct scope
|
|
158
185
|
return (
|
|
159
186
|
<core.Declaration symbol={ctorSymbol}>
|
|
160
187
|
<core.Scope value={ctorDeclScope}>
|
|
161
188
|
{modifiers}
|
|
162
|
-
<Name />
|
|
189
|
+
<Name />
|
|
190
|
+
<Parameters parameters={props.parameters} />
|
|
191
|
+
<core.Block newline>{props.children}</core.Block>
|
|
163
192
|
</core.Scope>
|
|
164
193
|
</core.Declaration>
|
|
165
194
|
);
|
|
@@ -170,6 +199,8 @@ export interface ClassMemberProps extends AccessModifiers {
|
|
|
170
199
|
name: string;
|
|
171
200
|
type: core.Children;
|
|
172
201
|
refkey?: core.Refkey;
|
|
202
|
+
/** Doc comment */
|
|
203
|
+
doc?: core.Children;
|
|
173
204
|
}
|
|
174
205
|
|
|
175
206
|
// a C# class member (i.e. a field within a class like "private int count")
|
|
@@ -194,6 +225,7 @@ export function ClassMember(props: ClassMemberProps) {
|
|
|
194
225
|
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
195
226
|
return (
|
|
196
227
|
<core.Declaration symbol={memberSymbol}>
|
|
228
|
+
<DocWhen doc={props.doc} />
|
|
197
229
|
{modifiers}
|
|
198
230
|
{props.type} <Name />
|
|
199
231
|
</core.Declaration>
|
|
@@ -16,8 +16,12 @@ import {
|
|
|
16
16
|
import { useCSharpNamePolicy } from "../name-policy.js";
|
|
17
17
|
import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
|
|
18
18
|
import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
|
|
19
|
-
import {
|
|
19
|
+
import { AttributeList, AttributesProp } from "./attributes/attributes.jsx";
|
|
20
20
|
import { DocWhen } from "./doc/comment.jsx";
|
|
21
|
+
import { ParameterProps, Parameters } from "./parameters/parameters.jsx";
|
|
22
|
+
import { TypeParameterConstraints } from "./type-parameters/type-parameter-constraints.jsx";
|
|
23
|
+
import { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
|
|
24
|
+
import { TypeParameters } from "./type-parameters/type-parameters.jsx";
|
|
21
25
|
|
|
22
26
|
/** Method modifiers. Can only be one. */
|
|
23
27
|
export interface ClassMethodModifiers {
|
|
@@ -51,6 +55,38 @@ export interface ClassMethodProps
|
|
|
51
55
|
|
|
52
56
|
/** Doc comment */
|
|
53
57
|
doc?: Children;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Type parameters for the method
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```tsx
|
|
64
|
+
* <InterfaceMethod name="Test" typeParameters={["T"]} />
|
|
65
|
+
* ```
|
|
66
|
+
* This will produce:
|
|
67
|
+
* ```csharp
|
|
68
|
+
* public void Test<T>()
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
typeParameters?: (TypeParameterProps | string)[];
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Define attributes to attach
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* <ClassMethod name="MyMethod" attributes={[
|
|
78
|
+
* <Attribute name="Test" />
|
|
79
|
+
* <Attribute name="Test2" args={["arg1", "arg2"]} />
|
|
80
|
+
* ]} />
|
|
81
|
+
* ```
|
|
82
|
+
* This will produce:
|
|
83
|
+
* ```csharp
|
|
84
|
+
* [Test]
|
|
85
|
+
* [Test2("arg1", "arg2")]
|
|
86
|
+
* public void MyMethod() { }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
attributes?: AttributesProp;
|
|
54
90
|
}
|
|
55
91
|
|
|
56
92
|
// a C# class method
|
|
@@ -71,8 +107,6 @@ export function ClassMethod(props: ClassMethodProps) {
|
|
|
71
107
|
owner: methodSymbol,
|
|
72
108
|
});
|
|
73
109
|
|
|
74
|
-
const params =
|
|
75
|
-
props.parameters ? <Parameters parameters={props.parameters} /> : "";
|
|
76
110
|
const returns = props.returns ?? (props.async ? "Task" : "void");
|
|
77
111
|
|
|
78
112
|
const modifiers = computeModifiersPrefix([
|
|
@@ -85,8 +119,16 @@ export function ClassMethod(props: ClassMethodProps) {
|
|
|
85
119
|
<MemberDeclaration symbol={methodSymbol}>
|
|
86
120
|
<Scope value={methodScope}>
|
|
87
121
|
<DocWhen doc={props.doc} />
|
|
122
|
+
<AttributeList attributes={props.attributes} endline />
|
|
88
123
|
{modifiers}
|
|
89
|
-
{returns} {name}
|
|
124
|
+
{returns} {name}
|
|
125
|
+
{props.typeParameters && (
|
|
126
|
+
<TypeParameters parameters={props.typeParameters} />
|
|
127
|
+
)}
|
|
128
|
+
<Parameters parameters={props.parameters} />
|
|
129
|
+
{props.typeParameters && (
|
|
130
|
+
<TypeParameterConstraints parameters={props.typeParameters} />
|
|
131
|
+
)}
|
|
90
132
|
{props.abstract ? ";" : <Block newline>{props.children}</Block>}
|
|
91
133
|
</Scope>
|
|
92
134
|
</MemberDeclaration>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import { Attribute, AttributeList } from "./attributes.jsx";
|
|
3
|
+
|
|
4
|
+
it("define attribute", () => {
|
|
5
|
+
expect(<Attribute name="Test" />).toRenderTo(`
|
|
6
|
+
[Test]
|
|
7
|
+
`);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("define attribute with single arg", () => {
|
|
11
|
+
expect(<Attribute name="Test" args={[`"abc"`]} />).toRenderTo(`
|
|
12
|
+
[Test("abc")]
|
|
13
|
+
`);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("define attribute with multiple arg", () => {
|
|
17
|
+
expect(<Attribute name="Test" args={[`"abc"`, `"def"`]} />).toRenderTo(`
|
|
18
|
+
[Test("abc", "def")]
|
|
19
|
+
`);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("define attribute list with Attribute components", () => {
|
|
23
|
+
expect(
|
|
24
|
+
<AttributeList
|
|
25
|
+
attributes={[<Attribute name="TestA" />, <Attribute name="TestB" />]}
|
|
26
|
+
/>,
|
|
27
|
+
).toRenderTo(`
|
|
28
|
+
[TestA]
|
|
29
|
+
[TestB]
|
|
30
|
+
`);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("define attribute list with attribute names", () => {
|
|
34
|
+
expect(<AttributeList attributes={["TestA", "TestB"]} />).toRenderTo(`
|
|
35
|
+
[TestA]
|
|
36
|
+
[TestB]
|
|
37
|
+
`);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("define attribute list with attribute props", () => {
|
|
41
|
+
expect(
|
|
42
|
+
<AttributeList
|
|
43
|
+
attributes={[{ name: "TestA" }, { name: "TestB", args: [`"test"`] }]}
|
|
44
|
+
/>,
|
|
45
|
+
).toRenderTo(`
|
|
46
|
+
[TestA]
|
|
47
|
+
[TestB("test")]
|
|
48
|
+
`);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("define attribute list with children", () => {
|
|
52
|
+
expect(
|
|
53
|
+
<AttributeList>
|
|
54
|
+
<Attribute name="TestA" />
|
|
55
|
+
<Attribute name="TestB" />
|
|
56
|
+
</AttributeList>,
|
|
57
|
+
).toRenderTo(`
|
|
58
|
+
[TestA]
|
|
59
|
+
[TestB]
|
|
60
|
+
`);
|
|
61
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
findKeyedChildren,
|
|
4
|
+
For,
|
|
5
|
+
Indent,
|
|
6
|
+
taggedComponent,
|
|
7
|
+
} from "@alloy-js/core";
|
|
8
|
+
|
|
9
|
+
export interface AttributeItem {
|
|
10
|
+
name: string;
|
|
11
|
+
args?: string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type AttributesProp = Array<string | AttributeProps | Children>;
|
|
15
|
+
|
|
16
|
+
export interface AttributeListProps {
|
|
17
|
+
/** If the attribute list should finish with a hard line if there is any attribute */
|
|
18
|
+
endline?: boolean;
|
|
19
|
+
attributes?: AttributesProp;
|
|
20
|
+
children?: Children[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Render each attributes in a new line.
|
|
25
|
+
*/
|
|
26
|
+
export function AttributeList(props: AttributeListProps) {
|
|
27
|
+
const attributes =
|
|
28
|
+
props.attributes ??
|
|
29
|
+
(props.children && findKeyedChildren(props.children, Attribute.tag));
|
|
30
|
+
|
|
31
|
+
if (!attributes) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
<For each={attributes} line>
|
|
38
|
+
{(arg) => renderAttribute(arg)}
|
|
39
|
+
</For>
|
|
40
|
+
{props.endline && attributes.length > 0 && <hbr />}
|
|
41
|
+
</>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function renderAttribute(attr: string | AttributeProps | Children): Children {
|
|
46
|
+
if (typeof attr === "string") {
|
|
47
|
+
return <Attribute name={attr} />;
|
|
48
|
+
} else if (typeof attr === "object" && attr && "name" in attr) {
|
|
49
|
+
return <Attribute {...attr} />;
|
|
50
|
+
} else {
|
|
51
|
+
return attr;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface AttributeProps {
|
|
56
|
+
/** Attribute name */
|
|
57
|
+
name: Children;
|
|
58
|
+
|
|
59
|
+
/** Argument */
|
|
60
|
+
args?: Children[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const AttributeTag = Symbol("AttributeTag");
|
|
64
|
+
/**
|
|
65
|
+
* Render a csharp attribute.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* <Attribute name="Test" /><hbr/>
|
|
70
|
+
* <Attribute name="Test" args={["arg1", "arg2"]} />
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* will render:
|
|
74
|
+
* ```csharp
|
|
75
|
+
* [Test]
|
|
76
|
+
* [Test("arg1", "arg2")]
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export const Attribute = taggedComponent(
|
|
80
|
+
AttributeTag,
|
|
81
|
+
(props: AttributeProps) => {
|
|
82
|
+
return (
|
|
83
|
+
<group>
|
|
84
|
+
[{props.name}
|
|
85
|
+
{props.args && props.args.length > 0 && (
|
|
86
|
+
<>
|
|
87
|
+
(
|
|
88
|
+
<Indent softline>
|
|
89
|
+
<For each={props.args ?? []} comma line>
|
|
90
|
+
{(arg) => arg}
|
|
91
|
+
</For>
|
|
92
|
+
</Indent>
|
|
93
|
+
)
|
|
94
|
+
</>
|
|
95
|
+
)}
|
|
96
|
+
]
|
|
97
|
+
</group>
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
);
|
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
import { expect, it } from "vitest";
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
2
|
import {
|
|
3
3
|
DocC,
|
|
4
4
|
DocCode,
|
|
5
5
|
DocComment,
|
|
6
|
-
DocCompletionList,
|
|
7
6
|
DocDescription,
|
|
8
7
|
DocExample,
|
|
9
8
|
DocException,
|
|
10
9
|
DocInclude,
|
|
11
|
-
DocItem,
|
|
12
10
|
DocList,
|
|
13
11
|
DocPara,
|
|
14
12
|
DocParam,
|
|
15
13
|
DocParamRef,
|
|
16
14
|
DocPermission,
|
|
17
15
|
DocRemarks,
|
|
18
|
-
DocResponse,
|
|
19
16
|
DocReturns,
|
|
20
17
|
DocSee,
|
|
21
18
|
DocSeeAlso,
|
|
22
19
|
DocSummary,
|
|
23
|
-
DocTerm,
|
|
24
20
|
DocTypeParam,
|
|
25
21
|
DocTypeParamRef,
|
|
26
22
|
DocValue,
|
|
@@ -56,9 +52,7 @@ it("define c", () => {
|
|
|
56
52
|
<DocC>inline code</DocC>
|
|
57
53
|
</DocComment>,
|
|
58
54
|
).toRenderTo(`
|
|
59
|
-
/// <c>
|
|
60
|
-
/// inline code
|
|
61
|
-
/// </c>
|
|
55
|
+
/// <c>inline code</c>
|
|
62
56
|
`);
|
|
63
57
|
});
|
|
64
58
|
|
|
@@ -89,7 +83,7 @@ it("define exception", () => {
|
|
|
89
83
|
it("define include", () => {
|
|
90
84
|
expect(
|
|
91
85
|
<DocComment>
|
|
92
|
-
|
|
86
|
+
<DocInclude file="external.xml" path="/doc/summary" />
|
|
93
87
|
</DocComment>,
|
|
94
88
|
).toRenderTo(`
|
|
95
89
|
/// <include file="external.xml" path="/doc/summary" />
|
|
@@ -164,66 +158,20 @@ it("define permission", () => {
|
|
|
164
158
|
`);
|
|
165
159
|
});
|
|
166
160
|
|
|
167
|
-
it("define response", () => {
|
|
168
|
-
expect(
|
|
169
|
-
<DocComment>
|
|
170
|
-
<DocResponse>response info</DocResponse>
|
|
171
|
-
</DocComment>,
|
|
172
|
-
).toRenderTo(`
|
|
173
|
-
/// <response>
|
|
174
|
-
/// response info
|
|
175
|
-
/// </response>
|
|
176
|
-
`);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it("define completionlist", () => {
|
|
180
|
-
expect(
|
|
181
|
-
<DocComment>
|
|
182
|
-
<DocCompletionList>completion list</DocCompletionList>
|
|
183
|
-
</DocComment>,
|
|
184
|
-
).toRenderTo(`
|
|
185
|
-
/// <completionlist>
|
|
186
|
-
/// completion list
|
|
187
|
-
/// </completionlist>
|
|
188
|
-
`);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
161
|
it("define list", () => {
|
|
192
162
|
expect(
|
|
193
163
|
<DocComment>
|
|
194
|
-
<DocList
|
|
164
|
+
<DocList type="bullet" items={["item 1", "item 2", "item 3"]} />
|
|
195
165
|
</DocComment>,
|
|
196
166
|
).toRenderTo(`
|
|
197
|
-
/// <list>
|
|
198
|
-
///
|
|
167
|
+
/// <list type="bullet">
|
|
168
|
+
/// <item><description>item 1</description></item>
|
|
169
|
+
/// <item><description>item 2</description></item>
|
|
170
|
+
/// <item><description>item 3</description></item>
|
|
199
171
|
/// </list>
|
|
200
172
|
`);
|
|
201
173
|
});
|
|
202
174
|
|
|
203
|
-
it("define item", () => {
|
|
204
|
-
expect(
|
|
205
|
-
<DocComment>
|
|
206
|
-
<DocItem>item content</DocItem>
|
|
207
|
-
</DocComment>,
|
|
208
|
-
).toRenderTo(`
|
|
209
|
-
/// <item>
|
|
210
|
-
/// item content
|
|
211
|
-
/// </item>
|
|
212
|
-
`);
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it("define term", () => {
|
|
216
|
-
expect(
|
|
217
|
-
<DocComment>
|
|
218
|
-
<DocTerm>term content</DocTerm>
|
|
219
|
-
</DocComment>,
|
|
220
|
-
).toRenderTo(`
|
|
221
|
-
/// <term>
|
|
222
|
-
/// term content
|
|
223
|
-
/// </term>
|
|
224
|
-
`);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
175
|
it("define description", () => {
|
|
228
176
|
expect(
|
|
229
177
|
<DocComment>
|
|
@@ -248,40 +196,93 @@ it("define para", () => {
|
|
|
248
196
|
`);
|
|
249
197
|
});
|
|
250
198
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
199
|
+
describe("define see", () => {
|
|
200
|
+
it("with cref", () => {
|
|
201
|
+
expect(
|
|
202
|
+
<DocComment>
|
|
203
|
+
<DocSee cref="T:MyType" />
|
|
204
|
+
</DocComment>,
|
|
205
|
+
).toRenderTo(`
|
|
206
|
+
/// <see cref="T:MyType" />
|
|
207
|
+
`);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("with href", () => {
|
|
211
|
+
expect(
|
|
212
|
+
<DocComment>
|
|
213
|
+
<DocSee href="https://github.com" />
|
|
214
|
+
</DocComment>,
|
|
215
|
+
).toRenderTo(`
|
|
216
|
+
/// <see href="https://github.com" />
|
|
217
|
+
`);
|
|
218
|
+
});
|
|
219
|
+
it("with href and children", () => {
|
|
220
|
+
expect(
|
|
221
|
+
<DocComment>
|
|
222
|
+
<DocSee href="https://github.com">GitHub</DocSee>
|
|
223
|
+
</DocComment>,
|
|
224
|
+
).toRenderTo(`
|
|
225
|
+
/// <see href="https://github.com">GitHub</see>
|
|
226
|
+
`);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("with langword", () => {
|
|
230
|
+
expect(
|
|
231
|
+
<DocComment>
|
|
232
|
+
<DocSee langword="keyword" />
|
|
233
|
+
</DocComment>,
|
|
234
|
+
).toRenderTo(`
|
|
235
|
+
/// <see langword="keyword" />
|
|
236
|
+
`);
|
|
237
|
+
});
|
|
259
238
|
});
|
|
260
239
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
240
|
+
describe("define seealso", () => {
|
|
241
|
+
it("with cref", () => {
|
|
242
|
+
expect(
|
|
243
|
+
<DocComment>
|
|
244
|
+
<DocSeeAlso cref="T:OtherType" />
|
|
245
|
+
</DocComment>,
|
|
246
|
+
).toRenderTo(`
|
|
247
|
+
/// <seealso cref="T:OtherType" />
|
|
248
|
+
`);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it("with href", () => {
|
|
252
|
+
expect(
|
|
253
|
+
<DocComment>
|
|
254
|
+
<DocSeeAlso href="https://github.com" />
|
|
255
|
+
</DocComment>,
|
|
256
|
+
).toRenderTo(`
|
|
257
|
+
/// <seealso href="https://github.com" />
|
|
258
|
+
`);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("with children", () => {
|
|
262
|
+
expect(
|
|
263
|
+
<DocComment>
|
|
264
|
+
<DocSeeAlso cref="T:OtherType">OtherType</DocSeeAlso>
|
|
265
|
+
</DocComment>,
|
|
266
|
+
).toRenderTo(`
|
|
267
|
+
/// <seealso cref="T:OtherType">OtherType</seealso>
|
|
268
|
+
`);
|
|
269
|
+
});
|
|
269
270
|
});
|
|
270
271
|
|
|
271
272
|
it("define paramref", () => {
|
|
272
273
|
expect(
|
|
273
274
|
<DocComment>
|
|
274
|
-
|
|
275
|
+
<DocParamRef name="x" />
|
|
275
276
|
</DocComment>,
|
|
276
277
|
).toRenderTo(`
|
|
277
|
-
/// <paramref name="x" />
|
|
278
|
+
/// <paramref name="${"x"}" />
|
|
278
279
|
`);
|
|
279
280
|
});
|
|
280
281
|
|
|
281
282
|
it("define typeparamref", () => {
|
|
282
283
|
expect(
|
|
283
284
|
<DocComment>
|
|
284
|
-
|
|
285
|
+
<DocTypeParamRef name="T" />
|
|
285
286
|
</DocComment>,
|
|
286
287
|
).toRenderTo(`
|
|
287
288
|
/// <typeparamref name="T" />
|