@alloy-js/csharp 0.20.0-dev.0 → 0.20.0-dev.10
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/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/access-expression/access-expression.d.ts +54 -0
- package/dist/src/components/access-expression/access-expression.d.ts.map +1 -0
- package/dist/src/components/access-expression/access-expression.js +277 -0
- package/dist/src/components/access-expression/access-expression.js.map +1 -0
- package/dist/src/components/access-expression/access-expression.test.d.ts +2 -0
- package/dist/src/components/access-expression/access-expression.test.d.ts.map +1 -0
- package/dist/src/components/access-expression/access-expression.test.js +336 -0
- package/dist/src/components/access-expression/access-expression.test.js.map +1 -0
- package/dist/src/components/access-expression/part-descriptors.d.ts +32 -0
- package/dist/src/components/access-expression/part-descriptors.d.ts.map +1 -0
- package/dist/src/components/access-expression/part-descriptors.js +99 -0
- package/dist/src/components/access-expression/part-descriptors.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/{ClassDeclaration.d.ts → class/declaration.d.ts} +30 -12
- package/dist/src/components/class/declaration.d.ts.map +1 -0
- package/dist/src/components/class/declaration.js +87 -0
- package/dist/src/components/class/declaration.js.map +1 -0
- package/dist/src/components/class/declaration.test.d.ts +2 -0
- package/dist/src/components/class/declaration.test.d.ts.map +1 -0
- package/dist/src/components/class/declaration.test.js +573 -0
- 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 -20
- package/dist/src/components/constructor/constructor.js.map +1 -0
- package/dist/src/components/constructor/constructor.test.js +13 -21
- 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 -18
- package/dist/src/components/field/field.js.map +1 -0
- package/dist/src/components/field/field.test.js +10 -9
- package/dist/src/components/field/field.test.js.map +1 -0
- package/dist/src/components/index.d.ts +8 -4
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +10 -5
- 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 -19
- 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 -40
- 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/invocation-expression/invocation-expression.d.ts +29 -0
- package/dist/src/components/invocation-expression/invocation-expression.d.ts.map +1 -0
- package/dist/src/components/invocation-expression/invocation-expression.js +70 -0
- package/dist/src/components/invocation-expression/invocation-expression.js.map +1 -0
- package/dist/src/components/invocation-expression/invocation-expression.test.d.ts +2 -0
- package/dist/src/components/invocation-expression/invocation-expression.test.d.ts.map +1 -0
- package/dist/src/components/invocation-expression/invocation-expression.test.js +105 -0
- package/dist/src/components/invocation-expression/invocation-expression.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 -17
- 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 -3
- package/dist/src/components/parameters/parameters.d.ts.map +1 -1
- package/dist/src/components/parameters/parameters.js +15 -15
- 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 +154 -0
- package/dist/src/components/parameters/parameters.test.js.map +1 -0
- package/dist/src/components/property/property.d.ts +2 -2
- package/dist/src/components/property/property.d.ts.map +1 -1
- package/dist/src/components/property/property.js +30 -40
- package/dist/src/components/property/property.js.map +1 -0
- package/dist/src/components/property/property.test.js +17 -16
- package/dist/src/components/property/property.test.js.map +1 -0
- 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 +21 -14
- package/dist/src/components/record/declaration.js.map +1 -0
- package/dist/src/components/record/declaration.test.js +52 -4
- package/dist/src/components/record/declaration.test.js.map +1 -0
- package/dist/src/components/source-file/source-file.d.ts +19 -0
- package/dist/src/components/source-file/source-file.d.ts.map +1 -0
- package/dist/src/components/source-file/source-file.js +59 -0
- package/dist/src/components/source-file/source-file.js.map +1 -0
- package/dist/src/components/source-file/source-file.test.d.ts +2 -0
- package/dist/src/components/source-file/source-file.test.d.ts.map +1 -0
- package/dist/src/components/source-file/source-file.test.js +136 -0
- package/dist/src/components/source-file/source-file.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/format-options.d.ts +5 -0
- package/dist/src/contexts/format-options.d.ts.map +1 -0
- package/dist/src/contexts/format-options.js +9 -0
- package/dist/src/contexts/format-options.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 +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -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 +10 -0
- package/dist/src/scopes/csharp.d.ts.map +1 -0
- package/dist/src/scopes/csharp.js +15 -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 +87 -0
- package/dist/src/symbols/csharp.d.ts.map +1 -0
- package/dist/src/symbols/csharp.js +246 -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 +93 -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 +50 -44
- package/dist/src/symbols/reference.js.map +1 -0
- package/dist/test/project-directory.test.js +20 -19
- package/dist/test/project-directory.test.js.map +1 -0
- package/dist/test/using.test.js +23 -21
- package/dist/test/using.test.js.map +1 -0
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +7 -4
- 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 +12 -6
- package/src/components/Declaration.tsx +3 -6
- package/src/components/Reference.tsx +3 -1
- package/src/components/UsingDirective.tsx +12 -2
- package/src/components/access-expression/access-expression.test.tsx +284 -0
- package/src/components/access-expression/access-expression.tsx +375 -0
- package/src/components/access-expression/part-descriptors.ts +175 -0
- package/src/components/class/declaration.test.tsx +484 -0
- package/src/components/{ClassDeclaration.tsx → class/declaration.tsx} +63 -44
- package/src/components/constructor/constructor.test.tsx +11 -17
- package/src/components/constructor/constructor.tsx +13 -32
- 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 +8 -8
- package/src/components/field/field.tsx +12 -22
- package/src/components/index.ts +8 -4
- 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 -20
- package/src/components/interface/property.test.tsx +11 -11
- package/src/components/interface/property.tsx +15 -34
- package/src/components/invocation-expression/invocation-expression.test.tsx +101 -0
- package/src/components/invocation-expression/invocation-expression.tsx +60 -0
- package/src/components/lexical-scope.tsx +29 -0
- package/src/components/method/method.test.tsx +11 -11
- package/src/components/method/method.tsx +12 -23
- 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 +117 -0
- package/src/components/parameters/parameters.tsx +11 -21
- package/src/components/property/property.test.tsx +15 -15
- package/src/components/property/property.tsx +23 -41
- package/src/components/record/declaration.test.tsx +47 -3
- package/src/components/record/declaration.tsx +34 -11
- package/src/components/source-file/source-file.test.tsx +96 -0
- package/src/components/source-file/source-file.tsx +98 -0
- 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/format-options.ts +14 -0
- package/src/contexts/global-namespace.ts +29 -0
- package/src/contexts/namespace.ts +13 -0
- package/src/index.ts +2 -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 +23 -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 +339 -0
- package/src/symbols/factories.ts +215 -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.tsx +64 -0
- package/temp/api.json +6910 -2491
- package/test/project-directory.test.tsx +14 -16
- package/test/using.test.tsx +21 -21
- package/test/utils.tsx +2 -1
- package/tsconfig.json +4 -1
- package/tsdoc-metadata.json +1 -1
- package/dist/src/components/ClassDeclaration.d.ts.map +0 -1
- package/dist/src/components/ClassDeclaration.js +0 -92
- package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
- package/dist/src/components/EnumDeclaration.js +0 -85
- 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/components/SourceFile.d.ts +0 -14
- package/dist/src/components/SourceFile.d.ts.map +0 -1
- package/dist/src/components/SourceFile.js +0 -69
- 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 -14
- package/dist/src/symbols/scopes.d.ts.map +0 -1
- package/dist/src/symbols/scopes.js +0 -31
- package/dist/test/class-declaration.test.d.ts +0 -2
- package/dist/test/class-declaration.test.d.ts.map +0 -1
- package/dist/test/class-declaration.test.js +0 -484
- 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/dist/test/sourcefile.test.d.ts +0 -2
- package/dist/test/sourcefile.test.d.ts.map +0 -1
- package/dist/test/sourcefile.test.js +0 -58
- package/src/components/EnumDeclaration.tsx +0 -99
- package/src/components/Namespace.tsx +0 -35
- package/src/components/SourceFile.tsx +0 -78
- package/src/symbols/csharp-output-symbol.ts +0 -22
- package/src/symbols/reference.ts +0 -65
- package/src/symbols/scopes.ts +0 -41
- package/test/class-declaration.test.tsx +0 -413
- package/test/enum.test.tsx +0 -149
- package/test/namespace.test.tsx +0 -55
- package/test/sourcefile.test.tsx +0 -47
- /package/dist/{test → src/components}/namespace.test.d.ts +0 -0
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import { Constructor } from "#components/constructor/constructor.jsx";
|
|
2
|
+
import { EnumDeclaration } from "#components/enum/declaration.jsx";
|
|
3
|
+
import { EnumMember } from "#components/enum/member.jsx";
|
|
4
|
+
import {
|
|
5
|
+
Children,
|
|
6
|
+
code,
|
|
7
|
+
createNamePolicy,
|
|
8
|
+
List,
|
|
9
|
+
NamePolicyContext,
|
|
10
|
+
Output,
|
|
11
|
+
refkey,
|
|
12
|
+
} from "@alloy-js/core";
|
|
13
|
+
import * as coretest from "@alloy-js/core/testing";
|
|
14
|
+
import { describe, expect, it } from "vitest";
|
|
15
|
+
import { TestNamespace, toSourceText } from "../../../test/utils.jsx";
|
|
16
|
+
import { createCSharpNamePolicy } from "../../name-policy.js";
|
|
17
|
+
import { Attribute } from "../attributes/attributes.jsx";
|
|
18
|
+
import { Field } from "../field/field.jsx";
|
|
19
|
+
import { Method } from "../method/method.jsx";
|
|
20
|
+
import { Property } from "../property/property.jsx";
|
|
21
|
+
import { SourceFile } from "../source-file/source-file.jsx";
|
|
22
|
+
import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
|
|
23
|
+
import { ClassDeclaration } from "./declaration.jsx";
|
|
24
|
+
|
|
25
|
+
function Wrapper({ children }: { children: Children }) {
|
|
26
|
+
return <TestNamespace>{children}</TestNamespace>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
it("declares class with no members", () => {
|
|
30
|
+
expect(
|
|
31
|
+
<TestNamespace>
|
|
32
|
+
<ClassDeclaration name="TestClass" />
|
|
33
|
+
</TestNamespace>,
|
|
34
|
+
).toRenderTo(`
|
|
35
|
+
class TestClass;
|
|
36
|
+
`);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("modifiers", () => {
|
|
40
|
+
it.each(["public", "private"])("%s", (mod) => {
|
|
41
|
+
expect(
|
|
42
|
+
<TestNamespace>
|
|
43
|
+
<ClassDeclaration {...{ [mod]: true }} name="TestClass" />
|
|
44
|
+
</TestNamespace>,
|
|
45
|
+
).toRenderTo(`
|
|
46
|
+
${mod} class TestClass;
|
|
47
|
+
`);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it.each(["partial", "abstract", "static", "sealed"])("%s", (mod) => {
|
|
51
|
+
expect(
|
|
52
|
+
<TestNamespace>
|
|
53
|
+
<ClassDeclaration {...{ [mod]: true }} name="TestClass" />
|
|
54
|
+
</TestNamespace>,
|
|
55
|
+
).toRenderTo(`
|
|
56
|
+
${mod} class TestClass;
|
|
57
|
+
`);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("combines modifiers", () => {
|
|
61
|
+
expect(
|
|
62
|
+
<TestNamespace>
|
|
63
|
+
<ClassDeclaration public abstract partial name="TestClass" />
|
|
64
|
+
</TestNamespace>,
|
|
65
|
+
).toRenderTo(`
|
|
66
|
+
public abstract partial class TestClass;
|
|
67
|
+
`);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("places visibility, attributes, and modifiers in the correct order", () => {
|
|
71
|
+
expect(
|
|
72
|
+
<TestNamespace>
|
|
73
|
+
<ClassDeclaration
|
|
74
|
+
partial
|
|
75
|
+
public
|
|
76
|
+
abstract
|
|
77
|
+
sealed
|
|
78
|
+
name="TestClass"
|
|
79
|
+
attributes={[<Attribute name="Test" />]}
|
|
80
|
+
/>
|
|
81
|
+
</TestNamespace>,
|
|
82
|
+
).toRenderTo(`
|
|
83
|
+
[Test]
|
|
84
|
+
public abstract sealed partial class TestClass;
|
|
85
|
+
`);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe("base", () => {
|
|
90
|
+
it("define base class", () => {
|
|
91
|
+
expect(
|
|
92
|
+
<TestNamespace>
|
|
93
|
+
<ClassDeclaration name="TestClass" baseType="Foo" />
|
|
94
|
+
</TestNamespace>,
|
|
95
|
+
).toRenderTo(`
|
|
96
|
+
class TestClass : Foo;
|
|
97
|
+
`);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("define multiple interface types", () => {
|
|
101
|
+
expect(
|
|
102
|
+
<TestNamespace>
|
|
103
|
+
<ClassDeclaration name="TestClass" interfaceTypes={["Foo", "Bar"]} />
|
|
104
|
+
</TestNamespace>,
|
|
105
|
+
).toRenderTo(`
|
|
106
|
+
class TestClass : Foo, Bar;
|
|
107
|
+
`);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("define base class and multiple interface types", () => {
|
|
111
|
+
expect(
|
|
112
|
+
<TestNamespace>
|
|
113
|
+
<ClassDeclaration
|
|
114
|
+
name="TestClass"
|
|
115
|
+
baseType="BaseClass"
|
|
116
|
+
interfaceTypes={["Foo", "Bar"]}
|
|
117
|
+
/>
|
|
118
|
+
</TestNamespace>,
|
|
119
|
+
).toRenderTo(`
|
|
120
|
+
class TestClass : BaseClass, Foo, Bar;
|
|
121
|
+
`);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("declares class with some members", () => {
|
|
126
|
+
const tree = (
|
|
127
|
+
<TestNamespace>
|
|
128
|
+
<ClassDeclaration public name="TestClass">
|
|
129
|
+
<List>
|
|
130
|
+
<Field public name="MemberOne" type="string" />
|
|
131
|
+
<Field public name="MemberTwo" type="int" />
|
|
132
|
+
</List>
|
|
133
|
+
</ClassDeclaration>
|
|
134
|
+
</TestNamespace>
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
expect(tree).toRenderTo(coretest.d`
|
|
138
|
+
public class TestClass
|
|
139
|
+
{
|
|
140
|
+
public string MemberOne;
|
|
141
|
+
public int MemberTwo;
|
|
142
|
+
}
|
|
143
|
+
`);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("declares class with some methods", () => {
|
|
147
|
+
const tree = (
|
|
148
|
+
<TestNamespace>
|
|
149
|
+
<ClassDeclaration public name="TestClass">
|
|
150
|
+
<List>
|
|
151
|
+
<Method public name="MethodOne" />
|
|
152
|
+
<Method private virtual name="MethodTwo" />
|
|
153
|
+
</List>
|
|
154
|
+
</ClassDeclaration>
|
|
155
|
+
</TestNamespace>
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
expect(tree).toRenderTo(coretest.d`
|
|
159
|
+
public class TestClass
|
|
160
|
+
{
|
|
161
|
+
public void MethodOne() {}
|
|
162
|
+
private virtual void MethodTwo() {}
|
|
163
|
+
}
|
|
164
|
+
`);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("uses refkeys for members, params, and return type", () => {
|
|
168
|
+
const inputTypeRefkey = refkey();
|
|
169
|
+
const testResultTypeRefkey = refkey();
|
|
170
|
+
const enumTypeRefkey = refkey();
|
|
171
|
+
|
|
172
|
+
const params = [
|
|
173
|
+
{
|
|
174
|
+
name: "IntParam",
|
|
175
|
+
type: "int",
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: "BodyParam",
|
|
179
|
+
type: inputTypeRefkey,
|
|
180
|
+
},
|
|
181
|
+
];
|
|
182
|
+
|
|
183
|
+
expect(
|
|
184
|
+
<Output namePolicy={createCSharpNamePolicy()}>
|
|
185
|
+
<SourceFile path="Test.cs">
|
|
186
|
+
<EnumDeclaration public name="TestEnum" refkey={enumTypeRefkey}>
|
|
187
|
+
<List comma hardline>
|
|
188
|
+
<EnumMember name="One" />
|
|
189
|
+
<EnumMember name="Two" />
|
|
190
|
+
</List>
|
|
191
|
+
</EnumDeclaration>
|
|
192
|
+
<hbr />
|
|
193
|
+
<ClassDeclaration public name="TestInput" refkey={inputTypeRefkey} />
|
|
194
|
+
<hbr />
|
|
195
|
+
<ClassDeclaration
|
|
196
|
+
public
|
|
197
|
+
name="TestResult"
|
|
198
|
+
refkey={testResultTypeRefkey}
|
|
199
|
+
/>
|
|
200
|
+
<hbr />
|
|
201
|
+
<ClassDeclaration public name="TestClass">
|
|
202
|
+
<Field private name="MemberOne" type={enumTypeRefkey} />
|
|
203
|
+
<hbr />
|
|
204
|
+
<Method
|
|
205
|
+
public
|
|
206
|
+
name="MethodOne"
|
|
207
|
+
parameters={params}
|
|
208
|
+
returns={testResultTypeRefkey}
|
|
209
|
+
>
|
|
210
|
+
return new {testResultTypeRefkey}();
|
|
211
|
+
</Method>
|
|
212
|
+
</ClassDeclaration>
|
|
213
|
+
</SourceFile>
|
|
214
|
+
</Output>,
|
|
215
|
+
).toRenderTo(`
|
|
216
|
+
public enum TestEnum
|
|
217
|
+
{
|
|
218
|
+
One,
|
|
219
|
+
Two
|
|
220
|
+
}
|
|
221
|
+
public class TestInput;
|
|
222
|
+
public class TestResult;
|
|
223
|
+
public class TestClass
|
|
224
|
+
{
|
|
225
|
+
private TestEnum _memberOne;
|
|
226
|
+
public TestResult MethodOne(int intParam, TestInput bodyParam)
|
|
227
|
+
{
|
|
228
|
+
return new TestResult();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
`);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe("with type parameters", () => {
|
|
235
|
+
it("reference parameters", () => {
|
|
236
|
+
const typeParameters: TypeParameterProps[] = [
|
|
237
|
+
{
|
|
238
|
+
name: "T",
|
|
239
|
+
refkey: refkey(),
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
name: "U",
|
|
243
|
+
refkey: refkey(),
|
|
244
|
+
},
|
|
245
|
+
];
|
|
246
|
+
|
|
247
|
+
expect(
|
|
248
|
+
<TestNamespace>
|
|
249
|
+
<ClassDeclaration
|
|
250
|
+
public
|
|
251
|
+
name="TestClass"
|
|
252
|
+
typeParameters={typeParameters}
|
|
253
|
+
>
|
|
254
|
+
<List>
|
|
255
|
+
<Property name="PropA" type={typeParameters[0].refkey} get set />
|
|
256
|
+
<Property name="PropB" type={typeParameters[1].refkey} get set />
|
|
257
|
+
</List>
|
|
258
|
+
</ClassDeclaration>
|
|
259
|
+
</TestNamespace>,
|
|
260
|
+
).toRenderTo(`
|
|
261
|
+
public class TestClass<T, U>
|
|
262
|
+
{
|
|
263
|
+
T PropA { get; set; }
|
|
264
|
+
U PropB { get; set; }
|
|
265
|
+
}
|
|
266
|
+
`);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("defines with constraints", () => {
|
|
270
|
+
const typeParameters: TypeParameterProps[] = [
|
|
271
|
+
{
|
|
272
|
+
name: "T",
|
|
273
|
+
constraints: "IFoo",
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
name: "U",
|
|
277
|
+
constraints: "IBar",
|
|
278
|
+
},
|
|
279
|
+
];
|
|
280
|
+
|
|
281
|
+
expect(
|
|
282
|
+
<TestNamespace>
|
|
283
|
+
<ClassDeclaration
|
|
284
|
+
public
|
|
285
|
+
name="TestClass"
|
|
286
|
+
typeParameters={typeParameters}
|
|
287
|
+
>
|
|
288
|
+
// Body
|
|
289
|
+
</ClassDeclaration>
|
|
290
|
+
</TestNamespace>,
|
|
291
|
+
).toRenderTo(`
|
|
292
|
+
public class TestClass<T, U>
|
|
293
|
+
where T : IFoo
|
|
294
|
+
where U : IBar
|
|
295
|
+
{
|
|
296
|
+
// Body
|
|
297
|
+
}
|
|
298
|
+
`);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it("declares class with invalid members", () => {
|
|
303
|
+
const decl = (
|
|
304
|
+
<ClassDeclaration public name="TestClass">
|
|
305
|
+
<EnumMember name="One" />,<hbr />
|
|
306
|
+
<EnumMember name="Two" />
|
|
307
|
+
</ClassDeclaration>
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
expect(() => toSourceText(decl)).toThrow(
|
|
311
|
+
"EnumMember must be used within an EnumDeclaration.",
|
|
312
|
+
);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
describe("constructor", () => {
|
|
316
|
+
it("declares with constructor", () => {
|
|
317
|
+
const tree = (
|
|
318
|
+
<TestNamespace>
|
|
319
|
+
<ClassDeclaration public name="TestClass">
|
|
320
|
+
<Constructor public />
|
|
321
|
+
</ClassDeclaration>
|
|
322
|
+
</TestNamespace>
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
expect(tree).toRenderTo(coretest.d`
|
|
326
|
+
public class TestClass
|
|
327
|
+
{
|
|
328
|
+
public TestClass() {}
|
|
329
|
+
}
|
|
330
|
+
`);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it("declares with constructor params and assigns values to fields", () => {
|
|
334
|
+
const thisNameRefkey = refkey();
|
|
335
|
+
const thisSizeRefkey = refkey();
|
|
336
|
+
const paramNameRefkey = refkey();
|
|
337
|
+
const paramSizeRefkey = refkey();
|
|
338
|
+
|
|
339
|
+
const ctorParams = [
|
|
340
|
+
{
|
|
341
|
+
name: "name",
|
|
342
|
+
type: "string",
|
|
343
|
+
refkey: paramNameRefkey,
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
name: "size",
|
|
347
|
+
type: "int",
|
|
348
|
+
refkey: paramSizeRefkey,
|
|
349
|
+
},
|
|
350
|
+
];
|
|
351
|
+
|
|
352
|
+
const tree = (
|
|
353
|
+
<TestNamespace>
|
|
354
|
+
<ClassDeclaration public name="TestClass">
|
|
355
|
+
<Field private name="name" type="string" refkey={thisNameRefkey} />
|
|
356
|
+
<hbr />
|
|
357
|
+
<Field private name="size" type="int" refkey={thisSizeRefkey} />
|
|
358
|
+
<hbr />
|
|
359
|
+
<Constructor public parameters={ctorParams}>
|
|
360
|
+
{thisNameRefkey} = {paramNameRefkey};<hbr />
|
|
361
|
+
{thisSizeRefkey} = {paramSizeRefkey};
|
|
362
|
+
</Constructor>
|
|
363
|
+
</ClassDeclaration>
|
|
364
|
+
</TestNamespace>
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
// TODO: assignments to members should have this. prefix
|
|
368
|
+
// e.g. this.name = name;
|
|
369
|
+
expect(tree).toRenderTo(coretest.d`
|
|
370
|
+
public class TestClass
|
|
371
|
+
{
|
|
372
|
+
private string _name;
|
|
373
|
+
private int _size;
|
|
374
|
+
public TestClass(string name, int size)
|
|
375
|
+
{
|
|
376
|
+
_name = name;
|
|
377
|
+
_size = size;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
`);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("declares primary constructor with args", () => {
|
|
384
|
+
const paramNameRefkey = refkey();
|
|
385
|
+
const paramSizeRefkey = refkey();
|
|
386
|
+
|
|
387
|
+
const ctorParams = [
|
|
388
|
+
{
|
|
389
|
+
name: "name",
|
|
390
|
+
type: "string",
|
|
391
|
+
refkey: paramNameRefkey,
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
name: "size",
|
|
395
|
+
type: "int",
|
|
396
|
+
refkey: paramSizeRefkey,
|
|
397
|
+
},
|
|
398
|
+
];
|
|
399
|
+
|
|
400
|
+
expect(
|
|
401
|
+
<Wrapper>
|
|
402
|
+
<ClassDeclaration
|
|
403
|
+
public
|
|
404
|
+
name="TestClass"
|
|
405
|
+
primaryConstructor={ctorParams}
|
|
406
|
+
>
|
|
407
|
+
<Property
|
|
408
|
+
name="PrettyName"
|
|
409
|
+
type="string"
|
|
410
|
+
get
|
|
411
|
+
initializer={code`$"{${paramNameRefkey}} {${paramSizeRefkey}}"`}
|
|
412
|
+
/>
|
|
413
|
+
</ClassDeclaration>
|
|
414
|
+
</Wrapper>,
|
|
415
|
+
).toRenderTo(`
|
|
416
|
+
public class TestClass(string name, int size)
|
|
417
|
+
{
|
|
418
|
+
string PrettyName { get; } = $"{name} {size}";
|
|
419
|
+
}
|
|
420
|
+
`);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it("primary constructor params conflict with method", () => {
|
|
424
|
+
const ctorParams = [{ name: "name", type: "string" }];
|
|
425
|
+
|
|
426
|
+
expect(
|
|
427
|
+
<Wrapper>
|
|
428
|
+
<NamePolicyContext.Provider value={createNamePolicy((x) => x)}>
|
|
429
|
+
<ClassDeclaration
|
|
430
|
+
public
|
|
431
|
+
name="TestClass"
|
|
432
|
+
primaryConstructor={ctorParams}
|
|
433
|
+
>
|
|
434
|
+
<Field name="name" type="string" />
|
|
435
|
+
</ClassDeclaration>
|
|
436
|
+
</NamePolicyContext.Provider>
|
|
437
|
+
</Wrapper>,
|
|
438
|
+
).toRenderTo(`
|
|
439
|
+
public class TestClass(string name)
|
|
440
|
+
{
|
|
441
|
+
string name_2;
|
|
442
|
+
}
|
|
443
|
+
`);
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it("specify doc comment", () => {
|
|
448
|
+
expect(
|
|
449
|
+
<TestNamespace>
|
|
450
|
+
<ClassDeclaration name="Test" doc="This is a test" />
|
|
451
|
+
</TestNamespace>,
|
|
452
|
+
).toRenderTo(`
|
|
453
|
+
/// This is a test
|
|
454
|
+
class Test;
|
|
455
|
+
`);
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
it("supports class member doc comments", () => {
|
|
459
|
+
expect(
|
|
460
|
+
<TestNamespace>
|
|
461
|
+
<ClassDeclaration name="Test" doc="This is a test">
|
|
462
|
+
<Field name="Member" public type="int" doc="This is a member" />
|
|
463
|
+
</ClassDeclaration>
|
|
464
|
+
</TestNamespace>,
|
|
465
|
+
).toRenderTo(`
|
|
466
|
+
/// This is a test
|
|
467
|
+
class Test
|
|
468
|
+
{
|
|
469
|
+
/// This is a member
|
|
470
|
+
public int Member;
|
|
471
|
+
}
|
|
472
|
+
`);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it("specify attributes", () => {
|
|
476
|
+
expect(
|
|
477
|
+
<TestNamespace>
|
|
478
|
+
<ClassDeclaration name="Test" attributes={[<Attribute name="Test" />]} />
|
|
479
|
+
</TestNamespace>,
|
|
480
|
+
).toRenderTo(`
|
|
481
|
+
[Test]
|
|
482
|
+
class Test;
|
|
483
|
+
`);
|
|
484
|
+
});
|
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
Block,
|
|
3
|
+
Children,
|
|
4
|
+
Declaration,
|
|
5
|
+
DeclarationProps,
|
|
6
|
+
join,
|
|
7
|
+
Name,
|
|
8
|
+
Namekey,
|
|
9
|
+
Refkey,
|
|
10
|
+
Scope,
|
|
11
|
+
} from "@alloy-js/core";
|
|
3
12
|
import {
|
|
4
13
|
AccessModifiers,
|
|
5
14
|
computeModifiersPrefix,
|
|
6
15
|
getAccessModifier,
|
|
7
16
|
makeModifiers,
|
|
8
|
-
} from "
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { TypeParameters } from "./type-parameters/type-parameters.jsx";
|
|
17
|
+
} from "../../modifiers.js";
|
|
18
|
+
import { createClassScope } from "../../scopes/factories.js";
|
|
19
|
+
import { createNamedTypeSymbol } from "../../symbols/factories.js";
|
|
20
|
+
import { AttributeList, AttributesProp } from "../attributes/attributes.jsx";
|
|
21
|
+
import { DocWhen } from "../doc/comment.jsx";
|
|
22
|
+
import { ParameterProps, Parameters } from "../parameters/parameters.jsx";
|
|
23
|
+
import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.jsx";
|
|
24
|
+
import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
|
|
25
|
+
import { TypeParameters } from "../type-parameters/type-parameters.jsx";
|
|
18
26
|
|
|
19
27
|
export interface ClassModifiers {
|
|
20
28
|
readonly abstract?: boolean;
|
|
@@ -25,20 +33,20 @@ export interface ClassModifiers {
|
|
|
25
33
|
|
|
26
34
|
const getClassModifiers = makeModifiers<ClassModifiers>([
|
|
27
35
|
"abstract",
|
|
28
|
-
"partial",
|
|
29
36
|
"sealed",
|
|
30
37
|
"static",
|
|
38
|
+
"partial",
|
|
31
39
|
]);
|
|
32
40
|
|
|
33
41
|
// properties for creating a class
|
|
34
42
|
export interface ClassDeclarationProps
|
|
35
|
-
extends Omit<
|
|
43
|
+
extends Omit<DeclarationProps, "nameKind">,
|
|
36
44
|
AccessModifiers,
|
|
37
45
|
ClassModifiers {
|
|
38
|
-
name: string;
|
|
46
|
+
name: string | Namekey;
|
|
39
47
|
/** Doc comment */
|
|
40
|
-
doc?:
|
|
41
|
-
refkey?:
|
|
48
|
+
doc?: Children;
|
|
49
|
+
refkey?: Refkey;
|
|
42
50
|
|
|
43
51
|
/**
|
|
44
52
|
* Type parameters for the class
|
|
@@ -55,10 +63,10 @@ export interface ClassDeclarationProps
|
|
|
55
63
|
typeParameters?: (string | TypeParameterProps)[];
|
|
56
64
|
|
|
57
65
|
/** Base class that this class extends */
|
|
58
|
-
baseType?:
|
|
66
|
+
baseType?: Children;
|
|
59
67
|
|
|
60
68
|
/** Interfaces this class implements */
|
|
61
|
-
interfaceTypes?:
|
|
69
|
+
interfaceTypes?: Children[];
|
|
62
70
|
|
|
63
71
|
/**
|
|
64
72
|
* Define attributes to attach
|
|
@@ -77,6 +85,24 @@ export interface ClassDeclarationProps
|
|
|
77
85
|
* ```
|
|
78
86
|
*/
|
|
79
87
|
attributes?: AttributesProp;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Set the primary constructor parameters
|
|
91
|
+
* @example
|
|
92
|
+
* ```tsx
|
|
93
|
+
* <ClassDeclaration name="MyClass" primaryConstructor={[
|
|
94
|
+
* {name: "value", type: "int"}
|
|
95
|
+
* ]}>
|
|
96
|
+
* ```
|
|
97
|
+
* This will produce:
|
|
98
|
+
* ```csharp
|
|
99
|
+
* public class MyClass(int value)
|
|
100
|
+
* {
|
|
101
|
+
*
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
primaryConstructor?: ParameterProps[];
|
|
80
106
|
}
|
|
81
107
|
|
|
82
108
|
/**
|
|
@@ -104,19 +130,11 @@ export interface ClassDeclarationProps
|
|
|
104
130
|
* ```
|
|
105
131
|
*/
|
|
106
132
|
export function ClassDeclaration(props: ClassDeclarationProps) {
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
const thisClassSymbol = new CSharpOutputSymbol(name, {
|
|
133
|
+
const thisClassSymbol = createNamedTypeSymbol(props.name, "class", {
|
|
110
134
|
refkeys: props.refkey,
|
|
111
135
|
});
|
|
112
136
|
|
|
113
|
-
|
|
114
|
-
// members will automatically "inherit" this scope so
|
|
115
|
-
// that refkeys to them will produce the fully-qualified
|
|
116
|
-
// name e.g. Foo.Bar.
|
|
117
|
-
const thisClassScope = new CSharpMemberScope("class-decl", {
|
|
118
|
-
owner: thisClassSymbol,
|
|
119
|
-
});
|
|
137
|
+
const thisClassScope = createClassScope(thisClassSymbol);
|
|
120
138
|
|
|
121
139
|
const bases = [
|
|
122
140
|
...(props.baseType ? [props.baseType] : []),
|
|
@@ -129,23 +147,24 @@ export function ClassDeclaration(props: ClassDeclarationProps) {
|
|
|
129
147
|
getClassModifiers(props),
|
|
130
148
|
]);
|
|
131
149
|
return (
|
|
132
|
-
<
|
|
150
|
+
<Declaration symbol={thisClassSymbol}>
|
|
133
151
|
<DocWhen doc={props.doc} />
|
|
134
152
|
<AttributeList attributes={props.attributes} endline />
|
|
135
153
|
{modifiers}class <Name />
|
|
136
|
-
{
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
154
|
+
<Scope value={thisClassScope}>
|
|
155
|
+
{props.typeParameters && (
|
|
156
|
+
<TypeParameters parameters={props.typeParameters} />
|
|
157
|
+
)}
|
|
158
|
+
{props.primaryConstructor && (
|
|
159
|
+
<Parameters parameters={props.primaryConstructor} />
|
|
160
|
+
)}
|
|
161
|
+
{base}
|
|
162
|
+
{props.typeParameters && (
|
|
163
|
+
<TypeParameterConstraints parameters={props.typeParameters} />
|
|
164
|
+
)}
|
|
165
|
+
{!props.children && ";"}
|
|
166
|
+
{props.children && <Block newline>{props.children}</Block>}
|
|
167
|
+
</Scope>
|
|
168
|
+
</Declaration>
|
|
150
169
|
);
|
|
151
170
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { refkey } from "@alloy-js/core";
|
|
2
2
|
import { expect, it } from "vitest";
|
|
3
3
|
import { TestNamespace } from "../../../test/utils.jsx";
|
|
4
|
-
import { ClassDeclaration } from "../
|
|
5
|
-
import { SourceFile } from "../SourceFile.jsx";
|
|
4
|
+
import { ClassDeclaration } from "../class/declaration.jsx";
|
|
6
5
|
import { Constructor } from "./constructor.jsx";
|
|
7
6
|
|
|
8
7
|
it("reference constructor parameters in body", () => {
|
|
@@ -16,25 +15,20 @@ it("reference constructor parameters in body", () => {
|
|
|
16
15
|
|
|
17
16
|
expect(
|
|
18
17
|
<TestNamespace>
|
|
19
|
-
<
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
</ClassDeclaration>
|
|
26
|
-
</SourceFile>
|
|
18
|
+
<ClassDeclaration public name="TestClass">
|
|
19
|
+
<Constructor public parameters={ctorParams}>
|
|
20
|
+
{paramNameRefkey};<hbr />
|
|
21
|
+
{paramSizeRefkey};
|
|
22
|
+
</Constructor>
|
|
23
|
+
</ClassDeclaration>
|
|
27
24
|
</TestNamespace>,
|
|
28
25
|
).toRenderTo(`
|
|
29
|
-
|
|
26
|
+
public class TestClass
|
|
30
27
|
{
|
|
31
|
-
public
|
|
28
|
+
public TestClass(string name, int size)
|
|
32
29
|
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
name;
|
|
36
|
-
size;
|
|
37
|
-
}
|
|
30
|
+
name;
|
|
31
|
+
size;
|
|
38
32
|
}
|
|
39
33
|
}
|
|
40
34
|
`);
|