@alloy-js/csharp 0.18.0-dev.16 → 0.18.0-dev.18
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 +14 -1
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +12 -25
- package/dist/src/components/ClassMethod.d.ts +14 -0
- package/dist/src/components/ClassMethod.d.ts.map +1 -1
- package/dist/src/components/ClassMethod.js +11 -1
- package/dist/src/components/index.d.ts +2 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +3 -1
- package/dist/src/components/interface/declaration.d.ts +14 -1
- package/dist/src/components/interface/declaration.d.ts.map +1 -1
- package/dist/src/components/interface/declaration.js +12 -25
- package/dist/src/components/interface/declaration.test.js +84 -0
- package/dist/src/components/interface/method.d.ts +14 -0
- package/dist/src/components/interface/method.d.ts.map +1 -1
- package/dist/src/components/interface/method.js +11 -1
- package/dist/src/components/interface/method.test.js +79 -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 +65 -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 +26 -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/test/class-declaration.test.js +79 -33
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/ClassDeclaration.tsx +23 -27
- package/src/components/ClassMethod.tsx +25 -1
- package/src/components/index.ts +2 -0
- package/src/components/interface/declaration.test.tsx +87 -0
- package/src/components/interface/declaration.tsx +23 -27
- package/src/components/interface/method.test.tsx +78 -0
- package/src/components/interface/method.tsx +24 -1
- 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 +19 -0
- package/src/components/type-parameters/type-parameters.tsx +72 -0
- package/src/components/var/declaration.test.tsx +59 -0
- package/src/components/var/declaration.tsx +47 -0
- package/src/name-policy.ts +1 -0
- package/temp/api.json +415 -23
- package/test/class-declaration.test.tsx +75 -25
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
2
|
import { AccessModifiers } from "../modifiers.js";
|
|
3
3
|
import { ParameterProps } from "./Parameters.jsx";
|
|
4
|
+
import { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
|
|
4
5
|
export interface ClassModifiers {
|
|
5
6
|
readonly abstract?: boolean;
|
|
6
7
|
readonly partial?: boolean;
|
|
@@ -12,7 +13,19 @@ export interface ClassDeclarationProps extends Omit<core.DeclarationProps, "name
|
|
|
12
13
|
/** Doc comment */
|
|
13
14
|
doc?: core.Children;
|
|
14
15
|
refkey?: core.Refkey;
|
|
15
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Type parameters for the class
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <ClassDeclaration name="MyClass" typeParameters={["T"]} />
|
|
22
|
+
* ```
|
|
23
|
+
* This will produce:
|
|
24
|
+
* ```csharp
|
|
25
|
+
* public class MyClass<T>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
typeParameters?: (string | TypeParameterProps)[];
|
|
16
29
|
/** Base class that this class extends */
|
|
17
30
|
baseType?: core.Children;
|
|
18
31
|
/** Interfaces this class implements */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/ClassDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EACL,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EAAE,cAAc,EAAc,MAAM,kBAAkB,CAAC;AAG9D,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,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,cAAc;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"ClassDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/ClassDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EACL,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EAAE,cAAc,EAAc,MAAM,kBAAkB,CAAC;AAG9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAG1E,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,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,cAAc;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IAErB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,CAAC;IAEjD,yCAAyC;IACzC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IAEzB,uCAAuC;IACvC,cAAc,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,iBA4C5D;AAED,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,UAAU,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC;IAC3B,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;CAC1B;AAGD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,iBAkC5D;AAGD,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;CACrB;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,iBA0BlD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import * as core from "@alloy-js/core";
|
|
3
3
|
import { join } from "@alloy-js/core";
|
|
4
4
|
import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../modifiers.js";
|
|
@@ -8,6 +8,8 @@ import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
|
|
|
8
8
|
import { Name } from "./Name.js";
|
|
9
9
|
import { Parameters } from "./Parameters.js";
|
|
10
10
|
import { DocWhen } from "./doc/comment.js";
|
|
11
|
+
import { TypeParameterConstraints } from "./type-parameters/type-parameter-constraints.js";
|
|
12
|
+
import { TypeParameters } from "./type-parameters/type-parameters.js";
|
|
11
13
|
const getClassModifiers = makeModifiers(["abstract", "partial", "sealed", "static"]);
|
|
12
14
|
|
|
13
15
|
// properties for creating a class
|
|
@@ -49,29 +51,6 @@ export function ClassDeclaration(props) {
|
|
|
49
51
|
const thisClassScope = new CSharpMemberScope("class-decl", {
|
|
50
52
|
owner: thisClassSymbol
|
|
51
53
|
});
|
|
52
|
-
let typeParams;
|
|
53
|
-
if (props.typeParameters) {
|
|
54
|
-
const typeParamNames = new Array();
|
|
55
|
-
for (const entry of Object.entries(props.typeParameters)) {
|
|
56
|
-
typeParamNames.push(useCSharpNamePolicy().getName(entry[0], "type-parameter"));
|
|
57
|
-
// create a symbol for each type param so its
|
|
58
|
-
// refkey resolves to the type param's name
|
|
59
|
-
new CSharpOutputSymbol(entry[0], {
|
|
60
|
-
scope: thisClassScope,
|
|
61
|
-
refkeys: entry[1]
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
typeParams = _$createIntrinsic("group", {
|
|
65
|
-
get children() {
|
|
66
|
-
return ["<", _$createComponent(core.For, {
|
|
67
|
-
each: typeParamNames,
|
|
68
|
-
comma: true,
|
|
69
|
-
line: true,
|
|
70
|
-
children: name => name
|
|
71
|
-
}), ">"];
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
54
|
const bases = [...(props.baseType ? [props.baseType] : []), ...(props.interfaceTypes || [])];
|
|
76
55
|
const base = bases.length > 0 ? [" : ", _$memo(() => join(bases, {
|
|
77
56
|
joiner: ", "
|
|
@@ -84,7 +63,15 @@ export function ClassDeclaration(props) {
|
|
|
84
63
|
get doc() {
|
|
85
64
|
return props.doc;
|
|
86
65
|
}
|
|
87
|
-
}), modifiers, "class ", _$createComponent(Name, {}),
|
|
66
|
+
}), modifiers, "class ", _$createComponent(Name, {}), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
|
|
67
|
+
get parameters() {
|
|
68
|
+
return props.typeParameters;
|
|
69
|
+
}
|
|
70
|
+
})), base, _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
|
|
71
|
+
get parameters() {
|
|
72
|
+
return props.typeParameters;
|
|
73
|
+
}
|
|
74
|
+
})), _$memo(() => !props.children && ";"), _$memo(() => _$memo(() => !!props.children)() && _$createComponent(core.Block, {
|
|
88
75
|
newline: true,
|
|
89
76
|
get children() {
|
|
90
77
|
return _$createComponent(core.Scope, {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Children, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { AccessModifiers } from "../modifiers.js";
|
|
3
3
|
import { ParameterProps } from "./Parameters.jsx";
|
|
4
|
+
import { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
|
|
4
5
|
/** Method modifiers. Can only be one. */
|
|
5
6
|
export interface ClassMethodModifiers {
|
|
6
7
|
readonly abstract?: boolean;
|
|
@@ -20,6 +21,19 @@ export interface ClassMethodProps extends AccessModifiers, ClassMethodModifiers
|
|
|
20
21
|
async?: boolean;
|
|
21
22
|
/** Doc comment */
|
|
22
23
|
doc?: Children;
|
|
24
|
+
/**
|
|
25
|
+
* Type parameters for the method
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* <InterfaceMethod name="Test" typeParameters={["T"]} />
|
|
30
|
+
* ```
|
|
31
|
+
* This will produce:
|
|
32
|
+
* ```csharp
|
|
33
|
+
* public void Test<T>()
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
typeParameters?: (TypeParameterProps | string)[];
|
|
23
37
|
}
|
|
24
38
|
export declare function ClassMethod(props: ClassMethodProps): Children;
|
|
25
39
|
//# sourceMappingURL=ClassMethod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassMethod.d.ts","sourceRoot":"","sources":["../../../src/components/ClassMethod.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAKhB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAE,cAAc,EAAc,MAAM,kBAAkB,CAAC;AAG9D,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAUD,MAAM,WAAW,gBACf,SAAQ,eAAe,EACrB,oBAAoB;IACtB,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;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"ClassMethod.d.ts","sourceRoot":"","sources":["../../../src/components/ClassMethod.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAKhB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAE,cAAc,EAAc,MAAM,kBAAkB,CAAC;AAG9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAG1E,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAUD,MAAM,WAAW,gBACf,SAAQ,eAAe,EACrB,oBAAoB;IACtB,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;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;IAEf;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;CAClD;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YA4ClD"}
|
|
@@ -6,6 +6,8 @@ import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
|
|
|
6
6
|
import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
|
|
7
7
|
import { Parameters } from "./Parameters.js";
|
|
8
8
|
import { DocWhen } from "./doc/comment.js";
|
|
9
|
+
import { TypeParameterConstraints } from "./type-parameters/type-parameter-constraints.js";
|
|
10
|
+
import { TypeParameters } from "./type-parameters/type-parameters.js";
|
|
9
11
|
|
|
10
12
|
/** Method modifiers. Can only be one. */
|
|
11
13
|
|
|
@@ -47,7 +49,15 @@ export function ClassMethod(props) {
|
|
|
47
49
|
get doc() {
|
|
48
50
|
return props.doc;
|
|
49
51
|
}
|
|
50
|
-
}), modifiers, returns, " ",
|
|
52
|
+
}), modifiers, returns, " ", _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
|
|
53
|
+
get parameters() {
|
|
54
|
+
return props.typeParameters;
|
|
55
|
+
}
|
|
56
|
+
})), name, "(", params, ")", _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
|
|
57
|
+
get parameters() {
|
|
58
|
+
return props.typeParameters;
|
|
59
|
+
}
|
|
60
|
+
})), _$memo(() => _$memo(() => !!props.abstract)() ? ";" : _$createComponent(Block, {
|
|
51
61
|
newline: true,
|
|
52
62
|
get children() {
|
|
53
63
|
return props.children;
|
|
@@ -15,5 +15,7 @@ export * from "./property/property.jsx";
|
|
|
15
15
|
export * from "./record/declaration.js";
|
|
16
16
|
export * from "./Reference.js";
|
|
17
17
|
export * from "./SourceFile.js";
|
|
18
|
+
export type { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
|
|
18
19
|
export * from "./UsingDirective.js";
|
|
20
|
+
export * from "./var/declaration.jsx";
|
|
19
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,YAAY,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
|
|
@@ -15,4 +15,6 @@ export * from "./property/property.js";
|
|
|
15
15
|
export * from "./record/declaration.js";
|
|
16
16
|
export * from "./Reference.js";
|
|
17
17
|
export * from "./SourceFile.js";
|
|
18
|
-
export * from "./UsingDirective.js";
|
|
18
|
+
export * from "./UsingDirective.js";
|
|
19
|
+
export * from "./var/declaration.js";
|
|
20
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
2
|
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
+
import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
|
|
3
4
|
export interface InterfaceModifiers {
|
|
4
5
|
readonly partial?: boolean;
|
|
5
6
|
}
|
|
@@ -8,7 +9,19 @@ export interface InterfaceDeclarationProps extends Omit<core.DeclarationProps, "
|
|
|
8
9
|
/** Doc comment */
|
|
9
10
|
doc?: core.Children;
|
|
10
11
|
refkey?: core.Refkey;
|
|
11
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Type parameters for the interface
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* <InterfaceDeclaration name="IList" typeParameters={["T"]} />
|
|
18
|
+
* ```
|
|
19
|
+
* This will produce:
|
|
20
|
+
* ```csharp
|
|
21
|
+
* public interface IList<T>
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
typeParameters?: (TypeParameterProps | string)[];
|
|
12
25
|
}
|
|
13
26
|
/**
|
|
14
27
|
* CSharp interface declaration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAO5B,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAKD,MAAM,WAAW,yBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,kBAAkB;IACpB,IAAI,EAAE,MAAM,CAAC;IAEb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAO5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAG3E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAKD,MAAM,WAAW,yBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,kBAAkB;IACpB,IAAI,EAAE,MAAM,CAAC;IAEb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IAErB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;CAClD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,iBAoCpE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createComponent as _$createComponent,
|
|
1
|
+
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import * as core from "@alloy-js/core";
|
|
3
3
|
import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../modifiers.js";
|
|
4
4
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
@@ -6,6 +6,8 @@ import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
|
6
6
|
import { CSharpMemberScope } from "../../symbols/scopes.js";
|
|
7
7
|
import { DocWhen } from "../doc/comment.js";
|
|
8
8
|
import { Name } from "../Name.js";
|
|
9
|
+
import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
|
|
10
|
+
import { TypeParameters } from "../type-parameters/type-parameters.js";
|
|
9
11
|
const getInterfaceModifiers = makeModifiers(["partial"]);
|
|
10
12
|
|
|
11
13
|
// properties for creating a class
|
|
@@ -43,29 +45,6 @@ export function InterfaceDeclaration(props) {
|
|
|
43
45
|
const thisInterfaceScope = new CSharpMemberScope("interface-decl", {
|
|
44
46
|
owner: thisInterfaceSymbol
|
|
45
47
|
});
|
|
46
|
-
let typeParams;
|
|
47
|
-
if (props.typeParameters) {
|
|
48
|
-
const typeParamNames = new Array();
|
|
49
|
-
for (const entry of Object.entries(props.typeParameters)) {
|
|
50
|
-
typeParamNames.push(useCSharpNamePolicy().getName(entry[0], "type-parameter"));
|
|
51
|
-
// create a symbol for each type param so its
|
|
52
|
-
// refkey resolves to the type param's name
|
|
53
|
-
new CSharpOutputSymbol(entry[0], {
|
|
54
|
-
scope: thisInterfaceScope,
|
|
55
|
-
refkeys: entry[1]
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
typeParams = _$createIntrinsic("group", {
|
|
59
|
-
get children() {
|
|
60
|
-
return ["<", _$createComponent(core.For, {
|
|
61
|
-
each: typeParamNames,
|
|
62
|
-
comma: true,
|
|
63
|
-
line: true,
|
|
64
|
-
children: name => name
|
|
65
|
-
}), ">"];
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
48
|
const modifiers = computeModifiersPrefix([getAccessModifier(props), getInterfaceModifiers(props)]);
|
|
70
49
|
return _$createComponent(core.Declaration, {
|
|
71
50
|
symbol: thisInterfaceSymbol,
|
|
@@ -74,7 +53,15 @@ export function InterfaceDeclaration(props) {
|
|
|
74
53
|
get doc() {
|
|
75
54
|
return props.doc;
|
|
76
55
|
}
|
|
77
|
-
}), modifiers, "interface ", _$createComponent(Name, {}),
|
|
56
|
+
}), modifiers, "interface ", _$createComponent(Name, {}), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
|
|
57
|
+
get parameters() {
|
|
58
|
+
return props.typeParameters;
|
|
59
|
+
}
|
|
60
|
+
})), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
|
|
61
|
+
get parameters() {
|
|
62
|
+
return props.typeParameters;
|
|
63
|
+
}
|
|
64
|
+
})), _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(core.Block, {
|
|
78
65
|
newline: true,
|
|
79
66
|
get children() {
|
|
80
67
|
return _$createComponent(core.Scope, {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { List, refkey } from "@alloy-js/core";
|
|
2
3
|
import { describe, expect, it } from "vitest";
|
|
3
4
|
import { TestNamespace } from "../../../test/utils.js";
|
|
5
|
+
import { SourceFile } from "../SourceFile.js";
|
|
4
6
|
import { InterfaceDeclaration } from "./declaration.js";
|
|
7
|
+
import { InterfaceProperty } from "./property.js";
|
|
5
8
|
it("declares class with no members", () => {
|
|
6
9
|
expect(_$createComponent(TestNamespace, {
|
|
7
10
|
get children() {
|
|
@@ -66,4 +69,85 @@ it("specify doc comment", () => {
|
|
|
66
69
|
/// This is a test
|
|
67
70
|
interface TestInterface;
|
|
68
71
|
`);
|
|
72
|
+
});
|
|
73
|
+
describe("with type parameters", () => {
|
|
74
|
+
it("reference parameters", () => {
|
|
75
|
+
const typeParameters = [{
|
|
76
|
+
name: "T",
|
|
77
|
+
refkey: refkey()
|
|
78
|
+
}, {
|
|
79
|
+
name: "U",
|
|
80
|
+
refkey: refkey()
|
|
81
|
+
}];
|
|
82
|
+
expect(_$createComponent(TestNamespace, {
|
|
83
|
+
get children() {
|
|
84
|
+
return _$createComponent(SourceFile, {
|
|
85
|
+
path: "Test.cs",
|
|
86
|
+
get children() {
|
|
87
|
+
return _$createComponent(InterfaceDeclaration, {
|
|
88
|
+
"public": true,
|
|
89
|
+
name: "Test",
|
|
90
|
+
typeParameters: typeParameters,
|
|
91
|
+
get children() {
|
|
92
|
+
return _$createComponent(List, {
|
|
93
|
+
get children() {
|
|
94
|
+
return [_$createComponent(InterfaceProperty, {
|
|
95
|
+
name: "PropA",
|
|
96
|
+
get type() {
|
|
97
|
+
return typeParameters[0].refkey;
|
|
98
|
+
},
|
|
99
|
+
get: true,
|
|
100
|
+
set: true
|
|
101
|
+
}), _$createComponent(InterfaceProperty, {
|
|
102
|
+
name: "PropB",
|
|
103
|
+
get type() {
|
|
104
|
+
return typeParameters[1].refkey;
|
|
105
|
+
},
|
|
106
|
+
get: true,
|
|
107
|
+
set: true
|
|
108
|
+
})];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
})).toRenderTo(`
|
|
117
|
+
namespace TestCode
|
|
118
|
+
{
|
|
119
|
+
public interface Test<T, U>
|
|
120
|
+
{
|
|
121
|
+
T PropA { get; set; }
|
|
122
|
+
U PropB { get; set; }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
`);
|
|
126
|
+
});
|
|
127
|
+
it("defines with constraints", () => {
|
|
128
|
+
const typeParameters = [{
|
|
129
|
+
name: "T",
|
|
130
|
+
constraints: "IFoo"
|
|
131
|
+
}, {
|
|
132
|
+
name: "U",
|
|
133
|
+
constraints: "IBar"
|
|
134
|
+
}];
|
|
135
|
+
expect(_$createComponent(TestNamespace, {
|
|
136
|
+
get children() {
|
|
137
|
+
return _$createComponent(InterfaceDeclaration, {
|
|
138
|
+
"public": true,
|
|
139
|
+
name: "Test",
|
|
140
|
+
typeParameters: typeParameters,
|
|
141
|
+
children: "// Body"
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
})).toRenderTo(`
|
|
145
|
+
public interface Test<T, U>
|
|
146
|
+
where T : IFoo
|
|
147
|
+
where U : IBar
|
|
148
|
+
{
|
|
149
|
+
// Body
|
|
150
|
+
}
|
|
151
|
+
`);
|
|
152
|
+
});
|
|
69
153
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Children, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { AccessModifiers } from "../../modifiers.js";
|
|
3
3
|
import { ParameterProps } from "../Parameters.jsx";
|
|
4
|
+
import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
|
|
4
5
|
/** Method modifiers. Can only be one. */
|
|
5
6
|
export interface InterfaceMethodModifiers {
|
|
6
7
|
readonly new?: boolean;
|
|
@@ -10,6 +11,19 @@ export interface InterfaceMethodProps extends AccessModifiers, InterfaceMethodMo
|
|
|
10
11
|
refkey?: Refkey;
|
|
11
12
|
children?: Children;
|
|
12
13
|
parameters?: Array<ParameterProps>;
|
|
14
|
+
/**
|
|
15
|
+
* Type parameters for the method
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* <InterfaceMethod name="Test" typeParameters={["T"]} />
|
|
20
|
+
* ```
|
|
21
|
+
* This will produce:
|
|
22
|
+
* ```csharp
|
|
23
|
+
* public void Test<T>()
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
typeParameters?: (TypeParameterProps | string)[];
|
|
13
27
|
returns?: Children;
|
|
14
28
|
/** Doc comment */
|
|
15
29
|
doc?: Children;
|
|
@@ -1 +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,
|
|
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,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAG3E,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;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;IACjD,OAAO,CAAC,EAAE,QAAQ,CAAC;IAEnB,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAGD,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YA8C1D"}
|
|
@@ -6,6 +6,8 @@ import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
|
6
6
|
import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
|
|
7
7
|
import { Parameters } from "../Parameters.js";
|
|
8
8
|
import { DocWhen } from "../doc/comment.js";
|
|
9
|
+
import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
|
|
10
|
+
import { TypeParameters } from "../type-parameters/type-parameters.js";
|
|
9
11
|
|
|
10
12
|
/** Method modifiers. Can only be one. */
|
|
11
13
|
|
|
@@ -46,7 +48,15 @@ export function InterfaceMethod(props) {
|
|
|
46
48
|
get doc() {
|
|
47
49
|
return props.doc;
|
|
48
50
|
}
|
|
49
|
-
}), modifiers, _$memo(() => props.returns ?? "void"), " ",
|
|
51
|
+
}), modifiers, _$memo(() => props.returns ?? "void"), " ", _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
|
|
52
|
+
get parameters() {
|
|
53
|
+
return props.typeParameters;
|
|
54
|
+
}
|
|
55
|
+
})), name, "(", params, ")", _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
|
|
56
|
+
get parameters() {
|
|
57
|
+
return props.typeParameters;
|
|
58
|
+
}
|
|
59
|
+
})), _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(Block, {
|
|
50
60
|
newline: true,
|
|
51
61
|
get children() {
|
|
52
62
|
return props.children;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { refkey } from "@alloy-js/core";
|
|
2
3
|
import { describe, expect, it } from "vitest";
|
|
3
4
|
import { TestNamespace } from "../../../test/utils.js";
|
|
5
|
+
import { SourceFile } from "../SourceFile.js";
|
|
4
6
|
import { InterfaceDeclaration } from "./declaration.js";
|
|
5
7
|
import { InterfaceMethod } from "./method.js";
|
|
6
8
|
const Wrapper = props => _$createComponent(TestNamespace, {
|
|
@@ -172,4 +174,81 @@ it("specify doc comment", () => {
|
|
|
172
174
|
void Method();
|
|
173
175
|
}
|
|
174
176
|
`);
|
|
177
|
+
});
|
|
178
|
+
describe("with type parameters", () => {
|
|
179
|
+
it("reference parameters", () => {
|
|
180
|
+
const typeParameters = [{
|
|
181
|
+
name: "T",
|
|
182
|
+
refkey: refkey()
|
|
183
|
+
}, {
|
|
184
|
+
name: "U",
|
|
185
|
+
refkey: refkey()
|
|
186
|
+
}];
|
|
187
|
+
expect(_$createComponent(TestNamespace, {
|
|
188
|
+
get children() {
|
|
189
|
+
return _$createComponent(SourceFile, {
|
|
190
|
+
path: "TestFile.cs",
|
|
191
|
+
get children() {
|
|
192
|
+
return _$createComponent(InterfaceDeclaration, {
|
|
193
|
+
"public": true,
|
|
194
|
+
name: "TestInterface",
|
|
195
|
+
get children() {
|
|
196
|
+
return _$createComponent(InterfaceMethod, {
|
|
197
|
+
name: "Test",
|
|
198
|
+
"public": true,
|
|
199
|
+
typeParameters: typeParameters,
|
|
200
|
+
get parameters() {
|
|
201
|
+
return [{
|
|
202
|
+
name: "paramA",
|
|
203
|
+
type: typeParameters[0].refkey
|
|
204
|
+
}];
|
|
205
|
+
},
|
|
206
|
+
get returns() {
|
|
207
|
+
return typeParameters[0].refkey;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
})).toRenderTo(`
|
|
216
|
+
namespace TestCode
|
|
217
|
+
{
|
|
218
|
+
public interface TestInterface
|
|
219
|
+
{
|
|
220
|
+
public T <T, U>Test(T paramA);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
`);
|
|
224
|
+
});
|
|
225
|
+
it("defines with constraints", () => {
|
|
226
|
+
const typeParameters = [{
|
|
227
|
+
name: "T",
|
|
228
|
+
constraints: "IFoo"
|
|
229
|
+
}, {
|
|
230
|
+
name: "U",
|
|
231
|
+
constraints: "IBar"
|
|
232
|
+
}];
|
|
233
|
+
expect(_$createComponent(Wrapper, {
|
|
234
|
+
get children() {
|
|
235
|
+
return _$createComponent(InterfaceMethod, {
|
|
236
|
+
"public": true,
|
|
237
|
+
name: "Test",
|
|
238
|
+
typeParameters: typeParameters,
|
|
239
|
+
children: "// Body"
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
})).toRenderTo(`
|
|
243
|
+
public interface TestInterface
|
|
244
|
+
{
|
|
245
|
+
public void <T, U>Test()
|
|
246
|
+
where T : IFoo
|
|
247
|
+
where U : IBar
|
|
248
|
+
{
|
|
249
|
+
// Body
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
`);
|
|
253
|
+
});
|
|
175
254
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Children } from "@alloy-js/core";
|
|
2
|
+
import { TypeParameterProps } from "./type-parameter.jsx";
|
|
3
|
+
export interface TypeParameterConstraintsProps {
|
|
4
|
+
/** Parameters */
|
|
5
|
+
parameters: (TypeParameterProps | string)[];
|
|
6
|
+
}
|
|
7
|
+
export declare function TypeParameterConstraints(props: TypeParameterConstraintsProps): Children;
|
|
8
|
+
//# sourceMappingURL=type-parameter-constraints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-parameter-constraints.d.ts","sourceRoot":"","sources":["../../../../src/components/type-parameters/type-parameter-constraints.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAqB,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,MAAM,WAAW,6BAA6B;IAC5C,iBAAiB;IACjB,UAAU,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;CAC7C;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,6BAA6B,GACnC,QAAQ,CAcV"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { code, For, Indent } from "@alloy-js/core";
|
|
3
|
+
import { normalizeParameters } from "./type-parameters.js";
|
|
4
|
+
export function TypeParameterConstraints(props) {
|
|
5
|
+
const parameters = normalizeParameters(props.parameters);
|
|
6
|
+
if (!parameters.some(x => x.constraints)) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
return _$createIntrinsic("group", {
|
|
10
|
+
get children() {
|
|
11
|
+
return _$createComponent(Indent, {
|
|
12
|
+
line: true,
|
|
13
|
+
get children() {
|
|
14
|
+
return _$createComponent(For, {
|
|
15
|
+
each: parameters,
|
|
16
|
+
hardline: true,
|
|
17
|
+
children: param => _$createComponent(TypeParameterConstraint, param)
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function TypeParameterConstraint(props) {
|
|
25
|
+
const constraints = arrayify(props.constraints);
|
|
26
|
+
return ["where ", _$memo(() => code`${props.name} : `), _$createIntrinsic("group", {
|
|
27
|
+
get children() {
|
|
28
|
+
return _$createComponent(Indent, {
|
|
29
|
+
softline: true,
|
|
30
|
+
get children() {
|
|
31
|
+
return _$createComponent(For, {
|
|
32
|
+
each: constraints,
|
|
33
|
+
comma: true,
|
|
34
|
+
line: true,
|
|
35
|
+
children: constraint => code`${constraint}`
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
})];
|
|
41
|
+
}
|
|
42
|
+
function arrayify(value) {
|
|
43
|
+
return Array.isArray(value) ? value : [value];
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-parameter-constraints.test.d.ts","sourceRoot":"","sources":["../../../../src/components/type-parameters/type-parameter-constraints.test.tsx"],"names":[],"mappings":""}
|