Ignore @private/@protected on constructor functions (#35782)
* Ignore @private on constructor functions This was incorrect in the best of circumstances and caused a crash when the parent of the function had no symbol, because the accessibility check assumed it was operating on a constructor and that the parent was always the containing class. * Non-constructors are always accessible Previously, all function-like kinds were accessible, which includes constructors. This was wrong.
This commit is contained in:
parent
9445657184
commit
2cc1340a7b
|
@ -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) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
31
tests/baselines/reference/privateConstructorFunction.js
Normal file
31
tests/baselines/reference/privateConstructorFunction.js
Normal file
|
@ -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
tests/baselines/reference/privateConstructorFunction.symbols
Normal file
16
tests/baselines/reference/privateConstructorFunction.symbols
Normal file
|
@ -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
tests/baselines/reference/privateConstructorFunction.types
Normal file
21
tests/baselines/reference/privateConstructorFunction.types
Normal file
|
@ -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
tests/cases/conformance/salsa/privateConstructorFunction.ts
Normal file
15
tests/cases/conformance/salsa/privateConstructorFunction.ts
Normal file
|
@ -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()
|
||||
}
|
Loading…
Reference in a new issue