Skip to content

Commit

Permalink
fix: Strip unnecessary "Object." from function name
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoulb committed Dec 16, 2018
1 parent 55dce4f commit 55de4f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/helpers/destack.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const PARSERS = [
// Chrome, Node, IE, Edge.
// e.g. ` at MyClass.myfunc (a/b/myFile.js:28:60)`
{
match: /^ +at (?:([^(\r\n]+) \(([^:\r\n]+?)(?::([0-9]+))?(?::([0-9]+))?\)|([^:\r\n]+?)(?::([0-9]+))?(?::([0-9]+))?)$/gm,
match: /^ +at (?:(?:Object\.)?([^(\r\n]+) \(([^:\r\n]+?)(?::([0-9]+))?(?::([0-9]+))?\)|([^:\r\n]+?)(?::([0-9]+))?(?::([0-9]+))?)$/gm,
each(matches) {
// Was function named?
if (matches[1]) {
Expand All @@ -34,7 +34,7 @@ const PARSERS = [
// Firefox, Safari.
// e.g. `func@a/b/myFile.js:28:60`
{
match: /^([^@\r\n]*)(?:@([^\r\n]+?)(?::([0-9]+))?(?::([0-9]+))?)?$/gm,
match: /^(?:Object\.)?([^@\r\n]*)(?:@([^\r\n]+?)(?::([0-9]+))?(?::([0-9]+))?)?$/gm,
each(matches) {
return {
function: FUNCS.indexOf(matches[1]) >= 0 ? "" : matches[1] + "()",
Expand Down
4 changes: 2 additions & 2 deletions test/errors/BlorkError.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ describe("BlorkError()", () => {
expect(new BlorkError()).not.toHaveProperty("value");
});
test("Return correct error with message only", () => {
expect(new BlorkError("Message")).toHaveProperty("message", "Object.test(): Message");
expect(new BlorkError("Message")).toHaveProperty("message", "test(): Message");
expect(new BlorkError("Message")).not.toHaveProperty("value");
});
test("Return correct error with message and value", () => {
expect(new BlorkError("Message", 123)).toHaveProperty("message", "Object.test(): Message (received 123)");
expect(new BlorkError("Message", 123)).toHaveProperty("message", "test(): Message (received 123)");
expect(new BlorkError("Message", 123)).toHaveProperty("value", 123);
});
});
17 changes: 13 additions & 4 deletions test/helpers/destack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ describe("destack()", () => {
const stack2 = [
"Error",
" at abc (<anonymous>:1:30)",
" at def (<anonymous>:1:18)",
" at Object.def (<anonymous>:1:18)",
" at GHI.ghi (<anonymous>:2:9)",
" at <anonymous>:1:3",
" at <anonymous>:1",
" at <anonymous>"
];
expect(destack(stack2.join("\n"))).toEqual([
{ function: "abc()", file: "", line: 1, column: 30, original: " at abc (<anonymous>:1:30)" },
{ function: "def()", file: "", line: 1, column: 18, original: " at def (<anonymous>:1:18)" },
{ function: "def()", file: "", line: 1, column: 18, original: " at Object.def (<anonymous>:1:18)" },
{ function: "GHI.ghi()", file: "", line: 2, column: 9, original: " at GHI.ghi (<anonymous>:2:9)" },
{ function: "", file: "", line: 1, column: 3, original: " at <anonymous>:1:3" },
{ function: "", file: "", line: 1, column: null, original: " at <anonymous>:1" },
Expand All @@ -74,14 +74,14 @@ describe("destack()", () => {
];
expect(destack(stack3.join("\n"))).toEqual([
{
function: "Object.test()",
function: "test()",
file: "/blork/test/functions/destack.test.js",
line: 21,
column: 15,
original: " at Object.test (/blork/test/functions/destack.test.js:21:15)"
},
{
function: "Object.asyncFn()",
function: "asyncFn()",
file: "/jest-jasmine2/build/jasmine_async.js",
line: 129,
column: 432,
Expand Down Expand Up @@ -154,6 +154,15 @@ describe("destack()", () => {
original: "a@file:///C:/example.html:19"
}
]);
expect(destack("Object.a@file:///C:/example.html:19")).toEqual([
{
function: "a()",
file: "file:///C:/example.html",
line: 19,
column: null,
original: "Object.a@file:///C:/example.html:19"
}
]);
expect(destack("@debugger eval code:21:9")).toEqual([
{ function: "", file: "", line: 21, column: 9, original: "@debugger eval code:21:9" }
]);
Expand Down

0 comments on commit 55de4f1

Please sign in to comment.