@alloy-js/csharp 0.20.0-dev.1 → 0.20.0-dev.3
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/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +2 -5
- package/dist/src/components/class/declaration.js +1 -1
- package/dist/src/components/class/declaration.test.js +22 -1
- package/dist/src/components/constructor/constructor.d.ts.map +1 -1
- package/dist/src/components/constructor/constructor.js +2 -5
- package/dist/src/components/field/field.d.ts.map +1 -1
- package/dist/src/components/field/field.js +2 -5
- package/dist/src/components/interface/method.d.ts.map +1 -1
- package/dist/src/components/interface/method.js +2 -5
- package/dist/src/components/interface/property.d.ts.map +1 -1
- package/dist/src/components/interface/property.js +2 -5
- package/dist/src/components/method/method.d.ts.map +1 -1
- package/dist/src/components/method/method.js +2 -5
- package/dist/src/components/parameters/parameters.d.ts.map +1 -1
- package/dist/src/components/parameters/parameters.js +2 -5
- package/dist/src/components/property/property.d.ts.map +1 -1
- package/dist/src/components/property/property.js +2 -5
- package/dist/src/components/record/declaration.d.ts +18 -0
- package/dist/src/components/record/declaration.d.ts.map +1 -1
- package/dist/src/components/record/declaration.js +11 -1
- package/dist/src/components/record/declaration.test.js +56 -2
- package/dist/src/symbols/scopes.d.ts +6 -0
- package/dist/src/symbols/scopes.d.ts.map +1 -1
- package/dist/src/symbols/scopes.js +11 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/components/EnumDeclaration.tsx +6 -7
- package/src/components/class/declaration.test.tsx +19 -1
- package/src/components/class/declaration.tsx +1 -1
- package/src/components/constructor/constructor.tsx +5 -10
- package/src/components/field/field.tsx +2 -10
- package/src/components/interface/method.tsx +6 -7
- package/src/components/interface/property.tsx +6 -7
- package/src/components/method/method.tsx +5 -10
- package/src/components/parameters/parameters.tsx +7 -12
- package/src/components/property/property.tsx +9 -12
- package/src/components/record/declaration.test.tsx +53 -2
- package/src/components/record/declaration.tsx +24 -0
- package/src/symbols/scopes.ts +20 -0
- package/temp/api.json +205 -1
- package/tsdoc-metadata.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnumDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/EnumDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAGhB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"EnumDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/EnumDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAGhB,MAAM,iBAAiB,CAAC;AAWzB,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,iBAgC1D;AAGD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;CACtB;AAGD,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,iBAchD"}
|
|
@@ -3,7 +3,7 @@ import * as core from "@alloy-js/core";
|
|
|
3
3
|
import { computeModifiersPrefix, getAccessModifier } from "../modifiers.js";
|
|
4
4
|
import { useCSharpNamePolicy } from "../name-policy.js";
|
|
5
5
|
import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
|
|
6
|
-
import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
|
|
6
|
+
import { CSharpMemberScope, useCSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
|
|
7
7
|
import { Name } from "./Name.js";
|
|
8
8
|
|
|
9
9
|
// properties for creating an enum
|
|
@@ -67,10 +67,7 @@ export function EnumDeclaration(props) {
|
|
|
67
67
|
|
|
68
68
|
// a member within a C# enum
|
|
69
69
|
export function EnumMember(props) {
|
|
70
|
-
const scope =
|
|
71
|
-
if (scope.kind === "member" && scope.name !== "enum-decl") {
|
|
72
|
-
throw new Error("can't define an enum member outside of an enum-decl scope");
|
|
73
|
-
}
|
|
70
|
+
const scope = useCSharpMemberScope(["enum-decl"]);
|
|
74
71
|
const name = useCSharpNamePolicy().getName(props.name, "enum-member");
|
|
75
72
|
const thisEnumValueSymbol = new CSharpOutputSymbol(name, {
|
|
76
73
|
scope,
|
|
@@ -9,7 +9,7 @@ import { DocWhen } from "../doc/comment.js";
|
|
|
9
9
|
import { Parameters } from "../parameters/parameters.js";
|
|
10
10
|
import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
|
|
11
11
|
import { TypeParameters } from "../type-parameters/type-parameters.js";
|
|
12
|
-
const getClassModifiers = makeModifiers(["abstract", "
|
|
12
|
+
const getClassModifiers = makeModifiers(["abstract", "sealed", "static", "partial"]);
|
|
13
13
|
|
|
14
14
|
// properties for creating a class
|
|
15
15
|
|
|
@@ -76,6 +76,27 @@ describe("modifiers", () => {
|
|
|
76
76
|
public abstract partial class TestClass;
|
|
77
77
|
`);
|
|
78
78
|
});
|
|
79
|
+
it("places visibility, attributes, and modifiers in the correct order", () => {
|
|
80
|
+
expect(_$createComponent(TestNamespace, {
|
|
81
|
+
get children() {
|
|
82
|
+
return _$createComponent(ClassDeclaration, {
|
|
83
|
+
partial: true,
|
|
84
|
+
"public": true,
|
|
85
|
+
abstract: true,
|
|
86
|
+
sealed: true,
|
|
87
|
+
name: "TestClass",
|
|
88
|
+
get attributes() {
|
|
89
|
+
return [_$createComponent(Attribute, {
|
|
90
|
+
name: "Test"
|
|
91
|
+
})];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
})).toRenderTo(`
|
|
96
|
+
[Test]
|
|
97
|
+
public abstract sealed partial class TestClass;
|
|
98
|
+
`);
|
|
99
|
+
});
|
|
79
100
|
});
|
|
80
101
|
describe("base", () => {
|
|
81
102
|
it("define base class", () => {
|
|
@@ -363,7 +384,7 @@ it("declares class with invalid members", () => {
|
|
|
363
384
|
})];
|
|
364
385
|
}
|
|
365
386
|
});
|
|
366
|
-
expect(() => toSourceText(decl)).toThrow("
|
|
387
|
+
expect(() => toSourceText(decl)).toThrow("Can't define a EnumMember outside of a enum-decl scope");
|
|
367
388
|
});
|
|
368
389
|
describe("constructor", () => {
|
|
369
390
|
it("declares with constructor", () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constructor.d.ts","sourceRoot":"","sources":["../../../../src/components/constructor/constructor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EAGP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EACL,eAAe,EAGhB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"constructor.d.ts","sourceRoot":"","sources":["../../../../src/components/constructor/constructor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EAGP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EACL,eAAe,EAGhB,MAAM,oBAAoB,CAAC;AAO5B,OAAO,EAAE,cAAc,EAAc,MAAM,8BAA8B,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,6BAA6B;IAC7B,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAE9B,aAAa;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,uBAAuB;IACvB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YAyBlD"}
|
|
@@ -3,7 +3,7 @@ import { Block, Declaration, Name, refkey, Scope } from "@alloy-js/core";
|
|
|
3
3
|
import { computeModifiersPrefix, getAccessModifier } from "../../modifiers.js";
|
|
4
4
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
5
|
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
|
-
import { CSharpMemberScope,
|
|
6
|
+
import { CSharpMemberScope, useCSharpMemberScope } from "../../symbols/scopes.js";
|
|
7
7
|
import { Parameters } from "../parameters/parameters.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -11,10 +11,7 @@ import { Parameters } from "../parameters/parameters.js";
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
export function Constructor(props) {
|
|
14
|
-
const scope =
|
|
15
|
-
if (scope.kind !== "member" || scope.name !== "class-decl" && scope.name !== "struct-decl") {
|
|
16
|
-
throw new Error("can't define a class method outside of a class or struct scope");
|
|
17
|
-
}
|
|
14
|
+
const scope = useCSharpMemberScope(["class-decl", "struct-decl"]);
|
|
18
15
|
const name = useCSharpNamePolicy().getName(scope.owner.name, "class-method");
|
|
19
16
|
const ctorSymbol = new CSharpOutputSymbol(name, {
|
|
20
17
|
scope,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../../src/components/field/field.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA6B,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAM5B,uBAAuB;AACvB,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AASD,MAAM,WAAW,UAAW,SAAQ,eAAe,EAAE,cAAc;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED,wBAAwB;AACxB,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../../src/components/field/field.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA6B,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAM5B,uBAAuB;AACvB,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AASD,MAAM,WAAW,UAAW,SAAQ,eAAe,EAAE,cAAc;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED,wBAAwB;AACxB,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,YAyBtC"}
|
|
@@ -3,7 +3,7 @@ import { Declaration, Name, refkey } from "@alloy-js/core";
|
|
|
3
3
|
import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../modifiers.js";
|
|
4
4
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
5
|
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
|
-
import {
|
|
6
|
+
import { useCSharpMemberScope } from "../../symbols/scopes.js";
|
|
7
7
|
import { DocWhen } from "../doc/comment.js";
|
|
8
8
|
|
|
9
9
|
/** Field modifiers. */
|
|
@@ -16,10 +16,7 @@ export function Field(props) {
|
|
|
16
16
|
nameElement = "class-member-public";
|
|
17
17
|
}
|
|
18
18
|
const name = useCSharpNamePolicy().getName(props.name, nameElement);
|
|
19
|
-
const scope =
|
|
20
|
-
if (scope.kind !== "member" || scope.name !== "class-decl" && scope.name !== "struct-decl") {
|
|
21
|
-
throw new Error("can't define a class member outside of a class or struct scope");
|
|
22
|
-
}
|
|
19
|
+
const scope = useCSharpMemberScope(["class-decl", "struct-decl"]);
|
|
23
20
|
const memberSymbol = new CSharpOutputSymbol(name, {
|
|
24
21
|
scope,
|
|
25
22
|
refkeys: props.refkey ?? refkey(props.name)
|
|
@@ -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;AAO5B,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,YAwC1D"}
|
|
@@ -3,7 +3,7 @@ import { Block, MemberDeclaration, refkey, Scope } from "@alloy-js/core";
|
|
|
3
3
|
import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../modifiers.js";
|
|
4
4
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
5
|
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
|
-
import { CSharpMemberScope,
|
|
6
|
+
import { CSharpMemberScope, useCSharpMemberScope } from "../../symbols/scopes.js";
|
|
7
7
|
import { AttributeList } from "../attributes/attributes.js";
|
|
8
8
|
import { DocWhen } from "../doc/comment.js";
|
|
9
9
|
import { Parameters } from "../parameters/parameters.js";
|
|
@@ -19,10 +19,7 @@ const getMethodModifier = makeModifiers(["new"]);
|
|
|
19
19
|
// a C# interface method
|
|
20
20
|
export function InterfaceMethod(props) {
|
|
21
21
|
const name = useCSharpNamePolicy().getName(props.name, "class-method");
|
|
22
|
-
const scope =
|
|
23
|
-
if (scope.kind !== "member" || scope.name !== "interface-decl") {
|
|
24
|
-
throw new Error("can't define an interface method outside of an interface scope");
|
|
25
|
-
}
|
|
22
|
+
const scope = useCSharpMemberScope(["interface-decl"]);
|
|
26
23
|
const methodSymbol = new CSharpOutputSymbol(name, {
|
|
27
24
|
scope,
|
|
28
25
|
refkeys: props.refkey ?? refkey(props.name)
|
|
@@ -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;AAO5B,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,YAqC9D"}
|
|
@@ -3,7 +3,7 @@ import { Block, List, MemberDeclaration, refkey, Scope } from "@alloy-js/core";
|
|
|
3
3
|
import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../modifiers.js";
|
|
4
4
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
5
|
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
|
-
import { CSharpMemberScope,
|
|
6
|
+
import { CSharpMemberScope, useCSharpMemberScope } from "../../symbols/scopes.js";
|
|
7
7
|
import { AttributeList } from "../attributes/attributes.js";
|
|
8
8
|
import { DocWhen } from "../doc/comment.js";
|
|
9
9
|
|
|
@@ -24,10 +24,7 @@ const getModifiers = makeModifiers(["new"]);
|
|
|
24
24
|
*/
|
|
25
25
|
export function InterfaceProperty(props) {
|
|
26
26
|
const name = useCSharpNamePolicy().getName(props.name, "class-property");
|
|
27
|
-
const scope =
|
|
28
|
-
if (scope.kind !== "member" || scope.name !== "interface-decl") {
|
|
29
|
-
throw new Error("can't define an interface method outside of an interface scope");
|
|
30
|
-
}
|
|
27
|
+
const scope = useCSharpMemberScope(["interface-decl"]);
|
|
31
28
|
const propertySymbol = new CSharpOutputSymbol(name, {
|
|
32
29
|
scope,
|
|
33
30
|
refkeys: props.refkey ?? refkey(props.name)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../../../src/components/method/method.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAKhB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../../../src/components/method/method.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAKhB,MAAM,oBAAoB,CAAC;AAO5B,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,eAAe;IAC9B,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;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAaD,MAAM,WAAW,WAAY,SAAQ,eAAe,EAAE,eAAe;IACnE,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;IAE5B;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAGD,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,YA4CxC"}
|
|
@@ -3,7 +3,7 @@ import { Block, MemberDeclaration, refkey, Scope } from "@alloy-js/core";
|
|
|
3
3
|
import { computeModifiersPrefix, getAccessModifier, getAsyncModifier, makeModifiers } from "../../modifiers.js";
|
|
4
4
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
5
|
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
|
-
import { CSharpMemberScope,
|
|
6
|
+
import { CSharpMemberScope, useCSharpMemberScope } from "../../symbols/scopes.js";
|
|
7
7
|
import { AttributeList } from "../attributes/attributes.js";
|
|
8
8
|
import { DocWhen } from "../doc/comment.js";
|
|
9
9
|
import { Parameters } from "../parameters/parameters.js";
|
|
@@ -19,10 +19,7 @@ const getMethodModifier = makeModifiers(["abstract", "sealed", "static", "virtua
|
|
|
19
19
|
// a C# class method
|
|
20
20
|
export function Method(props) {
|
|
21
21
|
const name = useCSharpNamePolicy().getName(props.name, "class-method");
|
|
22
|
-
const scope =
|
|
23
|
-
if (scope.kind !== "member" || scope.name !== "class-decl" && scope.name !== "struct-decl") {
|
|
24
|
-
throw new Error("can't define a class method outside of a class or struct scope");
|
|
25
|
-
}
|
|
22
|
+
const scope = useCSharpMemberScope(["class-decl", "struct-decl"]);
|
|
26
23
|
const methodSymbol = new CSharpOutputSymbol(name, {
|
|
27
24
|
scope,
|
|
28
25
|
refkeys: props.refkey ?? refkey(props.name)
|
|
@@ -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,
|
|
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,YAqB9C;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;CAC1C;AAED,wCAAwC;AACxC,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,YAehD"}
|
|
@@ -2,15 +2,12 @@ import { memo as _$memo, createComponent as _$createComponent, createIntrinsic a
|
|
|
2
2
|
import { code, Declaration, For, Indent, refkey } from "@alloy-js/core";
|
|
3
3
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
4
4
|
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
5
|
-
import {
|
|
5
|
+
import { useCSharpMemberScope } from "../../symbols/scopes.js";
|
|
6
6
|
import { Name } from "../Name.js";
|
|
7
7
|
/** Define a parameter to be used in class or interface method. */
|
|
8
8
|
export function Parameter(props) {
|
|
9
9
|
const name = useCSharpNamePolicy().getName(props.name, "parameter");
|
|
10
|
-
const scope =
|
|
11
|
-
if (scope.kind !== "member" || scope.name !== "constructor-decl" && scope.name !== "method-decl" && scope.name !== "class-decl") {
|
|
12
|
-
throw new Error("can't define a parameter outside of a constructor-decl or method-decl scope");
|
|
13
|
-
}
|
|
10
|
+
const scope = useCSharpMemberScope(["constructor-decl", "method-decl", "class-decl", "record-decl"]);
|
|
14
11
|
const memberSymbol = new CSharpOutputSymbol(name, {
|
|
15
12
|
scope,
|
|
16
13
|
refkeys: props.refkey ?? refkey(props.name)
|
|
@@ -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;AAO5B,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,YAgD5C"}
|
|
@@ -3,7 +3,7 @@ import { Block, code, List, MemberDeclaration, refkey, Scope } from "@alloy-js/c
|
|
|
3
3
|
import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../modifiers.js";
|
|
4
4
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
5
|
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
|
-
import { CSharpMemberScope,
|
|
6
|
+
import { CSharpMemberScope, useCSharpMemberScope } from "../../symbols/scopes.js";
|
|
7
7
|
import { AttributeList } from "../attributes/attributes.js";
|
|
8
8
|
import { DocWhen } from "../doc/comment.js";
|
|
9
9
|
|
|
@@ -24,10 +24,7 @@ const getModifiers = makeModifiers(["new", "static", "virtual", "sealed", "overr
|
|
|
24
24
|
*/
|
|
25
25
|
export function Property(props) {
|
|
26
26
|
const name = useCSharpNamePolicy().getName(props.name, "class-property");
|
|
27
|
-
const scope =
|
|
28
|
-
if (scope.kind !== "member" || scope.name !== "class-decl" && scope.name !== "record-decl" && scope.name !== "struct-decl") {
|
|
29
|
-
throw new Error("can't define an interface method outside of an interface scope");
|
|
30
|
-
}
|
|
27
|
+
const scope = useCSharpMemberScope(["class-decl", "record-decl", "struct-decl"]);
|
|
31
28
|
const propertySymbol = new CSharpOutputSymbol(name, {
|
|
32
29
|
scope,
|
|
33
30
|
refkeys: props.refkey ?? refkey(props.name)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
2
|
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
+
import { ParameterProps } from "../parameters/parameters.jsx";
|
|
3
4
|
export interface RecordModifiers {
|
|
4
5
|
readonly partial?: boolean;
|
|
5
6
|
}
|
|
@@ -10,6 +11,23 @@ export interface RecordDeclarationProps extends Omit<core.DeclarationProps, "nam
|
|
|
10
11
|
doc?: core.Children;
|
|
11
12
|
refkey?: core.Refkey;
|
|
12
13
|
typeParameters?: Record<string, core.Refkey>;
|
|
14
|
+
/**
|
|
15
|
+
* Set the primary constructor parameters
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* <ClassDeclaration name="MyClass" primaryConstructor={[
|
|
19
|
+
* {name: "value", type: "int"}
|
|
20
|
+
* ]}>
|
|
21
|
+
* ```
|
|
22
|
+
* This will produce:
|
|
23
|
+
* ```csharp
|
|
24
|
+
* public class MyClass(int value)
|
|
25
|
+
* {
|
|
26
|
+
*
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
primaryConstructor?: ParameterProps[];
|
|
13
31
|
}
|
|
14
32
|
/**
|
|
15
33
|
* CSharp record declaration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/record/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/record/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAM5B,OAAO,EAAE,cAAc,EAAc,MAAM,8BAA8B,CAAC;AAE1E,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAID,2DAA2D;AAC3D,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,eAAe;IACjB,IAAI,EAAE,MAAM,CAAC;IAEb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAE7C;;;;;;;;;;;;;;;OAeG;IACH,kBAAkB,CAAC,EAAE,cAAc,EAAE,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,iBA6D9D"}
|
|
@@ -6,6 +6,7 @@ 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 { Parameters } from "../parameters/parameters.js";
|
|
9
10
|
const getRecordModifiers = makeModifiers(["partial"]);
|
|
10
11
|
|
|
11
12
|
/** Props to use the {@link RecordDeclaration} component */
|
|
@@ -74,7 +75,16 @@ export function RecordDeclaration(props) {
|
|
|
74
75
|
get doc() {
|
|
75
76
|
return props.doc;
|
|
76
77
|
}
|
|
77
|
-
}), modifiers, "record ", _$createComponent(Name, {}), typeParams, _$memo(() => _$memo(() => !!props.
|
|
78
|
+
}), modifiers, "record ", _$createComponent(Name, {}), typeParams, _$memo(() => _$memo(() => !!props.primaryConstructor)() && _$createComponent(core.Scope, {
|
|
79
|
+
value: thisRecordScope,
|
|
80
|
+
get children() {
|
|
81
|
+
return _$createComponent(Parameters, {
|
|
82
|
+
get parameters() {
|
|
83
|
+
return props.primaryConstructor;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
})), _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(core.Block, {
|
|
78
88
|
newline: true,
|
|
79
89
|
get children() {
|
|
80
90
|
return _$createComponent(core.Scope, {
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { code, refkey } from "@alloy-js/core";
|
|
2
3
|
import { describe, expect, it } from "vitest";
|
|
3
4
|
import { TestNamespace } from "../../../test/utils.js";
|
|
4
5
|
import { Property } from "../property/property.js";
|
|
6
|
+
import { SourceFile } from "../SourceFile.js";
|
|
5
7
|
import { RecordDeclaration } from "./declaration.js";
|
|
6
|
-
|
|
8
|
+
function Wrapper({
|
|
9
|
+
children
|
|
10
|
+
}) {
|
|
11
|
+
return _$createComponent(TestNamespace, {
|
|
12
|
+
get children() {
|
|
13
|
+
return _$createComponent(SourceFile, {
|
|
14
|
+
path: "Test.cs",
|
|
15
|
+
children: children
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
it("declares record with no members", () => {
|
|
7
21
|
expect(_$createComponent(TestNamespace, {
|
|
8
22
|
get children() {
|
|
9
23
|
return _$createComponent(RecordDeclaration, {
|
|
@@ -68,7 +82,7 @@ it("specify doc comment", () => {
|
|
|
68
82
|
record TestRecord;
|
|
69
83
|
`);
|
|
70
84
|
});
|
|
71
|
-
it("specify
|
|
85
|
+
it("specify record property inside", () => {
|
|
72
86
|
expect(_$createComponent(TestNamespace, {
|
|
73
87
|
get children() {
|
|
74
88
|
return _$createComponent(RecordDeclaration, {
|
|
@@ -91,4 +105,44 @@ it("specify class property inside", () => {
|
|
|
91
105
|
string Prop { get; set; }
|
|
92
106
|
}
|
|
93
107
|
`);
|
|
108
|
+
});
|
|
109
|
+
describe("constructor", () => {
|
|
110
|
+
it("declares primary constructor with args", () => {
|
|
111
|
+
const paramNameRefkey = refkey();
|
|
112
|
+
const paramSizeRefkey = refkey();
|
|
113
|
+
const ctorParams = [{
|
|
114
|
+
name: "name",
|
|
115
|
+
type: "string",
|
|
116
|
+
refkey: paramNameRefkey
|
|
117
|
+
}, {
|
|
118
|
+
name: "size",
|
|
119
|
+
type: "int",
|
|
120
|
+
refkey: paramSizeRefkey
|
|
121
|
+
}];
|
|
122
|
+
expect(_$createComponent(Wrapper, {
|
|
123
|
+
get children() {
|
|
124
|
+
return _$createComponent(RecordDeclaration, {
|
|
125
|
+
"public": true,
|
|
126
|
+
name: "Test",
|
|
127
|
+
primaryConstructor: ctorParams,
|
|
128
|
+
get children() {
|
|
129
|
+
return _$createComponent(Property, {
|
|
130
|
+
name: "PrettyName",
|
|
131
|
+
type: "string",
|
|
132
|
+
get: true,
|
|
133
|
+
initializer: code`$"{${paramNameRefkey}} {${paramSizeRefkey}}"`
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
})).toRenderTo(`
|
|
139
|
+
namespace TestCode
|
|
140
|
+
{
|
|
141
|
+
public record Test(string name, int size)
|
|
142
|
+
{
|
|
143
|
+
string PrettyName { get; } = $"{name} {size}";
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
`);
|
|
147
|
+
});
|
|
94
148
|
});
|
|
@@ -11,4 +11,10 @@ export declare class CSharpMemberScope extends core.OutputScope {
|
|
|
11
11
|
}
|
|
12
12
|
export type CSharpOutputScope = CSharpMemberScope | CSharpNamespaceScope;
|
|
13
13
|
export declare function useCSharpScope(): CSharpOutputScope;
|
|
14
|
+
export declare function useCSharpMemberScope<T extends unknown[]>(names: T): CSharpMemberScope & {
|
|
15
|
+
name: T[number];
|
|
16
|
+
};
|
|
17
|
+
export declare function assertMemberOfScope<T extends unknown[]>(scope: CSharpOutputScope, names: T): asserts scope is CSharpMemberScope & {
|
|
18
|
+
name: T[number];
|
|
19
|
+
};
|
|
14
20
|
//# sourceMappingURL=scopes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../../src/symbols/scopes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAG/D,qBAAa,oBAAqB,SAAQ,IAAI,CAAC,WAAW;IACxD,IAAI,IAAI,WAEP;CACF;AAGD,MAAM,MAAM,qBAAqB,GAC7B,YAAY,GACZ,kBAAkB,GAClB,WAAW,GACX,aAAa,CAAC;AAKlB,qBAAa,iBAAkB,SAAQ,IAAI,CAAC,WAAW;IACrD,IAAI,IAAI,WAEP;IAED,IAAI,IAAI,IACe,qBAAqB,CAC3C;IAED,IAAI,KAAK,IACe,kBAAkB,CACzC;CACF;AAGD,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,oBAAoB,CAAC;AAGzE,wBAAgB,cAAc,IAAI,iBAAiB,CAElD"}
|
|
1
|
+
{"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../../src/symbols/scopes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAG/D,qBAAa,oBAAqB,SAAQ,IAAI,CAAC,WAAW;IACxD,IAAI,IAAI,WAEP;CACF;AAGD,MAAM,MAAM,qBAAqB,GAC7B,YAAY,GACZ,kBAAkB,GAClB,WAAW,GACX,aAAa,CAAC;AAKlB,qBAAa,iBAAkB,SAAQ,IAAI,CAAC,WAAW;IACrD,IAAI,IAAI,WAEP;IAED,IAAI,IAAI,IACe,qBAAqB,CAC3C;IAED,IAAI,KAAK,IACe,kBAAkB,CACzC;CACF;AAGD,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,oBAAoB,CAAC;AAGzE,wBAAgB,cAAc,IAAI,iBAAiB,CAElD;AAED,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,OAAO,EAAE,EACtD,KAAK,EAAE,CAAC,GACP,iBAAiB,GAAG;IAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;CAAE,CAIzC;AAED,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,OAAO,EAAE,EACrD,KAAK,EAAE,iBAAiB,EACxB,KAAK,EAAE,CAAC,GACP,OAAO,CAAC,KAAK,IAAI,iBAAiB,GAAG;IAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;CAAE,CAO1D"}
|
|
@@ -28,4 +28,15 @@ export class CSharpMemberScope extends core.OutputScope {
|
|
|
28
28
|
// returns the current C# scope
|
|
29
29
|
export function useCSharpScope() {
|
|
30
30
|
return core.useScope();
|
|
31
|
+
}
|
|
32
|
+
export function useCSharpMemberScope(names) {
|
|
33
|
+
const scope = useCSharpScope();
|
|
34
|
+
assertMemberOfScope(scope, names);
|
|
35
|
+
return scope;
|
|
36
|
+
}
|
|
37
|
+
export function assertMemberOfScope(scope, names) {
|
|
38
|
+
if (scope.kind !== "member" || !names.includes(scope.name)) {
|
|
39
|
+
const context = core.getContext();
|
|
40
|
+
throw new Error(`Can't define a ${context?.componentOwner?.component.name} outside of a ${names.join(" or ")} scope`);
|
|
41
|
+
}
|
|
31
42
|
}
|