]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/node_modules/grim/lib/deprecation.js
2 var Deprecation
, SourceMapCache
;
6 module
.exports
= Deprecation
= (function() {
7 Deprecation
.getFunctionNameFromCallsite = function(callsite
) {};
9 Deprecation
.deserialize = function(_arg
) {
10 var deprecation
, fileName
, lineNumber
, message
, stack
, stacks
, _i
, _len
;
11 message
= _arg
.message
, fileName
= _arg
.fileName
, lineNumber
= _arg
.lineNumber
, stacks
= _arg
.stacks
;
12 deprecation
= new Deprecation(message
, fileName
, lineNumber
);
13 for (_i
= 0, _len
= stacks
.length
; _i
< _len
; _i
++) {
15 deprecation
.addStack(stack
, stack
.metadata
);
20 function Deprecation(message
, fileName
, lineNumber
) {
21 this.message
= message
;
22 this.fileName
= fileName
;
23 this.lineNumber
= lineNumber
;
27 this.stackCallCounts
= {};
30 Deprecation
.prototype.getFunctionNameFromCallsite = function(callsite
) {
31 var _ref
, _ref1
, _ref2
;
32 if (callsite
.functionName
!= null) {
33 return callsite
.functionName
;
35 if (callsite
.isToplevel()) {
36 return (_ref
= callsite
.getFunctionName()) != null ? _ref : '<unknown>';
38 if (callsite
.isConstructor()) {
39 return "new " + (callsite
.getFunctionName());
40 } else if (callsite
.getMethodName() && !callsite
.getFunctionName()) {
41 return callsite
.getMethodName();
43 return "" + (callsite
.getTypeName()) + "." + ((_ref1
= (_ref2
= callsite
.getMethodName()) != null ? _ref2 : callsite
.getFunctionName()) != null ? _ref1 : '<anonymous>');
48 Deprecation
.prototype.getLocationFromCallsite = function(callsite
) {
49 var column
, fileName
, line
;
50 if (callsite
.location
!= null) {
51 return callsite
.location
;
53 if (callsite
.isNative()) {
55 } else if (callsite
.isEval()) {
56 return "eval at " + (this.getLocationFromCallsite(callsite
.getEvalOrigin()));
58 fileName
= callsite
.getFileName();
59 line
= callsite
.getLineNumber();
60 column
= callsite
.getColumnNumber();
61 return "" + fileName
+ ":" + line
+ ":" + column
;
65 Deprecation
.prototype.getFileNameFromCallSite = function(callsite
) {
67 return (_ref
= callsite
.fileName
) != null ? _ref : callsite
.getFileName();
70 Deprecation
.prototype.getOriginName = function() {
71 return this.originName
;
74 Deprecation
.prototype.getMessage = function() {
78 Deprecation
.prototype.getStacks = function() {
79 var location
, parsedStack
, parsedStacks
, stack
, _ref
;
82 for (location
in _ref
) {
83 stack
= _ref
[location
];
84 parsedStack
= this.parseStack(stack
);
85 parsedStack
.callCount
= this.stackCallCounts
[location
];
86 parsedStack
.metadata
= stack
.metadata
;
87 parsedStacks
.push(parsedStack
);
92 Deprecation
.prototype.getStackCount = function() {
93 return this.stackCount
;
96 Deprecation
.prototype.getCallCount = function() {
97 return this.callCount
;
100 Deprecation
.prototype.addStack = function(stack
, metadata
) {
101 var callerLocation
, _base
, _base1
;
102 if (this.originName
== null) {
103 this.originName
= this.getFunctionNameFromCallsite(stack
[0]);
105 if (this.fileName
== null) {
106 this.fileName
= this.getFileNameFromCallSite(stack
[0]);
108 if (this.lineNumber
== null) {
109 this.lineNumber
= typeof (_base
= stack
[0]).getLineNumber
=== "function" ? _base
.getLineNumber() : void 0;
112 stack
.metadata
= metadata
;
113 callerLocation
= this.getLocationFromCallsite(stack
[1]);
114 if (this.stacks
[callerLocation
] == null) {
115 this.stacks
[callerLocation
] = stack
;
118 if ((_base1
= this.stackCallCounts
)[callerLocation
] == null) {
119 _base1
[callerLocation
] = 0;
121 return this.stackCallCounts
[callerLocation
]++;
124 Deprecation
.prototype.parseStack = function(stack
) {
125 return stack
.map((function(_this
) {
126 return function(callsite
) {
128 functionName: _this
.getFunctionNameFromCallsite(callsite
),
129 location: _this
.getLocationFromCallsite(callsite
),
130 fileName: _this
.getFileNameFromCallSite(callsite
)
136 Deprecation
.prototype.serialize = function() {
138 message: this.getMessage(),
139 lineNumber: this.lineNumber
,
140 fileName: this.fileName
,
141 stacks: this.getStacks()