Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b8ca9ac
fix(58145): suppress jsdoc for private members
a-tarasyuk Aug 31, 2026
790d4ad
Merge branch 'main' into fix/58145
a-tarasyuk Sep 3, 2026
1d85723
Merge branch 'main' into fix/58145
a-tarasyuk Sep 4, 2026
ffdd731
Merge branch 'main' of https://github.com/microsoft/TypeScript into f…
a-tarasyuk Sep 4, 2026
6bb2679
update baseline
a-tarasyuk Sep 4, 2026
372c6cf
Merge branch 'main' into fix/58145
a-tarasyuk Sep 8, 2026
40536a8
Merge branch 'main' into fix/58145
a-tarasyuk Sep 11, 2026
7a842c7
Merge branch 'main' into fix/58145
a-tarasyuk Sep 14, 2026
41d034f
Merge branch 'main' of https://github.com/microsoft/TypeScript into f…
a-tarasyuk Sep 16, 2026
e60766e
Merge branch 'fix/58145' of https://github.com/a-tarasyuk/TypeScript …
a-tarasyuk Sep 16, 2026
4ca57ba
Merge branch 'main' into fix/58145
a-tarasyuk Sep 19, 2026
55c6bde
Merge branch 'main' into fix/58145
a-tarasyuk Sep 24, 2026
4e6a370
Merge branch 'main' into fix/58145
a-tarasyuk Sep 28, 2026
97d242f
Merge branch 'main' into fix/58145
a-tarasyuk Sep 30, 2026
a3ed37f
Merge branch 'main' of https://github.com/microsoft/TypeScript into f…
a-tarasyuk Oct 14, 2026
41191dd
suppress jsdoc on private constructor-assigned properties
a-tarasyuk Oct 14, 2026
c14c6b4
Merge branch 'main' of https://github.com/microsoft/TypeScript into f…
a-tarasyuk Oct 14, 2026
e358707
Merge branch 'main' into fix/58145
a-tarasyuk Oct 14, 2026
da42c0e
Merge branch 'main' into fix/58145
a-tarasyuk Oct 16, 2026
3995027
Merge branch 'main' into fix/58145
a-tarasyuk Oct 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions tsc/internal/transformers/declarations/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,47 +986,61 @@ 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(),
postfixToken,
tx.ensureType(input.AsNode(), false),
tx.ensureNoInitializer(input.AsNode()),
)
if tx.resolver.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(input.AsNode()), ast.ModifierFlagsPrivate) != 0 {
tx.suppressJsDoc(result)
Comment thread
a-tarasyuk marked this conversation as resolved.
}
return result
}

func (tx *DeclarationTransformer) transformSetAccessorDeclaration(input *ast.SetAccessorDeclaration) *ast.Node {
if ast.IsPrivateIdentifier(input.Name()) {
return nil
}

return tx.Factory().UpdateSetAccessorDeclaration(
isPrivate := tx.resolver.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.resolver.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.resolver.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.resolver.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 {
Expand Down Expand Up @@ -1110,10 +1124,14 @@ func (tx *DeclarationTransformer) omitPrivateMethodType(input *ast.Node) *ast.No
nil, /*initializer*/
)
}
tx.preserveJsDoc(result, input)
tx.suppressJsDoc(result)
return result
}

func (tx *DeclarationTransformer) suppressJsDoc(node *ast.Node) {
tx.EmitContext().AddEmitFlags(node, printer.EFNoComments|printer.EFNoNestedComments)
}
Comment thread
a-tarasyuk marked this conversation as resolved.

func (tx *DeclarationTransformer) transformMethodSignatureDeclaration(input *ast.MethodSignatureDeclaration) *ast.Node {
if tx.resolver.GetEffectiveDeclarationFlags(tx.EmitContext().ParseNode(input.AsNode()), ast.ModifierFlagsPrivate) != 0 {
return tx.omitPrivateMethodType(input.AsNode())
Expand Down Expand Up @@ -1966,7 +1984,11 @@ func (tx *DeclarationTransformer) buildClassMembers(classNode *ast.Node, extraMe
tx.ensureType(param, false),
tx.ensureNoInitializer(param),
)
tx.preserveJsDoc(updated, param)
if tx.resolver.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
Expand Down Expand Up @@ -2166,7 +2188,9 @@ caseBlock:
tx.ensureType(node, false),
nil,
)
if ast.IsExpressionStatement(node.Parent) {
if modifierFlags&ast.ModifierFlagsPrivate != 0 {
tx.suppressJsDoc(prop)
} else if ast.IsExpressionStatement(node.Parent) {
tx.preserveJsDoc(prop, node.Parent)
}
tx.thisPropertyAssignmentsCollected = append(tx.thisPropertyAssignmentsCollected, prop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ export class C {

//// [a.d.ts]
export declare class C {
/**
* Non Async function
*/
private a;
/**
* Async function
*/
private b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//// [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;

constructor() {
/** Public constructor property. */
this.f = 1;

/**
* Protected constructor property.
* @protected
*/
this.g = 1;

/**
* Private constructor property.
* @private
*/
this.h = 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 constructor property. */
f: number;
/**
* Protected constructor property.
* @protected
*/
protected g: number;
private h;
/** Public property. */
a: number;
private b;
private c;
private get d();
private set d(value);
constructor();
}
Loading