@alloy-js/csharp 0.20.0-dev.0 → 0.20.0-dev.2

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.
Files changed (27) hide show
  1. package/dist/src/components/{ClassDeclaration.d.ts → class/declaration.d.ts} +29 -11
  2. package/dist/src/components/class/declaration.d.ts.map +1 -0
  3. package/dist/src/components/{ClassDeclaration.js → class/declaration.js} +22 -14
  4. package/dist/src/components/class/declaration.test.d.ts +2 -0
  5. package/dist/src/components/class/declaration.test.d.ts.map +1 -0
  6. package/dist/{test/class-declaration.test.js → src/components/class/declaration.test.js} +190 -100
  7. package/dist/src/components/constructor/constructor.test.js +1 -1
  8. package/dist/src/components/field/field.test.js +1 -1
  9. package/dist/src/components/index.d.ts +1 -1
  10. package/dist/src/components/index.d.ts.map +1 -1
  11. package/dist/src/components/index.js +1 -1
  12. package/dist/src/components/parameters/parameters.d.ts.map +1 -1
  13. package/dist/src/components/parameters/parameters.js +1 -1
  14. package/dist/src/components/property/property.test.js +1 -1
  15. package/dist/tsconfig.tsbuildinfo +1 -1
  16. package/package.json +2 -2
  17. package/{test/class-declaration.test.tsx → src/components/class/declaration.test.tsx} +204 -125
  18. package/src/components/{ClassDeclaration.tsx → class/declaration.tsx} +53 -22
  19. package/src/components/constructor/constructor.test.tsx +1 -1
  20. package/src/components/field/field.test.tsx +1 -1
  21. package/src/components/index.ts +1 -1
  22. package/src/components/parameters/parameters.tsx +3 -1
  23. package/src/components/property/property.test.tsx +1 -1
  24. package/temp/api.json +41 -9
  25. package/dist/src/components/ClassDeclaration.d.ts.map +0 -1
  26. package/dist/test/class-declaration.test.d.ts +0 -2
  27. package/dist/test/class-declaration.test.d.ts.map +0 -1
@@ -1,18 +1,19 @@
1
- import * as core from "@alloy-js/core";
2
- import { AccessModifiers } from "../modifiers.js";
3
- import { AttributesProp } from "./attributes/attributes.jsx";
4
- import { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
1
+ import { Children, DeclarationProps, Refkey } from "@alloy-js/core";
2
+ import { AccessModifiers } from "../../modifiers.js";
3
+ import { AttributesProp } from "../attributes/attributes.jsx";
4
+ import { ParameterProps } from "../parameters/parameters.jsx";
5
+ import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
5
6
  export interface ClassModifiers {
6
7
  readonly abstract?: boolean;
7
8
  readonly partial?: boolean;
8
9
  readonly sealed?: boolean;
9
10
  readonly static?: boolean;
10
11
  }
11
- export interface ClassDeclarationProps extends Omit<core.DeclarationProps, "nameKind">, AccessModifiers, ClassModifiers {
12
+ export interface ClassDeclarationProps extends Omit<DeclarationProps, "nameKind">, AccessModifiers, ClassModifiers {
12
13
  name: string;
13
14
  /** Doc comment */
14
- doc?: core.Children;
15
- refkey?: core.Refkey;
15
+ doc?: Children;
16
+ refkey?: Refkey;
16
17
  /**
17
18
  * Type parameters for the class
18
19
  *
@@ -27,9 +28,9 @@ export interface ClassDeclarationProps extends Omit<core.DeclarationProps, "name
27
28
  */
28
29
  typeParameters?: (string | TypeParameterProps)[];
29
30
  /** Base class that this class extends */
30
- baseType?: core.Children;
31
+ baseType?: Children;
31
32
  /** Interfaces this class implements */
32
- interfaceTypes?: core.Children[];
33
+ interfaceTypes?: Children[];
33
34
  /**
34
35
  * Define attributes to attach
35
36
  * @example
@@ -47,6 +48,23 @@ export interface ClassDeclarationProps extends Omit<core.DeclarationProps, "name
47
48
  * ```
48
49
  */
49
50
  attributes?: AttributesProp;
51
+ /**
52
+ * Set the primary constructor parameters
53
+ * @example
54
+ * ```tsx
55
+ * <ClassDeclaration name="MyClass" primaryConstructor={[
56
+ * {name: "value", type: "int"}
57
+ * ]}>
58
+ * ```
59
+ * This will produce:
60
+ * ```csharp
61
+ * public class MyClass(int value)
62
+ * {
63
+ *
64
+ * }
65
+ * ```
66
+ */
67
+ primaryConstructor?: ParameterProps[];
50
68
  }
51
69
  /**
52
70
  * CSharp class declaration.
@@ -72,5 +90,5 @@ export interface ClassDeclarationProps extends Omit<core.DeclarationProps, "name
72
90
  * }
73
91
  * ```
74
92
  */
75
- export declare function ClassDeclaration(props: ClassDeclarationProps): core.Children;
76
- //# sourceMappingURL=ClassDeclaration.d.ts.map
93
+ export declare function ClassDeclaration(props: ClassDeclarationProps): Children;
94
+ //# sourceMappingURL=declaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/class/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAER,gBAAgB,EAGhB,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE7E,OAAO,EAAE,cAAc,EAAc,MAAM,8BAA8B,CAAC;AAE1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAG3E,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B;AAUD,MAAM,WAAW,qBACf,SAAQ,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EACxC,eAAe,EACf,cAAc;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,CAAC;IAEjD,yCAAyC;IACzC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB,uCAAuC;IACvC,cAAc,CAAC,EAAE,QAAQ,EAAE,CAAC;IAE5B;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;IAE5B;;;;;;;;;;;;;;;OAeG;IACH,kBAAkB,CAAC,EAAE,cAAc,EAAE,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,YAkD5D"}
@@ -1,15 +1,14 @@
1
1
  import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import * as core from "@alloy-js/core";
3
- import { join } from "@alloy-js/core";
4
- import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../modifiers.js";
5
- import { useCSharpNamePolicy } from "../name-policy.js";
6
- import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
7
- import { CSharpMemberScope } from "../symbols/scopes.js";
8
- import { AttributeList } from "./attributes/attributes.js";
9
- import { DocWhen } from "./doc/comment.js";
10
- import { Name } from "./Name.js";
11
- import { TypeParameterConstraints } from "./type-parameters/type-parameter-constraints.js";
12
- import { TypeParameters } from "./type-parameters/type-parameters.js";
2
+ import { Block, Declaration, join, Name, 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 } from "../../symbols/scopes.js";
7
+ import { AttributeList } from "../attributes/attributes.js";
8
+ import { DocWhen } from "../doc/comment.js";
9
+ import { Parameters } from "../parameters/parameters.js";
10
+ import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
11
+ import { TypeParameters } from "../type-parameters/type-parameters.js";
13
12
  const getClassModifiers = makeModifiers(["abstract", "partial", "sealed", "static"]);
14
13
 
15
14
  // properties for creating a class
@@ -56,7 +55,7 @@ export function ClassDeclaration(props) {
56
55
  joiner: ", "
57
56
  }))] : null;
58
57
  const modifiers = computeModifiersPrefix([getAccessModifier(props), getClassModifiers(props)]);
59
- return _$createComponent(core.Declaration, {
58
+ return _$createComponent(Declaration, {
60
59
  symbol: thisClassSymbol,
61
60
  get children() {
62
61
  return [_$createComponent(DocWhen, {
@@ -72,14 +71,23 @@ export function ClassDeclaration(props) {
72
71
  get parameters() {
73
72
  return props.typeParameters;
74
73
  }
74
+ })), _$memo(() => _$memo(() => !!props.primaryConstructor)() && _$createComponent(Scope, {
75
+ value: thisClassScope,
76
+ get children() {
77
+ return _$createComponent(Parameters, {
78
+ get parameters() {
79
+ return props.primaryConstructor;
80
+ }
81
+ });
82
+ }
75
83
  })), base, _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
76
84
  get parameters() {
77
85
  return props.typeParameters;
78
86
  }
79
- })), _$memo(() => !props.children && ";"), _$memo(() => _$memo(() => !!props.children)() && _$createComponent(core.Block, {
87
+ })), _$memo(() => !props.children && ";"), _$memo(() => _$memo(() => !!props.children)() && _$createComponent(Block, {
80
88
  newline: true,
81
89
  get children() {
82
- return _$createComponent(core.Scope, {
90
+ return _$createComponent(Scope, {
83
91
  value: thisClassScope,
84
92
  get children() {
85
93
  return props.children;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=declaration.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration.test.d.ts","sourceRoot":"","sources":["../../../../src/components/class/declaration.test.tsx"],"names":[],"mappings":""}
@@ -1,17 +1,31 @@
1
1
  import { createComponent as _$createComponent, mergeProps as _$mergeProps, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
- import * as core from "@alloy-js/core";
3
- import { List, refkey } from "@alloy-js/core";
2
+ import { code, createNamePolicy, List, NamePolicyContext, Output, refkey, render } from "@alloy-js/core";
4
3
  import * as coretest from "@alloy-js/core/testing";
5
4
  import { describe, expect, it } from "vitest";
6
- import { Attribute } from "../src/components/attributes/attributes.js";
7
- import { Field } from "../src/components/field/field.js";
8
- import { Constructor } from "../src/components/stc/index.js";
9
- import * as csharp from "../src/index.js";
10
- import { ClassDeclaration, Property, SourceFile } from "../src/index.js";
11
- import * as utils from "./utils.js";
12
- import { findFile } from "./utils.js";
5
+ import { findFile, TestNamespace, toSourceText } from "../../../test/utils.js";
6
+ import { createCSharpNamePolicy } from "../../name-policy.js";
7
+ import { Attribute } from "../attributes/attributes.js";
8
+ import { Field } from "../field/field.js";
9
+ import { Method } from "../method/method.js";
10
+ import { Namespace } from "../Namespace.js";
11
+ import { Property } from "../property/property.js";
12
+ import { SourceFile } from "../SourceFile.js";
13
+ import { Constructor, EnumDeclaration, EnumMember } from "../stc/index.js";
14
+ import { ClassDeclaration } from "./declaration.js";
15
+ function Wrapper({
16
+ children
17
+ }) {
18
+ return _$createComponent(TestNamespace, {
19
+ get children() {
20
+ return _$createComponent(SourceFile, {
21
+ path: "Test.cs",
22
+ children: children
23
+ });
24
+ }
25
+ });
26
+ }
13
27
  it("declares class with no members", () => {
14
- expect(_$createComponent(utils.TestNamespace, {
28
+ expect(_$createComponent(TestNamespace, {
15
29
  get children() {
16
30
  return _$createComponent(ClassDeclaration, {
17
31
  name: "TestClass"
@@ -23,7 +37,7 @@ it("declares class with no members", () => {
23
37
  });
24
38
  describe("modifiers", () => {
25
39
  it.each(["public", "private"])("%s", mod => {
26
- expect(_$createComponent(utils.TestNamespace, {
40
+ expect(_$createComponent(TestNamespace, {
27
41
  get children() {
28
42
  return _$createComponent(ClassDeclaration, _$mergeProps({
29
43
  [mod]: true
@@ -36,7 +50,7 @@ describe("modifiers", () => {
36
50
  `);
37
51
  });
38
52
  it.each(["partial", "abstract", "static", "sealed"])("%s", mod => {
39
- expect(_$createComponent(utils.TestNamespace, {
53
+ expect(_$createComponent(TestNamespace, {
40
54
  get children() {
41
55
  return _$createComponent(ClassDeclaration, _$mergeProps({
42
56
  [mod]: true
@@ -49,7 +63,7 @@ describe("modifiers", () => {
49
63
  `);
50
64
  });
51
65
  it("combines modifiers", () => {
52
- expect(_$createComponent(utils.TestNamespace, {
66
+ expect(_$createComponent(TestNamespace, {
53
67
  get children() {
54
68
  return _$createComponent(ClassDeclaration, {
55
69
  "public": true,
@@ -65,9 +79,9 @@ describe("modifiers", () => {
65
79
  });
66
80
  describe("base", () => {
67
81
  it("define base class", () => {
68
- expect(_$createComponent(utils.TestNamespace, {
82
+ expect(_$createComponent(TestNamespace, {
69
83
  get children() {
70
- return _$createComponent(csharp.ClassDeclaration, {
84
+ return _$createComponent(ClassDeclaration, {
71
85
  name: "TestClass",
72
86
  baseType: "Foo"
73
87
  });
@@ -77,9 +91,9 @@ describe("base", () => {
77
91
  `);
78
92
  });
79
93
  it("define multiple interface types", () => {
80
- expect(_$createComponent(utils.TestNamespace, {
94
+ expect(_$createComponent(TestNamespace, {
81
95
  get children() {
82
- return _$createComponent(csharp.ClassDeclaration, {
96
+ return _$createComponent(ClassDeclaration, {
83
97
  name: "TestClass",
84
98
  interfaceTypes: ["Foo", "Bar"]
85
99
  });
@@ -89,9 +103,9 @@ describe("base", () => {
89
103
  `);
90
104
  });
91
105
  it("define base class and multiple interface types", () => {
92
- expect(_$createComponent(utils.TestNamespace, {
106
+ expect(_$createComponent(TestNamespace, {
93
107
  get children() {
94
- return _$createComponent(csharp.ClassDeclaration, {
108
+ return _$createComponent(ClassDeclaration, {
95
109
  name: "TestClass",
96
110
  baseType: "BaseClass",
97
111
  interfaceTypes: ["Foo", "Bar"]
@@ -103,7 +117,7 @@ describe("base", () => {
103
117
  });
104
118
  });
105
119
  it("declares class with some members", () => {
106
- const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
120
+ const res = toSourceText(_$createComponent(ClassDeclaration, {
107
121
  "public": true,
108
122
  name: "TestClass",
109
123
  get children() {
@@ -134,16 +148,16 @@ it("declares class with some members", () => {
134
148
  `);
135
149
  });
136
150
  it("declares class with some methods", () => {
137
- const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
151
+ const res = toSourceText(_$createComponent(ClassDeclaration, {
138
152
  "public": true,
139
153
  name: "TestClass",
140
154
  get children() {
141
- return _$createComponent(core.List, {
155
+ return _$createComponent(List, {
142
156
  get children() {
143
- return [_$createComponent(csharp.Method, {
157
+ return [_$createComponent(Method, {
144
158
  "public": true,
145
159
  name: "MethodOne"
146
- }), _$createComponent(csharp.Method, {
160
+ }), _$createComponent(Method, {
147
161
  "private": true,
148
162
  virtual: true,
149
163
  name: "MethodTwo"
@@ -164,9 +178,9 @@ it("declares class with some methods", () => {
164
178
  `);
165
179
  });
166
180
  it("uses refkeys for members, params, and return type", () => {
167
- const inputTypeRefkey = core.refkey();
168
- const testResultTypeRefkey = core.refkey();
169
- const enumTypeRefkey = core.refkey();
181
+ const inputTypeRefkey = refkey();
182
+ const testResultTypeRefkey = refkey();
183
+ const enumTypeRefkey = refkey();
170
184
  const params = [{
171
185
  name: "IntParam",
172
186
  type: "int"
@@ -174,43 +188,43 @@ it("uses refkeys for members, params, and return type", () => {
174
188
  name: "BodyParam",
175
189
  type: inputTypeRefkey
176
190
  }];
177
- const res = core.render(_$createComponent(core.Output, {
191
+ const res = render(_$createComponent(Output, {
178
192
  get namePolicy() {
179
- return csharp.createCSharpNamePolicy();
193
+ return createCSharpNamePolicy();
180
194
  },
181
195
  get children() {
182
- return _$createComponent(csharp.Namespace, {
196
+ return _$createComponent(Namespace, {
183
197
  name: "TestCode",
184
198
  get children() {
185
- return _$createComponent(csharp.SourceFile, {
199
+ return _$createComponent(SourceFile, {
186
200
  path: "Test.cs",
187
201
  get children() {
188
- return [_$createComponent(csharp.EnumDeclaration, {
202
+ return [_$createComponent(EnumDeclaration, {
189
203
  "public": true,
190
204
  name: "TestEnum",
191
205
  refkey: enumTypeRefkey,
192
206
  get children() {
193
- return _$createComponent(core.List, {
207
+ return _$createComponent(List, {
194
208
  comma: true,
195
209
  hardline: true,
196
210
  get children() {
197
- return [_$createComponent(csharp.EnumMember, {
211
+ return [_$createComponent(EnumMember, {
198
212
  name: "One"
199
- }), _$createComponent(csharp.EnumMember, {
213
+ }), _$createComponent(EnumMember, {
200
214
  name: "Two"
201
215
  })];
202
216
  }
203
217
  });
204
218
  }
205
- }), _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassDeclaration, {
219
+ }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
206
220
  "public": true,
207
221
  name: "TestInput",
208
222
  refkey: inputTypeRefkey
209
- }), _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassDeclaration, {
223
+ }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
210
224
  "public": true,
211
225
  name: "TestResult",
212
226
  refkey: testResultTypeRefkey
213
- }), _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassDeclaration, {
227
+ }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
214
228
  "public": true,
215
229
  name: "TestClass",
216
230
  get children() {
@@ -218,7 +232,7 @@ it("uses refkeys for members, params, and return type", () => {
218
232
  "private": true,
219
233
  name: "MemberOne",
220
234
  type: enumTypeRefkey
221
- }), _$createIntrinsic("hbr", {}), _$createComponent(csharp.Method, {
235
+ }), _$createIntrinsic("hbr", {}), _$createComponent(Method, {
222
236
  "public": true,
223
237
  name: "MethodOne",
224
238
  parameters: params,
@@ -265,7 +279,7 @@ describe("with type parameters", () => {
265
279
  name: "U",
266
280
  refkey: refkey()
267
281
  }];
268
- expect(_$createComponent(utils.TestNamespace, {
282
+ expect(_$createComponent(TestNamespace, {
269
283
  get children() {
270
284
  return _$createComponent(SourceFile, {
271
285
  path: "Test.cs",
@@ -318,7 +332,7 @@ describe("with type parameters", () => {
318
332
  name: "U",
319
333
  constraints: "IBar"
320
334
  }];
321
- expect(_$createComponent(utils.TestNamespace, {
335
+ expect(_$createComponent(TestNamespace, {
322
336
  get children() {
323
337
  return _$createComponent(ClassDeclaration, {
324
338
  "public": true,
@@ -338,30 +352,31 @@ describe("with type parameters", () => {
338
352
  });
339
353
  });
340
354
  it("declares class with invalid members", () => {
341
- const decl = _$createComponent(csharp.ClassDeclaration, {
355
+ const decl = _$createComponent(ClassDeclaration, {
342
356
  "public": true,
343
357
  name: "TestClass",
344
358
  get children() {
345
- return [_$createComponent(csharp.EnumMember, {
359
+ return [_$createComponent(EnumMember, {
346
360
  name: "One"
347
- }), ",", _$createIntrinsic("hbr", {}), _$createComponent(csharp.EnumMember, {
361
+ }), ",", _$createIntrinsic("hbr", {}), _$createComponent(EnumMember, {
348
362
  name: "Two"
349
363
  })];
350
364
  }
351
365
  });
352
- expect(() => utils.toSourceText(decl)).toThrow("can't define an enum member outside of an enum-decl scope");
366
+ expect(() => toSourceText(decl)).toThrow("can't define an enum member outside of an enum-decl scope");
353
367
  });
354
- it("declares class with constructor", () => {
355
- const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
356
- "public": true,
357
- name: "TestClass",
358
- get children() {
359
- return _$createComponent(Constructor, {
360
- "public": true
361
- });
362
- }
363
- }));
364
- expect(res).toBe(coretest.d`
368
+ describe("constructor", () => {
369
+ it("declares with constructor", () => {
370
+ const res = toSourceText(_$createComponent(ClassDeclaration, {
371
+ "public": true,
372
+ name: "TestClass",
373
+ get children() {
374
+ return _$createComponent(Constructor, {
375
+ "public": true
376
+ });
377
+ }
378
+ }));
379
+ expect(res).toBe(coretest.d`
365
380
  namespace TestCode
366
381
  {
367
382
  public class TestClass
@@ -370,48 +385,48 @@ it("declares class with constructor", () => {
370
385
  }
371
386
  }
372
387
  `);
373
- });
374
- it("declares class with constructor params and assigns values to fields", () => {
375
- const thisNameRefkey = core.refkey();
376
- const thisSizeRefkey = core.refkey();
377
- const paramNameRefkey = core.refkey();
378
- const paramSizeRefkey = core.refkey();
379
- const ctorParams = [{
380
- name: "name",
381
- type: "string",
382
- refkey: paramNameRefkey
383
- }, {
384
- name: "size",
385
- type: "int",
386
- refkey: paramSizeRefkey
387
- }];
388
- const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
389
- "public": true,
390
- name: "TestClass",
391
- get children() {
392
- return [_$createComponent(Field, {
393
- "private": true,
394
- name: "name",
395
- type: "string",
396
- refkey: thisNameRefkey
397
- }), _$createIntrinsic("hbr", {}), _$createComponent(Field, {
398
- "private": true,
399
- name: "size",
400
- type: "int",
401
- refkey: thisSizeRefkey
402
- }), _$createIntrinsic("hbr", {}), _$createComponent(Constructor, {
403
- "public": true,
404
- parameters: ctorParams,
405
- get children() {
406
- return [thisNameRefkey, " = ", paramNameRefkey, ";", _$createIntrinsic("hbr", {}), thisSizeRefkey, " = ", paramSizeRefkey, ";"];
407
- }
408
- })];
409
- }
410
- }));
388
+ });
389
+ it("declares with constructor params and assigns values to fields", () => {
390
+ const thisNameRefkey = refkey();
391
+ const thisSizeRefkey = refkey();
392
+ const paramNameRefkey = refkey();
393
+ const paramSizeRefkey = refkey();
394
+ const ctorParams = [{
395
+ name: "name",
396
+ type: "string",
397
+ refkey: paramNameRefkey
398
+ }, {
399
+ name: "size",
400
+ type: "int",
401
+ refkey: paramSizeRefkey
402
+ }];
403
+ const res = toSourceText(_$createComponent(ClassDeclaration, {
404
+ "public": true,
405
+ name: "TestClass",
406
+ get children() {
407
+ return [_$createComponent(Field, {
408
+ "private": true,
409
+ name: "name",
410
+ type: "string",
411
+ refkey: thisNameRefkey
412
+ }), _$createIntrinsic("hbr", {}), _$createComponent(Field, {
413
+ "private": true,
414
+ name: "size",
415
+ type: "int",
416
+ refkey: thisSizeRefkey
417
+ }), _$createIntrinsic("hbr", {}), _$createComponent(Constructor, {
418
+ "public": true,
419
+ parameters: ctorParams,
420
+ get children() {
421
+ return [thisNameRefkey, " = ", paramNameRefkey, ";", _$createIntrinsic("hbr", {}), thisSizeRefkey, " = ", paramSizeRefkey, ";"];
422
+ }
423
+ })];
424
+ }
425
+ }));
411
426
 
412
- // TODO: assignments to members should have this. prefix
413
- // e.g. this.name = name;
414
- expect(res).toBe(coretest.d`
427
+ // TODO: assignments to members should have this. prefix
428
+ // e.g. this.name = name;
429
+ expect(res).toBe(coretest.d`
415
430
  namespace TestCode
416
431
  {
417
432
  public class TestClass
@@ -426,9 +441,84 @@ it("declares class with constructor params and assigns values to fields", () =>
426
441
  }
427
442
  }
428
443
  `);
444
+ });
445
+ it("declares primary constructor with args", () => {
446
+ const paramNameRefkey = refkey();
447
+ const paramSizeRefkey = refkey();
448
+ const ctorParams = [{
449
+ name: "name",
450
+ type: "string",
451
+ refkey: paramNameRefkey
452
+ }, {
453
+ name: "size",
454
+ type: "int",
455
+ refkey: paramSizeRefkey
456
+ }];
457
+ expect(_$createComponent(Wrapper, {
458
+ get children() {
459
+ return _$createComponent(ClassDeclaration, {
460
+ "public": true,
461
+ name: "TestClass",
462
+ primaryConstructor: ctorParams,
463
+ get children() {
464
+ return _$createComponent(Property, {
465
+ name: "PrettyName",
466
+ type: "string",
467
+ get: true,
468
+ initializer: code`$"{${paramNameRefkey}} {${paramSizeRefkey}}"`
469
+ });
470
+ }
471
+ });
472
+ }
473
+ })).toRenderTo(`
474
+ namespace TestCode
475
+ {
476
+ public class TestClass(string name, int size)
477
+ {
478
+ string PrettyName { get; } = $"{name} {size}";
479
+ }
480
+ }
481
+ `);
482
+ });
483
+ it("primary constructor params conflict with method", () => {
484
+ const ctorParams = [{
485
+ name: "name",
486
+ type: "string"
487
+ }];
488
+ expect(_$createComponent(Wrapper, {
489
+ get children() {
490
+ return _$createComponent(NamePolicyContext.Provider, {
491
+ get value() {
492
+ return createNamePolicy(x => x);
493
+ },
494
+ get children() {
495
+ return _$createComponent(ClassDeclaration, {
496
+ "public": true,
497
+ name: "TestClass",
498
+ primaryConstructor: ctorParams,
499
+ get children() {
500
+ return _$createComponent(Field, {
501
+ name: "name",
502
+ type: "string"
503
+ });
504
+ }
505
+ });
506
+ }
507
+ });
508
+ }
509
+ })).toRenderTo(`
510
+ namespace TestCode
511
+ {
512
+ public class TestClass(string name)
513
+ {
514
+ string name_2;
515
+ }
516
+ }
517
+ `);
518
+ });
429
519
  });
430
520
  it("specify doc comment", () => {
431
- expect(_$createComponent(utils.TestNamespace, {
521
+ expect(_$createComponent(TestNamespace, {
432
522
  get children() {
433
523
  return _$createComponent(ClassDeclaration, {
434
524
  name: "Test",
@@ -441,7 +531,7 @@ it("specify doc comment", () => {
441
531
  `);
442
532
  });
443
533
  it("supports class member doc comments", () => {
444
- expect(_$createComponent(utils.TestNamespace, {
534
+ expect(_$createComponent(TestNamespace, {
445
535
  get children() {
446
536
  return _$createComponent(ClassDeclaration, {
447
537
  name: "Test",
@@ -466,7 +556,7 @@ it("supports class member doc comments", () => {
466
556
  `);
467
557
  });
468
558
  it("specify attributes", () => {
469
- expect(_$createComponent(utils.TestNamespace, {
559
+ expect(_$createComponent(TestNamespace, {
470
560
  get children() {
471
561
  return _$createComponent(ClassDeclaration, {
472
562
  name: "Test",
@@ -2,7 +2,7 @@ import { createIntrinsic as _$createIntrinsic, createComponent as _$createCompon
2
2
  import { refkey } from "@alloy-js/core";
3
3
  import { expect, it } from "vitest";
4
4
  import { TestNamespace } from "../../../test/utils.js";
5
- import { ClassDeclaration } from "../ClassDeclaration.js";
5
+ import { ClassDeclaration } from "../class/declaration.js";
6
6
  import { SourceFile } from "../SourceFile.js";
7
7
  import { Constructor } from "./constructor.js";
8
8
  it("reference constructor parameters in body", () => {
@@ -2,7 +2,7 @@ import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$m
2
2
  import { List } from "@alloy-js/core";
3
3
  import { describe, expect, it } from "vitest";
4
4
  import { TestNamespace } from "../../../test/utils.js";
5
- import { ClassDeclaration } from "../ClassDeclaration.js";
5
+ import { ClassDeclaration } from "../class/declaration.js";
6
6
  import { Field } from "./field.js";
7
7
  function Wrapper(props) {
8
8
  return _$createComponent(TestNamespace, {
@@ -1,5 +1,5 @@
1
1
  export * from "./attributes/attributes.jsx";
2
- export * from "./ClassDeclaration.jsx";
2
+ export * from "./class/declaration.jsx";
3
3
  export * from "./constructor/constructor.jsx";
4
4
  export * from "./Declaration.js";
5
5
  export * from "./doc/comment.jsx";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,YAAY,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,YAAY,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  export * from "./attributes/attributes.js";
2
- export * from "./ClassDeclaration.js";
2
+ export * from "./class/declaration.js";
3
3
  export * from "./constructor/constructor.js";
4
4
  export * from "./Declaration.js";
5
5
  export * from "./doc/comment.js";
@@ -1 +1 @@
1
- {"version":3,"file":"parameters.d.ts","sourceRoot":"","sources":["../../../../src/components/parameters/parameters.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAKR,YAAY,EAEZ,MAAM,EACP,MAAM,gBAAgB,CAAC;AAMxB,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sCAAsC;IACtC,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,YAwB9C;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;CAC1C;AAED,wCAAwC;AACxC,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,YAehD"}
1
+ {"version":3,"file":"parameters.d.ts","sourceRoot":"","sources":["../../../../src/components/parameters/parameters.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAKR,YAAY,EAEZ,MAAM,EACP,MAAM,gBAAgB,CAAC;AAMxB,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sCAAsC;IACtC,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,YA0B9C;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;CAC1C;AAED,wCAAwC;AACxC,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,YAehD"}