@alloy-js/csharp 0.20.0-dev.3 → 0.20.0-dev.5
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/Declaration.d.ts +2 -2
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +5 -14
- package/dist/src/components/Declaration.js.map +1 -0
- package/dist/src/components/Name.js +2 -1
- package/dist/src/components/Name.js.map +1 -0
- package/dist/src/components/ProjectDirectory.js +2 -1
- package/dist/src/components/ProjectDirectory.js.map +1 -0
- package/dist/src/components/Reference.d.ts.map +1 -1
- package/dist/src/components/Reference.js +7 -2
- package/dist/src/components/Reference.js.map +1 -0
- package/dist/src/components/SourceFile.d.ts +8 -9
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +71 -46
- package/dist/src/components/SourceFile.js.map +1 -0
- package/dist/src/components/UsingDirective.d.ts +5 -1
- package/dist/src/components/UsingDirective.d.ts.map +1 -1
- package/dist/src/components/UsingDirective.js +5 -2
- package/dist/src/components/UsingDirective.js.map +1 -0
- package/dist/src/components/attributes/attributes.js +2 -1
- package/dist/src/components/attributes/attributes.js.map +1 -0
- package/dist/src/components/attributes/attributes.test.js +2 -1
- package/dist/src/components/attributes/attributes.test.js.map +1 -0
- package/dist/src/components/class/declaration.d.ts +2 -2
- package/dist/src/components/class/declaration.d.ts.map +1 -1
- package/dist/src/components/class/declaration.js +20 -33
- package/dist/src/components/class/declaration.js.map +1 -0
- package/dist/src/components/class/declaration.test.js +173 -194
- package/dist/src/components/class/declaration.test.js.map +1 -0
- package/dist/src/components/constructor/constructor.d.ts.map +1 -1
- package/dist/src/components/constructor/constructor.js +13 -17
- package/dist/src/components/constructor/constructor.js.map +1 -0
- package/dist/src/components/constructor/constructor.test.js +12 -20
- package/dist/src/components/constructor/constructor.test.js.map +1 -0
- package/dist/src/components/doc/comment.js +2 -1
- package/dist/src/components/doc/comment.js.map +1 -0
- package/dist/src/components/doc/comment.test.js +2 -1
- package/dist/src/components/doc/comment.test.js.map +1 -0
- package/dist/src/components/doc/from-markdown.js +2 -1
- package/dist/src/components/doc/from-markdown.js.map +1 -0
- package/dist/src/components/doc/from-markdown.test.js +2 -1
- package/dist/src/components/doc/from-markdown.test.js.map +1 -0
- package/dist/src/components/{EnumDeclaration.d.ts → enum/declaration.d.ts} +6 -11
- package/dist/src/components/enum/declaration.d.ts.map +1 -0
- package/dist/src/components/enum/declaration.js +55 -0
- package/dist/src/components/enum/declaration.js.map +1 -0
- package/dist/src/components/enum/declaration.ref.test.d.ts +2 -0
- package/dist/src/components/enum/declaration.ref.test.d.ts.map +1 -0
- package/dist/src/components/enum/declaration.ref.test.js +121 -0
- package/dist/src/components/enum/declaration.ref.test.js.map +1 -0
- package/dist/src/components/enum/declaration.test.d.ts +2 -0
- package/dist/src/components/enum/declaration.test.d.ts.map +1 -0
- package/dist/src/components/enum/declaration.test.js +40 -0
- package/dist/src/components/enum/declaration.test.js.map +1 -0
- package/dist/src/components/enum/member.d.ts +7 -0
- package/dist/src/components/enum/member.d.ts.map +1 -0
- package/dist/src/components/enum/member.js +30 -0
- package/dist/src/components/enum/member.js.map +1 -0
- package/dist/src/components/enum/member.test.d.ts +2 -0
- package/dist/src/components/enum/member.test.d.ts.map +1 -0
- package/dist/src/components/enum/member.test.js +29 -0
- package/dist/src/components/enum/member.test.js.map +1 -0
- package/dist/src/components/field/field.d.ts.map +1 -1
- package/dist/src/components/field/field.js +11 -15
- package/dist/src/components/field/field.js.map +1 -0
- package/dist/src/components/field/field.test.js +9 -8
- package/dist/src/components/field/field.test.js.map +1 -0
- package/dist/src/components/index.d.ts +5 -2
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +7 -3
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/interface/declaration.d.ts.map +1 -1
- package/dist/src/components/interface/declaration.js +21 -22
- package/dist/src/components/interface/declaration.js.map +1 -0
- package/dist/src/components/interface/declaration.test.js +28 -36
- package/dist/src/components/interface/declaration.test.js.map +1 -0
- package/dist/src/components/interface/method.d.ts.map +1 -1
- package/dist/src/components/interface/method.js +9 -16
- package/dist/src/components/interface/method.js.map +1 -0
- package/dist/src/components/interface/method.test.js +40 -48
- package/dist/src/components/interface/method.test.js.map +1 -0
- package/dist/src/components/interface/property.d.ts.map +1 -1
- package/dist/src/components/interface/property.js +23 -37
- package/dist/src/components/interface/property.js.map +1 -0
- package/dist/src/components/interface/property.test.js +13 -12
- package/dist/src/components/interface/property.test.js.map +1 -0
- package/dist/src/components/lexical-scope.d.ts +8 -0
- package/dist/src/components/lexical-scope.d.ts.map +1 -0
- package/dist/src/components/lexical-scope.js +25 -0
- package/dist/src/components/lexical-scope.js.map +1 -0
- package/dist/src/components/method/method.d.ts +5 -2
- package/dist/src/components/method/method.d.ts.map +1 -1
- package/dist/src/components/method/method.js +9 -14
- package/dist/src/components/method/method.js.map +1 -0
- package/dist/src/components/method/method.test.js +13 -12
- package/dist/src/components/method/method.test.js.map +1 -0
- package/dist/src/components/method-scope.d.ts +8 -0
- package/dist/src/components/method-scope.d.ts.map +1 -0
- package/dist/src/components/method-scope.js +25 -0
- package/dist/src/components/method-scope.js.map +1 -0
- package/dist/src/components/namespace-scopes.d.ts +13 -0
- package/dist/src/components/namespace-scopes.d.ts.map +1 -0
- package/dist/src/components/namespace-scopes.js +45 -0
- package/dist/src/components/namespace-scopes.js.map +1 -0
- package/dist/src/components/namespace.d.ts +7 -0
- package/dist/src/components/namespace.d.ts.map +1 -0
- package/dist/src/components/namespace.js +47 -0
- package/dist/src/components/namespace.js.map +1 -0
- package/dist/src/components/namespace.ref.test.d.ts +2 -0
- package/dist/src/components/namespace.ref.test.d.ts.map +1 -0
- package/dist/src/components/namespace.ref.test.js +182 -0
- package/dist/src/components/namespace.ref.test.js.map +1 -0
- package/dist/src/components/namespace.test.d.ts.map +1 -0
- package/dist/src/components/namespace.test.js +79 -0
- package/dist/src/components/namespace.test.js.map +1 -0
- package/dist/src/components/parameters/parameters.d.ts +2 -2
- package/dist/src/components/parameters/parameters.d.ts.map +1 -1
- package/dist/src/components/parameters/parameters.js +14 -12
- package/dist/src/components/parameters/parameters.js.map +1 -0
- package/dist/src/components/parameters/parameters.test.d.ts +2 -0
- package/dist/src/components/parameters/parameters.test.d.ts.map +1 -0
- package/dist/src/components/parameters/parameters.test.js +88 -0
- package/dist/src/components/parameters/parameters.test.js.map +1 -0
- package/dist/src/components/property/property.d.ts.map +1 -1
- package/dist/src/components/property/property.js +23 -37
- package/dist/src/components/property/property.js.map +1 -0
- package/dist/src/components/property/property.test.js +16 -15
- package/dist/src/components/property/property.test.js.map +1 -0
- package/dist/src/components/record/declaration.d.ts.map +1 -1
- package/dist/src/components/record/declaration.js +10 -13
- package/dist/src/components/record/declaration.js.map +1 -0
- package/dist/src/components/record/declaration.test.js +8 -14
- package/dist/src/components/record/declaration.test.js.map +1 -0
- package/dist/src/components/stc/index.js +2 -1
- package/dist/src/components/stc/index.js.map +1 -0
- package/dist/src/components/struct/declaration.d.ts.map +1 -1
- package/dist/src/components/struct/declaration.js +6 -7
- package/dist/src/components/struct/declaration.js.map +1 -0
- package/dist/src/components/struct/declaration.test.js +32 -40
- package/dist/src/components/struct/declaration.test.js.map +1 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.js +2 -1
- package/dist/src/components/type-parameters/type-parameter-constraints.js.map +1 -0
- package/dist/src/components/type-parameters/type-parameter-constraints.test.js +2 -1
- package/dist/src/components/type-parameters/type-parameter-constraints.test.js.map +1 -0
- package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -1
- package/dist/src/components/type-parameters/type-parameter.js +9 -11
- package/dist/src/components/type-parameters/type-parameter.js.map +1 -0
- package/dist/src/components/type-parameters/type-parameters.js +2 -1
- package/dist/src/components/type-parameters/type-parameters.js.map +1 -0
- package/dist/src/components/type-parameters/type-parameters.test.js +5 -4
- package/dist/src/components/type-parameters/type-parameters.test.js.map +1 -0
- package/dist/src/components/var/declaration.d.ts.map +1 -1
- package/dist/src/components/var/declaration.js +8 -9
- package/dist/src/components/var/declaration.js.map +1 -0
- package/dist/src/components/var/declaration.test.js +13 -21
- package/dist/src/components/var/declaration.test.js.map +1 -0
- package/dist/src/contexts/global-namespace.d.ts +5 -0
- package/dist/src/contexts/global-namespace.d.ts.map +1 -0
- package/dist/src/contexts/global-namespace.js +25 -0
- package/dist/src/contexts/global-namespace.js.map +1 -0
- package/dist/src/contexts/namespace.d.ts +8 -0
- package/dist/src/contexts/namespace.d.ts.map +1 -0
- package/dist/src/contexts/namespace.js +6 -0
- package/dist/src/contexts/namespace.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -0
- package/dist/src/modifiers.d.ts +11 -0
- package/dist/src/modifiers.d.ts.map +1 -1
- package/dist/src/modifiers.js +2 -1
- package/dist/src/modifiers.js.map +1 -0
- package/dist/src/name-policy.js +2 -1
- package/dist/src/name-policy.js.map +1 -0
- package/dist/src/scopes/class.d.ts +10 -0
- package/dist/src/scopes/class.d.ts.map +1 -0
- package/dist/src/scopes/class.js +11 -0
- package/dist/src/scopes/class.js.map +1 -0
- package/dist/src/scopes/contexts.d.ts +9 -0
- package/dist/src/scopes/contexts.d.ts.map +1 -0
- package/dist/src/scopes/contexts.js +34 -0
- package/dist/src/scopes/contexts.js.map +1 -0
- package/dist/src/scopes/csharp.d.ts +8 -0
- package/dist/src/scopes/csharp.d.ts.map +1 -0
- package/dist/src/scopes/csharp.js +12 -0
- package/dist/src/scopes/csharp.js.map +1 -0
- package/dist/src/scopes/factories.d.ts +9 -0
- package/dist/src/scopes/factories.d.ts.map +1 -0
- package/dist/src/scopes/factories.js +24 -0
- package/dist/src/scopes/factories.js.map +1 -0
- package/dist/src/scopes/index.d.ts +10 -0
- package/dist/src/scopes/index.d.ts.map +1 -0
- package/dist/src/scopes/index.js +10 -0
- package/dist/src/scopes/index.js.map +1 -0
- package/dist/src/scopes/lexical.d.ts +7 -0
- package/dist/src/scopes/lexical.d.ts.map +1 -0
- package/dist/src/scopes/lexical.js +8 -0
- package/dist/src/scopes/lexical.js.map +1 -0
- package/dist/src/scopes/method.d.ts +9 -0
- package/dist/src/scopes/method.d.ts.map +1 -0
- package/dist/src/scopes/method.js +14 -0
- package/dist/src/scopes/method.js.map +1 -0
- package/dist/src/scopes/named-type.d.ts +22 -0
- package/dist/src/scopes/named-type.d.ts.map +1 -0
- package/dist/src/scopes/named-type.js +33 -0
- package/dist/src/scopes/named-type.js.map +1 -0
- package/dist/src/scopes/namespace.d.ts +11 -0
- package/dist/src/scopes/namespace.d.ts.map +1 -0
- package/dist/src/scopes/namespace.js +39 -0
- package/dist/src/scopes/namespace.js.map +1 -0
- package/dist/src/scopes/source-file.d.ts +16 -0
- package/dist/src/scopes/source-file.d.ts.map +1 -0
- package/dist/src/scopes/source-file.js +44 -0
- package/dist/src/scopes/source-file.js.map +1 -0
- package/dist/src/symbols/csharp.d.ts +76 -0
- package/dist/src/symbols/csharp.d.ts.map +1 -0
- package/dist/src/symbols/csharp.js +223 -0
- package/dist/src/symbols/csharp.js.map +1 -0
- package/dist/src/symbols/factories.d.ts +25 -0
- package/dist/src/symbols/factories.d.ts.map +1 -0
- package/dist/src/symbols/factories.js +87 -0
- package/dist/src/symbols/factories.js.map +1 -0
- package/dist/src/symbols/index.d.ts +5 -2
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js +6 -2
- package/dist/src/symbols/index.js.map +1 -0
- package/dist/src/symbols/method.d.ts +13 -0
- package/dist/src/symbols/method.d.ts.map +1 -0
- package/dist/src/symbols/method.js +16 -0
- package/dist/src/symbols/method.js.map +1 -0
- package/dist/src/symbols/named-type.d.ts +19 -0
- package/dist/src/symbols/named-type.d.ts.map +1 -0
- package/dist/src/symbols/named-type.js +31 -0
- package/dist/src/symbols/named-type.js.map +1 -0
- package/dist/src/symbols/namespace.d.ts +22 -0
- package/dist/src/symbols/namespace.d.ts.map +1 -0
- package/dist/src/symbols/namespace.js +45 -0
- package/dist/src/symbols/namespace.js.map +1 -0
- package/dist/src/symbols/reference.d.ts +2 -2
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +38 -44
- package/dist/src/symbols/reference.js.map +1 -0
- package/dist/test/project-directory.test.js +14 -17
- package/dist/test/project-directory.test.js.map +1 -0
- package/dist/test/sourcefile.test.js +8 -19
- package/dist/test/sourcefile.test.js.map +1 -0
- package/dist/test/using.test.js +20 -17
- package/dist/test/using.test.js.map +1 -0
- package/dist/test/utils.js +4 -3
- package/dist/test/utils.js.map +1 -0
- package/dist/test/vitest.setup.js +2 -1
- package/dist/test/vitest.setup.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -3
- package/src/components/Declaration.tsx +3 -6
- package/src/components/Reference.tsx +3 -1
- package/src/components/SourceFile.tsx +68 -55
- package/src/components/UsingDirective.tsx +12 -2
- package/src/components/class/declaration.test.tsx +120 -143
- package/src/components/class/declaration.tsx +19 -32
- package/src/components/constructor/constructor.test.tsx +10 -16
- package/src/components/constructor/constructor.tsx +13 -27
- package/src/components/enum/declaration.ref.test.tsx +93 -0
- package/src/components/enum/declaration.test.tsx +34 -0
- package/src/components/enum/declaration.tsx +65 -0
- package/src/components/enum/member.test.tsx +24 -0
- package/src/components/enum/member.tsx +36 -0
- package/src/components/field/field.test.tsx +7 -7
- package/src/components/field/field.tsx +12 -14
- package/src/components/index.ts +5 -2
- package/src/components/interface/declaration.test.tsx +26 -32
- package/src/components/interface/declaration.tsx +16 -18
- package/src/components/interface/method.test.tsx +38 -44
- package/src/components/interface/method.tsx +7 -19
- package/src/components/interface/property.test.tsx +11 -11
- package/src/components/interface/property.tsx +15 -33
- package/src/components/lexical-scope.tsx +29 -0
- package/src/components/method/method.test.tsx +11 -11
- package/src/components/method/method.tsx +12 -18
- package/src/components/method-scope.tsx +27 -0
- package/src/components/namespace-scopes.tsx +44 -0
- package/src/components/namespace.ref.test.tsx +139 -0
- package/src/components/namespace.test.tsx +52 -0
- package/src/components/namespace.tsx +45 -0
- package/src/components/parameters/parameters.test.tsx +71 -0
- package/src/components/parameters/parameters.tsx +9 -16
- package/src/components/property/property.test.tsx +14 -14
- package/src/components/property/property.tsx +17 -38
- package/src/components/record/declaration.test.tsx +5 -12
- package/src/components/record/declaration.tsx +10 -11
- package/src/components/struct/declaration.test.tsx +16 -22
- package/src/components/struct/declaration.tsx +4 -6
- package/src/components/type-parameters/type-parameter.tsx +14 -11
- package/src/components/type-parameters/type-parameters.test.tsx +4 -4
- package/src/components/var/declaration.test.tsx +8 -14
- package/src/components/var/declaration.tsx +12 -6
- package/src/contexts/global-namespace.ts +29 -0
- package/src/contexts/namespace.ts +13 -0
- package/src/index.ts +1 -0
- package/src/modifiers.ts +14 -0
- package/src/scopes/class.ts +12 -0
- package/src/scopes/contexts.ts +45 -0
- package/src/scopes/csharp.ts +18 -0
- package/src/scopes/factories.ts +45 -0
- package/src/scopes/index.ts +9 -0
- package/src/scopes/lexical.ts +10 -0
- package/src/scopes/method.ts +22 -0
- package/src/scopes/named-type.ts +44 -0
- package/src/scopes/namespace.ts +59 -0
- package/src/scopes/source-file.ts +67 -0
- package/src/symbols/csharp.ts +307 -0
- package/src/symbols/factories.ts +199 -0
- package/src/symbols/index.ts +5 -2
- package/src/symbols/method.ts +26 -0
- package/src/symbols/named-type.ts +54 -0
- package/src/symbols/namespace.ts +62 -0
- package/src/symbols/reference.ts +47 -50
- package/temp/api.json +6251 -2454
- package/test/project-directory.test.tsx +12 -16
- package/test/sourcefile.test.tsx +7 -21
- package/test/using.test.tsx +18 -16
- package/test/utils.tsx +1 -1
- package/tsconfig.json +4 -1
- package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
- package/dist/src/components/EnumDeclaration.js +0 -82
- package/dist/src/components/Namespace.d.ts +0 -11
- package/dist/src/components/Namespace.d.ts.map +0 -1
- package/dist/src/components/Namespace.js +0 -33
- package/dist/src/symbols/csharp-output-symbol.d.ts +0 -8
- package/dist/src/symbols/csharp-output-symbol.d.ts.map +0 -1
- package/dist/src/symbols/csharp-output-symbol.js +0 -19
- package/dist/src/symbols/scopes.d.ts +0 -20
- package/dist/src/symbols/scopes.d.ts.map +0 -1
- package/dist/src/symbols/scopes.js +0 -42
- package/dist/test/enum.test.d.ts +0 -2
- package/dist/test/enum.test.d.ts.map +0 -1
- package/dist/test/enum.test.js +0 -178
- package/dist/test/namespace.test.d.ts.map +0 -1
- package/dist/test/namespace.test.js +0 -81
- package/src/components/EnumDeclaration.tsx +0 -98
- package/src/components/Namespace.tsx +0 -35
- package/src/symbols/csharp-output-symbol.ts +0 -22
- package/src/symbols/scopes.ts +0 -61
- package/test/enum.test.tsx +0 -149
- package/test/namespace.test.tsx +0 -55
- /package/dist/{test → src/components}/namespace.test.d.ts +0 -0
|
@@ -6,7 +6,6 @@ import { Constructor } from "../constructor/constructor.jsx";
|
|
|
6
6
|
import { Field } from "../field/field.jsx";
|
|
7
7
|
import { Method } from "../method/method.jsx";
|
|
8
8
|
import { Property } from "../property/property.jsx";
|
|
9
|
-
import { SourceFile } from "../SourceFile.jsx";
|
|
10
9
|
import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
|
|
11
10
|
import { StructDeclaration } from "./declaration.jsx";
|
|
12
11
|
|
|
@@ -78,23 +77,18 @@ describe("with type parameters", () => {
|
|
|
78
77
|
|
|
79
78
|
expect(
|
|
80
79
|
<TestNamespace>
|
|
81
|
-
<
|
|
82
|
-
<
|
|
83
|
-
<
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
</StructDeclaration>
|
|
88
|
-
</SourceFile>
|
|
80
|
+
<StructDeclaration public name="Test" typeParameters={typeParameters}>
|
|
81
|
+
<List>
|
|
82
|
+
<Property name="PropA" type={typeParameters[0].refkey} get set />
|
|
83
|
+
<Property name="PropB" type={typeParameters[1].refkey} get set />
|
|
84
|
+
</List>
|
|
85
|
+
</StructDeclaration>
|
|
89
86
|
</TestNamespace>,
|
|
90
87
|
).toRenderTo(`
|
|
91
|
-
|
|
88
|
+
public struct Test<T, U>
|
|
92
89
|
{
|
|
93
|
-
|
|
94
|
-
{
|
|
95
|
-
T PropA { get; set; }
|
|
96
|
-
U PropB { get; set; }
|
|
97
|
-
}
|
|
90
|
+
T PropA { get; set; }
|
|
91
|
+
U PropB { get; set; }
|
|
98
92
|
}
|
|
99
93
|
`);
|
|
100
94
|
});
|
|
@@ -119,10 +113,10 @@ describe("with type parameters", () => {
|
|
|
119
113
|
</TestNamespace>,
|
|
120
114
|
).toRenderTo(`
|
|
121
115
|
public struct Test<T, U>
|
|
122
|
-
|
|
123
|
-
|
|
116
|
+
where T : IFoo
|
|
117
|
+
where U : IBar
|
|
124
118
|
{
|
|
125
|
-
|
|
119
|
+
// Body
|
|
126
120
|
}
|
|
127
121
|
`);
|
|
128
122
|
});
|
|
@@ -149,7 +143,7 @@ it("define methods", () => {
|
|
|
149
143
|
).toRenderTo(`
|
|
150
144
|
struct Test
|
|
151
145
|
{
|
|
152
|
-
|
|
146
|
+
void MethodOne() {}
|
|
153
147
|
}
|
|
154
148
|
`);
|
|
155
149
|
});
|
|
@@ -164,7 +158,7 @@ it("define constructor", () => {
|
|
|
164
158
|
).toRenderTo(`
|
|
165
159
|
struct Test
|
|
166
160
|
{
|
|
167
|
-
|
|
161
|
+
public Test() {}
|
|
168
162
|
}
|
|
169
163
|
`);
|
|
170
164
|
});
|
|
@@ -182,8 +176,8 @@ it("defines fields", () => {
|
|
|
182
176
|
).toRenderTo(`
|
|
183
177
|
public struct TestClass
|
|
184
178
|
{
|
|
185
|
-
|
|
186
|
-
|
|
179
|
+
public string MemberOne;
|
|
180
|
+
public int MemberTwo;
|
|
187
181
|
}
|
|
188
182
|
`);
|
|
189
183
|
});
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
makeModifiers,
|
|
8
8
|
} from "../../modifiers.js";
|
|
9
9
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { createNamedTypeScope } from "../../scopes/factories.js";
|
|
11
|
+
import { createNamedTypeSymbol } from "../../symbols/factories.js";
|
|
12
12
|
import { AttributeList, AttributesProp } from "../attributes/attributes.jsx";
|
|
13
13
|
import { DocWhen } from "../doc/comment.jsx";
|
|
14
14
|
import { Name } from "../Name.jsx";
|
|
@@ -100,13 +100,11 @@ export interface StructDeclarationProps
|
|
|
100
100
|
export function StructDeclaration(props: StructDeclarationProps) {
|
|
101
101
|
const name = useCSharpNamePolicy().getName(props.name!, "struct");
|
|
102
102
|
|
|
103
|
-
const thisStructSymbol =
|
|
103
|
+
const thisStructSymbol = createNamedTypeSymbol(name, "struct", {
|
|
104
104
|
refkeys: props.refkey,
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
-
const thisStructScope =
|
|
108
|
-
owner: thisStructSymbol,
|
|
109
|
-
});
|
|
107
|
+
const thisStructScope = createNamedTypeScope(thisStructSymbol);
|
|
110
108
|
|
|
111
109
|
const modifiers = computeModifiersPrefix([
|
|
112
110
|
getAccessModifier(props),
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
MemberDeclaration,
|
|
4
|
+
MemberName,
|
|
5
|
+
Refkey,
|
|
6
|
+
} from "@alloy-js/core";
|
|
7
|
+
import { createTypeParameterSymbol } from "../../symbols/factories.js";
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Information for a TypeScript generic type parameter.
|
|
@@ -24,12 +27,12 @@ export interface TypeParameterProps {
|
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
export function TypeParameter(props: TypeParameterProps) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const symbol = new CSharpOutputSymbol(name, {
|
|
30
|
-
scope,
|
|
31
|
-
refkeys: props.refkey ?? refkey(props.name),
|
|
30
|
+
const symbol = createTypeParameterSymbol(props.name, {
|
|
31
|
+
refkeys: props.refkey,
|
|
32
32
|
});
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
return (
|
|
34
|
+
<MemberDeclaration symbol={symbol}>
|
|
35
|
+
<MemberName />
|
|
36
|
+
</MemberDeclaration>
|
|
37
|
+
);
|
|
35
38
|
}
|
|
@@ -15,16 +15,16 @@ it("render very long", () => {
|
|
|
15
15
|
<TestNamespace>
|
|
16
16
|
<TypeParameters
|
|
17
17
|
parameters={[
|
|
18
|
-
"
|
|
19
|
-
"
|
|
18
|
+
"SomeVeryVeryLongParamThatMightGetSplitOverMultipleLinesLongLongLongLongLongA",
|
|
19
|
+
"SomeVeryVeryLongParamThatMightGetSplitOverMultipleLinesLongLongLongLongLongB",
|
|
20
20
|
]}
|
|
21
21
|
/>
|
|
22
22
|
</TestNamespace>,
|
|
23
23
|
).toRenderTo(
|
|
24
24
|
`
|
|
25
25
|
<
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
SomeVeryVeryLongParamThatMightGetSplitOverMultipleLinesLongLongLongLongLongA,
|
|
27
|
+
SomeVeryVeryLongParamThatMightGetSplitOverMultipleLinesLongLongLongLongLongB>
|
|
28
28
|
`,
|
|
29
29
|
);
|
|
30
30
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { List, refkey } from "@alloy-js/core";
|
|
2
2
|
import { expect, it } from "vitest";
|
|
3
3
|
import { TestNamespace } from "../../../test/utils.jsx";
|
|
4
|
-
import { SourceFile } from "../SourceFile.jsx";
|
|
5
4
|
import { VarDeclaration } from "./declaration.jsx";
|
|
6
5
|
|
|
7
6
|
it("declares var without type", () => {
|
|
@@ -40,20 +39,15 @@ it("links refkey", () => {
|
|
|
40
39
|
const key = refkey();
|
|
41
40
|
expect(
|
|
42
41
|
<TestNamespace>
|
|
43
|
-
<
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
</List>
|
|
50
|
-
</SourceFile>
|
|
42
|
+
<List>
|
|
43
|
+
<VarDeclaration name="testVar" refkey={key}>
|
|
44
|
+
42
|
|
45
|
+
</VarDeclaration>
|
|
46
|
+
<VarDeclaration name="testVar2">{key}</VarDeclaration>
|
|
47
|
+
</List>
|
|
51
48
|
</TestNamespace>,
|
|
52
49
|
).toRenderTo(`
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
var testVar = 42;
|
|
56
|
-
var testVar2 = testVar;
|
|
57
|
-
}
|
|
50
|
+
var testVar = 42;
|
|
51
|
+
var testVar2 = testVar;
|
|
58
52
|
`);
|
|
59
53
|
});
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
Declaration,
|
|
4
|
+
DeclarationProps,
|
|
5
|
+
Name,
|
|
6
|
+
Refkey,
|
|
7
|
+
} from "@alloy-js/core";
|
|
8
|
+
import { createVariableSymbol } from "../../symbols/factories.js";
|
|
4
9
|
|
|
5
10
|
/** Props for {@link VarDeclaration} component */
|
|
6
11
|
export interface VarDeclarationProps
|
|
@@ -37,10 +42,11 @@ export interface VarDeclarationProps
|
|
|
37
42
|
* ```
|
|
38
43
|
*/
|
|
39
44
|
export function VarDeclaration(props: VarDeclarationProps) {
|
|
40
|
-
const
|
|
41
|
-
|
|
45
|
+
const sym = createVariableSymbol(props.name, {
|
|
46
|
+
refkeys: props.refkey,
|
|
47
|
+
});
|
|
42
48
|
return (
|
|
43
|
-
<Declaration
|
|
49
|
+
<Declaration symbol={sym}>
|
|
44
50
|
{props.type ?? "var"} <Name /> = {props.children};
|
|
45
51
|
</Declaration>
|
|
46
52
|
);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Binder, useBinder } from "@alloy-js/core";
|
|
2
|
+
import { NamespaceSymbol } from "../symbols/namespace.js";
|
|
3
|
+
|
|
4
|
+
export function useGlobalNamespace() {
|
|
5
|
+
const binder = useBinder();
|
|
6
|
+
return getGlobalNamespace(binder);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const globalNamespaces = new WeakMap<Binder, NamespaceSymbol>();
|
|
10
|
+
const defaultGlobalNamespace = new NamespaceSymbol("global", undefined, {
|
|
11
|
+
isGlobal: true,
|
|
12
|
+
});
|
|
13
|
+
export function getGlobalNamespace(binder: Binder | undefined) {
|
|
14
|
+
if (!binder) {
|
|
15
|
+
return defaultGlobalNamespace;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let namespace = globalNamespaces.get(binder);
|
|
19
|
+
|
|
20
|
+
if (!namespace) {
|
|
21
|
+
namespace = new NamespaceSymbol("global", undefined, {
|
|
22
|
+
binder,
|
|
23
|
+
isGlobal: true,
|
|
24
|
+
});
|
|
25
|
+
globalNamespaces.set(binder, namespace);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return namespace;
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ComponentContext, createContext, useContext } from "@alloy-js/core";
|
|
2
|
+
import { NamespaceSymbol } from "../symbols/namespace.js";
|
|
3
|
+
|
|
4
|
+
export interface NamespaceContext {
|
|
5
|
+
symbol: NamespaceSymbol;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const NamespaceContext: ComponentContext<NamespaceContext> =
|
|
9
|
+
createContext();
|
|
10
|
+
|
|
11
|
+
export function useNamespaceContext() {
|
|
12
|
+
return useContext(NamespaceContext);
|
|
13
|
+
}
|
package/src/index.ts
CHANGED
package/src/modifiers.ts
CHANGED
|
@@ -10,6 +10,20 @@ export interface AccessModifiers {
|
|
|
10
10
|
readonly file?: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export interface NonAccessModifiers {
|
|
14
|
+
readonly override?: boolean;
|
|
15
|
+
readonly abstract?: boolean;
|
|
16
|
+
readonly virtual?: boolean;
|
|
17
|
+
readonly static?: boolean;
|
|
18
|
+
readonly sealed?: boolean;
|
|
19
|
+
readonly extern?: boolean;
|
|
20
|
+
readonly readOnly?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface DeclarationModifiers
|
|
24
|
+
extends AccessModifiers,
|
|
25
|
+
NonAccessModifiers {}
|
|
26
|
+
|
|
13
27
|
export const getAccessModifier = makeModifiers<AccessModifiers>([
|
|
14
28
|
"public",
|
|
15
29
|
"protected",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { OutputSpace } from "@alloy-js/core";
|
|
2
|
+
import { CSharpNamedTypeScope } from "./named-type.js";
|
|
3
|
+
|
|
4
|
+
export class CSharpClassScope extends CSharpNamedTypeScope {
|
|
5
|
+
/**
|
|
6
|
+
* For now, we stuff class parameters into the member scope. This is to ensure
|
|
7
|
+
* name conflicts are handled correctly.
|
|
8
|
+
*/
|
|
9
|
+
get parameters(): OutputSpace {
|
|
10
|
+
return this.members;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useScope } from "@alloy-js/core";
|
|
2
|
+
import { CSharpScope } from "./csharp.js";
|
|
3
|
+
import { CSharpLexicalScope } from "./lexical.js";
|
|
4
|
+
import { CSharpMethodScope } from "./method.js";
|
|
5
|
+
import { CSharpNamedTypeScope } from "./named-type.js";
|
|
6
|
+
|
|
7
|
+
export function useCSharpScope() {
|
|
8
|
+
const scope = useScope();
|
|
9
|
+
if (!(scope instanceof CSharpScope)) {
|
|
10
|
+
throw new Error("Expected a C# scope, got a different kind of scope.");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return scope;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function useNamedTypeScope() {
|
|
17
|
+
const scope = useCSharpScope();
|
|
18
|
+
if (!(scope instanceof CSharpNamedTypeScope)) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"Expected a named type scope, got a " + scope.constructor.name,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return scope;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useMethodScope() {
|
|
28
|
+
const scope = useScope();
|
|
29
|
+
if (!(scope instanceof CSharpMethodScope)) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Expected a method scope, but got ${scope.constructor.name}.`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return scope;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function useLexicalScope() {
|
|
38
|
+
const scope = useScope();
|
|
39
|
+
if (!(scope instanceof CSharpLexicalScope)) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`Expected a lexical scope, but got ${scope.constructor.name}.`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return scope;
|
|
45
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OutputScope, OutputScopeOptions } from "@alloy-js/core";
|
|
2
|
+
import { NamespaceSymbol } from "../symbols/namespace.js";
|
|
3
|
+
|
|
4
|
+
export class CSharpScope extends OutputScope {
|
|
5
|
+
constructor(
|
|
6
|
+
name: string,
|
|
7
|
+
parent: CSharpScope | undefined,
|
|
8
|
+
options?: OutputScopeOptions,
|
|
9
|
+
) {
|
|
10
|
+
super(name, parent, options);
|
|
11
|
+
this.#namespaceSymbol = parent?.enclosingNamespace;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#namespaceSymbol: NamespaceSymbol | undefined;
|
|
15
|
+
get enclosingNamespace() {
|
|
16
|
+
return this.#namespaceSymbol;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { OutputScopeOptions } from "@alloy-js/core";
|
|
2
|
+
import { NamedTypeSymbol } from "../symbols/named-type.js";
|
|
3
|
+
import { CSharpClassScope } from "./class.js";
|
|
4
|
+
import { useCSharpScope, useNamedTypeScope } from "./contexts.js";
|
|
5
|
+
import { CSharpMethodScope } from "./method.js";
|
|
6
|
+
import { CSharpNamedTypeScope } from "./named-type.js";
|
|
7
|
+
import { CSharpSourceFileScope } from "./source-file.js";
|
|
8
|
+
|
|
9
|
+
export function createNamedTypeScope(
|
|
10
|
+
ownerSymbol: NamedTypeSymbol,
|
|
11
|
+
options: OutputScopeOptions = {},
|
|
12
|
+
) {
|
|
13
|
+
const currentScope = useCSharpScope();
|
|
14
|
+
if (
|
|
15
|
+
!(currentScope instanceof CSharpNamedTypeScope) &&
|
|
16
|
+
!(currentScope instanceof CSharpSourceFileScope)
|
|
17
|
+
) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"Can't create C# type declaration scope inside of " +
|
|
20
|
+
currentScope.constructor.name,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return new CSharpNamedTypeScope(ownerSymbol, currentScope, options);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createClassScope(
|
|
28
|
+
ownerSymbol: NamedTypeSymbol,
|
|
29
|
+
options: OutputScopeOptions = {},
|
|
30
|
+
) {
|
|
31
|
+
const currentScope = useCSharpScope();
|
|
32
|
+
if (
|
|
33
|
+
!(currentScope instanceof CSharpNamedTypeScope) &&
|
|
34
|
+
!(currentScope instanceof CSharpSourceFileScope)
|
|
35
|
+
) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"Can't create C# class scope inside of " + currentScope.constructor.name,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return new CSharpClassScope(ownerSymbol, currentScope, options);
|
|
41
|
+
}
|
|
42
|
+
export function createMethodScope(options: OutputScopeOptions = {}) {
|
|
43
|
+
const parentScope = useNamedTypeScope();
|
|
44
|
+
return new CSharpMethodScope("method scope", parentScope, options);
|
|
45
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./class.js";
|
|
2
|
+
export * from "./contexts.js";
|
|
3
|
+
export * from "./csharp.js";
|
|
4
|
+
export * from "./factories.js";
|
|
5
|
+
export * from "./lexical.js";
|
|
6
|
+
export * from "./method.js";
|
|
7
|
+
export * from "./named-type.js";
|
|
8
|
+
export * from "./namespace.js";
|
|
9
|
+
export * from "./source-file.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type OutputSpace } from "@alloy-js/core";
|
|
2
|
+
import { CSharpScope } from "./csharp.js";
|
|
3
|
+
|
|
4
|
+
export class CSharpLexicalScope extends CSharpScope {
|
|
5
|
+
public static readonly declarationSpaces = ["local-variables"];
|
|
6
|
+
|
|
7
|
+
get localVariables(): OutputSpace {
|
|
8
|
+
return this.spaceFor("local-variables")!;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { OutputSpace } from "@alloy-js/core";
|
|
2
|
+
import { CSharpLexicalScope } from "./lexical.js";
|
|
3
|
+
|
|
4
|
+
export class CSharpMethodScope extends CSharpLexicalScope {
|
|
5
|
+
public static readonly declarationSpaces = [
|
|
6
|
+
"local-variables",
|
|
7
|
+
"parameters",
|
|
8
|
+
"type-parameters",
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
get localVariables(): OutputSpace {
|
|
12
|
+
return this.spaceFor("local-variables")!;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
get parameters(): OutputSpace {
|
|
16
|
+
return this.spaceFor("parameters")!;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get typeParameters(): OutputSpace {
|
|
20
|
+
return this.spaceFor("type-parameters")!;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type OutputScopeOptions } from "@alloy-js/core";
|
|
2
|
+
import { NamedTypeSymbol } from "../symbols/named-type.js";
|
|
3
|
+
import { CSharpScope } from "./csharp.js";
|
|
4
|
+
import { CSharpSourceFileScope } from "./source-file.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This scope contains NamedTypeSymbols for types that are declared in
|
|
8
|
+
* containers like namespaces. This scope is a member scope which whose
|
|
9
|
+
* member symbol is a NamedTypeSymbol.
|
|
10
|
+
*/
|
|
11
|
+
export class CSharpNamedTypeScope extends CSharpScope {
|
|
12
|
+
public static readonly declarationSpaces = [];
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
ownerSymbol: NamedTypeSymbol,
|
|
16
|
+
parentScope: CSharpNamedTypeScope | CSharpSourceFileScope | undefined,
|
|
17
|
+
options: OutputScopeOptions = {},
|
|
18
|
+
) {
|
|
19
|
+
super(`${ownerSymbol.name} scope`, parentScope, {
|
|
20
|
+
ownerSymbol,
|
|
21
|
+
...options,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get ownerSymbol(): NamedTypeSymbol {
|
|
26
|
+
return super.ownerSymbol as NamedTypeSymbol;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get enclosingNamespace() {
|
|
30
|
+
return this.ownerSymbol.enclosingNamespace;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get members() {
|
|
34
|
+
return this.ownerSymbol.members;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* For now, we stuff type parameters into the member scope. This is to ensure
|
|
39
|
+
* name conflicts are handled correctly.
|
|
40
|
+
*/
|
|
41
|
+
get typeParameters() {
|
|
42
|
+
return this.ownerSymbol.members;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { OutputScope, useScope } from "@alloy-js/core";
|
|
2
|
+
import type { NamespaceSymbol } from "../symbols/namespace.js";
|
|
3
|
+
import { CSharpNamedTypeScope } from "./named-type.js";
|
|
4
|
+
import { CSharpSourceFileScope } from "./source-file.js";
|
|
5
|
+
|
|
6
|
+
export class CSharpNamespaceScope extends CSharpNamedTypeScope {
|
|
7
|
+
constructor(
|
|
8
|
+
namespaceSymbol: NamespaceSymbol,
|
|
9
|
+
parentScope?: CSharpNamespaceScope | CSharpSourceFileScope,
|
|
10
|
+
) {
|
|
11
|
+
super(namespaceSymbol, parentScope, {
|
|
12
|
+
binder: namespaceSymbol.binder,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get ownerSymbol() {
|
|
17
|
+
return super.ownerSymbol as NamespaceSymbol;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function createCSharpNamespaceScope(namespaceSymbol: NamespaceSymbol) {
|
|
22
|
+
const parentScope = useScope();
|
|
23
|
+
if (
|
|
24
|
+
parentScope &&
|
|
25
|
+
!(
|
|
26
|
+
parentScope instanceof CSharpNamespaceScope ||
|
|
27
|
+
parentScope instanceof CSharpSourceFileScope
|
|
28
|
+
)
|
|
29
|
+
) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
"Namespaces can only be created within a namespace or source file",
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const scope = new CSharpNamespaceScope(namespaceSymbol, parentScope);
|
|
36
|
+
|
|
37
|
+
return scope;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function useEnclosingNamespaceScope(): CSharpNamespaceScope | undefined {
|
|
41
|
+
const currentScope = useScope();
|
|
42
|
+
if (!(currentScope instanceof CSharpNamespaceScope)) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return currentScope;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function useNamespace() {
|
|
50
|
+
let scope: OutputScope | undefined = useScope();
|
|
51
|
+
while (scope) {
|
|
52
|
+
if (scope instanceof CSharpNamespaceScope) {
|
|
53
|
+
return scope;
|
|
54
|
+
}
|
|
55
|
+
scope = scope.parent;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
throw new Error("A namespace is not in scope");
|
|
59
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OutputScope,
|
|
3
|
+
OutputScopeOptions,
|
|
4
|
+
shallowReactive,
|
|
5
|
+
track,
|
|
6
|
+
TrackOpTypes,
|
|
7
|
+
trigger,
|
|
8
|
+
TriggerOpTypes,
|
|
9
|
+
useScope,
|
|
10
|
+
} from "@alloy-js/core";
|
|
11
|
+
import { NamespaceSymbol } from "../symbols/namespace.js";
|
|
12
|
+
import { CSharpLexicalScope } from "./lexical.js";
|
|
13
|
+
import { CSharpNamespaceScope } from "./namespace.js";
|
|
14
|
+
|
|
15
|
+
export class CSharpSourceFileScope extends CSharpLexicalScope {
|
|
16
|
+
#usings = shallowReactive<Set<NamespaceSymbol>>(new Set());
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
name: string,
|
|
20
|
+
parent?: CSharpNamespaceScope,
|
|
21
|
+
options?: OutputScopeOptions,
|
|
22
|
+
) {
|
|
23
|
+
super(name, parent, options);
|
|
24
|
+
}
|
|
25
|
+
get usings() {
|
|
26
|
+
return this.#usings;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get parent() {
|
|
30
|
+
return super.parent! as CSharpNamespaceScope;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
set parent(v: CSharpNamespaceScope) {
|
|
34
|
+
super.parent = v;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
addUsing(using: NamespaceSymbol) {
|
|
38
|
+
this.#usings.add(using);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
#hasBlockNamespace: boolean = false;
|
|
42
|
+
get hasBlockNamespace() {
|
|
43
|
+
track(this, TrackOpTypes.GET, "hasBlockNamespace");
|
|
44
|
+
return this.#hasBlockNamespace;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
set hasBlockNamespace(value: boolean) {
|
|
48
|
+
const old = this.#hasBlockNamespace;
|
|
49
|
+
if (this.#hasBlockNamespace === value) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.#hasBlockNamespace = value;
|
|
53
|
+
trigger(this, TriggerOpTypes.SET, "hasBlockNamespace", value, old);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function useSourceFileScope() {
|
|
58
|
+
let scope: OutputScope | undefined = useScope();
|
|
59
|
+
while (scope) {
|
|
60
|
+
if (scope instanceof CSharpSourceFileScope) {
|
|
61
|
+
return scope;
|
|
62
|
+
}
|
|
63
|
+
scope = scope.parent;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|