From 4ab446c31e7dc204bad7764bfe0ccd1e29c2779f Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 9 Jan 2018 15:14:41 -0800 Subject: [PATCH 1/4] Parse comment on @property tag and use as documentation comment --- src/compiler/parser.ts | 34 +++++++++++-------- src/compiler/utilities.ts | 15 +++----- src/services/jsDoc.ts | 30 +++++++++++----- tests/cases/fourslash/quickInfoPropertyTag.ts | 14 ++++++++ 4 files changed, 60 insertions(+), 33 deletions(-) create mode 100644 tests/cases/fourslash/quickInfoPropertyTag.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index bae9f0594ed19..a6cd4bb353b26 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6454,10 +6454,11 @@ namespace ts { // a badly malformed tag should not be added to the list of tags return; } - addTag(tag, parseTagComments(indent + tag.end - tag.pos)); + tag.comment = parseTagComments(indent + tag.end - tag.pos); + addTag(tag); } - function parseTagComments(indent: number) { + function parseTagComments(indent: number): string { const comments: string[] = []; let state = JSDocState.BeginningOfLine; let margin: number | undefined; @@ -6514,7 +6515,7 @@ namespace ts { removeLeadingNewlines(comments); removeTrailingNewlines(comments); - return comments; + return comments.join(""); } function parseUnknownTag(atToken: AtToken, tagName: Identifier) { @@ -6524,9 +6525,7 @@ namespace ts { return finishNode(result); } - function addTag(tag: JSDocTag, comments: string[]): void { - tag.comment = comments.join(""); - + function addTag(tag: JSDocTag): void { if (!tags) { tags = [tag]; tagsPos = tag.pos; @@ -6571,9 +6570,7 @@ namespace ts { } } - function parseParameterOrPropertyTag(atToken: AtToken, tagName: Identifier, target: PropertyLikeParse.Parameter): JSDocParameterTag; - function parseParameterOrPropertyTag(atToken: AtToken, tagName: Identifier, target: PropertyLikeParse.Property): JSDocPropertyTag; - function parseParameterOrPropertyTag(atToken: AtToken, tagName: Identifier, target: PropertyLikeParse): JSDocPropertyLikeTag { + function parseParameterOrPropertyTag(atToken: AtToken, tagName: Identifier, target: PropertyLikeParse): JSDocParameterTag | JSDocPropertyTag { let typeExpression = tryParseTypeExpression(); let isNameFirst = !typeExpression; skipWhitespace(); @@ -6585,7 +6582,7 @@ namespace ts { typeExpression = tryParseTypeExpression(); } - const result: JSDocPropertyLikeTag = target === PropertyLikeParse.Parameter ? + const result = target === PropertyLikeParse.Parameter ? createNode(SyntaxKind.JSDocParameterTag, atToken.pos) : createNode(SyntaxKind.JSDocPropertyTag, atToken.pos); const nestedTypeLiteral = parseNestedTypeLiteral(typeExpression, name); @@ -6600,7 +6597,6 @@ namespace ts { result.isNameFirst = isNameFirst; result.isBracketed = isBracketed; return finishNode(result); - } function parseNestedTypeLiteral(typeExpression: JSDocTypeExpression, name: EntityName) { @@ -6829,18 +6825,28 @@ namespace ts { if (!tagName) { return false; } + let t: PropertyLikeParse; switch (tagName.escapedText) { case "type": return target === PropertyLikeParse.Property && parseTypeTag(atToken, tagName); case "prop": case "property": - return target === PropertyLikeParse.Property && parseParameterOrPropertyTag(atToken, tagName, target); + t = PropertyLikeParse.Property; + break; case "arg": case "argument": case "param": - return target === PropertyLikeParse.Parameter && parseParameterOrPropertyTag(atToken, tagName, target); + t = PropertyLikeParse.Parameter; + break; + default: + return false; } - return false; + if (target !== t) { + return false; + } + const tag = parseParameterOrPropertyTag(atToken, tagName, target); + tag.comment = parseTagComments(tag.end - tag.pos); + return tag; } function parseTemplateTag(atToken: AtToken, tagName: Identifier): JSDocTemplateTag | undefined { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 37b62fd5d85fb..07e49c1f74b6d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1586,35 +1586,28 @@ namespace ts { ((node as JSDocFunctionType).parameters[0].name as Identifier).escapedText === "new"; } - export function getAllJSDocs(node: Node): (JSDoc | JSDocTag)[] { - if (isJSDocTypedefTag(node)) { - return [node.parent]; - } - return getJSDocCommentsAndTags(node); - } - - export function getSourceOfAssignment(node: Node): Node { + function getSourceOfAssignment(node: Node): Node { return isExpressionStatement(node) && node.expression && isBinaryExpression(node.expression) && node.expression.operatorToken.kind === SyntaxKind.EqualsToken && node.expression.right; } - export function getSingleInitializerOfVariableStatement(node: Node, child?: Node): Node { + function getSingleInitializerOfVariableStatement(node: Node, child?: Node): Node { return isVariableStatement(node) && node.declarationList.declarations.length > 0 && (!child || node.declarationList.declarations[0].initializer === child) && node.declarationList.declarations[0].initializer; } - export function getSingleVariableOfVariableStatement(node: Node, child?: Node): Node { + function getSingleVariableOfVariableStatement(node: Node, child?: Node): Node { return isVariableStatement(node) && node.declarationList.declarations.length > 0 && (!child || node.declarationList.declarations[0] === child) && node.declarationList.declarations[0]; } - export function getNestedModuleDeclaration(node: Node): Node { + function getNestedModuleDeclaration(node: Node): Node { return node.kind === SyntaxKind.ModuleDeclaration && (node as ModuleDeclaration).body && (node as ModuleDeclaration).body.kind === SyntaxKind.ModuleDeclaration && diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index 46f2458bba9ac..7dec105ff1d05 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -52,20 +52,34 @@ namespace ts.JsDoc { // Eg. const a: Array | Array; a.length // The property length will have two declarations of property length coming // from Array - Array and Array - const documentationComment = []; + const documentationComment: SymbolDisplayPart[] = []; forEachUnique(declarations, declaration => { - forEach(getAllJSDocs(declaration), doc => { - if (doc.comment) { - if (documentationComment.length) { - documentationComment.push(lineBreakPart()); - } - documentationComment.push(textPart(doc.comment)); + for (const comment of getCommentsFromDeclaration(declaration)) { + if (documentationComment.length) { + documentationComment.push(lineBreakPart()); } - }); + documentationComment.push(textPart(comment)); + } }); return documentationComment; } + function getCommentsFromDeclaration(declaration: Declaration): string[] { + switch (declaration.kind) { + case SyntaxKind.JSDocPropertyTag: + return [(declaration as JSDocPropertyTag).comment]; + default: + return mapDefined(getAllJSDocs(declaration), doc => doc.comment); + } + } + + function getAllJSDocs(node: Node): (JSDoc | JSDocTag)[] { + if (isJSDocTypedefTag(node)) { + return [node.parent]; + } + return getJSDocCommentsAndTags(node); + } + export function getJsDocTagsFromDeclarations(declarations?: Declaration[]): JSDocTagInfo[] { // Only collect doc comments from duplicate declarations once. const tags: JSDocTagInfo[] = []; diff --git a/tests/cases/fourslash/quickInfoPropertyTag.ts b/tests/cases/fourslash/quickInfoPropertyTag.ts new file mode 100644 index 0000000000000..30941c7e8b436 --- /dev/null +++ b/tests/cases/fourslash/quickInfoPropertyTag.ts @@ -0,0 +1,14 @@ +/// + +// @allowJs: true + +// @Filename: /a.js +/////** +//// * @typedef I +//// * @property {number} x Doc +//// */ +//// +/////** @type {I} */ +////const obj = { /**/x: 10 }; + +verify.quickInfoAt("", "(property) x: number", "Doc"); From 518101784116ab0908f9403d2f37f9342f5e2b69 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 10 Jan 2018 09:11:41 -0800 Subject: [PATCH 2/4] Fix comment parsing bug -- back up after seeing `@` character --- src/compiler/parser.ts | 16 ++++------ src/compiler/utilities.ts | 2 +- src/services/jsDoc.ts | 30 +++++++++---------- ...ments.parsesCorrectly.leadingAsterisk.json | 3 +- ...nts.parsesCorrectly.noLeadingAsterisk.json | 3 +- ...Comments.parsesCorrectly.noReturnType.json | 3 +- ...cComments.parsesCorrectly.oneParamTag.json | 3 +- ...parsesCorrectly.paramTagNameThenType1.json | 3 +- ...ents.parsesCorrectly.paramWithoutType.json | 3 +- ...ocComments.parsesCorrectly.returnTag1.json | 3 +- ...cComments.parsesCorrectly.returnsTag1.json | 3 +- ...cComments.parsesCorrectly.templateTag.json | 3 +- ...Comments.parsesCorrectly.templateTag2.json | 3 +- ...Comments.parsesCorrectly.templateTag3.json | 3 +- ...Comments.parsesCorrectly.templateTag4.json | 3 +- ...Comments.parsesCorrectly.templateTag5.json | 3 +- ...Comments.parsesCorrectly.twoParamTag2.json | 6 ++-- ...parsesCorrectly.twoParamTagOnSameLine.json | 6 ++-- .../DocComments.parsesCorrectly.typeTag.json | 3 +- ...sCorrectly.typedefTagWithChildrenTags.json | 3 +- tests/baselines/reference/jsDocTypeTag1.js | 26 ++++++++-------- tests/baselines/reference/jsDocTypeTag2.js | 24 +++++++-------- tests/baselines/reference/jsDocTypedef1.js | 2 +- .../reference/quickInfoJsDocTags.baseline | 4 +-- 24 files changed, 68 insertions(+), 93 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a6cd4bb353b26..4cbeb156573a5 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6268,7 +6268,6 @@ namespace ts { scanner.scanRange(start + 3, length - 5, () => { // Initially we can parse out a tag. We also have seen a starting asterisk. // This is so that /** * @type */ doesn't parse. - let advanceToken = true; let state = JSDocState.SawAsterisk; let margin: number | undefined = undefined; // + 4 for leading '/** ' @@ -6300,7 +6299,6 @@ namespace ts { // Real-world comments may break this rule, so "BeginningOfLine" will not be a real line beginning // for malformed examples like `/** @param {string} x @returns {number} the length */` state = JSDocState.BeginningOfLine; - advanceToken = false; margin = undefined; indent++; } @@ -6352,13 +6350,7 @@ namespace ts { pushComment(scanner.getTokenText()); break; } - if (advanceToken) { - t = nextJSDocToken(); - } - else { - advanceToken = true; - t = currentToken as JsDocSyntaxKind; - } + t = nextJSDocToken(); } removeLeadingNewlines(comments); removeTrailingNewlines(comments); @@ -6458,7 +6450,7 @@ namespace ts { addTag(tag); } - function parseTagComments(indent: number): string { + function parseTagComments(indent: number): string | undefined { const comments: string[] = []; let state = JSDocState.BeginningOfLine; let margin: number | undefined; @@ -6480,6 +6472,8 @@ namespace ts { indent = 0; break; case SyntaxKind.AtToken: + scanner.setTextPos(scanner.getTextPos() - 1); + // falls through case SyntaxKind.EndOfFileToken: // Done break loop; @@ -6515,7 +6509,7 @@ namespace ts { removeLeadingNewlines(comments); removeTrailingNewlines(comments); - return comments.join(""); + return comments.length === 0 ? undefined : comments.join(""); } function parseUnknownTag(atToken: AtToken, tagName: Identifier) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 07e49c1f74b6d..8304320b3019f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1614,7 +1614,7 @@ namespace ts { (node as ModuleDeclaration).body; } - export function getJSDocCommentsAndTags(node: Node): (JSDoc | JSDocTag)[] { + export function getJSDocCommentsAndTags(node: Node): ReadonlyArray { let result: (JSDoc | JSDocTag)[] | undefined; getJSDocCommentsAndTagsWorker(node); return result || emptyArray; diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index 7dec105ff1d05..369d65beff24a 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -54,7 +54,8 @@ namespace ts.JsDoc { // from Array - Array and Array const documentationComment: SymbolDisplayPart[] = []; forEachUnique(declarations, declaration => { - for (const comment of getCommentsFromDeclaration(declaration)) { + for (const { comment } of getCommentHavingNodes(declaration)) { + if (comment === undefined) continue; if (documentationComment.length) { documentationComment.push(lineBreakPart()); } @@ -64,20 +65,15 @@ namespace ts.JsDoc { return documentationComment; } - function getCommentsFromDeclaration(declaration: Declaration): string[] { + function getCommentHavingNodes(declaration: Declaration): ReadonlyArray { switch (declaration.kind) { case SyntaxKind.JSDocPropertyTag: - return [(declaration as JSDocPropertyTag).comment]; + return [declaration as JSDocPropertyTag]; + case SyntaxKind.JSDocTypedefTag: + return [(declaration as JSDocTypedefTag).parent]; default: - return mapDefined(getAllJSDocs(declaration), doc => doc.comment); - } - } - - function getAllJSDocs(node: Node): (JSDoc | JSDocTag)[] { - if (isJSDocTypedefTag(node)) { - return [node.parent]; + return getJSDocCommentsAndTags(declaration); } - return getJSDocCommentsAndTags(node); } export function getJsDocTagsFromDeclarations(declarations?: Declaration[]): JSDocTagInfo[] { @@ -91,7 +87,7 @@ namespace ts.JsDoc { return tags; } - function getCommentText(tag: JSDocTag): string { + function getCommentText(tag: JSDocTag): string | undefined { const { comment } = tag; switch (tag.kind) { case SyntaxKind.JSDocAugmentsTag: @@ -106,15 +102,19 @@ namespace ts.JsDoc { const { name } = tag as JSDocTypedefTag | JSDocPropertyTag | JSDocParameterTag; return name ? withNode(name) : comment; default: - return comment; + return comment || ""; } function withNode(node: Node) { - return `${node.getText()} ${comment}`; + return addComment(node.getText()); } function withList(list: NodeArray): string { - return `${list.map(x => x.getText())} ${comment}`; + return addComment(list.map(x => x.getText()).join(", ")); + } + + function addComment(s: string) { + return comment === undefined ? s : `${s} ${comment}`; } } diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.leadingAsterisk.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.leadingAsterisk.json index 934de3d8faf6d..a21f9f81c44fd 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.leadingAsterisk.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.leadingAsterisk.json @@ -27,8 +27,7 @@ "pos": 15, "end": 21 } - }, - "comment": "" + } }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noLeadingAsterisk.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noLeadingAsterisk.json index 934de3d8faf6d..a21f9f81c44fd 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noLeadingAsterisk.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noLeadingAsterisk.json @@ -27,8 +27,7 @@ "pos": 15, "end": 21 } - }, - "comment": "" + } }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noReturnType.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noReturnType.json index 62228eac4af6f..079d09c6eeb56 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noReturnType.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.noReturnType.json @@ -17,8 +17,7 @@ "pos": 9, "end": 15, "escapedText": "return" - }, - "comment": "" + } }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.oneParamTag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.oneParamTag.json index 15e8b4a5cfbb9..4940bcf325ebc 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.oneParamTag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.oneParamTag.json @@ -35,8 +35,7 @@ "escapedText": "name1" }, "isNameFirst": false, - "isBracketed": false, - "comment": "" + "isBracketed": false }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagNameThenType1.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagNameThenType1.json index 93f47686e8f11..7a1c85b25d65b 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagNameThenType1.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramTagNameThenType1.json @@ -35,8 +35,7 @@ "escapedText": "name1" }, "isNameFirst": true, - "isBracketed": false, - "comment": "" + "isBracketed": false }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramWithoutType.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramWithoutType.json index 926344175d795..3d511525c643f 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramWithoutType.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.paramWithoutType.json @@ -25,8 +25,7 @@ "escapedText": "foo" }, "isNameFirst": true, - "isBracketed": false, - "comment": "" + "isBracketed": false }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnTag1.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnTag1.json index 0668e7d6324ba..e02a0a38bb4f0 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnTag1.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnTag1.json @@ -27,8 +27,7 @@ "pos": 17, "end": 23 } - }, - "comment": "" + } }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnsTag1.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnsTag1.json index e108287c52acb..70497ee8c1bd7 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnsTag1.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.returnsTag1.json @@ -27,8 +27,7 @@ "pos": 18, "end": 24 } - }, - "comment": "" + } }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag.json index b39b16497e620..8a146e3cfaf2c 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag.json @@ -33,8 +33,7 @@ "length": 1, "pos": 18, "end": 20 - }, - "comment": "" + } }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag2.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag2.json index 5eeb97af1195b..5bb1df306651c 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag2.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag2.json @@ -44,8 +44,7 @@ "length": 2, "pos": 18, "end": 22 - }, - "comment": "" + } }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag3.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag3.json index 96645551c5c05..295b2122daab2 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag3.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag3.json @@ -44,8 +44,7 @@ "length": 2, "pos": 18, "end": 23 - }, - "comment": "" + } }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag4.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag4.json index 0b2719f59ba4b..4aa29db309216 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag4.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag4.json @@ -44,8 +44,7 @@ "length": 2, "pos": 18, "end": 23 - }, - "comment": "" + } }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag5.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag5.json index 8b6118e9b19ff..5e707f6f03b94 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag5.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.templateTag5.json @@ -44,8 +44,7 @@ "length": 2, "pos": 18, "end": 24 - }, - "comment": "" + } }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTag2.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTag2.json index 391ee1aac2f9b..c73009315bcda 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTag2.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTag2.json @@ -35,8 +35,7 @@ "escapedText": "name1" }, "isNameFirst": false, - "isBracketed": false, - "comment": "" + "isBracketed": false }, "1": { "kind": "JSDocParameterTag", @@ -70,8 +69,7 @@ "escapedText": "name2" }, "isNameFirst": false, - "isBracketed": false, - "comment": "" + "isBracketed": false }, "length": 2, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTagOnSameLine.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTagOnSameLine.json index 628d54d162d89..e1ef0adb9263d 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTagOnSameLine.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.twoParamTagOnSameLine.json @@ -35,8 +35,7 @@ "escapedText": "name1" }, "isNameFirst": false, - "isBracketed": false, - "comment": "" + "isBracketed": false }, "1": { "kind": "JSDocParameterTag", @@ -70,8 +69,7 @@ "escapedText": "name2" }, "isNameFirst": false, - "isBracketed": false, - "comment": "" + "isBracketed": false }, "length": 2, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typeTag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typeTag.json index 934de3d8faf6d..a21f9f81c44fd 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typeTag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typeTag.json @@ -27,8 +27,7 @@ "pos": 15, "end": 21 } - }, - "comment": "" + } }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typedefTagWithChildrenTags.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typedefTagWithChildrenTags.json index 08d270286b9fb..a4a69fc48a6c4 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typedefTagWithChildrenTags.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.typedefTagWithChildrenTags.json @@ -104,8 +104,7 @@ "isBracketed": false } ] - }, - "comment": "" + } }, "length": 1, "pos": 8, diff --git a/tests/baselines/reference/jsDocTypeTag1.js b/tests/baselines/reference/jsDocTypeTag1.js index 75333c693644c..657ff5031a24e 100644 --- a/tests/baselines/reference/jsDocTypeTag1.js +++ b/tests/baselines/reference/jsDocTypeTag1.js @@ -41,7 +41,7 @@ "tags": [ { "name": "type", - "text": "{String} " + "text": "{String}" } ] } @@ -88,7 +88,7 @@ "tags": [ { "name": "type", - "text": "{Number} " + "text": "{Number}" } ] } @@ -135,7 +135,7 @@ "tags": [ { "name": "type", - "text": "{Boolean} " + "text": "{Boolean}" } ] } @@ -182,7 +182,7 @@ "tags": [ { "name": "type", - "text": "{Void} " + "text": "{Void}" } ] } @@ -229,7 +229,7 @@ "tags": [ { "name": "type", - "text": "{Undefined} " + "text": "{Undefined}" } ] } @@ -276,7 +276,7 @@ "tags": [ { "name": "type", - "text": "{Null} " + "text": "{Null}" } ] } @@ -331,7 +331,7 @@ "tags": [ { "name": "type", - "text": "{Array} " + "text": "{Array}" } ] } @@ -390,7 +390,7 @@ "tags": [ { "name": "type", - "text": "{Promise} " + "text": "{Promise}" } ] } @@ -437,7 +437,7 @@ "tags": [ { "name": "type", - "text": "{Object} " + "text": "{Object}" } ] } @@ -484,7 +484,7 @@ "tags": [ { "name": "type", - "text": "{Function} " + "text": "{Function}" } ] } @@ -531,7 +531,7 @@ "tags": [ { "name": "type", - "text": "{*} " + "text": "{*}" } ] } @@ -578,7 +578,7 @@ "tags": [ { "name": "type", - "text": "{?} " + "text": "{?}" } ] } @@ -641,7 +641,7 @@ "tags": [ { "name": "type", - "text": "{String|Number} " + "text": "{String|Number}" } ] } diff --git a/tests/baselines/reference/jsDocTypeTag2.js b/tests/baselines/reference/jsDocTypeTag2.js index 01032a5cc09eb..9933360b0091a 100644 --- a/tests/baselines/reference/jsDocTypeTag2.js +++ b/tests/baselines/reference/jsDocTypeTag2.js @@ -41,7 +41,7 @@ "tags": [ { "name": "type", - "text": "{string} " + "text": "{string}" } ] } @@ -88,7 +88,7 @@ "tags": [ { "name": "type", - "text": "{number} " + "text": "{number}" } ] } @@ -135,7 +135,7 @@ "tags": [ { "name": "type", - "text": "{boolean} " + "text": "{boolean}" } ] } @@ -182,7 +182,7 @@ "tags": [ { "name": "type", - "text": "{void} " + "text": "{void}" } ] } @@ -229,7 +229,7 @@ "tags": [ { "name": "type", - "text": "{undefined} " + "text": "{undefined}" } ] } @@ -276,7 +276,7 @@ "tags": [ { "name": "type", - "text": "{null} " + "text": "{null}" } ] } @@ -331,7 +331,7 @@ "tags": [ { "name": "type", - "text": "{array} " + "text": "{array}" } ] } @@ -390,7 +390,7 @@ "tags": [ { "name": "type", - "text": "{promise} " + "text": "{promise}" } ] } @@ -437,7 +437,7 @@ "tags": [ { "name": "type", - "text": "{?number} " + "text": "{?number}" } ] } @@ -484,7 +484,7 @@ "tags": [ { "name": "type", - "text": "{function} " + "text": "{function}" } ] } @@ -567,7 +567,7 @@ "tags": [ { "name": "type", - "text": "{function (number): number} " + "text": "{function (number): number}" } ] } @@ -630,7 +630,7 @@ "tags": [ { "name": "type", - "text": "{string | number} " + "text": "{string | number}" } ] } diff --git a/tests/baselines/reference/jsDocTypedef1.js b/tests/baselines/reference/jsDocTypedef1.js index 96a86a4f7a81c..e1b34f14c2bfa 100644 --- a/tests/baselines/reference/jsDocTypedef1.js +++ b/tests/baselines/reference/jsDocTypedef1.js @@ -181,7 +181,7 @@ "tags": [ { "name": "param", - "text": "opts " + "text": "opts" } ] } diff --git a/tests/baselines/reference/quickInfoJsDocTags.baseline b/tests/baselines/reference/quickInfoJsDocTags.baseline index ba22520976025..56f190b4446d2 100644 --- a/tests/baselines/reference/quickInfoJsDocTags.baseline +++ b/tests/baselines/reference/quickInfoJsDocTags.baseline @@ -63,7 +63,7 @@ ], "documentation": [ { - "text": "Doc{T} A template", + "text": "DocT} A template", "kind": "text" } ], @@ -82,7 +82,7 @@ }, { "name": "typedef", - "text": "NumOrStr " + "text": "NumOrStr" }, { "name": "property", From a15127f0a69d12aa608bf8fc823bee1293a7e7c0 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 10 Jan 2018 11:00:54 -0800 Subject: [PATCH 3/4] Add test for indent --- tests/cases/fourslash/quickInfoPropertyTag.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/cases/fourslash/quickInfoPropertyTag.ts b/tests/cases/fourslash/quickInfoPropertyTag.ts index 30941c7e8b436..b413a7610e12a 100644 --- a/tests/cases/fourslash/quickInfoPropertyTag.ts +++ b/tests/cases/fourslash/quickInfoPropertyTag.ts @@ -6,9 +6,11 @@ /////** //// * @typedef I //// * @property {number} x Doc +//// * More doc //// */ //// /////** @type {I} */ ////const obj = { /**/x: 10 }; -verify.quickInfoAt("", "(property) x: number", "Doc"); +// TODO: GH#21123 There shouldn't be a " " before "More doc" +verify.quickInfoAt("", "(property) x: number", "Doc\n More doc"); From 28aa3f17a418bd92c3678cdc76045a9cfb52ad66 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 11 Jan 2018 10:31:22 -0800 Subject: [PATCH 4/4] Don't default comment to "" --- src/services/jsDoc.ts | 2 +- tests/baselines/reference/jsDocTags.baseline | 15 +++++---------- tests/cases/fourslash/jsDocTags.ts | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index 369d65beff24a..91774e2290c68 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -102,7 +102,7 @@ namespace ts.JsDoc { const { name } = tag as JSDocTypedefTag | JSDocPropertyTag | JSDocParameterTag; return name ? withNode(name) : comment; default: - return comment || ""; + return comment; } function withNode(node: Node) { diff --git a/tests/baselines/reference/jsDocTags.baseline b/tests/baselines/reference/jsDocTags.baseline index 7f9e9fdce986d..f316a9c42459d 100644 --- a/tests/baselines/reference/jsDocTags.baseline +++ b/tests/baselines/reference/jsDocTags.baseline @@ -268,8 +268,7 @@ "documentation": [], "tags": [ { - "name": "mytag", - "text": "" + "name": "mytag" } ] } @@ -446,8 +445,7 @@ "text": "Another value" }, { - "name": "mytag", - "text": "" + "name": "mytag" } ] } @@ -580,12 +578,10 @@ "text": "here all the comments are on a new line" }, { - "name": "mytag3", - "text": "" + "name": "mytag3" }, { - "name": "mytag", - "text": "" + "name": "mytag" } ] } @@ -655,8 +651,7 @@ "documentation": [], "tags": [ { - "name": "mytag", - "text": "" + "name": "mytag" } ] } diff --git a/tests/cases/fourslash/jsDocTags.ts b/tests/cases/fourslash/jsDocTags.ts index 368939ecbfc07..14ac14e633188 100644 --- a/tests/cases/fourslash/jsDocTags.ts +++ b/tests/cases/fourslash/jsDocTags.ts @@ -67,7 +67,7 @@ verify.currentSignatureHelpTagsAre([{name: "myjsdoctag", text:"this is a comment goTo.marker("11"); verify.currentSignatureHelpTagsAre([{name: "mytag", text:"comment1 comment2"}]) goTo.marker("12"); -verify.currentSignatureHelpTagsAre([{name: "mytag", text:""}]) +verify.currentSignatureHelpTagsAre([{name: "mytag"}]) goTo.marker("13"); verify.currentSignatureHelpTagsAre([{ name: "returns", text: "a value" }])