Fix crash in type resolution in JS IIFEs (#23171)
* Fix crash in type resolution in JS IIFEs We recognise IIFEs as JS special assignment initialisers, but not as containers otherwise. That means that IIFEs will not have a symbol unless they have an *outside* assignment. The permanent fix will be to make IIFEs a container, based on the containership of the value that they return. This fix does not do that; it just makes type resolution return undefined instead of crashing. * Comment the IIFE-fix line
This commit is contained in:
parent
9cb473e102
commit
9dd8e296f3
|
@ -2063,6 +2063,10 @@ namespace ts {
|
|||
if (initializer) {
|
||||
namespace = getSymbolOfNode(initializer);
|
||||
}
|
||||
// Currently, IIFEs may not have a symbol and we don't know about their contents. Give up in this case.
|
||||
if (!namespace) {
|
||||
return undefined;
|
||||
}
|
||||
if (namespace.valueDeclaration &&
|
||||
isVariableDeclaration(namespace.valueDeclaration) &&
|
||||
namespace.valueDeclaration.initializer &&
|
||||
|
|
9
tests/baselines/reference/typeLookupInIIFE.symbols
Normal file
9
tests/baselines/reference/typeLookupInIIFE.symbols
Normal file
|
@ -0,0 +1,9 @@
|
|||
=== tests/cases/conformance/salsa/a.js ===
|
||||
// #22973
|
||||
var ns = (function() {})();
|
||||
>ns : Symbol(ns, Decl(a.js, 1, 3))
|
||||
|
||||
/** @type {ns.NotFound} */
|
||||
var crash;
|
||||
>crash : Symbol(crash, Decl(a.js, 3, 3))
|
||||
|
12
tests/baselines/reference/typeLookupInIIFE.types
Normal file
12
tests/baselines/reference/typeLookupInIIFE.types
Normal file
|
@ -0,0 +1,12 @@
|
|||
=== tests/cases/conformance/salsa/a.js ===
|
||||
// #22973
|
||||
var ns = (function() {})();
|
||||
>ns : void
|
||||
>(function() {})() : void
|
||||
>(function() {}) : () => void
|
||||
>function() {} : () => void
|
||||
|
||||
/** @type {ns.NotFound} */
|
||||
var crash;
|
||||
>crash : any
|
||||
|
9
tests/cases/conformance/salsa/typeLookupInIIFE.ts
Normal file
9
tests/cases/conformance/salsa/typeLookupInIIFE.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
// @noEmit: true
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noImplicitAny: true
|
||||
// @Filename: a.js
|
||||
// #22973
|
||||
var ns = (function() {})();
|
||||
/** @type {ns.NotFound} */
|
||||
var crash;
|
Loading…
Reference in a new issue