Skip to content

Commit a026e20

Browse files
committed
refactor(index.js): remove custom function name
1 parent 845419d commit a026e20

File tree

3 files changed

+6
-24
lines changed

3 files changed

+6
-24
lines changed

index.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ var Promise = require('native-or-bluebird')
1414
var multiline = require('multiline')
1515
var fmt = require('util').format
1616

17-
module.exports = function (name, $$__fn__$$) {
18-
if (typeof name === 'function') {
19-
$$__fn__$$ = name
20-
name = $$__fn__$$.name || 'anonymous'
21-
}
22-
17+
module.exports = function ($$__fn__$$) {
2318
var fnstr = fmt(multiline.stripIndent(function () {;/*
2419
(function %s() {
2520
var self = this
@@ -38,7 +33,7 @@ module.exports = function (name, $$__fn__$$) {
3833
$$__fn__$$.apply(self, args)
3934
})
4035
})
41-
*/}), name)
36+
*/}), $$__fn__$$.name)
4237

4338
return eval(fnstr)
4439
}

test/all.test.js

-9
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,4 @@ describe('callback-and-promise/all', function () {
4646
assert(stat.size, fs.statSync(__filename).size)
4747
})
4848
})
49-
50-
it('promisifyAll with reserved words', function () {
51-
var module = {
52-
delete: function () {}
53-
}
54-
module = thenify(module)
55-
assert(typeof module.delete === 'function')
56-
assert(module.delete.name === 'anonymous')
57-
})
5849
})

test/index.test.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ describe('callback-and-promise', function () {
77
describe('fn.name', function () {
88
function someCrazyName() {}
99

10-
it('should set name correct', function () {
11-
assert.equal('someCrazyName', promisify('someCrazyName', someCrazyName).name)
12-
})
13-
1410
it('should set function name by default', function () {
1511
assert.equal('someCrazyName', promisify(someCrazyName).name)
1612
})
1713

18-
it('should set name to anonymous', function () {
19-
assert.equal('anonymous', promisify(function() {}).name)
14+
it('should set name to empty', function () {
15+
assert.equal('', promisify(function() {}).name)
2016
})
2117
})
2218

@@ -28,15 +24,15 @@ describe('callback-and-promise', function () {
2824
}
2925

3026
it('promise', function () {
31-
return promisify('blah', fn)().then(function () {
27+
return promisify(fn)().then(function () {
3228
throw new Error('bang')
3329
}).catch(function (err) {
3430
assert.equal(err.message, 'boom')
3531
})
3632
})
3733

3834
it('callback', function (done) {
39-
promisify('blah', fn)(function (err) {
35+
promisify(fn)(function (err) {
4036
assert.equal(err.message, 'boom')
4137
done()
4238
})

0 commit comments

Comments
 (0)