mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-21 22:54:11 +08:00
fix(deprecate-utils): Add location where deprecation warning was issued
- Resolves #1599
This commit is contained in:
parent
c6acca8ca3
commit
801325bb38
1 changed files with 12 additions and 1 deletions
|
@ -1,6 +1,16 @@
|
||||||
_ = require 'underscore'
|
_ = require 'underscore'
|
||||||
|
|
||||||
class DeprecateUtils
|
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) ->
|
@warn: (condition, message) ->
|
||||||
console.warn message if condition
|
console.warn message if condition
|
||||||
|
|
||||||
|
@ -8,10 +18,11 @@ class DeprecateUtils
|
||||||
if NylasEnv.inDevMode() and not NylasEnv.inSpecMode()
|
if NylasEnv.inDevMode() and not NylasEnv.inSpecMode()
|
||||||
warn = true
|
warn = true
|
||||||
newFn = =>
|
newFn = =>
|
||||||
|
stack = DeprecateUtils.parseStack((new Error()).stack)
|
||||||
DeprecateUtils.warn(
|
DeprecateUtils.warn(
|
||||||
warn,
|
warn,
|
||||||
"Deprecation warning! #{fnName} is deprecated and will be removed soon.
|
"Deprecation warning! #{fnName} is deprecated and will be removed soon.
|
||||||
Use #{newName} instead."
|
Use #{newName} instead.\nCheck your code at #{stack[1]}"
|
||||||
)
|
)
|
||||||
warn = false
|
warn = false
|
||||||
return fn.apply(ctx, arguments)
|
return fn.apply(ctx, arguments)
|
||||||
|
|
Loading…
Reference in a new issue