Skip to content

Commit 9ecab03

Browse files
Merge pull request #191 from SoftwareBrothers/remove-class-properties-duplicates
fix: removed duplicates of class properties definitions
2 parents 23dbb66 + 8469539 commit 9ecab03

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

tmpl/container.tmpl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,13 @@
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>

typescript/type-converter.js

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

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

0 commit comments

Comments
 (0)