From 8aad976c69ef4528f751a0312db2a40ed6a758d8 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 3 Feb 2016 00:18:36 -0800 Subject: [PATCH 1/2] Recognize object literal method JSDoc comments Fixes #6825 --- src/compiler/parser.ts | 4 +-- src/compiler/utilities.ts | 5 +++ .../fourslash/jsDocFunctionSignatures3.ts | 32 +++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/jsDocFunctionSignatures3.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b6ba02b987c..3ad2cb72507 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3960,7 +3960,7 @@ namespace ts { shorthandDeclaration.equalsToken = equalsToken; shorthandDeclaration.objectAssignmentInitializer = allowInAnd(parseAssignmentExpressionOrHigher); } - return finishNode(shorthandDeclaration); + return addJSDocComment(finishNode(shorthandDeclaration)); } else { const propertyAssignment = createNode(SyntaxKind.PropertyAssignment, fullStart); @@ -3969,7 +3969,7 @@ namespace ts { propertyAssignment.questionToken = questionToken; parseExpected(SyntaxKind.ColonToken); propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher); - return finishNode(propertyAssignment); + return addJSDocComment(finishNode(propertyAssignment)); } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 02b8385d0ff..f794bc81f39 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1220,6 +1220,11 @@ namespace ts { if (isSourceOfAssignmentExpressionStatement) { return node.parent.parent.jsDocComment; } + + const isPropertyAssignmentExpression = node.parent && node.parent.kind === SyntaxKind.PropertyAssignment; + if (isPropertyAssignmentExpression) { + return node.parent.jsDocComment; + } } return undefined; diff --git a/tests/cases/fourslash/jsDocFunctionSignatures3.ts b/tests/cases/fourslash/jsDocFunctionSignatures3.ts new file mode 100644 index 00000000000..3679035d31d --- /dev/null +++ b/tests/cases/fourslash/jsDocFunctionSignatures3.ts @@ -0,0 +1,32 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: Foo.js + +//// var someObject = { +//// /** +//// * @param {string} param1 Some string param. +//// * @param {number} parm2 Some number param. +//// */ +//// someMethod: function(param1, param2) { +//// console.log(param1/*1*/); +//// return false; +//// }, +//// /** +//// * @param {number} p1 Some number param. +//// */ +//// otherMethod(p1) { +//// p1/*2*/ +//// } +//// +//// }; + +goTo.marker('1'); +edit.insert('.'); +verify.memberListContains('substr', undefined, undefined, 'method'); +edit.backspace(); + +goTo.marker('2'); +edit.insert('.'); +verify.memberListContains('toFixed', undefined, undefined, 'method'); +edit.backspace(); From 1c7062313d2dde764ea7f7d20f2415b02d8d6fbb Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 3 Feb 2016 00:44:52 -0800 Subject: [PATCH 2/2] Capture `node.parent` --- src/compiler/utilities.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index f794bc81f39..8f66e43c1d6 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1212,18 +1212,19 @@ namespace ts { } // Also recognize when the node is the RHS of an assignment expression + const parent = node.parent; const isSourceOfAssignmentExpressionStatement = - node.parent && node.parent.parent && - node.parent.kind === SyntaxKind.BinaryExpression && - (node.parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken && - node.parent.parent.kind === SyntaxKind.ExpressionStatement; + parent && parent.parent && + parent.kind === SyntaxKind.BinaryExpression && + (parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken && + parent.parent.kind === SyntaxKind.ExpressionStatement; if (isSourceOfAssignmentExpressionStatement) { - return node.parent.parent.jsDocComment; + return parent.parent.jsDocComment; } - const isPropertyAssignmentExpression = node.parent && node.parent.kind === SyntaxKind.PropertyAssignment; + const isPropertyAssignmentExpression = parent && parent.kind === SyntaxKind.PropertyAssignment; if (isPropertyAssignmentExpression) { - return node.parent.jsDocComment; + return parent.jsDocComment; } }