Skip to content

Commit 53d2ac5

Browse files
committed
Correct call site for wrapped functions and properties
1 parent b7de7bc commit 53d2ac5

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

History.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
unreleased
2+
==========
3+
4+
* Correct call site for wrapped functions and properties
5+
16
0.4.1 / 2014-07-19
27
==================
38

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ function log(message, site) {
183183
}
184184

185185
var caller
186+
var callFile
186187
var callSite
187188
var i = 0
188189
var seen = false
@@ -204,9 +205,12 @@ function log(message, site) {
204205
// get caller of deprecated thing in relation to file
205206
for (; i < stack.length; i++) {
206207
caller = callSiteLocation(stack[i])
208+
callFile = caller[0]
207209

208-
if (caller[0] === file) {
210+
if (callFile === file) {
209211
seen = true
212+
} else if (callFile === this._file) {
213+
file = this._file
210214
} else if (seen) {
211215
break
212216
}

test/fixtures/my-lib.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ exports.fnprop.propautomsg = 'thingie'
6666
deprecate.property(exports.fnprop, 'propa', 'fn propa gone')
6767
deprecate.property(exports.fnprop, 'propautomsg')
6868

69+
exports.layerfn = function () {
70+
exports.oldfn()
71+
}
72+
73+
exports.layerprop = function () {
74+
exports.propa
75+
}
76+
6977
function fn(a1, a2) {
7078
return a2
7179
}

test/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ describe('deprecate.function(fn, message)', function () {
222222
ret.should.equal(2)
223223
})
224224

225+
it('should show call site outside scope', function () {
226+
function callold() { mylib.layerfn() }
227+
var stderr = captureStderr(callold)
228+
stderr.should.containEql(' oldfn ')
229+
stderr.should.match(/test.js:[0-9]+:[0-9]+/)
230+
})
231+
225232
it('should only warn once per call site', function () {
226233
function callold() {
227234
for (var i = 0; i < 5; i++) {
@@ -330,6 +337,13 @@ describe('deprecate.property(obj, prop, message)', function () {
330337
stderr.split(fileline[0]).should.have.length(3)
331338
})
332339

340+
it('should show call site outside scope', function () {
341+
function callold() { mylib.layerprop() }
342+
var stderr = captureStderr(callold)
343+
stderr.should.containEql(' propa ')
344+
stderr.should.match(/test.js:[0-9]+:[0-9]+/)
345+
})
346+
333347
describe('when obj is a function', function () {
334348
it('should log on access to property on function', function () {
335349
function callprop() { mylib.fnprop.propa }

0 commit comments

Comments
 (0)