diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 204c8a508fb..76394eeef53 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2318,9 +2318,9 @@ namespace ts { function getSourceOfAssignment(node: Node): Node | undefined { return isExpressionStatement(node) && - node.expression && isBinaryExpression(node.expression) && + isBinaryExpression(node.expression) && node.expression.operatorToken.kind === SyntaxKind.EqualsToken - ? node.expression.right + ? getRightMostAssignedExpression(node.expression) : undefined; } diff --git a/tests/baselines/reference/constructorTagOnNestedBinaryExpression.symbols b/tests/baselines/reference/constructorTagOnNestedBinaryExpression.symbols new file mode 100644 index 00000000000..669354c9916 --- /dev/null +++ b/tests/baselines/reference/constructorTagOnNestedBinaryExpression.symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/jsdoc/constructorTagOnNestedBinaryExpression.js === +// Fixes #35021 +/** @constructor */ +a = b = function c () { +>c : Symbol(c, Decl(constructorTagOnNestedBinaryExpression.js, 2, 7)) + + console.log(this) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(c, Decl(constructorTagOnNestedBinaryExpression.js, 2, 7)) + +}; + diff --git a/tests/baselines/reference/constructorTagOnNestedBinaryExpression.types b/tests/baselines/reference/constructorTagOnNestedBinaryExpression.types new file mode 100644 index 00000000000..64659df1d2b --- /dev/null +++ b/tests/baselines/reference/constructorTagOnNestedBinaryExpression.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/jsdoc/constructorTagOnNestedBinaryExpression.js === +// Fixes #35021 +/** @constructor */ +a = b = function c () { +>a = b = function c () { console.log(this)} : typeof c +>a : error +>b = function c () { console.log(this)} : typeof c +>b : error +>function c () { console.log(this)} : typeof c +>c : typeof c + + console.log(this) +>console.log(this) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>this : this + +}; + diff --git a/tests/cases/conformance/jsdoc/constructorTagOnNestedBinaryExpression.ts b/tests/cases/conformance/jsdoc/constructorTagOnNestedBinaryExpression.ts new file mode 100644 index 00000000000..956f302ed6f --- /dev/null +++ b/tests/cases/conformance/jsdoc/constructorTagOnNestedBinaryExpression.ts @@ -0,0 +1,8 @@ +// @allowjs: true +// @noemit: true +// @Filename: constructorTagOnNestedBinaryExpression.js +// Fixes #35021 +/** @constructor */ +a = b = function c () { + console.log(this) +};