4 _
= require('underscore-plus');
6 module
.exports
= Deprecation
= (function() {
7 Deprecation
.generateStack = function() {
8 var error
, originalPrepareStackTrace
, stack
;
9 originalPrepareStackTrace
= Error
.prepareStackTrace
;
10 Error
.prepareStackTrace = function(error
, stack
) {
14 Error
.captureStackTrace(error
);
15 stack
= error
.stack
.slice(1);
16 Error
.prepareStackTrace
= originalPrepareStackTrace
;
20 Deprecation
.getFunctionNameFromCallsite = function(callsite
) {
21 var _ref
, _ref1
, _ref2
;
22 if (callsite
.isToplevel()) {
23 return (_ref
= callsite
.getFunctionName()) != null ? _ref : '<unknown>';
25 if (callsite
.isConstructor()) {
26 return "new " + (callsite
.getFunctionName());
27 } else if (callsite
.getMethodName() && !callsite
.getFunctionName()) {
28 return callsite
.getMethodName();
30 return "" + (callsite
.getTypeName()) + "." + ((_ref1
= (_ref2
= callsite
.getMethodName()) != null ? _ref2 : callsite
.getFunctionName()) != null ? _ref1 : '<anonymous>');
35 function Deprecation(message
) {
36 this.message
= message
;
41 Deprecation
.prototype.getFunctionNameFromCallsite = function(callsite
) {
42 return Deprecation
.getFunctionNameFromCallsite(callsite
);
45 Deprecation
.prototype.getLocationFromCallsite = function(callsite
) {
46 if (callsite
.isNative()) {
48 } else if (callsite
.isEval()) {
49 return "eval at " + (this.getLocationFromCallsite(callsite
.getEvalOrigin()));
51 return "" + (callsite
.getFileName()) + ":" + (callsite
.getLineNumber()) + ":" + (callsite
.getColumnNumber());
55 Deprecation
.prototype.getOriginName = function() {
56 return this.originName
;
59 Deprecation
.prototype.getMessage = function() {
63 Deprecation
.prototype.getStacks = function() {
64 return _
.clone(this.stacks
);
67 Deprecation
.prototype.getCallCount = function() {
68 return this.callCount
;
71 Deprecation
.prototype.addStack = function(stack
) {
73 if (this.originName
== null) {
74 this.originName
= this.getFunctionNameFromCallsite(stack
[0]);
76 stack
= this.parseStack(stack
);
77 if (existingStack
= this.isStackUnique(stack
)) {
78 existingStack
.callCount
++;
80 this.stacks
.push(stack
);
82 return this.callCount
++;
85 Deprecation
.prototype.parseStack = function(stack
) {
86 stack
= stack
.map((function(_this
) {
87 return function(callsite
) {
89 functionName: _this
.getFunctionNameFromCallsite(callsite
),
90 location: _this
.getLocationFromCallsite(callsite
),
91 fileName: callsite
.getFileName()
99 Deprecation
.prototype.isStackUnique = function(stack
) {
101 stacks
= this.stacks
.filter(function(s
) {
102 var callsite
, functionName
, i
, location
, _i
, _len
, _ref
;
103 if (s
.length
!== stack
.length
) {
106 for (i
= _i
= 0, _len
= s
.length
; _i
< _len
; i
= ++_i
) {
107 _ref
= s
[i
], functionName
= _ref
.functionName
, location
= _ref
.location
;
109 if (!(functionName
=== callsite
.functionName
&& location
=== callsite
.location
)) {