Skip to content

Commit 16687e6

Browse files
committed
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
1 parent 8717a7b commit 16687e6

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,6 +2051,10 @@ namespace ts {
20512051
if (initializer) {
20522052
namespace = getSymbolOfNode(initializer);
20532053
}
2054+
// Currently, IIFEs may not have a symbol and we don't know about their contents. Give up in this case.
2055+
if (!namespace) {
2056+
return undefined;
2057+
}
20542058
if (namespace.valueDeclaration &&
20552059
isVariableDeclaration(namespace.valueDeclaration) &&
20562060
namespace.valueDeclaration.initializer &&
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/conformance/salsa/a.js ===
2+
// #22973
3+
var ns = (function() {})();
4+
>ns : Symbol(ns, Decl(a.js, 1, 3))
5+
6+
/** @type {ns.NotFound} */
7+
var crash;
8+
>crash : Symbol(crash, Decl(a.js, 3, 3))
9+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/conformance/salsa/a.js ===
2+
// #22973
3+
var ns = (function() {})();
4+
>ns : void
5+
>(function() {})() : void
6+
>(function() {}) : () => void
7+
>function() {} : () => void
8+
9+
/** @type {ns.NotFound} */
10+
var crash;
11+
>crash : any
12+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @noEmit: true
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @noImplicitAny: true
5+
// @Filename: a.js
6+
// #22973
7+
var ns = (function() {})();
8+
/** @type {ns.NotFound} */
9+
var crash;

0 commit comments

Comments
 (0)