]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/grim/lib/deprecation.js
8faa7ab295aae9089665c323102b944d00538b60
[rbdr/dotfiles] / atom / packages / ex-mode / node_modules / space-pen / node_modules / grim / lib / deprecation.js
1 (function() {
2 var Deprecation, SourceMapCache, convertLine;
3
4 convertLine = require('coffeestack').convertLine;
5
6 SourceMapCache = {};
7
8 module.exports = Deprecation = (function() {
9 Deprecation.getFunctionNameFromCallsite = function(callsite) {};
10
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++) {
16 stack = stacks[_i];
17 deprecation.addStack(stack, stack.metadata);
18 }
19 return deprecation;
20 };
21
22 function Deprecation(message, fileName, lineNumber) {
23 this.message = message;
24 this.fileName = fileName;
25 this.lineNumber = lineNumber;
26 this.callCount = 0;
27 this.stackCount = 0;
28 this.stacks = {};
29 this.stackCallCounts = {};
30 }
31
32 Deprecation.prototype.getFunctionNameFromCallsite = function(callsite) {
33 var _ref, _ref1, _ref2;
34 if (callsite.functionName != null) {
35 return callsite.functionName;
36 }
37 if (callsite.isToplevel()) {
38 return (_ref = callsite.getFunctionName()) != null ? _ref : '<unknown>';
39 } else {
40 if (callsite.isConstructor()) {
41 return "new " + (callsite.getFunctionName());
42 } else if (callsite.getMethodName() && !callsite.getFunctionName()) {
43 return callsite.getMethodName();
44 } else {
45 return "" + (callsite.getTypeName()) + "." + ((_ref1 = (_ref2 = callsite.getMethodName()) != null ? _ref2 : callsite.getFunctionName()) != null ? _ref1 : '<anonymous>');
46 }
47 }
48 };
49
50 Deprecation.prototype.getLocationFromCallsite = function(callsite) {
51 var column, converted, fileName, line;
52 if (callsite.location != null) {
53 return callsite.location;
54 }
55 if (callsite.isNative()) {
56 return "native";
57 } else if (callsite.isEval()) {
58 return "eval at " + (this.getLocationFromCallsite(callsite.getEvalOrigin()));
59 } else {
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;
66 }
67 }
68 return "" + fileName + ":" + line + ":" + column;
69 }
70 };
71
72 Deprecation.prototype.getFileNameFromCallSite = function(callsite) {
73 var _ref;
74 return (_ref = callsite.fileName) != null ? _ref : callsite.getFileName();
75 };
76
77 Deprecation.prototype.getOriginName = function() {
78 return this.originName;
79 };
80
81 Deprecation.prototype.getMessage = function() {
82 return this.message;
83 };
84
85 Deprecation.prototype.getStacks = function() {
86 var location, parsedStack, parsedStacks, stack, _ref;
87 parsedStacks = [];
88 _ref = this.stacks;
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);
95 }
96 return parsedStacks;
97 };
98
99 Deprecation.prototype.getStackCount = function() {
100 return this.stackCount;
101 };
102
103 Deprecation.prototype.getCallCount = function() {
104 return this.callCount;
105 };
106
107 Deprecation.prototype.addStack = function(stack, metadata) {
108 var callerLocation, _base, _base1;
109 if (this.originName == null) {
110 this.originName = this.getFunctionNameFromCallsite(stack[0]);
111 }
112 if (this.fileName == null) {
113 this.fileName = this.getFileNameFromCallSite(stack[0]);
114 }
115 if (this.lineNumber == null) {
116 this.lineNumber = typeof (_base = stack[0]).getLineNumber === "function" ? _base.getLineNumber() : void 0;
117 }
118 this.callCount++;
119 stack.metadata = metadata;
120 callerLocation = this.getLocationFromCallsite(stack[1]);
121 if (this.stacks[callerLocation] == null) {
122 this.stacks[callerLocation] = stack;
123 this.stackCount++;
124 }
125 if ((_base1 = this.stackCallCounts)[callerLocation] == null) {
126 _base1[callerLocation] = 0;
127 }
128 return this.stackCallCounts[callerLocation]++;
129 };
130
131 Deprecation.prototype.parseStack = function(stack) {
132 return stack.map((function(_this) {
133 return function(callsite) {
134 return {
135 functionName: _this.getFunctionNameFromCallsite(callsite),
136 location: _this.getLocationFromCallsite(callsite),
137 fileName: _this.getFileNameFromCallSite(callsite)
138 };
139 };
140 })(this));
141 };
142
143 Deprecation.prototype.serialize = function() {
144 return {
145 message: this.getMessage(),
146 lineNumber: this.lineNumber,
147 fileName: this.fileName,
148 stacks: this.getStacks()
149 };
150 };
151
152 return Deprecation;
153
154 })();
155
156 }).call(this);