Skip to content

Commit 5e11044

Browse files
fix: removed duplicates of class properties definitions
1 parent eac1043 commit 5e11044

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

tmpl/container.tmpl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,19 @@
194194
<?js
195195
var methods = self.find({kind: 'function', memberof: isGlobalPage ? {isUndefined: true} : doc.longname});
196196
if (methods && methods.length && methods.forEach) {
197-
methods = methods.filter(function(m) {
198-
return m.access !== 'private';
199-
});
197+
// Remove duplicated definition, keep overwritten by the converter
198+
methods = methods.reduce((acc, method) => {
199+
if(method.access === 'private') return acc
200+
var index = acc.findIndex(m => m.id === method.id)
201+
index < 0 ? acc.push(method) : acc[index] = method
202+
return acc
203+
}, [])
200204
?>
201205
<div class='vertical-section'>
202206
<h1>Methods</h1>
203207
<div class="members">
204-
<?js methods.forEach(function(m) { ?>
208+
<?js methods.forEach(function(m, i) { ?>
209+
<span><?js= m.summary ?></span>
205210
<div class="member"><?js= self.partial('method.tmpl', m) ?></div>
206211
<?js }); ?>
207212
</div>

typescript/type-converter.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,31 @@ const getName = (node, src) => {
4949
return name
5050
}
5151

52+
/**
53+
* Fill missing method declaration
54+
*
55+
* @param {string} comment
56+
* @param member
57+
* @param {string} src
58+
* @return {string}
59+
*/
60+
const fillMethodComment = (comment, member, src) => {
61+
if (!comment.includes('@method')) {
62+
comment = appendComment(comment, '@method')
63+
}
64+
if (!comment.includes('@param')) {
65+
comment = convertParams(comment, member, src)
66+
}
67+
if (ts.isArrayTypeNode(member.type)) {
68+
comment = convertMembers(comment, member.type, src)
69+
}
70+
if (!comment.includes('@return')) {
71+
const returnType = getTypeName(member.type, src)
72+
comment = appendComment(comment, `@return {${returnType}}`)
73+
}
74+
return comment
75+
}
76+
5277
/**
5378
* converts function parameters to @params
5479
*
@@ -203,7 +228,7 @@ module.exports = function typeConverter(src, filename = 'test.ts') {
203228
let memberComment = src.substring(member.jsDoc[0].pos, member.jsDoc[0].end)
204229
const modifiers = (member.modifiers || []).map(m => m.getText({text: src}))
205230
modifiers.forEach(modifier => {
206-
const allowedModifiers = ['abstract', 'private', 'public', 'protected']
231+
const allowedModifiers = ['async', 'abstract', 'private', 'public', 'protected']
207232
if (allowedModifiers.includes(modifier)) {
208233
memberComment = appendComment(memberComment, `@${modifier}`)
209234
}
@@ -213,10 +238,7 @@ module.exports = function typeConverter(src, filename = 'test.ts') {
213238
memberComment = appendComment(memberComment, `@type {${type}}`)
214239
}
215240
if (member.type && ts.isFunctionLike(member)) {
216-
memberComment = appendComment(memberComment, '@method')
217-
memberComment = convertParams(memberComment, member, src)
218-
memberComment = convertMembers(memberComment, member.type, src)
219-
memberComment = appendComment(memberComment, `@return {${getTypeName(member.type, src)}}`)
241+
memberComment = fillMethodComment(memberComment, member, src)
220242
}
221243
if (modifiers.find((m => m === 'static'))) {
222244
memberComment += '\n' + `${className}.${getName(member, src)}`

0 commit comments

Comments
 (0)