From c3d943a6a2a37dbdeca53c2aaa1d8741f48f0461 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 8 Oct 2026 10:45:33 -0700 Subject: [PATCH] Use ensureModifierFlags to calculate jsdoc constructor property modifiers --- .../transformers/declarations/transform.go | 8 +++- ...clarationEmitThisPropertyJSDocModifiers.js | 39 +++++++++++++++++++ .../jsdocAccessibilityTagsDeclarations.js | 4 +- .../conformance/jsdocReadonlyDeclarations.js | 2 +- ...clarationEmitThisPropertyJSDocModifiers.ts | 25 ++++++++++++ 5 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 tsc/testdata/baselines/reference/compiler/jsDeclarationEmitThisPropertyJSDocModifiers.js create mode 100644 tsc/testdata/tests/cases/compiler/jsDeclarationEmitThisPropertyJSDocModifiers.ts diff --git a/tsc/internal/transformers/declarations/transform.go b/tsc/internal/transformers/declarations/transform.go index 0daf681bfb59e..9f8458d17b4b3 100644 --- a/tsc/internal/transformers/declarations/transform.go +++ b/tsc/internal/transformers/declarations/transform.go @@ -2118,9 +2118,13 @@ caseBlock: } } - var mods *ast.ModifierList + modifierFlags := tx.ensureModifierFlags(node) if isStatic { - mods = tx.Factory().NewModifierList([]*ast.Node{tx.Factory().NewModifier(ast.KindStaticKeyword)}) + modifierFlags |= ast.ModifierFlagsStatic + } + var mods *ast.ModifierList + if modifierFlags != ast.ModifierFlagsNone { + mods = tx.Factory().NewModifierList(ast.CreateModifiersFromModifierFlags(modifierFlags, tx.Factory().NewModifier)) } if ast.HasDynamicName(node) { if !transformers.IsSimpleInlineableExpression(name) { diff --git a/tsc/testdata/baselines/reference/compiler/jsDeclarationEmitThisPropertyJSDocModifiers.js b/tsc/testdata/baselines/reference/compiler/jsDeclarationEmitThisPropertyJSDocModifiers.js new file mode 100644 index 0000000000000..32cc7c070b62f --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/jsDeclarationEmitThisPropertyJSDocModifiers.js @@ -0,0 +1,39 @@ +//// [tests/cases/compiler/jsDeclarationEmitThisPropertyJSDocModifiers.ts] //// + +//// [a.js] +export class A { + constructor() { + /** @private @type {boolean} */ + this.privateProperty = false; + /** @protected @type {string} */ + this.protectedProperty = ""; + /** @readonly @type {number} */ + this.readonlyProperty = 0; + /** @public @type {bigint} */ + this.publicProperty = 0n; + } + + static initialize() { + /** @private @type {symbol} */ + this.privateStaticProperty = Symbol(); + } +} + + + + +//// [a.d.ts] +export declare class A { + /** @private @type {boolean} */ + private privateProperty; + /** @protected @type {string} */ + protected protectedProperty: string; + /** @readonly @type {number} */ + readonly readonlyProperty: number; + /** @public @type {bigint} */ + publicProperty: bigint; + /** @private @type {symbol} */ + private static privateStaticProperty; + constructor(); + static initialize(): void; +} diff --git a/tsc/testdata/baselines/reference/conformance/jsdocAccessibilityTagsDeclarations.js b/tsc/testdata/baselines/reference/conformance/jsdocAccessibilityTagsDeclarations.js index 2c4cafa8f1b2c..1ad91499186dc 100644 --- a/tsc/testdata/baselines/reference/conformance/jsdocAccessibilityTagsDeclarations.js +++ b/tsc/testdata/baselines/reference/conformance/jsdocAccessibilityTagsDeclarations.js @@ -82,7 +82,7 @@ class C { //// [jsdocAccessibilityTagDeclarations.d.ts] declare class Protected { /** @protected */ - c: any; + protected c: any; /** @protected */ protected constructor(c: any); /** @protected */ @@ -94,7 +94,7 @@ declare class Protected { } declare class Private { /** @private */ - c; + private c; /** @private */ private constructor(); /** @private */ diff --git a/tsc/testdata/baselines/reference/conformance/jsdocReadonlyDeclarations.js b/tsc/testdata/baselines/reference/conformance/jsdocReadonlyDeclarations.js index ac76b89c22288..dc7e79c16c795 100644 --- a/tsc/testdata/baselines/reference/conformance/jsdocReadonlyDeclarations.js +++ b/tsc/testdata/baselines/reference/conformance/jsdocReadonlyDeclarations.js @@ -59,7 +59,7 @@ declare class C { * @readonly * @type {number} */ - y: number; + readonly y: number; /** @readonly */ readonly x = 6; /** @readonly */ diff --git a/tsc/testdata/tests/cases/compiler/jsDeclarationEmitThisPropertyJSDocModifiers.ts b/tsc/testdata/tests/cases/compiler/jsDeclarationEmitThisPropertyJSDocModifiers.ts new file mode 100644 index 0000000000000..0a8e9c6628072 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/jsDeclarationEmitThisPropertyJSDocModifiers.ts @@ -0,0 +1,25 @@ +// @target: esnext +// @allowJs: true +// @checkJs: true +// @declaration: true +// @emitDeclarationOnly: true +// @noTypesAndSymbols: true +// @filename: /a.js + +export class A { + constructor() { + /** @private @type {boolean} */ + this.privateProperty = false; + /** @protected @type {string} */ + this.protectedProperty = ""; + /** @readonly @type {number} */ + this.readonlyProperty = 0; + /** @public @type {bigint} */ + this.publicProperty = 0n; + } + + static initialize() { + /** @private @type {symbol} */ + this.privateStaticProperty = Symbol(); + } +}