mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix js-prototype-assignment on declarations
This commit is contained in:
+21
-2
@@ -17915,15 +17915,34 @@ namespace ts {
|
||||
|
||||
function getAssignedClassType(symbol: Symbol) {
|
||||
const decl = symbol.valueDeclaration;
|
||||
const assignmentSymbol = decl && decl.parent && isBinaryExpression(decl.parent) && getSymbolOfNode(decl.parent.left);
|
||||
const assignmentSymbol = decl && decl.parent &&
|
||||
(isBinaryExpression(decl.parent) && getSymbolOfNode(decl.parent.left) ||
|
||||
isVariableDeclaration(decl.parent) && getSymbolOfNode(decl.parent));
|
||||
if (assignmentSymbol) {
|
||||
const prototype = forEach(assignmentSymbol.declarations, d => getAssignedJavascriptPrototype(d.parent));
|
||||
const prototype = forEach(assignmentSymbol.declarations, getAssignedJavascriptPrototype);
|
||||
if (prototype) {
|
||||
return checkExpression(prototype);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getAssignedJavascriptPrototype(node: Node) {
|
||||
if (!node.parent) {
|
||||
return false;
|
||||
}
|
||||
let parent: Node = node.parent;
|
||||
while (parent && parent.kind === SyntaxKind.PropertyAccessExpression) {
|
||||
parent = parent.parent;
|
||||
}
|
||||
return parent && isBinaryExpression(parent) &&
|
||||
isPropertyAccessExpression(parent.left) &&
|
||||
parent.left.name.escapedText === "prototype" &&
|
||||
parent.operatorToken.kind === SyntaxKind.EqualsToken &&
|
||||
isObjectLiteralExpression(parent.right) &&
|
||||
parent.right;
|
||||
}
|
||||
|
||||
|
||||
function getInferredClassType(symbol: Symbol) {
|
||||
const links = getSymbolLinks(symbol);
|
||||
if (!links.inferredClassType) {
|
||||
|
||||
@@ -1488,18 +1488,10 @@ namespace ts {
|
||||
return symbol;
|
||||
}
|
||||
const declaration = symbol.valueDeclaration;
|
||||
const e = getDeclaredJavascriptInitializer(declaration) || getAssignedJavascriptInitializer(declaration) || getAssignedJavascriptPrototype(declaration);
|
||||
const e = getDeclaredJavascriptInitializer(declaration) || getAssignedJavascriptInitializer(declaration);
|
||||
return e ? e.symbol : symbol;
|
||||
}
|
||||
|
||||
export function getAssignedJavascriptPrototype(node: Node) {
|
||||
return isPropertyAccessExpression(node) &&
|
||||
node.parent && isPropertyAccessExpression(node.parent) && node.parent.name.escapedText === "prototype" &&
|
||||
node.parent.parent && isBinaryExpression(node.parent.parent) && node.parent.parent.operatorToken.kind === SyntaxKind.EqualsToken &&
|
||||
node.parent.parent.right.kind === SyntaxKind.ObjectLiteralExpression &&
|
||||
node.parent.parent.right;
|
||||
}
|
||||
|
||||
export function getDeclaredJavascriptInitializer(node: Node) {
|
||||
if (node && isVariableDeclaration(node) && node.initializer) {
|
||||
return getJavascriptInitializer(node.initializer) ||
|
||||
|
||||
Reference in New Issue
Block a user