]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/node_modules/grim/lib/grim.js
Fixes submodule names for paths
[rbdr/dotfiles] / atom / packages / vim-mode / node_modules / grim / lib / grim.js
1 (function() {
2 var Deprecation, Emitter, grim;
3
4 Emitter = require('emissary').Emitter;
5
6 Deprecation = require('./deprecation');
7
8 if (global.__grim__ == null) {
9 grim = global.__grim__ = {
10 deprecations: {},
11 includeDeprecatedAPIs: true,
12 getDeprecations: function() {
13 var deprecation, deprecations, deprecationsByLineNumber, deprecationsByPackage, fileName, lineNumber, packageName, _ref;
14 deprecations = [];
15 _ref = grim.deprecations;
16 for (fileName in _ref) {
17 deprecationsByLineNumber = _ref[fileName];
18 for (lineNumber in deprecationsByLineNumber) {
19 deprecationsByPackage = deprecationsByLineNumber[lineNumber];
20 for (packageName in deprecationsByPackage) {
21 deprecation = deprecationsByPackage[packageName];
22 deprecations.push(deprecation);
23 }
24 }
25 }
26 return deprecations;
27 },
28 getDeprecationsLength: function() {
29 return this.getDeprecations().length;
30 },
31 clearDeprecations: function() {
32 grim.deprecations = {};
33 },
34 logDeprecations: function() {
35 var deprecation, deprecations, _i, _len;
36 deprecations = this.getDeprecations();
37 deprecations.sort(function(a, b) {
38 return b.getCallCount() - a.getCallCount();
39 });
40 console.warn("\nCalls to deprecated functions\n-----------------------------");
41 for (_i = 0, _len = deprecations.length; _i < _len; _i++) {
42 deprecation = deprecations[_i];
43 console.warn("(" + (deprecation.getCallCount()) + ") " + (deprecation.getOriginName()) + " : " + (deprecation.getMessage()), deprecation);
44 }
45 },
46 deprecate: function(message, metadata) {
47 var deprecation, deprecationSite, error, fileName, lineNumber, originalPrepareStackTrace, originalStackTraceLimit, packageName, stack, _base, _base1, _base2, _ref;
48 originalStackTraceLimit = Error.stackTraceLimit;
49 Error.stackTraceLimit = 7;
50 error = new Error;
51 Error.captureStackTrace(error);
52 Error.stackTraceLimit = originalStackTraceLimit;
53 originalPrepareStackTrace = Error.prepareStackTrace;
54 Error.prepareStackTrace = function(error, stack) {
55 return stack;
56 };
57 stack = error.stack.slice(1);
58 Error.prepareStackTrace = originalPrepareStackTrace;
59 deprecationSite = stack[0];
60 fileName = deprecationSite.getFileName();
61 lineNumber = deprecationSite.getLineNumber();
62 packageName = (_ref = metadata != null ? metadata.packageName : void 0) != null ? _ref : "";
63 if ((_base = grim.deprecations)[fileName] == null) {
64 _base[fileName] = {};
65 }
66 if ((_base1 = grim.deprecations[fileName])[lineNumber] == null) {
67 _base1[lineNumber] = {};
68 }
69 if ((_base2 = grim.deprecations[fileName][lineNumber])[packageName] == null) {
70 _base2[packageName] = new Deprecation(message);
71 }
72 deprecation = grim.deprecations[fileName][lineNumber][packageName];
73 deprecation.addStack(stack, metadata);
74 grim.emit("updated", deprecation);
75 },
76 addSerializedDeprecation: function(serializedDeprecation) {
77 var deprecation, fileName, lineNumber, message, packageName, stack, stacks, _base, _base1, _base2, _i, _len, _ref, _ref1, _ref2;
78 deprecation = Deprecation.deserialize(serializedDeprecation);
79 message = deprecation.getMessage();
80 fileName = deprecation.fileName, lineNumber = deprecation.lineNumber;
81 stacks = deprecation.getStacks();
82 packageName = (_ref = (_ref1 = stacks[0]) != null ? (_ref2 = _ref1.metadata) != null ? _ref2.packageName : void 0 : void 0) != null ? _ref : "";
83 if ((_base = grim.deprecations)[fileName] == null) {
84 _base[fileName] = {};
85 }
86 if ((_base1 = grim.deprecations[fileName])[lineNumber] == null) {
87 _base1[lineNumber] = {};
88 }
89 if ((_base2 = grim.deprecations[fileName][lineNumber])[packageName] == null) {
90 _base2[packageName] = new Deprecation(message, fileName, lineNumber);
91 }
92 deprecation = grim.deprecations[fileName][lineNumber][packageName];
93 for (_i = 0, _len = stacks.length; _i < _len; _i++) {
94 stack = stacks[_i];
95 deprecation.addStack(stack, stack.metadata);
96 }
97 grim.emit("updated", deprecation);
98 }
99 };
100 Emitter.extend(grim);
101 }
102
103 module.exports = global.__grim__;
104
105 }).call(this);