URI.js
9 years ago
URI.min.js
5 years ago
css.js
5 years ago
css.min.js
5 years ago
csslint.js
9 years ago
csslint.min.js
5 years ago
editor.js
5 years ago
editor.min.js
5 years ago
inspector.js
5 years ago
inspector.min.js
5 years ago
jquery.sizes.js
11 years ago
jquery.sizes.min.js
5 years ago
specificity.js
11 years ago
specificity.min.js
5 years ago
css.js
5515 lines
| 1 | (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ |
| 2 | |
| 3 | },{}],2:[function(require,module,exports){ |
| 4 | (function (process){ |
| 5 | // .dirname, .basename, and .extname methods are extracted from Node.js v8.11.1, |
| 6 | // backported and transplited with Babel, with backwards-compat fixes |
| 7 | |
| 8 | // Copyright Joyent, Inc. and other Node contributors. |
| 9 | // |
| 10 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 11 | // copy of this software and associated documentation files (the |
| 12 | // "Software"), to deal in the Software without restriction, including |
| 13 | // without limitation the rights to use, copy, modify, merge, publish, |
| 14 | // distribute, sublicense, and/or sell copies of the Software, and to permit |
| 15 | // persons to whom the Software is furnished to do so, subject to the |
| 16 | // following conditions: |
| 17 | // |
| 18 | // The above copyright notice and this permission notice shall be included |
| 19 | // in all copies or substantial portions of the Software. |
| 20 | // |
| 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 22 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 23 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
| 24 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 25 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 26 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 27 | // USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 28 | |
| 29 | // resolves . and .. elements in a path array with directory names there |
| 30 | // must be no slashes, empty elements, or device names (c:\) in the array |
| 31 | // (so also no leading and trailing slashes - it does not distinguish |
| 32 | // relative and absolute paths) |
| 33 | function normalizeArray(parts, allowAboveRoot) { |
| 34 | // if the path tries to go above the root, `up` ends up > 0 |
| 35 | var up = 0; |
| 36 | for (var i = parts.length - 1; i >= 0; i--) { |
| 37 | var last = parts[i]; |
| 38 | if (last === '.') { |
| 39 | parts.splice(i, 1); |
| 40 | } else if (last === '..') { |
| 41 | parts.splice(i, 1); |
| 42 | up++; |
| 43 | } else if (up) { |
| 44 | parts.splice(i, 1); |
| 45 | up--; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // if the path is allowed to go above the root, restore leading ..s |
| 50 | if (allowAboveRoot) { |
| 51 | for (; up--; up) { |
| 52 | parts.unshift('..'); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return parts; |
| 57 | } |
| 58 | |
| 59 | // path.resolve([from ...], to) |
| 60 | // posix version |
| 61 | exports.resolve = function() { |
| 62 | var resolvedPath = '', |
| 63 | resolvedAbsolute = false; |
| 64 | |
| 65 | for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { |
| 66 | var path = (i >= 0) ? arguments[i] : process.cwd(); |
| 67 | |
| 68 | // Skip empty and invalid entries |
| 69 | if (typeof path !== 'string') { |
| 70 | throw new TypeError('Arguments to path.resolve must be strings'); |
| 71 | } else if (!path) { |
| 72 | continue; |
| 73 | } |
| 74 | |
| 75 | resolvedPath = path + '/' + resolvedPath; |
| 76 | resolvedAbsolute = path.charAt(0) === '/'; |
| 77 | } |
| 78 | |
| 79 | // At this point the path should be resolved to a full absolute path, but |
| 80 | // handle relative paths to be safe (might happen when process.cwd() fails) |
| 81 | |
| 82 | // Normalize the path |
| 83 | resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { |
| 84 | return !!p; |
| 85 | }), !resolvedAbsolute).join('/'); |
| 86 | |
| 87 | return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; |
| 88 | }; |
| 89 | |
| 90 | // path.normalize(path) |
| 91 | // posix version |
| 92 | exports.normalize = function(path) { |
| 93 | var isAbsolute = exports.isAbsolute(path), |
| 94 | trailingSlash = substr(path, -1) === '/'; |
| 95 | |
| 96 | // Normalize the path |
| 97 | path = normalizeArray(filter(path.split('/'), function(p) { |
| 98 | return !!p; |
| 99 | }), !isAbsolute).join('/'); |
| 100 | |
| 101 | if (!path && !isAbsolute) { |
| 102 | path = '.'; |
| 103 | } |
| 104 | if (path && trailingSlash) { |
| 105 | path += '/'; |
| 106 | } |
| 107 | |
| 108 | return (isAbsolute ? '/' : '') + path; |
| 109 | }; |
| 110 | |
| 111 | // posix version |
| 112 | exports.isAbsolute = function(path) { |
| 113 | return path.charAt(0) === '/'; |
| 114 | }; |
| 115 | |
| 116 | // posix version |
| 117 | exports.join = function() { |
| 118 | var paths = Array.prototype.slice.call(arguments, 0); |
| 119 | return exports.normalize(filter(paths, function(p, index) { |
| 120 | if (typeof p !== 'string') { |
| 121 | throw new TypeError('Arguments to path.join must be strings'); |
| 122 | } |
| 123 | return p; |
| 124 | }).join('/')); |
| 125 | }; |
| 126 | |
| 127 | |
| 128 | // path.relative(from, to) |
| 129 | // posix version |
| 130 | exports.relative = function(from, to) { |
| 131 | from = exports.resolve(from).substr(1); |
| 132 | to = exports.resolve(to).substr(1); |
| 133 | |
| 134 | function trim(arr) { |
| 135 | var start = 0; |
| 136 | for (; start < arr.length; start++) { |
| 137 | if (arr[start] !== '') break; |
| 138 | } |
| 139 | |
| 140 | var end = arr.length - 1; |
| 141 | for (; end >= 0; end--) { |
| 142 | if (arr[end] !== '') break; |
| 143 | } |
| 144 | |
| 145 | if (start > end) return []; |
| 146 | return arr.slice(start, end - start + 1); |
| 147 | } |
| 148 | |
| 149 | var fromParts = trim(from.split('/')); |
| 150 | var toParts = trim(to.split('/')); |
| 151 | |
| 152 | var length = Math.min(fromParts.length, toParts.length); |
| 153 | var samePartsLength = length; |
| 154 | for (var i = 0; i < length; i++) { |
| 155 | if (fromParts[i] !== toParts[i]) { |
| 156 | samePartsLength = i; |
| 157 | break; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | var outputParts = []; |
| 162 | for (var i = samePartsLength; i < fromParts.length; i++) { |
| 163 | outputParts.push('..'); |
| 164 | } |
| 165 | |
| 166 | outputParts = outputParts.concat(toParts.slice(samePartsLength)); |
| 167 | |
| 168 | return outputParts.join('/'); |
| 169 | }; |
| 170 | |
| 171 | exports.sep = '/'; |
| 172 | exports.delimiter = ':'; |
| 173 | |
| 174 | exports.dirname = function (path) { |
| 175 | if (typeof path !== 'string') path = path + ''; |
| 176 | if (path.length === 0) return '.'; |
| 177 | var code = path.charCodeAt(0); |
| 178 | var hasRoot = code === 47 /*/*/; |
| 179 | var end = -1; |
| 180 | var matchedSlash = true; |
| 181 | for (var i = path.length - 1; i >= 1; --i) { |
| 182 | code = path.charCodeAt(i); |
| 183 | if (code === 47 /*/*/) { |
| 184 | if (!matchedSlash) { |
| 185 | end = i; |
| 186 | break; |
| 187 | } |
| 188 | } else { |
| 189 | // We saw the first non-path separator |
| 190 | matchedSlash = false; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | if (end === -1) return hasRoot ? '/' : '.'; |
| 195 | if (hasRoot && end === 1) { |
| 196 | // return '//'; |
| 197 | // Backwards-compat fix: |
| 198 | return '/'; |
| 199 | } |
| 200 | return path.slice(0, end); |
| 201 | }; |
| 202 | |
| 203 | function basename(path) { |
| 204 | if (typeof path !== 'string') path = path + ''; |
| 205 | |
| 206 | var start = 0; |
| 207 | var end = -1; |
| 208 | var matchedSlash = true; |
| 209 | var i; |
| 210 | |
| 211 | for (i = path.length - 1; i >= 0; --i) { |
| 212 | if (path.charCodeAt(i) === 47 /*/*/) { |
| 213 | // If we reached a path separator that was not part of a set of path |
| 214 | // separators at the end of the string, stop now |
| 215 | if (!matchedSlash) { |
| 216 | start = i + 1; |
| 217 | break; |
| 218 | } |
| 219 | } else if (end === -1) { |
| 220 | // We saw the first non-path separator, mark this as the end of our |
| 221 | // path component |
| 222 | matchedSlash = false; |
| 223 | end = i + 1; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | if (end === -1) return ''; |
| 228 | return path.slice(start, end); |
| 229 | } |
| 230 | |
| 231 | // Uses a mixed approach for backwards-compatibility, as ext behavior changed |
| 232 | // in new Node.js versions, so only basename() above is backported here |
| 233 | exports.basename = function (path, ext) { |
| 234 | var f = basename(path); |
| 235 | if (ext && f.substr(-1 * ext.length) === ext) { |
| 236 | f = f.substr(0, f.length - ext.length); |
| 237 | } |
| 238 | return f; |
| 239 | }; |
| 240 | |
| 241 | exports.extname = function (path) { |
| 242 | if (typeof path !== 'string') path = path + ''; |
| 243 | var startDot = -1; |
| 244 | var startPart = 0; |
| 245 | var end = -1; |
| 246 | var matchedSlash = true; |
| 247 | // Track the state of characters (if any) we see before our first dot and |
| 248 | // after any path separator we find |
| 249 | var preDotState = 0; |
| 250 | for (var i = path.length - 1; i >= 0; --i) { |
| 251 | var code = path.charCodeAt(i); |
| 252 | if (code === 47 /*/*/) { |
| 253 | // If we reached a path separator that was not part of a set of path |
| 254 | // separators at the end of the string, stop now |
| 255 | if (!matchedSlash) { |
| 256 | startPart = i + 1; |
| 257 | break; |
| 258 | } |
| 259 | continue; |
| 260 | } |
| 261 | if (end === -1) { |
| 262 | // We saw the first non-path separator, mark this as the end of our |
| 263 | // extension |
| 264 | matchedSlash = false; |
| 265 | end = i + 1; |
| 266 | } |
| 267 | if (code === 46 /*.*/) { |
| 268 | // If this is our first dot, mark it as the start of our extension |
| 269 | if (startDot === -1) |
| 270 | startDot = i; |
| 271 | else if (preDotState !== 1) |
| 272 | preDotState = 1; |
| 273 | } else if (startDot !== -1) { |
| 274 | // We saw a non-dot and non-path separator before our dot, so we should |
| 275 | // have a good chance at having a non-empty extension |
| 276 | preDotState = -1; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | if (startDot === -1 || end === -1 || |
| 281 | // We saw a non-dot character immediately before the dot |
| 282 | preDotState === 0 || |
| 283 | // The (right-most) trimmed path component is exactly '..' |
| 284 | preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { |
| 285 | return ''; |
| 286 | } |
| 287 | return path.slice(startDot, end); |
| 288 | }; |
| 289 | |
| 290 | function filter (xs, f) { |
| 291 | if (xs.filter) return xs.filter(f); |
| 292 | var res = []; |
| 293 | for (var i = 0; i < xs.length; i++) { |
| 294 | if (f(xs[i], i, xs)) res.push(xs[i]); |
| 295 | } |
| 296 | return res; |
| 297 | } |
| 298 | |
| 299 | // String.prototype.substr - negative index don't work in IE8 |
| 300 | var substr = 'ab'.substr(-1) === 'b' |
| 301 | ? function (str, start, len) { return str.substr(start, len) } |
| 302 | : function (str, start, len) { |
| 303 | if (start < 0) start = str.length + start; |
| 304 | return str.substr(start, len); |
| 305 | } |
| 306 | ; |
| 307 | |
| 308 | }).call(this,require('_process')) |
| 309 | },{"_process":3}],3:[function(require,module,exports){ |
| 310 | // shim for using process in browser |
| 311 | var process = module.exports = {}; |
| 312 | |
| 313 | // cached from whatever global is present so that test runners that stub it |
| 314 | // don't break things. But we need to wrap it in a try catch in case it is |
| 315 | // wrapped in strict mode code which doesn't define any globals. It's inside a |
| 316 | // function because try/catches deoptimize in certain engines. |
| 317 | |
| 318 | var cachedSetTimeout; |
| 319 | var cachedClearTimeout; |
| 320 | |
| 321 | function defaultSetTimout() { |
| 322 | throw new Error('setTimeout has not been defined'); |
| 323 | } |
| 324 | function defaultClearTimeout () { |
| 325 | throw new Error('clearTimeout has not been defined'); |
| 326 | } |
| 327 | (function () { |
| 328 | try { |
| 329 | if (typeof setTimeout === 'function') { |
| 330 | cachedSetTimeout = setTimeout; |
| 331 | } else { |
| 332 | cachedSetTimeout = defaultSetTimout; |
| 333 | } |
| 334 | } catch (e) { |
| 335 | cachedSetTimeout = defaultSetTimout; |
| 336 | } |
| 337 | try { |
| 338 | if (typeof clearTimeout === 'function') { |
| 339 | cachedClearTimeout = clearTimeout; |
| 340 | } else { |
| 341 | cachedClearTimeout = defaultClearTimeout; |
| 342 | } |
| 343 | } catch (e) { |
| 344 | cachedClearTimeout = defaultClearTimeout; |
| 345 | } |
| 346 | } ()) |
| 347 | function runTimeout(fun) { |
| 348 | if (cachedSetTimeout === setTimeout) { |
| 349 | //normal enviroments in sane situations |
| 350 | return setTimeout(fun, 0); |
| 351 | } |
| 352 | // if setTimeout wasn't available but was latter defined |
| 353 | if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { |
| 354 | cachedSetTimeout = setTimeout; |
| 355 | return setTimeout(fun, 0); |
| 356 | } |
| 357 | try { |
| 358 | // when when somebody has screwed with setTimeout but no I.E. maddness |
| 359 | return cachedSetTimeout(fun, 0); |
| 360 | } catch(e){ |
| 361 | try { |
| 362 | // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally |
| 363 | return cachedSetTimeout.call(null, fun, 0); |
| 364 | } catch(e){ |
| 365 | // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error |
| 366 | return cachedSetTimeout.call(this, fun, 0); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | |
| 371 | } |
| 372 | function runClearTimeout(marker) { |
| 373 | if (cachedClearTimeout === clearTimeout) { |
| 374 | //normal enviroments in sane situations |
| 375 | return clearTimeout(marker); |
| 376 | } |
| 377 | // if clearTimeout wasn't available but was latter defined |
| 378 | if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { |
| 379 | cachedClearTimeout = clearTimeout; |
| 380 | return clearTimeout(marker); |
| 381 | } |
| 382 | try { |
| 383 | // when when somebody has screwed with setTimeout but no I.E. maddness |
| 384 | return cachedClearTimeout(marker); |
| 385 | } catch (e){ |
| 386 | try { |
| 387 | // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally |
| 388 | return cachedClearTimeout.call(null, marker); |
| 389 | } catch (e){ |
| 390 | // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. |
| 391 | // Some versions of I.E. have different rules for clearTimeout vs setTimeout |
| 392 | return cachedClearTimeout.call(this, marker); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | |
| 397 | |
| 398 | } |
| 399 | var queue = []; |
| 400 | var draining = false; |
| 401 | var currentQueue; |
| 402 | var queueIndex = -1; |
| 403 | |
| 404 | function cleanUpNextTick() { |
| 405 | if (!draining || !currentQueue) { |
| 406 | return; |
| 407 | } |
| 408 | draining = false; |
| 409 | if (currentQueue.length) { |
| 410 | queue = currentQueue.concat(queue); |
| 411 | } else { |
| 412 | queueIndex = -1; |
| 413 | } |
| 414 | if (queue.length) { |
| 415 | drainQueue(); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | function drainQueue() { |
| 420 | if (draining) { |
| 421 | return; |
| 422 | } |
| 423 | var timeout = runTimeout(cleanUpNextTick); |
| 424 | draining = true; |
| 425 | |
| 426 | var len = queue.length; |
| 427 | while(len) { |
| 428 | currentQueue = queue; |
| 429 | queue = []; |
| 430 | while (++queueIndex < len) { |
| 431 | if (currentQueue) { |
| 432 | currentQueue[queueIndex].run(); |
| 433 | } |
| 434 | } |
| 435 | queueIndex = -1; |
| 436 | len = queue.length; |
| 437 | } |
| 438 | currentQueue = null; |
| 439 | draining = false; |
| 440 | runClearTimeout(timeout); |
| 441 | } |
| 442 | |
| 443 | process.nextTick = function (fun) { |
| 444 | var args = new Array(arguments.length - 1); |
| 445 | if (arguments.length > 1) { |
| 446 | for (var i = 1; i < arguments.length; i++) { |
| 447 | args[i - 1] = arguments[i]; |
| 448 | } |
| 449 | } |
| 450 | queue.push(new Item(fun, args)); |
| 451 | if (queue.length === 1 && !draining) { |
| 452 | runTimeout(drainQueue); |
| 453 | } |
| 454 | }; |
| 455 | |
| 456 | // v8 likes predictible objects |
| 457 | function Item(fun, array) { |
| 458 | this.fun = fun; |
| 459 | this.array = array; |
| 460 | } |
| 461 | Item.prototype.run = function () { |
| 462 | this.fun.apply(null, this.array); |
| 463 | }; |
| 464 | process.title = 'browser'; |
| 465 | process.browser = true; |
| 466 | process.env = {}; |
| 467 | process.argv = []; |
| 468 | process.version = ''; // empty string to avoid regexp issues |
| 469 | process.versions = {}; |
| 470 | |
| 471 | function noop() {} |
| 472 | |
| 473 | process.on = noop; |
| 474 | process.addListener = noop; |
| 475 | process.once = noop; |
| 476 | process.off = noop; |
| 477 | process.removeListener = noop; |
| 478 | process.removeAllListeners = noop; |
| 479 | process.emit = noop; |
| 480 | process.prependListener = noop; |
| 481 | process.prependOnceListener = noop; |
| 482 | |
| 483 | process.listeners = function (name) { return [] } |
| 484 | |
| 485 | process.binding = function (name) { |
| 486 | throw new Error('process.binding is not supported'); |
| 487 | }; |
| 488 | |
| 489 | process.cwd = function () { return '/' }; |
| 490 | process.chdir = function (dir) { |
| 491 | throw new Error('process.chdir is not supported'); |
| 492 | }; |
| 493 | process.umask = function() { return 0; }; |
| 494 | |
| 495 | },{}],4:[function(require,module,exports){ |
| 496 | (function (setImmediate,clearImmediate){ |
| 497 | var nextTick = require('process/browser.js').nextTick; |
| 498 | var apply = Function.prototype.apply; |
| 499 | var slice = Array.prototype.slice; |
| 500 | var immediateIds = {}; |
| 501 | var nextImmediateId = 0; |
| 502 | |
| 503 | // DOM APIs, for completeness |
| 504 | |
| 505 | exports.setTimeout = function() { |
| 506 | return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout); |
| 507 | }; |
| 508 | exports.setInterval = function() { |
| 509 | return new Timeout(apply.call(setInterval, window, arguments), clearInterval); |
| 510 | }; |
| 511 | exports.clearTimeout = |
| 512 | exports.clearInterval = function(timeout) { timeout.close(); }; |
| 513 | |
| 514 | function Timeout(id, clearFn) { |
| 515 | this._id = id; |
| 516 | this._clearFn = clearFn; |
| 517 | } |
| 518 | Timeout.prototype.unref = Timeout.prototype.ref = function() {}; |
| 519 | Timeout.prototype.close = function() { |
| 520 | this._clearFn.call(window, this._id); |
| 521 | }; |
| 522 | |
| 523 | // Does not start the time, just sets up the members needed. |
| 524 | exports.enroll = function(item, msecs) { |
| 525 | clearTimeout(item._idleTimeoutId); |
| 526 | item._idleTimeout = msecs; |
| 527 | }; |
| 528 | |
| 529 | exports.unenroll = function(item) { |
| 530 | clearTimeout(item._idleTimeoutId); |
| 531 | item._idleTimeout = -1; |
| 532 | }; |
| 533 | |
| 534 | exports._unrefActive = exports.active = function(item) { |
| 535 | clearTimeout(item._idleTimeoutId); |
| 536 | |
| 537 | var msecs = item._idleTimeout; |
| 538 | if (msecs >= 0) { |
| 539 | item._idleTimeoutId = setTimeout(function onTimeout() { |
| 540 | if (item._onTimeout) |
| 541 | item._onTimeout(); |
| 542 | }, msecs); |
| 543 | } |
| 544 | }; |
| 545 | |
| 546 | // That's not how node.js implements it but the exposed api is the same. |
| 547 | exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) { |
| 548 | var id = nextImmediateId++; |
| 549 | var args = arguments.length < 2 ? false : slice.call(arguments, 1); |
| 550 | |
| 551 | immediateIds[id] = true; |
| 552 | |
| 553 | nextTick(function onNextTick() { |
| 554 | if (immediateIds[id]) { |
| 555 | // fn.call() is faster so we optimize for the common use-case |
| 556 | // @see http://jsperf.com/call-apply-segu |
| 557 | if (args) { |
| 558 | fn.apply(null, args); |
| 559 | } else { |
| 560 | fn.call(null); |
| 561 | } |
| 562 | // Prevent ids from leaking |
| 563 | exports.clearImmediate(id); |
| 564 | } |
| 565 | }); |
| 566 | |
| 567 | return id; |
| 568 | }; |
| 569 | |
| 570 | exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) { |
| 571 | delete immediateIds[id]; |
| 572 | }; |
| 573 | }).call(this,require("timers").setImmediate,require("timers").clearImmediate) |
| 574 | },{"process/browser.js":3,"timers":4}],5:[function(require,module,exports){ |
| 575 | //This is for browserify to build the required CSS module into something we can use in the browser. |
| 576 | window.css = require('css'); |
| 577 | |
| 578 | },{"css":6}],6:[function(require,module,exports){ |
| 579 | exports.parse = require('./lib/parse'); |
| 580 | exports.stringify = require('./lib/stringify'); |
| 581 | |
| 582 | },{"./lib/parse":7,"./lib/stringify":11}],7:[function(require,module,exports){ |
| 583 | // http://www.w3.org/TR/CSS21/grammar.html |
| 584 | // https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027 |
| 585 | var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g |
| 586 | |
| 587 | module.exports = function(css, options){ |
| 588 | options = options || {}; |
| 589 | |
| 590 | /** |
| 591 | * Positional. |
| 592 | */ |
| 593 | |
| 594 | var lineno = 1; |
| 595 | var column = 1; |
| 596 | |
| 597 | /** |
| 598 | * Update lineno and column based on `str`. |
| 599 | */ |
| 600 | |
| 601 | function updatePosition(str) { |
| 602 | var lines = str.match(/\n/g); |
| 603 | if (lines) lineno += lines.length; |
| 604 | var i = str.lastIndexOf('\n'); |
| 605 | column = ~i ? str.length - i : column + str.length; |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Mark position and patch `node.position`. |
| 610 | */ |
| 611 | |
| 612 | function position() { |
| 613 | var start = { line: lineno, column: column }; |
| 614 | return function(node){ |
| 615 | node.position = new Position(start); |
| 616 | whitespace(); |
| 617 | return node; |
| 618 | }; |
| 619 | } |
| 620 | |
| 621 | /** |
| 622 | * Store position information for a node |
| 623 | */ |
| 624 | |
| 625 | function Position(start) { |
| 626 | this.start = start; |
| 627 | this.end = { line: lineno, column: column }; |
| 628 | this.source = options.source; |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * Non-enumerable source string |
| 633 | */ |
| 634 | |
| 635 | Position.prototype.content = css; |
| 636 | |
| 637 | /** |
| 638 | * Error `msg`. |
| 639 | */ |
| 640 | |
| 641 | var errorsList = []; |
| 642 | |
| 643 | function error(msg) { |
| 644 | var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg); |
| 645 | err.reason = msg; |
| 646 | err.filename = options.source; |
| 647 | err.line = lineno; |
| 648 | err.column = column; |
| 649 | err.source = css; |
| 650 | |
| 651 | if (options.silent) { |
| 652 | errorsList.push(err); |
| 653 | } else { |
| 654 | throw err; |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | /** |
| 659 | * Parse stylesheet. |
| 660 | */ |
| 661 | |
| 662 | function stylesheet() { |
| 663 | var rulesList = rules(); |
| 664 | |
| 665 | return { |
| 666 | type: 'stylesheet', |
| 667 | stylesheet: { |
| 668 | source: options.source, |
| 669 | rules: rulesList, |
| 670 | parsingErrors: errorsList |
| 671 | } |
| 672 | }; |
| 673 | } |
| 674 | |
| 675 | /** |
| 676 | * Opening brace. |
| 677 | */ |
| 678 | |
| 679 | function open() { |
| 680 | return match(/^{\s*/); |
| 681 | } |
| 682 | |
| 683 | /** |
| 684 | * Closing brace. |
| 685 | */ |
| 686 | |
| 687 | function close() { |
| 688 | return match(/^}/); |
| 689 | } |
| 690 | |
| 691 | /** |
| 692 | * Parse ruleset. |
| 693 | */ |
| 694 | |
| 695 | function rules() { |
| 696 | var node; |
| 697 | var rules = []; |
| 698 | whitespace(); |
| 699 | comments(rules); |
| 700 | while (css.length && css.charAt(0) != '}' && (node = atrule() || rule())) { |
| 701 | if (node !== false) { |
| 702 | rules.push(node); |
| 703 | comments(rules); |
| 704 | } |
| 705 | } |
| 706 | return rules; |
| 707 | } |
| 708 | |
| 709 | /** |
| 710 | * Match `re` and return captures. |
| 711 | */ |
| 712 | |
| 713 | function match(re) { |
| 714 | var m = re.exec(css); |
| 715 | if (!m) return; |
| 716 | var str = m[0]; |
| 717 | updatePosition(str); |
| 718 | css = css.slice(str.length); |
| 719 | return m; |
| 720 | } |
| 721 | |
| 722 | /** |
| 723 | * Parse whitespace. |
| 724 | */ |
| 725 | |
| 726 | function whitespace() { |
| 727 | match(/^\s*/); |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * Parse comments; |
| 732 | */ |
| 733 | |
| 734 | function comments(rules) { |
| 735 | var c; |
| 736 | rules = rules || []; |
| 737 | while (c = comment()) { |
| 738 | if (c !== false) { |
| 739 | rules.push(c); |
| 740 | } |
| 741 | } |
| 742 | return rules; |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Parse comment. |
| 747 | */ |
| 748 | |
| 749 | function comment() { |
| 750 | var pos = position(); |
| 751 | if ('/' != css.charAt(0) || '*' != css.charAt(1)) return; |
| 752 | |
| 753 | var i = 2; |
| 754 | while ("" != css.charAt(i) && ('*' != css.charAt(i) || '/' != css.charAt(i + 1))) ++i; |
| 755 | i += 2; |
| 756 | |
| 757 | if ("" === css.charAt(i-1)) { |
| 758 | return error('End of comment missing'); |
| 759 | } |
| 760 | |
| 761 | var str = css.slice(2, i - 2); |
| 762 | column += 2; |
| 763 | updatePosition(str); |
| 764 | css = css.slice(i); |
| 765 | column += 2; |
| 766 | |
| 767 | return pos({ |
| 768 | type: 'comment', |
| 769 | comment: str |
| 770 | }); |
| 771 | } |
| 772 | |
| 773 | /** |
| 774 | * Parse selector. |
| 775 | */ |
| 776 | |
| 777 | function selector() { |
| 778 | var m = match(/^([^{]+)/); |
| 779 | if (!m) return; |
| 780 | /* @fix Remove all comments from selectors |
| 781 | * http://ostermiller.org/findcomment.html */ |
| 782 | return trim(m[0]) |
| 783 | .replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '') |
| 784 | .replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function(m) { |
| 785 | return m.replace(/,/g, '\u200C'); |
| 786 | }) |
| 787 | .split(/\s*(?![^(]*\)),\s*/) |
| 788 | .map(function(s) { |
| 789 | return s.replace(/\u200C/g, ','); |
| 790 | }); |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * Parse declaration. |
| 795 | */ |
| 796 | |
| 797 | function declaration() { |
| 798 | var pos = position(); |
| 799 | |
| 800 | // prop |
| 801 | var prop = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/); |
| 802 | if (!prop) return; |
| 803 | prop = trim(prop[0]); |
| 804 | |
| 805 | // : |
| 806 | if (!match(/^:\s*/)) return error("property missing ':'"); |
| 807 | |
| 808 | // val |
| 809 | var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/); |
| 810 | |
| 811 | var ret = pos({ |
| 812 | type: 'declaration', |
| 813 | property: prop.replace(commentre, ''), |
| 814 | value: val ? trim(val[0]).replace(commentre, '') : '' |
| 815 | }); |
| 816 | |
| 817 | // ; |
| 818 | match(/^[;\s]*/); |
| 819 | |
| 820 | return ret; |
| 821 | } |
| 822 | |
| 823 | /** |
| 824 | * Parse declarations. |
| 825 | */ |
| 826 | |
| 827 | function declarations() { |
| 828 | var decls = []; |
| 829 | |
| 830 | if (!open()) return error("missing '{'"); |
| 831 | comments(decls); |
| 832 | |
| 833 | // declarations |
| 834 | var decl; |
| 835 | while (decl = declaration()) { |
| 836 | if (decl !== false) { |
| 837 | decls.push(decl); |
| 838 | comments(decls); |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | if (!close()) return error("missing '}'"); |
| 843 | return decls; |
| 844 | } |
| 845 | |
| 846 | /** |
| 847 | * Parse keyframe. |
| 848 | */ |
| 849 | |
| 850 | function keyframe() { |
| 851 | var m; |
| 852 | var vals = []; |
| 853 | var pos = position(); |
| 854 | |
| 855 | while (m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/)) { |
| 856 | vals.push(m[1]); |
| 857 | match(/^,\s*/); |
| 858 | } |
| 859 | |
| 860 | if (!vals.length) return; |
| 861 | |
| 862 | return pos({ |
| 863 | type: 'keyframe', |
| 864 | values: vals, |
| 865 | declarations: declarations() |
| 866 | }); |
| 867 | } |
| 868 | |
| 869 | /** |
| 870 | * Parse keyframes. |
| 871 | */ |
| 872 | |
| 873 | function atkeyframes() { |
| 874 | var pos = position(); |
| 875 | var m = match(/^@([-\w]+)?keyframes\s*/); |
| 876 | |
| 877 | if (!m) return; |
| 878 | var vendor = m[1]; |
| 879 | |
| 880 | // identifier |
| 881 | var m = match(/^([-\w]+)\s*/); |
| 882 | if (!m) return error("@keyframes missing name"); |
| 883 | var name = m[1]; |
| 884 | |
| 885 | if (!open()) return error("@keyframes missing '{'"); |
| 886 | |
| 887 | var frame; |
| 888 | var frames = comments(); |
| 889 | while (frame = keyframe()) { |
| 890 | frames.push(frame); |
| 891 | frames = frames.concat(comments()); |
| 892 | } |
| 893 | |
| 894 | if (!close()) return error("@keyframes missing '}'"); |
| 895 | |
| 896 | return pos({ |
| 897 | type: 'keyframes', |
| 898 | name: name, |
| 899 | vendor: vendor, |
| 900 | keyframes: frames |
| 901 | }); |
| 902 | } |
| 903 | |
| 904 | /** |
| 905 | * Parse supports. |
| 906 | */ |
| 907 | |
| 908 | function atsupports() { |
| 909 | var pos = position(); |
| 910 | var m = match(/^@supports *([^{]+)/); |
| 911 | |
| 912 | if (!m) return; |
| 913 | var supports = trim(m[1]); |
| 914 | |
| 915 | if (!open()) return error("@supports missing '{'"); |
| 916 | |
| 917 | var style = comments().concat(rules()); |
| 918 | |
| 919 | if (!close()) return error("@supports missing '}'"); |
| 920 | |
| 921 | return pos({ |
| 922 | type: 'supports', |
| 923 | supports: supports, |
| 924 | rules: style |
| 925 | }); |
| 926 | } |
| 927 | |
| 928 | /** |
| 929 | * Parse host. |
| 930 | */ |
| 931 | |
| 932 | function athost() { |
| 933 | var pos = position(); |
| 934 | var m = match(/^@host\s*/); |
| 935 | |
| 936 | if (!m) return; |
| 937 | |
| 938 | if (!open()) return error("@host missing '{'"); |
| 939 | |
| 940 | var style = comments().concat(rules()); |
| 941 | |
| 942 | if (!close()) return error("@host missing '}'"); |
| 943 | |
| 944 | return pos({ |
| 945 | type: 'host', |
| 946 | rules: style |
| 947 | }); |
| 948 | } |
| 949 | |
| 950 | /** |
| 951 | * Parse media. |
| 952 | */ |
| 953 | |
| 954 | function atmedia() { |
| 955 | var pos = position(); |
| 956 | var m = match(/^@media *([^{]+)/); |
| 957 | |
| 958 | if (!m) return; |
| 959 | var media = trim(m[1]); |
| 960 | |
| 961 | if (!open()) return error("@media missing '{'"); |
| 962 | |
| 963 | var style = comments().concat(rules()); |
| 964 | |
| 965 | if (!close()) return error("@media missing '}'"); |
| 966 | |
| 967 | return pos({ |
| 968 | type: 'media', |
| 969 | media: media, |
| 970 | rules: style |
| 971 | }); |
| 972 | } |
| 973 | |
| 974 | |
| 975 | /** |
| 976 | * Parse custom-media. |
| 977 | */ |
| 978 | |
| 979 | function atcustommedia() { |
| 980 | var pos = position(); |
| 981 | var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/); |
| 982 | if (!m) return; |
| 983 | |
| 984 | return pos({ |
| 985 | type: 'custom-media', |
| 986 | name: trim(m[1]), |
| 987 | media: trim(m[2]) |
| 988 | }); |
| 989 | } |
| 990 | |
| 991 | /** |
| 992 | * Parse paged media. |
| 993 | */ |
| 994 | |
| 995 | function atpage() { |
| 996 | var pos = position(); |
| 997 | var m = match(/^@page */); |
| 998 | if (!m) return; |
| 999 | |
| 1000 | var sel = selector() || []; |
| 1001 | |
| 1002 | if (!open()) return error("@page missing '{'"); |
| 1003 | var decls = comments(); |
| 1004 | |
| 1005 | // declarations |
| 1006 | var decl; |
| 1007 | while (decl = declaration()) { |
| 1008 | decls.push(decl); |
| 1009 | decls = decls.concat(comments()); |
| 1010 | } |
| 1011 | |
| 1012 | if (!close()) return error("@page missing '}'"); |
| 1013 | |
| 1014 | return pos({ |
| 1015 | type: 'page', |
| 1016 | selectors: sel, |
| 1017 | declarations: decls |
| 1018 | }); |
| 1019 | } |
| 1020 | |
| 1021 | /** |
| 1022 | * Parse document. |
| 1023 | */ |
| 1024 | |
| 1025 | function atdocument() { |
| 1026 | var pos = position(); |
| 1027 | var m = match(/^@([-\w]+)?document *([^{]+)/); |
| 1028 | if (!m) return; |
| 1029 | |
| 1030 | var vendor = trim(m[1]); |
| 1031 | var doc = trim(m[2]); |
| 1032 | |
| 1033 | if (!open()) return error("@document missing '{'"); |
| 1034 | |
| 1035 | var style = comments().concat(rules()); |
| 1036 | |
| 1037 | if (!close()) return error("@document missing '}'"); |
| 1038 | |
| 1039 | return pos({ |
| 1040 | type: 'document', |
| 1041 | document: doc, |
| 1042 | vendor: vendor, |
| 1043 | rules: style |
| 1044 | }); |
| 1045 | } |
| 1046 | |
| 1047 | /** |
| 1048 | * Parse font-face. |
| 1049 | */ |
| 1050 | |
| 1051 | function atfontface() { |
| 1052 | var pos = position(); |
| 1053 | var m = match(/^@font-face\s*/); |
| 1054 | if (!m) return; |
| 1055 | |
| 1056 | if (!open()) return error("@font-face missing '{'"); |
| 1057 | var decls = comments(); |
| 1058 | |
| 1059 | // declarations |
| 1060 | var decl; |
| 1061 | while (decl = declaration()) { |
| 1062 | decls.push(decl); |
| 1063 | decls = decls.concat(comments()); |
| 1064 | } |
| 1065 | |
| 1066 | if (!close()) return error("@font-face missing '}'"); |
| 1067 | |
| 1068 | return pos({ |
| 1069 | type: 'font-face', |
| 1070 | declarations: decls |
| 1071 | }); |
| 1072 | } |
| 1073 | |
| 1074 | /** |
| 1075 | * Parse import |
| 1076 | */ |
| 1077 | |
| 1078 | var atimport = _compileAtrule('import'); |
| 1079 | |
| 1080 | /** |
| 1081 | * Parse charset |
| 1082 | */ |
| 1083 | |
| 1084 | var atcharset = _compileAtrule('charset'); |
| 1085 | |
| 1086 | /** |
| 1087 | * Parse namespace |
| 1088 | */ |
| 1089 | |
| 1090 | var atnamespace = _compileAtrule('namespace'); |
| 1091 | |
| 1092 | /** |
| 1093 | * Parse non-block at-rules |
| 1094 | */ |
| 1095 | |
| 1096 | |
| 1097 | function _compileAtrule(name) { |
| 1098 | var re = new RegExp('^@' + name + '\\s*([^;]+);'); |
| 1099 | return function() { |
| 1100 | var pos = position(); |
| 1101 | var m = match(re); |
| 1102 | if (!m) return; |
| 1103 | var ret = { type: name }; |
| 1104 | ret[name] = m[1].trim(); |
| 1105 | return pos(ret); |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | /** |
| 1110 | * Parse at rule. |
| 1111 | */ |
| 1112 | |
| 1113 | function atrule() { |
| 1114 | if (css[0] != '@') return; |
| 1115 | |
| 1116 | return atkeyframes() |
| 1117 | || atmedia() |
| 1118 | || atcustommedia() |
| 1119 | || atsupports() |
| 1120 | || atimport() |
| 1121 | || atcharset() |
| 1122 | || atnamespace() |
| 1123 | || atdocument() |
| 1124 | || atpage() |
| 1125 | || athost() |
| 1126 | || atfontface(); |
| 1127 | } |
| 1128 | |
| 1129 | /** |
| 1130 | * Parse rule. |
| 1131 | */ |
| 1132 | |
| 1133 | function rule() { |
| 1134 | var pos = position(); |
| 1135 | var sel = selector(); |
| 1136 | |
| 1137 | if (!sel) return error('selector missing'); |
| 1138 | comments(); |
| 1139 | |
| 1140 | return pos({ |
| 1141 | type: 'rule', |
| 1142 | selectors: sel, |
| 1143 | declarations: declarations() |
| 1144 | }); |
| 1145 | } |
| 1146 | |
| 1147 | return addParent(stylesheet()); |
| 1148 | }; |
| 1149 | |
| 1150 | /** |
| 1151 | * Trim `str`. |
| 1152 | */ |
| 1153 | |
| 1154 | function trim(str) { |
| 1155 | return str ? str.replace(/^\s+|\s+$/g, '') : ''; |
| 1156 | } |
| 1157 | |
| 1158 | /** |
| 1159 | * Adds non-enumerable parent node reference to each node. |
| 1160 | */ |
| 1161 | |
| 1162 | function addParent(obj, parent) { |
| 1163 | var isNode = obj && typeof obj.type === 'string'; |
| 1164 | var childParent = isNode ? obj : parent; |
| 1165 | |
| 1166 | for (var k in obj) { |
| 1167 | var value = obj[k]; |
| 1168 | if (Array.isArray(value)) { |
| 1169 | value.forEach(function(v) { addParent(v, childParent); }); |
| 1170 | } else if (value && typeof value === 'object') { |
| 1171 | addParent(value, childParent); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | if (isNode) { |
| 1176 | Object.defineProperty(obj, 'parent', { |
| 1177 | configurable: true, |
| 1178 | writable: true, |
| 1179 | enumerable: false, |
| 1180 | value: parent || null |
| 1181 | }); |
| 1182 | } |
| 1183 | |
| 1184 | return obj; |
| 1185 | } |
| 1186 | |
| 1187 | },{}],8:[function(require,module,exports){ |
| 1188 | |
| 1189 | /** |
| 1190 | * Expose `Compiler`. |
| 1191 | */ |
| 1192 | |
| 1193 | module.exports = Compiler; |
| 1194 | |
| 1195 | /** |
| 1196 | * Initialize a compiler. |
| 1197 | * |
| 1198 | * @param {Type} name |
| 1199 | * @return {Type} |
| 1200 | * @api public |
| 1201 | */ |
| 1202 | |
| 1203 | function Compiler(opts) { |
| 1204 | this.options = opts || {}; |
| 1205 | } |
| 1206 | |
| 1207 | /** |
| 1208 | * Emit `str` |
| 1209 | */ |
| 1210 | |
| 1211 | Compiler.prototype.emit = function(str) { |
| 1212 | return str; |
| 1213 | }; |
| 1214 | |
| 1215 | /** |
| 1216 | * Visit `node`. |
| 1217 | */ |
| 1218 | |
| 1219 | Compiler.prototype.visit = function(node){ |
| 1220 | return this[node.type](node); |
| 1221 | }; |
| 1222 | |
| 1223 | /** |
| 1224 | * Map visit over array of `nodes`, optionally using a `delim` |
| 1225 | */ |
| 1226 | |
| 1227 | Compiler.prototype.mapVisit = function(nodes, delim){ |
| 1228 | var buf = ''; |
| 1229 | delim = delim || ''; |
| 1230 | |
| 1231 | for (var i = 0, length = nodes.length; i < length; i++) { |
| 1232 | buf += this.visit(nodes[i]); |
| 1233 | if (delim && i < length - 1) buf += this.emit(delim); |
| 1234 | } |
| 1235 | |
| 1236 | return buf; |
| 1237 | }; |
| 1238 | |
| 1239 | },{}],9:[function(require,module,exports){ |
| 1240 | |
| 1241 | /** |
| 1242 | * Module dependencies. |
| 1243 | */ |
| 1244 | |
| 1245 | var Base = require('./compiler'); |
| 1246 | var inherits = require('inherits'); |
| 1247 | |
| 1248 | /** |
| 1249 | * Expose compiler. |
| 1250 | */ |
| 1251 | |
| 1252 | module.exports = Compiler; |
| 1253 | |
| 1254 | /** |
| 1255 | * Initialize a new `Compiler`. |
| 1256 | */ |
| 1257 | |
| 1258 | function Compiler(options) { |
| 1259 | Base.call(this, options); |
| 1260 | } |
| 1261 | |
| 1262 | /** |
| 1263 | * Inherit from `Base.prototype`. |
| 1264 | */ |
| 1265 | |
| 1266 | inherits(Compiler, Base); |
| 1267 | |
| 1268 | /** |
| 1269 | * Compile `node`. |
| 1270 | */ |
| 1271 | |
| 1272 | Compiler.prototype.compile = function(node){ |
| 1273 | return node.stylesheet |
| 1274 | .rules.map(this.visit, this) |
| 1275 | .join(''); |
| 1276 | }; |
| 1277 | |
| 1278 | /** |
| 1279 | * Visit comment node. |
| 1280 | */ |
| 1281 | |
| 1282 | Compiler.prototype.comment = function(node){ |
| 1283 | return this.emit('', node.position); |
| 1284 | }; |
| 1285 | |
| 1286 | /** |
| 1287 | * Visit import node. |
| 1288 | */ |
| 1289 | |
| 1290 | Compiler.prototype.import = function(node){ |
| 1291 | return this.emit('@import ' + node.import + ';', node.position); |
| 1292 | }; |
| 1293 | |
| 1294 | /** |
| 1295 | * Visit media node. |
| 1296 | */ |
| 1297 | |
| 1298 | Compiler.prototype.media = function(node){ |
| 1299 | return this.emit('@media ' + node.media, node.position) |
| 1300 | + this.emit('{') |
| 1301 | + this.mapVisit(node.rules) |
| 1302 | + this.emit('}'); |
| 1303 | }; |
| 1304 | |
| 1305 | /** |
| 1306 | * Visit document node. |
| 1307 | */ |
| 1308 | |
| 1309 | Compiler.prototype.document = function(node){ |
| 1310 | var doc = '@' + (node.vendor || '') + 'document ' + node.document; |
| 1311 | |
| 1312 | return this.emit(doc, node.position) |
| 1313 | + this.emit('{') |
| 1314 | + this.mapVisit(node.rules) |
| 1315 | + this.emit('}'); |
| 1316 | }; |
| 1317 | |
| 1318 | /** |
| 1319 | * Visit charset node. |
| 1320 | */ |
| 1321 | |
| 1322 | Compiler.prototype.charset = function(node){ |
| 1323 | return this.emit('@charset ' + node.charset + ';', node.position); |
| 1324 | }; |
| 1325 | |
| 1326 | /** |
| 1327 | * Visit namespace node. |
| 1328 | */ |
| 1329 | |
| 1330 | Compiler.prototype.namespace = function(node){ |
| 1331 | return this.emit('@namespace ' + node.namespace + ';', node.position); |
| 1332 | }; |
| 1333 | |
| 1334 | /** |
| 1335 | * Visit supports node. |
| 1336 | */ |
| 1337 | |
| 1338 | Compiler.prototype.supports = function(node){ |
| 1339 | return this.emit('@supports ' + node.supports, node.position) |
| 1340 | + this.emit('{') |
| 1341 | + this.mapVisit(node.rules) |
| 1342 | + this.emit('}'); |
| 1343 | }; |
| 1344 | |
| 1345 | /** |
| 1346 | * Visit keyframes node. |
| 1347 | */ |
| 1348 | |
| 1349 | Compiler.prototype.keyframes = function(node){ |
| 1350 | return this.emit('@' |
| 1351 | + (node.vendor || '') |
| 1352 | + 'keyframes ' |
| 1353 | + node.name, node.position) |
| 1354 | + this.emit('{') |
| 1355 | + this.mapVisit(node.keyframes) |
| 1356 | + this.emit('}'); |
| 1357 | }; |
| 1358 | |
| 1359 | /** |
| 1360 | * Visit keyframe node. |
| 1361 | */ |
| 1362 | |
| 1363 | Compiler.prototype.keyframe = function(node){ |
| 1364 | var decls = node.declarations; |
| 1365 | |
| 1366 | return this.emit(node.values.join(','), node.position) |
| 1367 | + this.emit('{') |
| 1368 | + this.mapVisit(decls) |
| 1369 | + this.emit('}'); |
| 1370 | }; |
| 1371 | |
| 1372 | /** |
| 1373 | * Visit page node. |
| 1374 | */ |
| 1375 | |
| 1376 | Compiler.prototype.page = function(node){ |
| 1377 | var sel = node.selectors.length |
| 1378 | ? node.selectors.join(', ') |
| 1379 | : ''; |
| 1380 | |
| 1381 | return this.emit('@page ' + sel, node.position) |
| 1382 | + this.emit('{') |
| 1383 | + this.mapVisit(node.declarations) |
| 1384 | + this.emit('}'); |
| 1385 | }; |
| 1386 | |
| 1387 | /** |
| 1388 | * Visit font-face node. |
| 1389 | */ |
| 1390 | |
| 1391 | Compiler.prototype['font-face'] = function(node){ |
| 1392 | return this.emit('@font-face', node.position) |
| 1393 | + this.emit('{') |
| 1394 | + this.mapVisit(node.declarations) |
| 1395 | + this.emit('}'); |
| 1396 | }; |
| 1397 | |
| 1398 | /** |
| 1399 | * Visit host node. |
| 1400 | */ |
| 1401 | |
| 1402 | Compiler.prototype.host = function(node){ |
| 1403 | return this.emit('@host', node.position) |
| 1404 | + this.emit('{') |
| 1405 | + this.mapVisit(node.rules) |
| 1406 | + this.emit('}'); |
| 1407 | }; |
| 1408 | |
| 1409 | /** |
| 1410 | * Visit custom-media node. |
| 1411 | */ |
| 1412 | |
| 1413 | Compiler.prototype['custom-media'] = function(node){ |
| 1414 | return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position); |
| 1415 | }; |
| 1416 | |
| 1417 | /** |
| 1418 | * Visit rule node. |
| 1419 | */ |
| 1420 | |
| 1421 | Compiler.prototype.rule = function(node){ |
| 1422 | var decls = node.declarations; |
| 1423 | if (!decls.length) return ''; |
| 1424 | |
| 1425 | return this.emit(node.selectors.join(','), node.position) |
| 1426 | + this.emit('{') |
| 1427 | + this.mapVisit(decls) |
| 1428 | + this.emit('}'); |
| 1429 | }; |
| 1430 | |
| 1431 | /** |
| 1432 | * Visit declaration node. |
| 1433 | */ |
| 1434 | |
| 1435 | Compiler.prototype.declaration = function(node){ |
| 1436 | return this.emit(node.property + ':' + node.value, node.position) + this.emit(';'); |
| 1437 | }; |
| 1438 | |
| 1439 | |
| 1440 | },{"./compiler":8,"inherits":13}],10:[function(require,module,exports){ |
| 1441 | |
| 1442 | /** |
| 1443 | * Module dependencies. |
| 1444 | */ |
| 1445 | |
| 1446 | var Base = require('./compiler'); |
| 1447 | var inherits = require('inherits'); |
| 1448 | |
| 1449 | /** |
| 1450 | * Expose compiler. |
| 1451 | */ |
| 1452 | |
| 1453 | module.exports = Compiler; |
| 1454 | |
| 1455 | /** |
| 1456 | * Initialize a new `Compiler`. |
| 1457 | */ |
| 1458 | |
| 1459 | function Compiler(options) { |
| 1460 | options = options || {}; |
| 1461 | Base.call(this, options); |
| 1462 | this.indentation = options.indent; |
| 1463 | } |
| 1464 | |
| 1465 | /** |
| 1466 | * Inherit from `Base.prototype`. |
| 1467 | */ |
| 1468 | |
| 1469 | inherits(Compiler, Base); |
| 1470 | |
| 1471 | /** |
| 1472 | * Compile `node`. |
| 1473 | */ |
| 1474 | |
| 1475 | Compiler.prototype.compile = function(node){ |
| 1476 | return this.stylesheet(node); |
| 1477 | }; |
| 1478 | |
| 1479 | /** |
| 1480 | * Visit stylesheet node. |
| 1481 | */ |
| 1482 | |
| 1483 | Compiler.prototype.stylesheet = function(node){ |
| 1484 | return this.mapVisit(node.stylesheet.rules, '\n\n'); |
| 1485 | }; |
| 1486 | |
| 1487 | /** |
| 1488 | * Visit comment node. |
| 1489 | */ |
| 1490 | |
| 1491 | Compiler.prototype.comment = function(node){ |
| 1492 | return this.emit(this.indent() + '/*' + node.comment + '*/', node.position); |
| 1493 | }; |
| 1494 | |
| 1495 | /** |
| 1496 | * Visit import node. |
| 1497 | */ |
| 1498 | |
| 1499 | Compiler.prototype.import = function(node){ |
| 1500 | return this.emit('@import ' + node.import + ';', node.position); |
| 1501 | }; |
| 1502 | |
| 1503 | /** |
| 1504 | * Visit media node. |
| 1505 | */ |
| 1506 | |
| 1507 | Compiler.prototype.media = function(node){ |
| 1508 | return this.emit('@media ' + node.media, node.position) |
| 1509 | + this.emit( |
| 1510 | ' {\n' |
| 1511 | + this.indent(1)) |
| 1512 | + this.mapVisit(node.rules, '\n\n') |
| 1513 | + this.emit( |
| 1514 | this.indent(-1) |
| 1515 | + '\n}'); |
| 1516 | }; |
| 1517 | |
| 1518 | /** |
| 1519 | * Visit document node. |
| 1520 | */ |
| 1521 | |
| 1522 | Compiler.prototype.document = function(node){ |
| 1523 | var doc = '@' + (node.vendor || '') + 'document ' + node.document; |
| 1524 | |
| 1525 | return this.emit(doc, node.position) |
| 1526 | + this.emit( |
| 1527 | ' ' |
| 1528 | + ' {\n' |
| 1529 | + this.indent(1)) |
| 1530 | + this.mapVisit(node.rules, '\n\n') |
| 1531 | + this.emit( |
| 1532 | this.indent(-1) |
| 1533 | + '\n}'); |
| 1534 | }; |
| 1535 | |
| 1536 | /** |
| 1537 | * Visit charset node. |
| 1538 | */ |
| 1539 | |
| 1540 | Compiler.prototype.charset = function(node){ |
| 1541 | return this.emit('@charset ' + node.charset + ';', node.position); |
| 1542 | }; |
| 1543 | |
| 1544 | /** |
| 1545 | * Visit namespace node. |
| 1546 | */ |
| 1547 | |
| 1548 | Compiler.prototype.namespace = function(node){ |
| 1549 | return this.emit('@namespace ' + node.namespace + ';', node.position); |
| 1550 | }; |
| 1551 | |
| 1552 | /** |
| 1553 | * Visit supports node. |
| 1554 | */ |
| 1555 | |
| 1556 | Compiler.prototype.supports = function(node){ |
| 1557 | return this.emit('@supports ' + node.supports, node.position) |
| 1558 | + this.emit( |
| 1559 | ' {\n' |
| 1560 | + this.indent(1)) |
| 1561 | + this.mapVisit(node.rules, '\n\n') |
| 1562 | + this.emit( |
| 1563 | this.indent(-1) |
| 1564 | + '\n}'); |
| 1565 | }; |
| 1566 | |
| 1567 | /** |
| 1568 | * Visit keyframes node. |
| 1569 | */ |
| 1570 | |
| 1571 | Compiler.prototype.keyframes = function(node){ |
| 1572 | return this.emit('@' + (node.vendor || '') + 'keyframes ' + node.name, node.position) |
| 1573 | + this.emit( |
| 1574 | ' {\n' |
| 1575 | + this.indent(1)) |
| 1576 | + this.mapVisit(node.keyframes, '\n') |
| 1577 | + this.emit( |
| 1578 | this.indent(-1) |
| 1579 | + '}'); |
| 1580 | }; |
| 1581 | |
| 1582 | /** |
| 1583 | * Visit keyframe node. |
| 1584 | */ |
| 1585 | |
| 1586 | Compiler.prototype.keyframe = function(node){ |
| 1587 | var decls = node.declarations; |
| 1588 | |
| 1589 | return this.emit(this.indent()) |
| 1590 | + this.emit(node.values.join(', '), node.position) |
| 1591 | + this.emit( |
| 1592 | ' {\n' |
| 1593 | + this.indent(1)) |
| 1594 | + this.mapVisit(decls, '\n') |
| 1595 | + this.emit( |
| 1596 | this.indent(-1) |
| 1597 | + '\n' |
| 1598 | + this.indent() + '}\n'); |
| 1599 | }; |
| 1600 | |
| 1601 | /** |
| 1602 | * Visit page node. |
| 1603 | */ |
| 1604 | |
| 1605 | Compiler.prototype.page = function(node){ |
| 1606 | var sel = node.selectors.length |
| 1607 | ? node.selectors.join(', ') + ' ' |
| 1608 | : ''; |
| 1609 | |
| 1610 | return this.emit('@page ' + sel, node.position) |
| 1611 | + this.emit('{\n') |
| 1612 | + this.emit(this.indent(1)) |
| 1613 | + this.mapVisit(node.declarations, '\n') |
| 1614 | + this.emit(this.indent(-1)) |
| 1615 | + this.emit('\n}'); |
| 1616 | }; |
| 1617 | |
| 1618 | /** |
| 1619 | * Visit font-face node. |
| 1620 | */ |
| 1621 | |
| 1622 | Compiler.prototype['font-face'] = function(node){ |
| 1623 | return this.emit('@font-face ', node.position) |
| 1624 | + this.emit('{\n') |
| 1625 | + this.emit(this.indent(1)) |
| 1626 | + this.mapVisit(node.declarations, '\n') |
| 1627 | + this.emit(this.indent(-1)) |
| 1628 | + this.emit('\n}'); |
| 1629 | }; |
| 1630 | |
| 1631 | /** |
| 1632 | * Visit host node. |
| 1633 | */ |
| 1634 | |
| 1635 | Compiler.prototype.host = function(node){ |
| 1636 | return this.emit('@host', node.position) |
| 1637 | + this.emit( |
| 1638 | ' {\n' |
| 1639 | + this.indent(1)) |
| 1640 | + this.mapVisit(node.rules, '\n\n') |
| 1641 | + this.emit( |
| 1642 | this.indent(-1) |
| 1643 | + '\n}'); |
| 1644 | }; |
| 1645 | |
| 1646 | /** |
| 1647 | * Visit custom-media node. |
| 1648 | */ |
| 1649 | |
| 1650 | Compiler.prototype['custom-media'] = function(node){ |
| 1651 | return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position); |
| 1652 | }; |
| 1653 | |
| 1654 | /** |
| 1655 | * Visit rule node. |
| 1656 | */ |
| 1657 | |
| 1658 | Compiler.prototype.rule = function(node){ |
| 1659 | var indent = this.indent(); |
| 1660 | var decls = node.declarations; |
| 1661 | if (!decls.length) return ''; |
| 1662 | |
| 1663 | return this.emit(node.selectors.map(function(s){ return indent + s }).join(',\n'), node.position) |
| 1664 | + this.emit(' {\n') |
| 1665 | + this.emit(this.indent(1)) |
| 1666 | + this.mapVisit(decls, '\n') |
| 1667 | + this.emit(this.indent(-1)) |
| 1668 | + this.emit('\n' + this.indent() + '}'); |
| 1669 | }; |
| 1670 | |
| 1671 | /** |
| 1672 | * Visit declaration node. |
| 1673 | */ |
| 1674 | |
| 1675 | Compiler.prototype.declaration = function(node){ |
| 1676 | return this.emit(this.indent()) |
| 1677 | + this.emit(node.property + ': ' + node.value, node.position) |
| 1678 | + this.emit(';'); |
| 1679 | }; |
| 1680 | |
| 1681 | /** |
| 1682 | * Increase, decrease or return current indentation. |
| 1683 | */ |
| 1684 | |
| 1685 | Compiler.prototype.indent = function(level) { |
| 1686 | this.level = this.level || 1; |
| 1687 | |
| 1688 | if (null != level) { |
| 1689 | this.level += level; |
| 1690 | return ''; |
| 1691 | } |
| 1692 | |
| 1693 | return Array(this.level).join(this.indentation || ' '); |
| 1694 | }; |
| 1695 | |
| 1696 | },{"./compiler":8,"inherits":13}],11:[function(require,module,exports){ |
| 1697 | |
| 1698 | /** |
| 1699 | * Module dependencies. |
| 1700 | */ |
| 1701 | |
| 1702 | var Compressed = require('./compress'); |
| 1703 | var Identity = require('./identity'); |
| 1704 | |
| 1705 | /** |
| 1706 | * Stringfy the given AST `node`. |
| 1707 | * |
| 1708 | * Options: |
| 1709 | * |
| 1710 | * - `compress` space-optimized output |
| 1711 | * - `sourcemap` return an object with `.code` and `.map` |
| 1712 | * |
| 1713 | * @param {Object} node |
| 1714 | * @param {Object} [options] |
| 1715 | * @return {String} |
| 1716 | * @api public |
| 1717 | */ |
| 1718 | |
| 1719 | module.exports = function(node, options){ |
| 1720 | options = options || {}; |
| 1721 | |
| 1722 | var compiler = options.compress |
| 1723 | ? new Compressed(options) |
| 1724 | : new Identity(options); |
| 1725 | |
| 1726 | // source maps |
| 1727 | if (options.sourcemap) { |
| 1728 | var sourcemaps = require('./source-map-support'); |
| 1729 | sourcemaps(compiler); |
| 1730 | |
| 1731 | var code = compiler.compile(node); |
| 1732 | compiler.applySourceMaps(); |
| 1733 | |
| 1734 | var map = options.sourcemap === 'generator' |
| 1735 | ? compiler.map |
| 1736 | : compiler.map.toJSON(); |
| 1737 | |
| 1738 | return { code: code, map: map }; |
| 1739 | } |
| 1740 | |
| 1741 | var code = compiler.compile(node); |
| 1742 | return code; |
| 1743 | }; |
| 1744 | |
| 1745 | },{"./compress":9,"./identity":10,"./source-map-support":12}],12:[function(require,module,exports){ |
| 1746 | |
| 1747 | /** |
| 1748 | * Module dependencies. |
| 1749 | */ |
| 1750 | |
| 1751 | var SourceMap = require('source-map').SourceMapGenerator; |
| 1752 | var SourceMapConsumer = require('source-map').SourceMapConsumer; |
| 1753 | var sourceMapResolve = require('source-map-resolve'); |
| 1754 | var urix = require('urix'); |
| 1755 | var fs = require('fs'); |
| 1756 | var path = require('path'); |
| 1757 | |
| 1758 | /** |
| 1759 | * Expose `mixin()`. |
| 1760 | */ |
| 1761 | |
| 1762 | module.exports = mixin; |
| 1763 | |
| 1764 | /** |
| 1765 | * Mixin source map support into `compiler`. |
| 1766 | * |
| 1767 | * @param {Compiler} compiler |
| 1768 | * @api public |
| 1769 | */ |
| 1770 | |
| 1771 | function mixin(compiler) { |
| 1772 | compiler._comment = compiler.comment; |
| 1773 | compiler.map = new SourceMap(); |
| 1774 | compiler.position = { line: 1, column: 1 }; |
| 1775 | compiler.files = {}; |
| 1776 | for (var k in exports) compiler[k] = exports[k]; |
| 1777 | } |
| 1778 | |
| 1779 | /** |
| 1780 | * Update position. |
| 1781 | * |
| 1782 | * @param {String} str |
| 1783 | * @api private |
| 1784 | */ |
| 1785 | |
| 1786 | exports.updatePosition = function(str) { |
| 1787 | var lines = str.match(/\n/g); |
| 1788 | if (lines) this.position.line += lines.length; |
| 1789 | var i = str.lastIndexOf('\n'); |
| 1790 | this.position.column = ~i ? str.length - i : this.position.column + str.length; |
| 1791 | }; |
| 1792 | |
| 1793 | /** |
| 1794 | * Emit `str`. |
| 1795 | * |
| 1796 | * @param {String} str |
| 1797 | * @param {Object} [pos] |
| 1798 | * @return {String} |
| 1799 | * @api private |
| 1800 | */ |
| 1801 | |
| 1802 | exports.emit = function(str, pos) { |
| 1803 | if (pos) { |
| 1804 | var sourceFile = urix(pos.source || 'source.css'); |
| 1805 | |
| 1806 | this.map.addMapping({ |
| 1807 | source: sourceFile, |
| 1808 | generated: { |
| 1809 | line: this.position.line, |
| 1810 | column: Math.max(this.position.column - 1, 0) |
| 1811 | }, |
| 1812 | original: { |
| 1813 | line: pos.start.line, |
| 1814 | column: pos.start.column - 1 |
| 1815 | } |
| 1816 | }); |
| 1817 | |
| 1818 | this.addFile(sourceFile, pos); |
| 1819 | } |
| 1820 | |
| 1821 | this.updatePosition(str); |
| 1822 | |
| 1823 | return str; |
| 1824 | }; |
| 1825 | |
| 1826 | /** |
| 1827 | * Adds a file to the source map output if it has not already been added |
| 1828 | * @param {String} file |
| 1829 | * @param {Object} pos |
| 1830 | */ |
| 1831 | |
| 1832 | exports.addFile = function(file, pos) { |
| 1833 | if (typeof pos.content !== 'string') return; |
| 1834 | if (Object.prototype.hasOwnProperty.call(this.files, file)) return; |
| 1835 | |
| 1836 | this.files[file] = pos.content; |
| 1837 | }; |
| 1838 | |
| 1839 | /** |
| 1840 | * Applies any original source maps to the output and embeds the source file |
| 1841 | * contents in the source map. |
| 1842 | */ |
| 1843 | |
| 1844 | exports.applySourceMaps = function() { |
| 1845 | Object.keys(this.files).forEach(function(file) { |
| 1846 | var content = this.files[file]; |
| 1847 | this.map.setSourceContent(file, content); |
| 1848 | |
| 1849 | if (this.options.inputSourcemaps !== false) { |
| 1850 | var originalMap = sourceMapResolve.resolveSync( |
| 1851 | content, file, fs.readFileSync); |
| 1852 | if (originalMap) { |
| 1853 | var map = new SourceMapConsumer(originalMap.map); |
| 1854 | var relativeTo = originalMap.sourcesRelativeTo; |
| 1855 | this.map.applySourceMap(map, file, urix(path.dirname(relativeTo))); |
| 1856 | } |
| 1857 | } |
| 1858 | }, this); |
| 1859 | }; |
| 1860 | |
| 1861 | /** |
| 1862 | * Process comments, drops sourceMap comments. |
| 1863 | * @param {Object} node |
| 1864 | */ |
| 1865 | |
| 1866 | exports.comment = function(node) { |
| 1867 | if (/^# sourceMappingURL=/.test(node.comment)) |
| 1868 | return this.emit('', node.position); |
| 1869 | else |
| 1870 | return this._comment(node); |
| 1871 | }; |
| 1872 | |
| 1873 | },{"fs":1,"path":2,"source-map":27,"source-map-resolve":15,"urix":28}],13:[function(require,module,exports){ |
| 1874 | if (typeof Object.create === 'function') { |
| 1875 | // implementation from standard node.js 'util' module |
| 1876 | module.exports = function inherits(ctor, superCtor) { |
| 1877 | if (superCtor) { |
| 1878 | ctor.super_ = superCtor |
| 1879 | ctor.prototype = Object.create(superCtor.prototype, { |
| 1880 | constructor: { |
| 1881 | value: ctor, |
| 1882 | enumerable: false, |
| 1883 | writable: true, |
| 1884 | configurable: true |
| 1885 | } |
| 1886 | }) |
| 1887 | } |
| 1888 | }; |
| 1889 | } else { |
| 1890 | // old school shim for old browsers |
| 1891 | module.exports = function inherits(ctor, superCtor) { |
| 1892 | if (superCtor) { |
| 1893 | ctor.super_ = superCtor |
| 1894 | var TempCtor = function () {} |
| 1895 | TempCtor.prototype = superCtor.prototype |
| 1896 | ctor.prototype = new TempCtor() |
| 1897 | ctor.prototype.constructor = ctor |
| 1898 | } |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | },{}],14:[function(require,module,exports){ |
| 1903 | // Copyright 2014 Simon Lydell |
| 1904 | // X11 (“MIT”) Licensed. (See LICENSE.) |
| 1905 | |
| 1906 | void (function(root, factory) { |
| 1907 | if (typeof define === "function" && define.amd) { |
| 1908 | define(factory) |
| 1909 | } else if (typeof exports === "object") { |
| 1910 | module.exports = factory() |
| 1911 | } else { |
| 1912 | root.resolveUrl = factory() |
| 1913 | } |
| 1914 | }(this, function() { |
| 1915 | |
| 1916 | function resolveUrl(/* ...urls */) { |
| 1917 | var numUrls = arguments.length |
| 1918 | |
| 1919 | if (numUrls === 0) { |
| 1920 | throw new Error("resolveUrl requires at least one argument; got none.") |
| 1921 | } |
| 1922 | |
| 1923 | var base = document.createElement("base") |
| 1924 | base.href = arguments[0] |
| 1925 | |
| 1926 | if (numUrls === 1) { |
| 1927 | return base.href |
| 1928 | } |
| 1929 | |
| 1930 | var head = document.getElementsByTagName("head")[0] |
| 1931 | head.insertBefore(base, head.firstChild) |
| 1932 | |
| 1933 | var a = document.createElement("a") |
| 1934 | var resolved |
| 1935 | |
| 1936 | for (var index = 1; index < numUrls; index++) { |
| 1937 | a.href = arguments[index] |
| 1938 | resolved = a.href |
| 1939 | base.href = resolved |
| 1940 | } |
| 1941 | |
| 1942 | head.removeChild(base) |
| 1943 | |
| 1944 | return resolved |
| 1945 | } |
| 1946 | |
| 1947 | return resolveUrl |
| 1948 | |
| 1949 | })); |
| 1950 | |
| 1951 | },{}],15:[function(require,module,exports){ |
| 1952 | (function (setImmediate){ |
| 1953 | // Note: source-map-resolve.js is generated from source-map-resolve-node.js and |
| 1954 | // source-map-resolve-template.js. Only edit the two latter files, _not_ |
| 1955 | // source-map-resolve.js! |
| 1956 | |
| 1957 | void (function(root, factory) { |
| 1958 | if (typeof define === "function" && define.amd) { |
| 1959 | define(["source-map-url", "resolve-url"], factory) |
| 1960 | } else if (typeof exports === "object") { |
| 1961 | var sourceMappingURL = require("source-map-url") |
| 1962 | var resolveUrl = require("resolve-url") |
| 1963 | module.exports = factory(sourceMappingURL, resolveUrl) |
| 1964 | } else { |
| 1965 | root.sourceMapResolve = factory(root.sourceMappingURL, root.resolveUrl) |
| 1966 | } |
| 1967 | }(this, function(sourceMappingURL, resolveUrl) { |
| 1968 | |
| 1969 | function callbackAsync(callback, error, result) { |
| 1970 | setImmediate(function() { callback(error, result) }) |
| 1971 | } |
| 1972 | |
| 1973 | function parseMapToJSON(string, data) { |
| 1974 | try { |
| 1975 | return JSON.parse(string.replace(/^\)\]\}'/, "")) |
| 1976 | } catch (error) { |
| 1977 | error.sourceMapData = data |
| 1978 | throw error |
| 1979 | } |
| 1980 | } |
| 1981 | |
| 1982 | function readSync(read, url, data) { |
| 1983 | var readUrl = url |
| 1984 | try { |
| 1985 | return String(read(readUrl)) |
| 1986 | } catch (error) { |
| 1987 | error.sourceMapData = data |
| 1988 | throw error |
| 1989 | } |
| 1990 | } |
| 1991 | |
| 1992 | |
| 1993 | |
| 1994 | function resolveSourceMap(code, codeUrl, read, callback) { |
| 1995 | var mapData |
| 1996 | try { |
| 1997 | mapData = resolveSourceMapHelper(code, codeUrl) |
| 1998 | } catch (error) { |
| 1999 | return callbackAsync(callback, error) |
| 2000 | } |
| 2001 | if (!mapData || mapData.map) { |
| 2002 | return callbackAsync(callback, null, mapData) |
| 2003 | } |
| 2004 | var readUrl = mapData.url |
| 2005 | read(readUrl, function(error, result) { |
| 2006 | if (error) { |
| 2007 | error.sourceMapData = mapData |
| 2008 | return callback(error) |
| 2009 | } |
| 2010 | mapData.map = String(result) |
| 2011 | try { |
| 2012 | mapData.map = parseMapToJSON(mapData.map, mapData) |
| 2013 | } catch (error) { |
| 2014 | return callback(error) |
| 2015 | } |
| 2016 | callback(null, mapData) |
| 2017 | }) |
| 2018 | } |
| 2019 | |
| 2020 | function resolveSourceMapSync(code, codeUrl, read) { |
| 2021 | var mapData = resolveSourceMapHelper(code, codeUrl) |
| 2022 | if (!mapData || mapData.map) { |
| 2023 | return mapData |
| 2024 | } |
| 2025 | mapData.map = readSync(read, mapData.url, mapData) |
| 2026 | mapData.map = parseMapToJSON(mapData.map, mapData) |
| 2027 | return mapData |
| 2028 | } |
| 2029 | |
| 2030 | var dataUriRegex = /^data:([^,;]*)(;[^,;]*)*(?:,(.*))?$/ |
| 2031 | |
| 2032 | /** |
| 2033 | * The media type for JSON text is application/json. |
| 2034 | * |
| 2035 | * {@link https://tools.ietf.org/html/rfc8259#section-11 | IANA Considerations } |
| 2036 | * |
| 2037 | * `text/json` is non-standard media type |
| 2038 | */ |
| 2039 | var jsonMimeTypeRegex = /^(?:application|text)\/json$/ |
| 2040 | |
| 2041 | /** |
| 2042 | * JSON text exchanged between systems that are not part of a closed ecosystem |
| 2043 | * MUST be encoded using UTF-8. |
| 2044 | * |
| 2045 | * {@link https://tools.ietf.org/html/rfc8259#section-8.1 | Character Encoding} |
| 2046 | */ |
| 2047 | var jsonCharacterEncoding = "utf-8" |
| 2048 | |
| 2049 | function base64ToBuf(b64) { |
| 2050 | var binStr = atob(b64) |
| 2051 | var len = binStr.length |
| 2052 | var arr = new Uint8Array(len) |
| 2053 | for (var i = 0; i < len; i++) { |
| 2054 | arr[i] = binStr.charCodeAt(i) |
| 2055 | } |
| 2056 | return arr |
| 2057 | } |
| 2058 | |
| 2059 | function decodeBase64String(b64) { |
| 2060 | if (typeof TextDecoder === "undefined" || typeof Uint8Array === "undefined") { |
| 2061 | return atob(b64) |
| 2062 | } |
| 2063 | var buf = base64ToBuf(b64); |
| 2064 | // Note: `decoder.decode` method will throw a `DOMException` with the |
| 2065 | // `"EncodingError"` value when an coding error is found. |
| 2066 | var decoder = new TextDecoder(jsonCharacterEncoding, {fatal: true}) |
| 2067 | return decoder.decode(buf); |
| 2068 | } |
| 2069 | |
| 2070 | function resolveSourceMapHelper(code, codeUrl) { |
| 2071 | var url = sourceMappingURL.getFrom(code) |
| 2072 | if (!url) { |
| 2073 | return null |
| 2074 | } |
| 2075 | |
| 2076 | var dataUri = url.match(dataUriRegex) |
| 2077 | if (dataUri) { |
| 2078 | var mimeType = dataUri[1] || "text/plain" |
| 2079 | var lastParameter = dataUri[2] || "" |
| 2080 | var encoded = dataUri[3] || "" |
| 2081 | var data = { |
| 2082 | sourceMappingURL: url, |
| 2083 | url: null, |
| 2084 | sourcesRelativeTo: codeUrl, |
| 2085 | map: encoded |
| 2086 | } |
| 2087 | if (!jsonMimeTypeRegex.test(mimeType)) { |
| 2088 | var error = new Error("Unuseful data uri mime type: " + mimeType) |
| 2089 | error.sourceMapData = data |
| 2090 | throw error |
| 2091 | } |
| 2092 | try { |
| 2093 | data.map = parseMapToJSON( |
| 2094 | lastParameter === ";base64" ? decodeBase64String(encoded) : decodeURIComponent(encoded), |
| 2095 | data |
| 2096 | ) |
| 2097 | } catch (error) { |
| 2098 | error.sourceMapData = data |
| 2099 | throw error |
| 2100 | } |
| 2101 | return data |
| 2102 | } |
| 2103 | |
| 2104 | var mapUrl = resolveUrl(codeUrl, url) |
| 2105 | return { |
| 2106 | sourceMappingURL: url, |
| 2107 | url: mapUrl, |
| 2108 | sourcesRelativeTo: mapUrl, |
| 2109 | map: null |
| 2110 | } |
| 2111 | } |
| 2112 | |
| 2113 | |
| 2114 | |
| 2115 | function resolveSources(map, mapUrl, read, options, callback) { |
| 2116 | if (typeof options === "function") { |
| 2117 | callback = options |
| 2118 | options = {} |
| 2119 | } |
| 2120 | var pending = map.sources ? map.sources.length : 0 |
| 2121 | var result = { |
| 2122 | sourcesResolved: [], |
| 2123 | sourcesContent: [] |
| 2124 | } |
| 2125 | |
| 2126 | if (pending === 0) { |
| 2127 | callbackAsync(callback, null, result) |
| 2128 | return |
| 2129 | } |
| 2130 | |
| 2131 | var done = function() { |
| 2132 | pending-- |
| 2133 | if (pending === 0) { |
| 2134 | callback(null, result) |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | resolveSourcesHelper(map, mapUrl, options, function(fullUrl, sourceContent, index) { |
| 2139 | result.sourcesResolved[index] = fullUrl |
| 2140 | if (typeof sourceContent === "string") { |
| 2141 | result.sourcesContent[index] = sourceContent |
| 2142 | callbackAsync(done, null) |
| 2143 | } else { |
| 2144 | var readUrl = fullUrl |
| 2145 | read(readUrl, function(error, source) { |
| 2146 | result.sourcesContent[index] = error ? error : String(source) |
| 2147 | done() |
| 2148 | }) |
| 2149 | } |
| 2150 | }) |
| 2151 | } |
| 2152 | |
| 2153 | function resolveSourcesSync(map, mapUrl, read, options) { |
| 2154 | var result = { |
| 2155 | sourcesResolved: [], |
| 2156 | sourcesContent: [] |
| 2157 | } |
| 2158 | |
| 2159 | if (!map.sources || map.sources.length === 0) { |
| 2160 | return result |
| 2161 | } |
| 2162 | |
| 2163 | resolveSourcesHelper(map, mapUrl, options, function(fullUrl, sourceContent, index) { |
| 2164 | result.sourcesResolved[index] = fullUrl |
| 2165 | if (read !== null) { |
| 2166 | if (typeof sourceContent === "string") { |
| 2167 | result.sourcesContent[index] = sourceContent |
| 2168 | } else { |
| 2169 | var readUrl = fullUrl |
| 2170 | try { |
| 2171 | result.sourcesContent[index] = String(read(readUrl)) |
| 2172 | } catch (error) { |
| 2173 | result.sourcesContent[index] = error |
| 2174 | } |
| 2175 | } |
| 2176 | } |
| 2177 | }) |
| 2178 | |
| 2179 | return result |
| 2180 | } |
| 2181 | |
| 2182 | var endingSlash = /\/?$/ |
| 2183 | |
| 2184 | function resolveSourcesHelper(map, mapUrl, options, fn) { |
| 2185 | options = options || {} |
| 2186 | var fullUrl |
| 2187 | var sourceContent |
| 2188 | var sourceRoot |
| 2189 | for (var index = 0, len = map.sources.length; index < len; index++) { |
| 2190 | sourceRoot = null |
| 2191 | if (typeof options.sourceRoot === "string") { |
| 2192 | sourceRoot = options.sourceRoot |
| 2193 | } else if (typeof map.sourceRoot === "string" && options.sourceRoot !== false) { |
| 2194 | sourceRoot = map.sourceRoot |
| 2195 | } |
| 2196 | // If the sourceRoot is the empty string, it is equivalent to not setting |
| 2197 | // the property at all. |
| 2198 | if (sourceRoot === null || sourceRoot === '') { |
| 2199 | fullUrl = resolveUrl(mapUrl, map.sources[index]) |
| 2200 | } else { |
| 2201 | // Make sure that the sourceRoot ends with a slash, so that `/scripts/subdir` becomes |
| 2202 | // `/scripts/subdir/<source>`, not `/scripts/<source>`. Pointing to a file as source root |
| 2203 | // does not make sense. |
| 2204 | fullUrl = resolveUrl(mapUrl, sourceRoot.replace(endingSlash, "/"), map.sources[index]) |
| 2205 | } |
| 2206 | sourceContent = (map.sourcesContent || [])[index] |
| 2207 | fn(fullUrl, sourceContent, index) |
| 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | |
| 2212 | |
| 2213 | function resolve(code, codeUrl, read, options, callback) { |
| 2214 | if (typeof options === "function") { |
| 2215 | callback = options |
| 2216 | options = {} |
| 2217 | } |
| 2218 | if (code === null) { |
| 2219 | var mapUrl = codeUrl |
| 2220 | var data = { |
| 2221 | sourceMappingURL: null, |
| 2222 | url: mapUrl, |
| 2223 | sourcesRelativeTo: mapUrl, |
| 2224 | map: null |
| 2225 | } |
| 2226 | var readUrl = mapUrl |
| 2227 | read(readUrl, function(error, result) { |
| 2228 | if (error) { |
| 2229 | error.sourceMapData = data |
| 2230 | return callback(error) |
| 2231 | } |
| 2232 | data.map = String(result) |
| 2233 | try { |
| 2234 | data.map = parseMapToJSON(data.map, data) |
| 2235 | } catch (error) { |
| 2236 | return callback(error) |
| 2237 | } |
| 2238 | _resolveSources(data) |
| 2239 | }) |
| 2240 | } else { |
| 2241 | resolveSourceMap(code, codeUrl, read, function(error, mapData) { |
| 2242 | if (error) { |
| 2243 | return callback(error) |
| 2244 | } |
| 2245 | if (!mapData) { |
| 2246 | return callback(null, null) |
| 2247 | } |
| 2248 | _resolveSources(mapData) |
| 2249 | }) |
| 2250 | } |
| 2251 | |
| 2252 | function _resolveSources(mapData) { |
| 2253 | resolveSources(mapData.map, mapData.sourcesRelativeTo, read, options, function(error, result) { |
| 2254 | if (error) { |
| 2255 | return callback(error) |
| 2256 | } |
| 2257 | mapData.sourcesResolved = result.sourcesResolved |
| 2258 | mapData.sourcesContent = result.sourcesContent |
| 2259 | callback(null, mapData) |
| 2260 | }) |
| 2261 | } |
| 2262 | } |
| 2263 | |
| 2264 | function resolveSync(code, codeUrl, read, options) { |
| 2265 | var mapData |
| 2266 | if (code === null) { |
| 2267 | var mapUrl = codeUrl |
| 2268 | mapData = { |
| 2269 | sourceMappingURL: null, |
| 2270 | url: mapUrl, |
| 2271 | sourcesRelativeTo: mapUrl, |
| 2272 | map: null |
| 2273 | } |
| 2274 | mapData.map = readSync(read, mapUrl, mapData) |
| 2275 | mapData.map = parseMapToJSON(mapData.map, mapData) |
| 2276 | } else { |
| 2277 | mapData = resolveSourceMapSync(code, codeUrl, read) |
| 2278 | if (!mapData) { |
| 2279 | return null |
| 2280 | } |
| 2281 | } |
| 2282 | var result = resolveSourcesSync(mapData.map, mapData.sourcesRelativeTo, read, options) |
| 2283 | mapData.sourcesResolved = result.sourcesResolved |
| 2284 | mapData.sourcesContent = result.sourcesContent |
| 2285 | return mapData |
| 2286 | } |
| 2287 | |
| 2288 | |
| 2289 | |
| 2290 | return { |
| 2291 | resolveSourceMap: resolveSourceMap, |
| 2292 | resolveSourceMapSync: resolveSourceMapSync, |
| 2293 | resolveSources: resolveSources, |
| 2294 | resolveSourcesSync: resolveSourcesSync, |
| 2295 | resolve: resolve, |
| 2296 | resolveSync: resolveSync, |
| 2297 | parseMapToJSON: parseMapToJSON |
| 2298 | } |
| 2299 | |
| 2300 | })); |
| 2301 | |
| 2302 | }).call(this,require("timers").setImmediate) |
| 2303 | },{"resolve-url":14,"source-map-url":16,"timers":4}],16:[function(require,module,exports){ |
| 2304 | // Copyright 2014 Simon Lydell |
| 2305 | // X11 (“MIT”) Licensed. (See LICENSE.) |
| 2306 | |
| 2307 | void (function(root, factory) { |
| 2308 | if (typeof define === "function" && define.amd) { |
| 2309 | define(factory) |
| 2310 | } else if (typeof exports === "object") { |
| 2311 | module.exports = factory() |
| 2312 | } else { |
| 2313 | root.sourceMappingURL = factory() |
| 2314 | } |
| 2315 | }(this, function() { |
| 2316 | |
| 2317 | var innerRegex = /[#@] sourceMappingURL=([^\s'"]*)/ |
| 2318 | |
| 2319 | var regex = RegExp( |
| 2320 | "(?:" + |
| 2321 | "/\\*" + |
| 2322 | "(?:\\s*\r?\n(?://)?)?" + |
| 2323 | "(?:" + innerRegex.source + ")" + |
| 2324 | "\\s*" + |
| 2325 | "\\*/" + |
| 2326 | "|" + |
| 2327 | "//(?:" + innerRegex.source + ")" + |
| 2328 | ")" + |
| 2329 | "\\s*" |
| 2330 | ) |
| 2331 | |
| 2332 | return { |
| 2333 | |
| 2334 | regex: regex, |
| 2335 | _innerRegex: innerRegex, |
| 2336 | |
| 2337 | getFrom: function(code) { |
| 2338 | var match = code.match(regex) |
| 2339 | return (match ? match[1] || match[2] || "" : null) |
| 2340 | }, |
| 2341 | |
| 2342 | existsIn: function(code) { |
| 2343 | return regex.test(code) |
| 2344 | }, |
| 2345 | |
| 2346 | removeFrom: function(code) { |
| 2347 | return code.replace(regex, "") |
| 2348 | }, |
| 2349 | |
| 2350 | insertBefore: function(code, string) { |
| 2351 | var match = code.match(regex) |
| 2352 | if (match) { |
| 2353 | return code.slice(0, match.index) + string + code.slice(match.index) |
| 2354 | } else { |
| 2355 | return code + string |
| 2356 | } |
| 2357 | } |
| 2358 | } |
| 2359 | |
| 2360 | })); |
| 2361 | |
| 2362 | },{}],17:[function(require,module,exports){ |
| 2363 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 2364 | /* |
| 2365 | * Copyright 2011 Mozilla Foundation and contributors |
| 2366 | * Licensed under the New BSD license. See LICENSE or: |
| 2367 | * http://opensource.org/licenses/BSD-3-Clause |
| 2368 | */ |
| 2369 | |
| 2370 | var util = require('./util'); |
| 2371 | var has = Object.prototype.hasOwnProperty; |
| 2372 | var hasNativeMap = typeof Map !== "undefined"; |
| 2373 | |
| 2374 | /** |
| 2375 | * A data structure which is a combination of an array and a set. Adding a new |
| 2376 | * member is O(1), testing for membership is O(1), and finding the index of an |
| 2377 | * element is O(1). Removing elements from the set is not supported. Only |
| 2378 | * strings are supported for membership. |
| 2379 | */ |
| 2380 | function ArraySet() { |
| 2381 | this._array = []; |
| 2382 | this._set = hasNativeMap ? new Map() : Object.create(null); |
| 2383 | } |
| 2384 | |
| 2385 | /** |
| 2386 | * Static method for creating ArraySet instances from an existing array. |
| 2387 | */ |
| 2388 | ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { |
| 2389 | var set = new ArraySet(); |
| 2390 | for (var i = 0, len = aArray.length; i < len; i++) { |
| 2391 | set.add(aArray[i], aAllowDuplicates); |
| 2392 | } |
| 2393 | return set; |
| 2394 | }; |
| 2395 | |
| 2396 | /** |
| 2397 | * Return how many unique items are in this ArraySet. If duplicates have been |
| 2398 | * added, than those do not count towards the size. |
| 2399 | * |
| 2400 | * @returns Number |
| 2401 | */ |
| 2402 | ArraySet.prototype.size = function ArraySet_size() { |
| 2403 | return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length; |
| 2404 | }; |
| 2405 | |
| 2406 | /** |
| 2407 | * Add the given string to this set. |
| 2408 | * |
| 2409 | * @param String aStr |
| 2410 | */ |
| 2411 | ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { |
| 2412 | var sStr = hasNativeMap ? aStr : util.toSetString(aStr); |
| 2413 | var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr); |
| 2414 | var idx = this._array.length; |
| 2415 | if (!isDuplicate || aAllowDuplicates) { |
| 2416 | this._array.push(aStr); |
| 2417 | } |
| 2418 | if (!isDuplicate) { |
| 2419 | if (hasNativeMap) { |
| 2420 | this._set.set(aStr, idx); |
| 2421 | } else { |
| 2422 | this._set[sStr] = idx; |
| 2423 | } |
| 2424 | } |
| 2425 | }; |
| 2426 | |
| 2427 | /** |
| 2428 | * Is the given string a member of this set? |
| 2429 | * |
| 2430 | * @param String aStr |
| 2431 | */ |
| 2432 | ArraySet.prototype.has = function ArraySet_has(aStr) { |
| 2433 | if (hasNativeMap) { |
| 2434 | return this._set.has(aStr); |
| 2435 | } else { |
| 2436 | var sStr = util.toSetString(aStr); |
| 2437 | return has.call(this._set, sStr); |
| 2438 | } |
| 2439 | }; |
| 2440 | |
| 2441 | /** |
| 2442 | * What is the index of the given string in the array? |
| 2443 | * |
| 2444 | * @param String aStr |
| 2445 | */ |
| 2446 | ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { |
| 2447 | if (hasNativeMap) { |
| 2448 | var idx = this._set.get(aStr); |
| 2449 | if (idx >= 0) { |
| 2450 | return idx; |
| 2451 | } |
| 2452 | } else { |
| 2453 | var sStr = util.toSetString(aStr); |
| 2454 | if (has.call(this._set, sStr)) { |
| 2455 | return this._set[sStr]; |
| 2456 | } |
| 2457 | } |
| 2458 | |
| 2459 | throw new Error('"' + aStr + '" is not in the set.'); |
| 2460 | }; |
| 2461 | |
| 2462 | /** |
| 2463 | * What is the element at the given index? |
| 2464 | * |
| 2465 | * @param Number aIdx |
| 2466 | */ |
| 2467 | ArraySet.prototype.at = function ArraySet_at(aIdx) { |
| 2468 | if (aIdx >= 0 && aIdx < this._array.length) { |
| 2469 | return this._array[aIdx]; |
| 2470 | } |
| 2471 | throw new Error('No element indexed by ' + aIdx); |
| 2472 | }; |
| 2473 | |
| 2474 | /** |
| 2475 | * Returns the array representation of this set (which has the proper indices |
| 2476 | * indicated by indexOf). Note that this is a copy of the internal array used |
| 2477 | * for storing the members so that no one can mess with internal state. |
| 2478 | */ |
| 2479 | ArraySet.prototype.toArray = function ArraySet_toArray() { |
| 2480 | return this._array.slice(); |
| 2481 | }; |
| 2482 | |
| 2483 | exports.ArraySet = ArraySet; |
| 2484 | |
| 2485 | },{"./util":26}],18:[function(require,module,exports){ |
| 2486 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 2487 | /* |
| 2488 | * Copyright 2011 Mozilla Foundation and contributors |
| 2489 | * Licensed under the New BSD license. See LICENSE or: |
| 2490 | * http://opensource.org/licenses/BSD-3-Clause |
| 2491 | * |
| 2492 | * Based on the Base 64 VLQ implementation in Closure Compiler: |
| 2493 | * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java |
| 2494 | * |
| 2495 | * Copyright 2011 The Closure Compiler Authors. All rights reserved. |
| 2496 | * Redistribution and use in source and binary forms, with or without |
| 2497 | * modification, are permitted provided that the following conditions are |
| 2498 | * met: |
| 2499 | * |
| 2500 | * * Redistributions of source code must retain the above copyright |
| 2501 | * notice, this list of conditions and the following disclaimer. |
| 2502 | * * Redistributions in binary form must reproduce the above |
| 2503 | * copyright notice, this list of conditions and the following |
| 2504 | * disclaimer in the documentation and/or other materials provided |
| 2505 | * with the distribution. |
| 2506 | * * Neither the name of Google Inc. nor the names of its |
| 2507 | * contributors may be used to endorse or promote products derived |
| 2508 | * from this software without specific prior written permission. |
| 2509 | * |
| 2510 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 2511 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 2512 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 2513 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 2514 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 2515 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 2516 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 2517 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 2518 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 2519 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 2520 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 2521 | */ |
| 2522 | |
| 2523 | var base64 = require('./base64'); |
| 2524 | |
| 2525 | // A single base 64 digit can contain 6 bits of data. For the base 64 variable |
| 2526 | // length quantities we use in the source map spec, the first bit is the sign, |
| 2527 | // the next four bits are the actual value, and the 6th bit is the |
| 2528 | // continuation bit. The continuation bit tells us whether there are more |
| 2529 | // digits in this value following this digit. |
| 2530 | // |
| 2531 | // Continuation |
| 2532 | // | Sign |
| 2533 | // | | |
| 2534 | // V V |
| 2535 | // 101011 |
| 2536 | |
| 2537 | var VLQ_BASE_SHIFT = 5; |
| 2538 | |
| 2539 | // binary: 100000 |
| 2540 | var VLQ_BASE = 1 << VLQ_BASE_SHIFT; |
| 2541 | |
| 2542 | // binary: 011111 |
| 2543 | var VLQ_BASE_MASK = VLQ_BASE - 1; |
| 2544 | |
| 2545 | // binary: 100000 |
| 2546 | var VLQ_CONTINUATION_BIT = VLQ_BASE; |
| 2547 | |
| 2548 | /** |
| 2549 | * Converts from a two-complement value to a value where the sign bit is |
| 2550 | * placed in the least significant bit. For example, as decimals: |
| 2551 | * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) |
| 2552 | * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) |
| 2553 | */ |
| 2554 | function toVLQSigned(aValue) { |
| 2555 | return aValue < 0 |
| 2556 | ? ((-aValue) << 1) + 1 |
| 2557 | : (aValue << 1) + 0; |
| 2558 | } |
| 2559 | |
| 2560 | /** |
| 2561 | * Converts to a two-complement value from a value where the sign bit is |
| 2562 | * placed in the least significant bit. For example, as decimals: |
| 2563 | * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 |
| 2564 | * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 |
| 2565 | */ |
| 2566 | function fromVLQSigned(aValue) { |
| 2567 | var isNegative = (aValue & 1) === 1; |
| 2568 | var shifted = aValue >> 1; |
| 2569 | return isNegative |
| 2570 | ? -shifted |
| 2571 | : shifted; |
| 2572 | } |
| 2573 | |
| 2574 | /** |
| 2575 | * Returns the base 64 VLQ encoded value. |
| 2576 | */ |
| 2577 | exports.encode = function base64VLQ_encode(aValue) { |
| 2578 | var encoded = ""; |
| 2579 | var digit; |
| 2580 | |
| 2581 | var vlq = toVLQSigned(aValue); |
| 2582 | |
| 2583 | do { |
| 2584 | digit = vlq & VLQ_BASE_MASK; |
| 2585 | vlq >>>= VLQ_BASE_SHIFT; |
| 2586 | if (vlq > 0) { |
| 2587 | // There are still more digits in this value, so we must make sure the |
| 2588 | // continuation bit is marked. |
| 2589 | digit |= VLQ_CONTINUATION_BIT; |
| 2590 | } |
| 2591 | encoded += base64.encode(digit); |
| 2592 | } while (vlq > 0); |
| 2593 | |
| 2594 | return encoded; |
| 2595 | }; |
| 2596 | |
| 2597 | /** |
| 2598 | * Decodes the next base 64 VLQ value from the given string and returns the |
| 2599 | * value and the rest of the string via the out parameter. |
| 2600 | */ |
| 2601 | exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) { |
| 2602 | var strLen = aStr.length; |
| 2603 | var result = 0; |
| 2604 | var shift = 0; |
| 2605 | var continuation, digit; |
| 2606 | |
| 2607 | do { |
| 2608 | if (aIndex >= strLen) { |
| 2609 | throw new Error("Expected more digits in base 64 VLQ value."); |
| 2610 | } |
| 2611 | |
| 2612 | digit = base64.decode(aStr.charCodeAt(aIndex++)); |
| 2613 | if (digit === -1) { |
| 2614 | throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1)); |
| 2615 | } |
| 2616 | |
| 2617 | continuation = !!(digit & VLQ_CONTINUATION_BIT); |
| 2618 | digit &= VLQ_BASE_MASK; |
| 2619 | result = result + (digit << shift); |
| 2620 | shift += VLQ_BASE_SHIFT; |
| 2621 | } while (continuation); |
| 2622 | |
| 2623 | aOutParam.value = fromVLQSigned(result); |
| 2624 | aOutParam.rest = aIndex; |
| 2625 | }; |
| 2626 | |
| 2627 | },{"./base64":19}],19:[function(require,module,exports){ |
| 2628 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 2629 | /* |
| 2630 | * Copyright 2011 Mozilla Foundation and contributors |
| 2631 | * Licensed under the New BSD license. See LICENSE or: |
| 2632 | * http://opensource.org/licenses/BSD-3-Clause |
| 2633 | */ |
| 2634 | |
| 2635 | var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); |
| 2636 | |
| 2637 | /** |
| 2638 | * Encode an integer in the range of 0 to 63 to a single base 64 digit. |
| 2639 | */ |
| 2640 | exports.encode = function (number) { |
| 2641 | if (0 <= number && number < intToCharMap.length) { |
| 2642 | return intToCharMap[number]; |
| 2643 | } |
| 2644 | throw new TypeError("Must be between 0 and 63: " + number); |
| 2645 | }; |
| 2646 | |
| 2647 | /** |
| 2648 | * Decode a single base 64 character code digit to an integer. Returns -1 on |
| 2649 | * failure. |
| 2650 | */ |
| 2651 | exports.decode = function (charCode) { |
| 2652 | var bigA = 65; // 'A' |
| 2653 | var bigZ = 90; // 'Z' |
| 2654 | |
| 2655 | var littleA = 97; // 'a' |
| 2656 | var littleZ = 122; // 'z' |
| 2657 | |
| 2658 | var zero = 48; // '0' |
| 2659 | var nine = 57; // '9' |
| 2660 | |
| 2661 | var plus = 43; // '+' |
| 2662 | var slash = 47; // '/' |
| 2663 | |
| 2664 | var littleOffset = 26; |
| 2665 | var numberOffset = 52; |
| 2666 | |
| 2667 | // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ |
| 2668 | if (bigA <= charCode && charCode <= bigZ) { |
| 2669 | return (charCode - bigA); |
| 2670 | } |
| 2671 | |
| 2672 | // 26 - 51: abcdefghijklmnopqrstuvwxyz |
| 2673 | if (littleA <= charCode && charCode <= littleZ) { |
| 2674 | return (charCode - littleA + littleOffset); |
| 2675 | } |
| 2676 | |
| 2677 | // 52 - 61: 0123456789 |
| 2678 | if (zero <= charCode && charCode <= nine) { |
| 2679 | return (charCode - zero + numberOffset); |
| 2680 | } |
| 2681 | |
| 2682 | // 62: + |
| 2683 | if (charCode == plus) { |
| 2684 | return 62; |
| 2685 | } |
| 2686 | |
| 2687 | // 63: / |
| 2688 | if (charCode == slash) { |
| 2689 | return 63; |
| 2690 | } |
| 2691 | |
| 2692 | // Invalid base64 digit. |
| 2693 | return -1; |
| 2694 | }; |
| 2695 | |
| 2696 | },{}],20:[function(require,module,exports){ |
| 2697 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 2698 | /* |
| 2699 | * Copyright 2011 Mozilla Foundation and contributors |
| 2700 | * Licensed under the New BSD license. See LICENSE or: |
| 2701 | * http://opensource.org/licenses/BSD-3-Clause |
| 2702 | */ |
| 2703 | |
| 2704 | exports.GREATEST_LOWER_BOUND = 1; |
| 2705 | exports.LEAST_UPPER_BOUND = 2; |
| 2706 | |
| 2707 | /** |
| 2708 | * Recursive implementation of binary search. |
| 2709 | * |
| 2710 | * @param aLow Indices here and lower do not contain the needle. |
| 2711 | * @param aHigh Indices here and higher do not contain the needle. |
| 2712 | * @param aNeedle The element being searched for. |
| 2713 | * @param aHaystack The non-empty array being searched. |
| 2714 | * @param aCompare Function which takes two elements and returns -1, 0, or 1. |
| 2715 | * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or |
| 2716 | * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the |
| 2717 | * closest element that is smaller than or greater than the one we are |
| 2718 | * searching for, respectively, if the exact element cannot be found. |
| 2719 | */ |
| 2720 | function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) { |
| 2721 | // This function terminates when one of the following is true: |
| 2722 | // |
| 2723 | // 1. We find the exact element we are looking for. |
| 2724 | // |
| 2725 | // 2. We did not find the exact element, but we can return the index of |
| 2726 | // the next-closest element. |
| 2727 | // |
| 2728 | // 3. We did not find the exact element, and there is no next-closest |
| 2729 | // element than the one we are searching for, so we return -1. |
| 2730 | var mid = Math.floor((aHigh - aLow) / 2) + aLow; |
| 2731 | var cmp = aCompare(aNeedle, aHaystack[mid], true); |
| 2732 | if (cmp === 0) { |
| 2733 | // Found the element we are looking for. |
| 2734 | return mid; |
| 2735 | } |
| 2736 | else if (cmp > 0) { |
| 2737 | // Our needle is greater than aHaystack[mid]. |
| 2738 | if (aHigh - mid > 1) { |
| 2739 | // The element is in the upper half. |
| 2740 | return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias); |
| 2741 | } |
| 2742 | |
| 2743 | // The exact needle element was not found in this haystack. Determine if |
| 2744 | // we are in termination case (3) or (2) and return the appropriate thing. |
| 2745 | if (aBias == exports.LEAST_UPPER_BOUND) { |
| 2746 | return aHigh < aHaystack.length ? aHigh : -1; |
| 2747 | } else { |
| 2748 | return mid; |
| 2749 | } |
| 2750 | } |
| 2751 | else { |
| 2752 | // Our needle is less than aHaystack[mid]. |
| 2753 | if (mid - aLow > 1) { |
| 2754 | // The element is in the lower half. |
| 2755 | return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); |
| 2756 | } |
| 2757 | |
| 2758 | // we are in termination case (3) or (2) and return the appropriate thing. |
| 2759 | if (aBias == exports.LEAST_UPPER_BOUND) { |
| 2760 | return mid; |
| 2761 | } else { |
| 2762 | return aLow < 0 ? -1 : aLow; |
| 2763 | } |
| 2764 | } |
| 2765 | } |
| 2766 | |
| 2767 | /** |
| 2768 | * This is an implementation of binary search which will always try and return |
| 2769 | * the index of the closest element if there is no exact hit. This is because |
| 2770 | * mappings between original and generated line/col pairs are single points, |
| 2771 | * and there is an implicit region between each of them, so a miss just means |
| 2772 | * that you aren't on the very start of a region. |
| 2773 | * |
| 2774 | * @param aNeedle The element you are looking for. |
| 2775 | * @param aHaystack The array that is being searched. |
| 2776 | * @param aCompare A function which takes the needle and an element in the |
| 2777 | * array and returns -1, 0, or 1 depending on whether the needle is less |
| 2778 | * than, equal to, or greater than the element, respectively. |
| 2779 | * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or |
| 2780 | * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the |
| 2781 | * closest element that is smaller than or greater than the one we are |
| 2782 | * searching for, respectively, if the exact element cannot be found. |
| 2783 | * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'. |
| 2784 | */ |
| 2785 | exports.search = function search(aNeedle, aHaystack, aCompare, aBias) { |
| 2786 | if (aHaystack.length === 0) { |
| 2787 | return -1; |
| 2788 | } |
| 2789 | |
| 2790 | var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, |
| 2791 | aCompare, aBias || exports.GREATEST_LOWER_BOUND); |
| 2792 | if (index < 0) { |
| 2793 | return -1; |
| 2794 | } |
| 2795 | |
| 2796 | // We have found either the exact element, or the next-closest element than |
| 2797 | // the one we are searching for. However, there may be more than one such |
| 2798 | // element. Make sure we always return the smallest of these. |
| 2799 | while (index - 1 >= 0) { |
| 2800 | if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) { |
| 2801 | break; |
| 2802 | } |
| 2803 | --index; |
| 2804 | } |
| 2805 | |
| 2806 | return index; |
| 2807 | }; |
| 2808 | |
| 2809 | },{}],21:[function(require,module,exports){ |
| 2810 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 2811 | /* |
| 2812 | * Copyright 2014 Mozilla Foundation and contributors |
| 2813 | * Licensed under the New BSD license. See LICENSE or: |
| 2814 | * http://opensource.org/licenses/BSD-3-Clause |
| 2815 | */ |
| 2816 | |
| 2817 | var util = require('./util'); |
| 2818 | |
| 2819 | /** |
| 2820 | * Determine whether mappingB is after mappingA with respect to generated |
| 2821 | * position. |
| 2822 | */ |
| 2823 | function generatedPositionAfter(mappingA, mappingB) { |
| 2824 | // Optimized for most common case |
| 2825 | var lineA = mappingA.generatedLine; |
| 2826 | var lineB = mappingB.generatedLine; |
| 2827 | var columnA = mappingA.generatedColumn; |
| 2828 | var columnB = mappingB.generatedColumn; |
| 2829 | return lineB > lineA || lineB == lineA && columnB >= columnA || |
| 2830 | util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0; |
| 2831 | } |
| 2832 | |
| 2833 | /** |
| 2834 | * A data structure to provide a sorted view of accumulated mappings in a |
| 2835 | * performance conscious manner. It trades a neglibable overhead in general |
| 2836 | * case for a large speedup in case of mappings being added in order. |
| 2837 | */ |
| 2838 | function MappingList() { |
| 2839 | this._array = []; |
| 2840 | this._sorted = true; |
| 2841 | // Serves as infimum |
| 2842 | this._last = {generatedLine: -1, generatedColumn: 0}; |
| 2843 | } |
| 2844 | |
| 2845 | /** |
| 2846 | * Iterate through internal items. This method takes the same arguments that |
| 2847 | * `Array.prototype.forEach` takes. |
| 2848 | * |
| 2849 | * NOTE: The order of the mappings is NOT guaranteed. |
| 2850 | */ |
| 2851 | MappingList.prototype.unsortedForEach = |
| 2852 | function MappingList_forEach(aCallback, aThisArg) { |
| 2853 | this._array.forEach(aCallback, aThisArg); |
| 2854 | }; |
| 2855 | |
| 2856 | /** |
| 2857 | * Add the given source mapping. |
| 2858 | * |
| 2859 | * @param Object aMapping |
| 2860 | */ |
| 2861 | MappingList.prototype.add = function MappingList_add(aMapping) { |
| 2862 | if (generatedPositionAfter(this._last, aMapping)) { |
| 2863 | this._last = aMapping; |
| 2864 | this._array.push(aMapping); |
| 2865 | } else { |
| 2866 | this._sorted = false; |
| 2867 | this._array.push(aMapping); |
| 2868 | } |
| 2869 | }; |
| 2870 | |
| 2871 | /** |
| 2872 | * Returns the flat, sorted array of mappings. The mappings are sorted by |
| 2873 | * generated position. |
| 2874 | * |
| 2875 | * WARNING: This method returns internal data without copying, for |
| 2876 | * performance. The return value must NOT be mutated, and should be treated as |
| 2877 | * an immutable borrow. If you want to take ownership, you must make your own |
| 2878 | * copy. |
| 2879 | */ |
| 2880 | MappingList.prototype.toArray = function MappingList_toArray() { |
| 2881 | if (!this._sorted) { |
| 2882 | this._array.sort(util.compareByGeneratedPositionsInflated); |
| 2883 | this._sorted = true; |
| 2884 | } |
| 2885 | return this._array; |
| 2886 | }; |
| 2887 | |
| 2888 | exports.MappingList = MappingList; |
| 2889 | |
| 2890 | },{"./util":26}],22:[function(require,module,exports){ |
| 2891 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 2892 | /* |
| 2893 | * Copyright 2011 Mozilla Foundation and contributors |
| 2894 | * Licensed under the New BSD license. See LICENSE or: |
| 2895 | * http://opensource.org/licenses/BSD-3-Clause |
| 2896 | */ |
| 2897 | |
| 2898 | // It turns out that some (most?) JavaScript engines don't self-host |
| 2899 | // `Array.prototype.sort`. This makes sense because C++ will likely remain |
| 2900 | // faster than JS when doing raw CPU-intensive sorting. However, when using a |
| 2901 | // custom comparator function, calling back and forth between the VM's C++ and |
| 2902 | // JIT'd JS is rather slow *and* loses JIT type information, resulting in |
| 2903 | // worse generated code for the comparator function than would be optimal. In |
| 2904 | // fact, when sorting with a comparator, these costs outweigh the benefits of |
| 2905 | // sorting in C++. By using our own JS-implemented Quick Sort (below), we get |
| 2906 | // a ~3500ms mean speed-up in `bench/bench.html`. |
| 2907 | |
| 2908 | /** |
| 2909 | * Swap the elements indexed by `x` and `y` in the array `ary`. |
| 2910 | * |
| 2911 | * @param {Array} ary |
| 2912 | * The array. |
| 2913 | * @param {Number} x |
| 2914 | * The index of the first item. |
| 2915 | * @param {Number} y |
| 2916 | * The index of the second item. |
| 2917 | */ |
| 2918 | function swap(ary, x, y) { |
| 2919 | var temp = ary[x]; |
| 2920 | ary[x] = ary[y]; |
| 2921 | ary[y] = temp; |
| 2922 | } |
| 2923 | |
| 2924 | /** |
| 2925 | * Returns a random integer within the range `low .. high` inclusive. |
| 2926 | * |
| 2927 | * @param {Number} low |
| 2928 | * The lower bound on the range. |
| 2929 | * @param {Number} high |
| 2930 | * The upper bound on the range. |
| 2931 | */ |
| 2932 | function randomIntInRange(low, high) { |
| 2933 | return Math.round(low + (Math.random() * (high - low))); |
| 2934 | } |
| 2935 | |
| 2936 | /** |
| 2937 | * The Quick Sort algorithm. |
| 2938 | * |
| 2939 | * @param {Array} ary |
| 2940 | * An array to sort. |
| 2941 | * @param {function} comparator |
| 2942 | * Function to use to compare two items. |
| 2943 | * @param {Number} p |
| 2944 | * Start index of the array |
| 2945 | * @param {Number} r |
| 2946 | * End index of the array |
| 2947 | */ |
| 2948 | function doQuickSort(ary, comparator, p, r) { |
| 2949 | // If our lower bound is less than our upper bound, we (1) partition the |
| 2950 | // array into two pieces and (2) recurse on each half. If it is not, this is |
| 2951 | // the empty array and our base case. |
| 2952 | |
| 2953 | if (p < r) { |
| 2954 | // (1) Partitioning. |
| 2955 | // |
| 2956 | // The partitioning chooses a pivot between `p` and `r` and moves all |
| 2957 | // elements that are less than or equal to the pivot to the before it, and |
| 2958 | // all the elements that are greater than it after it. The effect is that |
| 2959 | // once partition is done, the pivot is in the exact place it will be when |
| 2960 | // the array is put in sorted order, and it will not need to be moved |
| 2961 | // again. This runs in O(n) time. |
| 2962 | |
| 2963 | // Always choose a random pivot so that an input array which is reverse |
| 2964 | // sorted does not cause O(n^2) running time. |
| 2965 | var pivotIndex = randomIntInRange(p, r); |
| 2966 | var i = p - 1; |
| 2967 | |
| 2968 | swap(ary, pivotIndex, r); |
| 2969 | var pivot = ary[r]; |
| 2970 | |
| 2971 | // Immediately after `j` is incremented in this loop, the following hold |
| 2972 | // true: |
| 2973 | // |
| 2974 | // * Every element in `ary[p .. i]` is less than or equal to the pivot. |
| 2975 | // |
| 2976 | // * Every element in `ary[i+1 .. j-1]` is greater than the pivot. |
| 2977 | for (var j = p; j < r; j++) { |
| 2978 | if (comparator(ary[j], pivot) <= 0) { |
| 2979 | i += 1; |
| 2980 | swap(ary, i, j); |
| 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | swap(ary, i + 1, j); |
| 2985 | var q = i + 1; |
| 2986 | |
| 2987 | // (2) Recurse on each half. |
| 2988 | |
| 2989 | doQuickSort(ary, comparator, p, q - 1); |
| 2990 | doQuickSort(ary, comparator, q + 1, r); |
| 2991 | } |
| 2992 | } |
| 2993 | |
| 2994 | /** |
| 2995 | * Sort the given array in-place with the given comparator function. |
| 2996 | * |
| 2997 | * @param {Array} ary |
| 2998 | * An array to sort. |
| 2999 | * @param {function} comparator |
| 3000 | * Function to use to compare two items. |
| 3001 | */ |
| 3002 | exports.quickSort = function (ary, comparator) { |
| 3003 | doQuickSort(ary, comparator, 0, ary.length - 1); |
| 3004 | }; |
| 3005 | |
| 3006 | },{}],23:[function(require,module,exports){ |
| 3007 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 3008 | /* |
| 3009 | * Copyright 2011 Mozilla Foundation and contributors |
| 3010 | * Licensed under the New BSD license. See LICENSE or: |
| 3011 | * http://opensource.org/licenses/BSD-3-Clause |
| 3012 | */ |
| 3013 | |
| 3014 | var util = require('./util'); |
| 3015 | var binarySearch = require('./binary-search'); |
| 3016 | var ArraySet = require('./array-set').ArraySet; |
| 3017 | var base64VLQ = require('./base64-vlq'); |
| 3018 | var quickSort = require('./quick-sort').quickSort; |
| 3019 | |
| 3020 | function SourceMapConsumer(aSourceMap, aSourceMapURL) { |
| 3021 | var sourceMap = aSourceMap; |
| 3022 | if (typeof aSourceMap === 'string') { |
| 3023 | sourceMap = util.parseSourceMapInput(aSourceMap); |
| 3024 | } |
| 3025 | |
| 3026 | return sourceMap.sections != null |
| 3027 | ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL) |
| 3028 | : new BasicSourceMapConsumer(sourceMap, aSourceMapURL); |
| 3029 | } |
| 3030 | |
| 3031 | SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) { |
| 3032 | return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL); |
| 3033 | } |
| 3034 | |
| 3035 | /** |
| 3036 | * The version of the source mapping spec that we are consuming. |
| 3037 | */ |
| 3038 | SourceMapConsumer.prototype._version = 3; |
| 3039 | |
| 3040 | // `__generatedMappings` and `__originalMappings` are arrays that hold the |
| 3041 | // parsed mapping coordinates from the source map's "mappings" attribute. They |
| 3042 | // are lazily instantiated, accessed via the `_generatedMappings` and |
| 3043 | // `_originalMappings` getters respectively, and we only parse the mappings |
| 3044 | // and create these arrays once queried for a source location. We jump through |
| 3045 | // these hoops because there can be many thousands of mappings, and parsing |
| 3046 | // them is expensive, so we only want to do it if we must. |
| 3047 | // |
| 3048 | // Each object in the arrays is of the form: |
| 3049 | // |
| 3050 | // { |
| 3051 | // generatedLine: The line number in the generated code, |
| 3052 | // generatedColumn: The column number in the generated code, |
| 3053 | // source: The path to the original source file that generated this |
| 3054 | // chunk of code, |
| 3055 | // originalLine: The line number in the original source that |
| 3056 | // corresponds to this chunk of generated code, |
| 3057 | // originalColumn: The column number in the original source that |
| 3058 | // corresponds to this chunk of generated code, |
| 3059 | // name: The name of the original symbol which generated this chunk of |
| 3060 | // code. |
| 3061 | // } |
| 3062 | // |
| 3063 | // All properties except for `generatedLine` and `generatedColumn` can be |
| 3064 | // `null`. |
| 3065 | // |
| 3066 | // `_generatedMappings` is ordered by the generated positions. |
| 3067 | // |
| 3068 | // `_originalMappings` is ordered by the original positions. |
| 3069 | |
| 3070 | SourceMapConsumer.prototype.__generatedMappings = null; |
| 3071 | Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', { |
| 3072 | configurable: true, |
| 3073 | enumerable: true, |
| 3074 | get: function () { |
| 3075 | if (!this.__generatedMappings) { |
| 3076 | this._parseMappings(this._mappings, this.sourceRoot); |
| 3077 | } |
| 3078 | |
| 3079 | return this.__generatedMappings; |
| 3080 | } |
| 3081 | }); |
| 3082 | |
| 3083 | SourceMapConsumer.prototype.__originalMappings = null; |
| 3084 | Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', { |
| 3085 | configurable: true, |
| 3086 | enumerable: true, |
| 3087 | get: function () { |
| 3088 | if (!this.__originalMappings) { |
| 3089 | this._parseMappings(this._mappings, this.sourceRoot); |
| 3090 | } |
| 3091 | |
| 3092 | return this.__originalMappings; |
| 3093 | } |
| 3094 | }); |
| 3095 | |
| 3096 | SourceMapConsumer.prototype._charIsMappingSeparator = |
| 3097 | function SourceMapConsumer_charIsMappingSeparator(aStr, index) { |
| 3098 | var c = aStr.charAt(index); |
| 3099 | return c === ";" || c === ","; |
| 3100 | }; |
| 3101 | |
| 3102 | /** |
| 3103 | * Parse the mappings in a string in to a data structure which we can easily |
| 3104 | * query (the ordered arrays in the `this.__generatedMappings` and |
| 3105 | * `this.__originalMappings` properties). |
| 3106 | */ |
| 3107 | SourceMapConsumer.prototype._parseMappings = |
| 3108 | function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { |
| 3109 | throw new Error("Subclasses must implement _parseMappings"); |
| 3110 | }; |
| 3111 | |
| 3112 | SourceMapConsumer.GENERATED_ORDER = 1; |
| 3113 | SourceMapConsumer.ORIGINAL_ORDER = 2; |
| 3114 | |
| 3115 | SourceMapConsumer.GREATEST_LOWER_BOUND = 1; |
| 3116 | SourceMapConsumer.LEAST_UPPER_BOUND = 2; |
| 3117 | |
| 3118 | /** |
| 3119 | * Iterate over each mapping between an original source/line/column and a |
| 3120 | * generated line/column in this source map. |
| 3121 | * |
| 3122 | * @param Function aCallback |
| 3123 | * The function that is called with each mapping. |
| 3124 | * @param Object aContext |
| 3125 | * Optional. If specified, this object will be the value of `this` every |
| 3126 | * time that `aCallback` is called. |
| 3127 | * @param aOrder |
| 3128 | * Either `SourceMapConsumer.GENERATED_ORDER` or |
| 3129 | * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to |
| 3130 | * iterate over the mappings sorted by the generated file's line/column |
| 3131 | * order or the original's source/line/column order, respectively. Defaults to |
| 3132 | * `SourceMapConsumer.GENERATED_ORDER`. |
| 3133 | */ |
| 3134 | SourceMapConsumer.prototype.eachMapping = |
| 3135 | function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) { |
| 3136 | var context = aContext || null; |
| 3137 | var order = aOrder || SourceMapConsumer.GENERATED_ORDER; |
| 3138 | |
| 3139 | var mappings; |
| 3140 | switch (order) { |
| 3141 | case SourceMapConsumer.GENERATED_ORDER: |
| 3142 | mappings = this._generatedMappings; |
| 3143 | break; |
| 3144 | case SourceMapConsumer.ORIGINAL_ORDER: |
| 3145 | mappings = this._originalMappings; |
| 3146 | break; |
| 3147 | default: |
| 3148 | throw new Error("Unknown order of iteration."); |
| 3149 | } |
| 3150 | |
| 3151 | var sourceRoot = this.sourceRoot; |
| 3152 | mappings.map(function (mapping) { |
| 3153 | var source = mapping.source === null ? null : this._sources.at(mapping.source); |
| 3154 | source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL); |
| 3155 | return { |
| 3156 | source: source, |
| 3157 | generatedLine: mapping.generatedLine, |
| 3158 | generatedColumn: mapping.generatedColumn, |
| 3159 | originalLine: mapping.originalLine, |
| 3160 | originalColumn: mapping.originalColumn, |
| 3161 | name: mapping.name === null ? null : this._names.at(mapping.name) |
| 3162 | }; |
| 3163 | }, this).forEach(aCallback, context); |
| 3164 | }; |
| 3165 | |
| 3166 | /** |
| 3167 | * Returns all generated line and column information for the original source, |
| 3168 | * line, and column provided. If no column is provided, returns all mappings |
| 3169 | * corresponding to a either the line we are searching for or the next |
| 3170 | * closest line that has any mappings. Otherwise, returns all mappings |
| 3171 | * corresponding to the given line and either the column we are searching for |
| 3172 | * or the next closest column that has any offsets. |
| 3173 | * |
| 3174 | * The only argument is an object with the following properties: |
| 3175 | * |
| 3176 | * - source: The filename of the original source. |
| 3177 | * - line: The line number in the original source. The line number is 1-based. |
| 3178 | * - column: Optional. the column number in the original source. |
| 3179 | * The column number is 0-based. |
| 3180 | * |
| 3181 | * and an array of objects is returned, each with the following properties: |
| 3182 | * |
| 3183 | * - line: The line number in the generated source, or null. The |
| 3184 | * line number is 1-based. |
| 3185 | * - column: The column number in the generated source, or null. |
| 3186 | * The column number is 0-based. |
| 3187 | */ |
| 3188 | SourceMapConsumer.prototype.allGeneratedPositionsFor = |
| 3189 | function SourceMapConsumer_allGeneratedPositionsFor(aArgs) { |
| 3190 | var line = util.getArg(aArgs, 'line'); |
| 3191 | |
| 3192 | // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping |
| 3193 | // returns the index of the closest mapping less than the needle. By |
| 3194 | // setting needle.originalColumn to 0, we thus find the last mapping for |
| 3195 | // the given line, provided such a mapping exists. |
| 3196 | var needle = { |
| 3197 | source: util.getArg(aArgs, 'source'), |
| 3198 | originalLine: line, |
| 3199 | originalColumn: util.getArg(aArgs, 'column', 0) |
| 3200 | }; |
| 3201 | |
| 3202 | needle.source = this._findSourceIndex(needle.source); |
| 3203 | if (needle.source < 0) { |
| 3204 | return []; |
| 3205 | } |
| 3206 | |
| 3207 | var mappings = []; |
| 3208 | |
| 3209 | var index = this._findMapping(needle, |
| 3210 | this._originalMappings, |
| 3211 | "originalLine", |
| 3212 | "originalColumn", |
| 3213 | util.compareByOriginalPositions, |
| 3214 | binarySearch.LEAST_UPPER_BOUND); |
| 3215 | if (index >= 0) { |
| 3216 | var mapping = this._originalMappings[index]; |
| 3217 | |
| 3218 | if (aArgs.column === undefined) { |
| 3219 | var originalLine = mapping.originalLine; |
| 3220 | |
| 3221 | // Iterate until either we run out of mappings, or we run into |
| 3222 | // a mapping for a different line than the one we found. Since |
| 3223 | // mappings are sorted, this is guaranteed to find all mappings for |
| 3224 | // the line we found. |
| 3225 | while (mapping && mapping.originalLine === originalLine) { |
| 3226 | mappings.push({ |
| 3227 | line: util.getArg(mapping, 'generatedLine', null), |
| 3228 | column: util.getArg(mapping, 'generatedColumn', null), |
| 3229 | lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) |
| 3230 | }); |
| 3231 | |
| 3232 | mapping = this._originalMappings[++index]; |
| 3233 | } |
| 3234 | } else { |
| 3235 | var originalColumn = mapping.originalColumn; |
| 3236 | |
| 3237 | // Iterate until either we run out of mappings, or we run into |
| 3238 | // a mapping for a different line than the one we were searching for. |
| 3239 | // Since mappings are sorted, this is guaranteed to find all mappings for |
| 3240 | // the line we are searching for. |
| 3241 | while (mapping && |
| 3242 | mapping.originalLine === line && |
| 3243 | mapping.originalColumn == originalColumn) { |
| 3244 | mappings.push({ |
| 3245 | line: util.getArg(mapping, 'generatedLine', null), |
| 3246 | column: util.getArg(mapping, 'generatedColumn', null), |
| 3247 | lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) |
| 3248 | }); |
| 3249 | |
| 3250 | mapping = this._originalMappings[++index]; |
| 3251 | } |
| 3252 | } |
| 3253 | } |
| 3254 | |
| 3255 | return mappings; |
| 3256 | }; |
| 3257 | |
| 3258 | exports.SourceMapConsumer = SourceMapConsumer; |
| 3259 | |
| 3260 | /** |
| 3261 | * A BasicSourceMapConsumer instance represents a parsed source map which we can |
| 3262 | * query for information about the original file positions by giving it a file |
| 3263 | * position in the generated source. |
| 3264 | * |
| 3265 | * The first parameter is the raw source map (either as a JSON string, or |
| 3266 | * already parsed to an object). According to the spec, source maps have the |
| 3267 | * following attributes: |
| 3268 | * |
| 3269 | * - version: Which version of the source map spec this map is following. |
| 3270 | * - sources: An array of URLs to the original source files. |
| 3271 | * - names: An array of identifiers which can be referrenced by individual mappings. |
| 3272 | * - sourceRoot: Optional. The URL root from which all sources are relative. |
| 3273 | * - sourcesContent: Optional. An array of contents of the original source files. |
| 3274 | * - mappings: A string of base64 VLQs which contain the actual mappings. |
| 3275 | * - file: Optional. The generated file this source map is associated with. |
| 3276 | * |
| 3277 | * Here is an example source map, taken from the source map spec[0]: |
| 3278 | * |
| 3279 | * { |
| 3280 | * version : 3, |
| 3281 | * file: "out.js", |
| 3282 | * sourceRoot : "", |
| 3283 | * sources: ["foo.js", "bar.js"], |
| 3284 | * names: ["src", "maps", "are", "fun"], |
| 3285 | * mappings: "AA,AB;;ABCDE;" |
| 3286 | * } |
| 3287 | * |
| 3288 | * The second parameter, if given, is a string whose value is the URL |
| 3289 | * at which the source map was found. This URL is used to compute the |
| 3290 | * sources array. |
| 3291 | * |
| 3292 | * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1# |
| 3293 | */ |
| 3294 | function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) { |
| 3295 | var sourceMap = aSourceMap; |
| 3296 | if (typeof aSourceMap === 'string') { |
| 3297 | sourceMap = util.parseSourceMapInput(aSourceMap); |
| 3298 | } |
| 3299 | |
| 3300 | var version = util.getArg(sourceMap, 'version'); |
| 3301 | var sources = util.getArg(sourceMap, 'sources'); |
| 3302 | // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which |
| 3303 | // requires the array) to play nice here. |
| 3304 | var names = util.getArg(sourceMap, 'names', []); |
| 3305 | var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null); |
| 3306 | var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null); |
| 3307 | var mappings = util.getArg(sourceMap, 'mappings'); |
| 3308 | var file = util.getArg(sourceMap, 'file', null); |
| 3309 | |
| 3310 | // Once again, Sass deviates from the spec and supplies the version as a |
| 3311 | // string rather than a number, so we use loose equality checking here. |
| 3312 | if (version != this._version) { |
| 3313 | throw new Error('Unsupported version: ' + version); |
| 3314 | } |
| 3315 | |
| 3316 | if (sourceRoot) { |
| 3317 | sourceRoot = util.normalize(sourceRoot); |
| 3318 | } |
| 3319 | |
| 3320 | sources = sources |
| 3321 | .map(String) |
| 3322 | // Some source maps produce relative source paths like "./foo.js" instead of |
| 3323 | // "foo.js". Normalize these first so that future comparisons will succeed. |
| 3324 | // See bugzil.la/1090768. |
| 3325 | .map(util.normalize) |
| 3326 | // Always ensure that absolute sources are internally stored relative to |
| 3327 | // the source root, if the source root is absolute. Not doing this would |
| 3328 | // be particularly problematic when the source root is a prefix of the |
| 3329 | // source (valid, but why??). See github issue #199 and bugzil.la/1188982. |
| 3330 | .map(function (source) { |
| 3331 | return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source) |
| 3332 | ? util.relative(sourceRoot, source) |
| 3333 | : source; |
| 3334 | }); |
| 3335 | |
| 3336 | // Pass `true` below to allow duplicate names and sources. While source maps |
| 3337 | // are intended to be compressed and deduplicated, the TypeScript compiler |
| 3338 | // sometimes generates source maps with duplicates in them. See Github issue |
| 3339 | // #72 and bugzil.la/889492. |
| 3340 | this._names = ArraySet.fromArray(names.map(String), true); |
| 3341 | this._sources = ArraySet.fromArray(sources, true); |
| 3342 | |
| 3343 | this._absoluteSources = this._sources.toArray().map(function (s) { |
| 3344 | return util.computeSourceURL(sourceRoot, s, aSourceMapURL); |
| 3345 | }); |
| 3346 | |
| 3347 | this.sourceRoot = sourceRoot; |
| 3348 | this.sourcesContent = sourcesContent; |
| 3349 | this._mappings = mappings; |
| 3350 | this._sourceMapURL = aSourceMapURL; |
| 3351 | this.file = file; |
| 3352 | } |
| 3353 | |
| 3354 | BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); |
| 3355 | BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer; |
| 3356 | |
| 3357 | /** |
| 3358 | * Utility function to find the index of a source. Returns -1 if not |
| 3359 | * found. |
| 3360 | */ |
| 3361 | BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) { |
| 3362 | var relativeSource = aSource; |
| 3363 | if (this.sourceRoot != null) { |
| 3364 | relativeSource = util.relative(this.sourceRoot, relativeSource); |
| 3365 | } |
| 3366 | |
| 3367 | if (this._sources.has(relativeSource)) { |
| 3368 | return this._sources.indexOf(relativeSource); |
| 3369 | } |
| 3370 | |
| 3371 | // Maybe aSource is an absolute URL as returned by |sources|. In |
| 3372 | // this case we can't simply undo the transform. |
| 3373 | var i; |
| 3374 | for (i = 0; i < this._absoluteSources.length; ++i) { |
| 3375 | if (this._absoluteSources[i] == aSource) { |
| 3376 | return i; |
| 3377 | } |
| 3378 | } |
| 3379 | |
| 3380 | return -1; |
| 3381 | }; |
| 3382 | |
| 3383 | /** |
| 3384 | * Create a BasicSourceMapConsumer from a SourceMapGenerator. |
| 3385 | * |
| 3386 | * @param SourceMapGenerator aSourceMap |
| 3387 | * The source map that will be consumed. |
| 3388 | * @param String aSourceMapURL |
| 3389 | * The URL at which the source map can be found (optional) |
| 3390 | * @returns BasicSourceMapConsumer |
| 3391 | */ |
| 3392 | BasicSourceMapConsumer.fromSourceMap = |
| 3393 | function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) { |
| 3394 | var smc = Object.create(BasicSourceMapConsumer.prototype); |
| 3395 | |
| 3396 | var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true); |
| 3397 | var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true); |
| 3398 | smc.sourceRoot = aSourceMap._sourceRoot; |
| 3399 | smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(), |
| 3400 | smc.sourceRoot); |
| 3401 | smc.file = aSourceMap._file; |
| 3402 | smc._sourceMapURL = aSourceMapURL; |
| 3403 | smc._absoluteSources = smc._sources.toArray().map(function (s) { |
| 3404 | return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL); |
| 3405 | }); |
| 3406 | |
| 3407 | // Because we are modifying the entries (by converting string sources and |
| 3408 | // names to indices into the sources and names ArraySets), we have to make |
| 3409 | // a copy of the entry or else bad things happen. Shared mutable state |
| 3410 | // strikes again! See github issue #191. |
| 3411 | |
| 3412 | var generatedMappings = aSourceMap._mappings.toArray().slice(); |
| 3413 | var destGeneratedMappings = smc.__generatedMappings = []; |
| 3414 | var destOriginalMappings = smc.__originalMappings = []; |
| 3415 | |
| 3416 | for (var i = 0, length = generatedMappings.length; i < length; i++) { |
| 3417 | var srcMapping = generatedMappings[i]; |
| 3418 | var destMapping = new Mapping; |
| 3419 | destMapping.generatedLine = srcMapping.generatedLine; |
| 3420 | destMapping.generatedColumn = srcMapping.generatedColumn; |
| 3421 | |
| 3422 | if (srcMapping.source) { |
| 3423 | destMapping.source = sources.indexOf(srcMapping.source); |
| 3424 | destMapping.originalLine = srcMapping.originalLine; |
| 3425 | destMapping.originalColumn = srcMapping.originalColumn; |
| 3426 | |
| 3427 | if (srcMapping.name) { |
| 3428 | destMapping.name = names.indexOf(srcMapping.name); |
| 3429 | } |
| 3430 | |
| 3431 | destOriginalMappings.push(destMapping); |
| 3432 | } |
| 3433 | |
| 3434 | destGeneratedMappings.push(destMapping); |
| 3435 | } |
| 3436 | |
| 3437 | quickSort(smc.__originalMappings, util.compareByOriginalPositions); |
| 3438 | |
| 3439 | return smc; |
| 3440 | }; |
| 3441 | |
| 3442 | /** |
| 3443 | * The version of the source mapping spec that we are consuming. |
| 3444 | */ |
| 3445 | BasicSourceMapConsumer.prototype._version = 3; |
| 3446 | |
| 3447 | /** |
| 3448 | * The list of original sources. |
| 3449 | */ |
| 3450 | Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', { |
| 3451 | get: function () { |
| 3452 | return this._absoluteSources.slice(); |
| 3453 | } |
| 3454 | }); |
| 3455 | |
| 3456 | /** |
| 3457 | * Provide the JIT with a nice shape / hidden class. |
| 3458 | */ |
| 3459 | function Mapping() { |
| 3460 | this.generatedLine = 0; |
| 3461 | this.generatedColumn = 0; |
| 3462 | this.source = null; |
| 3463 | this.originalLine = null; |
| 3464 | this.originalColumn = null; |
| 3465 | this.name = null; |
| 3466 | } |
| 3467 | |
| 3468 | /** |
| 3469 | * Parse the mappings in a string in to a data structure which we can easily |
| 3470 | * query (the ordered arrays in the `this.__generatedMappings` and |
| 3471 | * `this.__originalMappings` properties). |
| 3472 | */ |
| 3473 | BasicSourceMapConsumer.prototype._parseMappings = |
| 3474 | function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { |
| 3475 | var generatedLine = 1; |
| 3476 | var previousGeneratedColumn = 0; |
| 3477 | var previousOriginalLine = 0; |
| 3478 | var previousOriginalColumn = 0; |
| 3479 | var previousSource = 0; |
| 3480 | var previousName = 0; |
| 3481 | var length = aStr.length; |
| 3482 | var index = 0; |
| 3483 | var cachedSegments = {}; |
| 3484 | var temp = {}; |
| 3485 | var originalMappings = []; |
| 3486 | var generatedMappings = []; |
| 3487 | var mapping, str, segment, end, value; |
| 3488 | |
| 3489 | while (index < length) { |
| 3490 | if (aStr.charAt(index) === ';') { |
| 3491 | generatedLine++; |
| 3492 | index++; |
| 3493 | previousGeneratedColumn = 0; |
| 3494 | } |
| 3495 | else if (aStr.charAt(index) === ',') { |
| 3496 | index++; |
| 3497 | } |
| 3498 | else { |
| 3499 | mapping = new Mapping(); |
| 3500 | mapping.generatedLine = generatedLine; |
| 3501 | |
| 3502 | // Because each offset is encoded relative to the previous one, |
| 3503 | // many segments often have the same encoding. We can exploit this |
| 3504 | // fact by caching the parsed variable length fields of each segment, |
| 3505 | // allowing us to avoid a second parse if we encounter the same |
| 3506 | // segment again. |
| 3507 | for (end = index; end < length; end++) { |
| 3508 | if (this._charIsMappingSeparator(aStr, end)) { |
| 3509 | break; |
| 3510 | } |
| 3511 | } |
| 3512 | str = aStr.slice(index, end); |
| 3513 | |
| 3514 | segment = cachedSegments[str]; |
| 3515 | if (segment) { |
| 3516 | index += str.length; |
| 3517 | } else { |
| 3518 | segment = []; |
| 3519 | while (index < end) { |
| 3520 | base64VLQ.decode(aStr, index, temp); |
| 3521 | value = temp.value; |
| 3522 | index = temp.rest; |
| 3523 | segment.push(value); |
| 3524 | } |
| 3525 | |
| 3526 | if (segment.length === 2) { |
| 3527 | throw new Error('Found a source, but no line and column'); |
| 3528 | } |
| 3529 | |
| 3530 | if (segment.length === 3) { |
| 3531 | throw new Error('Found a source and line, but no column'); |
| 3532 | } |
| 3533 | |
| 3534 | cachedSegments[str] = segment; |
| 3535 | } |
| 3536 | |
| 3537 | // Generated column. |
| 3538 | mapping.generatedColumn = previousGeneratedColumn + segment[0]; |
| 3539 | previousGeneratedColumn = mapping.generatedColumn; |
| 3540 | |
| 3541 | if (segment.length > 1) { |
| 3542 | // Original source. |
| 3543 | mapping.source = previousSource + segment[1]; |
| 3544 | previousSource += segment[1]; |
| 3545 | |
| 3546 | // Original line. |
| 3547 | mapping.originalLine = previousOriginalLine + segment[2]; |
| 3548 | previousOriginalLine = mapping.originalLine; |
| 3549 | // Lines are stored 0-based |
| 3550 | mapping.originalLine += 1; |
| 3551 | |
| 3552 | // Original column. |
| 3553 | mapping.originalColumn = previousOriginalColumn + segment[3]; |
| 3554 | previousOriginalColumn = mapping.originalColumn; |
| 3555 | |
| 3556 | if (segment.length > 4) { |
| 3557 | // Original name. |
| 3558 | mapping.name = previousName + segment[4]; |
| 3559 | previousName += segment[4]; |
| 3560 | } |
| 3561 | } |
| 3562 | |
| 3563 | generatedMappings.push(mapping); |
| 3564 | if (typeof mapping.originalLine === 'number') { |
| 3565 | originalMappings.push(mapping); |
| 3566 | } |
| 3567 | } |
| 3568 | } |
| 3569 | |
| 3570 | quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated); |
| 3571 | this.__generatedMappings = generatedMappings; |
| 3572 | |
| 3573 | quickSort(originalMappings, util.compareByOriginalPositions); |
| 3574 | this.__originalMappings = originalMappings; |
| 3575 | }; |
| 3576 | |
| 3577 | /** |
| 3578 | * Find the mapping that best matches the hypothetical "needle" mapping that |
| 3579 | * we are searching for in the given "haystack" of mappings. |
| 3580 | */ |
| 3581 | BasicSourceMapConsumer.prototype._findMapping = |
| 3582 | function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName, |
| 3583 | aColumnName, aComparator, aBias) { |
| 3584 | // To return the position we are searching for, we must first find the |
| 3585 | // mapping for the given position and then return the opposite position it |
| 3586 | // points to. Because the mappings are sorted, we can use binary search to |
| 3587 | // find the best mapping. |
| 3588 | |
| 3589 | if (aNeedle[aLineName] <= 0) { |
| 3590 | throw new TypeError('Line must be greater than or equal to 1, got ' |
| 3591 | + aNeedle[aLineName]); |
| 3592 | } |
| 3593 | if (aNeedle[aColumnName] < 0) { |
| 3594 | throw new TypeError('Column must be greater than or equal to 0, got ' |
| 3595 | + aNeedle[aColumnName]); |
| 3596 | } |
| 3597 | |
| 3598 | return binarySearch.search(aNeedle, aMappings, aComparator, aBias); |
| 3599 | }; |
| 3600 | |
| 3601 | /** |
| 3602 | * Compute the last column for each generated mapping. The last column is |
| 3603 | * inclusive. |
| 3604 | */ |
| 3605 | BasicSourceMapConsumer.prototype.computeColumnSpans = |
| 3606 | function SourceMapConsumer_computeColumnSpans() { |
| 3607 | for (var index = 0; index < this._generatedMappings.length; ++index) { |
| 3608 | var mapping = this._generatedMappings[index]; |
| 3609 | |
| 3610 | // Mappings do not contain a field for the last generated columnt. We |
| 3611 | // can come up with an optimistic estimate, however, by assuming that |
| 3612 | // mappings are contiguous (i.e. given two consecutive mappings, the |
| 3613 | // first mapping ends where the second one starts). |
| 3614 | if (index + 1 < this._generatedMappings.length) { |
| 3615 | var nextMapping = this._generatedMappings[index + 1]; |
| 3616 | |
| 3617 | if (mapping.generatedLine === nextMapping.generatedLine) { |
| 3618 | mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1; |
| 3619 | continue; |
| 3620 | } |
| 3621 | } |
| 3622 | |
| 3623 | // The last mapping for each line spans the entire line. |
| 3624 | mapping.lastGeneratedColumn = Infinity; |
| 3625 | } |
| 3626 | }; |
| 3627 | |
| 3628 | /** |
| 3629 | * Returns the original source, line, and column information for the generated |
| 3630 | * source's line and column positions provided. The only argument is an object |
| 3631 | * with the following properties: |
| 3632 | * |
| 3633 | * - line: The line number in the generated source. The line number |
| 3634 | * is 1-based. |
| 3635 | * - column: The column number in the generated source. The column |
| 3636 | * number is 0-based. |
| 3637 | * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or |
| 3638 | * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the |
| 3639 | * closest element that is smaller than or greater than the one we are |
| 3640 | * searching for, respectively, if the exact element cannot be found. |
| 3641 | * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. |
| 3642 | * |
| 3643 | * and an object is returned with the following properties: |
| 3644 | * |
| 3645 | * - source: The original source file, or null. |
| 3646 | * - line: The line number in the original source, or null. The |
| 3647 | * line number is 1-based. |
| 3648 | * - column: The column number in the original source, or null. The |
| 3649 | * column number is 0-based. |
| 3650 | * - name: The original identifier, or null. |
| 3651 | */ |
| 3652 | BasicSourceMapConsumer.prototype.originalPositionFor = |
| 3653 | function SourceMapConsumer_originalPositionFor(aArgs) { |
| 3654 | var needle = { |
| 3655 | generatedLine: util.getArg(aArgs, 'line'), |
| 3656 | generatedColumn: util.getArg(aArgs, 'column') |
| 3657 | }; |
| 3658 | |
| 3659 | var index = this._findMapping( |
| 3660 | needle, |
| 3661 | this._generatedMappings, |
| 3662 | "generatedLine", |
| 3663 | "generatedColumn", |
| 3664 | util.compareByGeneratedPositionsDeflated, |
| 3665 | util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) |
| 3666 | ); |
| 3667 | |
| 3668 | if (index >= 0) { |
| 3669 | var mapping = this._generatedMappings[index]; |
| 3670 | |
| 3671 | if (mapping.generatedLine === needle.generatedLine) { |
| 3672 | var source = util.getArg(mapping, 'source', null); |
| 3673 | if (source !== null) { |
| 3674 | source = this._sources.at(source); |
| 3675 | source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL); |
| 3676 | } |
| 3677 | var name = util.getArg(mapping, 'name', null); |
| 3678 | if (name !== null) { |
| 3679 | name = this._names.at(name); |
| 3680 | } |
| 3681 | return { |
| 3682 | source: source, |
| 3683 | line: util.getArg(mapping, 'originalLine', null), |
| 3684 | column: util.getArg(mapping, 'originalColumn', null), |
| 3685 | name: name |
| 3686 | }; |
| 3687 | } |
| 3688 | } |
| 3689 | |
| 3690 | return { |
| 3691 | source: null, |
| 3692 | line: null, |
| 3693 | column: null, |
| 3694 | name: null |
| 3695 | }; |
| 3696 | }; |
| 3697 | |
| 3698 | /** |
| 3699 | * Return true if we have the source content for every source in the source |
| 3700 | * map, false otherwise. |
| 3701 | */ |
| 3702 | BasicSourceMapConsumer.prototype.hasContentsOfAllSources = |
| 3703 | function BasicSourceMapConsumer_hasContentsOfAllSources() { |
| 3704 | if (!this.sourcesContent) { |
| 3705 | return false; |
| 3706 | } |
| 3707 | return this.sourcesContent.length >= this._sources.size() && |
| 3708 | !this.sourcesContent.some(function (sc) { return sc == null; }); |
| 3709 | }; |
| 3710 | |
| 3711 | /** |
| 3712 | * Returns the original source content. The only argument is the url of the |
| 3713 | * original source file. Returns null if no original source content is |
| 3714 | * available. |
| 3715 | */ |
| 3716 | BasicSourceMapConsumer.prototype.sourceContentFor = |
| 3717 | function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { |
| 3718 | if (!this.sourcesContent) { |
| 3719 | return null; |
| 3720 | } |
| 3721 | |
| 3722 | var index = this._findSourceIndex(aSource); |
| 3723 | if (index >= 0) { |
| 3724 | return this.sourcesContent[index]; |
| 3725 | } |
| 3726 | |
| 3727 | var relativeSource = aSource; |
| 3728 | if (this.sourceRoot != null) { |
| 3729 | relativeSource = util.relative(this.sourceRoot, relativeSource); |
| 3730 | } |
| 3731 | |
| 3732 | var url; |
| 3733 | if (this.sourceRoot != null |
| 3734 | && (url = util.urlParse(this.sourceRoot))) { |
| 3735 | // XXX: file:// URIs and absolute paths lead to unexpected behavior for |
| 3736 | // many users. We can help them out when they expect file:// URIs to |
| 3737 | // behave like it would if they were running a local HTTP server. See |
| 3738 | // https://bugzilla.mozilla.org/show_bug.cgi?id=885597. |
| 3739 | var fileUriAbsPath = relativeSource.replace(/^file:\/\//, ""); |
| 3740 | if (url.scheme == "file" |
| 3741 | && this._sources.has(fileUriAbsPath)) { |
| 3742 | return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)] |
| 3743 | } |
| 3744 | |
| 3745 | if ((!url.path || url.path == "/") |
| 3746 | && this._sources.has("/" + relativeSource)) { |
| 3747 | return this.sourcesContent[this._sources.indexOf("/" + relativeSource)]; |
| 3748 | } |
| 3749 | } |
| 3750 | |
| 3751 | // This function is used recursively from |
| 3752 | // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we |
| 3753 | // don't want to throw if we can't find the source - we just want to |
| 3754 | // return null, so we provide a flag to exit gracefully. |
| 3755 | if (nullOnMissing) { |
| 3756 | return null; |
| 3757 | } |
| 3758 | else { |
| 3759 | throw new Error('"' + relativeSource + '" is not in the SourceMap.'); |
| 3760 | } |
| 3761 | }; |
| 3762 | |
| 3763 | /** |
| 3764 | * Returns the generated line and column information for the original source, |
| 3765 | * line, and column positions provided. The only argument is an object with |
| 3766 | * the following properties: |
| 3767 | * |
| 3768 | * - source: The filename of the original source. |
| 3769 | * - line: The line number in the original source. The line number |
| 3770 | * is 1-based. |
| 3771 | * - column: The column number in the original source. The column |
| 3772 | * number is 0-based. |
| 3773 | * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or |
| 3774 | * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the |
| 3775 | * closest element that is smaller than or greater than the one we are |
| 3776 | * searching for, respectively, if the exact element cannot be found. |
| 3777 | * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. |
| 3778 | * |
| 3779 | * and an object is returned with the following properties: |
| 3780 | * |
| 3781 | * - line: The line number in the generated source, or null. The |
| 3782 | * line number is 1-based. |
| 3783 | * - column: The column number in the generated source, or null. |
| 3784 | * The column number is 0-based. |
| 3785 | */ |
| 3786 | BasicSourceMapConsumer.prototype.generatedPositionFor = |
| 3787 | function SourceMapConsumer_generatedPositionFor(aArgs) { |
| 3788 | var source = util.getArg(aArgs, 'source'); |
| 3789 | source = this._findSourceIndex(source); |
| 3790 | if (source < 0) { |
| 3791 | return { |
| 3792 | line: null, |
| 3793 | column: null, |
| 3794 | lastColumn: null |
| 3795 | }; |
| 3796 | } |
| 3797 | |
| 3798 | var needle = { |
| 3799 | source: source, |
| 3800 | originalLine: util.getArg(aArgs, 'line'), |
| 3801 | originalColumn: util.getArg(aArgs, 'column') |
| 3802 | }; |
| 3803 | |
| 3804 | var index = this._findMapping( |
| 3805 | needle, |
| 3806 | this._originalMappings, |
| 3807 | "originalLine", |
| 3808 | "originalColumn", |
| 3809 | util.compareByOriginalPositions, |
| 3810 | util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) |
| 3811 | ); |
| 3812 | |
| 3813 | if (index >= 0) { |
| 3814 | var mapping = this._originalMappings[index]; |
| 3815 | |
| 3816 | if (mapping.source === needle.source) { |
| 3817 | return { |
| 3818 | line: util.getArg(mapping, 'generatedLine', null), |
| 3819 | column: util.getArg(mapping, 'generatedColumn', null), |
| 3820 | lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) |
| 3821 | }; |
| 3822 | } |
| 3823 | } |
| 3824 | |
| 3825 | return { |
| 3826 | line: null, |
| 3827 | column: null, |
| 3828 | lastColumn: null |
| 3829 | }; |
| 3830 | }; |
| 3831 | |
| 3832 | exports.BasicSourceMapConsumer = BasicSourceMapConsumer; |
| 3833 | |
| 3834 | /** |
| 3835 | * An IndexedSourceMapConsumer instance represents a parsed source map which |
| 3836 | * we can query for information. It differs from BasicSourceMapConsumer in |
| 3837 | * that it takes "indexed" source maps (i.e. ones with a "sections" field) as |
| 3838 | * input. |
| 3839 | * |
| 3840 | * The first parameter is a raw source map (either as a JSON string, or already |
| 3841 | * parsed to an object). According to the spec for indexed source maps, they |
| 3842 | * have the following attributes: |
| 3843 | * |
| 3844 | * - version: Which version of the source map spec this map is following. |
| 3845 | * - file: Optional. The generated file this source map is associated with. |
| 3846 | * - sections: A list of section definitions. |
| 3847 | * |
| 3848 | * Each value under the "sections" field has two fields: |
| 3849 | * - offset: The offset into the original specified at which this section |
| 3850 | * begins to apply, defined as an object with a "line" and "column" |
| 3851 | * field. |
| 3852 | * - map: A source map definition. This source map could also be indexed, |
| 3853 | * but doesn't have to be. |
| 3854 | * |
| 3855 | * Instead of the "map" field, it's also possible to have a "url" field |
| 3856 | * specifying a URL to retrieve a source map from, but that's currently |
| 3857 | * unsupported. |
| 3858 | * |
| 3859 | * Here's an example source map, taken from the source map spec[0], but |
| 3860 | * modified to omit a section which uses the "url" field. |
| 3861 | * |
| 3862 | * { |
| 3863 | * version : 3, |
| 3864 | * file: "app.js", |
| 3865 | * sections: [{ |
| 3866 | * offset: {line:100, column:10}, |
| 3867 | * map: { |
| 3868 | * version : 3, |
| 3869 | * file: "section.js", |
| 3870 | * sources: ["foo.js", "bar.js"], |
| 3871 | * names: ["src", "maps", "are", "fun"], |
| 3872 | * mappings: "AAAA,E;;ABCDE;" |
| 3873 | * } |
| 3874 | * }], |
| 3875 | * } |
| 3876 | * |
| 3877 | * The second parameter, if given, is a string whose value is the URL |
| 3878 | * at which the source map was found. This URL is used to compute the |
| 3879 | * sources array. |
| 3880 | * |
| 3881 | * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt |
| 3882 | */ |
| 3883 | function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) { |
| 3884 | var sourceMap = aSourceMap; |
| 3885 | if (typeof aSourceMap === 'string') { |
| 3886 | sourceMap = util.parseSourceMapInput(aSourceMap); |
| 3887 | } |
| 3888 | |
| 3889 | var version = util.getArg(sourceMap, 'version'); |
| 3890 | var sections = util.getArg(sourceMap, 'sections'); |
| 3891 | |
| 3892 | if (version != this._version) { |
| 3893 | throw new Error('Unsupported version: ' + version); |
| 3894 | } |
| 3895 | |
| 3896 | this._sources = new ArraySet(); |
| 3897 | this._names = new ArraySet(); |
| 3898 | |
| 3899 | var lastOffset = { |
| 3900 | line: -1, |
| 3901 | column: 0 |
| 3902 | }; |
| 3903 | this._sections = sections.map(function (s) { |
| 3904 | if (s.url) { |
| 3905 | // The url field will require support for asynchronicity. |
| 3906 | // See https://github.com/mozilla/source-map/issues/16 |
| 3907 | throw new Error('Support for url field in sections not implemented.'); |
| 3908 | } |
| 3909 | var offset = util.getArg(s, 'offset'); |
| 3910 | var offsetLine = util.getArg(offset, 'line'); |
| 3911 | var offsetColumn = util.getArg(offset, 'column'); |
| 3912 | |
| 3913 | if (offsetLine < lastOffset.line || |
| 3914 | (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) { |
| 3915 | throw new Error('Section offsets must be ordered and non-overlapping.'); |
| 3916 | } |
| 3917 | lastOffset = offset; |
| 3918 | |
| 3919 | return { |
| 3920 | generatedOffset: { |
| 3921 | // The offset fields are 0-based, but we use 1-based indices when |
| 3922 | // encoding/decoding from VLQ. |
| 3923 | generatedLine: offsetLine + 1, |
| 3924 | generatedColumn: offsetColumn + 1 |
| 3925 | }, |
| 3926 | consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL) |
| 3927 | } |
| 3928 | }); |
| 3929 | } |
| 3930 | |
| 3931 | IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); |
| 3932 | IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer; |
| 3933 | |
| 3934 | /** |
| 3935 | * The version of the source mapping spec that we are consuming. |
| 3936 | */ |
| 3937 | IndexedSourceMapConsumer.prototype._version = 3; |
| 3938 | |
| 3939 | /** |
| 3940 | * The list of original sources. |
| 3941 | */ |
| 3942 | Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', { |
| 3943 | get: function () { |
| 3944 | var sources = []; |
| 3945 | for (var i = 0; i < this._sections.length; i++) { |
| 3946 | for (var j = 0; j < this._sections[i].consumer.sources.length; j++) { |
| 3947 | sources.push(this._sections[i].consumer.sources[j]); |
| 3948 | } |
| 3949 | } |
| 3950 | return sources; |
| 3951 | } |
| 3952 | }); |
| 3953 | |
| 3954 | /** |
| 3955 | * Returns the original source, line, and column information for the generated |
| 3956 | * source's line and column positions provided. The only argument is an object |
| 3957 | * with the following properties: |
| 3958 | * |
| 3959 | * - line: The line number in the generated source. The line number |
| 3960 | * is 1-based. |
| 3961 | * - column: The column number in the generated source. The column |
| 3962 | * number is 0-based. |
| 3963 | * |
| 3964 | * and an object is returned with the following properties: |
| 3965 | * |
| 3966 | * - source: The original source file, or null. |
| 3967 | * - line: The line number in the original source, or null. The |
| 3968 | * line number is 1-based. |
| 3969 | * - column: The column number in the original source, or null. The |
| 3970 | * column number is 0-based. |
| 3971 | * - name: The original identifier, or null. |
| 3972 | */ |
| 3973 | IndexedSourceMapConsumer.prototype.originalPositionFor = |
| 3974 | function IndexedSourceMapConsumer_originalPositionFor(aArgs) { |
| 3975 | var needle = { |
| 3976 | generatedLine: util.getArg(aArgs, 'line'), |
| 3977 | generatedColumn: util.getArg(aArgs, 'column') |
| 3978 | }; |
| 3979 | |
| 3980 | // Find the section containing the generated position we're trying to map |
| 3981 | // to an original position. |
| 3982 | var sectionIndex = binarySearch.search(needle, this._sections, |
| 3983 | function(needle, section) { |
| 3984 | var cmp = needle.generatedLine - section.generatedOffset.generatedLine; |
| 3985 | if (cmp) { |
| 3986 | return cmp; |
| 3987 | } |
| 3988 | |
| 3989 | return (needle.generatedColumn - |
| 3990 | section.generatedOffset.generatedColumn); |
| 3991 | }); |
| 3992 | var section = this._sections[sectionIndex]; |
| 3993 | |
| 3994 | if (!section) { |
| 3995 | return { |
| 3996 | source: null, |
| 3997 | line: null, |
| 3998 | column: null, |
| 3999 | name: null |
| 4000 | }; |
| 4001 | } |
| 4002 | |
| 4003 | return section.consumer.originalPositionFor({ |
| 4004 | line: needle.generatedLine - |
| 4005 | (section.generatedOffset.generatedLine - 1), |
| 4006 | column: needle.generatedColumn - |
| 4007 | (section.generatedOffset.generatedLine === needle.generatedLine |
| 4008 | ? section.generatedOffset.generatedColumn - 1 |
| 4009 | : 0), |
| 4010 | bias: aArgs.bias |
| 4011 | }); |
| 4012 | }; |
| 4013 | |
| 4014 | /** |
| 4015 | * Return true if we have the source content for every source in the source |
| 4016 | * map, false otherwise. |
| 4017 | */ |
| 4018 | IndexedSourceMapConsumer.prototype.hasContentsOfAllSources = |
| 4019 | function IndexedSourceMapConsumer_hasContentsOfAllSources() { |
| 4020 | return this._sections.every(function (s) { |
| 4021 | return s.consumer.hasContentsOfAllSources(); |
| 4022 | }); |
| 4023 | }; |
| 4024 | |
| 4025 | /** |
| 4026 | * Returns the original source content. The only argument is the url of the |
| 4027 | * original source file. Returns null if no original source content is |
| 4028 | * available. |
| 4029 | */ |
| 4030 | IndexedSourceMapConsumer.prototype.sourceContentFor = |
| 4031 | function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { |
| 4032 | for (var i = 0; i < this._sections.length; i++) { |
| 4033 | var section = this._sections[i]; |
| 4034 | |
| 4035 | var content = section.consumer.sourceContentFor(aSource, true); |
| 4036 | if (content) { |
| 4037 | return content; |
| 4038 | } |
| 4039 | } |
| 4040 | if (nullOnMissing) { |
| 4041 | return null; |
| 4042 | } |
| 4043 | else { |
| 4044 | throw new Error('"' + aSource + '" is not in the SourceMap.'); |
| 4045 | } |
| 4046 | }; |
| 4047 | |
| 4048 | /** |
| 4049 | * Returns the generated line and column information for the original source, |
| 4050 | * line, and column positions provided. The only argument is an object with |
| 4051 | * the following properties: |
| 4052 | * |
| 4053 | * - source: The filename of the original source. |
| 4054 | * - line: The line number in the original source. The line number |
| 4055 | * is 1-based. |
| 4056 | * - column: The column number in the original source. The column |
| 4057 | * number is 0-based. |
| 4058 | * |
| 4059 | * and an object is returned with the following properties: |
| 4060 | * |
| 4061 | * - line: The line number in the generated source, or null. The |
| 4062 | * line number is 1-based. |
| 4063 | * - column: The column number in the generated source, or null. |
| 4064 | * The column number is 0-based. |
| 4065 | */ |
| 4066 | IndexedSourceMapConsumer.prototype.generatedPositionFor = |
| 4067 | function IndexedSourceMapConsumer_generatedPositionFor(aArgs) { |
| 4068 | for (var i = 0; i < this._sections.length; i++) { |
| 4069 | var section = this._sections[i]; |
| 4070 | |
| 4071 | // Only consider this section if the requested source is in the list of |
| 4072 | // sources of the consumer. |
| 4073 | if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) { |
| 4074 | continue; |
| 4075 | } |
| 4076 | var generatedPosition = section.consumer.generatedPositionFor(aArgs); |
| 4077 | if (generatedPosition) { |
| 4078 | var ret = { |
| 4079 | line: generatedPosition.line + |
| 4080 | (section.generatedOffset.generatedLine - 1), |
| 4081 | column: generatedPosition.column + |
| 4082 | (section.generatedOffset.generatedLine === generatedPosition.line |
| 4083 | ? section.generatedOffset.generatedColumn - 1 |
| 4084 | : 0) |
| 4085 | }; |
| 4086 | return ret; |
| 4087 | } |
| 4088 | } |
| 4089 | |
| 4090 | return { |
| 4091 | line: null, |
| 4092 | column: null |
| 4093 | }; |
| 4094 | }; |
| 4095 | |
| 4096 | /** |
| 4097 | * Parse the mappings in a string in to a data structure which we can easily |
| 4098 | * query (the ordered arrays in the `this.__generatedMappings` and |
| 4099 | * `this.__originalMappings` properties). |
| 4100 | */ |
| 4101 | IndexedSourceMapConsumer.prototype._parseMappings = |
| 4102 | function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) { |
| 4103 | this.__generatedMappings = []; |
| 4104 | this.__originalMappings = []; |
| 4105 | for (var i = 0; i < this._sections.length; i++) { |
| 4106 | var section = this._sections[i]; |
| 4107 | var sectionMappings = section.consumer._generatedMappings; |
| 4108 | for (var j = 0; j < sectionMappings.length; j++) { |
| 4109 | var mapping = sectionMappings[j]; |
| 4110 | |
| 4111 | var source = section.consumer._sources.at(mapping.source); |
| 4112 | source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL); |
| 4113 | this._sources.add(source); |
| 4114 | source = this._sources.indexOf(source); |
| 4115 | |
| 4116 | var name = null; |
| 4117 | if (mapping.name) { |
| 4118 | name = section.consumer._names.at(mapping.name); |
| 4119 | this._names.add(name); |
| 4120 | name = this._names.indexOf(name); |
| 4121 | } |
| 4122 | |
| 4123 | // The mappings coming from the consumer for the section have |
| 4124 | // generated positions relative to the start of the section, so we |
| 4125 | // need to offset them to be relative to the start of the concatenated |
| 4126 | // generated file. |
| 4127 | var adjustedMapping = { |
| 4128 | source: source, |
| 4129 | generatedLine: mapping.generatedLine + |
| 4130 | (section.generatedOffset.generatedLine - 1), |
| 4131 | generatedColumn: mapping.generatedColumn + |
| 4132 | (section.generatedOffset.generatedLine === mapping.generatedLine |
| 4133 | ? section.generatedOffset.generatedColumn - 1 |
| 4134 | : 0), |
| 4135 | originalLine: mapping.originalLine, |
| 4136 | originalColumn: mapping.originalColumn, |
| 4137 | name: name |
| 4138 | }; |
| 4139 | |
| 4140 | this.__generatedMappings.push(adjustedMapping); |
| 4141 | if (typeof adjustedMapping.originalLine === 'number') { |
| 4142 | this.__originalMappings.push(adjustedMapping); |
| 4143 | } |
| 4144 | } |
| 4145 | } |
| 4146 | |
| 4147 | quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated); |
| 4148 | quickSort(this.__originalMappings, util.compareByOriginalPositions); |
| 4149 | }; |
| 4150 | |
| 4151 | exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer; |
| 4152 | |
| 4153 | },{"./array-set":17,"./base64-vlq":18,"./binary-search":20,"./quick-sort":22,"./util":26}],24:[function(require,module,exports){ |
| 4154 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 4155 | /* |
| 4156 | * Copyright 2011 Mozilla Foundation and contributors |
| 4157 | * Licensed under the New BSD license. See LICENSE or: |
| 4158 | * http://opensource.org/licenses/BSD-3-Clause |
| 4159 | */ |
| 4160 | |
| 4161 | var base64VLQ = require('./base64-vlq'); |
| 4162 | var util = require('./util'); |
| 4163 | var ArraySet = require('./array-set').ArraySet; |
| 4164 | var MappingList = require('./mapping-list').MappingList; |
| 4165 | |
| 4166 | /** |
| 4167 | * An instance of the SourceMapGenerator represents a source map which is |
| 4168 | * being built incrementally. You may pass an object with the following |
| 4169 | * properties: |
| 4170 | * |
| 4171 | * - file: The filename of the generated source. |
| 4172 | * - sourceRoot: A root for all relative URLs in this source map. |
| 4173 | */ |
| 4174 | function SourceMapGenerator(aArgs) { |
| 4175 | if (!aArgs) { |
| 4176 | aArgs = {}; |
| 4177 | } |
| 4178 | this._file = util.getArg(aArgs, 'file', null); |
| 4179 | this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null); |
| 4180 | this._skipValidation = util.getArg(aArgs, 'skipValidation', false); |
| 4181 | this._sources = new ArraySet(); |
| 4182 | this._names = new ArraySet(); |
| 4183 | this._mappings = new MappingList(); |
| 4184 | this._sourcesContents = null; |
| 4185 | } |
| 4186 | |
| 4187 | SourceMapGenerator.prototype._version = 3; |
| 4188 | |
| 4189 | /** |
| 4190 | * Creates a new SourceMapGenerator based on a SourceMapConsumer |
| 4191 | * |
| 4192 | * @param aSourceMapConsumer The SourceMap. |
| 4193 | */ |
| 4194 | SourceMapGenerator.fromSourceMap = |
| 4195 | function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) { |
| 4196 | var sourceRoot = aSourceMapConsumer.sourceRoot; |
| 4197 | var generator = new SourceMapGenerator({ |
| 4198 | file: aSourceMapConsumer.file, |
| 4199 | sourceRoot: sourceRoot |
| 4200 | }); |
| 4201 | aSourceMapConsumer.eachMapping(function (mapping) { |
| 4202 | var newMapping = { |
| 4203 | generated: { |
| 4204 | line: mapping.generatedLine, |
| 4205 | column: mapping.generatedColumn |
| 4206 | } |
| 4207 | }; |
| 4208 | |
| 4209 | if (mapping.source != null) { |
| 4210 | newMapping.source = mapping.source; |
| 4211 | if (sourceRoot != null) { |
| 4212 | newMapping.source = util.relative(sourceRoot, newMapping.source); |
| 4213 | } |
| 4214 | |
| 4215 | newMapping.original = { |
| 4216 | line: mapping.originalLine, |
| 4217 | column: mapping.originalColumn |
| 4218 | }; |
| 4219 | |
| 4220 | if (mapping.name != null) { |
| 4221 | newMapping.name = mapping.name; |
| 4222 | } |
| 4223 | } |
| 4224 | |
| 4225 | generator.addMapping(newMapping); |
| 4226 | }); |
| 4227 | aSourceMapConsumer.sources.forEach(function (sourceFile) { |
| 4228 | var sourceRelative = sourceFile; |
| 4229 | if (sourceRoot !== null) { |
| 4230 | sourceRelative = util.relative(sourceRoot, sourceFile); |
| 4231 | } |
| 4232 | |
| 4233 | if (!generator._sources.has(sourceRelative)) { |
| 4234 | generator._sources.add(sourceRelative); |
| 4235 | } |
| 4236 | |
| 4237 | var content = aSourceMapConsumer.sourceContentFor(sourceFile); |
| 4238 | if (content != null) { |
| 4239 | generator.setSourceContent(sourceFile, content); |
| 4240 | } |
| 4241 | }); |
| 4242 | return generator; |
| 4243 | }; |
| 4244 | |
| 4245 | /** |
| 4246 | * Add a single mapping from original source line and column to the generated |
| 4247 | * source's line and column for this source map being created. The mapping |
| 4248 | * object should have the following properties: |
| 4249 | * |
| 4250 | * - generated: An object with the generated line and column positions. |
| 4251 | * - original: An object with the original line and column positions. |
| 4252 | * - source: The original source file (relative to the sourceRoot). |
| 4253 | * - name: An optional original token name for this mapping. |
| 4254 | */ |
| 4255 | SourceMapGenerator.prototype.addMapping = |
| 4256 | function SourceMapGenerator_addMapping(aArgs) { |
| 4257 | var generated = util.getArg(aArgs, 'generated'); |
| 4258 | var original = util.getArg(aArgs, 'original', null); |
| 4259 | var source = util.getArg(aArgs, 'source', null); |
| 4260 | var name = util.getArg(aArgs, 'name', null); |
| 4261 | |
| 4262 | if (!this._skipValidation) { |
| 4263 | this._validateMapping(generated, original, source, name); |
| 4264 | } |
| 4265 | |
| 4266 | if (source != null) { |
| 4267 | source = String(source); |
| 4268 | if (!this._sources.has(source)) { |
| 4269 | this._sources.add(source); |
| 4270 | } |
| 4271 | } |
| 4272 | |
| 4273 | if (name != null) { |
| 4274 | name = String(name); |
| 4275 | if (!this._names.has(name)) { |
| 4276 | this._names.add(name); |
| 4277 | } |
| 4278 | } |
| 4279 | |
| 4280 | this._mappings.add({ |
| 4281 | generatedLine: generated.line, |
| 4282 | generatedColumn: generated.column, |
| 4283 | originalLine: original != null && original.line, |
| 4284 | originalColumn: original != null && original.column, |
| 4285 | source: source, |
| 4286 | name: name |
| 4287 | }); |
| 4288 | }; |
| 4289 | |
| 4290 | /** |
| 4291 | * Set the source content for a source file. |
| 4292 | */ |
| 4293 | SourceMapGenerator.prototype.setSourceContent = |
| 4294 | function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { |
| 4295 | var source = aSourceFile; |
| 4296 | if (this._sourceRoot != null) { |
| 4297 | source = util.relative(this._sourceRoot, source); |
| 4298 | } |
| 4299 | |
| 4300 | if (aSourceContent != null) { |
| 4301 | // Add the source content to the _sourcesContents map. |
| 4302 | // Create a new _sourcesContents map if the property is null. |
| 4303 | if (!this._sourcesContents) { |
| 4304 | this._sourcesContents = Object.create(null); |
| 4305 | } |
| 4306 | this._sourcesContents[util.toSetString(source)] = aSourceContent; |
| 4307 | } else if (this._sourcesContents) { |
| 4308 | // Remove the source file from the _sourcesContents map. |
| 4309 | // If the _sourcesContents map is empty, set the property to null. |
| 4310 | delete this._sourcesContents[util.toSetString(source)]; |
| 4311 | if (Object.keys(this._sourcesContents).length === 0) { |
| 4312 | this._sourcesContents = null; |
| 4313 | } |
| 4314 | } |
| 4315 | }; |
| 4316 | |
| 4317 | /** |
| 4318 | * Applies the mappings of a sub-source-map for a specific source file to the |
| 4319 | * source map being generated. Each mapping to the supplied source file is |
| 4320 | * rewritten using the supplied source map. Note: The resolution for the |
| 4321 | * resulting mappings is the minimium of this map and the supplied map. |
| 4322 | * |
| 4323 | * @param aSourceMapConsumer The source map to be applied. |
| 4324 | * @param aSourceFile Optional. The filename of the source file. |
| 4325 | * If omitted, SourceMapConsumer's file property will be used. |
| 4326 | * @param aSourceMapPath Optional. The dirname of the path to the source map |
| 4327 | * to be applied. If relative, it is relative to the SourceMapConsumer. |
| 4328 | * This parameter is needed when the two source maps aren't in the same |
| 4329 | * directory, and the source map to be applied contains relative source |
| 4330 | * paths. If so, those relative source paths need to be rewritten |
| 4331 | * relative to the SourceMapGenerator. |
| 4332 | */ |
| 4333 | SourceMapGenerator.prototype.applySourceMap = |
| 4334 | function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { |
| 4335 | var sourceFile = aSourceFile; |
| 4336 | // If aSourceFile is omitted, we will use the file property of the SourceMap |
| 4337 | if (aSourceFile == null) { |
| 4338 | if (aSourceMapConsumer.file == null) { |
| 4339 | throw new Error( |
| 4340 | 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' + |
| 4341 | 'or the source map\'s "file" property. Both were omitted.' |
| 4342 | ); |
| 4343 | } |
| 4344 | sourceFile = aSourceMapConsumer.file; |
| 4345 | } |
| 4346 | var sourceRoot = this._sourceRoot; |
| 4347 | // Make "sourceFile" relative if an absolute Url is passed. |
| 4348 | if (sourceRoot != null) { |
| 4349 | sourceFile = util.relative(sourceRoot, sourceFile); |
| 4350 | } |
| 4351 | // Applying the SourceMap can add and remove items from the sources and |
| 4352 | // the names array. |
| 4353 | var newSources = new ArraySet(); |
| 4354 | var newNames = new ArraySet(); |
| 4355 | |
| 4356 | // Find mappings for the "sourceFile" |
| 4357 | this._mappings.unsortedForEach(function (mapping) { |
| 4358 | if (mapping.source === sourceFile && mapping.originalLine != null) { |
| 4359 | // Check if it can be mapped by the source map, then update the mapping. |
| 4360 | var original = aSourceMapConsumer.originalPositionFor({ |
| 4361 | line: mapping.originalLine, |
| 4362 | column: mapping.originalColumn |
| 4363 | }); |
| 4364 | if (original.source != null) { |
| 4365 | // Copy mapping |
| 4366 | mapping.source = original.source; |
| 4367 | if (aSourceMapPath != null) { |
| 4368 | mapping.source = util.join(aSourceMapPath, mapping.source) |
| 4369 | } |
| 4370 | if (sourceRoot != null) { |
| 4371 | mapping.source = util.relative(sourceRoot, mapping.source); |
| 4372 | } |
| 4373 | mapping.originalLine = original.line; |
| 4374 | mapping.originalColumn = original.column; |
| 4375 | if (original.name != null) { |
| 4376 | mapping.name = original.name; |
| 4377 | } |
| 4378 | } |
| 4379 | } |
| 4380 | |
| 4381 | var source = mapping.source; |
| 4382 | if (source != null && !newSources.has(source)) { |
| 4383 | newSources.add(source); |
| 4384 | } |
| 4385 | |
| 4386 | var name = mapping.name; |
| 4387 | if (name != null && !newNames.has(name)) { |
| 4388 | newNames.add(name); |
| 4389 | } |
| 4390 | |
| 4391 | }, this); |
| 4392 | this._sources = newSources; |
| 4393 | this._names = newNames; |
| 4394 | |
| 4395 | // Copy sourcesContents of applied map. |
| 4396 | aSourceMapConsumer.sources.forEach(function (sourceFile) { |
| 4397 | var content = aSourceMapConsumer.sourceContentFor(sourceFile); |
| 4398 | if (content != null) { |
| 4399 | if (aSourceMapPath != null) { |
| 4400 | sourceFile = util.join(aSourceMapPath, sourceFile); |
| 4401 | } |
| 4402 | if (sourceRoot != null) { |
| 4403 | sourceFile = util.relative(sourceRoot, sourceFile); |
| 4404 | } |
| 4405 | this.setSourceContent(sourceFile, content); |
| 4406 | } |
| 4407 | }, this); |
| 4408 | }; |
| 4409 | |
| 4410 | /** |
| 4411 | * A mapping can have one of the three levels of data: |
| 4412 | * |
| 4413 | * 1. Just the generated position. |
| 4414 | * 2. The Generated position, original position, and original source. |
| 4415 | * 3. Generated and original position, original source, as well as a name |
| 4416 | * token. |
| 4417 | * |
| 4418 | * To maintain consistency, we validate that any new mapping being added falls |
| 4419 | * in to one of these categories. |
| 4420 | */ |
| 4421 | SourceMapGenerator.prototype._validateMapping = |
| 4422 | function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, |
| 4423 | aName) { |
| 4424 | // When aOriginal is truthy but has empty values for .line and .column, |
| 4425 | // it is most likely a programmer error. In this case we throw a very |
| 4426 | // specific error message to try to guide them the right way. |
| 4427 | // For example: https://github.com/Polymer/polymer-bundler/pull/519 |
| 4428 | if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') { |
| 4429 | throw new Error( |
| 4430 | 'original.line and original.column are not numbers -- you probably meant to omit ' + |
| 4431 | 'the original mapping entirely and only map the generated position. If so, pass ' + |
| 4432 | 'null for the original mapping instead of an object with empty or null values.' |
| 4433 | ); |
| 4434 | } |
| 4435 | |
| 4436 | if (aGenerated && 'line' in aGenerated && 'column' in aGenerated |
| 4437 | && aGenerated.line > 0 && aGenerated.column >= 0 |
| 4438 | && !aOriginal && !aSource && !aName) { |
| 4439 | // Case 1. |
| 4440 | return; |
| 4441 | } |
| 4442 | else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated |
| 4443 | && aOriginal && 'line' in aOriginal && 'column' in aOriginal |
| 4444 | && aGenerated.line > 0 && aGenerated.column >= 0 |
| 4445 | && aOriginal.line > 0 && aOriginal.column >= 0 |
| 4446 | && aSource) { |
| 4447 | // Cases 2 and 3. |
| 4448 | return; |
| 4449 | } |
| 4450 | else { |
| 4451 | throw new Error('Invalid mapping: ' + JSON.stringify({ |
| 4452 | generated: aGenerated, |
| 4453 | source: aSource, |
| 4454 | original: aOriginal, |
| 4455 | name: aName |
| 4456 | })); |
| 4457 | } |
| 4458 | }; |
| 4459 | |
| 4460 | /** |
| 4461 | * Serialize the accumulated mappings in to the stream of base 64 VLQs |
| 4462 | * specified by the source map format. |
| 4463 | */ |
| 4464 | SourceMapGenerator.prototype._serializeMappings = |
| 4465 | function SourceMapGenerator_serializeMappings() { |
| 4466 | var previousGeneratedColumn = 0; |
| 4467 | var previousGeneratedLine = 1; |
| 4468 | var previousOriginalColumn = 0; |
| 4469 | var previousOriginalLine = 0; |
| 4470 | var previousName = 0; |
| 4471 | var previousSource = 0; |
| 4472 | var result = ''; |
| 4473 | var next; |
| 4474 | var mapping; |
| 4475 | var nameIdx; |
| 4476 | var sourceIdx; |
| 4477 | |
| 4478 | var mappings = this._mappings.toArray(); |
| 4479 | for (var i = 0, len = mappings.length; i < len; i++) { |
| 4480 | mapping = mappings[i]; |
| 4481 | next = '' |
| 4482 | |
| 4483 | if (mapping.generatedLine !== previousGeneratedLine) { |
| 4484 | previousGeneratedColumn = 0; |
| 4485 | while (mapping.generatedLine !== previousGeneratedLine) { |
| 4486 | next += ';'; |
| 4487 | previousGeneratedLine++; |
| 4488 | } |
| 4489 | } |
| 4490 | else { |
| 4491 | if (i > 0) { |
| 4492 | if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) { |
| 4493 | continue; |
| 4494 | } |
| 4495 | next += ','; |
| 4496 | } |
| 4497 | } |
| 4498 | |
| 4499 | next += base64VLQ.encode(mapping.generatedColumn |
| 4500 | - previousGeneratedColumn); |
| 4501 | previousGeneratedColumn = mapping.generatedColumn; |
| 4502 | |
| 4503 | if (mapping.source != null) { |
| 4504 | sourceIdx = this._sources.indexOf(mapping.source); |
| 4505 | next += base64VLQ.encode(sourceIdx - previousSource); |
| 4506 | previousSource = sourceIdx; |
| 4507 | |
| 4508 | // lines are stored 0-based in SourceMap spec version 3 |
| 4509 | next += base64VLQ.encode(mapping.originalLine - 1 |
| 4510 | - previousOriginalLine); |
| 4511 | previousOriginalLine = mapping.originalLine - 1; |
| 4512 | |
| 4513 | next += base64VLQ.encode(mapping.originalColumn |
| 4514 | - previousOriginalColumn); |
| 4515 | previousOriginalColumn = mapping.originalColumn; |
| 4516 | |
| 4517 | if (mapping.name != null) { |
| 4518 | nameIdx = this._names.indexOf(mapping.name); |
| 4519 | next += base64VLQ.encode(nameIdx - previousName); |
| 4520 | previousName = nameIdx; |
| 4521 | } |
| 4522 | } |
| 4523 | |
| 4524 | result += next; |
| 4525 | } |
| 4526 | |
| 4527 | return result; |
| 4528 | }; |
| 4529 | |
| 4530 | SourceMapGenerator.prototype._generateSourcesContent = |
| 4531 | function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) { |
| 4532 | return aSources.map(function (source) { |
| 4533 | if (!this._sourcesContents) { |
| 4534 | return null; |
| 4535 | } |
| 4536 | if (aSourceRoot != null) { |
| 4537 | source = util.relative(aSourceRoot, source); |
| 4538 | } |
| 4539 | var key = util.toSetString(source); |
| 4540 | return Object.prototype.hasOwnProperty.call(this._sourcesContents, key) |
| 4541 | ? this._sourcesContents[key] |
| 4542 | : null; |
| 4543 | }, this); |
| 4544 | }; |
| 4545 | |
| 4546 | /** |
| 4547 | * Externalize the source map. |
| 4548 | */ |
| 4549 | SourceMapGenerator.prototype.toJSON = |
| 4550 | function SourceMapGenerator_toJSON() { |
| 4551 | var map = { |
| 4552 | version: this._version, |
| 4553 | sources: this._sources.toArray(), |
| 4554 | names: this._names.toArray(), |
| 4555 | mappings: this._serializeMappings() |
| 4556 | }; |
| 4557 | if (this._file != null) { |
| 4558 | map.file = this._file; |
| 4559 | } |
| 4560 | if (this._sourceRoot != null) { |
| 4561 | map.sourceRoot = this._sourceRoot; |
| 4562 | } |
| 4563 | if (this._sourcesContents) { |
| 4564 | map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot); |
| 4565 | } |
| 4566 | |
| 4567 | return map; |
| 4568 | }; |
| 4569 | |
| 4570 | /** |
| 4571 | * Render the source map being generated to a string. |
| 4572 | */ |
| 4573 | SourceMapGenerator.prototype.toString = |
| 4574 | function SourceMapGenerator_toString() { |
| 4575 | return JSON.stringify(this.toJSON()); |
| 4576 | }; |
| 4577 | |
| 4578 | exports.SourceMapGenerator = SourceMapGenerator; |
| 4579 | |
| 4580 | },{"./array-set":17,"./base64-vlq":18,"./mapping-list":21,"./util":26}],25:[function(require,module,exports){ |
| 4581 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 4582 | /* |
| 4583 | * Copyright 2011 Mozilla Foundation and contributors |
| 4584 | * Licensed under the New BSD license. See LICENSE or: |
| 4585 | * http://opensource.org/licenses/BSD-3-Clause |
| 4586 | */ |
| 4587 | |
| 4588 | var SourceMapGenerator = require('./source-map-generator').SourceMapGenerator; |
| 4589 | var util = require('./util'); |
| 4590 | |
| 4591 | // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other |
| 4592 | // operating systems these days (capturing the result). |
| 4593 | var REGEX_NEWLINE = /(\r?\n)/; |
| 4594 | |
| 4595 | // Newline character code for charCodeAt() comparisons |
| 4596 | var NEWLINE_CODE = 10; |
| 4597 | |
| 4598 | // Private symbol for identifying `SourceNode`s when multiple versions of |
| 4599 | // the source-map library are loaded. This MUST NOT CHANGE across |
| 4600 | // versions! |
| 4601 | var isSourceNode = "$$$isSourceNode$$$"; |
| 4602 | |
| 4603 | /** |
| 4604 | * SourceNodes provide a way to abstract over interpolating/concatenating |
| 4605 | * snippets of generated JavaScript source code while maintaining the line and |
| 4606 | * column information associated with the original source code. |
| 4607 | * |
| 4608 | * @param aLine The original line number. |
| 4609 | * @param aColumn The original column number. |
| 4610 | * @param aSource The original source's filename. |
| 4611 | * @param aChunks Optional. An array of strings which are snippets of |
| 4612 | * generated JS, or other SourceNodes. |
| 4613 | * @param aName The original identifier. |
| 4614 | */ |
| 4615 | function SourceNode(aLine, aColumn, aSource, aChunks, aName) { |
| 4616 | this.children = []; |
| 4617 | this.sourceContents = {}; |
| 4618 | this.line = aLine == null ? null : aLine; |
| 4619 | this.column = aColumn == null ? null : aColumn; |
| 4620 | this.source = aSource == null ? null : aSource; |
| 4621 | this.name = aName == null ? null : aName; |
| 4622 | this[isSourceNode] = true; |
| 4623 | if (aChunks != null) this.add(aChunks); |
| 4624 | } |
| 4625 | |
| 4626 | /** |
| 4627 | * Creates a SourceNode from generated code and a SourceMapConsumer. |
| 4628 | * |
| 4629 | * @param aGeneratedCode The generated code |
| 4630 | * @param aSourceMapConsumer The SourceMap for the generated code |
| 4631 | * @param aRelativePath Optional. The path that relative sources in the |
| 4632 | * SourceMapConsumer should be relative to. |
| 4633 | */ |
| 4634 | SourceNode.fromStringWithSourceMap = |
| 4635 | function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) { |
| 4636 | // The SourceNode we want to fill with the generated code |
| 4637 | // and the SourceMap |
| 4638 | var node = new SourceNode(); |
| 4639 | |
| 4640 | // All even indices of this array are one line of the generated code, |
| 4641 | // while all odd indices are the newlines between two adjacent lines |
| 4642 | // (since `REGEX_NEWLINE` captures its match). |
| 4643 | // Processed fragments are accessed by calling `shiftNextLine`. |
| 4644 | var remainingLines = aGeneratedCode.split(REGEX_NEWLINE); |
| 4645 | var remainingLinesIndex = 0; |
| 4646 | var shiftNextLine = function() { |
| 4647 | var lineContents = getNextLine(); |
| 4648 | // The last line of a file might not have a newline. |
| 4649 | var newLine = getNextLine() || ""; |
| 4650 | return lineContents + newLine; |
| 4651 | |
| 4652 | function getNextLine() { |
| 4653 | return remainingLinesIndex < remainingLines.length ? |
| 4654 | remainingLines[remainingLinesIndex++] : undefined; |
| 4655 | } |
| 4656 | }; |
| 4657 | |
| 4658 | // We need to remember the position of "remainingLines" |
| 4659 | var lastGeneratedLine = 1, lastGeneratedColumn = 0; |
| 4660 | |
| 4661 | // The generate SourceNodes we need a code range. |
| 4662 | // To extract it current and last mapping is used. |
| 4663 | // Here we store the last mapping. |
| 4664 | var lastMapping = null; |
| 4665 | |
| 4666 | aSourceMapConsumer.eachMapping(function (mapping) { |
| 4667 | if (lastMapping !== null) { |
| 4668 | // We add the code from "lastMapping" to "mapping": |
| 4669 | // First check if there is a new line in between. |
| 4670 | if (lastGeneratedLine < mapping.generatedLine) { |
| 4671 | // Associate first line with "lastMapping" |
| 4672 | addMappingWithCode(lastMapping, shiftNextLine()); |
| 4673 | lastGeneratedLine++; |
| 4674 | lastGeneratedColumn = 0; |
| 4675 | // The remaining code is added without mapping |
| 4676 | } else { |
| 4677 | // There is no new line in between. |
| 4678 | // Associate the code between "lastGeneratedColumn" and |
| 4679 | // "mapping.generatedColumn" with "lastMapping" |
| 4680 | var nextLine = remainingLines[remainingLinesIndex] || ''; |
| 4681 | var code = nextLine.substr(0, mapping.generatedColumn - |
| 4682 | lastGeneratedColumn); |
| 4683 | remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn - |
| 4684 | lastGeneratedColumn); |
| 4685 | lastGeneratedColumn = mapping.generatedColumn; |
| 4686 | addMappingWithCode(lastMapping, code); |
| 4687 | // No more remaining code, continue |
| 4688 | lastMapping = mapping; |
| 4689 | return; |
| 4690 | } |
| 4691 | } |
| 4692 | // We add the generated code until the first mapping |
| 4693 | // to the SourceNode without any mapping. |
| 4694 | // Each line is added as separate string. |
| 4695 | while (lastGeneratedLine < mapping.generatedLine) { |
| 4696 | node.add(shiftNextLine()); |
| 4697 | lastGeneratedLine++; |
| 4698 | } |
| 4699 | if (lastGeneratedColumn < mapping.generatedColumn) { |
| 4700 | var nextLine = remainingLines[remainingLinesIndex] || ''; |
| 4701 | node.add(nextLine.substr(0, mapping.generatedColumn)); |
| 4702 | remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn); |
| 4703 | lastGeneratedColumn = mapping.generatedColumn; |
| 4704 | } |
| 4705 | lastMapping = mapping; |
| 4706 | }, this); |
| 4707 | // We have processed all mappings. |
| 4708 | if (remainingLinesIndex < remainingLines.length) { |
| 4709 | if (lastMapping) { |
| 4710 | // Associate the remaining code in the current line with "lastMapping" |
| 4711 | addMappingWithCode(lastMapping, shiftNextLine()); |
| 4712 | } |
| 4713 | // and add the remaining lines without any mapping |
| 4714 | node.add(remainingLines.splice(remainingLinesIndex).join("")); |
| 4715 | } |
| 4716 | |
| 4717 | // Copy sourcesContent into SourceNode |
| 4718 | aSourceMapConsumer.sources.forEach(function (sourceFile) { |
| 4719 | var content = aSourceMapConsumer.sourceContentFor(sourceFile); |
| 4720 | if (content != null) { |
| 4721 | if (aRelativePath != null) { |
| 4722 | sourceFile = util.join(aRelativePath, sourceFile); |
| 4723 | } |
| 4724 | node.setSourceContent(sourceFile, content); |
| 4725 | } |
| 4726 | }); |
| 4727 | |
| 4728 | return node; |
| 4729 | |
| 4730 | function addMappingWithCode(mapping, code) { |
| 4731 | if (mapping === null || mapping.source === undefined) { |
| 4732 | node.add(code); |
| 4733 | } else { |
| 4734 | var source = aRelativePath |
| 4735 | ? util.join(aRelativePath, mapping.source) |
| 4736 | : mapping.source; |
| 4737 | node.add(new SourceNode(mapping.originalLine, |
| 4738 | mapping.originalColumn, |
| 4739 | source, |
| 4740 | code, |
| 4741 | mapping.name)); |
| 4742 | } |
| 4743 | } |
| 4744 | }; |
| 4745 | |
| 4746 | /** |
| 4747 | * Add a chunk of generated JS to this source node. |
| 4748 | * |
| 4749 | * @param aChunk A string snippet of generated JS code, another instance of |
| 4750 | * SourceNode, or an array where each member is one of those things. |
| 4751 | */ |
| 4752 | SourceNode.prototype.add = function SourceNode_add(aChunk) { |
| 4753 | if (Array.isArray(aChunk)) { |
| 4754 | aChunk.forEach(function (chunk) { |
| 4755 | this.add(chunk); |
| 4756 | }, this); |
| 4757 | } |
| 4758 | else if (aChunk[isSourceNode] || typeof aChunk === "string") { |
| 4759 | if (aChunk) { |
| 4760 | this.children.push(aChunk); |
| 4761 | } |
| 4762 | } |
| 4763 | else { |
| 4764 | throw new TypeError( |
| 4765 | "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk |
| 4766 | ); |
| 4767 | } |
| 4768 | return this; |
| 4769 | }; |
| 4770 | |
| 4771 | /** |
| 4772 | * Add a chunk of generated JS to the beginning of this source node. |
| 4773 | * |
| 4774 | * @param aChunk A string snippet of generated JS code, another instance of |
| 4775 | * SourceNode, or an array where each member is one of those things. |
| 4776 | */ |
| 4777 | SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) { |
| 4778 | if (Array.isArray(aChunk)) { |
| 4779 | for (var i = aChunk.length-1; i >= 0; i--) { |
| 4780 | this.prepend(aChunk[i]); |
| 4781 | } |
| 4782 | } |
| 4783 | else if (aChunk[isSourceNode] || typeof aChunk === "string") { |
| 4784 | this.children.unshift(aChunk); |
| 4785 | } |
| 4786 | else { |
| 4787 | throw new TypeError( |
| 4788 | "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk |
| 4789 | ); |
| 4790 | } |
| 4791 | return this; |
| 4792 | }; |
| 4793 | |
| 4794 | /** |
| 4795 | * Walk over the tree of JS snippets in this node and its children. The |
| 4796 | * walking function is called once for each snippet of JS and is passed that |
| 4797 | * snippet and the its original associated source's line/column location. |
| 4798 | * |
| 4799 | * @param aFn The traversal function. |
| 4800 | */ |
| 4801 | SourceNode.prototype.walk = function SourceNode_walk(aFn) { |
| 4802 | var chunk; |
| 4803 | for (var i = 0, len = this.children.length; i < len; i++) { |
| 4804 | chunk = this.children[i]; |
| 4805 | if (chunk[isSourceNode]) { |
| 4806 | chunk.walk(aFn); |
| 4807 | } |
| 4808 | else { |
| 4809 | if (chunk !== '') { |
| 4810 | aFn(chunk, { source: this.source, |
| 4811 | line: this.line, |
| 4812 | column: this.column, |
| 4813 | name: this.name }); |
| 4814 | } |
| 4815 | } |
| 4816 | } |
| 4817 | }; |
| 4818 | |
| 4819 | /** |
| 4820 | * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between |
| 4821 | * each of `this.children`. |
| 4822 | * |
| 4823 | * @param aSep The separator. |
| 4824 | */ |
| 4825 | SourceNode.prototype.join = function SourceNode_join(aSep) { |
| 4826 | var newChildren; |
| 4827 | var i; |
| 4828 | var len = this.children.length; |
| 4829 | if (len > 0) { |
| 4830 | newChildren = []; |
| 4831 | for (i = 0; i < len-1; i++) { |
| 4832 | newChildren.push(this.children[i]); |
| 4833 | newChildren.push(aSep); |
| 4834 | } |
| 4835 | newChildren.push(this.children[i]); |
| 4836 | this.children = newChildren; |
| 4837 | } |
| 4838 | return this; |
| 4839 | }; |
| 4840 | |
| 4841 | /** |
| 4842 | * Call String.prototype.replace on the very right-most source snippet. Useful |
| 4843 | * for trimming whitespace from the end of a source node, etc. |
| 4844 | * |
| 4845 | * @param aPattern The pattern to replace. |
| 4846 | * @param aReplacement The thing to replace the pattern with. |
| 4847 | */ |
| 4848 | SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) { |
| 4849 | var lastChild = this.children[this.children.length - 1]; |
| 4850 | if (lastChild[isSourceNode]) { |
| 4851 | lastChild.replaceRight(aPattern, aReplacement); |
| 4852 | } |
| 4853 | else if (typeof lastChild === 'string') { |
| 4854 | this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement); |
| 4855 | } |
| 4856 | else { |
| 4857 | this.children.push(''.replace(aPattern, aReplacement)); |
| 4858 | } |
| 4859 | return this; |
| 4860 | }; |
| 4861 | |
| 4862 | /** |
| 4863 | * Set the source content for a source file. This will be added to the SourceMapGenerator |
| 4864 | * in the sourcesContent field. |
| 4865 | * |
| 4866 | * @param aSourceFile The filename of the source file |
| 4867 | * @param aSourceContent The content of the source file |
| 4868 | */ |
| 4869 | SourceNode.prototype.setSourceContent = |
| 4870 | function SourceNode_setSourceContent(aSourceFile, aSourceContent) { |
| 4871 | this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent; |
| 4872 | }; |
| 4873 | |
| 4874 | /** |
| 4875 | * Walk over the tree of SourceNodes. The walking function is called for each |
| 4876 | * source file content and is passed the filename and source content. |
| 4877 | * |
| 4878 | * @param aFn The traversal function. |
| 4879 | */ |
| 4880 | SourceNode.prototype.walkSourceContents = |
| 4881 | function SourceNode_walkSourceContents(aFn) { |
| 4882 | for (var i = 0, len = this.children.length; i < len; i++) { |
| 4883 | if (this.children[i][isSourceNode]) { |
| 4884 | this.children[i].walkSourceContents(aFn); |
| 4885 | } |
| 4886 | } |
| 4887 | |
| 4888 | var sources = Object.keys(this.sourceContents); |
| 4889 | for (var i = 0, len = sources.length; i < len; i++) { |
| 4890 | aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]); |
| 4891 | } |
| 4892 | }; |
| 4893 | |
| 4894 | /** |
| 4895 | * Return the string representation of this source node. Walks over the tree |
| 4896 | * and concatenates all the various snippets together to one string. |
| 4897 | */ |
| 4898 | SourceNode.prototype.toString = function SourceNode_toString() { |
| 4899 | var str = ""; |
| 4900 | this.walk(function (chunk) { |
| 4901 | str += chunk; |
| 4902 | }); |
| 4903 | return str; |
| 4904 | }; |
| 4905 | |
| 4906 | /** |
| 4907 | * Returns the string representation of this source node along with a source |
| 4908 | * map. |
| 4909 | */ |
| 4910 | SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) { |
| 4911 | var generated = { |
| 4912 | code: "", |
| 4913 | line: 1, |
| 4914 | column: 0 |
| 4915 | }; |
| 4916 | var map = new SourceMapGenerator(aArgs); |
| 4917 | var sourceMappingActive = false; |
| 4918 | var lastOriginalSource = null; |
| 4919 | var lastOriginalLine = null; |
| 4920 | var lastOriginalColumn = null; |
| 4921 | var lastOriginalName = null; |
| 4922 | this.walk(function (chunk, original) { |
| 4923 | generated.code += chunk; |
| 4924 | if (original.source !== null |
| 4925 | && original.line !== null |
| 4926 | && original.column !== null) { |
| 4927 | if(lastOriginalSource !== original.source |
| 4928 | || lastOriginalLine !== original.line |
| 4929 | || lastOriginalColumn !== original.column |
| 4930 | || lastOriginalName !== original.name) { |
| 4931 | map.addMapping({ |
| 4932 | source: original.source, |
| 4933 | original: { |
| 4934 | line: original.line, |
| 4935 | column: original.column |
| 4936 | }, |
| 4937 | generated: { |
| 4938 | line: generated.line, |
| 4939 | column: generated.column |
| 4940 | }, |
| 4941 | name: original.name |
| 4942 | }); |
| 4943 | } |
| 4944 | lastOriginalSource = original.source; |
| 4945 | lastOriginalLine = original.line; |
| 4946 | lastOriginalColumn = original.column; |
| 4947 | lastOriginalName = original.name; |
| 4948 | sourceMappingActive = true; |
| 4949 | } else if (sourceMappingActive) { |
| 4950 | map.addMapping({ |
| 4951 | generated: { |
| 4952 | line: generated.line, |
| 4953 | column: generated.column |
| 4954 | } |
| 4955 | }); |
| 4956 | lastOriginalSource = null; |
| 4957 | sourceMappingActive = false; |
| 4958 | } |
| 4959 | for (var idx = 0, length = chunk.length; idx < length; idx++) { |
| 4960 | if (chunk.charCodeAt(idx) === NEWLINE_CODE) { |
| 4961 | generated.line++; |
| 4962 | generated.column = 0; |
| 4963 | // Mappings end at eol |
| 4964 | if (idx + 1 === length) { |
| 4965 | lastOriginalSource = null; |
| 4966 | sourceMappingActive = false; |
| 4967 | } else if (sourceMappingActive) { |
| 4968 | map.addMapping({ |
| 4969 | source: original.source, |
| 4970 | original: { |
| 4971 | line: original.line, |
| 4972 | column: original.column |
| 4973 | }, |
| 4974 | generated: { |
| 4975 | line: generated.line, |
| 4976 | column: generated.column |
| 4977 | }, |
| 4978 | name: original.name |
| 4979 | }); |
| 4980 | } |
| 4981 | } else { |
| 4982 | generated.column++; |
| 4983 | } |
| 4984 | } |
| 4985 | }); |
| 4986 | this.walkSourceContents(function (sourceFile, sourceContent) { |
| 4987 | map.setSourceContent(sourceFile, sourceContent); |
| 4988 | }); |
| 4989 | |
| 4990 | return { code: generated.code, map: map }; |
| 4991 | }; |
| 4992 | |
| 4993 | exports.SourceNode = SourceNode; |
| 4994 | |
| 4995 | },{"./source-map-generator":24,"./util":26}],26:[function(require,module,exports){ |
| 4996 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 4997 | /* |
| 4998 | * Copyright 2011 Mozilla Foundation and contributors |
| 4999 | * Licensed under the New BSD license. See LICENSE or: |
| 5000 | * http://opensource.org/licenses/BSD-3-Clause |
| 5001 | */ |
| 5002 | |
| 5003 | /** |
| 5004 | * This is a helper function for getting values from parameter/options |
| 5005 | * objects. |
| 5006 | * |
| 5007 | * @param args The object we are extracting values from |
| 5008 | * @param name The name of the property we are getting. |
| 5009 | * @param defaultValue An optional value to return if the property is missing |
| 5010 | * from the object. If this is not specified and the property is missing, an |
| 5011 | * error will be thrown. |
| 5012 | */ |
| 5013 | function getArg(aArgs, aName, aDefaultValue) { |
| 5014 | if (aName in aArgs) { |
| 5015 | return aArgs[aName]; |
| 5016 | } else if (arguments.length === 3) { |
| 5017 | return aDefaultValue; |
| 5018 | } else { |
| 5019 | throw new Error('"' + aName + '" is a required argument.'); |
| 5020 | } |
| 5021 | } |
| 5022 | exports.getArg = getArg; |
| 5023 | |
| 5024 | var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/; |
| 5025 | var dataUrlRegexp = /^data:.+\,.+$/; |
| 5026 | |
| 5027 | function urlParse(aUrl) { |
| 5028 | var match = aUrl.match(urlRegexp); |
| 5029 | if (!match) { |
| 5030 | return null; |
| 5031 | } |
| 5032 | return { |
| 5033 | scheme: match[1], |
| 5034 | auth: match[2], |
| 5035 | host: match[3], |
| 5036 | port: match[4], |
| 5037 | path: match[5] |
| 5038 | }; |
| 5039 | } |
| 5040 | exports.urlParse = urlParse; |
| 5041 | |
| 5042 | function urlGenerate(aParsedUrl) { |
| 5043 | var url = ''; |
| 5044 | if (aParsedUrl.scheme) { |
| 5045 | url += aParsedUrl.scheme + ':'; |
| 5046 | } |
| 5047 | url += '//'; |
| 5048 | if (aParsedUrl.auth) { |
| 5049 | url += aParsedUrl.auth + '@'; |
| 5050 | } |
| 5051 | if (aParsedUrl.host) { |
| 5052 | url += aParsedUrl.host; |
| 5053 | } |
| 5054 | if (aParsedUrl.port) { |
| 5055 | url += ":" + aParsedUrl.port |
| 5056 | } |
| 5057 | if (aParsedUrl.path) { |
| 5058 | url += aParsedUrl.path; |
| 5059 | } |
| 5060 | return url; |
| 5061 | } |
| 5062 | exports.urlGenerate = urlGenerate; |
| 5063 | |
| 5064 | /** |
| 5065 | * Normalizes a path, or the path portion of a URL: |
| 5066 | * |
| 5067 | * - Replaces consecutive slashes with one slash. |
| 5068 | * - Removes unnecessary '.' parts. |
| 5069 | * - Removes unnecessary '<dir>/..' parts. |
| 5070 | * |
| 5071 | * Based on code in the Node.js 'path' core module. |
| 5072 | * |
| 5073 | * @param aPath The path or url to normalize. |
| 5074 | */ |
| 5075 | function normalize(aPath) { |
| 5076 | var path = aPath; |
| 5077 | var url = urlParse(aPath); |
| 5078 | if (url) { |
| 5079 | if (!url.path) { |
| 5080 | return aPath; |
| 5081 | } |
| 5082 | path = url.path; |
| 5083 | } |
| 5084 | var isAbsolute = exports.isAbsolute(path); |
| 5085 | |
| 5086 | var parts = path.split(/\/+/); |
| 5087 | for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { |
| 5088 | part = parts[i]; |
| 5089 | if (part === '.') { |
| 5090 | parts.splice(i, 1); |
| 5091 | } else if (part === '..') { |
| 5092 | up++; |
| 5093 | } else if (up > 0) { |
| 5094 | if (part === '') { |
| 5095 | // The first part is blank if the path is absolute. Trying to go |
| 5096 | // above the root is a no-op. Therefore we can remove all '..' parts |
| 5097 | // directly after the root. |
| 5098 | parts.splice(i + 1, up); |
| 5099 | up = 0; |
| 5100 | } else { |
| 5101 | parts.splice(i, 2); |
| 5102 | up--; |
| 5103 | } |
| 5104 | } |
| 5105 | } |
| 5106 | path = parts.join('/'); |
| 5107 | |
| 5108 | if (path === '') { |
| 5109 | path = isAbsolute ? '/' : '.'; |
| 5110 | } |
| 5111 | |
| 5112 | if (url) { |
| 5113 | url.path = path; |
| 5114 | return urlGenerate(url); |
| 5115 | } |
| 5116 | return path; |
| 5117 | } |
| 5118 | exports.normalize = normalize; |
| 5119 | |
| 5120 | /** |
| 5121 | * Joins two paths/URLs. |
| 5122 | * |
| 5123 | * @param aRoot The root path or URL. |
| 5124 | * @param aPath The path or URL to be joined with the root. |
| 5125 | * |
| 5126 | * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a |
| 5127 | * scheme-relative URL: Then the scheme of aRoot, if any, is prepended |
| 5128 | * first. |
| 5129 | * - Otherwise aPath is a path. If aRoot is a URL, then its path portion |
| 5130 | * is updated with the result and aRoot is returned. Otherwise the result |
| 5131 | * is returned. |
| 5132 | * - If aPath is absolute, the result is aPath. |
| 5133 | * - Otherwise the two paths are joined with a slash. |
| 5134 | * - Joining for example 'http://' and 'www.example.com' is also supported. |
| 5135 | */ |
| 5136 | function join(aRoot, aPath) { |
| 5137 | if (aRoot === "") { |
| 5138 | aRoot = "."; |
| 5139 | } |
| 5140 | if (aPath === "") { |
| 5141 | aPath = "."; |
| 5142 | } |
| 5143 | var aPathUrl = urlParse(aPath); |
| 5144 | var aRootUrl = urlParse(aRoot); |
| 5145 | if (aRootUrl) { |
| 5146 | aRoot = aRootUrl.path || '/'; |
| 5147 | } |
| 5148 | |
| 5149 | // `join(foo, '//www.example.org')` |
| 5150 | if (aPathUrl && !aPathUrl.scheme) { |
| 5151 | if (aRootUrl) { |
| 5152 | aPathUrl.scheme = aRootUrl.scheme; |
| 5153 | } |
| 5154 | return urlGenerate(aPathUrl); |
| 5155 | } |
| 5156 | |
| 5157 | if (aPathUrl || aPath.match(dataUrlRegexp)) { |
| 5158 | return aPath; |
| 5159 | } |
| 5160 | |
| 5161 | // `join('http://', 'www.example.com')` |
| 5162 | if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { |
| 5163 | aRootUrl.host = aPath; |
| 5164 | return urlGenerate(aRootUrl); |
| 5165 | } |
| 5166 | |
| 5167 | var joined = aPath.charAt(0) === '/' |
| 5168 | ? aPath |
| 5169 | : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); |
| 5170 | |
| 5171 | if (aRootUrl) { |
| 5172 | aRootUrl.path = joined; |
| 5173 | return urlGenerate(aRootUrl); |
| 5174 | } |
| 5175 | return joined; |
| 5176 | } |
| 5177 | exports.join = join; |
| 5178 | |
| 5179 | exports.isAbsolute = function (aPath) { |
| 5180 | return aPath.charAt(0) === '/' || urlRegexp.test(aPath); |
| 5181 | }; |
| 5182 | |
| 5183 | /** |
| 5184 | * Make a path relative to a URL or another path. |
| 5185 | * |
| 5186 | * @param aRoot The root path or URL. |
| 5187 | * @param aPath The path or URL to be made relative to aRoot. |
| 5188 | */ |
| 5189 | function relative(aRoot, aPath) { |
| 5190 | if (aRoot === "") { |
| 5191 | aRoot = "."; |
| 5192 | } |
| 5193 | |
| 5194 | aRoot = aRoot.replace(/\/$/, ''); |
| 5195 | |
| 5196 | // It is possible for the path to be above the root. In this case, simply |
| 5197 | // checking whether the root is a prefix of the path won't work. Instead, we |
| 5198 | // need to remove components from the root one by one, until either we find |
| 5199 | // a prefix that fits, or we run out of components to remove. |
| 5200 | var level = 0; |
| 5201 | while (aPath.indexOf(aRoot + '/') !== 0) { |
| 5202 | var index = aRoot.lastIndexOf("/"); |
| 5203 | if (index < 0) { |
| 5204 | return aPath; |
| 5205 | } |
| 5206 | |
| 5207 | // If the only part of the root that is left is the scheme (i.e. http://, |
| 5208 | // file:///, etc.), one or more slashes (/), or simply nothing at all, we |
| 5209 | // have exhausted all components, so the path is not relative to the root. |
| 5210 | aRoot = aRoot.slice(0, index); |
| 5211 | if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { |
| 5212 | return aPath; |
| 5213 | } |
| 5214 | |
| 5215 | ++level; |
| 5216 | } |
| 5217 | |
| 5218 | // Make sure we add a "../" for each component we removed from the root. |
| 5219 | return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); |
| 5220 | } |
| 5221 | exports.relative = relative; |
| 5222 | |
| 5223 | var supportsNullProto = (function () { |
| 5224 | var obj = Object.create(null); |
| 5225 | return !('__proto__' in obj); |
| 5226 | }()); |
| 5227 | |
| 5228 | function identity (s) { |
| 5229 | return s; |
| 5230 | } |
| 5231 | |
| 5232 | /** |
| 5233 | * Because behavior goes wacky when you set `__proto__` on objects, we |
| 5234 | * have to prefix all the strings in our set with an arbitrary character. |
| 5235 | * |
| 5236 | * See https://github.com/mozilla/source-map/pull/31 and |
| 5237 | * https://github.com/mozilla/source-map/issues/30 |
| 5238 | * |
| 5239 | * @param String aStr |
| 5240 | */ |
| 5241 | function toSetString(aStr) { |
| 5242 | if (isProtoString(aStr)) { |
| 5243 | return '$' + aStr; |
| 5244 | } |
| 5245 | |
| 5246 | return aStr; |
| 5247 | } |
| 5248 | exports.toSetString = supportsNullProto ? identity : toSetString; |
| 5249 | |
| 5250 | function fromSetString(aStr) { |
| 5251 | if (isProtoString(aStr)) { |
| 5252 | return aStr.slice(1); |
| 5253 | } |
| 5254 | |
| 5255 | return aStr; |
| 5256 | } |
| 5257 | exports.fromSetString = supportsNullProto ? identity : fromSetString; |
| 5258 | |
| 5259 | function isProtoString(s) { |
| 5260 | if (!s) { |
| 5261 | return false; |
| 5262 | } |
| 5263 | |
| 5264 | var length = s.length; |
| 5265 | |
| 5266 | if (length < 9 /* "__proto__".length */) { |
| 5267 | return false; |
| 5268 | } |
| 5269 | |
| 5270 | if (s.charCodeAt(length - 1) !== 95 /* '_' */ || |
| 5271 | s.charCodeAt(length - 2) !== 95 /* '_' */ || |
| 5272 | s.charCodeAt(length - 3) !== 111 /* 'o' */ || |
| 5273 | s.charCodeAt(length - 4) !== 116 /* 't' */ || |
| 5274 | s.charCodeAt(length - 5) !== 111 /* 'o' */ || |
| 5275 | s.charCodeAt(length - 6) !== 114 /* 'r' */ || |
| 5276 | s.charCodeAt(length - 7) !== 112 /* 'p' */ || |
| 5277 | s.charCodeAt(length - 8) !== 95 /* '_' */ || |
| 5278 | s.charCodeAt(length - 9) !== 95 /* '_' */) { |
| 5279 | return false; |
| 5280 | } |
| 5281 | |
| 5282 | for (var i = length - 10; i >= 0; i--) { |
| 5283 | if (s.charCodeAt(i) !== 36 /* '$' */) { |
| 5284 | return false; |
| 5285 | } |
| 5286 | } |
| 5287 | |
| 5288 | return true; |
| 5289 | } |
| 5290 | |
| 5291 | /** |
| 5292 | * Comparator between two mappings where the original positions are compared. |
| 5293 | * |
| 5294 | * Optionally pass in `true` as `onlyCompareGenerated` to consider two |
| 5295 | * mappings with the same original source/line/column, but different generated |
| 5296 | * line and column the same. Useful when searching for a mapping with a |
| 5297 | * stubbed out mapping. |
| 5298 | */ |
| 5299 | function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { |
| 5300 | var cmp = strcmp(mappingA.source, mappingB.source); |
| 5301 | if (cmp !== 0) { |
| 5302 | return cmp; |
| 5303 | } |
| 5304 | |
| 5305 | cmp = mappingA.originalLine - mappingB.originalLine; |
| 5306 | if (cmp !== 0) { |
| 5307 | return cmp; |
| 5308 | } |
| 5309 | |
| 5310 | cmp = mappingA.originalColumn - mappingB.originalColumn; |
| 5311 | if (cmp !== 0 || onlyCompareOriginal) { |
| 5312 | return cmp; |
| 5313 | } |
| 5314 | |
| 5315 | cmp = mappingA.generatedColumn - mappingB.generatedColumn; |
| 5316 | if (cmp !== 0) { |
| 5317 | return cmp; |
| 5318 | } |
| 5319 | |
| 5320 | cmp = mappingA.generatedLine - mappingB.generatedLine; |
| 5321 | if (cmp !== 0) { |
| 5322 | return cmp; |
| 5323 | } |
| 5324 | |
| 5325 | return strcmp(mappingA.name, mappingB.name); |
| 5326 | } |
| 5327 | exports.compareByOriginalPositions = compareByOriginalPositions; |
| 5328 | |
| 5329 | /** |
| 5330 | * Comparator between two mappings with deflated source and name indices where |
| 5331 | * the generated positions are compared. |
| 5332 | * |
| 5333 | * Optionally pass in `true` as `onlyCompareGenerated` to consider two |
| 5334 | * mappings with the same generated line and column, but different |
| 5335 | * source/name/original line and column the same. Useful when searching for a |
| 5336 | * mapping with a stubbed out mapping. |
| 5337 | */ |
| 5338 | function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { |
| 5339 | var cmp = mappingA.generatedLine - mappingB.generatedLine; |
| 5340 | if (cmp !== 0) { |
| 5341 | return cmp; |
| 5342 | } |
| 5343 | |
| 5344 | cmp = mappingA.generatedColumn - mappingB.generatedColumn; |
| 5345 | if (cmp !== 0 || onlyCompareGenerated) { |
| 5346 | return cmp; |
| 5347 | } |
| 5348 | |
| 5349 | cmp = strcmp(mappingA.source, mappingB.source); |
| 5350 | if (cmp !== 0) { |
| 5351 | return cmp; |
| 5352 | } |
| 5353 | |
| 5354 | cmp = mappingA.originalLine - mappingB.originalLine; |
| 5355 | if (cmp !== 0) { |
| 5356 | return cmp; |
| 5357 | } |
| 5358 | |
| 5359 | cmp = mappingA.originalColumn - mappingB.originalColumn; |
| 5360 | if (cmp !== 0) { |
| 5361 | return cmp; |
| 5362 | } |
| 5363 | |
| 5364 | return strcmp(mappingA.name, mappingB.name); |
| 5365 | } |
| 5366 | exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; |
| 5367 | |
| 5368 | function strcmp(aStr1, aStr2) { |
| 5369 | if (aStr1 === aStr2) { |
| 5370 | return 0; |
| 5371 | } |
| 5372 | |
| 5373 | if (aStr1 === null) { |
| 5374 | return 1; // aStr2 !== null |
| 5375 | } |
| 5376 | |
| 5377 | if (aStr2 === null) { |
| 5378 | return -1; // aStr1 !== null |
| 5379 | } |
| 5380 | |
| 5381 | if (aStr1 > aStr2) { |
| 5382 | return 1; |
| 5383 | } |
| 5384 | |
| 5385 | return -1; |
| 5386 | } |
| 5387 | |
| 5388 | /** |
| 5389 | * Comparator between two mappings with inflated source and name strings where |
| 5390 | * the generated positions are compared. |
| 5391 | */ |
| 5392 | function compareByGeneratedPositionsInflated(mappingA, mappingB) { |
| 5393 | var cmp = mappingA.generatedLine - mappingB.generatedLine; |
| 5394 | if (cmp !== 0) { |
| 5395 | return cmp; |
| 5396 | } |
| 5397 | |
| 5398 | cmp = mappingA.generatedColumn - mappingB.generatedColumn; |
| 5399 | if (cmp !== 0) { |
| 5400 | return cmp; |
| 5401 | } |
| 5402 | |
| 5403 | cmp = strcmp(mappingA.source, mappingB.source); |
| 5404 | if (cmp !== 0) { |
| 5405 | return cmp; |
| 5406 | } |
| 5407 | |
| 5408 | cmp = mappingA.originalLine - mappingB.originalLine; |
| 5409 | if (cmp !== 0) { |
| 5410 | return cmp; |
| 5411 | } |
| 5412 | |
| 5413 | cmp = mappingA.originalColumn - mappingB.originalColumn; |
| 5414 | if (cmp !== 0) { |
| 5415 | return cmp; |
| 5416 | } |
| 5417 | |
| 5418 | return strcmp(mappingA.name, mappingB.name); |
| 5419 | } |
| 5420 | exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; |
| 5421 | |
| 5422 | /** |
| 5423 | * Strip any JSON XSSI avoidance prefix from the string (as documented |
| 5424 | * in the source maps specification), and then parse the string as |
| 5425 | * JSON. |
| 5426 | */ |
| 5427 | function parseSourceMapInput(str) { |
| 5428 | return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, '')); |
| 5429 | } |
| 5430 | exports.parseSourceMapInput = parseSourceMapInput; |
| 5431 | |
| 5432 | /** |
| 5433 | * Compute the URL of a source given the the source root, the source's |
| 5434 | * URL, and the source map's URL. |
| 5435 | */ |
| 5436 | function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) { |
| 5437 | sourceURL = sourceURL || ''; |
| 5438 | |
| 5439 | if (sourceRoot) { |
| 5440 | // This follows what Chrome does. |
| 5441 | if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') { |
| 5442 | sourceRoot += '/'; |
| 5443 | } |
| 5444 | // The spec says: |
| 5445 | // Line 4: An optional source root, useful for relocating source |
| 5446 | // files on a server or removing repeated values in the |
| 5447 | // “sources” entry. This value is prepended to the individual |
| 5448 | // entries in the “source” field. |
| 5449 | sourceURL = sourceRoot + sourceURL; |
| 5450 | } |
| 5451 | |
| 5452 | // Historically, SourceMapConsumer did not take the sourceMapURL as |
| 5453 | // a parameter. This mode is still somewhat supported, which is why |
| 5454 | // this code block is conditional. However, it's preferable to pass |
| 5455 | // the source map URL to SourceMapConsumer, so that this function |
| 5456 | // can implement the source URL resolution algorithm as outlined in |
| 5457 | // the spec. This block is basically the equivalent of: |
| 5458 | // new URL(sourceURL, sourceMapURL).toString() |
| 5459 | // ... except it avoids using URL, which wasn't available in the |
| 5460 | // older releases of node still supported by this library. |
| 5461 | // |
| 5462 | // The spec says: |
| 5463 | // If the sources are not absolute URLs after prepending of the |
| 5464 | // “sourceRoot”, the sources are resolved relative to the |
| 5465 | // SourceMap (like resolving script src in a html document). |
| 5466 | if (sourceMapURL) { |
| 5467 | var parsed = urlParse(sourceMapURL); |
| 5468 | if (!parsed) { |
| 5469 | throw new Error("sourceMapURL could not be parsed"); |
| 5470 | } |
| 5471 | if (parsed.path) { |
| 5472 | // Strip the last path component, but keep the "/". |
| 5473 | var index = parsed.path.lastIndexOf('/'); |
| 5474 | if (index >= 0) { |
| 5475 | parsed.path = parsed.path.substring(0, index + 1); |
| 5476 | } |
| 5477 | } |
| 5478 | sourceURL = join(urlGenerate(parsed), sourceURL); |
| 5479 | } |
| 5480 | |
| 5481 | return normalize(sourceURL); |
| 5482 | } |
| 5483 | exports.computeSourceURL = computeSourceURL; |
| 5484 | |
| 5485 | },{}],27:[function(require,module,exports){ |
| 5486 | /* |
| 5487 | * Copyright 2009-2011 Mozilla Foundation and contributors |
| 5488 | * Licensed under the New BSD license. See LICENSE.txt or: |
| 5489 | * http://opensource.org/licenses/BSD-3-Clause |
| 5490 | */ |
| 5491 | exports.SourceMapGenerator = require('./lib/source-map-generator').SourceMapGenerator; |
| 5492 | exports.SourceMapConsumer = require('./lib/source-map-consumer').SourceMapConsumer; |
| 5493 | exports.SourceNode = require('./lib/source-node').SourceNode; |
| 5494 | |
| 5495 | },{"./lib/source-map-consumer":23,"./lib/source-map-generator":24,"./lib/source-node":25}],28:[function(require,module,exports){ |
| 5496 | // Copyright 2014 Simon Lydell |
| 5497 | // X11 (“MIT”) Licensed. (See LICENSE.) |
| 5498 | |
| 5499 | var path = require("path") |
| 5500 | |
| 5501 | "use strict" |
| 5502 | |
| 5503 | function urix(aPath) { |
| 5504 | if (path.sep === "\\") { |
| 5505 | return aPath |
| 5506 | .replace(/\\/g, "/") |
| 5507 | .replace(/^[a-z]:\/?/i, "/") |
| 5508 | } |
| 5509 | return aPath |
| 5510 | } |
| 5511 | |
| 5512 | module.exports = urix |
| 5513 | |
| 5514 | },{"path":2}]},{},[5]); |
| 5515 |