(elt, t)
| 153 | } |
| 154 | |
| 155 | function mapperFor(elt, t) { |
| 156 | const p = t.identifier('parsers'); |
| 157 | const wrap = identifier => t.memberExpression(p, identifier); |
| 158 | |
| 159 | if (t.isNumberTypeAnnotation(elt)) { |
| 160 | return t.callExpression(wrap(t.identifier('numberParser')), [t.stringLiteral(elt.name)]); |
| 161 | } else if (t.isArrayTypeAnnotation(elt)) { |
| 162 | return wrap(t.identifier('arrayParser')); |
| 163 | } else if (t.isAnyTypeAnnotation(elt)) { |
| 164 | return wrap(t.identifier('objectParser')); |
| 165 | } else if (t.isBooleanTypeAnnotation(elt)) { |
| 166 | return wrap(t.identifier('booleanParser')); |
| 167 | } else if (t.isObjectTypeAnnotation(elt)) { |
| 168 | return wrap(t.identifier('objectParser')); |
| 169 | } else if (t.isUnionTypeAnnotation(elt)) { |
| 170 | const unionTypes = elt.typeAnnotation?.types || elt.types; |
| 171 | if (unionTypes?.some(type => t.isBooleanTypeAnnotation(type)) && unionTypes?.some(type => t.isFunctionTypeAnnotation(type))) { |
| 172 | return wrap(t.identifier('booleanOrFunctionParser')); |
| 173 | } |
| 174 | } else if (t.isGenericTypeAnnotation(elt)) { |
| 175 | const type = elt.typeAnnotation.id.name; |
| 176 | if (type == 'Adapter') { |
| 177 | return wrap(t.identifier('moduleOrObjectParser')); |
| 178 | } |
| 179 | if (type == 'NumberOrBoolean') { |
| 180 | return wrap(t.identifier('numberOrBooleanParser')); |
| 181 | } |
| 182 | if (type == 'NumberOrString') { |
| 183 | return t.callExpression(wrap(t.identifier('numberOrStringParser')), [t.stringLiteral(elt.name)]); |
| 184 | } |
| 185 | if (type === 'StringOrStringArray') { |
| 186 | return wrap(t.identifier('arrayParser')); |
| 187 | } |
| 188 | return wrap(t.identifier('objectParser')); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | function parseDefaultValue(elt, value, t) { |
| 193 | let literalValue; |
no test coverage detected
searching dependent graphs…