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:
Nathan Shively-Sanders 2018-04-05 09:57:35 -07:00 committed by GitHub
parent 9cb473e102
commit 9dd8e296f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 0 deletions

View file

@ -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 &&

View 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))

View 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

View 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;