|
| 1 | +/** |
| 2 | +* Transform @property tags to @member tags if it looks like @property was incorrectly used. |
| 3 | +* - That is, there is only one property and it has the same name as the member. |
| 4 | +* The result is less-redundancy and better type exposure in the JSDoc output. |
| 5 | +* |
| 6 | +* If the member type is not assigned then the property type is used. |
| 7 | +* |
| 8 | +* A meld of the description are used; appending the property description if appropriate. |
| 9 | +* |
| 10 | +* This approach works for most cases in Phaser because JSDoc automatically determines the name if not specified in @name, @method, @member or @field. |
| 11 | +*/ |
| 12 | + |
| 13 | +var path = require('path'); |
| 14 | + |
| 15 | +function looksLikeItMightContain (haystack, needle) { |
| 16 | + |
| 17 | + haystack = haystack || ''; |
| 18 | + needle = needle || ''; |
| 19 | + |
| 20 | + haystack = haystack.replace(/[^a-z]/gi, '').toLowerCase(); |
| 21 | + needle = needle.replace(/[^a-z]/gi, '').toLowerCase(); |
| 22 | + |
| 23 | + return haystack.indexOf(needle) > -1; |
| 24 | + |
| 25 | +} |
| 26 | + |
| 27 | +exports.handlers = {}; |
| 28 | +exports.handlers.newDoclet = function (e) { |
| 29 | + |
| 30 | + var doclet = e.doclet; |
| 31 | + var props = e.doclet.properties; |
| 32 | + |
| 33 | + if (doclet.kind === 'member' && |
| 34 | + props && props.length === 1 && |
| 35 | + props[0].name === doclet.name) |
| 36 | + { |
| 37 | + // "Duplicate" |
| 38 | + var prop = props[0]; |
| 39 | + |
| 40 | + if (!doclet.type) |
| 41 | + { |
| 42 | + doclet.type = prop.type; |
| 43 | + } |
| 44 | + |
| 45 | + if (!doclet.description) |
| 46 | + { |
| 47 | + doclet.description = prop.description; |
| 48 | + } |
| 49 | + else if (prop.description && |
| 50 | + !looksLikeItMightContain(doclet.description, prop.description)) |
| 51 | + { |
| 52 | + // Tack it on.. |
| 53 | + doclet.description += " " + prop.description; |
| 54 | + } |
| 55 | + |
| 56 | + // And no more prop |
| 57 | + e.doclet.properties = undefined; |
| 58 | + } |
| 59 | + |
| 60 | +}; |
0 commit comments