|
| 1 | +var flatteners = { |
| 2 | + 'abstract': flattenBoolean, |
| 3 | + 'access': propKey('access', 'access'), |
| 4 | + 'alias': prop('name'), |
| 5 | + 'arg': synonym('param'), |
| 6 | + 'argument': synonym('param'), |
| 7 | + 'augments': collect('augments'), |
| 8 | + 'author': prop('description'), |
| 9 | + 'borrows': todo, |
| 10 | + 'callback': prop('description'), |
| 11 | + 'class': flattenTypedName, |
| 12 | + 'classdesc': prop('description'), |
| 13 | + 'const': synonym('constant'), |
| 14 | + 'constant': flattenTypedName, |
| 15 | + 'constructor': synonym('class'), |
| 16 | + 'constructs': todo, |
| 17 | + 'copyright': prop('description'), |
| 18 | + 'default': todo, |
| 19 | + 'defaultvalue': synonym('default'), |
| 20 | + 'deprecated': prop('description'), |
| 21 | + 'desc': synonym('description'), |
| 22 | + 'description': prop('description'), |
| 23 | + 'emits': synonym('fires'), |
| 24 | + 'enum': todo, |
| 25 | + 'event': prop('description'), |
| 26 | + 'example': function (result, tag) { |
| 27 | + if (!tag.description) { |
| 28 | + result.errors.push({ |
| 29 | + message: '@example without code', |
| 30 | + commentLineNumber: tag.lineNumber |
| 31 | + }); |
| 32 | + return; |
| 33 | + } |
| 34 | + |
| 35 | + if (!result.examples) { |
| 36 | + result.examples = []; |
| 37 | + } |
| 38 | + |
| 39 | + var example = { |
| 40 | + description: tag.description |
| 41 | + }; |
| 42 | + |
| 43 | + if (tag.caption) { |
| 44 | + example.caption = tag.caption; |
| 45 | + } |
| 46 | + |
| 47 | + result.examples.push(example); |
| 48 | + }, |
| 49 | + 'exception': synonym('throws'), |
| 50 | + 'exports': todo, |
| 51 | + 'extends': synonym('augments'), |
| 52 | + 'external': prop('description'), |
| 53 | + 'file': prop('description'), |
| 54 | + 'fileoverview': synonym('file'), |
| 55 | + 'fires': todo, |
| 56 | + 'func': synonym('function'), |
| 57 | + 'function': prop('name'), |
| 58 | + 'global': propKey('title', 'scope'), |
| 59 | + 'host': synonym('external'), |
| 60 | + 'ignore': flattenBoolean, |
| 61 | + 'implements': todo, |
| 62 | + 'inheritdoc': todo, |
| 63 | + 'inner': propKey('title', 'scope'), |
| 64 | + 'instance': propKey('title', 'scope'), |
| 65 | + 'interface': function (result, tag) { |
| 66 | + result.interface = true; |
| 67 | + if (tag.description) { |
| 68 | + result.name = tag.description; |
| 69 | + } |
| 70 | + }, |
| 71 | + 'kind': propKey('kind', 'kind'), |
| 72 | + 'lends': prop('description'), |
| 73 | + 'license': prop('description'), |
| 74 | + 'linkcode': synonym('link'), |
| 75 | + 'linkplain': synonym('link'), |
| 76 | + 'listens': todo, |
| 77 | + 'member': flattenTypedName, |
| 78 | + 'memberof': prop('description'), |
| 79 | + 'method': synonym('function'), |
| 80 | + 'mixes': todo, |
| 81 | + 'mixin': prop('name'), |
| 82 | + 'module': flattenTypedName, |
| 83 | + 'name': prop('name'), |
| 84 | + 'namespace': flattenTypedName, |
| 85 | + 'override': flattenBoolean, |
| 86 | + 'overview': synonym('file'), |
| 87 | + 'param': collect('params'), |
| 88 | + 'private': propKey('title', 'access'), |
| 89 | + 'prop': synonym('property'), |
| 90 | + 'property': collect('properties'), |
| 91 | + 'protected': propKey('title', 'access'), |
| 92 | + 'public': propKey('title', 'access'), |
| 93 | + 'readonly': flattenBoolean, |
| 94 | + 'requires': todo, |
| 95 | + 'return': synonym('returns'), |
| 96 | + 'returns': collect('returns'), |
| 97 | + 'see': collect('sees', true), |
| 98 | + 'since': prop('description'), |
| 99 | + 'static': propKey('title', 'scope'), |
| 100 | + 'summary': prop('description'), |
| 101 | + 'this': todo, |
| 102 | + 'throws': collect('throws'), |
| 103 | + 'todo': collect('todos', true), |
| 104 | + 'tutorial': todo, |
| 105 | + 'type': todo, |
| 106 | + 'typedef': flattenTypedName, |
| 107 | + 'var': synonym('member'), |
| 108 | + 'variation': propKey('variation', 'variation'), |
| 109 | + 'version': prop('description'), |
| 110 | + 'virtual': synonym('abstract') |
| 111 | +}; |
| 112 | + |
| 113 | +function todo() {} |
| 114 | + |
| 115 | +function collect(key, description) { |
| 116 | + function flattenCollect(result, tag) { |
| 117 | + if (!result[key]) { |
| 118 | + result[key] = []; |
| 119 | + } |
| 120 | + if (description) { |
| 121 | + result[key].push(tag.description); |
| 122 | + } else { |
| 123 | + result[key].push(tag); |
| 124 | + } |
| 125 | + } |
| 126 | + return flattenCollect; |
| 127 | +} |
| 128 | + |
| 129 | +function synonym(key) { |
| 130 | + function flattenSynonym(result, tag) { |
| 131 | + return flatteners[key](result, tag, key); |
| 132 | + } |
| 133 | + return flattenSynonym; |
| 134 | +} |
| 135 | + |
| 136 | +function flattenBoolean(result, tag, key) { |
| 137 | + result[key] = true; |
| 138 | +} |
| 139 | +flattenBoolean.singleUse = true; |
| 140 | + |
| 141 | +function prop(prop) { |
| 142 | + function flattenProp(result, tag, key) { |
| 143 | + result[key] = tag[prop]; |
| 144 | + } |
| 145 | + flattenProp.singleUse = true; |
| 146 | + return flattenProp; |
| 147 | +} |
| 148 | +prop.singleUse = true; |
| 149 | + |
| 150 | +function propKey(prop, key) { |
| 151 | + function flattenProp(result, tag) { |
| 152 | + result[key] = tag[prop]; |
| 153 | + } |
| 154 | + flattenProp.singleUse = true; |
| 155 | + return flattenProp; |
| 156 | +} |
| 157 | +propKey.singleUse = true; |
| 158 | + |
| 159 | +function flattenTypedName(result, tag, key) { |
| 160 | + result[key] = { |
| 161 | + name: tag.name |
| 162 | + }; |
| 163 | + |
| 164 | + if (tag.type) { |
| 165 | + result[key].type = tag.type; |
| 166 | + } |
| 167 | +} |
| 168 | + |
| 169 | +module.exports = flatteners; |
0 commit comments