fix unit test, add handling for line only location

This commit is contained in:
Tobias Koppers 2018-07-15 09:57:36 +02:00
parent 24cfc39658
commit 9f0eeed919
2 changed files with 11 additions and 28 deletions

View File

@ -39,6 +39,15 @@ const formatLocation = loc => {
loc.start.line === loc.end.line
) {
return `${formatPosition(loc.start)}-${loc.end.column}`;
} else if (
typeof loc.start === "object" &&
typeof loc.start.line === "number" &&
typeof loc.start.column !== "number" &&
typeof loc.end === "object" &&
typeof loc.end.line === "number" &&
typeof loc.end.column !== "number"
) {
return `${loc.start.line}-${loc.end.line}`;
} else {
return `${formatPosition(loc.start)}-${formatPosition(loc.end)}`;
}

View File

@ -14,16 +14,6 @@ describe("formatLocation", () => {
loc: null,
result: ""
},
{
name: "string",
loc: "str",
result: "str"
},
{
name: "number",
loc: 12,
result: "12"
},
{
name: "line-column",
loc: {
@ -62,22 +52,6 @@ describe("formatLocation", () => {
},
result: "5:6"
},
{
name: "start-end string",
loc: {
start: "start",
end: "end"
},
result: "start-end"
},
{
name: "start-end number",
loc: {
start: 9,
end: 7
},
result: "9-7"
},
{
name: "line",
loc: {
@ -85,10 +59,10 @@ describe("formatLocation", () => {
line: 10
},
end: {
index: 20
line: 20
}
},
result: "10:?-+20"
result: "10-20"
},
{
name: "line",