File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -1945,7 +1945,7 @@ namespace ts {
1945
1945
classPrototype . parent = leftSideOfAssignment ;
1946
1946
1947
1947
const funcSymbol = container . locals [ constructorFunction . text ] ;
1948
- if ( ! funcSymbol || ! ( funcSymbol . flags & SymbolFlags . Function ) ) {
1948
+ if ( ! funcSymbol || ! ( funcSymbol . flags & SymbolFlags . Function || isDeclarationOfFunctionExpression ( funcSymbol ) ) ) {
1949
1949
return ;
1950
1950
}
1951
1951
Original file line number Diff line number Diff line change @@ -11481,8 +11481,12 @@ namespace ts {
11481
11481
// When resolved signature is a call signature (and not a construct signature) the result type is any, unless
11482
11482
// the declaring function had members created through 'x.prototype.y = expr' or 'this.y = expr' psuedodeclarations
11483
11483
// in a JS file
11484
- const funcSymbol = checkExpression(node.expression).symbol;
11485
- if (funcSymbol && funcSymbol.members && (funcSymbol.flags & SymbolFlags.Function)) {
11484
+ // Note:JS inferred classes might come from a variable declaration instead of a function declaration.
11485
+ // In this case, using getResolvedSymbol directly is required to avoid losing the members from the declaration.
11486
+ const funcSymbol = node.expression.kind === SyntaxKind.Identifier ?
11487
+ getResolvedSymbol(node.expression as Identifier) :
11488
+ checkExpression(node.expression).symbol;
11489
+ if (funcSymbol && funcSymbol.members && (funcSymbol.flags & SymbolFlags.Function || isDeclarationOfFunctionExpression(funcSymbol))) {
11486
11490
return getInferredClassType(funcSymbol);
11487
11491
}
11488
11492
else if (compilerOptions.noImplicitAny) {
Original file line number Diff line number Diff line change @@ -1257,6 +1257,18 @@ namespace ts {
1257
1257
return charCode === CharacterCodes . singleQuote || charCode === CharacterCodes . doubleQuote ;
1258
1258
}
1259
1259
1260
+ /**
1261
+ * Returns true if the node is a variable declaration whose initializer is a function expression.
1262
+ * This function does not test if the node is in a JavaScript file or not.
1263
+ */
1264
+ export function isDeclarationOfFunctionExpression ( s : Symbol ) {
1265
+ if ( s . valueDeclaration && s . valueDeclaration . kind === SyntaxKind . VariableDeclaration ) {
1266
+ const declaration = s . valueDeclaration as VariableDeclaration ;
1267
+ return declaration . initializer && declaration . initializer . kind === SyntaxKind . FunctionExpression ;
1268
+ }
1269
+ return false ;
1270
+ }
1271
+
1260
1272
/// Given a BinaryExpression, returns SpecialPropertyAssignmentKind for the various kinds of property
1261
1273
/// assignments we treat as special in the binder
1262
1274
export function getSpecialPropertyAssignmentKind ( expression : Node ) : SpecialPropertyAssignmentKind {
You can’t perform that action at this time.
0 commit comments