| OLD | NEW |
| (Empty) | |
| 1 (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.e
xports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var
g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined")
{g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Stacky = f()}}
)(function(){var define,module,exports;return (function e(t,n,r){function s(o,u)
{if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a
(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f
.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,functi
on(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports
}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);re
turn s})({1:[function(require,module,exports){ |
| 2 /** |
| 3 * @license |
| 4 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
| 5 * |
| 6 * This code may only be used under the BSD style license found at polymer.githu
b.io/LICENSE.txt |
| 7 * The complete set of authors may be found at polymer.github.io/AUTHORS.txt |
| 8 * The complete set of contributors may be found at polymer.github.io/CONTRIBUTO
RS.txt |
| 9 * Code distributed by Google as part of the polymer project is also subject to |
| 10 * an additional IP rights grant found at polymer.github.io/PATENTS.txt |
| 11 */ |
| 12 (function(scope) { |
| 13 'use strict'; |
| 14 |
| 15 var parse = scope.parse || require('./parsing').parse; |
| 16 |
| 17 scope.defaults = { |
| 18 // Methods are aligned up to this much padding. |
| 19 maxMethodPadding: 40, |
| 20 // A string to prefix each line with. |
| 21 indent: '', |
| 22 // A string to show for stack lines that are missing a method. |
| 23 methodPlaceholder: '<unknown>', |
| 24 // A list of Strings/RegExps that will be stripped from `location` values on |
| 25 // each line (via `String#replace`). |
| 26 locationStrip: [], |
| 27 // A list of Strings/RegExps that indicate that a line is *not* important, and |
| 28 // should be styled as such. |
| 29 unimportantLocation: [], |
| 30 // A filter function to completely remove lines |
| 31 filter: function() { return false; }, |
| 32 // styles are functions that take a string and return that string when styled. |
| 33 styles: { |
| 34 method: passthrough, |
| 35 location: passthrough, |
| 36 line: passthrough, |
| 37 column: passthrough, |
| 38 unimportant: passthrough, |
| 39 }, |
| 40 }; |
| 41 |
| 42 // See Tero Tolonen's answer at |
| 43 // http://stackoverflow.com/questions/17575790/environment-detection-node-js-or-
browser |
| 44 /*jshint -W054 */ |
| 45 var isNode = new Function('try {return this===global;}catch(e){return false;}'); |
| 46 |
| 47 // For Stacky-in-Node, we default to colored stacks. |
| 48 if (isNode()) { |
| 49 var chalk = require('chalk'); |
| 50 |
| 51 scope.defaults.styles = { |
| 52 method: chalk.magenta, |
| 53 location: chalk.blue, |
| 54 line: chalk.cyan, |
| 55 column: chalk.cyan, |
| 56 unimportant: chalk.dim |
| 57 }; |
| 58 } |
| 59 |
| 60 |
| 61 function pretty(stackOrParsed, options) { |
| 62 options = mergeDefaults(options || {}, scope.defaults); |
| 63 var lines = Array.isArray(stackOrParsed) ? stackOrParsed : parse(stackOrParsed
); |
| 64 lines = clean(lines, options); |
| 65 |
| 66 var padSize = methodPadding(lines, options); |
| 67 var parts = lines.map(function(line) { |
| 68 var method = line.method || options.methodPlaceholder; |
| 69 var pad = options.indent + padding(padSize - method.length); |
| 70 |
| 71 var locationBits = [ |
| 72 options.styles.location(line.location), |
| 73 options.styles.line(line.line), |
| 74 ]; |
| 75 if ('column' in line) { |
| 76 locationBits.push(options.styles.column(line.column)); |
| 77 } |
| 78 var location = locationBits.join(':'); |
| 79 |
| 80 var text = pad + options.styles.method(method) + ' at ' + location; |
| 81 if (!line.important) { |
| 82 text = options.styles.unimportant(text); |
| 83 } |
| 84 return text; |
| 85 }); |
| 86 |
| 87 return parts.join('\n'); |
| 88 } |
| 89 |
| 90 function clean(lines, options) { |
| 91 var result = []; |
| 92 for (var i = 0, line; line = lines[i]; i++) { |
| 93 if (options.filter(line)) continue; |
| 94 line.location = cleanLocation(line.location, options); |
| 95 line.important = isImportant(line, options); |
| 96 result.push(line); |
| 97 } |
| 98 |
| 99 return result; |
| 100 } |
| 101 |
| 102 // Utility |
| 103 |
| 104 function passthrough(string) { |
| 105 return string; |
| 106 } |
| 107 |
| 108 function mergeDefaults(options, defaults) { |
| 109 var result = Object.create(defaults); |
| 110 Object.keys(options).forEach(function(key) { |
| 111 var value = options[key]; |
| 112 if (typeof value === 'object' && !Array.isArray(value)) { |
| 113 value = mergeDefaults(value, defaults[key]); |
| 114 } |
| 115 result[key] = value; |
| 116 }); |
| 117 return result; |
| 118 } |
| 119 |
| 120 function methodPadding(lines, options) { |
| 121 var size = options.methodPlaceholder.length; |
| 122 for (var i = 0, line; line = lines[i]; i++) { |
| 123 size = Math.min(options.maxMethodPadding, Math.max(size, line.method.length)
); |
| 124 } |
| 125 return size; |
| 126 } |
| 127 |
| 128 function padding(length) { |
| 129 var result = ''; |
| 130 for (var i = 0; i < length; i++) { |
| 131 result = result + ' '; |
| 132 } |
| 133 return result; |
| 134 } |
| 135 |
| 136 function cleanLocation(location, options) { |
| 137 if (options.locationStrip) { |
| 138 for (var i = 0, matcher; matcher = options.locationStrip[i]; i++) { |
| 139 location = location.replace(matcher, ''); |
| 140 } |
| 141 } |
| 142 |
| 143 return location; |
| 144 } |
| 145 |
| 146 function isImportant(line, options) { |
| 147 if (options.unimportantLocation) { |
| 148 for (var i = 0, matcher; matcher = options.unimportantLocation[i]; i++) { |
| 149 if (line.location.match(matcher)) return false; |
| 150 } |
| 151 } |
| 152 |
| 153 return true; |
| 154 } |
| 155 |
| 156 scope.clean = clean; |
| 157 scope.pretty = pretty; |
| 158 })(typeof module !== 'undefined' ? module.exports : (this.Stacky = this.Stacky |
| {})); |
| 159 |
| 160 |
| 161 },{"./parsing":4,"chalk":undefined}],2:[function(require,module,exports){ |
| 162 /** |
| 163 * @license |
| 164 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
| 165 * |
| 166 * This code may only be used under the BSD style license found at polymer.githu
b.io/LICENSE.txt |
| 167 * The complete set of authors may be found at polymer.github.io/AUTHORS.txt |
| 168 * The complete set of contributors may be found at polymer.github.io/CONTRIBUTO
RS.txt |
| 169 * Code distributed by Google as part of the polymer project is also subject to |
| 170 * an additional IP rights grant found at polymer.github.io/PATENTS.txt |
| 171 */ |
| 172 'use strict'; |
| 173 |
| 174 var formatting = require('./formatting'); |
| 175 var normalization = require('./normalization'); |
| 176 var parsing = require('./parsing'); |
| 177 |
| 178 module.exports = { |
| 179 // Shorthands for your convenience. |
| 180 normalize: normalization.normalize, |
| 181 parse: parsing.parse, |
| 182 pretty: formatting.pretty, |
| 183 // Or the full modules. |
| 184 formatting: formatting, |
| 185 normalization: normalization, |
| 186 parsing: parsing, |
| 187 }; |
| 188 |
| 189 },{"./formatting":1,"./normalization":3,"./parsing":4}],3:[function(require,modu
le,exports){ |
| 190 /** |
| 191 * @license |
| 192 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
| 193 * |
| 194 * This code may only be used under the BSD style license found at polymer.githu
b.io/LICENSE.txt |
| 195 * The complete set of authors may be found at polymer.github.io/AUTHORS.txt |
| 196 * The complete set of contributors may be found at polymer.github.io/CONTRIBUTO
RS.txt |
| 197 * Code distributed by Google as part of the polymer project is also subject to |
| 198 * an additional IP rights grant found at polymer.github.io/PATENTS.txt |
| 199 */ |
| 200 (function(scope) { |
| 201 'use strict'; |
| 202 |
| 203 var parse = scope.parse || require('./parsing').parse; |
| 204 var pretty = scope.pretty || require('./formatting').pretty; |
| 205 |
| 206 function normalize(error, prettyOptions) { |
| 207 if (error.parsedStack) return error; |
| 208 var message = error.message || error.description || error || '<unknown error>'
; |
| 209 var parsedStack = []; |
| 210 try { |
| 211 parsedStack = parse(error.stack || error.toString()); |
| 212 } catch (error) { |
| 213 // Ah well. |
| 214 } |
| 215 |
| 216 if (parsedStack.length === 0 && error.fileName) { |
| 217 parsedStack.push({ |
| 218 method: '', |
| 219 location: error.fileName, |
| 220 line: error.lineNumber, |
| 221 column: error.columnNumber, |
| 222 }); |
| 223 } |
| 224 |
| 225 if (!prettyOptions || !prettyOptions.showColumns) { |
| 226 for (var i = 0, line; line = parsedStack[i]; i++) { |
| 227 delete line.column; |
| 228 } |
| 229 } |
| 230 |
| 231 var prettyStack = message; |
| 232 if (parsedStack.length > 0) { |
| 233 prettyStack = prettyStack + '\n' + pretty(parsedStack, prettyOptions); |
| 234 } |
| 235 |
| 236 var cleanErr = Object.create(Error.prototype); |
| 237 cleanErr.message = message; |
| 238 cleanErr.stack = prettyStack; |
| 239 cleanErr.parsedStack = parsedStack; |
| 240 |
| 241 return cleanErr; |
| 242 } |
| 243 |
| 244 scope.normalize = normalize; |
| 245 })(typeof module !== 'undefined' ? module.exports : (this.Stacky = this.Stacky |
| {})); |
| 246 |
| 247 |
| 248 },{"./formatting":1,"./parsing":4}],4:[function(require,module,exports){ |
| 249 /** |
| 250 * @license |
| 251 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
| 252 * |
| 253 * This code may only be used under the BSD style license found at polymer.githu
b.io/LICENSE.txt |
| 254 * The complete set of authors may be found at polymer.github.io/AUTHORS.txt |
| 255 * The complete set of contributors may be found at polymer.github.io/CONTRIBUTO
RS.txt |
| 256 * Code distributed by Google as part of the polymer project is also subject to |
| 257 * an additional IP rights grant found at polymer.github.io/PATENTS.txt |
| 258 */ |
| 259 (function(scope) { |
| 260 'use strict'; |
| 261 |
| 262 function parse(stack) { |
| 263 var rawLines = stack.split('\n'); |
| 264 |
| 265 var stackyLines = compact(rawLines.map(parseStackyLine)); |
| 266 if (stackyLines.length === rawLines.length) return stackyLines; |
| 267 |
| 268 var v8Lines = compact(rawLines.map(parseV8Line)); |
| 269 if (v8Lines.length > 0) return v8Lines; |
| 270 |
| 271 var geckoLines = compact(rawLines.map(parseGeckoLine)); |
| 272 if (geckoLines.length > 0) return geckoLines; |
| 273 |
| 274 throw new Error('Unknown stack format: ' + stack); |
| 275 } |
| 276 |
| 277 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Obje
cts/Error/Stack |
| 278 var GECKO_LINE = /^(?:([^@]*)@)?(.*?):(\d+)(?::(\d+))?$/; |
| 279 |
| 280 function parseGeckoLine(line) { |
| 281 var match = line.match(GECKO_LINE); |
| 282 if (!match) return null; |
| 283 return { |
| 284 method: match[1] || '', |
| 285 location: match[2] || '', |
| 286 line: parseInt(match[3]) || 0, |
| 287 column: parseInt(match[4]) || 0, |
| 288 }; |
| 289 } |
| 290 |
| 291 // https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi |
| 292 var V8_OUTER1 = /^\s*(eval )?at (.*) \((.*)\)$/; |
| 293 var V8_OUTER2 = /^\s*at()() (\S+)$/; |
| 294 var V8_INNER = /^\(?([^\(]+):(\d+):(\d+)\)?$/; |
| 295 |
| 296 function parseV8Line(line) { |
| 297 var outer = line.match(V8_OUTER1) || line.match(V8_OUTER2); |
| 298 if (!outer) return null; |
| 299 var inner = outer[3].match(V8_INNER); |
| 300 if (!inner) return null; |
| 301 |
| 302 var method = outer[2] || ''; |
| 303 if (outer[1]) method = 'eval at ' + method; |
| 304 return { |
| 305 method: method, |
| 306 location: inner[1] || '', |
| 307 line: parseInt(inner[2]) || 0, |
| 308 column: parseInt(inner[3]) || 0, |
| 309 }; |
| 310 } |
| 311 |
| 312 // Stacky.formatting.pretty |
| 313 |
| 314 var STACKY_LINE = /^\s*(.+) at (.+):(\d+):(\d+)$/; |
| 315 |
| 316 function parseStackyLine(line) { |
| 317 var match = line.match(STACKY_LINE); |
| 318 if (!match) return null; |
| 319 return { |
| 320 method: match[1] || '', |
| 321 location: match[2] || '', |
| 322 line: parseInt(match[3]) || 0, |
| 323 column: parseInt(match[4]) || 0, |
| 324 }; |
| 325 } |
| 326 |
| 327 // Helpers |
| 328 |
| 329 function compact(array) { |
| 330 var result = []; |
| 331 array.forEach(function(value) { |
| 332 if (value) { |
| 333 result.push(value); |
| 334 } |
| 335 }); |
| 336 return result; |
| 337 } |
| 338 |
| 339 scope.parse = parse; |
| 340 scope.parseGeckoLine = parseGeckoLine; |
| 341 scope.parseV8Line = parseV8Line; |
| 342 scope.parseStackyLine = parseStackyLine; |
| 343 })(typeof module !== 'undefined' ? module.exports : (this.Stacky = this.Stacky |
| {})); |
| 344 |
| 345 },{}]},{},[2])(2) |
| 346 }); |
| OLD | NEW |