From e30d36a9043a6b1c4bbbb01ea176bef03aa4832b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=91=A8=F0=9F=8F=BC=E2=80=8D=F0=9F=92=BB=20Romain=20M?= =?UTF-8?q?arcadier-Muller?= Date: Mon, 10 Aug 2020 18:32:08 +0200 Subject: [PATCH] fix(jsii): unable to use nested types from dependencies Using `--project-references`, nested types from dependencies could not be used as they would result in the following `jsii` error: ``` Type "" cannot be used as the return type because it is private or @internal ``` THis is because in `--project-references` mode, the ambient declaration for the nested type is the declaration that gets resolved to, and those cannot have the `export` keyword: instead, the surrounding module declaration is annotated with `export ambient`. This adds the necessary code path to actually identify this scenario and to appropriately detect the type is actually visible and exported. The check that was failing had been added in #1861 as a way to provide a more helpful error message when private or `@internal` types are mistakenly used on exported APIs; which explains why this situation did not previously occur. --- .../jsii-calc-lib/lib/submodule/index.ts | 29 +- .../@scope/jsii-calc-lib/test/assembly.jsii | 59 ++- packages/jsii-calc/lib/index.ts | 1 + packages/jsii-calc/lib/nested-class.ts | 9 + packages/jsii-calc/test/assembly.jsii | 35 +- .../lib/targets/dotnet/dotnetgenerator.ts | 3 +- .../__snapshots__/jsii-pacmak.test.ts.snap | 368 +++++++++++++++++- .../test/__snapshots__/jsii-tree.test.js.snap | 28 ++ .../__snapshots__/type-system.test.js.snap | 3 + packages/jsii/lib/assembler.ts | 15 + 10 files changed, 523 insertions(+), 27 deletions(-) create mode 100644 packages/jsii-calc/lib/nested-class.ts diff --git a/packages/@scope/jsii-calc-lib/lib/submodule/index.ts b/packages/@scope/jsii-calc-lib/lib/submodule/index.ts index c6e8c21031..47f4d88df6 100644 --- a/packages/@scope/jsii-calc-lib/lib/submodule/index.ts +++ b/packages/@scope/jsii-calc-lib/lib/submodule/index.ts @@ -8,15 +8,26 @@ export interface ReflectableEntry { } export class Reflector { - public constructor() { } - public asMap(reflectable: IReflectable): Record { - return reflectable.entries.reduce( - (mapping, entry) => { - mapping[entry.key] = entry.value; - return mapping; - }, - {} as Record, - ); + return reflectable.entries.reduce((mapping, entry) => { + mapping[entry.key] = entry.value; + return mapping; + }, {} as Record); + } +} + +/** + * This class is here to show we can use nested classes across module boundaries. + */ +export class NestingClass { + private constructor() {} +} +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace NestingClass { + /** + * This class is here to show we can use nested classes across module boundaries. + */ + export class NestedClass { + public readonly property: string = 'property'; } } diff --git a/packages/@scope/jsii-calc-lib/test/assembly.jsii b/packages/@scope/jsii-calc-lib/test/assembly.jsii index ab9b6e0c47..45cfe84bb7 100644 --- a/packages/@scope/jsii-calc-lib/test/assembly.jsii +++ b/packages/@scope/jsii-calc-lib/test/assembly.jsii @@ -574,6 +574,57 @@ } ] }, + "@scope/jsii-calc-lib.submodule.NestingClass": { + "assembly": "@scope/jsii-calc-lib", + "docs": { + "stability": "deprecated", + "summary": "This class is here to show we can use nested classes across module boundaries." + }, + "fqn": "@scope/jsii-calc-lib.submodule.NestingClass", + "kind": "class", + "locationInModule": { + "filename": "lib/submodule/index.ts", + "line": 22 + }, + "name": "NestingClass", + "namespace": "submodule" + }, + "@scope/jsii-calc-lib.submodule.NestingClass.NestedClass": { + "assembly": "@scope/jsii-calc-lib", + "docs": { + "stability": "deprecated", + "summary": "This class is here to show we can use nested classes across module boundaries." + }, + "fqn": "@scope/jsii-calc-lib.submodule.NestingClass.NestedClass", + "initializer": { + "docs": { + "stability": "deprecated" + } + }, + "kind": "class", + "locationInModule": { + "filename": "lib/submodule/index.ts", + "line": 30 + }, + "name": "NestedClass", + "namespace": "submodule.NestingClass", + "properties": [ + { + "docs": { + "stability": "deprecated" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/submodule/index.ts", + "line": 31 + }, + "name": "property", + "type": { + "primitive": "string" + } + } + ] + }, "@scope/jsii-calc-lib.submodule.ReflectableEntry": { "assembly": "@scope/jsii-calc-lib", "datatype": true, @@ -630,10 +681,6 @@ "initializer": { "docs": { "stability": "deprecated" - }, - "locationInModule": { - "filename": "lib/submodule/index.ts", - "line": 11 } }, "kind": "class", @@ -648,7 +695,7 @@ }, "locationInModule": { "filename": "lib/submodule/index.ts", - "line": 13 + "line": 11 }, "name": "asMap", "parameters": [ @@ -676,5 +723,5 @@ } }, "version": "0.0.0", - "fingerprint": "fVfpIK7xUajlT1zkHIJ8uYJPvy0gLgEe5BM8afu1mVg=" + "fingerprint": "f/4VuNiOkSgTgLR80loQUAzAuzFi+25rmfLcRWKDCrY=" } diff --git a/packages/jsii-calc/lib/index.ts b/packages/jsii-calc/lib/index.ts index f32fd46330..93509cfad0 100644 --- a/packages/jsii-calc/lib/index.ts +++ b/packages/jsii-calc/lib/index.ts @@ -2,6 +2,7 @@ export * from './calculator'; export * from './compliance'; export * from './documented'; export * from './erasures'; +export * from './nested-class'; export * from './stability'; export * from './submodules'; diff --git a/packages/jsii-calc/lib/nested-class.ts b/packages/jsii-calc/lib/nested-class.ts new file mode 100644 index 0000000000..8311927085 --- /dev/null +++ b/packages/jsii-calc/lib/nested-class.ts @@ -0,0 +1,9 @@ +import { submodule } from '@scope/jsii-calc-lib'; + +export class NestedClassInstance { + public static makeInstance(): submodule.NestingClass.NestedClass { + return new submodule.NestingClass.NestedClass(); + } + + private constructor() {} +} diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index 9652ef283f..818f3d2acc 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -196,7 +196,7 @@ "jsii-calc.submodule": { "locationInModule": { "filename": "lib/index.ts", - "line": 8 + "line": 9 } }, "jsii-calc.submodule.back_references": { @@ -8373,6 +8373,37 @@ } ] }, + "jsii-calc.NestedClassInstance": { + "assembly": "jsii-calc", + "docs": { + "stability": "experimental" + }, + "fqn": "jsii-calc.NestedClassInstance", + "kind": "class", + "locationInModule": { + "filename": "lib/nested-class.ts", + "line": 3 + }, + "methods": [ + { + "docs": { + "stability": "experimental" + }, + "locationInModule": { + "filename": "lib/nested-class.ts", + "line": 4 + }, + "name": "makeInstance", + "returns": { + "type": { + "fqn": "@scope/jsii-calc-lib.submodule.NestingClass.NestedClass" + } + }, + "static": true + } + ], + "name": "NestedClassInstance" + }, "jsii-calc.NestedStruct": { "assembly": "jsii-calc", "datatype": true, @@ -13722,5 +13753,5 @@ } }, "version": "0.0.0", - "fingerprint": "AksOoFurRMyuF7gSjHXHbIRIIjq0e0R0CvpHycvyI3U=" + "fingerprint": "mLU0hvK9Teaq2GAeeCGFPwAZab85G7lFIH/VCKgAvp4=" } diff --git a/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts b/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts index 691655584c..98fffa0bc8 100644 --- a/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts +++ b/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts @@ -283,7 +283,6 @@ export class DotNetGenerator extends Generator { // Nested classes will be dealt with during calc code generation const nested = this.isNested(cls); - const inner = nested ? ' static' : ''; const absPrefix = abstract ? ' abstract' : ''; this.openFileIfNeeded(className, namespace, nested); @@ -294,7 +293,7 @@ export class DotNetGenerator extends Generator { this.dotnetRuntimeGenerator.emitAttributesForClass(cls); this.code.openBlock( - `public${inner}${absPrefix} class ${className}${implementsExpr}`, + `public${absPrefix} class ${className}${implementsExpr}`, ); // Compute the class parameters diff --git a/packages/jsii-pacmak/test/__snapshots__/jsii-pacmak.test.ts.snap b/packages/jsii-pacmak/test/__snapshots__/jsii-pacmak.test.ts.snap index 96df49deac..95fafe499c 100644 --- a/packages/jsii-pacmak/test/__snapshots__/jsii-pacmak.test.ts.snap +++ b/packages/jsii-pacmak/test/__snapshots__/jsii-pacmak.test.ts.snap @@ -2241,6 +2241,7 @@ exports[`Generated code for "@scope/jsii-calc-lib": / 1`] = ` ┃ ┃ ┣━ 📄 IReflectable.cs ┃ ┃ ┣━ 📄 IReflectableEntry.cs ┃ ┃ ┣━ 📄 IReflectableProxy.cs + ┃ ┃ ┣━ 📄 NestingClass.cs ┃ ┃ ┣━ 📄 ReflectableEntry.cs ┃ ┃ ┣━ 📄 ReflectableEntryProxy.cs ┃ ┃ ┗━ 📄 Reflector.cs @@ -2259,6 +2260,7 @@ exports[`Generated code for "@scope/jsii-calc-lib": / 1`] = ` ┃ ┃ ┗━ 📁 calculator ┃ ┃ ┣━ 📁 custom_submodule_name ┃ ┃ ┃ ┣━ 📄 IReflectable.java + ┃ ┃ ┃ ┣━ 📄 NestingClass.java ┃ ┃ ┃ ┣━ 📄 ReflectableEntry.java ┃ ┃ ┃ ┗━ 📄 Reflector.java ┃ ┃ ┗━ 📁 lib @@ -2879,6 +2881,57 @@ Object { } ] }, + \\"@scope/jsii-calc-lib.submodule.NestingClass\\": { + \\"assembly\\": \\"@scope/jsii-calc-lib\\", + \\"docs\\": { + \\"stability\\": \\"deprecated\\", + \\"summary\\": \\"This class is here to show we can use nested classes across module boundaries.\\" + }, + \\"fqn\\": \\"@scope/jsii-calc-lib.submodule.NestingClass\\", + \\"kind\\": \\"class\\", + \\"locationInModule\\": { + \\"filename\\": \\"lib/submodule/index.ts\\", + \\"line\\": 22 + }, + \\"name\\": \\"NestingClass\\", + \\"namespace\\": \\"submodule\\" + }, + \\"@scope/jsii-calc-lib.submodule.NestingClass.NestedClass\\": { + \\"assembly\\": \\"@scope/jsii-calc-lib\\", + \\"docs\\": { + \\"stability\\": \\"deprecated\\", + \\"summary\\": \\"This class is here to show we can use nested classes across module boundaries.\\" + }, + \\"fqn\\": \\"@scope/jsii-calc-lib.submodule.NestingClass.NestedClass\\", + \\"initializer\\": { + \\"docs\\": { + \\"stability\\": \\"deprecated\\" + } + }, + \\"kind\\": \\"class\\", + \\"locationInModule\\": { + \\"filename\\": \\"lib/submodule/index.ts\\", + \\"line\\": 30 + }, + \\"name\\": \\"NestedClass\\", + \\"namespace\\": \\"submodule.NestingClass\\", + \\"properties\\": [ + { + \\"docs\\": { + \\"stability\\": \\"deprecated\\" + }, + \\"immutable\\": true, + \\"locationInModule\\": { + \\"filename\\": \\"lib/submodule/index.ts\\", + \\"line\\": 31 + }, + \\"name\\": \\"property\\", + \\"type\\": { + \\"primitive\\": \\"string\\" + } + } + ] + }, \\"@scope/jsii-calc-lib.submodule.ReflectableEntry\\": { \\"assembly\\": \\"@scope/jsii-calc-lib\\", \\"datatype\\": true, @@ -2935,10 +2988,6 @@ Object { \\"initializer\\": { \\"docs\\": { \\"stability\\": \\"deprecated\\" - }, - \\"locationInModule\\": { - \\"filename\\": \\"lib/submodule/index.ts\\", - \\"line\\": 11 } }, \\"kind\\": \\"class\\", @@ -2953,7 +3002,7 @@ Object { }, \\"locationInModule\\": { \\"filename\\": \\"lib/submodule/index.ts\\", - \\"line\\": 13 + \\"line\\": 11 }, \\"name\\": \\"asMap\\", \\"parameters\\": [ @@ -2981,7 +3030,7 @@ Object { } }, \\"version\\": \\"0.0.0\\", - \\"fingerprint\\": \\"fVfpIK7xUajlT1zkHIJ8uYJPvy0gLgEe5BM8afu1mVg=\\" + \\"fingerprint\\": \\"f/4VuNiOkSgTgLR80loQUAzAuzFi+25rmfLcRWKDCrY=\\" } ", } @@ -4020,6 +4069,83 @@ namespace Amazon.JSII.Tests.CustomSubmoduleName } `; +exports[`Generated code for "@scope/jsii-calc-lib": /dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon/JSII/Tests/CustomSubmoduleName/NestingClass.cs 1`] = ` +Object { + Symbol(file): "using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CustomSubmoduleName +{ + /// This class is here to show we can use nested classes across module boundaries. + /// + /// Stability: Deprecated + /// + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CustomSubmoduleName.NestingClass), fullyQualifiedName: \\"@scope/jsii-calc-lib.submodule.NestingClass\\")] + [System.Obsolete()] + public class NestingClass : DeputyBase + { + /// Used by jsii to construct an instance of this class from a Javascript-owned object reference + /// The Javascript-owned object reference + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected NestingClass(ByRefValue reference): base(reference) + { + } + + /// Used by jsii to construct an instance of this class from DeputyProps + /// The deputy props + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected NestingClass(DeputyProps props): base(props) + { + } + /// This class is here to show we can use nested classes across module boundaries. + /// + /// Stability: Deprecated + /// + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CustomSubmoduleName.NestingClass.NestedClass), fullyQualifiedName: \\"@scope/jsii-calc-lib.submodule.NestingClass.NestedClass\\")] + [System.Obsolete()] + public class NestedClass : DeputyBase + { + /// + /// Stability: Deprecated + /// + [System.Obsolete()] + public NestedClass(): base(new DeputyProps(new object[]{})) + { + } + + /// Used by jsii to construct an instance of this class from a Javascript-owned object reference + /// The Javascript-owned object reference + [System.Obsolete()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected NestedClass(ByRefValue reference): base(reference) + { + } + + /// Used by jsii to construct an instance of this class from DeputyProps + /// The deputy props + [System.Obsolete()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected NestedClass(DeputyProps props): base(props) + { + } + + /// + /// Stability: Deprecated + /// + [JsiiProperty(name: \\"property\\", typeJson: \\"{\\\\\\"primitive\\\\\\":\\\\\\"string\\\\\\"}\\")] + [System.Obsolete()] + public virtual string Property + { + get => GetInstanceProperty(); + } + } + } +} +", +} +`; + exports[`Generated code for "@scope/jsii-calc-lib": /dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon/JSII/Tests/CustomSubmoduleName/ReflectableEntry.cs 1`] = ` Object { Symbol(file): "using Amazon.JSII.Runtime.Deputy; @@ -4373,6 +4499,64 @@ public interface IReflectable extends software.amazon.jsii.JsiiSerializable { } `; +exports[`Generated code for "@scope/jsii-calc-lib": /java/src/main/java/software/amazon/jsii/tests/calculator/custom_submodule_name/NestingClass.java 1`] = ` +Object { + Symbol(file): "package software.amazon.jsii.tests.calculator.custom_submodule_name; + +/** + * This class is here to show we can use nested classes across module boundaries. + */ +@javax.annotation.Generated(value = \\"jsii-pacmak\\") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) +@Deprecated +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.lib.$Module.class, fqn = \\"@scope/jsii-calc-lib.submodule.NestingClass\\") +public class NestingClass extends software.amazon.jsii.JsiiObject { + + protected NestingClass(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected NestingClass(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + /** + * This class is here to show we can use nested classes across module boundaries. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) + @Deprecated + @software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.lib.$Module.class, fqn = \\"@scope/jsii-calc-lib.submodule.NestingClass.NestedClass\\") + public static class NestedClass extends software.amazon.jsii.JsiiObject { + + protected NestedClass(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected NestedClass(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) + @Deprecated + public NestedClass() { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Deprecated) + @Deprecated + public @org.jetbrains.annotations.NotNull java.lang.String getProperty() { + return this.jsiiGet(\\"property\\", java.lang.String.class); + } + } +} +", +} +`; + exports[`Generated code for "@scope/jsii-calc-lib": /java/src/main/java/software/amazon/jsii/tests/calculator/custom_submodule_name/ReflectableEntry.java 1`] = ` Object { Symbol(file): "package software.amazon.jsii.tests.calculator.custom_submodule_name; @@ -5438,6 +5622,8 @@ Object { @scope/jsii-calc-lib.StructWithOnlyOptionals=software.amazon.jsii.tests.calculator.lib.StructWithOnlyOptionals @scope/jsii-calc-lib.Value=software.amazon.jsii.tests.calculator.lib.Value @scope/jsii-calc-lib.submodule.IReflectable=software.amazon.jsii.tests.calculator.custom_submodule_name.IReflectable +@scope/jsii-calc-lib.submodule.NestingClass=software.amazon.jsii.tests.calculator.custom_submodule_name.NestingClass +@scope/jsii-calc-lib.submodule.NestingClass.NestedClass=software.amazon.jsii.tests.calculator.custom_submodule_name.NestingClass$NestedClass @scope/jsii-calc-lib.submodule.ReflectableEntry=software.amazon.jsii.tests.calculator.custom_submodule_name.ReflectableEntry @scope/jsii-calc-lib.submodule.Reflector=software.amazon.jsii.tests.calculator.custom_submodule_name.Reflector ", @@ -6080,6 +6266,42 @@ class _IReflectableProxy: return jsii.get(self, \\"entries\\") +class NestingClass( + metaclass=jsii.JSIIMeta, jsii_type=\\"@scope/jsii-calc-lib.submodule.NestingClass\\" +): + \\"\\"\\"This class is here to show we can use nested classes across module boundaries. + + stability + :stability: deprecated + \\"\\"\\" + + class NestedClass( + metaclass=jsii.JSIIMeta, + jsii_type=\\"@scope/jsii-calc-lib.submodule.NestingClass.NestedClass\\", + ): + \\"\\"\\"This class is here to show we can use nested classes across module boundaries. + + stability + :stability: deprecated + \\"\\"\\" + + def __init__(self) -> None: + \\"\\"\\" + stability + :stability: deprecated + \\"\\"\\" + jsii.create(NestingClass.NestedClass, self, []) + + @builtins.property + @jsii.member(jsii_name=\\"property\\") + def property(self) -> str: + \\"\\"\\" + stability + :stability: deprecated + \\"\\"\\" + return jsii.get(self, \\"property\\") + + @jsii.data_type( jsii_type=\\"@scope/jsii-calc-lib.submodule.ReflectableEntry\\", jsii_struct_bases=[], @@ -6155,6 +6377,7 @@ class Reflector( __all__ = [ \\"IReflectable\\", + \\"NestingClass\\", \\"ReflectableEntry\\", \\"Reflector\\", ] @@ -6410,6 +6633,7 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┃ ┣━ 📄 Multiply.cs ┃ ┃ ┣━ 📄 NamespaceDoc.cs ┃ ┃ ┣━ 📄 Negate.cs + ┃ ┃ ┣━ 📄 NestedClassInstance.cs ┃ ┃ ┣━ 📄 NestedStruct.cs ┃ ┃ ┣━ 📄 NestedStructProxy.cs ┃ ┃ ┣━ 📄 NodeStandardLibrary.cs @@ -6678,6 +6902,7 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┃ ┣━ 📄 MethodNamedProperty.java ┃ ┃ ┣━ 📄 Multiply.java ┃ ┃ ┣━ 📄 Negate.java + ┃ ┃ ┣━ 📄 NestedClassInstance.java ┃ ┃ ┣━ 📄 NestedStruct.java ┃ ┃ ┣━ 📄 NodeStandardLibrary.java ┃ ┃ ┣━ 📄 NullShouldBeTreatedAsUndefined.java @@ -7015,7 +7240,7 @@ Object { \\"jsii-calc.submodule\\": { \\"locationInModule\\": { \\"filename\\": \\"lib/index.ts\\", - \\"line\\": 8 + \\"line\\": 9 } }, \\"jsii-calc.submodule.back_references\\": { @@ -15192,6 +15417,37 @@ Object { } ] }, + \\"jsii-calc.NestedClassInstance\\": { + \\"assembly\\": \\"jsii-calc\\", + \\"docs\\": { + \\"stability\\": \\"experimental\\" + }, + \\"fqn\\": \\"jsii-calc.NestedClassInstance\\", + \\"kind\\": \\"class\\", + \\"locationInModule\\": { + \\"filename\\": \\"lib/nested-class.ts\\", + \\"line\\": 3 + }, + \\"methods\\": [ + { + \\"docs\\": { + \\"stability\\": \\"experimental\\" + }, + \\"locationInModule\\": { + \\"filename\\": \\"lib/nested-class.ts\\", + \\"line\\": 4 + }, + \\"name\\": \\"makeInstance\\", + \\"returns\\": { + \\"type\\": { + \\"fqn\\": \\"@scope/jsii-calc-lib.submodule.NestingClass.NestedClass\\" + } + }, + \\"static\\": true + } + ], + \\"name\\": \\"NestedClassInstance\\" + }, \\"jsii-calc.NestedStruct\\": { \\"assembly\\": \\"jsii-calc\\", \\"datatype\\": true, @@ -20541,7 +20797,7 @@ Object { } }, \\"version\\": \\"0.0.0\\", - \\"fingerprint\\": \\"AksOoFurRMyuF7gSjHXHbIRIIjq0e0R0CvpHycvyI3U=\\" + \\"fingerprint\\": \\"mLU0hvK9Teaq2GAeeCGFPwAZab85G7lFIH/VCKgAvp4=\\" } ", } @@ -31953,6 +32209,48 @@ namespace Amazon.JSII.Tests.CalculatorNamespace } `; +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/NestedClassInstance.cs 1`] = ` +Object { + Symbol(file): "using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + /// + /// Stability: Experimental + /// + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.NestedClassInstance), fullyQualifiedName: \\"jsii-calc.NestedClassInstance\\")] + public class NestedClassInstance : DeputyBase + { + /// Used by jsii to construct an instance of this class from a Javascript-owned object reference + /// The Javascript-owned object reference + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected NestedClassInstance(ByRefValue reference): base(reference) + { + } + + /// Used by jsii to construct an instance of this class from DeputyProps + /// The deputy props + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected NestedClassInstance(DeputyProps props): base(props) + { + } + + /// + /// Stability: Experimental + /// + [JsiiMethod(name: \\"makeInstance\\", returnsJson: \\"{\\\\\\"type\\\\\\":{\\\\\\"fqn\\\\\\":\\\\\\"@scope/jsii-calc-lib.submodule.NestingClass.NestedClass\\\\\\"}}\\")] + public static Amazon.JSII.Tests.CustomSubmoduleName.NestingClass.NestedClass MakeInstance() + { + return InvokeStaticMethod(typeof(Amazon.JSII.Tests.CalculatorNamespace.NestedClassInstance), new System.Type[]{}, new object[]{}); + } + } +} +", +} +`; + exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/NestedStruct.cs 1`] = ` Object { Symbol(file): "using Amazon.JSII.Runtime.Deputy; @@ -48362,6 +48660,38 @@ public class Negate extends software.amazon.jsii.tests.calculator.UnaryOperation } `; +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/NestedClassInstance.java 1`] = ` +Object { + Symbol(file): "package software.amazon.jsii.tests.calculator; + +/** + * EXPERIMENTAL + */ +@javax.annotation.Generated(value = \\"jsii-pacmak\\") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = \\"jsii-calc.NestedClassInstance\\") +public class NestedClassInstance extends software.amazon.jsii.JsiiObject { + + protected NestedClassInstance(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected NestedClassInstance(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + + /** + * EXPERIMENTAL + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public static @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.custom_submodule_name.NestingClass.NestedClass makeInstance() { + return software.amazon.jsii.JsiiObject.jsiiStaticCall(software.amazon.jsii.tests.calculator.NestedClassInstance.class, \\"makeInstance\\", software.amazon.jsii.tests.calculator.custom_submodule_name.NestingClass.NestedClass.class); + } +} +", +} +`; + exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/NestedStruct.java 1`] = ` Object { Symbol(file): "package software.amazon.jsii.tests.calculator; @@ -56317,6 +56647,7 @@ jsii-calc.LoadBalancedFargateServiceProps=software.amazon.jsii.tests.calculator. jsii-calc.MethodNamedProperty=software.amazon.jsii.tests.calculator.MethodNamedProperty jsii-calc.Multiply=software.amazon.jsii.tests.calculator.Multiply jsii-calc.Negate=software.amazon.jsii.tests.calculator.Negate +jsii-calc.NestedClassInstance=software.amazon.jsii.tests.calculator.NestedClassInstance jsii-calc.NestedStruct=software.amazon.jsii.tests.calculator.NestedStruct jsii-calc.NodeStandardLibrary=software.amazon.jsii.tests.calculator.NodeStandardLibrary jsii-calc.NullShouldBeTreatedAsUndefined=software.amazon.jsii.tests.calculator.NullShouldBeTreatedAsUndefined @@ -62544,6 +62875,26 @@ class Multiply( return jsii.get(self, \\"value\\") +class NestedClassInstance( + metaclass=jsii.JSIIMeta, jsii_type=\\"jsii-calc.NestedClassInstance\\" +): + \\"\\"\\" + stability + :stability: experimental + \\"\\"\\" + + @jsii.member(jsii_name=\\"makeInstance\\") + @builtins.classmethod + def make_instance( + cls + ) -> scope.jsii_calc_lib.custom_submodule_name.NestingClass.NestedClass: + \\"\\"\\" + stability + :stability: experimental + \\"\\"\\" + return jsii.sinvoke(cls, \\"makeInstance\\", []) + + @jsii.data_type( jsii_type=\\"jsii-calc.NestedStruct\\", jsii_struct_bases=[], @@ -66521,6 +66872,7 @@ __all__ = [ \\"MethodNamedProperty\\", \\"Multiply\\", \\"Negate\\", + \\"NestedClassInstance\\", \\"NestedStruct\\", \\"NodeStandardLibrary\\", \\"NullShouldBeTreatedAsUndefined\\", diff --git a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap index f33ff2debc..cbe8823e4d 100644 --- a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap +++ b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap @@ -1217,6 +1217,11 @@ exports[`jsii-tree --all 1`] = ` │ │ └─┬ value property (experimental) │ │ ├── immutable │ │ └── type: number + │ ├─┬ class NestedClassInstance (experimental) + │ │ └─┬ members + │ │ └─┬ static makeInstance() method (experimental) + │ │ ├── static + │ │ └── returns: @scope/jsii-calc-lib.submodule.NestingClass.NestedClass │ ├─┬ class NodeStandardLibrary (experimental) │ │ └─┬ members │ │ ├── () initializer (experimental) @@ -2538,6 +2543,14 @@ exports[`jsii-tree --all 1`] = ` ├─┬ submodules │ └─┬ submodule │ └─┬ types + │ ├─┬ class NestingClass (deprecated) + │ │ └── members + │ ├─┬ class NestedClass (deprecated) + │ │ └─┬ members + │ │ ├── () initializer (deprecated) + │ │ └─┬ property property (deprecated) + │ │ ├── immutable + │ │ └── type: string │ ├─┬ class Reflector (deprecated) │ │ └─┬ members │ │ ├── () initializer (deprecated) @@ -2795,6 +2808,7 @@ exports[`jsii-tree --inheritance 1`] = ` │ ├─┬ class Negate │ │ ├── base: UnaryOperation │ │ └── interfaces: IFriendlier + │ ├── class NestedClassInstance │ ├── class NodeStandardLibrary │ ├── class NullShouldBeTreatedAsUndefined │ ├── class NumberGenerator @@ -2966,6 +2980,8 @@ exports[`jsii-tree --inheritance 1`] = ` ├─┬ submodules │ └─┬ submodule │ └─┬ types + │ ├── class NestingClass + │ ├── class NestedClass │ ├── class Reflector │ ├── interface IReflectable │ └── interface ReflectableEntry @@ -3549,6 +3565,9 @@ exports[`jsii-tree --members 1`] = ` │ │ ├── hello() method │ │ ├── toString() method │ │ └── value property + │ ├─┬ class NestedClassInstance + │ │ └─┬ members + │ │ └── static makeInstance() method │ ├─┬ class NodeStandardLibrary │ │ └─┬ members │ │ ├── () initializer @@ -4122,6 +4141,12 @@ exports[`jsii-tree --members 1`] = ` ├─┬ submodules │ └─┬ submodule │ └─┬ types + │ ├─┬ class NestingClass + │ │ └── members + │ ├─┬ class NestedClass + │ │ └─┬ members + │ │ ├── () initializer + │ │ └── property property │ ├─┬ class Reflector │ │ └─┬ members │ │ ├── () initializer @@ -4318,6 +4343,7 @@ exports[`jsii-tree --types 1`] = ` │ ├── class MethodNamedProperty │ ├── class Multiply │ ├── class Negate + │ ├── class NestedClassInstance │ ├── class NodeStandardLibrary │ ├── class NullShouldBeTreatedAsUndefined │ ├── class NumberGenerator @@ -4454,6 +4480,8 @@ exports[`jsii-tree --types 1`] = ` ├─┬ submodules │ └─┬ submodule │ └─┬ types + │ ├── class NestingClass + │ ├── class NestedClass │ ├── class Reflector │ ├── interface IReflectable │ └── interface ReflectableEntry diff --git a/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap b/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap index ba7ad1b5c6..1ed794d0c4 100644 --- a/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap +++ b/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap @@ -16,6 +16,8 @@ Array [ "@scope/jsii-calc-lib.Number", "@scope/jsii-calc-lib.Operation", "@scope/jsii-calc-lib.Value", + "@scope/jsii-calc-lib.submodule.NestingClass", + "@scope/jsii-calc-lib.submodule.NestingClass.NestedClass", "@scope/jsii-calc-lib.submodule.Reflector", "jsii-calc.AbstractClass", "jsii-calc.AbstractClassBase", @@ -87,6 +89,7 @@ Array [ "jsii-calc.MethodNamedProperty", "jsii-calc.Multiply", "jsii-calc.Negate", + "jsii-calc.NestedClassInstance", "jsii-calc.NodeStandardLibrary", "jsii-calc.NullShouldBeTreatedAsUndefined", "jsii-calc.NumberGenerator", diff --git a/packages/jsii/lib/assembler.ts b/packages/jsii/lib/assembler.ts index fa8bed0f3b..8b3b1d5c34 100644 --- a/packages/jsii/lib/assembler.ts +++ b/packages/jsii/lib/assembler.ts @@ -2528,6 +2528,7 @@ function _isPrivate(symbol: ts.Symbol): boolean { ts.SyntaxKind.InterfaceDeclaration, ts.SyntaxKind.EnumDeclaration, ]); + // if the symbol doesn't have a value declaration, we are assuming it's a type (enum/interface/class) // and check that it has an "export" modifier if ( @@ -2538,6 +2539,20 @@ function _isPrivate(symbol: ts.Symbol): boolean { for (const decl of symbol.declarations) { if (ts.getCombinedModifierFlags(decl) & ts.ModifierFlags.Export) { hasExport = true; + break; + } + // Handle nested classes from project references + if (ts.isModuleBlock(decl.parent)) { + const moduleDeclaration = decl.parent.parent; + const modifiers = ts.getCombinedModifierFlags(moduleDeclaration); + // The trick is the module is declared as ambient & exported + if ( + (modifiers & ts.ModifierFlags.Ambient) !== 0 && + (modifiers & ts.ModifierFlags.Export) !== 0 + ) { + hasExport = true; + break; + } } } return !hasExport;