diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5c835582da0..604357511c6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16491,7 +16491,7 @@ namespace ts { // If the symbol of the node has members, treat it like a constructor. const symbol = isFunctionDeclaration(node) || isFunctionExpression(node) ? getSymbolOfNode(node) : - isVariableDeclaration(node) && isFunctionExpression(node.initializer) ? getSymbolOfNode(node.initializer) : + isVariableDeclaration(node) && node.initializer && isFunctionExpression(node.initializer) ? getSymbolOfNode(node.initializer) : undefined; return symbol && symbol.members !== undefined; diff --git a/tests/baselines/reference/constructorFunctions.symbols b/tests/baselines/reference/constructorFunctions.symbols index f55075794ab..abd77f3ea21 100644 --- a/tests/baselines/reference/constructorFunctions.symbols +++ b/tests/baselines/reference/constructorFunctions.symbols @@ -74,3 +74,23 @@ const c4_v2 = new C4(); >c4_v2 : Symbol(c4_v2, Decl(index.js, 30, 5)) >C4 : Symbol(C4, Decl(index.js, 25, 3)) +var c5_v1; +>c5_v1 : Symbol(c5_v1, Decl(index.js, 32, 3)) + +c5_v1 = function f() { }; +>c5_v1 : Symbol(c5_v1, Decl(index.js, 32, 3)) +>f : Symbol(f, Decl(index.js, 33, 7)) + +new c5_v1(); +>c5_v1 : Symbol(c5_v1, Decl(index.js, 32, 3)) + +var c5_v2; +>c5_v2 : Symbol(c5_v2, Decl(index.js, 36, 3)) + +c5_v2 = class { }; +>c5_v2 : Symbol(c5_v2, Decl(index.js, 36, 3)) + +new c5_v2(); +>c5_v2 : Symbol(c5_v2, Decl(index.js, 36, 3)) + + diff --git a/tests/baselines/reference/constructorFunctions.types b/tests/baselines/reference/constructorFunctions.types index 3429758b017..e93f0c23aec 100644 --- a/tests/baselines/reference/constructorFunctions.types +++ b/tests/baselines/reference/constructorFunctions.types @@ -112,3 +112,29 @@ const c4_v2 = new C4(); >new C4() : {} >C4 : () => any +var c5_v1; +>c5_v1 : any + +c5_v1 = function f() { }; +>c5_v1 = function f() { } : () => void +>c5_v1 : any +>function f() { } : () => void +>f : () => void + +new c5_v1(); +>new c5_v1() : any +>c5_v1 : () => void + +var c5_v2; +>c5_v2 : any + +c5_v2 = class { }; +>c5_v2 = class { } : typeof (Anonymous class) +>c5_v2 : any +>class { } : typeof (Anonymous class) + +new c5_v2(); +>new c5_v2() : (Anonymous class) +>c5_v2 : typeof (Anonymous class) + + diff --git a/tests/cases/conformance/salsa/constructorFunctions.ts b/tests/cases/conformance/salsa/constructorFunctions.ts index 4f1a0368244..6c166a22f77 100644 --- a/tests/cases/conformance/salsa/constructorFunctions.ts +++ b/tests/cases/conformance/salsa/constructorFunctions.ts @@ -33,4 +33,13 @@ var C4 = function () { }; const c4_v1 = C4(); -const c4_v2 = new C4(); \ No newline at end of file +const c4_v2 = new C4(); + +var c5_v1; +c5_v1 = function f() { }; +new c5_v1(); + +var c5_v2; +c5_v2 = class { }; +new c5_v2(); +