mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-12 03:20:56 -06:00
fix(39373): add diagnostic message about using a private name for class declarations without name (#39567)
This commit is contained in:
parent
1d671c3588
commit
4e24b1b00d
@ -3057,6 +3057,10 @@
|
||||
"category": "Error",
|
||||
"code": 4020
|
||||
},
|
||||
"'extends' clause of exported class has or is using private name '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 4021
|
||||
},
|
||||
"'extends' clause of exported interface '{0}' has or is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4022
|
||||
|
||||
@ -447,11 +447,12 @@ namespace ts {
|
||||
function getHeritageClauseVisibilityError(): SymbolAccessibilityDiagnostic {
|
||||
let diagnosticMessage: DiagnosticMessage;
|
||||
// Heritage clause is written by user so it can always be named
|
||||
if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||
if (isClassDeclaration(node.parent.parent)) {
|
||||
// Class or Interface implemented/extended is inaccessible
|
||||
diagnosticMessage = isHeritageClause(node.parent) && node.parent.token === SyntaxKind.ImplementsKeyword ?
|
||||
Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 :
|
||||
Diagnostics.extends_clause_of_exported_class_0_has_or_is_using_private_name_1;
|
||||
node.parent.parent.name ? Diagnostics.extends_clause_of_exported_class_0_has_or_is_using_private_name_1 :
|
||||
Diagnostics.extends_clause_of_exported_class_has_or_is_using_private_name_0;
|
||||
}
|
||||
else {
|
||||
// interface is inaccessible
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
/b.ts(2,30): error TS4021: 'extends' clause of exported class has or is using private name 'Foo'.
|
||||
|
||||
|
||||
==== /b.ts (1 errors) ====
|
||||
const { Foo } = require("./a");
|
||||
export default class extends Foo {}
|
||||
~~~
|
||||
!!! error TS4021: 'extends' clause of exported class has or is using private name 'Foo'.
|
||||
|
||||
==== /node_modules/@types/node/index.d.ts (0 errors) ====
|
||||
declare const require: any;
|
||||
|
||||
==== /a.ts (0 errors) ====
|
||||
export class Foo {}
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
//// [tests/cases/compiler/declarationEmitExpressionInExtends6.ts] ////
|
||||
|
||||
//// [index.d.ts]
|
||||
declare const require: any;
|
||||
|
||||
//// [a.ts]
|
||||
export class Foo {}
|
||||
|
||||
//// [b.ts]
|
||||
const { Foo } = require("./a");
|
||||
export default class extends Foo {}
|
||||
|
||||
|
||||
//// [b.js]
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
exports.__esModule = true;
|
||||
var Foo = require("./a").Foo;
|
||||
var default_1 = /** @class */ (function (_super) {
|
||||
__extends(default_1, _super);
|
||||
function default_1() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return default_1;
|
||||
}(Foo));
|
||||
exports["default"] = default_1;
|
||||
@ -0,0 +1,12 @@
|
||||
=== /b.ts ===
|
||||
const { Foo } = require("./a");
|
||||
>Foo : Symbol(Foo, Decl(b.ts, 0, 7))
|
||||
>require : Symbol(require, Decl(index.d.ts, 0, 13))
|
||||
|
||||
export default class extends Foo {}
|
||||
>Foo : Symbol(Foo, Decl(b.ts, 0, 7))
|
||||
|
||||
=== /node_modules/@types/node/index.d.ts ===
|
||||
declare const require: any;
|
||||
>require : Symbol(require, Decl(index.d.ts, 0, 13))
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
=== /b.ts ===
|
||||
const { Foo } = require("./a");
|
||||
>Foo : any
|
||||
>require("./a") : any
|
||||
>require : any
|
||||
>"./a" : "./a"
|
||||
|
||||
export default class extends Foo {}
|
||||
>Foo : any
|
||||
|
||||
=== /node_modules/@types/node/index.d.ts ===
|
||||
declare const require: any;
|
||||
>require : any
|
||||
|
||||
14
tests/cases/compiler/declarationEmitExpressionInExtends6.ts
Normal file
14
tests/cases/compiler/declarationEmitExpressionInExtends6.ts
Normal file
@ -0,0 +1,14 @@
|
||||
// @module: commonjs
|
||||
// @declaration: true
|
||||
// @types: node
|
||||
// @currentDirectory: /
|
||||
|
||||
// @Filename: /node_modules/@types/node/index.d.ts
|
||||
declare const require: any;
|
||||
|
||||
// @Filename: /a.ts
|
||||
export class Foo {}
|
||||
|
||||
// @Filename: /b.ts
|
||||
const { Foo } = require("./a");
|
||||
export default class extends Foo {}
|
||||
Loading…
x
Reference in New Issue
Block a user