Don't treat object properties as potential JS contructors without JSDoc class tag (#49735)

This commit is contained in:
Jake Bailey
2022-08-10 14:19:19 -04:00
committed by GitHub
parent 382f0c3af3
commit 5fbf3b04dc
10 changed files with 324 additions and 5 deletions

View File

@@ -31906,12 +31906,15 @@ namespace ts {
return false;
}
const func = isFunctionDeclaration(node) || isFunctionExpression(node) ? node :
isVariableDeclaration(node) && node.initializer && isFunctionExpression(node.initializer) ? node.initializer :
(isVariableDeclaration(node) || isPropertyAssignment(node)) && node.initializer && isFunctionExpression(node.initializer) ? node.initializer :
undefined;
if (func) {
// If the node has a @class tag, treat it like a constructor.
// If the node has a @class or @constructor tag, treat it like a constructor.
if (getJSDocClassTag(node)) return true;
// If the node is a property of an object literal.
if (isPropertyAssignment(walkUpParenthesizedExpressions(func.parent))) return false;
// If the symbol of the node has members, treat it like a constructor.
const symbol = getSymbolOfNode(func);
return !!symbol?.members?.size;