fix(deprecate-utils): Add location where deprecation warning was issued

- Resolves #1599
This commit is contained in:
Juan Tejada 2016-03-09 11:29:47 -08:00
parent c6acca8ca3
commit 801325bb38

View file

@ -1,6 +1,16 @@
_ = require 'underscore'
class DeprecateUtils
# See
# http://www.codeovertones.com/2011/08/how-to-print-stack-trace-anywhere-in.html
@parseStack: (stackString) ->
stack = stackString
.replace(/^[^\(]+?[\n$]/gm, '')
.replace(/^\s+at\s+/gm, '')
.replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@')
.split('\n')
return stack
@warn: (condition, message) ->
console.warn message if condition
@ -8,10 +18,11 @@ class DeprecateUtils
if NylasEnv.inDevMode() and not NylasEnv.inSpecMode()
warn = true
newFn = =>
stack = DeprecateUtils.parseStack((new Error()).stack)
DeprecateUtils.warn(
warn,
"Deprecation warning! #{fnName} is deprecated and will be removed soon.
Use #{newName} instead."
Use #{newName} instead.\nCheck your code at #{stack[1]}"
)
warn = false
return fn.apply(ctx, arguments)