@alloy-js/csharp 0.21.0-dev.3 → 0.21.0-dev.5
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/method/method.js +10 -2
- package/dist/src/components/method/method.js.map +1 -1
- package/dist/src/components/method/method.test.js +61 -0
- package/dist/src/components/method/method.test.js.map +1 -1
- package/dist/src/components/parameters/parameters.d.ts.map +1 -1
- package/dist/src/components/parameters/parameters.js +2 -2
- package/dist/src/components/parameters/parameters.js.map +1 -1
- package/dist/src/components/property/property.d.ts.map +1 -1
- package/dist/src/components/property/property.js +21 -12
- package/dist/src/components/property/property.js.map +1 -1
- package/dist/src/components/property/property.test.js +28 -0
- package/dist/src/components/property/property.test.js.map +1 -1
- package/dist/src/symbols/reference.js +2 -2
- package/dist/src/symbols/reference.js.map +1 -1
- package/dist/test/utils.d.ts +4 -2
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +5 -4
- package/dist/test/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/method/method.test.tsx +49 -0
- package/src/components/method/method.tsx +7 -4
- package/src/components/parameters/parameters.tsx +7 -2
- package/src/components/property/property.test.tsx +25 -0
- package/src/components/property/property.tsx +22 -11
- package/src/symbols/reference.tsx +2 -2
- package/test/utils.tsx +6 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alloy-js/csharp",
|
|
3
|
-
"version": "0.21.0-dev.
|
|
3
|
+
"version": "0.21.0-dev.5",
|
|
4
4
|
"description": "Alloy components for CSharp language.",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"author": "jhendrix@microsoft.com",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@alloy-js/core": "~0.20.0 || >= 0.21.0-dev.
|
|
23
|
+
"@alloy-js/core": "~0.20.0 || >= 0.21.0-dev.2",
|
|
24
24
|
"change-case": "^5.4.4",
|
|
25
25
|
"marked": "^16.1.1",
|
|
26
26
|
"pathe": "^2.0.3"
|
|
@@ -158,3 +158,52 @@ it("use expression body form", () => {
|
|
|
158
158
|
}
|
|
159
159
|
`);
|
|
160
160
|
});
|
|
161
|
+
|
|
162
|
+
describe("format", () => {
|
|
163
|
+
it("split expression after => if too long", () => {
|
|
164
|
+
expect(
|
|
165
|
+
<TestNamespace printWidth={60}>
|
|
166
|
+
<ClassDeclaration name="Test">
|
|
167
|
+
<Method public override name="ThisIsAVeryLongMethodName" expression>
|
|
168
|
+
this.WithAVeryLongPropertyName.AndAnEvenLongerMemberName
|
|
169
|
+
</Method>
|
|
170
|
+
</ClassDeclaration>
|
|
171
|
+
</TestNamespace>,
|
|
172
|
+
).toRenderTo(`
|
|
173
|
+
class Test
|
|
174
|
+
{
|
|
175
|
+
public override void ThisIsAVeryLongMethodName() =>
|
|
176
|
+
this.WithAVeryLongPropertyName.AndAnEvenLongerMemberName;
|
|
177
|
+
}
|
|
178
|
+
`);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("split parameters first if too long", () => {
|
|
182
|
+
expect(
|
|
183
|
+
<TestNamespace printWidth={60}>
|
|
184
|
+
<ClassDeclaration name="Test">
|
|
185
|
+
<Method
|
|
186
|
+
public
|
|
187
|
+
override
|
|
188
|
+
name="ThisIsAVeryLongMethodName"
|
|
189
|
+
expression
|
|
190
|
+
parameters={[
|
|
191
|
+
{ name: "firstParameter", type: "int" },
|
|
192
|
+
{ name: "secondParameter", type: "string" },
|
|
193
|
+
]}
|
|
194
|
+
>
|
|
195
|
+
this.Short
|
|
196
|
+
</Method>
|
|
197
|
+
</ClassDeclaration>
|
|
198
|
+
</TestNamespace>,
|
|
199
|
+
).toRenderTo(`
|
|
200
|
+
class Test
|
|
201
|
+
{
|
|
202
|
+
public override void ThisIsAVeryLongMethodName(
|
|
203
|
+
int firstParameter,
|
|
204
|
+
string secondParameter
|
|
205
|
+
) => this.Short;
|
|
206
|
+
}
|
|
207
|
+
`);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
@@ -154,9 +154,12 @@ export function Method(props: MethodProps) {
|
|
|
154
154
|
|
|
155
155
|
const ExpressionBody = (props: { children?: Children }) => {
|
|
156
156
|
return (
|
|
157
|
-
|
|
158
|
-
{" =>
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
<group>
|
|
158
|
+
{" =>"}
|
|
159
|
+
<indent>
|
|
160
|
+
<line />
|
|
161
|
+
{props.children};
|
|
162
|
+
</indent>
|
|
163
|
+
</group>
|
|
161
164
|
);
|
|
162
165
|
};
|
|
@@ -51,9 +51,14 @@ export function Parameters(props: ParametersProps) {
|
|
|
51
51
|
<group>
|
|
52
52
|
{"("}
|
|
53
53
|
{props.parameters && (
|
|
54
|
-
<Indent
|
|
54
|
+
<Indent nobreak>
|
|
55
55
|
<For each={props.parameters} joiner={", "}>
|
|
56
|
-
{(param) =>
|
|
56
|
+
{(param) => (
|
|
57
|
+
<>
|
|
58
|
+
<softline />
|
|
59
|
+
<Parameter {...param} />
|
|
60
|
+
</>
|
|
61
|
+
)}
|
|
57
62
|
</For>
|
|
58
63
|
</Indent>
|
|
59
64
|
)}
|
|
@@ -207,3 +207,28 @@ it("specify attributes", () => {
|
|
|
207
207
|
}
|
|
208
208
|
`);
|
|
209
209
|
});
|
|
210
|
+
|
|
211
|
+
describe("format", () => {
|
|
212
|
+
it("split after = if initializer too long", () => {
|
|
213
|
+
expect(
|
|
214
|
+
<TestNamespace printWidth={60}>
|
|
215
|
+
<ClassDeclaration name="Test">
|
|
216
|
+
<Property
|
|
217
|
+
public
|
|
218
|
+
get
|
|
219
|
+
set
|
|
220
|
+
name="ThisIsAVeryLongPropertyName"
|
|
221
|
+
type="string"
|
|
222
|
+
initializer={`"Some very long initializer value"`}
|
|
223
|
+
/>
|
|
224
|
+
</ClassDeclaration>
|
|
225
|
+
</TestNamespace>,
|
|
226
|
+
).toRenderTo(`
|
|
227
|
+
class Test
|
|
228
|
+
{
|
|
229
|
+
public string ThisIsAVeryLongPropertyName { get; set; } =
|
|
230
|
+
"Some very long initializer value";
|
|
231
|
+
}
|
|
232
|
+
`);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Block,
|
|
3
2
|
Children,
|
|
4
|
-
code,
|
|
5
3
|
createSymbolSlot,
|
|
6
4
|
List,
|
|
7
5
|
MemberDeclaration,
|
|
@@ -142,15 +140,28 @@ export function Property(props: PropertyProps) {
|
|
|
142
140
|
<AttributeList attributes={props.attributes} endline />
|
|
143
141
|
{modifiers}
|
|
144
142
|
<TypeSlot>{props.type}</TypeSlot>
|
|
145
|
-
{props.nullable && "?"} <MemberName />{" "}
|
|
146
|
-
<
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
143
|
+
{props.nullable && "?"} <MemberName /> {"{ "}
|
|
144
|
+
<List joiner=" ">
|
|
145
|
+
{props.get && "get;"}
|
|
146
|
+
{props.set && "set;"}
|
|
147
|
+
{props.init && "init;"}
|
|
148
|
+
</List>
|
|
149
|
+
{" }"}
|
|
150
|
+
{props.initializer && (
|
|
151
|
+
<PropertyInitializer>{props.initializer}</PropertyInitializer>
|
|
152
|
+
)}
|
|
154
153
|
</MemberDeclaration>
|
|
155
154
|
);
|
|
156
155
|
}
|
|
156
|
+
|
|
157
|
+
function PropertyInitializer(props: { children: Children }) {
|
|
158
|
+
return (
|
|
159
|
+
<group>
|
|
160
|
+
{" ="}
|
|
161
|
+
<indent>
|
|
162
|
+
<line />
|
|
163
|
+
{props.children};
|
|
164
|
+
</indent>
|
|
165
|
+
</group>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
@@ -17,7 +17,7 @@ export function ref(
|
|
|
17
17
|
const resolveResult = resolve<CSharpScope, CSharpSymbol>(refkey as Refkey);
|
|
18
18
|
return memo(() => {
|
|
19
19
|
if (resolveResult.value === undefined) {
|
|
20
|
-
return [
|
|
20
|
+
return [`unresolvedRefkey(refkey)`, undefined];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const result = resolveResult.value;
|
|
@@ -26,7 +26,7 @@ export function ref(
|
|
|
26
26
|
|
|
27
27
|
if (!commonScope) {
|
|
28
28
|
// this shouldn't be possible in csharp.
|
|
29
|
-
return [
|
|
29
|
+
return [`unresolvedRefkey(refkey)`, undefined];
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
if (
|
package/test/utils.tsx
CHANGED
|
@@ -3,12 +3,15 @@ import * as coretest from "@alloy-js/core/testing";
|
|
|
3
3
|
import { expect } from "vitest";
|
|
4
4
|
import * as csharp from "../src/index.js";
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export interface TestNamespaceProps extends csharp.CSharpFormatOptions {
|
|
7
7
|
children: core.Children;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
|
+
export function TestNamespace(props: TestNamespaceProps): core.Children {
|
|
9
10
|
return (
|
|
10
11
|
<core.Output namePolicy={csharp.createCSharpNamePolicy()}>
|
|
11
|
-
<csharp.SourceFile path="Test.cs"
|
|
12
|
+
<csharp.SourceFile path="Test.cs" {...props}>
|
|
13
|
+
{props.children}
|
|
14
|
+
</csharp.SourceFile>
|
|
12
15
|
</core.Output>
|
|
13
16
|
);
|
|
14
17
|
}
|