From e804caba89e480fb9c1ec7361d5082e0d1eb5ade Mon Sep 17 00:00:00 2001 From: Romain Marcadier-Muller Date: Wed, 12 Jun 2019 13:47:19 +0200 Subject: [PATCH] fix(jsii): Correctly ignore private properties from ctor (#531) Whend eclared as part of a constructor argument declaration, private properties would not be ignored as such, which could cause spurious JSII errors, and made private APIs visible to other languages. --- packages/jsii-calc/lib/compliance.ts | 11 +++++ packages/jsii-calc/test/assembly.jsii | 46 ++++++++++++++++++- .../.jsii | 46 ++++++++++++++++++- .../WithPrivatePropertyInConstructor.cs | 30 ++++++++++++ .../amazon/jsii/tests/calculator/$Module.java | 1 + .../WithPrivatePropertyInConstructor.java | 39 ++++++++++++++++ .../python/src/jsii_calc/__init__.py | 28 ++++++++++- .../expected.jsii-calc/sphinx/jsii-calc.rst | 39 ++++++++++++++++ .../jsii-reflect/test/classes.expected.txt | 3 +- .../test/jsii-tree.test.all.expected.txt | 9 ++++ .../jsii-tree.test.inheritance.expected.txt | 1 + .../test/jsii-tree.test.members.expected.txt | 4 ++ .../test/jsii-tree.test.types.expected.txt | 1 + packages/jsii/lib/assembler.ts | 2 +- 14 files changed, 255 insertions(+), 5 deletions(-) create mode 100644 packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/WithPrivatePropertyInConstructor.cs create mode 100644 packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/WithPrivatePropertyInConstructor.java diff --git a/packages/jsii-calc/lib/compliance.ts b/packages/jsii-calc/lib/compliance.ts index 7442a7b274..b5a0a7f858 100644 --- a/packages/jsii-calc/lib/compliance.ts +++ b/packages/jsii-calc/lib/compliance.ts @@ -1681,3 +1681,14 @@ export abstract class VoidCallback { } protected abstract overrideMe(): void; } + +/** + * Verifies that private property declarations in constructor arguments are hidden. + */ +export class WithPrivatePropertyInConstructor { + constructor(private readonly privateField: string = 'Success!') { } + + public get success() { + return this.privateField === 'Success!'; + } +} diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index 732163dddb..5246a4694d 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -8448,6 +8448,50 @@ } ] }, + "jsii-calc.WithPrivatePropertyInConstructor": { + "assembly": "jsii-calc", + "docs": { + "stability": "experimental", + "summary": "Verifies that private property declarations in constructor arguments are hidden." + }, + "fqn": "jsii-calc.WithPrivatePropertyInConstructor", + "initializer": { + "docs": { + "stability": "experimental" + }, + "parameters": [ + { + "name": "privateField", + "optional": true, + "type": { + "primitive": "string" + } + } + ] + }, + "kind": "class", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1688 + }, + "name": "WithPrivatePropertyInConstructor", + "properties": [ + { + "docs": { + "stability": "experimental" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1691 + }, + "name": "success", + "type": { + "primitive": "boolean" + } + } + ] + }, "jsii-calc.composition.CompositeOperation": { "abstract": true, "assembly": "jsii-calc", @@ -8604,5 +8648,5 @@ } }, "version": "0.11.2", - "fingerprint": "5vdOZenAtu9InhNSB0CQ4IjyHtR1CAttxJ+dpDOSCBE=" + "fingerprint": "eQpFH3EHC2GlCSnThymTxnuO9HyZBFvsvddZqu1Fy+8=" } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii index 732163dddb..5246a4694d 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii @@ -8448,6 +8448,50 @@ } ] }, + "jsii-calc.WithPrivatePropertyInConstructor": { + "assembly": "jsii-calc", + "docs": { + "stability": "experimental", + "summary": "Verifies that private property declarations in constructor arguments are hidden." + }, + "fqn": "jsii-calc.WithPrivatePropertyInConstructor", + "initializer": { + "docs": { + "stability": "experimental" + }, + "parameters": [ + { + "name": "privateField", + "optional": true, + "type": { + "primitive": "string" + } + } + ] + }, + "kind": "class", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1688 + }, + "name": "WithPrivatePropertyInConstructor", + "properties": [ + { + "docs": { + "stability": "experimental" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 1691 + }, + "name": "success", + "type": { + "primitive": "boolean" + } + } + ] + }, "jsii-calc.composition.CompositeOperation": { "abstract": true, "assembly": "jsii-calc", @@ -8604,5 +8648,5 @@ } }, "version": "0.11.2", - "fingerprint": "5vdOZenAtu9InhNSB0CQ4IjyHtR1CAttxJ+dpDOSCBE=" + "fingerprint": "eQpFH3EHC2GlCSnThymTxnuO9HyZBFvsvddZqu1Fy+8=" } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/WithPrivatePropertyInConstructor.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/WithPrivatePropertyInConstructor.cs new file mode 100644 index 0000000000..df1311762a --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/WithPrivatePropertyInConstructor.cs @@ -0,0 +1,30 @@ +using Amazon.JSII.Runtime.Deputy; + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + /// Verifies that private property declarations in constructor arguments are hidden. + /// stability: Experimental + [JsiiClass(nativeType: typeof(WithPrivatePropertyInConstructor), fullyQualifiedName: "jsii-calc.WithPrivatePropertyInConstructor", parametersJson: "[{\"name\":\"privateField\",\"type\":{\"primitive\":\"string\"},\"optional\":true}]")] + public class WithPrivatePropertyInConstructor : DeputyBase + { + /// stability: Experimental + public WithPrivatePropertyInConstructor(string privateField): base(new DeputyProps(new object[]{privateField})) + { + } + + protected WithPrivatePropertyInConstructor(ByRefValue reference): base(reference) + { + } + + protected WithPrivatePropertyInConstructor(DeputyProps props): base(props) + { + } + + /// stability: Experimental + [JsiiProperty(name: "success", typeJson: "{\"primitive\":\"boolean\"}")] + public virtual bool Success + { + get => GetInstanceProperty(); + } + } +} \ No newline at end of file diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java index 39e5b247a3..b208408dfc 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java +++ b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java @@ -144,6 +144,7 @@ protected Class resolveClass(final String fqn) throws ClassNotFoundException case "jsii-calc.VariadicMethod": return software.amazon.jsii.tests.calculator.VariadicMethod.class; case "jsii-calc.VirtualMethodPlayground": return software.amazon.jsii.tests.calculator.VirtualMethodPlayground.class; case "jsii-calc.VoidCallback": return software.amazon.jsii.tests.calculator.VoidCallback.class; + case "jsii-calc.WithPrivatePropertyInConstructor": return software.amazon.jsii.tests.calculator.WithPrivatePropertyInConstructor.class; case "jsii-calc.composition.CompositeOperation": return software.amazon.jsii.tests.calculator.composition.CompositeOperation.class; case "jsii-calc.composition.CompositeOperation.CompositionStringStyle": return software.amazon.jsii.tests.calculator.composition.CompositeOperation.CompositionStringStyle.class; default: throw new ClassNotFoundException("Unknown JSII type: " + fqn); diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/WithPrivatePropertyInConstructor.java b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/WithPrivatePropertyInConstructor.java new file mode 100644 index 0000000000..47261442b8 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/WithPrivatePropertyInConstructor.java @@ -0,0 +1,39 @@ +package software.amazon.jsii.tests.calculator; + +/** + * Verifies that private property declarations in constructor arguments are hidden. + * + * 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.WithPrivatePropertyInConstructor") +public class WithPrivatePropertyInConstructor extends software.amazon.jsii.JsiiObject { + protected WithPrivatePropertyInConstructor(final software.amazon.jsii.JsiiObject.InitializationMode mode) { + super(mode); + } + /** + * EXPERIMENTAL + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public WithPrivatePropertyInConstructor(@javax.annotation.Nullable final java.lang.String privateField) { + super(software.amazon.jsii.JsiiObject.InitializationMode.Jsii); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this, new Object[] { privateField }); + } + /** + * EXPERIMENTAL + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public WithPrivatePropertyInConstructor() { + super(software.amazon.jsii.JsiiObject.InitializationMode.Jsii); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); + } + + /** + * EXPERIMENTAL + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public java.lang.Boolean getSuccess() { + return this.jsiiGet("success", java.lang.Boolean.class); + } +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py b/packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py index 1585ed1545..49474c4c6f 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py +++ b/packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py @@ -5526,6 +5526,32 @@ def _override_me(self) -> None: return jsii.invoke(self, "overrideMe", []) +class WithPrivatePropertyInConstructor(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.WithPrivatePropertyInConstructor"): + """Verifies that private property declarations in constructor arguments are hidden. + + Stability: + experimental + """ + def __init__(self, private_field: typing.Optional[str]=None) -> None: + """ + Arguments: + privateField: - + + Stability: + experimental + """ + jsii.create(WithPrivatePropertyInConstructor, self, [private_field]) + + @property + @jsii.member(jsii_name="success") + def success(self) -> bool: + """ + Stability: + experimental + """ + return jsii.get(self, "success") + + class composition: class CompositeOperation(scope.jsii_calc_lib.Operation, metaclass=jsii.JSIIAbstractClass, jsii_type="jsii-calc.composition.CompositeOperation"): """Abstract operation composed from an expression of other operations. @@ -5887,6 +5913,6 @@ def parts(self, value: typing.List[scope.jsii_calc_lib.Value]): return jsii.set(self, "parts", value) -__all__ = ["AbstractClass", "AbstractClassBase", "AbstractClassReturner", "Add", "AllTypes", "AllTypesEnum", "AllowedMethodNames", "AsyncVirtualMethods", "AugmentableClass", "BinaryOperation", "Calculator", "CalculatorProps", "ClassThatImplementsTheInternalInterface", "ClassThatImplementsThePrivateInterface", "ClassWithDocs", "ClassWithMutableObjectLiteralProperty", "ClassWithPrivateConstructorAndAutomaticProperties", "ConstructorPassesThisOut", "Constructors", "ConsumersOfThisCrazyTypeSystem", "DefaultedConstructorArgument", "DeprecatedClass", "DeprecatedEnum", "DeprecatedStruct", "DerivedClassHasNoProperties", "DerivedStruct", "DoNotOverridePrivates", "DoNotRecognizeAnyAsOptional", "DocumentedClass", "DontComplainAboutVariadicAfterOptional", "DoubleTrouble", "EraseUndefinedHashValues", "EraseUndefinedHashValuesOptions", "ExperimentalClass", "ExperimentalEnum", "ExperimentalStruct", "ExportedBaseClass", "ExtendsInternalInterface", "GiveMeStructs", "Greetee", "GreetingAugmenter", "IAnotherPublicInterface", "IDeprecatedInterface", "IExperimentalInterface", "IExtendsPrivateInterface", "IFriendlier", "IFriendlyRandomGenerator", "IInterfaceImplementedByAbstractClass", "IInterfaceThatShouldNotBeADataType", "IInterfaceWithInternal", "IInterfaceWithMethods", "IInterfaceWithOptionalMethodArguments", "IInterfaceWithProperties", "IInterfaceWithPropertiesExtension", "IJSII417Derived", "IJSII417PublicBaseOfBase", "IJsii487External", "IJsii487External2", "IJsii496", "IMutableObjectLiteral", "INonInternalInterface", "IPrivatelyImplemented", "IPublicInterface", "IPublicInterface2", "IRandomNumberGenerator", "IReturnsNumber", "IStableInterface", "ImplementInternalInterface", "ImplementsInterfaceWithInternal", "ImplementsInterfaceWithInternalSubclass", "ImplementsPrivateInterface", "ImplictBaseOfBase", "InbetweenClass", "InterfaceInNamespaceIncludesClasses", "InterfaceInNamespaceOnlyInterface", "JSII417Derived", "JSII417PublicBaseOfBase", "JSObjectLiteralForInterface", "JSObjectLiteralToNative", "JSObjectLiteralToNativeClass", "JavaReservedWords", "Jsii487Derived", "Jsii496Derived", "JsiiAgent", "LoadBalancedFargateServiceProps", "Multiply", "Negate", "NodeStandardLibrary", "NullShouldBeTreatedAsUndefined", "NullShouldBeTreatedAsUndefinedData", "NumberGenerator", "ObjectRefsInCollections", "Old", "OptionalConstructorArgument", "OptionalStruct", "OptionalStructConsumer", "OverrideReturnsObject", "PartiallyInitializedThisConsumer", "Polymorphism", "Power", "PublicClass", "PythonReservedWords", "ReferenceEnumFromScopedPackage", "ReturnsPrivateImplementationOfInterface", "RuntimeTypeChecking", "SingleInstanceTwoTypes", "StableClass", "StableEnum", "StableStruct", "StaticContext", "Statics", "StringEnum", "StripInternal", "Sum", "SyncVirtualMethods", "Thrower", "UnaryOperation", "UnionProperties", "UseBundledDependency", "UseCalcBase", "UsesInterfaceWithProperties", "VariadicMethod", "VirtualMethodPlayground", "VoidCallback", "__jsii_assembly__", "composition"] +__all__ = ["AbstractClass", "AbstractClassBase", "AbstractClassReturner", "Add", "AllTypes", "AllTypesEnum", "AllowedMethodNames", "AsyncVirtualMethods", "AugmentableClass", "BinaryOperation", "Calculator", "CalculatorProps", "ClassThatImplementsTheInternalInterface", "ClassThatImplementsThePrivateInterface", "ClassWithDocs", "ClassWithMutableObjectLiteralProperty", "ClassWithPrivateConstructorAndAutomaticProperties", "ConstructorPassesThisOut", "Constructors", "ConsumersOfThisCrazyTypeSystem", "DefaultedConstructorArgument", "DeprecatedClass", "DeprecatedEnum", "DeprecatedStruct", "DerivedClassHasNoProperties", "DerivedStruct", "DoNotOverridePrivates", "DoNotRecognizeAnyAsOptional", "DocumentedClass", "DontComplainAboutVariadicAfterOptional", "DoubleTrouble", "EraseUndefinedHashValues", "EraseUndefinedHashValuesOptions", "ExperimentalClass", "ExperimentalEnum", "ExperimentalStruct", "ExportedBaseClass", "ExtendsInternalInterface", "GiveMeStructs", "Greetee", "GreetingAugmenter", "IAnotherPublicInterface", "IDeprecatedInterface", "IExperimentalInterface", "IExtendsPrivateInterface", "IFriendlier", "IFriendlyRandomGenerator", "IInterfaceImplementedByAbstractClass", "IInterfaceThatShouldNotBeADataType", "IInterfaceWithInternal", "IInterfaceWithMethods", "IInterfaceWithOptionalMethodArguments", "IInterfaceWithProperties", "IInterfaceWithPropertiesExtension", "IJSII417Derived", "IJSII417PublicBaseOfBase", "IJsii487External", "IJsii487External2", "IJsii496", "IMutableObjectLiteral", "INonInternalInterface", "IPrivatelyImplemented", "IPublicInterface", "IPublicInterface2", "IRandomNumberGenerator", "IReturnsNumber", "IStableInterface", "ImplementInternalInterface", "ImplementsInterfaceWithInternal", "ImplementsInterfaceWithInternalSubclass", "ImplementsPrivateInterface", "ImplictBaseOfBase", "InbetweenClass", "InterfaceInNamespaceIncludesClasses", "InterfaceInNamespaceOnlyInterface", "JSII417Derived", "JSII417PublicBaseOfBase", "JSObjectLiteralForInterface", "JSObjectLiteralToNative", "JSObjectLiteralToNativeClass", "JavaReservedWords", "Jsii487Derived", "Jsii496Derived", "JsiiAgent", "LoadBalancedFargateServiceProps", "Multiply", "Negate", "NodeStandardLibrary", "NullShouldBeTreatedAsUndefined", "NullShouldBeTreatedAsUndefinedData", "NumberGenerator", "ObjectRefsInCollections", "Old", "OptionalConstructorArgument", "OptionalStruct", "OptionalStructConsumer", "OverrideReturnsObject", "PartiallyInitializedThisConsumer", "Polymorphism", "Power", "PublicClass", "PythonReservedWords", "ReferenceEnumFromScopedPackage", "ReturnsPrivateImplementationOfInterface", "RuntimeTypeChecking", "SingleInstanceTwoTypes", "StableClass", "StableEnum", "StableStruct", "StaticContext", "Statics", "StringEnum", "StripInternal", "Sum", "SyncVirtualMethods", "Thrower", "UnaryOperation", "UnionProperties", "UseBundledDependency", "UseCalcBase", "UsesInterfaceWithProperties", "VariadicMethod", "VirtualMethodPlayground", "VoidCallback", "WithPrivatePropertyInConstructor", "__jsii_assembly__", "composition"] publication.publish() diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst b/packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst index f1e4f8175b..0bf8ce4668 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst +++ b/packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst @@ -6808,6 +6808,45 @@ VoidCallback :type: boolean *(readonly)* +WithPrivatePropertyInConstructor +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. py:class:: WithPrivatePropertyInConstructor([privateField]) + + **Language-specific names:** + + .. tabs:: + + .. code-tab:: c# + + using Amazon.JSII.Tests.CalculatorNamespace; + + .. code-tab:: java + + import software.amazon.jsii.tests.calculator.WithPrivatePropertyInConstructor; + + .. code-tab:: javascript + + const { WithPrivatePropertyInConstructor } = require('jsii-calc'); + + .. code-tab:: typescript + + import { WithPrivatePropertyInConstructor } from 'jsii-calc'; + + + + Verifies that private property declarations in constructor arguments are hidden. + + + + :param privateField: + :type privateField: string + + .. py:attribute:: success + + :type: boolean *(readonly)* + + composition ^^^^^^^^^^^ diff --git a/packages/jsii-reflect/test/classes.expected.txt b/packages/jsii-reflect/test/classes.expected.txt index 2c2e244197..37f16cd47e 100644 --- a/packages/jsii-reflect/test/classes.expected.txt +++ b/packages/jsii-reflect/test/classes.expected.txt @@ -83,4 +83,5 @@ Value VariadicMethod Very VirtualMethodPlayground -VoidCallback \ No newline at end of file +VoidCallback +WithPrivatePropertyInConstructor \ No newline at end of file diff --git a/packages/jsii-reflect/test/jsii-tree.test.all.expected.txt b/packages/jsii-reflect/test/jsii-tree.test.all.expected.txt index 559508bb05..7439bc6896 100644 --- a/packages/jsii-reflect/test/jsii-tree.test.all.expected.txt +++ b/packages/jsii-reflect/test/jsii-tree.test.all.expected.txt @@ -1219,6 +1219,15 @@ assemblies │ │ └─┬ methodWasCalled property │ │ ├── immutable │ │ └── type: boolean + │ ├─┬ class WithPrivatePropertyInConstructor + │ │ └─┬ members + │ │ ├─┬ (privateField) initializer + │ │ │ └─┬ parameters + │ │ │ └─┬ privateField + │ │ │ └── type: Optional + │ │ └─┬ success property + │ │ ├── immutable + │ │ └── type: boolean │ ├─┬ class CompositeOperation │ │ ├── base: Operation │ │ └─┬ members diff --git a/packages/jsii-reflect/test/jsii-tree.test.inheritance.expected.txt b/packages/jsii-reflect/test/jsii-tree.test.inheritance.expected.txt index 5c30a6e070..0222f01813 100644 --- a/packages/jsii-reflect/test/jsii-tree.test.inheritance.expected.txt +++ b/packages/jsii-reflect/test/jsii-tree.test.inheritance.expected.txt @@ -106,6 +106,7 @@ assemblies │ ├── class VariadicMethod │ ├── class VirtualMethodPlayground │ ├── class VoidCallback + │ ├── class WithPrivatePropertyInConstructor │ ├─┬ class CompositeOperation │ │ └── base: Operation │ ├── interface CalculatorProps diff --git a/packages/jsii-reflect/test/jsii-tree.test.members.expected.txt b/packages/jsii-reflect/test/jsii-tree.test.members.expected.txt index a434acf0ab..207b924487 100644 --- a/packages/jsii-reflect/test/jsii-tree.test.members.expected.txt +++ b/packages/jsii-reflect/test/jsii-tree.test.members.expected.txt @@ -542,6 +542,10 @@ assemblies │ │ ├── callMe() method │ │ ├── overrideMe() method │ │ └── methodWasCalled property + │ ├─┬ class WithPrivatePropertyInConstructor + │ │ └─┬ members + │ │ ├── (privateField) initializer + │ │ └── success property │ ├─┬ class CompositeOperation │ │ └─┬ members │ │ ├── () initializer diff --git a/packages/jsii-reflect/test/jsii-tree.test.types.expected.txt b/packages/jsii-reflect/test/jsii-tree.test.types.expected.txt index 726ecf0266..9912394562 100644 --- a/packages/jsii-reflect/test/jsii-tree.test.types.expected.txt +++ b/packages/jsii-reflect/test/jsii-tree.test.types.expected.txt @@ -81,6 +81,7 @@ assemblies │ ├── class VariadicMethod │ ├── class VirtualMethodPlayground │ ├── class VoidCallback + │ ├── class WithPrivatePropertyInConstructor │ ├── class CompositeOperation │ ├── interface CalculatorProps │ ├── interface DeprecatedStruct diff --git a/packages/jsii/lib/assembler.ts b/packages/jsii/lib/assembler.ts index 0ec75d42a4..5bf1b68990 100644 --- a/packages/jsii/lib/assembler.ts +++ b/packages/jsii/lib/assembler.ts @@ -610,7 +610,7 @@ export class Assembler implements Emitter { // Process constructor-based property declarations even if constructor is private if (signature) { for (const param of signature.getParameters()) { - if (ts.isParameterPropertyDeclaration(param.valueDeclaration)) { + if (ts.isParameterPropertyDeclaration(param.valueDeclaration) && !this._isPrivateOrInternal(param)) { await this._visitProperty(param, jsiiType, ctx.replaceStability(jsiiType.docs && jsiiType.docs.stability)); } }