Skip to content

Commit

Permalink
Fixes #385 (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
remojansen committed Oct 9, 2016
1 parent 115ebfe commit 36ffbb5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "inversify",
"version": "2.0.0",
"version": "2.0.1",
"description": "A powerful and lightweight inversion of control container for JavaScript and Node.js apps powered by TypeScript.",
"main": "lib/inversify.js",
"jsnext:main": "es/inversify.js",
Expand Down
8 changes: 7 additions & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export function getFunctionName(v: any): string {
return v.name ? v.name : v.toString().match(/^function\s*([^\s(]+)/)[1];
if (v.name) {
return v.name;
} else {
let name = v.toString();
let match = name.match(/^function\s*([^\s(]+)/);
return match ? match[1] : `Anonymous function: ${name}`;
}
}
13 changes: 13 additions & 0 deletions test/bugs/bugs.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from "chai";
import * as ERROR_MSGS from "../../src/constants/error_msgs";
import { getFunctionName } from "../../src/utils/utils";

import {
Kernel,
Expand Down Expand Up @@ -276,4 +277,16 @@ describe("Bugs", () => {

});

it("Helper getFunctionName should not throw when using an anonymous function", () => {

let name = getFunctionName(function (options: any) {
this.configure(options);
});

expect(name).to.eql("Anonymous function: " + (function (options: any) {
this.configure(options);
}).toString());

});

});

0 comments on commit 36ffbb5

Please sign in to comment.