Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24865,8 +24865,8 @@ namespace ts {
const declaration = signature.declaration;
const modifiers = getSelectedModifierFlags(declaration, ModifierFlags.NonPublicAccessibilityModifier);

// Public constructor is accessible.
if (!modifiers) {
// (1) Public constructors and (2) constructor functions are always accessible.
if (!modifiers || declaration.kind !== SyntaxKind.Constructor) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, isFunctionLikeDeclaration includes constructors. I think I'll flip the check and exclude SyntaxKind.Constructor explicitly.

return true;
}

Expand Down
31 changes: 31 additions & 0 deletions tests/baselines/reference/privateConstructorFunction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//// [privateConstructorFunction.js]
{
// make sure not to crash when parent's a block rather than a source file or some other
// symbol-having node.

/** @private */
function C() {
this.x = 1
}
new C()
}


//// [privateConstructorFunction.js]
{
// make sure not to crash when parent's a block rather than a source file or some other
// symbol-having node.
/** @private */
function C() {
this.x = 1;
}
new C();
}


//// [privateConstructorFunction.d.ts]
/** @private */
declare function C(): void;
declare class C {
x: number;
}
16 changes: 16 additions & 0 deletions tests/baselines/reference/privateConstructorFunction.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== tests/cases/conformance/salsa/privateConstructorFunction.js ===
{
// make sure not to crash when parent's a block rather than a source file or some other
// symbol-having node.

/** @private */
function C() {
>C : Symbol(C, Decl(privateConstructorFunction.js, 0, 1))

this.x = 1
>x : Symbol(C.x, Decl(privateConstructorFunction.js, 5, 18))
}
new C()
>C : Symbol(C, Decl(privateConstructorFunction.js, 0, 1))
}

21 changes: 21 additions & 0 deletions tests/baselines/reference/privateConstructorFunction.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
=== tests/cases/conformance/salsa/privateConstructorFunction.js ===
{
// make sure not to crash when parent's a block rather than a source file or some other
// symbol-having node.

/** @private */
function C() {
>C : typeof C

this.x = 1
>this.x = 1 : 1
>this.x : any
>this : any
>x : any
>1 : 1
}
new C()
>new C() : C
>C : typeof C
}

15 changes: 15 additions & 0 deletions tests/cases/conformance/salsa/privateConstructorFunction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @allowjs: true
// @checkjs: true
// @outdir: salsa
// @declaration: true
// @filename: privateConstructorFunction.js
{
// make sure not to crash when parent's a block rather than a source file or some other
// symbol-having node.

/** @private */
function C() {
this.x = 1
}
new C()
}