Skip to content

Commit b682ee1

Browse files
Merge pull request microsoft#38489 from microsoft/removeDuplicateInfo
Remove duplicate JSDoc comments
2 parents c2b5594 + 355c28e commit b682ee1

File tree

4 files changed

+108
-6
lines changed

4 files changed

+108
-6
lines changed

src/compiler/core.ts

+16
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,22 @@ namespace ts {
129129
return map;
130130
}
131131

132+
/**
133+
* Creates a new array with `element` interspersed in between each element of `input`
134+
* if there is more than 1 value in `input`. Otherwise, returns the existing array.
135+
*/
136+
export function intersperse<T>(input: T[], element: T): T[] {
137+
if (input.length <= 1) {
138+
return input;
139+
}
140+
const result: T[] = [];
141+
for (let i = 0, n = input.length; i < n; i++) {
142+
if (i) result.push(element);
143+
result.push(input[i]);
144+
}
145+
return result;
146+
}
147+
132148
/**
133149
* Iterates through `array` by index and performs the callback on each element of array until the callback
134150
* returns a falsey value, then returns false.

src/services/jsDoc.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,14 @@ namespace ts.JsDoc {
8989
// Eg. const a: Array<string> | Array<number>; a.length
9090
// The property length will have two declarations of property length coming
9191
// from Array<T> - Array<string> and Array<number>
92-
const documentationComment: SymbolDisplayPart[] = [];
92+
const documentationComment: string[] = [];
9393
forEachUnique(declarations, declaration => {
9494
for (const { comment } of getCommentHavingNodes(declaration)) {
9595
if (comment === undefined) continue;
96-
if (documentationComment.length) {
97-
documentationComment.push(lineBreakPart());
98-
}
99-
documentationComment.push(textPart(comment));
96+
pushIfUnique(documentationComment, comment);
10097
}
10198
});
102-
return documentationComment;
99+
return intersperse(map(documentationComment, textPart), lineBreakPart());
103100
}
104101

105102
function getCommentHavingNodes(declaration: Declaration): readonly (JSDoc | JSDocTag)[] {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/quickInfoOnUnionPropertiesWithIdenticalJSDocComments01.ts",
5+
"position": 746
6+
},
7+
"quickInfo": {
8+
"kind": "property",
9+
"kindModifiers": "optional",
10+
"textSpan": {
11+
"start": 746,
12+
"length": 8
13+
},
14+
"displayParts": [
15+
{
16+
"text": "(",
17+
"kind": "punctuation"
18+
},
19+
{
20+
"text": "property",
21+
"kind": "text"
22+
},
23+
{
24+
"text": ")",
25+
"kind": "punctuation"
26+
},
27+
{
28+
"text": " ",
29+
"kind": "space"
30+
},
31+
{
32+
"text": "language",
33+
"kind": "propertyName"
34+
},
35+
{
36+
"text": "?",
37+
"kind": "punctuation"
38+
},
39+
{
40+
"text": ":",
41+
"kind": "punctuation"
42+
},
43+
{
44+
"text": " ",
45+
"kind": "space"
46+
},
47+
{
48+
"text": "string",
49+
"kind": "keyword"
50+
}
51+
],
52+
"documentation": [
53+
{
54+
"text": "A language id, like `typescript`.",
55+
"kind": "text"
56+
}
57+
]
58+
}
59+
}
60+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////export type DocumentFilter = {
4+
//// /** A language id, like `typescript`. */
5+
//// language: string;
6+
//// /** A Uri [scheme](#Uri.scheme), like `file` or `untitled`. */
7+
//// scheme?: string;
8+
//// /** A glob pattern, like `*.{ts,js}`. */
9+
//// pattern?: string;
10+
////} | {
11+
//// /** A language id, like `typescript`. */
12+
//// language?: string;
13+
//// /** A Uri [scheme](#Uri.scheme), like `file` or `untitled`. */
14+
//// scheme: string;
15+
//// /** A glob pattern, like `*.{ts,js}`. */
16+
//// pattern?: string;
17+
////} | {
18+
//// /** A language id, like `typescript`. */
19+
//// language?: string;
20+
//// /** A Uri [scheme](#Uri.scheme), like `file` or `untitled`. */
21+
//// scheme?: string;
22+
//// /** A glob pattern, like `*.{ts,js}`. */
23+
//// pattern: string;
24+
////};
25+
////
26+
////declare let x: DocumentFilter;
27+
////x./**/language
28+
29+
verify.baselineQuickInfo();

0 commit comments

Comments
 (0)