Skip to content

Commit

Permalink
fix: removed duplicates of class properties definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
ariansobczak-rst committed Jan 21, 2022
1 parent eac1043 commit 5e11044
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
13 changes: 9 additions & 4 deletions tmpl/container.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,19 @@
<?js
var methods = self.find({kind: 'function', memberof: isGlobalPage ? {isUndefined: true} : doc.longname});
if (methods && methods.length && methods.forEach) {
methods = methods.filter(function(m) {
return m.access !== 'private';
});
// Remove duplicated definition, keep overwritten by the converter
methods = methods.reduce((acc, method) => {
if(method.access === 'private') return acc
var index = acc.findIndex(m => m.id === method.id)
index < 0 ? acc.push(method) : acc[index] = method
return acc
}, [])
?>
<div class='vertical-section'>
<h1>Methods</h1>
<div class="members">
<?js methods.forEach(function(m) { ?>
<?js methods.forEach(function(m, i) { ?>
<span><?js= m.summary ?></span>
<div class="member"><?js= self.partial('method.tmpl', m) ?></div>
<?js }); ?>
</div>
Expand Down
32 changes: 27 additions & 5 deletions typescript/type-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@ const getName = (node, src) => {
return name
}

/**
* Fill missing method declaration
*
* @param {string} comment
* @param member
* @param {string} src
* @return {string}
*/
const fillMethodComment = (comment, member, src) => {
if (!comment.includes('@method')) {
comment = appendComment(comment, '@method')
}
if (!comment.includes('@param')) {
comment = convertParams(comment, member, src)
}
if (ts.isArrayTypeNode(member.type)) {
comment = convertMembers(comment, member.type, src)
}
if (!comment.includes('@return')) {
const returnType = getTypeName(member.type, src)
comment = appendComment(comment, `@return {${returnType}}`)
}
return comment
}

/**
* converts function parameters to @params
*
Expand Down Expand Up @@ -203,7 +228,7 @@ module.exports = function typeConverter(src, filename = 'test.ts') {
let memberComment = src.substring(member.jsDoc[0].pos, member.jsDoc[0].end)
const modifiers = (member.modifiers || []).map(m => m.getText({text: src}))
modifiers.forEach(modifier => {
const allowedModifiers = ['abstract', 'private', 'public', 'protected']
const allowedModifiers = ['async', 'abstract', 'private', 'public', 'protected']
if (allowedModifiers.includes(modifier)) {
memberComment = appendComment(memberComment, `@${modifier}`)
}
Expand All @@ -213,10 +238,7 @@ module.exports = function typeConverter(src, filename = 'test.ts') {
memberComment = appendComment(memberComment, `@type {${type}}`)
}
if (member.type && ts.isFunctionLike(member)) {
memberComment = appendComment(memberComment, '@method')
memberComment = convertParams(memberComment, member, src)
memberComment = convertMembers(memberComment, member.type, src)
memberComment = appendComment(memberComment, `@return {${getTypeName(member.type, src)}}`)
memberComment = fillMethodComment(memberComment, member, src)
}
if (modifiers.find((m => m === 'static'))) {
memberComment += '\n' + `${className}.${getName(member, src)}`
Expand Down

0 comments on commit 5e11044

Please sign in to comment.