MCPcopy
hub / github.com/webpack/webpack / formatLocation

Function formatLocation

lib/util/formatLocation.js:32–67  ·  view source on GitHub ↗
(loc)

Source from the content-addressed store, hash-verified

30 * @returns {string} formatted location
31 */
32const 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
69module.exports = formatLocation;

Callers 7

recordSideEffectsBailoutFunction · 0.85
applyMethod · 0.85
handleAccessExportMethod · 0.85

Calls 1

formatPositionFunction · 0.85

Tested by

no test coverage detected