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