@alloy-js/csharp 0.18.0-dev.23 → 0.18.0-dev.24
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 +18 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +6 -0
- package/dist/src/components/ClassMethod.d.ts +18 -0
- package/dist/src/components/ClassMethod.d.ts.map +1 -1
- package/dist/src/components/ClassMethod.js +6 -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/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/interface/declaration.d.ts +18 -0
- package/dist/src/components/interface/declaration.d.ts.map +1 -1
- package/dist/src/components/interface/declaration.js +6 -0
- package/dist/src/components/interface/declaration.test.js +18 -0
- package/dist/src/components/interface/method.d.ts +18 -0
- package/dist/src/components/interface/method.d.ts.map +1 -1
- package/dist/src/components/interface/method.js +6 -0
- package/dist/src/components/interface/method.test.js +21 -0
- package/dist/src/components/interface/property.d.ts +18 -0
- package/dist/src/components/interface/property.d.ts.map +1 -1
- package/dist/src/components/interface/property.js +6 -0
- package/dist/src/components/interface/property.test.js +24 -0
- package/dist/src/components/property/property.d.ts +18 -0
- package/dist/src/components/property/property.d.ts.map +1 -1
- package/dist/src/components/property/property.js +6 -0
- package/dist/src/components/property/property.test.js +24 -0
- package/dist/test/class-declaration.test.js +18 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/ClassDeclaration.tsx +20 -0
- package/src/components/ClassMethod.tsx +20 -0
- package/src/components/attributes/attributes.test.tsx +61 -0
- package/src/components/attributes/attributes.tsx +100 -0
- package/src/components/index.ts +1 -0
- package/src/components/interface/declaration.test.tsx +15 -0
- package/src/components/interface/declaration.tsx +20 -0
- package/src/components/interface/method.test.tsx +15 -0
- package/src/components/interface/method.tsx +20 -0
- package/src/components/interface/property.test.tsx +21 -0
- package/src/components/interface/property.tsx +20 -0
- package/src/components/property/property.test.tsx +21 -0
- package/src/components/property/property.tsx +20 -0
- package/temp/api.json +596 -0
- package/test/class-declaration.test.tsx +12 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
2
|
import { AccessModifiers } from "../modifiers.js";
|
|
3
|
+
import { AttributesProp } from "./attributes/attributes.jsx";
|
|
3
4
|
import { ParameterProps } from "./parameters/parameters.jsx";
|
|
4
5
|
import { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
|
|
5
6
|
export interface ClassModifiers {
|
|
@@ -30,6 +31,23 @@ export interface ClassDeclarationProps extends Omit<core.DeclarationProps, "name
|
|
|
30
31
|
baseType?: core.Children;
|
|
31
32
|
/** Interfaces this class implements */
|
|
32
33
|
interfaceTypes?: core.Children[];
|
|
34
|
+
/**
|
|
35
|
+
* Define attributes to attach
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* <ClassDeclaration name="MyClass" attributes={[
|
|
39
|
+
* <Attribute name="Test" />
|
|
40
|
+
* <Attribute name="Test2" args={["arg1", "arg2"]} />
|
|
41
|
+
* ]}>
|
|
42
|
+
* ```
|
|
43
|
+
* This will produce:
|
|
44
|
+
* ```csharp
|
|
45
|
+
* [Test]
|
|
46
|
+
* [Test2("arg1", "arg2")]
|
|
47
|
+
* public class MyClass
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
attributes?: AttributesProp;
|
|
33
51
|
}
|
|
34
52
|
/**
|
|
35
53
|
* CSharp class declaration.
|
|
@@ -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;
|
|
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;AAIzB,OAAO,EAAiB,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAG5E,OAAO,EAAE,cAAc,EAAc,MAAM,6BAA6B,CAAC;AAEzE,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;IAEjC;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,iBA6C5D;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,iBAiC5D;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"}
|
|
@@ -5,6 +5,7 @@ import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../mod
|
|
|
5
5
|
import { useCSharpNamePolicy } from "../name-policy.js";
|
|
6
6
|
import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
|
|
7
7
|
import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
|
|
8
|
+
import { AttributeList } from "./attributes/attributes.js";
|
|
8
9
|
import { DocWhen } from "./doc/comment.js";
|
|
9
10
|
import { Name } from "./Name.js";
|
|
10
11
|
import { Parameters } from "./parameters/parameters.js";
|
|
@@ -63,6 +64,11 @@ export function ClassDeclaration(props) {
|
|
|
63
64
|
get doc() {
|
|
64
65
|
return props.doc;
|
|
65
66
|
}
|
|
67
|
+
}), _$createComponent(AttributeList, {
|
|
68
|
+
get attributes() {
|
|
69
|
+
return props.attributes;
|
|
70
|
+
},
|
|
71
|
+
endline: true
|
|
66
72
|
}), modifiers, "class ", _$createComponent(Name, {}), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
|
|
67
73
|
get parameters() {
|
|
68
74
|
return props.typeParameters;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Children, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { AccessModifiers } from "../modifiers.js";
|
|
3
|
+
import { AttributesProp } from "./attributes/attributes.jsx";
|
|
3
4
|
import { ParameterProps } from "./parameters/parameters.jsx";
|
|
4
5
|
import { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
|
|
5
6
|
/** Method modifiers. Can only be one. */
|
|
@@ -34,6 +35,23 @@ export interface ClassMethodProps extends AccessModifiers, ClassMethodModifiers
|
|
|
34
35
|
* ```
|
|
35
36
|
*/
|
|
36
37
|
typeParameters?: (TypeParameterProps | string)[];
|
|
38
|
+
/**
|
|
39
|
+
* Define attributes to attach
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* <ClassMethod name="MyMethod" attributes={[
|
|
43
|
+
* <Attribute name="Test" />
|
|
44
|
+
* <Attribute name="Test2" args={["arg1", "arg2"]} />
|
|
45
|
+
* ]} />
|
|
46
|
+
* ```
|
|
47
|
+
* This will produce:
|
|
48
|
+
* ```csharp
|
|
49
|
+
* [Test]
|
|
50
|
+
* [Test2("arg1", "arg2")]
|
|
51
|
+
* public void MyMethod() { }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
attributes?: AttributesProp;
|
|
37
55
|
}
|
|
38
56
|
export declare function ClassMethod(props: ClassMethodProps): Children;
|
|
39
57
|
//# 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;
|
|
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,EAAiB,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE5E,OAAO,EAAE,cAAc,EAAc,MAAM,6BAA6B,CAAC;AAEzE,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;IAEjD;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YA2ClD"}
|
|
@@ -4,6 +4,7 @@ import { computeModifiersPrefix, getAccessModifier, getAsyncModifier, makeModifi
|
|
|
4
4
|
import { useCSharpNamePolicy } from "../name-policy.js";
|
|
5
5
|
import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
|
|
6
6
|
import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
|
|
7
|
+
import { AttributeList } from "./attributes/attributes.js";
|
|
7
8
|
import { DocWhen } from "./doc/comment.js";
|
|
8
9
|
import { Parameters } from "./parameters/parameters.js";
|
|
9
10
|
import { TypeParameterConstraints } from "./type-parameters/type-parameter-constraints.js";
|
|
@@ -44,6 +45,11 @@ export function ClassMethod(props) {
|
|
|
44
45
|
get doc() {
|
|
45
46
|
return props.doc;
|
|
46
47
|
}
|
|
48
|
+
}), _$createComponent(AttributeList, {
|
|
49
|
+
get attributes() {
|
|
50
|
+
return props.attributes;
|
|
51
|
+
},
|
|
52
|
+
endline: true
|
|
47
53
|
}), modifiers, returns, " ", name, _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
|
|
48
54
|
get parameters() {
|
|
49
55
|
return props.typeParameters;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Children } from "@alloy-js/core";
|
|
2
|
+
export interface AttributeItem {
|
|
3
|
+
name: string;
|
|
4
|
+
args?: string[];
|
|
5
|
+
}
|
|
6
|
+
export type AttributesProp = Array<string | AttributeProps | Children>;
|
|
7
|
+
export interface AttributeListProps {
|
|
8
|
+
/** If the attribute list should finish with a hard line if there is any attribute */
|
|
9
|
+
endline?: boolean;
|
|
10
|
+
attributes?: AttributesProp;
|
|
11
|
+
children?: Children[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Render each attributes in a new line.
|
|
15
|
+
*/
|
|
16
|
+
export declare function AttributeList(props: AttributeListProps): Children;
|
|
17
|
+
export interface AttributeProps {
|
|
18
|
+
/** Attribute name */
|
|
19
|
+
name: Children;
|
|
20
|
+
/** Argument */
|
|
21
|
+
args?: Children[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Render a csharp attribute.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <Attribute name="Test" /><hbr/>
|
|
29
|
+
* <Attribute name="Test" args={["arg1", "arg2"]} />
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* will render:
|
|
33
|
+
* ```csharp
|
|
34
|
+
* [Test]
|
|
35
|
+
* [Test("arg1", "arg2")]
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const Attribute: import("@alloy-js/core").Component<AttributeProps> & Required<Pick<import("@alloy-js/core").Component<AttributeProps>, "tag">>;
|
|
39
|
+
//# sourceMappingURL=attributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../../../src/components/attributes/attributes.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAKT,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,GAAG,cAAc,GAAG,QAAQ,CAAC,CAAC;AAEvE,MAAM,WAAW,kBAAkB;IACjC,qFAAqF;IACrF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,YAiBtD;AAYD,MAAM,WAAW,cAAc;IAC7B,qBAAqB;IACrB,IAAI,EAAE,QAAQ,CAAC;IAEf,eAAe;IACf,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC;CACnB;AAGD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,SAAS,gIAqBrB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, memo as _$memo, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { findKeyedChildren, For, Indent, taggedComponent } from "@alloy-js/core";
|
|
3
|
+
/**
|
|
4
|
+
* Render each attributes in a new line.
|
|
5
|
+
*/
|
|
6
|
+
export function AttributeList(props) {
|
|
7
|
+
const attributes = props.attributes ?? (props.children && findKeyedChildren(props.children, Attribute.tag));
|
|
8
|
+
if (!attributes) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return [_$createComponent(For, {
|
|
12
|
+
each: attributes,
|
|
13
|
+
line: true,
|
|
14
|
+
children: arg => renderAttribute(arg)
|
|
15
|
+
}), _$memo(() => _$memo(() => !!(props.endline && attributes.length > 0))() && _$createIntrinsic("hbr", {}))];
|
|
16
|
+
}
|
|
17
|
+
function renderAttribute(attr) {
|
|
18
|
+
if (typeof attr === "string") {
|
|
19
|
+
return _$createComponent(Attribute, {
|
|
20
|
+
name: attr
|
|
21
|
+
});
|
|
22
|
+
} else if (typeof attr === "object" && attr && "name" in attr) {
|
|
23
|
+
return _$createComponent(Attribute, attr);
|
|
24
|
+
} else {
|
|
25
|
+
return attr;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const AttributeTag = Symbol("AttributeTag");
|
|
29
|
+
/**
|
|
30
|
+
* Render a csharp attribute.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* <Attribute name="Test" /><hbr/>
|
|
35
|
+
* <Attribute name="Test" args={["arg1", "arg2"]} />
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* will render:
|
|
39
|
+
* ```csharp
|
|
40
|
+
* [Test]
|
|
41
|
+
* [Test("arg1", "arg2")]
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export const Attribute = taggedComponent(AttributeTag, props => {
|
|
45
|
+
return _$createIntrinsic("group", {
|
|
46
|
+
get children() {
|
|
47
|
+
return ["[", _$memo(() => props.name), _$memo(() => _$memo(() => !!(props.args && props.args.length > 0))() && ["(", _$createComponent(Indent, {
|
|
48
|
+
softline: true,
|
|
49
|
+
get children() {
|
|
50
|
+
return _$createComponent(For, {
|
|
51
|
+
get each() {
|
|
52
|
+
return props.args ?? [];
|
|
53
|
+
},
|
|
54
|
+
comma: true,
|
|
55
|
+
line: true,
|
|
56
|
+
children: arg => arg
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}), ")"]), "]"];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attributes.test.d.ts","sourceRoot":"","sources":["../../../../src/components/attributes/attributes.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import { Attribute, AttributeList } from "./attributes.js";
|
|
4
|
+
it("define attribute", () => {
|
|
5
|
+
expect(_$createComponent(Attribute, {
|
|
6
|
+
name: "Test"
|
|
7
|
+
})).toRenderTo(`
|
|
8
|
+
[Test]
|
|
9
|
+
`);
|
|
10
|
+
});
|
|
11
|
+
it("define attribute with single arg", () => {
|
|
12
|
+
expect(_$createComponent(Attribute, {
|
|
13
|
+
name: "Test",
|
|
14
|
+
args: [`"abc"`]
|
|
15
|
+
})).toRenderTo(`
|
|
16
|
+
[Test("abc")]
|
|
17
|
+
`);
|
|
18
|
+
});
|
|
19
|
+
it("define attribute with multiple arg", () => {
|
|
20
|
+
expect(_$createComponent(Attribute, {
|
|
21
|
+
name: "Test",
|
|
22
|
+
args: [`"abc"`, `"def"`]
|
|
23
|
+
})).toRenderTo(`
|
|
24
|
+
[Test("abc", "def")]
|
|
25
|
+
`);
|
|
26
|
+
});
|
|
27
|
+
it("define attribute list with Attribute components", () => {
|
|
28
|
+
expect(_$createComponent(AttributeList, {
|
|
29
|
+
get attributes() {
|
|
30
|
+
return [_$createComponent(Attribute, {
|
|
31
|
+
name: "TestA"
|
|
32
|
+
}), _$createComponent(Attribute, {
|
|
33
|
+
name: "TestB"
|
|
34
|
+
})];
|
|
35
|
+
}
|
|
36
|
+
})).toRenderTo(`
|
|
37
|
+
[TestA]
|
|
38
|
+
[TestB]
|
|
39
|
+
`);
|
|
40
|
+
});
|
|
41
|
+
it("define attribute list with attribute names", () => {
|
|
42
|
+
expect(_$createComponent(AttributeList, {
|
|
43
|
+
attributes: ["TestA", "TestB"]
|
|
44
|
+
})).toRenderTo(`
|
|
45
|
+
[TestA]
|
|
46
|
+
[TestB]
|
|
47
|
+
`);
|
|
48
|
+
});
|
|
49
|
+
it("define attribute list with attribute props", () => {
|
|
50
|
+
expect(_$createComponent(AttributeList, {
|
|
51
|
+
attributes: [{
|
|
52
|
+
name: "TestA"
|
|
53
|
+
}, {
|
|
54
|
+
name: "TestB",
|
|
55
|
+
args: [`"test"`]
|
|
56
|
+
}]
|
|
57
|
+
})).toRenderTo(`
|
|
58
|
+
[TestA]
|
|
59
|
+
[TestB("test")]
|
|
60
|
+
`);
|
|
61
|
+
});
|
|
62
|
+
it("define attribute list with children", () => {
|
|
63
|
+
expect(_$createComponent(AttributeList, {
|
|
64
|
+
get children() {
|
|
65
|
+
return [_$createComponent(Attribute, {
|
|
66
|
+
name: "TestA"
|
|
67
|
+
}), _$createComponent(Attribute, {
|
|
68
|
+
name: "TestB"
|
|
69
|
+
})];
|
|
70
|
+
}
|
|
71
|
+
})).toRenderTo(`
|
|
72
|
+
[TestA]
|
|
73
|
+
[TestB]
|
|
74
|
+
`);
|
|
75
|
+
});
|
|
@@ -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,6BAA6B,CAAC;AAC5C,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"}
|
|
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,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,6BAA6B,CAAC;AAC5C,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"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
2
|
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
+
import { AttributesProp } from "../attributes/attributes.jsx";
|
|
3
4
|
import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
|
|
4
5
|
export interface InterfaceModifiers {
|
|
5
6
|
readonly partial?: boolean;
|
|
@@ -22,6 +23,23 @@ export interface InterfaceDeclarationProps extends Omit<core.DeclarationProps, "
|
|
|
22
23
|
* ```
|
|
23
24
|
*/
|
|
24
25
|
typeParameters?: (TypeParameterProps | string)[];
|
|
26
|
+
/**
|
|
27
|
+
* Define attributes to attach
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* <InterfaceDeclaration name="MyInterface" attributes={[
|
|
31
|
+
* <Attribute name="Test" />
|
|
32
|
+
* <Attribute name="Test2" args={["arg1", "arg2"]} />
|
|
33
|
+
* ]} />
|
|
34
|
+
* ```
|
|
35
|
+
* This will produce:
|
|
36
|
+
* ```csharp
|
|
37
|
+
* [Test]
|
|
38
|
+
* [Test2("arg1", "arg2")]
|
|
39
|
+
* public interface MyInterface
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
attributes?: AttributesProp;
|
|
25
43
|
}
|
|
26
44
|
/**
|
|
27
45
|
* 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;
|
|
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;AAI5B,OAAO,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAI7E,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;IAEjD;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,iBAqCpE"}
|
|
@@ -4,6 +4,7 @@ import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../
|
|
|
4
4
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
5
|
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
6
|
import { CSharpMemberScope } from "../../symbols/scopes.js";
|
|
7
|
+
import { AttributeList } from "../attributes/attributes.js";
|
|
7
8
|
import { DocWhen } from "../doc/comment.js";
|
|
8
9
|
import { Name } from "../Name.js";
|
|
9
10
|
import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
|
|
@@ -53,6 +54,11 @@ export function InterfaceDeclaration(props) {
|
|
|
53
54
|
get doc() {
|
|
54
55
|
return props.doc;
|
|
55
56
|
}
|
|
57
|
+
}), _$createComponent(AttributeList, {
|
|
58
|
+
get attributes() {
|
|
59
|
+
return props.attributes;
|
|
60
|
+
},
|
|
61
|
+
endline: true
|
|
56
62
|
}), modifiers, "interface ", _$createComponent(Name, {}), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
|
|
57
63
|
get parameters() {
|
|
58
64
|
return props.typeParameters;
|
|
@@ -2,6 +2,7 @@ import { createComponent as _$createComponent, mergeProps as _$mergeProps } from
|
|
|
2
2
|
import { List, refkey } from "@alloy-js/core";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
import { TestNamespace } from "../../../test/utils.js";
|
|
5
|
+
import { Attribute } from "../attributes/attributes.js";
|
|
5
6
|
import { SourceFile } from "../SourceFile.js";
|
|
6
7
|
import { InterfaceDeclaration } from "./declaration.js";
|
|
7
8
|
import { InterfaceProperty } from "./property.js";
|
|
@@ -150,4 +151,21 @@ describe("with type parameters", () => {
|
|
|
150
151
|
}
|
|
151
152
|
`);
|
|
152
153
|
});
|
|
154
|
+
});
|
|
155
|
+
it("specify attributes", () => {
|
|
156
|
+
expect(_$createComponent(TestNamespace, {
|
|
157
|
+
get children() {
|
|
158
|
+
return _$createComponent(InterfaceDeclaration, {
|
|
159
|
+
name: "Test",
|
|
160
|
+
get attributes() {
|
|
161
|
+
return [_$createComponent(Attribute, {
|
|
162
|
+
name: "Test"
|
|
163
|
+
})];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
})).toRenderTo(`
|
|
168
|
+
[Test]
|
|
169
|
+
interface Test;
|
|
170
|
+
`);
|
|
153
171
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Children, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
+
import { AttributesProp } from "../attributes/attributes.jsx";
|
|
3
4
|
import { ParameterProps } from "../parameters/parameters.jsx";
|
|
4
5
|
import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
|
|
5
6
|
/** Method modifiers. Can only be one. */
|
|
@@ -27,6 +28,23 @@ export interface InterfaceMethodProps extends AccessModifiers, InterfaceMethodMo
|
|
|
27
28
|
returns?: Children;
|
|
28
29
|
/** Doc comment */
|
|
29
30
|
doc?: Children;
|
|
31
|
+
/**
|
|
32
|
+
* Define attributes to attach
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* <InterfaceMethod name="MyMethod" attributes={[
|
|
36
|
+
* <Attribute name="Test" />
|
|
37
|
+
* <Attribute name="Test2" args={["arg1", "arg2"]} />
|
|
38
|
+
* ]} />
|
|
39
|
+
* ```
|
|
40
|
+
* This will produce:
|
|
41
|
+
* ```csharp
|
|
42
|
+
* [Test]
|
|
43
|
+
* [Test2("arg1", "arg2")]
|
|
44
|
+
* void MyMethod();
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
attributes?: AttributesProp;
|
|
30
48
|
}
|
|
31
49
|
export declare function InterfaceMethod(props: InterfaceMethodProps): Children;
|
|
32
50
|
//# sourceMappingURL=method.d.ts.map
|
|
@@ -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;
|
|
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,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE7E,OAAO,EAAE,cAAc,EAAc,MAAM,8BAA8B,CAAC;AAE1E,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;IAEf;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAGD,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YA4C1D"}
|
|
@@ -4,6 +4,7 @@ import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../
|
|
|
4
4
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
5
|
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
6
|
import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
|
|
7
|
+
import { AttributeList } from "../attributes/attributes.js";
|
|
7
8
|
import { DocWhen } from "../doc/comment.js";
|
|
8
9
|
import { Parameters } from "../parameters/parameters.js";
|
|
9
10
|
import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
|
|
@@ -43,6 +44,11 @@ export function InterfaceMethod(props) {
|
|
|
43
44
|
get doc() {
|
|
44
45
|
return props.doc;
|
|
45
46
|
}
|
|
47
|
+
}), _$createComponent(AttributeList, {
|
|
48
|
+
get attributes() {
|
|
49
|
+
return props.attributes;
|
|
50
|
+
},
|
|
51
|
+
endline: true
|
|
46
52
|
}), modifiers, _$memo(() => props.returns ?? "void"), " ", name, _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
|
|
47
53
|
get parameters() {
|
|
48
54
|
return props.typeParameters;
|
|
@@ -2,6 +2,7 @@ import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$m
|
|
|
2
2
|
import { refkey } from "@alloy-js/core";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
import { TestNamespace } from "../../../test/utils.js";
|
|
5
|
+
import { Attribute } from "../attributes/attributes.js";
|
|
5
6
|
import { SourceFile } from "../SourceFile.js";
|
|
6
7
|
import { InterfaceDeclaration } from "./declaration.js";
|
|
7
8
|
import { InterfaceMethod } from "./method.js";
|
|
@@ -175,6 +176,26 @@ it("specify doc comment", () => {
|
|
|
175
176
|
}
|
|
176
177
|
`);
|
|
177
178
|
});
|
|
179
|
+
it("specify attributes", () => {
|
|
180
|
+
expect(_$createComponent(Wrapper, {
|
|
181
|
+
get children() {
|
|
182
|
+
return _$createComponent(InterfaceMethod, {
|
|
183
|
+
name: "Test",
|
|
184
|
+
get attributes() {
|
|
185
|
+
return [_$createComponent(Attribute, {
|
|
186
|
+
name: "Test"
|
|
187
|
+
})];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
})).toRenderTo(`
|
|
192
|
+
public interface TestInterface
|
|
193
|
+
{
|
|
194
|
+
[Test]
|
|
195
|
+
void Test();
|
|
196
|
+
}
|
|
197
|
+
`);
|
|
198
|
+
});
|
|
178
199
|
describe("with type parameters", () => {
|
|
179
200
|
it("reference parameters", () => {
|
|
180
201
|
const typeParameters = [{
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Children, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
+
import { AttributesProp } from "../attributes/attributes.jsx";
|
|
3
4
|
/** Method modifiers. Can only be one. */
|
|
4
5
|
export interface InterfacePropertyModifiers {
|
|
5
6
|
readonly new?: boolean;
|
|
@@ -24,6 +25,23 @@ export interface InterfacePropertyProps extends AccessModifiers, InterfaceProper
|
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
27
|
nullable?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Define attributes to attach
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* <InterfaceProperty name="MyProp" attributes={[
|
|
33
|
+
* <Attribute name="Test" />
|
|
34
|
+
* <Attribute name="Test2" args={["arg1", "arg2"]} />
|
|
35
|
+
* ]} />
|
|
36
|
+
* ```
|
|
37
|
+
* This will produce:
|
|
38
|
+
* ```csharp
|
|
39
|
+
* [Test]
|
|
40
|
+
* [Test2("arg1", "arg2")]
|
|
41
|
+
* int MyProp { get; set; }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
attributes?: AttributesProp;
|
|
27
45
|
}
|
|
28
46
|
/**
|
|
29
47
|
* Render a C# interface property.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAIR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAIR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG7E,yCAAyC;AACzC,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAKD,MAAM,WAAW,sBACf,SAAQ,eAAe,EACrB,0BAA0B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,oBAAoB;IACpB,IAAI,EAAE,QAAQ,CAAC;IAEf,uCAAuC;IACvC,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,uCAAuC;IACvC,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;IAEf;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,YAyC9D"}
|
|
@@ -4,6 +4,7 @@ import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../
|
|
|
4
4
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
5
|
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
6
|
import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
|
|
7
|
+
import { AttributeList } from "../attributes/attributes.js";
|
|
7
8
|
import { DocWhen } from "../doc/comment.js";
|
|
8
9
|
|
|
9
10
|
/** Method modifiers. Can only be one. */
|
|
@@ -48,6 +49,11 @@ export function InterfaceProperty(props) {
|
|
|
48
49
|
get doc() {
|
|
49
50
|
return props.doc;
|
|
50
51
|
}
|
|
52
|
+
}), _$createComponent(AttributeList, {
|
|
53
|
+
get attributes() {
|
|
54
|
+
return props.attributes;
|
|
55
|
+
},
|
|
56
|
+
endline: true
|
|
51
57
|
}), modifiers, _$memo(() => props.type), _$memo(() => props.nullable && "?"), " ", name, " ", _$createComponent(Block, {
|
|
52
58
|
newline: true,
|
|
53
59
|
inline: true,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
import { TestNamespace } from "../../../test/utils.js";
|
|
4
|
+
import { Attribute } from "../attributes/attributes.js";
|
|
4
5
|
import { InterfaceDeclaration } from "./declaration.js";
|
|
5
6
|
import { InterfaceProperty } from "./property.js";
|
|
6
7
|
const Wrapper = props => _$createComponent(TestNamespace, {
|
|
@@ -162,4 +163,27 @@ it("specify doc comment", () => {
|
|
|
162
163
|
string Method { get; set; }
|
|
163
164
|
}
|
|
164
165
|
`);
|
|
166
|
+
});
|
|
167
|
+
it("specify attributes", () => {
|
|
168
|
+
expect(_$createComponent(Wrapper, {
|
|
169
|
+
get children() {
|
|
170
|
+
return _$createComponent(InterfaceProperty, {
|
|
171
|
+
name: "Test",
|
|
172
|
+
type: "int",
|
|
173
|
+
get attributes() {
|
|
174
|
+
return [_$createComponent(Attribute, {
|
|
175
|
+
name: "Test"
|
|
176
|
+
})];
|
|
177
|
+
},
|
|
178
|
+
get: true,
|
|
179
|
+
set: true
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
})).toRenderTo(`
|
|
183
|
+
public interface TestInterface
|
|
184
|
+
{
|
|
185
|
+
[Test]
|
|
186
|
+
int Test { get; set; }
|
|
187
|
+
}
|
|
188
|
+
`);
|
|
165
189
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Children, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
+
import { AttributesProp } from "../attributes/attributes.jsx";
|
|
3
4
|
/** Property modifiers. */
|
|
4
5
|
export interface PropertyModifiers {
|
|
5
6
|
readonly new?: boolean;
|
|
@@ -48,6 +49,23 @@ export interface PropertyProps extends AccessModifiers, PropertyModifiers {
|
|
|
48
49
|
* ```
|
|
49
50
|
*/
|
|
50
51
|
initializer?: Children;
|
|
52
|
+
/**
|
|
53
|
+
* Define attributes to attach
|
|
54
|
+
* @example
|
|
55
|
+
* ```tsx
|
|
56
|
+
* <Property name="MyProp" attributes={[
|
|
57
|
+
* <Attribute name="Test" />
|
|
58
|
+
* <Attribute name="Test2" args={["arg1", "arg2"]} />
|
|
59
|
+
* ]} />
|
|
60
|
+
* ```
|
|
61
|
+
* This will produce:
|
|
62
|
+
* ```csharp
|
|
63
|
+
* [Test]
|
|
64
|
+
* [Test2("arg1", "arg2")]
|
|
65
|
+
* int MyProp { get; set; }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
attributes?: AttributesProp;
|
|
51
69
|
}
|
|
52
70
|
/**
|
|
53
71
|
* Render a C# class property.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../src/components/property/property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAKR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../src/components/property/property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAKR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG7E,0BAA0B;AAC1B,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAcD,gDAAgD;AAChD,MAAM,WAAW,aAAc,SAAQ,eAAe,EAAE,iBAAiB;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,oBAAoB;IACpB,IAAI,EAAE,QAAQ,CAAC;IAEf,uCAAuC;IACvC,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,uCAAuC;IACvC,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,0DAA0D;IAC1D,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;IAEf;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,QAAQ,CAAC;IAEvB;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,YAoD5C"}
|