| 103 | // Reduce the amount of information in each function's overloads, while |
| 104 | // keeping all the essential data available. |
| 105 | const flattenOverloads = funcObj => { |
| 106 | const result = {}; |
| 107 | |
| 108 | const processOverload = overload => { |
| 109 | if (overload.params) { |
| 110 | return Object.values(overload.params).map(param => processParam(param)); |
| 111 | } |
| 112 | return overload; |
| 113 | }; |
| 114 | |
| 115 | // To simplify `parameterData.json`, instead of having a separate field for |
| 116 | // optional parameters, we'll add a ? to the end of parameter type to |
| 117 | // indicate that it's optional. |
| 118 | const processParam = param => { |
| 119 | let type = param.type; |
| 120 | if (param.optional) { |
| 121 | type += '?'; |
| 122 | } |
| 123 | if (param.rest) { |
| 124 | type = `...${type}[]`; |
| 125 | } |
| 126 | return type; |
| 127 | }; |
| 128 | |
| 129 | // In some cases, even when the arguments are intended to mean different |
| 130 | // things, their types and order are identical. Since the exact meaning |
| 131 | // of the arguments is less important for parameter validation, we'll |
| 132 | // perform overload deduplication here. |
| 133 | const removeDuplicateOverloads = (overload, uniqueOverloads) => { |
| 134 | const overloadString = JSON.stringify(overload); |
| 135 | if (uniqueOverloads.has(overloadString)) { |
| 136 | return false; |
| 137 | } |
| 138 | uniqueOverloads.add(overloadString); |
| 139 | return true; |
| 140 | }; |
| 141 | |
| 142 | for (const [key, value] of Object.entries(funcObj)) { |
| 143 | if (value && typeof value === 'object' && value.overloads) { |
| 144 | const uniqueOverloads = new Set(); |
| 145 | result[key] = { |
| 146 | overloads: Object.values(value.overloads) |
| 147 | .map(overload => processOverload(overload)) |
| 148 | .filter(overload => |
| 149 | removeDuplicateOverloads(overload, uniqueOverloads) |
| 150 | ) |
| 151 | }; |
| 152 | } else { |
| 153 | result[key] = value; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | return result; |
| 158 | }; |
| 159 | |
| 160 | for (const classItem in data) { |
| 161 | if (typeof data[classItem] === 'object') { |
no test coverage detected