@alloy-js/csharp 0.21.0-dev.4 → 0.21.0-dev.6
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/components/var/declaration.d.ts +2 -0
- package/dist/src/components/var/declaration.d.ts.map +1 -1
- package/dist/src/components/var/declaration.js +4 -1
- package/dist/src/components/var/declaration.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 +1 -1
- 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/components/var/declaration.tsx +7 -0
- package/temp/api.json +27 -0
- package/test/utils.tsx +6 -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
|
+
}
|
|
@@ -19,6 +19,9 @@ export interface VarDeclarationProps
|
|
|
19
19
|
refkey?: Refkey;
|
|
20
20
|
/** Variable value */
|
|
21
21
|
children?: Children;
|
|
22
|
+
|
|
23
|
+
/** Constant variable. Add the const modifier. */
|
|
24
|
+
const?: boolean;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
/**
|
|
@@ -46,8 +49,12 @@ export function VarDeclaration(props: VarDeclarationProps) {
|
|
|
46
49
|
const sym = createVariableSymbol(props.name, {
|
|
47
50
|
refkeys: props.refkey,
|
|
48
51
|
});
|
|
52
|
+
if (props.const && !props.type) {
|
|
53
|
+
throw new Error("Implicitly-typed variables cannot be constant");
|
|
54
|
+
}
|
|
49
55
|
return (
|
|
50
56
|
<Declaration symbol={sym}>
|
|
57
|
+
{props.const ? "const " : ""}
|
|
51
58
|
{props.type ?? "var"} <Name /> = {props.children};
|
|
52
59
|
</Declaration>
|
|
53
60
|
);
|
package/temp/api.json
CHANGED
|
@@ -13886,6 +13886,33 @@
|
|
|
13886
13886
|
"endIndex": 2
|
|
13887
13887
|
}
|
|
13888
13888
|
},
|
|
13889
|
+
{
|
|
13890
|
+
"kind": "PropertySignature",
|
|
13891
|
+
"canonicalReference": "@alloy-js/csharp!VarDeclarationProps#const:member",
|
|
13892
|
+
"docComment": "/**\n * Constant variable. Add the const modifier.\n */\n",
|
|
13893
|
+
"excerptTokens": [
|
|
13894
|
+
{
|
|
13895
|
+
"kind": "Content",
|
|
13896
|
+
"text": "const?: "
|
|
13897
|
+
},
|
|
13898
|
+
{
|
|
13899
|
+
"kind": "Content",
|
|
13900
|
+
"text": "boolean"
|
|
13901
|
+
},
|
|
13902
|
+
{
|
|
13903
|
+
"kind": "Content",
|
|
13904
|
+
"text": ";"
|
|
13905
|
+
}
|
|
13906
|
+
],
|
|
13907
|
+
"isReadonly": false,
|
|
13908
|
+
"isOptional": true,
|
|
13909
|
+
"releaseTag": "Public",
|
|
13910
|
+
"name": "const",
|
|
13911
|
+
"propertyTypeTokenRange": {
|
|
13912
|
+
"startIndex": 1,
|
|
13913
|
+
"endIndex": 2
|
|
13914
|
+
}
|
|
13915
|
+
},
|
|
13889
13916
|
{
|
|
13890
13917
|
"kind": "PropertySignature",
|
|
13891
13918
|
"canonicalReference": "@alloy-js/csharp!VarDeclarationProps#name:member",
|
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
|
}
|