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