Don't crash when there's no class type to derive a 'this' type from (#37164)
Fixes #37161
This commit is contained in:
parent
dfc0b58fe7
commit
67930fc163
|
@ -21107,8 +21107,10 @@ namespace ts {
|
||||||
if (isInJS && className) {
|
if (isInJS && className) {
|
||||||
const classSymbol = checkExpression(className).symbol;
|
const classSymbol = checkExpression(className).symbol;
|
||||||
if (classSymbol && classSymbol.members && (classSymbol.flags & SymbolFlags.Function)) {
|
if (classSymbol && classSymbol.members && (classSymbol.flags & SymbolFlags.Function)) {
|
||||||
const classType = (getDeclaredTypeOfSymbol(classSymbol) as InterfaceType).thisType!;
|
const classType = (getDeclaredTypeOfSymbol(classSymbol) as InterfaceType).thisType;
|
||||||
return getFlowTypeOfReference(node, classType);
|
if (classType) {
|
||||||
|
return getFlowTypeOfReference(node, classType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check if it's a constructor definition, can be either a variable decl or function decl
|
// Check if it's a constructor definition, can be either a variable decl or function decl
|
||||||
|
|
16
tests/baselines/reference/allowJsClassThisTypeCrash.symbols
Normal file
16
tests/baselines/reference/allowJsClassThisTypeCrash.symbols
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
=== tests/cases/compiler/app.js ===
|
||||||
|
const f = function() {};
|
||||||
|
>f : Symbol(f, Decl(app.js, 0, 5))
|
||||||
|
|
||||||
|
var g = f;
|
||||||
|
>g : Symbol(g, Decl(app.js, 1, 3))
|
||||||
|
>f : Symbol(f, Decl(app.js, 0, 5))
|
||||||
|
|
||||||
|
g.prototype.m = function () {
|
||||||
|
>g.prototype : Symbol(g.m, Decl(app.js, 1, 10))
|
||||||
|
>g : Symbol(g, Decl(app.js, 1, 3))
|
||||||
|
>prototype : Symbol(Function.prototype, Decl(lib.es5.d.ts, --, --))
|
||||||
|
>m : Symbol(g.m, Decl(app.js, 1, 10))
|
||||||
|
|
||||||
|
this;
|
||||||
|
};
|
22
tests/baselines/reference/allowJsClassThisTypeCrash.types
Normal file
22
tests/baselines/reference/allowJsClassThisTypeCrash.types
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
=== tests/cases/compiler/app.js ===
|
||||||
|
const f = function() {};
|
||||||
|
>f : () => void
|
||||||
|
>function() {} : () => void
|
||||||
|
|
||||||
|
var g = f;
|
||||||
|
>g : () => void
|
||||||
|
>f : () => void
|
||||||
|
|
||||||
|
g.prototype.m = function () {
|
||||||
|
>g.prototype.m = function () { this;} : () => void
|
||||||
|
>g.prototype.m : any
|
||||||
|
>g.prototype : any
|
||||||
|
>g : () => void
|
||||||
|
>prototype : any
|
||||||
|
>m : any
|
||||||
|
>function () { this;} : () => void
|
||||||
|
|
||||||
|
this;
|
||||||
|
>this : any
|
||||||
|
|
||||||
|
};
|
10
tests/cases/compiler/allowJsClassThisTypeCrash.ts
Normal file
10
tests/cases/compiler/allowJsClassThisTypeCrash.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
// @checkJs: true
|
||||||
|
// @allowJs: true
|
||||||
|
// @noEmit: true
|
||||||
|
|
||||||
|
// @filename: app.js
|
||||||
|
const f = function() {};
|
||||||
|
var g = f;
|
||||||
|
g.prototype.m = function () {
|
||||||
|
this;
|
||||||
|
};
|
Loading…
Reference in a new issue