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