(loc)
| 30 | * @returns {string} formatted location |
| 31 | */ |
| 32 | const formatLocation = (loc) => { |
| 33 | if (loc && typeof loc === "object") { |
| 34 | if ("start" in loc && loc.start && "end" in loc && loc.end) { |
| 35 | if ( |
| 36 | typeof loc.start === "object" && |
| 37 | typeof loc.start.line === "number" && |
| 38 | typeof loc.end === "object" && |
| 39 | typeof loc.end.line === "number" && |
| 40 | typeof loc.end.column === "number" && |
| 41 | loc.start.line === loc.end.line |
| 42 | ) { |
| 43 | return `${formatPosition(loc.start)}-${loc.end.column}`; |
| 44 | } else if ( |
| 45 | typeof loc.start === "object" && |
| 46 | typeof loc.start.line === "number" && |
| 47 | typeof loc.start.column !== "number" && |
| 48 | typeof loc.end === "object" && |
| 49 | typeof loc.end.line === "number" && |
| 50 | typeof loc.end.column !== "number" |
| 51 | ) { |
| 52 | return `${loc.start.line}-${loc.end.line}`; |
| 53 | } |
| 54 | return `${formatPosition(loc.start)}-${formatPosition(loc.end)}`; |
| 55 | } |
| 56 | if ("start" in loc && loc.start) { |
| 57 | return formatPosition(loc.start); |
| 58 | } |
| 59 | if ("name" in loc && "index" in loc) { |
| 60 | return `${loc.name}[${loc.index}]`; |
| 61 | } |
| 62 | if ("name" in loc) { |
| 63 | return loc.name; |
| 64 | } |
| 65 | } |
| 66 | return ""; |
| 67 | }; |
| 68 | |
| 69 | module.exports = formatLocation; |
no test coverage detected