From ab91f0371bffffc82922eae70eee98f1cdf9d2ab Mon Sep 17 00:00:00 2001 From: Matthieu Riegler Date: Wed, 21 Aug 2024 01:07:13 +0200 Subject: [PATCH] refactor(compiler-cli): exclude private computed properties from class member extractions (#57596) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will exclude properties like `[ɵWRITABLE_SIGNAL]` from the `WritableSignal` interface. PR Close #57596 --- .../src/ngtsc/docs/src/class_extractor.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/compiler-cli/src/ngtsc/docs/src/class_extractor.ts b/packages/compiler-cli/src/ngtsc/docs/src/class_extractor.ts index 6cf0aa24210..fc179950db4 100644 --- a/packages/compiler-cli/src/ngtsc/docs/src/class_extractor.ts +++ b/packages/compiler-cli/src/ngtsc/docs/src/class_extractor.ts @@ -110,7 +110,10 @@ class ClassExtractor { protected extractClassMember(memberDeclaration: MemberElement): MemberEntry | undefined { if (this.isMethod(memberDeclaration)) { return this.extractMethod(memberDeclaration); - } else if (this.isProperty(memberDeclaration)) { + } else if ( + this.isProperty(memberDeclaration) && + !this.hasPrivateComputedProperty(memberDeclaration) + ) { return this.extractClassProperty(memberDeclaration); } else if (ts.isAccessor(memberDeclaration)) { return this.extractGetterSetter(memberDeclaration); @@ -375,6 +378,17 @@ class ClassExtractor { const modifiers = this.declaration.modifiers ?? []; return modifiers.some((mod) => mod.kind === ts.SyntaxKind.AbstractKeyword); } + + /** + * Check wether a member has a private computed property name like [ɵWRITABLE_SIGNAL] + * + * This will prevent exposing private computed properties in the docs. + */ + private hasPrivateComputedProperty(property: PropertyLike) { + return ( + ts.isComputedPropertyName(property.name) && property.name.expression.getText().startsWith('ɵ') + ); + } } /** Extractor to pull info for API reference documentation for an Angular directive. */