Get jsdoc host from chained assignment (#36111)

* Get jsdoc host from chained assignment

getSourceOfAssignment previously only checked one level of binary
expression instead of following binary expressions all the way to the
right. This meant that binding of `@constructor` would fail in the
following example:

```js
/** @constructor */
a = b = function () { }
```

* cleanup lint

* use existing utility
This commit is contained in:
Nathan Shively-Sanders authored and GitHub committed 2020-01-10 10:09:39 -08:00
1 parent 94271aa753
commit 517d6eea28
4 files changed
+44 -2

No files matched your search

+2 -2
View File
@@ -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;
}
@@ -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))
};
@@ -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
};
@@ -0,0 +1,8 @@
// @allowjs: true
// @noemit: true
// @Filename: constructorTagOnNestedBinaryExpression.js
// Fixes #35021
/** @constructor */
a = b = function c () {
console.log(this)
};