mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 04:43:37 -05:00
Exclude JSDoc @extends from 'super()' checks (#29308)
* Exclude JSDoc @extends from 'super()' checks This fixes a similar problem as #29244 where JSDoc `@extends` * fix check 'super can only be referenced in a derived class'
This commit is contained in:
committed by
Nathan Shively-Sanders
parent
85e6c2f8ab
commit
b52a7fc3ea
@@ -16625,7 +16625,7 @@ namespace ts {
|
||||
|
||||
function checkThisBeforeSuper(node: Node, container: Node, diagnosticMessage: DiagnosticMessage) {
|
||||
const containingClassDecl = <ClassDeclaration>container.parent;
|
||||
const baseTypeNode = getEffectiveBaseTypeNode(containingClassDecl);
|
||||
const baseTypeNode = getClassExtendsHeritageElement(containingClassDecl);
|
||||
|
||||
// If a containing class does not have extends clause or the class extends null
|
||||
// skip checking whether super statement is called before "this" accessing.
|
||||
@@ -16974,7 +16974,7 @@ namespace ts {
|
||||
|
||||
// at this point the only legal case for parent is ClassLikeDeclaration
|
||||
const classLikeDeclaration = <ClassLikeDeclaration>container.parent;
|
||||
if (!getEffectiveBaseTypeNode(classLikeDeclaration)) {
|
||||
if (!getClassExtendsHeritageElement(classLikeDeclaration)) {
|
||||
error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class);
|
||||
return errorType;
|
||||
}
|
||||
@@ -23575,7 +23575,7 @@ namespace ts {
|
||||
// Constructors of classes with no extends clause may not contain super calls, whereas
|
||||
// constructors of derived classes must contain at least one super call somewhere in their function body.
|
||||
const containingClassDecl = <ClassDeclaration>node.parent;
|
||||
if (getEffectiveBaseTypeNode(containingClassDecl)) {
|
||||
if (getClassExtendsHeritageElement(containingClassDecl)) {
|
||||
captureLexicalThis(node.parent, containingClassDecl);
|
||||
const classExtendsNull = classDeclarationExtendsNull(containingClassDecl);
|
||||
const superCall = getSuperCallInConstructor(node);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
tests/cases/compiler/noSuperInJSDocExtends.js(14,9): error TS2335: 'super' can only be referenced in a derived class.
|
||||
|
||||
|
||||
==== tests/cases/compiler/noSuperInJSDocExtends.js (1 errors) ====
|
||||
class Based { }
|
||||
/** @extends {Based} */
|
||||
class Derived {
|
||||
constructor() {
|
||||
this;
|
||||
this.x = 10;
|
||||
var that = this;
|
||||
}
|
||||
}
|
||||
|
||||
/** @extends {Based} */
|
||||
class Derived2 {
|
||||
constructor() {
|
||||
super();
|
||||
~~~~~
|
||||
!!! error TS2335: 'super' can only be referenced in a derived class.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
=== tests/cases/compiler/noSuperInJSDocExtends.js ===
|
||||
class Based { }
|
||||
>Based : Symbol(Based, Decl(noSuperInJSDocExtends.js, 0, 0))
|
||||
|
||||
/** @extends {Based} */
|
||||
class Derived {
|
||||
>Derived : Symbol(Derived, Decl(noSuperInJSDocExtends.js, 0, 15))
|
||||
|
||||
constructor() {
|
||||
this;
|
||||
>this : Symbol(Derived, Decl(noSuperInJSDocExtends.js, 0, 15))
|
||||
|
||||
this.x = 10;
|
||||
>this.x : Symbol(Derived.x, Decl(noSuperInJSDocExtends.js, 4, 13))
|
||||
>this : Symbol(Derived, Decl(noSuperInJSDocExtends.js, 0, 15))
|
||||
>x : Symbol(Derived.x, Decl(noSuperInJSDocExtends.js, 4, 13))
|
||||
|
||||
var that = this;
|
||||
>that : Symbol(that, Decl(noSuperInJSDocExtends.js, 6, 11))
|
||||
>this : Symbol(Derived, Decl(noSuperInJSDocExtends.js, 0, 15))
|
||||
}
|
||||
}
|
||||
|
||||
/** @extends {Based} */
|
||||
class Derived2 {
|
||||
>Derived2 : Symbol(Derived2, Decl(noSuperInJSDocExtends.js, 8, 1))
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
=== tests/cases/compiler/noSuperInJSDocExtends.js ===
|
||||
class Based { }
|
||||
>Based : Based
|
||||
|
||||
/** @extends {Based} */
|
||||
class Derived {
|
||||
>Derived : Derived
|
||||
|
||||
constructor() {
|
||||
this;
|
||||
>this : this
|
||||
|
||||
this.x = 10;
|
||||
>this.x = 10 : 10
|
||||
>this.x : number
|
||||
>this : this
|
||||
>x : number
|
||||
>10 : 10
|
||||
|
||||
var that = this;
|
||||
>that : this
|
||||
>this : this
|
||||
}
|
||||
}
|
||||
|
||||
/** @extends {Based} */
|
||||
class Derived2 {
|
||||
>Derived2 : Derived2
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
>super() : void
|
||||
>super : any
|
||||
}
|
||||
}
|
||||
21
tests/cases/compiler/checkSuperCallBeforeThisAccessing9.ts
Normal file
21
tests/cases/compiler/checkSuperCallBeforeThisAccessing9.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
|
||||
// @filename: noSuperInJSDocExtends.js
|
||||
class Based { }
|
||||
/** @extends {Based} */
|
||||
class Derived {
|
||||
constructor() {
|
||||
this;
|
||||
this.x = 10;
|
||||
var that = this;
|
||||
}
|
||||
}
|
||||
|
||||
/** @extends {Based} */
|
||||
class Derived2 {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user