Fixes #10624
This commit is contained in:
parent
db0ee4f763
commit
58ed72fd9a
|
@ -17114,7 +17114,9 @@ namespace ts {
|
|||
checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node,
|
||||
Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
|
||||
|
||||
if (baseType.symbol.valueDeclaration && !isInAmbientContext(baseType.symbol.valueDeclaration)) {
|
||||
if (baseType.symbol.valueDeclaration &&
|
||||
!isInAmbientContext(baseType.symbol.valueDeclaration) &&
|
||||
baseType.symbol.valueDeclaration.kind === SyntaxKind.ClassDeclaration) {
|
||||
if (!isBlockScopedNameDeclaredBeforeUse(baseType.symbol.valueDeclaration, node)) {
|
||||
error(baseTypeNode, Diagnostics.A_class_must_be_declared_after_its_base_class);
|
||||
}
|
||||
|
|
30
tests/baselines/reference/classDeclaredBeforeClassFactory.js
Normal file
30
tests/baselines/reference/classDeclaredBeforeClassFactory.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
//// [classDeclaredBeforeClassFactory.ts]
|
||||
// Should be OK due to hoisting
|
||||
class Derived extends makeBaseClass() {}
|
||||
|
||||
function makeBaseClass() {
|
||||
return class Base {};
|
||||
}
|
||||
|
||||
|
||||
//// [classDeclaredBeforeClassFactory.js]
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
// Should be OK due to hoisting
|
||||
var Derived = (function (_super) {
|
||||
__extends(Derived, _super);
|
||||
function Derived() {
|
||||
return _super.apply(this, arguments) || this;
|
||||
}
|
||||
return Derived;
|
||||
}(makeBaseClass()));
|
||||
function makeBaseClass() {
|
||||
return (function () {
|
||||
function Base() {
|
||||
}
|
||||
return Base;
|
||||
}());
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
=== tests/cases/compiler/classDeclaredBeforeClassFactory.ts ===
|
||||
// Should be OK due to hoisting
|
||||
class Derived extends makeBaseClass() {}
|
||||
>Derived : Symbol(Derived, Decl(classDeclaredBeforeClassFactory.ts, 0, 0))
|
||||
>makeBaseClass : Symbol(makeBaseClass, Decl(classDeclaredBeforeClassFactory.ts, 1, 40))
|
||||
|
||||
function makeBaseClass() {
|
||||
>makeBaseClass : Symbol(makeBaseClass, Decl(classDeclaredBeforeClassFactory.ts, 1, 40))
|
||||
|
||||
return class Base {};
|
||||
>Base : Symbol(Base, Decl(classDeclaredBeforeClassFactory.ts, 4, 10))
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
=== tests/cases/compiler/classDeclaredBeforeClassFactory.ts ===
|
||||
// Should be OK due to hoisting
|
||||
class Derived extends makeBaseClass() {}
|
||||
>Derived : Derived
|
||||
>makeBaseClass() : Base
|
||||
>makeBaseClass : () => typeof Base
|
||||
|
||||
function makeBaseClass() {
|
||||
>makeBaseClass : () => typeof Base
|
||||
|
||||
return class Base {};
|
||||
>class Base {} : typeof Base
|
||||
>Base : typeof Base
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
tests/cases/conformance/classes/classExpressions/classExpression3.ts(1,23): error TS2690: A class must be declared after its base class.
|
||||
tests/cases/conformance/classes/classExpressions/classExpression3.ts(1,37): error TS2690: A class must be declared after its base class.
|
||||
|
||||
|
||||
==== tests/cases/conformance/classes/classExpressions/classExpression3.ts (2 errors) ====
|
||||
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
let c = new C();
|
||||
c.a;
|
||||
c.b;
|
||||
c.c;
|
||||
|
26
tests/baselines/reference/classExpression3.symbols
Normal file
26
tests/baselines/reference/classExpression3.symbols
Normal file
|
@ -0,0 +1,26 @@
|
|||
=== tests/cases/conformance/classes/classExpressions/classExpression3.ts ===
|
||||
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
|
||||
>C : Symbol(C, Decl(classExpression3.ts, 0, 3))
|
||||
>a : Symbol((Anonymous class).a, Decl(classExpression3.ts, 0, 43))
|
||||
>b : Symbol((Anonymous class).b, Decl(classExpression3.ts, 0, 53))
|
||||
>c : Symbol((Anonymous class).c, Decl(classExpression3.ts, 0, 63))
|
||||
|
||||
let c = new C();
|
||||
>c : Symbol(c, Decl(classExpression3.ts, 1, 3))
|
||||
>C : Symbol(C, Decl(classExpression3.ts, 0, 3))
|
||||
|
||||
c.a;
|
||||
>c.a : Symbol((Anonymous class).a, Decl(classExpression3.ts, 0, 43))
|
||||
>c : Symbol(c, Decl(classExpression3.ts, 1, 3))
|
||||
>a : Symbol((Anonymous class).a, Decl(classExpression3.ts, 0, 43))
|
||||
|
||||
c.b;
|
||||
>c.b : Symbol((Anonymous class).b, Decl(classExpression3.ts, 0, 53))
|
||||
>c : Symbol(c, Decl(classExpression3.ts, 1, 3))
|
||||
>b : Symbol((Anonymous class).b, Decl(classExpression3.ts, 0, 53))
|
||||
|
||||
c.c;
|
||||
>c.c : Symbol((Anonymous class).c, Decl(classExpression3.ts, 0, 63))
|
||||
>c : Symbol(c, Decl(classExpression3.ts, 1, 3))
|
||||
>c : Symbol((Anonymous class).c, Decl(classExpression3.ts, 0, 63))
|
||||
|
33
tests/baselines/reference/classExpression3.types
Normal file
33
tests/baselines/reference/classExpression3.types
Normal file
|
@ -0,0 +1,33 @@
|
|||
=== tests/cases/conformance/classes/classExpressions/classExpression3.ts ===
|
||||
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
|
||||
>C : typeof (Anonymous class)
|
||||
>class extends class extends class { a = 1 } { b = 2 } { c = 3 } : typeof (Anonymous class)
|
||||
>class extends class { a = 1 } { b = 2 } : (Anonymous class)
|
||||
>class { a = 1 } : (Anonymous class)
|
||||
>a : number
|
||||
>1 : 1
|
||||
>b : number
|
||||
>2 : 2
|
||||
>c : number
|
||||
>3 : 3
|
||||
|
||||
let c = new C();
|
||||
>c : (Anonymous class)
|
||||
>new C() : (Anonymous class)
|
||||
>C : typeof (Anonymous class)
|
||||
|
||||
c.a;
|
||||
>c.a : number
|
||||
>c : (Anonymous class)
|
||||
>a : number
|
||||
|
||||
c.b;
|
||||
>c.b : number
|
||||
>c : (Anonymous class)
|
||||
>b : number
|
||||
|
||||
c.c;
|
||||
>c.c : number
|
||||
>c : (Anonymous class)
|
||||
>c : number
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
tests/cases/conformance/es6/classExpressions/classExpressionES63.ts(1,23): error TS2690: A class must be declared after its base class.
|
||||
tests/cases/conformance/es6/classExpressions/classExpressionES63.ts(1,37): error TS2690: A class must be declared after its base class.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/classExpressions/classExpressionES63.ts (2 errors) ====
|
||||
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
let c = new C();
|
||||
c.a;
|
||||
c.b;
|
||||
c.c;
|
||||
|
26
tests/baselines/reference/classExpressionES63.symbols
Normal file
26
tests/baselines/reference/classExpressionES63.symbols
Normal file
|
@ -0,0 +1,26 @@
|
|||
=== tests/cases/conformance/es6/classExpressions/classExpressionES63.ts ===
|
||||
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
|
||||
>C : Symbol(C, Decl(classExpressionES63.ts, 0, 3))
|
||||
>a : Symbol((Anonymous class).a, Decl(classExpressionES63.ts, 0, 43))
|
||||
>b : Symbol((Anonymous class).b, Decl(classExpressionES63.ts, 0, 53))
|
||||
>c : Symbol((Anonymous class).c, Decl(classExpressionES63.ts, 0, 63))
|
||||
|
||||
let c = new C();
|
||||
>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3))
|
||||
>C : Symbol(C, Decl(classExpressionES63.ts, 0, 3))
|
||||
|
||||
c.a;
|
||||
>c.a : Symbol((Anonymous class).a, Decl(classExpressionES63.ts, 0, 43))
|
||||
>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3))
|
||||
>a : Symbol((Anonymous class).a, Decl(classExpressionES63.ts, 0, 43))
|
||||
|
||||
c.b;
|
||||
>c.b : Symbol((Anonymous class).b, Decl(classExpressionES63.ts, 0, 53))
|
||||
>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3))
|
||||
>b : Symbol((Anonymous class).b, Decl(classExpressionES63.ts, 0, 53))
|
||||
|
||||
c.c;
|
||||
>c.c : Symbol((Anonymous class).c, Decl(classExpressionES63.ts, 0, 63))
|
||||
>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3))
|
||||
>c : Symbol((Anonymous class).c, Decl(classExpressionES63.ts, 0, 63))
|
||||
|
33
tests/baselines/reference/classExpressionES63.types
Normal file
33
tests/baselines/reference/classExpressionES63.types
Normal file
|
@ -0,0 +1,33 @@
|
|||
=== tests/cases/conformance/es6/classExpressions/classExpressionES63.ts ===
|
||||
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
|
||||
>C : typeof (Anonymous class)
|
||||
>class extends class extends class { a = 1 } { b = 2 } { c = 3 } : typeof (Anonymous class)
|
||||
>class extends class { a = 1 } { b = 2 } : (Anonymous class)
|
||||
>class { a = 1 } : (Anonymous class)
|
||||
>a : number
|
||||
>1 : 1
|
||||
>b : number
|
||||
>2 : 2
|
||||
>c : number
|
||||
>3 : 3
|
||||
|
||||
let c = new C();
|
||||
>c : (Anonymous class)
|
||||
>new C() : (Anonymous class)
|
||||
>C : typeof (Anonymous class)
|
||||
|
||||
c.a;
|
||||
>c.a : number
|
||||
>c : (Anonymous class)
|
||||
>a : number
|
||||
|
||||
c.b;
|
||||
>c.b : number
|
||||
>c : (Anonymous class)
|
||||
>b : number
|
||||
|
||||
c.c;
|
||||
>c.c : number
|
||||
>c : (Anonymous class)
|
||||
>c : number
|
||||
|
|
@ -1,11 +1,8 @@
|
|||
tests/cases/compiler/missingPropertiesOfClassExpression.ts(1,22): error TS2690: A class must be declared after its base class.
|
||||
tests/cases/compiler/missingPropertiesOfClassExpression.ts(1,52): error TS2339: Property 'y' does not exist on type '(Anonymous class)'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/missingPropertiesOfClassExpression.ts (2 errors) ====
|
||||
==== tests/cases/compiler/missingPropertiesOfClassExpression.ts (1 errors) ====
|
||||
class George extends class { reset() { return this.y; } } {
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
~
|
||||
!!! error TS2339: Property 'y' does not exist on type '(Anonymous class)'.
|
||||
constructor() {
|
||||
|
|
6
tests/cases/compiler/classDeclaredBeforeClassFactory.ts
Normal file
6
tests/cases/compiler/classDeclaredBeforeClassFactory.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Should be OK due to hoisting
|
||||
class Derived extends makeBaseClass() {}
|
||||
|
||||
function makeBaseClass() {
|
||||
return class Base {};
|
||||
}
|
Loading…
Reference in a new issue