(getHref, node)
| 101 | * // => 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String' |
| 102 | */ |
| 103 | export default function formatType(getHref, node) { |
| 104 | let result = []; |
| 105 | |
| 106 | if (!node) { |
| 107 | return [t('any')]; |
| 108 | } |
| 109 | |
| 110 | switch (node.type) { |
| 111 | case Syntax.NullableLiteral: |
| 112 | return [t('?')]; |
| 113 | case Syntax.AllLiteral: |
| 114 | return [t('any')]; |
| 115 | case Syntax.NullLiteral: |
| 116 | return [t('null')]; |
| 117 | case Syntax.VoidLiteral: |
| 118 | return [t('void')]; |
| 119 | case Syntax.UndefinedLiteral: |
| 120 | return [link('undefined', getHref)]; |
| 121 | case Syntax.NameExpression: |
| 122 | return [link(node.name, getHref)]; |
| 123 | case Syntax.ParameterType: |
| 124 | if (node.name) { |
| 125 | result.push(t(node.name + ': ')); |
| 126 | } |
| 127 | return result.concat(formatType(getHref, node.expression)); |
| 128 | |
| 129 | case Syntax.TypeApplication: |
| 130 | return formatType(getHref, node.expression).concat( |
| 131 | commaList(getHref, node.applications, '<', '>') |
| 132 | ); |
| 133 | case Syntax.UnionType: |
| 134 | return commaList(getHref, node.elements, '(', ')', ' | '); |
| 135 | case Syntax.ArrayType: |
| 136 | return commaList(getHref, node.elements, '[', ']'); |
| 137 | case Syntax.RecordType: |
| 138 | return commaList(getHref, node.fields, '{', '}'); |
| 139 | |
| 140 | case Syntax.FieldType: |
| 141 | if (node.value) { |
| 142 | return [t(node.key + ': ')].concat(formatType(getHref, node.value)); |
| 143 | } |
| 144 | return [t(node.key)]; |
| 145 | |
| 146 | case Syntax.FunctionType: |
| 147 | result = [t('function (')]; |
| 148 | |
| 149 | if (node['this']) { |
| 150 | if (node['new']) { |
| 151 | result.push(t('new: ')); |
| 152 | } else { |
| 153 | result.push(t('this: ')); |
| 154 | } |
| 155 | |
| 156 | result = result.concat(formatType(getHref, node['this'])); |
| 157 | |
| 158 | if (node.params.length !== 0) { |
| 159 | result.push(t(', ')); |
| 160 | } |
no test coverage detected