From b8ca9ac5b8c2f3dcc0af0bf184cb089988f302ee Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Mon, 31 Aug 2026 08:35:29 +0300 Subject: [PATCH 1/2] fix(58145): suppress jsdoc for private members --- .../transformers/declarations/transform.go | 36 +++++++-- .../commentsClassMembers(target=es2015).js | 8 -- .../declFileAccessors(target=es2015).js | 4 - .../declFileMethods(target=es2015).js | 8 -- .../declarationEmitPrivateAsyncMethod.js | 6 -- .../declarationEmitPrivateMemberComments.js | 76 ++++++++++++++++++ ...clarationEmitPrivateMemberComments.symbols | 69 +++++++++++++++++ ...declarationEmitPrivateMemberComments.types | 77 +++++++++++++++++++ .../jsDeclarationEmitPrivateStaticMethod.js | 1 - .../declarationEmitPrivateMemberComments.ts | 51 ++++++++++++ 10 files changed, 302 insertions(+), 34 deletions(-) create mode 100644 tsc/testdata/baselines/reference/compiler/declarationEmitPrivateMemberComments.js create mode 100644 tsc/testdata/baselines/reference/compiler/declarationEmitPrivateMemberComments.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/declarationEmitPrivateMemberComments.types create mode 100644 tsc/testdata/tests/cases/compiler/declarationEmitPrivateMemberComments.ts diff --git a/tsc/internal/transformers/declarations/transform.go b/tsc/internal/transformers/declarations/transform.go index 08e26b96a82fd..783faaf94ce6a 100644 --- a/tsc/internal/transformers/declarations/transform.go +++ b/tsc/internal/transformers/declarations/transform.go @@ -992,7 +992,7 @@ func (tx *DeclarationTransformer) transformPropertyDeclaration(input *ast.Proper if postfixToken != nil && postfixToken.Kind == ast.KindExclamationToken { postfixToken = nil } - return tx.Factory().UpdatePropertyDeclaration( + result := tx.Factory().UpdatePropertyDeclaration( input, tx.ensureModifiers(input.AsNode()), input.Name(), @@ -1000,6 +1000,10 @@ func (tx *DeclarationTransformer) transformPropertyDeclaration(input *ast.Proper tx.ensureType(input.AsNode(), false), tx.ensureNoInitializer(input.AsNode()), ) + if tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(input.AsNode()), ast.ModifierFlagsPrivate) != 0 { + tx.suppressJsDoc(result) + } + return result } func (tx *DeclarationTransformer) transformSetAccessorDeclaration(input *ast.SetAccessorDeclaration) *ast.Node { @@ -1007,32 +1011,42 @@ func (tx *DeclarationTransformer) transformSetAccessorDeclaration(input *ast.Set return nil } - return tx.Factory().UpdateSetAccessorDeclaration( + isPrivate := tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(input.AsNode()), ast.ModifierFlagsPrivate) != 0 + result := tx.Factory().UpdateSetAccessorDeclaration( input, tx.ensureModifiers(input.AsNode()), input.Name(), nil, // accessors shouldn't have type params - tx.updateAccessorParamList(input.AsNode(), tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(input.AsNode()), ast.ModifierFlagsPrivate) != 0), + tx.updateAccessorParamList(input.AsNode(), isPrivate), nil, nil, nil, ) + if isPrivate { + tx.suppressJsDoc(result) + } + return result } func (tx *DeclarationTransformer) transformGetAccesorDeclaration(input *ast.GetAccessorDeclaration) *ast.Node { if ast.IsPrivateIdentifier(input.Name()) { return nil } - return tx.Factory().UpdateGetAccessorDeclaration( + isPrivate := tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(input.AsNode()), ast.ModifierFlagsPrivate) != 0 + result := tx.Factory().UpdateGetAccessorDeclaration( input, tx.ensureModifiers(input.AsNode()), input.Name(), nil, // accessors shouldn't have type params - tx.updateAccessorParamList(input.AsNode(), tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(input.AsNode()), ast.ModifierFlagsPrivate) != 0), + tx.updateAccessorParamList(input.AsNode(), isPrivate), tx.ensureType(input.AsNode(), false), nil, nil, ) + if isPrivate { + tx.suppressJsDoc(result) + } + return result } func (tx *DeclarationTransformer) updateAccessorParamList(input *ast.Node, isPrivate bool) *ast.ParameterList { @@ -1105,10 +1119,14 @@ func (tx *DeclarationTransformer) omitPrivateMethodType(input *ast.Node) *ast.No nil, nil, ) - tx.preserveJsDoc(result, input) + tx.suppressJsDoc(result) return result } +func (tx *DeclarationTransformer) suppressJsDoc(node *ast.Node) { + tx.EmitContext().AddEmitFlags(node, printer.EFNoComments|printer.EFNoNestedComments) +} + func (tx *DeclarationTransformer) transformMethodSignatureDeclaration(input *ast.MethodSignatureDeclaration) *ast.Node { if tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(input.AsNode()), ast.ModifierFlagsPrivate) != 0 { return tx.omitPrivateMethodType(input.AsNode()) @@ -1940,7 +1958,11 @@ func (tx *DeclarationTransformer) buildClassMembers(classNode *ast.Node, extraMe tx.ensureType(param, false), tx.ensureNoInitializer(param), ) - tx.preserveJsDoc(updated, param) + if tx.host.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(param), ast.ModifierFlagsPrivate) != 0 { + tx.suppressJsDoc(updated) + } else { + tx.preserveJsDoc(updated, param) + } parameterProperties = append(parameterProperties, updated) } else { // Pattern - this is currently an error, but we emit declarations for it somewhat correctly diff --git a/tsc/testdata/baselines/reference/compiler/commentsClassMembers(target=es2015).js b/tsc/testdata/baselines/reference/compiler/commentsClassMembers(target=es2015).js index 2d27770cfe14d..02e749bf3970a 100644 --- a/tsc/testdata/baselines/reference/compiler/commentsClassMembers(target=es2015).js +++ b/tsc/testdata/baselines/reference/compiler/commentsClassMembers(target=es2015).js @@ -423,13 +423,9 @@ declare class c1 { get p3(): number; /** setter property*/ set p3(/** this is value*/ value: number); - /** pp1 is property of c1*/ private pp1; - /** sum with property*/ private pp2; - /** getter property*/ private get pp3(); - /** setter property*/ private set pp3(value); /** Constructor method*/ constructor(); @@ -473,13 +469,9 @@ declare class c1 { get b_p3(): number; /** setter property */ set b_p3(value: number); - /** pp1 is property of c1 */ private b_pp1; - /** sum with property */ private b_pp2; - /** getter property */ private get b_pp3(); - /** setter property */ private set b_pp3(value); /** s1 is static property of c1 */ static b_s1: number; diff --git a/tsc/testdata/baselines/reference/compiler/declFileAccessors(target=es2015).js b/tsc/testdata/baselines/reference/compiler/declFileAccessors(target=es2015).js index 2fb11763d7233..3b32af1e46e62 100644 --- a/tsc/testdata/baselines/reference/compiler/declFileAccessors(target=es2015).js +++ b/tsc/testdata/baselines/reference/compiler/declFileAccessors(target=es2015).js @@ -208,9 +208,7 @@ export declare class c1 { get p3(): number; /** setter property*/ set p3(/** this is value*/ value: number); - /** private getter property*/ private get pp3(); - /** private setter property*/ private set pp3(value); /** static getter property*/ static get s3(): number; @@ -232,9 +230,7 @@ declare class c2 { get p3(): number; /** setter property*/ set p3(/** this is value*/ value: number); - /** private getter property*/ private get pp3(); - /** private setter property*/ private set pp3(value); /** static getter property*/ static get s3(): number; diff --git a/tsc/testdata/baselines/reference/compiler/declFileMethods(target=es2015).js b/tsc/testdata/baselines/reference/compiler/declFileMethods(target=es2015).js index f524ed2b3c46b..2f79881994732 100644 --- a/tsc/testdata/baselines/reference/compiler/declFileMethods(target=es2015).js +++ b/tsc/testdata/baselines/reference/compiler/declFileMethods(target=es2015).js @@ -333,9 +333,7 @@ export declare class c1 { fooWithRestParameters(a: string, ...rests: string[]): string; fooWithOverloads(a: string): string; fooWithOverloads(a: number): number; - /** This comment should appear for privateFoo*/ private privateFoo; - /** This is comment for function signature*/ private privateFooWithParameters; private privateFooWithRestParameters; private privateFooWithOverloads; @@ -348,9 +346,7 @@ export declare class c1 { static staticFooWithRestParameters(a: string, ...rests: string[]): string; static staticFooWithOverloads(a: string): string; static staticFooWithOverloads(a: number): number; - /** This comment should appear for privateStaticFoo*/ private static privateStaticFoo; - /** This is comment for function signature*/ private static privateStaticFooWithParameters; private static privateStaticFooWithRestParameters; private static privateStaticFooWithOverloads; @@ -377,9 +373,7 @@ declare class c2 { fooWithRestParameters(a: string, ...rests: string[]): string; fooWithOverloads(a: string): string; fooWithOverloads(a: number): number; - /** This comment should appear for privateFoo*/ private privateFoo; - /** This is comment for function signature*/ private privateFooWithParameters; private privateFooWithRestParameters; private privateFooWithOverloads; @@ -392,9 +386,7 @@ declare class c2 { static staticFooWithRestParameters(a: string, ...rests: string[]): string; static staticFooWithOverloads(a: string): string; static staticFooWithOverloads(a: number): number; - /** This comment should appear for privateStaticFoo*/ private static privateStaticFoo; - /** This is comment for function signature*/ private static privateStaticFooWithParameters; private static privateStaticFooWithRestParameters; private static privateStaticFooWithOverloads; diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitPrivateAsyncMethod.js b/tsc/testdata/baselines/reference/compiler/declarationEmitPrivateAsyncMethod.js index 797cefbe4f9ea..9b46df671cded 100644 --- a/tsc/testdata/baselines/reference/compiler/declarationEmitPrivateAsyncMethod.js +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitPrivateAsyncMethod.js @@ -33,12 +33,6 @@ export class C { //// [a.d.ts] export declare class C { - /** - * Non Async function - */ private a; - /** - * Async function - */ private b; } diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitPrivateMemberComments.js b/tsc/testdata/baselines/reference/compiler/declarationEmitPrivateMemberComments.js new file mode 100644 index 0000000000000..a6ebb21ffdece --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitPrivateMemberComments.js @@ -0,0 +1,76 @@ +//// [tests/cases/compiler/declarationEmitPrivateMemberComments.ts] //// + +//// [a.ts] +export class A { + /** Public property. */ + a = 1; + + /** Private property. */ + private b = 1; + + /** Private method. */ + private c() {} + + /** Private getter. */ + private get d() { return 1; } + + /** Private setter. */ + private set d(value: number) {} + + /** ECMAScript private property. */ + #e = 1; + + constructor( + /** Private parameter property. */ + private f: number, + ) {} +} + +//// [b.js] +export class B { + /** Public property. */ + a = 1; + + /** @private */ + b = 1; + + /** @private */ + c() {} + + /** @private */ + get d() { return 1; } + + /** @private */ + set d(value) {} + + /** ECMAScript private property. */ + #e = 1; +} + + + + +//// [a.d.ts] +export declare class A { + #private; + private f; + /** Public property. */ + a: number; + private b; + private c; + private get d(); + private set d(value); + constructor( + /** Private parameter property. */ + f: number); +} +//// [b.d.ts] +export declare class B { + #private; + /** Public property. */ + a: number; + private b; + private c; + private get d(); + private set d(value); +} diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitPrivateMemberComments.symbols b/tsc/testdata/baselines/reference/compiler/declarationEmitPrivateMemberComments.symbols new file mode 100644 index 0000000000000..da3e5d78b8ea1 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitPrivateMemberComments.symbols @@ -0,0 +1,69 @@ +//// [tests/cases/compiler/declarationEmitPrivateMemberComments.ts] //// + +=== a.ts === +export class A { +>A : Symbol(A, Decl(a.ts, 0, 0)) + + /** Public property. */ + a = 1; +>a : Symbol(A.a, Decl(a.ts, 0, 16)) + + /** Private property. */ + private b = 1; +>b : Symbol(A.b, Decl(a.ts, 2, 10)) + + /** Private method. */ + private c() {} +>c : Symbol(A.c, Decl(a.ts, 5, 18)) + + /** Private getter. */ + private get d() { return 1; } +>d : Symbol(A.d, Decl(a.ts, 8, 18), Decl(a.ts, 11, 33)) + + /** Private setter. */ + private set d(value: number) {} +>d : Symbol(A.d, Decl(a.ts, 8, 18), Decl(a.ts, 11, 33)) +>value : Symbol(value, Decl(a.ts, 14, 18)) + + /** ECMAScript private property. */ + #e = 1; +>#e : Symbol(A.#e, Decl(a.ts, 14, 35)) + + constructor( + /** Private parameter property. */ + private f: number, +>f : Symbol(A.f, Decl(a.ts, 19, 16)) + + ) {} +} + +=== b.js === +export class B { +>B : Symbol(B, Decl(b.js, 0, 0)) + + /** Public property. */ + a = 1; +>a : Symbol(B.a, Decl(b.js, 0, 16)) + + /** @private */ + b = 1; +>b : Symbol(B.b, Decl(b.js, 2, 10)) + + /** @private */ + c() {} +>c : Symbol(B.c, Decl(b.js, 5, 10)) + + /** @private */ + get d() { return 1; } +>d : Symbol(B.d, Decl(b.js, 8, 10), Decl(b.js, 11, 25)) + + /** @private */ + set d(value) {} +>d : Symbol(B.d, Decl(b.js, 8, 10), Decl(b.js, 11, 25)) +>value : Symbol(value, Decl(b.js, 14, 10)) + + /** ECMAScript private property. */ + #e = 1; +>#e : Symbol(B.#e, Decl(b.js, 14, 19)) +} + diff --git a/tsc/testdata/baselines/reference/compiler/declarationEmitPrivateMemberComments.types b/tsc/testdata/baselines/reference/compiler/declarationEmitPrivateMemberComments.types new file mode 100644 index 0000000000000..d9440663134f5 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/declarationEmitPrivateMemberComments.types @@ -0,0 +1,77 @@ +//// [tests/cases/compiler/declarationEmitPrivateMemberComments.ts] //// + +=== a.ts === +export class A { +>A : A + + /** Public property. */ + a = 1; +>a : number +>1 : 1 + + /** Private property. */ + private b = 1; +>b : number +>1 : 1 + + /** Private method. */ + private c() {} +>c : () => void + + /** Private getter. */ + private get d() { return 1; } +>d : number +>1 : 1 + + /** Private setter. */ + private set d(value: number) {} +>d : number +>value : number + + /** ECMAScript private property. */ + #e = 1; +>#e : number +>1 : 1 + + constructor( + /** Private parameter property. */ + private f: number, +>f : number + + ) {} +} + +=== b.js === +export class B { +>B : B + + /** Public property. */ + a = 1; +>a : number +>1 : 1 + + /** @private */ + b = 1; +>b : number +>1 : 1 + + /** @private */ + c() {} +>c : () => void + + /** @private */ + get d() { return 1; } +>d : number +>1 : 1 + + /** @private */ + set d(value) {} +>d : number +>value : number + + /** ECMAScript private property. */ + #e = 1; +>#e : number +>1 : 1 +} + diff --git a/tsc/testdata/baselines/reference/compiler/jsDeclarationEmitPrivateStaticMethod.js b/tsc/testdata/baselines/reference/compiler/jsDeclarationEmitPrivateStaticMethod.js index b0c05be34face..12af002a86773 100644 --- a/tsc/testdata/baselines/reference/compiler/jsDeclarationEmitPrivateStaticMethod.js +++ b/tsc/testdata/baselines/reference/compiler/jsDeclarationEmitPrivateStaticMethod.js @@ -13,7 +13,6 @@ export class C { //// [a.d.ts] export declare class C { - /** @private */ private static foo; /** @protected */ protected static bar(): void; diff --git a/tsc/testdata/tests/cases/compiler/declarationEmitPrivateMemberComments.ts b/tsc/testdata/tests/cases/compiler/declarationEmitPrivateMemberComments.ts new file mode 100644 index 0000000000000..794f030906f56 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/declarationEmitPrivateMemberComments.ts @@ -0,0 +1,51 @@ +// @allowJs: true +// @checkJs: true +// @declaration: true +// @emitDeclarationOnly: true + +// @filename: a.ts +export class A { + /** Public property. */ + a = 1; + + /** Private property. */ + private b = 1; + + /** Private method. */ + private c() {} + + /** Private getter. */ + private get d() { return 1; } + + /** Private setter. */ + private set d(value: number) {} + + /** ECMAScript private property. */ + #e = 1; + + constructor( + /** Private parameter property. */ + private f: number, + ) {} +} + +// @filename: b.js +export class B { + /** Public property. */ + a = 1; + + /** @private */ + b = 1; + + /** @private */ + c() {} + + /** @private */ + get d() { return 1; } + + /** @private */ + set d(value) {} + + /** ECMAScript private property. */ + #e = 1; +} From 6bb267981a7c082503a229bfef08b67dd3eb9e96 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Fri, 4 Sep 2026 22:29:38 +0300 Subject: [PATCH 2/2] update baseline --- .../conformance/jsdocAccessibilityTagsDeclarations.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/tsc/testdata/baselines/reference/conformance/jsdocAccessibilityTagsDeclarations.js b/tsc/testdata/baselines/reference/conformance/jsdocAccessibilityTagsDeclarations.js index 2c4cafa8f1b2c..08349a96139f0 100644 --- a/tsc/testdata/baselines/reference/conformance/jsdocAccessibilityTagsDeclarations.js +++ b/tsc/testdata/baselines/reference/conformance/jsdocAccessibilityTagsDeclarations.js @@ -97,11 +97,8 @@ declare class Private { c; /** @private */ private constructor(); - /** @private */ private m; - /** @private */ private get p(); - /** @private */ private set p(value); } declare class C {