]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/grim/lib/deprecation.js
8faa7ab295aae9089665c323102b944d00538b60
2 var Deprecation
, SourceMapCache
, convertLine
;
4 convertLine
= require('coffeestack').convertLine
;
8 module
.exports
= Deprecation
= (function() {
9 Deprecation
.getFunctionNameFromCallsite = function(callsite
) {};
11 Deprecation
.deserialize = function(_arg
) {
12 var deprecation
, fileName
, lineNumber
, message
, stack
, stacks
, _i
, _len
;
13 message
= _arg
.message
, fileName
= _arg
.fileName
, lineNumber
= _arg
.lineNumber
, stacks
= _arg
.stacks
;
14 deprecation
= new Deprecation(message
, fileName
, lineNumber
);
15 for (_i
= 0, _len
= stacks
.length
; _i
< _len
; _i
++) {
17 deprecation
.addStack(stack
, stack
.metadata
);
22 function Deprecation(message
, fileName
, lineNumber
) {
23 this.message
= message
;
24 this.fileName
= fileName
;
25 this.lineNumber
= lineNumber
;
29 this.stackCallCounts
= {};
32 Deprecation
.prototype.getFunctionNameFromCallsite = function(callsite
) {
33 var _ref
, _ref1
, _ref2
;
34 if (callsite
.functionName
!= null) {
35 return callsite
.functionName
;
37 if (callsite
.isToplevel()) {
38 return (_ref
= callsite
.getFunctionName()) != null ? _ref : '<unknown>';
40 if (callsite
.isConstructor()) {
41 return "new " + (callsite
.getFunctionName());
42 } else if (callsite
.getMethodName() && !callsite
.getFunctionName()) {
43 return callsite
.getMethodName();
45 return "" + (callsite
.getTypeName()) + "." + ((_ref1
= (_ref2
= callsite
.getMethodName()) != null ? _ref2 : callsite
.getFunctionName()) != null ? _ref1 : '<anonymous>');
50 Deprecation
.prototype.getLocationFromCallsite = function(callsite
) {
51 var column
, converted
, fileName
, line
;
52 if (callsite
.location
!= null) {
53 return callsite
.location
;
55 if (callsite
.isNative()) {
57 } else if (callsite
.isEval()) {
58 return "eval at " + (this.getLocationFromCallsite(callsite
.getEvalOrigin()));
60 fileName
= callsite
.getFileName();
61 line
= callsite
.getLineNumber();
62 column
= callsite
.getColumnNumber();
63 if (/\.coffee$/.test(fileName
)) {
64 if (converted
= convertLine(fileName
, line
, column
, SourceMapCache
)) {
65 line
= converted
.line
, column
= converted
.column
;
68 return "" + fileName
+ ":" + line
+ ":" + column
;
72 Deprecation
.prototype.getFileNameFromCallSite = function(callsite
) {
74 return (_ref
= callsite
.fileName
) != null ? _ref : callsite
.getFileName();
77 Deprecation
.prototype.getOriginName = function() {
78 return this.originName
;
81 Deprecation
.prototype.getMessage = function() {
85 Deprecation
.prototype.getStacks = function() {
86 var location
, parsedStack
, parsedStacks
, stack
, _ref
;
89 for (location
in _ref
) {
90 stack
= _ref
[location
];
91 parsedStack
= this.parseStack(stack
);
92 parsedStack
.callCount
= this.stackCallCounts
[location
];
93 parsedStack
.metadata
= stack
.metadata
;
94 parsedStacks
.push(parsedStack
);
99 Deprecation
.prototype.getStackCount = function() {
100 return this.stackCount
;
103 Deprecation
.prototype.getCallCount = function() {
104 return this.callCount
;
107 Deprecation
.prototype.addStack = function(stack
, metadata
) {
108 var callerLocation
, _base
, _base1
;
109 if (this.originName
== null) {
110 this.originName
= this.getFunctionNameFromCallsite(stack
[0]);
112 if (this.fileName
== null) {
113 this.fileName
= this.getFileNameFromCallSite(stack
[0]);
115 if (this.lineNumber
== null) {
116 this.lineNumber
= typeof (_base
= stack
[0]).getLineNumber
=== "function" ? _base
.getLineNumber() : void 0;
119 stack
.metadata
= metadata
;
120 callerLocation
= this.getLocationFromCallsite(stack
[1]);
121 if (this.stacks
[callerLocation
] == null) {
122 this.stacks
[callerLocation
] = stack
;
125 if ((_base1
= this.stackCallCounts
)[callerLocation
] == null) {
126 _base1
[callerLocation
] = 0;
128 return this.stackCallCounts
[callerLocation
]++;
131 Deprecation
.prototype.parseStack = function(stack
) {
132 return stack
.map((function(_this
) {
133 return function(callsite
) {
135 functionName: _this
.getFunctionNameFromCallsite(callsite
),
136 location: _this
.getLocationFromCallsite(callsite
),
137 fileName: _this
.getFileNameFromCallSite(callsite
)
143 Deprecation
.prototype.serialize = function() {
145 message: this.getMessage(),
146 lineNumber: this.lineNumber
,
147 fileName: this.fileName
,
148 stacks: this.getStacks()