mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
2614 lines
256 KiB
JavaScript
2614 lines
256 KiB
JavaScript
|
// https://developer.mozilla.org/en/JavaScript/Reference/global_objects/array/foreach
|
|||
|
|
|||
|
if (!Array.prototype.forEach)
|
|||
|
{
|
|||
|
Array.prototype.forEach = function(fun /*, thisp */)
|
|||
|
{
|
|||
|
"use strict";
|
|||
|
|
|||
|
if (this === void 0 || this === null)
|
|||
|
throw new TypeError();
|
|||
|
|
|||
|
var t = Object(this);
|
|||
|
var len = t.length >>> 0;
|
|||
|
if (typeof fun !== "function")
|
|||
|
throw new TypeError();
|
|||
|
|
|||
|
var thisp = arguments[1];
|
|||
|
for (var i = 0; i < len; i++)
|
|||
|
{
|
|||
|
if (i in t)
|
|||
|
fun.call(thisp, t[i], i, t);
|
|||
|
}
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
|
|||
|
// Production steps of ECMA-262, Edition 5, 15.4.4.19
|
|||
|
// Reference: http://es5.github.com/#x15.4.4.19
|
|||
|
if (!Array.prototype.map) {
|
|||
|
Array.prototype.map = function(callback, thisArg) {
|
|||
|
|
|||
|
var T, A, k;
|
|||
|
|
|||
|
if (this == null) {
|
|||
|
throw new TypeError(" this is null or not defined");
|
|||
|
}
|
|||
|
|
|||
|
// 1. Let O be the result of calling ToObject passing the |this| value as the argument.
|
|||
|
var O = Object(this);
|
|||
|
|
|||
|
// 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
|
|||
|
// 3. Let len be ToUint32(lenValue).
|
|||
|
var len = O.length >>> 0;
|
|||
|
|
|||
|
// 4. If IsCallable(callback) is false, throw a TypeError exception.
|
|||
|
// See: http://es5.github.com/#x9.11
|
|||
|
if ({}.toString.call(callback) != "[object Function]") {
|
|||
|
throw new TypeError(callback + " is not a function");
|
|||
|
}
|
|||
|
|
|||
|
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
|||
|
if (thisArg) {
|
|||
|
T = thisArg;
|
|||
|
}
|
|||
|
|
|||
|
// 6. Let A be a new array created as if by the expression new Array(len) where Array is
|
|||
|
// the standard built-in constructor with that name and len is the value of len.
|
|||
|
A = new Array(len);
|
|||
|
|
|||
|
// 7. Let k be 0
|
|||
|
k = 0;
|
|||
|
|
|||
|
// 8. Repeat, while k < len
|
|||
|
while(k < len) {
|
|||
|
|
|||
|
var kValue, mappedValue;
|
|||
|
|
|||
|
// a. Let Pk be ToString(k).
|
|||
|
// This is implicit for LHS operands of the in operator
|
|||
|
// b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
|
|||
|
// This step can be combined with c
|
|||
|
// c. If kPresent is true, then
|
|||
|
if (k in O) {
|
|||
|
|
|||
|
// i. Let kValue be the result of calling the Get internal method of O with argument Pk.
|
|||
|
kValue = O[ k ];
|
|||
|
|
|||
|
// ii. Let mappedValue be the result of calling the Call internal method of callback
|
|||
|
// with T as the this value and argument list containing kValue, k, and O.
|
|||
|
mappedValue = callback.call(T, kValue, k, O);
|
|||
|
|
|||
|
// iii. Call the DefineOwnProperty internal method of A with arguments
|
|||
|
// Pk, Property Descriptor {Value: mappedValue, Writable: true, Enumerable: true, Configurable: true},
|
|||
|
// and false.
|
|||
|
|
|||
|
// In browsers that support Object.defineProperty, use the following:
|
|||
|
// Object.defineProperty(A, Pk, { value: mappedValue, writable: true, enumerable: true, configurable: true });
|
|||
|
|
|||
|
// For best browser support, use the following:
|
|||
|
A[ k ] = mappedValue;
|
|||
|
}
|
|||
|
// d. Increase k by 1.
|
|||
|
k++;
|
|||
|
}
|
|||
|
|
|||
|
// 9. return A
|
|||
|
return A;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/Reduce
|
|||
|
|
|||
|
if (!Array.prototype.reduce)
|
|||
|
{
|
|||
|
Array.prototype.reduce = function(fun /*, initialValue */)
|
|||
|
{
|
|||
|
"use strict";
|
|||
|
|
|||
|
if (this === void 0 || this === null)
|
|||
|
throw new TypeError();
|
|||
|
|
|||
|
var t = Object(this);
|
|||
|
var len = t.length >>> 0;
|
|||
|
if (typeof fun !== "function")
|
|||
|
throw new TypeError();
|
|||
|
|
|||
|
// no value to return if no initial value and an empty array
|
|||
|
if (len == 0 && arguments.length == 1)
|
|||
|
throw new TypeError();
|
|||
|
|
|||
|
var k = 0;
|
|||
|
var accumulator;
|
|||
|
if (arguments.length >= 2)
|
|||
|
{
|
|||
|
accumulator = arguments[1];
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
do
|
|||
|
{
|
|||
|
if (k in t)
|
|||
|
{
|
|||
|
accumulator = t[k++];
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
// if array contains no values, no initial value to return
|
|||
|
if (++k >= len)
|
|||
|
throw new TypeError();
|
|||
|
}
|
|||
|
while (true);
|
|||
|
}
|
|||
|
|
|||
|
while (k < len)
|
|||
|
{
|
|||
|
if (k in t)
|
|||
|
accumulator = fun.call(undefined, accumulator, t[k], k, t);
|
|||
|
k++;
|
|||
|
}
|
|||
|
|
|||
|
return accumulator;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
|
|||
|
if (!Array.prototype.indexOf) {
|
|||
|
Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
|
|||
|
"use strict";
|
|||
|
if (this === void 0 || this === null) {
|
|||
|
throw new TypeError();
|
|||
|
}
|
|||
|
var t = Object(this);
|
|||
|
var len = t.length >>> 0;
|
|||
|
if (len === 0) {
|
|||
|
return -1;
|
|||
|
}
|
|||
|
var n = 0;
|
|||
|
if (arguments.length > 0) {
|
|||
|
n = Number(arguments[1]);
|
|||
|
if (n !== n) { // shortcut for verifying if it's NaN
|
|||
|
n = 0;
|
|||
|
} else if (n !== 0 && n !== Infinity && n !== -Infinity) {
|
|||
|
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
|||
|
}
|
|||
|
}
|
|||
|
if (n >= len) {
|
|||
|
return -1;
|
|||
|
}
|
|||
|
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
|
|||
|
for (; k < len; k++) {
|
|||
|
if (k in t && t[k] === searchElement) {
|
|||
|
return k;
|
|||
|
}
|
|||
|
}
|
|||
|
return -1;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/Object/keys
|
|||
|
if (!Object.keys) {
|
|||
|
Object.keys = (function () {
|
|||
|
var hasOwnProperty = Object.prototype.hasOwnProperty,
|
|||
|
hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
|
|||
|
dontEnums = [
|
|||
|
'toString',
|
|||
|
'toLocaleString',
|
|||
|
'valueOf',
|
|||
|
'hasOwnProperty',
|
|||
|
'isPrototypeOf',
|
|||
|
'propertyIsEnumerable',
|
|||
|
'constructor'
|
|||
|
],
|
|||
|
dontEnumsLength = dontEnums.length;
|
|||
|
|
|||
|
return function (obj) {
|
|||
|
if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) throw new TypeError('Object.keys called on non-object');
|
|||
|
|
|||
|
var result = [];
|
|||
|
|
|||
|
for (var prop in obj) {
|
|||
|
if (hasOwnProperty.call(obj, prop)) result.push(prop);
|
|||
|
}
|
|||
|
|
|||
|
if (hasDontEnumBug) {
|
|||
|
for (var i=0; i < dontEnumsLength; i++) {
|
|||
|
if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
})()
|
|||
|
};
|
|||
|
|
|||
|
// https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/Object/create
|
|||
|
if (!Object.create) {
|
|||
|
Object.create = function (o) {
|
|||
|
if (arguments.length > 1) {
|
|||
|
throw new Error('Object.create implementation only accepts the first parameter.');
|
|||
|
}
|
|||
|
function F() {}
|
|||
|
F.prototype = o;
|
|||
|
return new F();
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/Array/filter
|
|||
|
if (!Array.prototype.filter)
|
|||
|
{
|
|||
|
Array.prototype.filter = function(fun /*, thisp*/)
|
|||
|
{
|
|||
|
"use strict";
|
|||
|
|
|||
|
if (this == null)
|
|||
|
throw new TypeError();
|
|||
|
|
|||
|
var t = Object(this);
|
|||
|
var len = t.length >>> 0;
|
|||
|
if (typeof fun != "function")
|
|||
|
throw new TypeError();
|
|||
|
|
|||
|
var res = [];
|
|||
|
var thisp = arguments[1];
|
|||
|
for (var i = 0; i < len; i++)
|
|||
|
{
|
|||
|
if (i in t)
|
|||
|
{
|
|||
|
var val = t[i]; // in case fun mutates this
|
|||
|
if (fun.call(thisp, val, i, t))
|
|||
|
res.push(val);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return res;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/Function/bind
|
|||
|
if (!Function.prototype.bind) {
|
|||
|
Function.prototype.bind = function (oThis) {
|
|||
|
if (typeof this !== "function") {
|
|||
|
// closest thing possible to the ECMAScript 5 internal IsCallable function
|
|||
|
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
|
|||
|
}
|
|||
|
|
|||
|
var aArgs = Array.prototype.slice.call(arguments, 1),
|
|||
|
fToBind = this,
|
|||
|
fNOP = function () {},
|
|||
|
fBound = function () {
|
|||
|
return fToBind.apply(this instanceof fNOP && oThis
|
|||
|
? this
|
|||
|
: oThis,
|
|||
|
aArgs.concat(Array.prototype.slice.call(arguments)));
|
|||
|
};
|
|||
|
|
|||
|
fNOP.prototype = this.prototype;
|
|||
|
fBound.prototype = new fNOP();
|
|||
|
|
|||
|
return fBound;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/Array/isArray
|
|||
|
if(!Array.isArray) {
|
|||
|
Array.isArray = function (vArg) {
|
|||
|
return Object.prototype.toString.call(vArg) === "[object Array]";
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
// https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/String/trim
|
|||
|
if(!String.prototype.trim) {
|
|||
|
String.prototype.trim = function () {
|
|||
|
return this.replace(/^\s+|\s+$/g,'');
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
function definePropertyWorks() {
|
|||
|
try {
|
|||
|
Object.defineProperty({}, "property", {});
|
|||
|
return "property" in object;
|
|||
|
} catch (exception) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (!definePropertyWorks()) {
|
|||
|
Object.defineProperty = function defineProperty(object) {
|
|||
|
// fail silently
|
|||
|
return object;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/*!
|
|||
|
* Cross-Browser Split 1.1.1
|
|||
|
* Copyright 2007-2012 Steven Levithan <stevenlevithan.com>
|
|||
|
* Available under the MIT License
|
|||
|
* ECMAScript compliant, uniform cross-browser split method
|
|||
|
*/
|
|||
|
|
|||
|
/**
|
|||
|
* Splits a string into an array of strings using a regex or string separator. Matches of the
|
|||
|
* separator are not included in the result array. However, if `separator` is a regex that contains
|
|||
|
* capturing groups, backreferences are spliced into the result each time `separator` is matched.
|
|||
|
* Fixes browser bugs compared to the native `String.prototype.split` and can be used reliably
|
|||
|
* cross-browser.
|
|||
|
* @param {String} str String to split.
|
|||
|
* @param {RegExp|String} separator Regex or string to use for separating the string.
|
|||
|
* @param {Number} [limit] Maximum number of items to include in the result array.
|
|||
|
* @returns {Array} Array of substrings.
|
|||
|
* @example
|
|||
|
*
|
|||
|
* // Basic use
|
|||
|
* split('a b c d', ' ');
|
|||
|
* // -> ['a', 'b', 'c', 'd']
|
|||
|
*
|
|||
|
* // With limit
|
|||
|
* split('a b c d', ' ', 2);
|
|||
|
* // -> ['a', 'b']
|
|||
|
*
|
|||
|
* // Backreferences in result array
|
|||
|
* split('..word1 word2..', /([a-z]+)(\d+)/i);
|
|||
|
* // -> ['..', 'word', '1', ' ', 'word', '2', '..']
|
|||
|
*/
|
|||
|
var split;
|
|||
|
|
|||
|
// Avoid running twice; that would break the `nativeSplit` reference
|
|||
|
split = split || function (undef) {
|
|||
|
|
|||
|
var nativeSplit = String.prototype.split,
|
|||
|
compliantExecNpcg = /()??/.exec("")[1] === undef, // NPCG: nonparticipating capturing group
|
|||
|
self;
|
|||
|
|
|||
|
self = function (str, separator, limit) {
|
|||
|
// If `separator` is not a regex, use `nativeSplit`
|
|||
|
if (Object.prototype.toString.call(separator) !== "[object RegExp]") {
|
|||
|
return nativeSplit.call(str, separator, limit);
|
|||
|
}
|
|||
|
var output = [],
|
|||
|
flags = (separator.ignoreCase ? "i" : "") +
|
|||
|
(separator.multiline ? "m" : "") +
|
|||
|
(separator.extended ? "x" : "") + // Proposed for ES6
|
|||
|
(separator.sticky ? "y" : ""), // Firefox 3+
|
|||
|
lastLastIndex = 0,
|
|||
|
// Make `global` and avoid `lastIndex` issues by working with a copy
|
|||
|
separator = new RegExp(separator.source, flags + "g"),
|
|||
|
separator2, match, lastIndex, lastLength;
|
|||
|
str += ""; // Type-convert
|
|||
|
if (!compliantExecNpcg) {
|
|||
|
// Doesn't need flags gy, but they don't hurt
|
|||
|
separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags);
|
|||
|
}
|
|||
|
/* Values for `limit`, per the spec:
|
|||
|
* If undefined: 4294967295 // Math.pow(2, 32) - 1
|
|||
|
* If 0, Infinity, or NaN: 0
|
|||
|
* If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
|
|||
|
* If negative number: 4294967296 - Math.floor(Math.abs(limit))
|
|||
|
* If other: Type-convert, then use the above rules
|
|||
|
*/
|
|||
|
limit = limit === undef ?
|
|||
|
-1 >>> 0 : // Math.pow(2, 32) - 1
|
|||
|
limit >>> 0; // ToUint32(limit)
|
|||
|
while (match = separator.exec(str)) {
|
|||
|
// `separator.lastIndex` is not reliable cross-browser
|
|||
|
lastIndex = match.index + match[0].length;
|
|||
|
if (lastIndex > lastLastIndex) {
|
|||
|
output.push(str.slice(lastLastIndex, match.index));
|
|||
|
// Fix browsers whose `exec` methods don't consistently return `undefined` for
|
|||
|
// nonparticipating capturing groups
|
|||
|
if (!compliantExecNpcg && match.length > 1) {
|
|||
|
match[0].replace(separator2, function () {
|
|||
|
for (var i = 1; i < arguments.length - 2; i++) {
|
|||
|
if (arguments[i] === undef) {
|
|||
|
match[i] = undef;
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
if (match.length > 1 && match.index < str.length) {
|
|||
|
Array.prototype.push.apply(output, match.slice(1));
|
|||
|
}
|
|||
|
lastLength = match[0].length;
|
|||
|
lastLastIndex = lastIndex;
|
|||
|
if (output.length >= limit) {
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
if (separator.lastIndex === match.index) {
|
|||
|
separator.lastIndex++; // Avoid an infinite loop
|
|||
|
}
|
|||
|
}
|
|||
|
if (lastLastIndex === str.length) {
|
|||
|
if (lastLength || !separator.test("")) {
|
|||
|
output.push("");
|
|||
|
}
|
|||
|
} else {
|
|||
|
output.push(str.slice(lastLastIndex));
|
|||
|
}
|
|||
|
return output.length > limit ? output.slice(0, limit) : output;
|
|||
|
};
|
|||
|
|
|||
|
if ("\n".split(/\n/).length == 0) {
|
|||
|
String.prototype.split = function (separator, limit) {
|
|||
|
return self(this, separator, limit);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
return self;
|
|||
|
|
|||
|
}();
|
|||
|
|
|||
|
window = this;/* -*- Mode: js; js-indent-level: 2; -*- */
|
|||
|
/*
|
|||
|
* Copyright 2011 Mozilla Foundation and contributors
|
|||
|
* Licensed under the New BSD license. See LICENSE or:
|
|||
|
* http://opensource.org/licenses/BSD-3-Clause
|
|||
|
*/
|
|||
|
|
|||
|
/**
|
|||
|
* Define a module along with a payload.
|
|||
|
* @param {string} moduleName Name for the payload
|
|||
|
* @param {ignored} deps Ignored. For compatibility with CommonJS AMD Spec
|
|||
|
* @param {function} payload Function with (require, exports, module) params
|
|||
|
*/
|
|||
|
function define(moduleName, deps, payload) {
|
|||
|
if (typeof moduleName != "string") {
|
|||
|
throw new TypeError('Expected string, got: ' + moduleName);
|
|||
|
}
|
|||
|
|
|||
|
if (arguments.length == 2) {
|
|||
|
payload = deps;
|
|||
|
}
|
|||
|
|
|||
|
if (moduleName in define.modules) {
|
|||
|
throw new Error("Module already defined: " + moduleName);
|
|||
|
}
|
|||
|
define.modules[moduleName] = payload;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* The global store of un-instantiated modules
|
|||
|
*/
|
|||
|
define.modules = {};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* We invoke require() in the context of a Domain so we can have multiple
|
|||
|
* sets of modules running separate from each other.
|
|||
|
* This contrasts with JSMs which are singletons, Domains allows us to
|
|||
|
* optionally load a CommonJS module twice with separate data each time.
|
|||
|
* Perhaps you want 2 command lines with a different set of commands in each,
|
|||
|
* for example.
|
|||
|
*/
|
|||
|
function Domain() {
|
|||
|
this.modules = {};
|
|||
|
this._currentModule = null;
|
|||
|
}
|
|||
|
|
|||
|
(function () {
|
|||
|
|
|||
|
/**
|
|||
|
* Lookup module names and resolve them by calling the definition function if
|
|||
|
* needed.
|
|||
|
* There are 2 ways to call this, either with an array of dependencies and a
|
|||
|
* callback to call when the dependencies are found (which can happen
|
|||
|
* asynchronously in an in-page context) or with a single string an no callback
|
|||
|
* where the dependency is resolved synchronously and returned.
|
|||
|
* The API is designed to be compatible with the CommonJS AMD spec and
|
|||
|
* RequireJS.
|
|||
|
* @param {string[]|string} deps A name, or names for the payload
|
|||
|
* @param {function|undefined} callback Function to call when the dependencies
|
|||
|
* are resolved
|
|||
|
* @return {undefined|object} The module required or undefined for
|
|||
|
* array/callback method
|
|||
|
*/
|
|||
|
Domain.prototype.require = function(deps, callback) {
|
|||
|
if (Array.isArray(deps)) {
|
|||
|
var params = deps.map(function(dep) {
|
|||
|
return this.lookup(dep);
|
|||
|
}, this);
|
|||
|
if (callback) {
|
|||
|
callback.apply(null, params);
|
|||
|
}
|
|||
|
return undefined;
|
|||
|
}
|
|||
|
else {
|
|||
|
return this.lookup(deps);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
function normalize(path) {
|
|||
|
var bits = path.split('/');
|
|||
|
var i = 1;
|
|||
|
while (i < bits.length) {
|
|||
|
if (bits[i] === '..') {
|
|||
|
bits.splice(i-1, 1);
|
|||
|
} else if (bits[i] === '.') {
|
|||
|
bits.splice(i, 1);
|
|||
|
} else {
|
|||
|
i++;
|
|||
|
}
|
|||
|
}
|
|||
|
return bits.join('/');
|
|||
|
}
|
|||
|
|
|||
|
function join(a, b) {
|
|||
|
a = a.trim();
|
|||
|
b = b.trim();
|
|||
|
if (/^\//.test(b)) {
|
|||
|
return b;
|
|||
|
} else {
|
|||
|
return a.replace(/\/*$/, '/') + b;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function dirname(path) {
|
|||
|
var bits = path.split('/');
|
|||
|
bits.pop();
|
|||
|
return bits.join('/');
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Lookup module names and resolve them by calling the definition function if
|
|||
|
* needed.
|
|||
|
* @param {string} moduleName A name for the payload to lookup
|
|||
|
* @return {object} The module specified by aModuleName or null if not found.
|
|||
|
*/
|
|||
|
Domain.prototype.lookup = function(moduleName) {
|
|||
|
if (/^\./.test(moduleName)) {
|
|||
|
moduleName = normalize(join(dirname(this._currentModule), moduleName));
|
|||
|
}
|
|||
|
|
|||
|
if (moduleName in this.modules) {
|
|||
|
var module = this.modules[moduleName];
|
|||
|
return module;
|
|||
|
}
|
|||
|
|
|||
|
if (!(moduleName in define.modules)) {
|
|||
|
throw new Error("Module not defined: " + moduleName);
|
|||
|
}
|
|||
|
|
|||
|
var module = define.modules[moduleName];
|
|||
|
|
|||
|
if (typeof module == "function") {
|
|||
|
var exports = {};
|
|||
|
var previousModule = this._currentModule;
|
|||
|
this._currentModule = moduleName;
|
|||
|
module(this.require.bind(this), exports, { id: moduleName, uri: "" });
|
|||
|
this._currentModule = previousModule;
|
|||
|
module = exports;
|
|||
|
}
|
|||
|
|
|||
|
// cache the resulting module object for next time
|
|||
|
this.modules[moduleName] = module;
|
|||
|
|
|||
|
return module;
|
|||
|
};
|
|||
|
|
|||
|
}());
|
|||
|
|
|||
|
define.Domain = Domain;
|
|||
|
define.globalDomain = new Domain();
|
|||
|
var require = define.globalDomain.require.bind(define.globalDomain);
|
|||
|
/* -*- Mode: js; js-indent-level: 2; -*- */
|
|||
|
/*
|
|||
|
* Copyright 2011 Mozilla Foundation and contributors
|
|||
|
* Licensed under the New BSD license. See LICENSE or:
|
|||
|
* http://opensource.org/licenses/BSD-3-Clause
|
|||
|
*/
|
|||
|
define('source-map/source-map-generator', ['require', 'exports', 'module' , 'source-map/base64-vlq', 'source-map/util', 'source-map/array-set'], function(require, exports, module) {
|
|||
|
|
|||
|
var base64VLQ = require('./base64-vlq');
|
|||
|
var util = require('./util');
|
|||
|
var ArraySet = require('./array-set').ArraySet;
|
|||
|
|
|||
|
/**
|
|||
|
* An instance of the SourceMapGenerator represents a source map which is
|
|||
|
* being built incrementally. To create a new one, you must pass an object
|
|||
|
* with the following properties:
|
|||
|
*
|
|||
|
* - file: The filename of the generated source.
|
|||
|
* - sourceRoot: An optional root for all URLs in this source map.
|
|||
|
*/
|
|||
|
function SourceMapGenerator(aArgs) {
|
|||
|
this._file = util.getArg(aArgs, 'file');
|
|||
|
this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
|
|||
|
this._sources = new ArraySet();
|
|||
|
this._names = new ArraySet();
|
|||
|
this._mappings = [];
|
|||
|
this._sourcesContents = null;
|
|||
|
}
|
|||
|
|
|||
|
SourceMapGenerator.prototype._version = 3;
|
|||
|
|
|||
|
/**
|
|||
|
* Creates a new SourceMapGenerator based on a SourceMapConsumer
|
|||
|
*
|
|||
|
* @param aSourceMapConsumer The SourceMap.
|
|||
|
*/
|
|||
|
SourceMapGenerator.fromSourceMap =
|
|||
|
function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
|
|||
|
var sourceRoot = aSourceMapConsumer.sourceRoot;
|
|||
|
var generator = new SourceMapGenerator({
|
|||
|
file: aSourceMapConsumer.file,
|
|||
|
sourceRoot: sourceRoot
|
|||
|
});
|
|||
|
aSourceMapConsumer.eachMapping(function (mapping) {
|
|||
|
var newMapping = {
|
|||
|
generated: {
|
|||
|
line: mapping.generatedLine,
|
|||
|
column: mapping.generatedColumn
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
if (mapping.source) {
|
|||
|
newMapping.source = mapping.source;
|
|||
|
if (sourceRoot) {
|
|||
|
newMapping.source = util.relative(sourceRoot, newMapping.source);
|
|||
|
}
|
|||
|
|
|||
|
newMapping.original = {
|
|||
|
line: mapping.originalLine,
|
|||
|
column: mapping.originalColumn
|
|||
|
};
|
|||
|
|
|||
|
if (mapping.name) {
|
|||
|
newMapping.name = mapping.name;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
generator.addMapping(newMapping);
|
|||
|
});
|
|||
|
aSourceMapConsumer.sources.forEach(function (sourceFile) {
|
|||
|
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
|
|||
|
if (content) {
|
|||
|
generator.setSourceContent(sourceFile, content);
|
|||
|
}
|
|||
|
});
|
|||
|
return generator;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Add a single mapping from original source line and column to the generated
|
|||
|
* source's line and column for this source map being created. The mapping
|
|||
|
* object should have the following properties:
|
|||
|
*
|
|||
|
* - generated: An object with the generated line and column positions.
|
|||
|
* - original: An object with the original line and column positions.
|
|||
|
* - source: The original source file (relative to the sourceRoot).
|
|||
|
* - name: An optional original token name for this mapping.
|
|||
|
*/
|
|||
|
SourceMapGenerator.prototype.addMapping =
|
|||
|
function SourceMapGenerator_addMapping(aArgs) {
|
|||
|
var generated = util.getArg(aArgs, 'generated');
|
|||
|
var original = util.getArg(aArgs, 'original', null);
|
|||
|
var source = util.getArg(aArgs, 'source', null);
|
|||
|
var name = util.getArg(aArgs, 'name', null);
|
|||
|
|
|||
|
this._validateMapping(generated, original, source, name);
|
|||
|
|
|||
|
if (source && !this._sources.has(source)) {
|
|||
|
this._sources.add(source);
|
|||
|
}
|
|||
|
|
|||
|
if (name && !this._names.has(name)) {
|
|||
|
this._names.add(name);
|
|||
|
}
|
|||
|
|
|||
|
this._mappings.push({
|
|||
|
generated: generated,
|
|||
|
original: original,
|
|||
|
source: source,
|
|||
|
name: name
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Set the source content for a source file.
|
|||
|
*/
|
|||
|
SourceMapGenerator.prototype.setSourceContent =
|
|||
|
function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
|
|||
|
var source = aSourceFile;
|
|||
|
if (this._sourceRoot) {
|
|||
|
source = util.relative(this._sourceRoot, source);
|
|||
|
}
|
|||
|
|
|||
|
if (aSourceContent !== null) {
|
|||
|
// Add the source content to the _sourcesContents map.
|
|||
|
// Create a new _sourcesContents map if the property is null.
|
|||
|
if (!this._sourcesContents) {
|
|||
|
this._sourcesContents = {};
|
|||
|
}
|
|||
|
this._sourcesContents[util.toSetString(source)] = aSourceContent;
|
|||
|
} else {
|
|||
|
// Remove the source file from the _sourcesContents map.
|
|||
|
// If the _sourcesContents map is empty, set the property to null.
|
|||
|
delete this._sourcesContents[util.toSetString(source)];
|
|||
|
if (Object.keys(this._sourcesContents).length === 0) {
|
|||
|
this._sourcesContents = null;
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Applies the mappings of a sub-source-map for a specific source file to the
|
|||
|
* source map being generated. Each mapping to the supplied source file is
|
|||
|
* rewritten using the supplied source map. Note: The resolution for the
|
|||
|
* resulting mappings is the minimium of this map and the supplied map.
|
|||
|
*
|
|||
|
* @param aSourceMapConsumer The source map to be applied.
|
|||
|
* @param aSourceFile Optional. The filename of the source file.
|
|||
|
* If omitted, SourceMapConsumer's file property will be used.
|
|||
|
*/
|
|||
|
SourceMapGenerator.prototype.applySourceMap =
|
|||
|
function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile) {
|
|||
|
// If aSourceFile is omitted, we will use the file property of the SourceMap
|
|||
|
if (!aSourceFile) {
|
|||
|
aSourceFile = aSourceMapConsumer.file;
|
|||
|
}
|
|||
|
var sourceRoot = this._sourceRoot;
|
|||
|
// Make "aSourceFile" relative if an absolute Url is passed.
|
|||
|
if (sourceRoot) {
|
|||
|
aSourceFile = util.relative(sourceRoot, aSourceFile);
|
|||
|
}
|
|||
|
// Applying the SourceMap can add and remove items from the sources and
|
|||
|
// the names array.
|
|||
|
var newSources = new ArraySet();
|
|||
|
var newNames = new ArraySet();
|
|||
|
|
|||
|
// Find mappings for the "aSourceFile"
|
|||
|
this._mappings.forEach(function (mapping) {
|
|||
|
if (mapping.source === aSourceFile && mapping.original) {
|
|||
|
// Check if it can be mapped by the source map, then update the mapping.
|
|||
|
var original = aSourceMapConsumer.originalPositionFor({
|
|||
|
line: mapping.original.line,
|
|||
|
column: mapping.original.column
|
|||
|
});
|
|||
|
if (original.source !== null) {
|
|||
|
// Copy mapping
|
|||
|
if (sourceRoot) {
|
|||
|
mapping.source = util.relative(sourceRoot, original.source);
|
|||
|
} else {
|
|||
|
mapping.source = original.source;
|
|||
|
}
|
|||
|
mapping.original.line = original.line;
|
|||
|
mapping.original.column = original.column;
|
|||
|
if (original.name !== null && mapping.name !== null) {
|
|||
|
// Only use the identifier name if it's an identifier
|
|||
|
// in both SourceMaps
|
|||
|
mapping.name = original.name;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var source = mapping.source;
|
|||
|
if (source && !newSources.has(source)) {
|
|||
|
newSources.add(source);
|
|||
|
}
|
|||
|
|
|||
|
var name = mapping.name;
|
|||
|
if (name && !newNames.has(name)) {
|
|||
|
newNames.add(name);
|
|||
|
}
|
|||
|
|
|||
|
}, this);
|
|||
|
this._sources = newSources;
|
|||
|
this._names = newNames;
|
|||
|
|
|||
|
// Copy sourcesContents of applied map.
|
|||
|
aSourceMapConsumer.sources.forEach(function (sourceFile) {
|
|||
|
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
|
|||
|
if (content) {
|
|||
|
if (sourceRoot) {
|
|||
|
sourceFile = util.relative(sourceRoot, sourceFile);
|
|||
|
}
|
|||
|
this.setSourceContent(sourceFile, content);
|
|||
|
}
|
|||
|
}, this);
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* A mapping can have one of the three levels of data:
|
|||
|
*
|
|||
|
* 1. Just the generated position.
|
|||
|
* 2. The Generated position, original position, and original source.
|
|||
|
* 3. Generated and original position, original source, as well as a name
|
|||
|
* token.
|
|||
|
*
|
|||
|
* To maintain consistency, we validate that any new mapping being added falls
|
|||
|
* in to one of these categories.
|
|||
|
*/
|
|||
|
SourceMapGenerator.prototype._validateMapping =
|
|||
|
function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
|
|||
|
aName) {
|
|||
|
if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
|
|||
|
&& aGenerated.line > 0 && aGenerated.column >= 0
|
|||
|
&& !aOriginal && !aSource && !aName) {
|
|||
|
// Case 1.
|
|||
|
return;
|
|||
|
}
|
|||
|
else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
|
|||
|
&& aOriginal && 'line' in aOriginal && 'column' in aOriginal
|
|||
|
&& aGenerated.line > 0 && aGenerated.column >= 0
|
|||
|
&& aOriginal.line > 0 && aOriginal.column >= 0
|
|||
|
&& aSource) {
|
|||
|
// Cases 2 and 3.
|
|||
|
return;
|
|||
|
}
|
|||
|
else {
|
|||
|
throw new Error('Invalid mapping.');
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
function cmpLocation(loc1, loc2) {
|
|||
|
var cmp = (loc1 && loc1.line) - (loc2 && loc2.line);
|
|||
|
return cmp ? cmp : (loc1 && loc1.column) - (loc2 && loc2.column);
|
|||
|
}
|
|||
|
|
|||
|
function strcmp(str1, str2) {
|
|||
|
str1 = str1 || '';
|
|||
|
str2 = str2 || '';
|
|||
|
return (str1 > str2) - (str1 < str2);
|
|||
|
}
|
|||
|
|
|||
|
function cmpMapping(mappingA, mappingB) {
|
|||
|
return cmpLocation(mappingA.generated, mappingB.generated) ||
|
|||
|
cmpLocation(mappingA.original, mappingB.original) ||
|
|||
|
strcmp(mappingA.source, mappingB.source) ||
|
|||
|
strcmp(mappingA.name, mappingB.name);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Serialize the accumulated mappings in to the stream of base 64 VLQs
|
|||
|
* specified by the source map format.
|
|||
|
*/
|
|||
|
SourceMapGenerator.prototype._serializeMappings =
|
|||
|
function SourceMapGenerator_serializeMappings() {
|
|||
|
var previousGeneratedColumn = 0;
|
|||
|
var previousGeneratedLine = 1;
|
|||
|
var previousOriginalColumn = 0;
|
|||
|
var previousOriginalLine = 0;
|
|||
|
var previousName = 0;
|
|||
|
var previousSource = 0;
|
|||
|
var result = '';
|
|||
|
var mapping;
|
|||
|
|
|||
|
// The mappings must be guaranteed to be in sorted order before we start
|
|||
|
// serializing them or else the generated line numbers (which are defined
|
|||
|
// via the ';' separators) will be all messed up. Note: it might be more
|
|||
|
// performant to maintain the sorting as we insert them, rather than as we
|
|||
|
// serialize them, but the big O is the same either way.
|
|||
|
this._mappings.sort(cmpMapping);
|
|||
|
|
|||
|
for (var i = 0, len = this._mappings.length; i < len; i++) {
|
|||
|
mapping = this._mappings[i];
|
|||
|
|
|||
|
if (mapping.generated.line !== previousGeneratedLine) {
|
|||
|
previousGeneratedColumn = 0;
|
|||
|
while (mapping.generated.line !== previousGeneratedLine) {
|
|||
|
result += ';';
|
|||
|
previousGeneratedLine++;
|
|||
|
}
|
|||
|
}
|
|||
|
else {
|
|||
|
if (i > 0) {
|
|||
|
if (!cmpMapping(mapping, this._mappings[i - 1])) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
result += ',';
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
result += base64VLQ.encode(mapping.generated.column
|
|||
|
- previousGeneratedColumn);
|
|||
|
previousGeneratedColumn = mapping.generated.column;
|
|||
|
|
|||
|
if (mapping.source && mapping.original) {
|
|||
|
result += base64VLQ.encode(this._sources.indexOf(mapping.source)
|
|||
|
- previousSource);
|
|||
|
previousSource = this._sources.indexOf(mapping.source);
|
|||
|
|
|||
|
// lines are stored 0-based in SourceMap spec version 3
|
|||
|
result += base64VLQ.encode(mapping.original.line - 1
|
|||
|
- previousOriginalLine);
|
|||
|
previousOriginalLine = mapping.original.line - 1;
|
|||
|
|
|||
|
result += base64VLQ.encode(mapping.original.column
|
|||
|
- previousOriginalColumn);
|
|||
|
previousOriginalColumn = mapping.original.column;
|
|||
|
|
|||
|
if (mapping.name) {
|
|||
|
result += base64VLQ.encode(this._names.indexOf(mapping.name)
|
|||
|
- previousName);
|
|||
|
previousName = this._names.indexOf(mapping.name);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return result;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Externalize the source map.
|
|||
|
*/
|
|||
|
SourceMapGenerator.prototype.toJSON =
|
|||
|
function SourceMapGenerator_toJSON() {
|
|||
|
var map = {
|
|||
|
version: this._version,
|
|||
|
file: this._file,
|
|||
|
sources: this._sources.toArray(),
|
|||
|
names: this._names.toArray(),
|
|||
|
mappings: this._serializeMappings()
|
|||
|
};
|
|||
|
if (this._sourceRoot) {
|
|||
|
map.sourceRoot = this._sourceRoot;
|
|||
|
}
|
|||
|
if (this._sourcesContents) {
|
|||
|
map.sourcesContent = map.sources.map(function (source) {
|
|||
|
if (map.sourceRoot) {
|
|||
|
source = util.relative(map.sourceRoot, source);
|
|||
|
}
|
|||
|
return Object.prototype.hasOwnProperty.call(
|
|||
|
this._sourcesContents, util.toSetString(source))
|
|||
|
? this._sourcesContents[util.toSetString(source)]
|
|||
|
: null;
|
|||
|
}, this);
|
|||
|
}
|
|||
|
return map;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Render the source map being generated to a string.
|
|||
|
*/
|
|||
|
SourceMapGenerator.prototype.toString =
|
|||
|
function SourceMapGenerator_toString() {
|
|||
|
return JSON.stringify(this);
|
|||
|
};
|
|||
|
|
|||
|
exports.SourceMapGenerator = SourceMapGenerator;
|
|||
|
|
|||
|
});
|
|||
|
/* -*- Mode: js; js-indent-level: 2; -*- */
|
|||
|
/*
|
|||
|
* Copyright 2011 Mozilla Foundation and contributors
|
|||
|
* Licensed under the New BSD license. See LICENSE or:
|
|||
|
* http://opensource.org/licenses/BSD-3-Clause
|
|||
|
*
|
|||
|
* Based on the Base 64 VLQ implementation in Closure Compiler:
|
|||
|
* https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
|
|||
|
*
|
|||
|
* Copyright 2011 The Closure Compiler Authors. All rights reserved.
|
|||
|
* Redistribution and use in source and binary forms, with or without
|
|||
|
* modification, are permitted provided that the following conditions are
|
|||
|
* met:
|
|||
|
*
|
|||
|
* * Redistributions of source code must retain the above copyright
|
|||
|
* notice, this list of conditions and the following disclaimer.
|
|||
|
* * Redistributions in binary form must reproduce the above
|
|||
|
* copyright notice, this list of conditions and the following
|
|||
|
* disclaimer in the documentation and/or other materials provided
|
|||
|
* with the distribution.
|
|||
|
* * Neither the name of Google Inc. nor the names of its
|
|||
|
* contributors may be used to endorse or promote products derived
|
|||
|
* from this software without specific prior written permission.
|
|||
|
*
|
|||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
*/
|
|||
|
define('source-map/base64-vlq', ['require', 'exports', 'module' , 'source-map/base64'], function(require, exports, module) {
|
|||
|
|
|||
|
var base64 = require('./base64');
|
|||
|
|
|||
|
// A single base 64 digit can contain 6 bits of data. For the base 64 variable
|
|||
|
// length quantities we use in the source map spec, the first bit is the sign,
|
|||
|
// the next four bits are the actual value, and the 6th bit is the
|
|||
|
// continuation bit. The continuation bit tells us whether there are more
|
|||
|
// digits in this value following this digit.
|
|||
|
//
|
|||
|
// Continuation
|
|||
|
// | Sign
|
|||
|
// | |
|
|||
|
// V V
|
|||
|
// 101011
|
|||
|
|
|||
|
var VLQ_BASE_SHIFT = 5;
|
|||
|
|
|||
|
// binary: 100000
|
|||
|
var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
|
|||
|
|
|||
|
// binary: 011111
|
|||
|
var VLQ_BASE_MASK = VLQ_BASE - 1;
|
|||
|
|
|||
|
// binary: 100000
|
|||
|
var VLQ_CONTINUATION_BIT = VLQ_BASE;
|
|||
|
|
|||
|
/**
|
|||
|
* Converts from a two-complement value to a value where the sign bit is
|
|||
|
* is placed in the least significant bit. For example, as decimals:
|
|||
|
* 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
|
|||
|
* 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
|
|||
|
*/
|
|||
|
function toVLQSigned(aValue) {
|
|||
|
return aValue < 0
|
|||
|
? ((-aValue) << 1) + 1
|
|||
|
: (aValue << 1) + 0;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Converts to a two-complement value from a value where the sign bit is
|
|||
|
* is placed in the least significant bit. For example, as decimals:
|
|||
|
* 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
|
|||
|
* 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
|
|||
|
*/
|
|||
|
function fromVLQSigned(aValue) {
|
|||
|
var isNegative = (aValue & 1) === 1;
|
|||
|
var shifted = aValue >> 1;
|
|||
|
return isNegative
|
|||
|
? -shifted
|
|||
|
: shifted;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Returns the base 64 VLQ encoded value.
|
|||
|
*/
|
|||
|
exports.encode = function base64VLQ_encode(aValue) {
|
|||
|
var encoded = "";
|
|||
|
var digit;
|
|||
|
|
|||
|
var vlq = toVLQSigned(aValue);
|
|||
|
|
|||
|
do {
|
|||
|
digit = vlq & VLQ_BASE_MASK;
|
|||
|
vlq >>>= VLQ_BASE_SHIFT;
|
|||
|
if (vlq > 0) {
|
|||
|
// There are still more digits in this value, so we must make sure the
|
|||
|
// continuation bit is marked.
|
|||
|
digit |= VLQ_CONTINUATION_BIT;
|
|||
|
}
|
|||
|
encoded += base64.encode(digit);
|
|||
|
} while (vlq > 0);
|
|||
|
|
|||
|
return encoded;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Decodes the next base 64 VLQ value from the given string and returns the
|
|||
|
* value and the rest of the string.
|
|||
|
*/
|
|||
|
exports.decode = function base64VLQ_decode(aStr) {
|
|||
|
var i = 0;
|
|||
|
var strLen = aStr.length;
|
|||
|
var result = 0;
|
|||
|
var shift = 0;
|
|||
|
var continuation, digit;
|
|||
|
|
|||
|
do {
|
|||
|
if (i >= strLen) {
|
|||
|
throw new Error("Expected more digits in base 64 VLQ value.");
|
|||
|
}
|
|||
|
digit = base64.decode(aStr.charAt(i++));
|
|||
|
continuation = !!(digit & VLQ_CONTINUATION_BIT);
|
|||
|
digit &= VLQ_BASE_MASK;
|
|||
|
result = result + (digit << shift);
|
|||
|
shift += VLQ_BASE_SHIFT;
|
|||
|
} while (continuation);
|
|||
|
|
|||
|
return {
|
|||
|
value: fromVLQSigned(result),
|
|||
|
rest: aStr.slice(i)
|
|||
|
};
|
|||
|
};
|
|||
|
|
|||
|
});
|
|||
|
/* -*- Mode: js; js-indent-level: 2; -*- */
|
|||
|
/*
|
|||
|
* Copyright 2011 Mozilla Foundation and contributors
|
|||
|
* Licensed under the New BSD license. See LICENSE or:
|
|||
|
* http://opensource.org/licenses/BSD-3-Clause
|
|||
|
*/
|
|||
|
define('source-map/base64', ['require', 'exports', 'module' , ], function(require, exports, module) {
|
|||
|
|
|||
|
var charToIntMap = {};
|
|||
|
var intToCharMap = {};
|
|||
|
|
|||
|
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
|||
|
.split('')
|
|||
|
.forEach(function (ch, index) {
|
|||
|
charToIntMap[ch] = index;
|
|||
|
intToCharMap[index] = ch;
|
|||
|
});
|
|||
|
|
|||
|
/**
|
|||
|
* Encode an integer in the range of 0 to 63 to a single base 64 digit.
|
|||
|
*/
|
|||
|
exports.encode = function base64_encode(aNumber) {
|
|||
|
if (aNumber in intToCharMap) {
|
|||
|
return intToCharMap[aNumber];
|
|||
|
}
|
|||
|
throw new TypeError("Must be between 0 and 63: " + aNumber);
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Decode a single base 64 digit to an integer.
|
|||
|
*/
|
|||
|
exports.decode = function base64_decode(aChar) {
|
|||
|
if (aChar in charToIntMap) {
|
|||
|
return charToIntMap[aChar];
|
|||
|
}
|
|||
|
throw new TypeError("Not a valid base 64 digit: " + aChar);
|
|||
|
};
|
|||
|
|
|||
|
});
|
|||
|
/* -*- Mode: js; js-indent-level: 2; -*- */
|
|||
|
/*
|
|||
|
* Copyright 2011 Mozilla Foundation and contributors
|
|||
|
* Licensed under the New BSD license. See LICENSE or:
|
|||
|
* http://opensource.org/licenses/BSD-3-Clause
|
|||
|
*/
|
|||
|
define('source-map/util', ['require', 'exports', 'module' , ], function(require, exports, module) {
|
|||
|
|
|||
|
/**
|
|||
|
* This is a helper function for getting values from parameter/options
|
|||
|
* objects.
|
|||
|
*
|
|||
|
* @param args The object we are extracting values from
|
|||
|
* @param name The name of the property we are getting.
|
|||
|
* @param defaultValue An optional value to return if the property is missing
|
|||
|
* from the object. If this is not specified and the property is missing, an
|
|||
|
* error will be thrown.
|
|||
|
*/
|
|||
|
function getArg(aArgs, aName, aDefaultValue) {
|
|||
|
if (aName in aArgs) {
|
|||
|
return aArgs[aName];
|
|||
|
} else if (arguments.length === 3) {
|
|||
|
return aDefaultValue;
|
|||
|
} else {
|
|||
|
throw new Error('"' + aName + '" is a required argument.');
|
|||
|
}
|
|||
|
}
|
|||
|
exports.getArg = getArg;
|
|||
|
|
|||
|
var urlRegexp = /([\w+\-.]+):\/\/((\w+:\w+)@)?([\w.]+)?(:(\d+))?(\S+)?/;
|
|||
|
|
|||
|
function urlParse(aUrl) {
|
|||
|
var match = aUrl.match(urlRegexp);
|
|||
|
if (!match) {
|
|||
|
return null;
|
|||
|
}
|
|||
|
return {
|
|||
|
scheme: match[1],
|
|||
|
auth: match[3],
|
|||
|
host: match[4],
|
|||
|
port: match[6],
|
|||
|
path: match[7]
|
|||
|
};
|
|||
|
}
|
|||
|
exports.urlParse = urlParse;
|
|||
|
|
|||
|
function urlGenerate(aParsedUrl) {
|
|||
|
var url = aParsedUrl.scheme + "://";
|
|||
|
if (aParsedUrl.auth) {
|
|||
|
url += aParsedUrl.auth + "@"
|
|||
|
}
|
|||
|
if (aParsedUrl.host) {
|
|||
|
url += aParsedUrl.host;
|
|||
|
}
|
|||
|
if (aParsedUrl.port) {
|
|||
|
url += ":" + aParsedUrl.port
|
|||
|
}
|
|||
|
if (aParsedUrl.path) {
|
|||
|
url += aParsedUrl.path;
|
|||
|
}
|
|||
|
return url;
|
|||
|
}
|
|||
|
exports.urlGenerate = urlGenerate;
|
|||
|
|
|||
|
function join(aRoot, aPath) {
|
|||
|
var url;
|
|||
|
|
|||
|
if (aPath.match(urlRegexp)) {
|
|||
|
return aPath;
|
|||
|
}
|
|||
|
|
|||
|
if (aPath.charAt(0) === '/' && (url = urlParse(aRoot))) {
|
|||
|
url.path = aPath;
|
|||
|
return urlGenerate(url);
|
|||
|
}
|
|||
|
|
|||
|
return aRoot.replace(/\/$/, '') + '/' + aPath;
|
|||
|
}
|
|||
|
exports.join = join;
|
|||
|
|
|||
|
/**
|
|||
|
* Because behavior goes wacky when you set `__proto__` on objects, we
|
|||
|
* have to prefix all the strings in our set with an arbitrary character.
|
|||
|
*
|
|||
|
* See https://github.com/mozilla/source-map/pull/31 and
|
|||
|
* https://github.com/mozilla/source-map/issues/30
|
|||
|
*
|
|||
|
* @param String aStr
|
|||
|
*/
|
|||
|
function toSetString(aStr) {
|
|||
|
return '$' + aStr;
|
|||
|
}
|
|||
|
exports.toSetString = toSetString;
|
|||
|
|
|||
|
function fromSetString(aStr) {
|
|||
|
return aStr.substr(1);
|
|||
|
}
|
|||
|
exports.fromSetString = fromSetString;
|
|||
|
|
|||
|
function relative(aRoot, aPath) {
|
|||
|
aRoot = aRoot.replace(/\/$/, '');
|
|||
|
|
|||
|
var url = urlParse(aRoot);
|
|||
|
if (aPath.charAt(0) == "/" && url && url.path == "/") {
|
|||
|
return aPath.slice(1);
|
|||
|
}
|
|||
|
|
|||
|
return aPath.indexOf(aRoot + '/') === 0
|
|||
|
? aPath.substr(aRoot.length + 1)
|
|||
|
: aPath;
|
|||
|
}
|
|||
|
exports.relative = relative;
|
|||
|
|
|||
|
});
|
|||
|
/* -*- Mode: js; js-indent-level: 2; -*- */
|
|||
|
/*
|
|||
|
* Copyright 2011 Mozilla Foundation and contributors
|
|||
|
* Licensed under the New BSD license. See LICENSE or:
|
|||
|
* http://opensource.org/licenses/BSD-3-Clause
|
|||
|
*/
|
|||
|
define('source-map/array-set', ['require', 'exports', 'module' , 'source-map/util'], function(require, exports, module) {
|
|||
|
|
|||
|
var util = require('./util');
|
|||
|
|
|||
|
/**
|
|||
|
* A data structure which is a combination of an array and a set. Adding a new
|
|||
|
* member is O(1), testing for membership is O(1), and finding the index of an
|
|||
|
* element is O(1). Removing elements from the set is not supported. Only
|
|||
|
* strings are supported for membership.
|
|||
|
*/
|
|||
|
function ArraySet() {
|
|||
|
this._array = [];
|
|||
|
this._set = {};
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Static method for creating ArraySet instances from an existing array.
|
|||
|
*/
|
|||
|
ArraySet.fromArray = function ArraySet_fromArray(aArray) {
|
|||
|
var set = new ArraySet();
|
|||
|
for (var i = 0, len = aArray.length; i < len; i++) {
|
|||
|
set.add(aArray[i]);
|
|||
|
}
|
|||
|
return set;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Add the given string to this set.
|
|||
|
*
|
|||
|
* @param String aStr
|
|||
|
*/
|
|||
|
ArraySet.prototype.add = function ArraySet_add(aStr) {
|
|||
|
if (this.has(aStr)) {
|
|||
|
// Already a member; nothing to do.
|
|||
|
return;
|
|||
|
}
|
|||
|
var idx = this._array.length;
|
|||
|
this._array.push(aStr);
|
|||
|
this._set[util.toSetString(aStr)] = idx;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Is the given string a member of this set?
|
|||
|
*
|
|||
|
* @param String aStr
|
|||
|
*/
|
|||
|
ArraySet.prototype.has = function ArraySet_has(aStr) {
|
|||
|
return Object.prototype.hasOwnProperty.call(this._set,
|
|||
|
util.toSetString(aStr));
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* What is the index of the given string in the array?
|
|||
|
*
|
|||
|
* @param String aStr
|
|||
|
*/
|
|||
|
ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
|
|||
|
if (this.has(aStr)) {
|
|||
|
return this._set[util.toSetString(aStr)];
|
|||
|
}
|
|||
|
throw new Error('"' + aStr + '" is not in the set.');
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* What is the element at the given index?
|
|||
|
*
|
|||
|
* @param Number aIdx
|
|||
|
*/
|
|||
|
ArraySet.prototype.at = function ArraySet_at(aIdx) {
|
|||
|
if (aIdx >= 0 && aIdx < this._array.length) {
|
|||
|
return this._array[aIdx];
|
|||
|
}
|
|||
|
throw new Error('No element indexed by ' + aIdx);
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Returns the array representation of this set (which has the proper indices
|
|||
|
* indicated by indexOf). Note that this is a copy of the internal array used
|
|||
|
* for storing the members so that no one can mess with internal state.
|
|||
|
*/
|
|||
|
ArraySet.prototype.toArray = function ArraySet_toArray() {
|
|||
|
return this._array.slice();
|
|||
|
};
|
|||
|
|
|||
|
exports.ArraySet = ArraySet;
|
|||
|
|
|||
|
});
|
|||
|
/* -*- Mode: js; js-indent-level: 2; -*- */
|
|||
|
/*
|
|||
|
* Copyright 2011 Mozilla Foundation and contributors
|
|||
|
* Licensed under the New BSD license. See LICENSE or:
|
|||
|
* http://opensource.org/licenses/BSD-3-Clause
|
|||
|
*/
|
|||
|
define('source-map/source-map-consumer', ['require', 'exports', 'module' , 'source-map/util', 'source-map/binary-search', 'source-map/array-set', 'source-map/base64-vlq'], function(require, exports, module) {
|
|||
|
|
|||
|
var util = require('./util');
|
|||
|
var binarySearch = require('./binary-search');
|
|||
|
var ArraySet = require('./array-set').ArraySet;
|
|||
|
var base64VLQ = require('./base64-vlq');
|
|||
|
|
|||
|
/**
|
|||
|
* A SourceMapConsumer instance represents a parsed source map which we can
|
|||
|
* query for information about the original file positions by giving it a file
|
|||
|
* position in the generated source.
|
|||
|
*
|
|||
|
* The only parameter is the raw source map (either as a JSON string, or
|
|||
|
* already parsed to an object). According to the spec, source maps have the
|
|||
|
* following attributes:
|
|||
|
*
|
|||
|
* - version: Which version of the source map spec this map is following.
|
|||
|
* - sources: An array of URLs to the original source files.
|
|||
|
* - names: An array of identifiers which can be referrenced by individual mappings.
|
|||
|
* - sourceRoot: Optional. The URL root from which all sources are relative.
|
|||
|
* - sourcesContent: Optional. An array of contents of the original source files.
|
|||
|
* - mappings: A string of base64 VLQs which contain the actual mappings.
|
|||
|
* - file: The generated file this source map is associated with.
|
|||
|
*
|
|||
|
* Here is an example source map, taken from the source map spec[0]:
|
|||
|
*
|
|||
|
* {
|
|||
|
* version : 3,
|
|||
|
* file: "out.js",
|
|||
|
* sourceRoot : "",
|
|||
|
* sources: ["foo.js", "bar.js"],
|
|||
|
* names: ["src", "maps", "are", "fun"],
|
|||
|
* mappings: "AA,AB;;ABCDE;"
|
|||
|
* }
|
|||
|
*
|
|||
|
* [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
|
|||
|
*/
|
|||
|
function SourceMapConsumer(aSourceMap) {
|
|||
|
var sourceMap = aSourceMap;
|
|||
|
if (typeof aSourceMap === 'string') {
|
|||
|
sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
|
|||
|
}
|
|||
|
|
|||
|
var version = util.getArg(sourceMap, 'version');
|
|||
|
var sources = util.getArg(sourceMap, 'sources');
|
|||
|
var names = util.getArg(sourceMap, 'names');
|
|||
|
var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
|
|||
|
var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
|
|||
|
var mappings = util.getArg(sourceMap, 'mappings');
|
|||
|
var file = util.getArg(sourceMap, 'file');
|
|||
|
|
|||
|
if (version !== this._version) {
|
|||
|
throw new Error('Unsupported version: ' + version);
|
|||
|
}
|
|||
|
|
|||
|
this._names = ArraySet.fromArray(names);
|
|||
|
this._sources = ArraySet.fromArray(sources);
|
|||
|
this.sourceRoot = sourceRoot;
|
|||
|
this.sourcesContent = sourcesContent;
|
|||
|
this.file = file;
|
|||
|
|
|||
|
// `this._generatedMappings` and `this._originalMappings` hold the parsed
|
|||
|
// mapping coordinates from the source map's "mappings" attribute. Each
|
|||
|
// object in the array is of the form
|
|||
|
//
|
|||
|
// {
|
|||
|
// generatedLine: The line number in the generated code,
|
|||
|
// generatedColumn: The column number in the generated code,
|
|||
|
// source: The path to the original source file that generated this
|
|||
|
// chunk of code,
|
|||
|
// originalLine: The line number in the original source that
|
|||
|
// corresponds to this chunk of generated code,
|
|||
|
// originalColumn: The column number in the original source that
|
|||
|
// corresponds to this chunk of generated code,
|
|||
|
// name: The name of the original symbol which generated this chunk of
|
|||
|
// code.
|
|||
|
// }
|
|||
|
//
|
|||
|
// All properties except for `generatedLine` and `generatedColumn` can be
|
|||
|
// `null`.
|
|||
|
//
|
|||
|
// `this._generatedMappings` is ordered by the generated positions.
|
|||
|
//
|
|||
|
// `this._originalMappings` is ordered by the original positions.
|
|||
|
this._generatedMappings = [];
|
|||
|
this._originalMappings = [];
|
|||
|
this._parseMappings(mappings, sourceRoot);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* The version of the source mapping spec that we are consuming.
|
|||
|
*/
|
|||
|
SourceMapConsumer.prototype._version = 3;
|
|||
|
|
|||
|
/**
|
|||
|
* The list of original sources.
|
|||
|
*/
|
|||
|
Object.defineProperty(SourceMapConsumer.prototype, 'sources', {
|
|||
|
get: function () {
|
|||
|
return this._sources.toArray().map(function (s) {
|
|||
|
return this.sourceRoot ? util.join(this.sourceRoot, s) : s;
|
|||
|
}, this);
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
/**
|
|||
|
* Parse the mappings in a string in to a data structure which we can easily
|
|||
|
* query (an ordered list in this._generatedMappings).
|
|||
|
*/
|
|||
|
SourceMapConsumer.prototype._parseMappings =
|
|||
|
function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
|
|||
|
var generatedLine = 1;
|
|||
|
var previousGeneratedColumn = 0;
|
|||
|
var previousOriginalLine = 0;
|
|||
|
var previousOriginalColumn = 0;
|
|||
|
var previousSource = 0;
|
|||
|
var previousName = 0;
|
|||
|
var mappingSeparator = /^[,;]/;
|
|||
|
var str = aStr;
|
|||
|
var mapping;
|
|||
|
var temp;
|
|||
|
|
|||
|
while (str.length > 0) {
|
|||
|
if (str.charAt(0) === ';') {
|
|||
|
generatedLine++;
|
|||
|
str = str.slice(1);
|
|||
|
previousGeneratedColumn = 0;
|
|||
|
}
|
|||
|
else if (str.charAt(0) === ',') {
|
|||
|
str = str.slice(1);
|
|||
|
}
|
|||
|
else {
|
|||
|
mapping = {};
|
|||
|
mapping.generatedLine = generatedLine;
|
|||
|
|
|||
|
// Generated column.
|
|||
|
temp = base64VLQ.decode(str);
|
|||
|
mapping.generatedColumn = previousGeneratedColumn + temp.value;
|
|||
|
previousGeneratedColumn = mapping.generatedColumn;
|
|||
|
str = temp.rest;
|
|||
|
|
|||
|
if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
|
|||
|
// Original source.
|
|||
|
temp = base64VLQ.decode(str);
|
|||
|
mapping.source = this._sources.at(previousSource + temp.value);
|
|||
|
previousSource += temp.value;
|
|||
|
str = temp.rest;
|
|||
|
if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
|
|||
|
throw new Error('Found a source, but no line and column');
|
|||
|
}
|
|||
|
|
|||
|
// Original line.
|
|||
|
temp = base64VLQ.decode(str);
|
|||
|
mapping.originalLine = previousOriginalLine + temp.value;
|
|||
|
previousOriginalLine = mapping.originalLine;
|
|||
|
// Lines are stored 0-based
|
|||
|
mapping.originalLine += 1;
|
|||
|
str = temp.rest;
|
|||
|
if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
|
|||
|
throw new Error('Found a source and line, but no column');
|
|||
|
}
|
|||
|
|
|||
|
// Original column.
|
|||
|
temp = base64VLQ.decode(str);
|
|||
|
mapping.originalColumn = previousOriginalColumn + temp.value;
|
|||
|
previousOriginalColumn = mapping.originalColumn;
|
|||
|
str = temp.rest;
|
|||
|
|
|||
|
if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
|
|||
|
// Original name.
|
|||
|
temp = base64VLQ.decode(str);
|
|||
|
mapping.name = this._names.at(previousName + temp.value);
|
|||
|
previousName += temp.value;
|
|||
|
str = temp.rest;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
this._generatedMappings.push(mapping);
|
|||
|
if (typeof mapping.originalLine === 'number') {
|
|||
|
this._originalMappings.push(mapping);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
this._originalMappings.sort(this._compareOriginalPositions);
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Comparator between two mappings where the original positions are compared.
|
|||
|
*/
|
|||
|
SourceMapConsumer.prototype._compareOriginalPositions =
|
|||
|
function SourceMapConsumer_compareOriginalPositions(mappingA, mappingB) {
|
|||
|
if (mappingA.source > mappingB.source) {
|
|||
|
return 1;
|
|||
|
}
|
|||
|
else if (mappingA.source < mappingB.source) {
|
|||
|
return -1;
|
|||
|
}
|
|||
|
else {
|
|||
|
var cmp = mappingA.originalLine - mappingB.originalLine;
|
|||
|
return cmp === 0
|
|||
|
? mappingA.originalColumn - mappingB.originalColumn
|
|||
|
: cmp;
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Comparator between two mappings where the generated positions are compared.
|
|||
|
*/
|
|||
|
SourceMapConsumer.prototype._compareGeneratedPositions =
|
|||
|
function SourceMapConsumer_compareGeneratedPositions(mappingA, mappingB) {
|
|||
|
var cmp = mappingA.generatedLine - mappingB.generatedLine;
|
|||
|
return cmp === 0
|
|||
|
? mappingA.generatedColumn - mappingB.generatedColumn
|
|||
|
: cmp;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Find the mapping that best matches the hypothetical "needle" mapping that
|
|||
|
* we are searching for in the given "haystack" of mappings.
|
|||
|
*/
|
|||
|
SourceMapConsumer.prototype._findMapping =
|
|||
|
function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
|
|||
|
aColumnName, aComparator) {
|
|||
|
// To return the position we are searching for, we must first find the
|
|||
|
// mapping for the given position and then return the opposite position it
|
|||
|
// points to. Because the mappings are sorted, we can use binary search to
|
|||
|
// find the best mapping.
|
|||
|
|
|||
|
if (aNeedle[aLineName] <= 0) {
|
|||
|
throw new TypeError('Line must be greater than or equal to 1, got '
|
|||
|
+ aNeedle[aLineName]);
|
|||
|
}
|
|||
|
if (aNeedle[aColumnName] < 0) {
|
|||
|
throw new TypeError('Column must be greater than or equal to 0, got '
|
|||
|
+ aNeedle[aColumnName]);
|
|||
|
}
|
|||
|
|
|||
|
return binarySearch.search(aNeedle, aMappings, aComparator);
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Returns the original source, line, and column information for the generated
|
|||
|
* source's line and column positions provided. The only argument is an object
|
|||
|
* with the following properties:
|
|||
|
*
|
|||
|
* - line: The line number in the generated source.
|
|||
|
* - column: The column number in the generated source.
|
|||
|
*
|
|||
|
* and an object is returned with the following properties:
|
|||
|
*
|
|||
|
* - source: The original source file, or null.
|
|||
|
* - line: The line number in the original source, or null.
|
|||
|
* - column: The column number in the original source, or null.
|
|||
|
* - name: The original identifier, or null.
|
|||
|
*/
|
|||
|
SourceMapConsumer.prototype.originalPositionFor =
|
|||
|
function SourceMapConsumer_originalPositionFor(aArgs) {
|
|||
|
var needle = {
|
|||
|
generatedLine: util.getArg(aArgs, 'line'),
|
|||
|
generatedColumn: util.getArg(aArgs, 'column')
|
|||
|
};
|
|||
|
|
|||
|
var mapping = this._findMapping(needle,
|
|||
|
this._generatedMappings,
|
|||
|
"generatedLine",
|
|||
|
"generatedColumn",
|
|||
|
this._compareGeneratedPositions);
|
|||
|
|
|||
|
if (mapping) {
|
|||
|
var source = util.getArg(mapping, 'source', null);
|
|||
|
if (source && this.sourceRoot) {
|
|||
|
source = util.join(this.sourceRoot, source);
|
|||
|
}
|
|||
|
return {
|
|||
|
source: source,
|
|||
|
line: util.getArg(mapping, 'originalLine', null),
|
|||
|
column: util.getArg(mapping, 'originalColumn', null),
|
|||
|
name: util.getArg(mapping, 'name', null)
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
return {
|
|||
|
source: null,
|
|||
|
line: null,
|
|||
|
column: null,
|
|||
|
name: null
|
|||
|
};
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Returns the original source content. The only argument is the url of the
|
|||
|
* original source file. Returns null if no original source content is
|
|||
|
* availible.
|
|||
|
*/
|
|||
|
SourceMapConsumer.prototype.sourceContentFor =
|
|||
|
function SourceMapConsumer_sourceContentFor(aSource) {
|
|||
|
if (!this.sourcesContent) {
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
if (this.sourceRoot) {
|
|||
|
aSource = util.relative(this.sourceRoot, aSource);
|
|||
|
}
|
|||
|
|
|||
|
if (this._sources.has(aSource)) {
|
|||
|
return this.sourcesContent[this._sources.indexOf(aSource)];
|
|||
|
}
|
|||
|
|
|||
|
var url;
|
|||
|
if (this.sourceRoot
|
|||
|
&& (url = util.urlParse(this.sourceRoot))) {
|
|||
|
// XXX: file:// URIs and absolute paths lead to unexpected behavior for
|
|||
|
// many users. We can help them out when they expect file:// URIs to
|
|||
|
// behave like it would if they were running a local HTTP server. See
|
|||
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
|
|||
|
var fileUriAbsPath = aSource.replace(/^file:\/\//, "");
|
|||
|
if (url.scheme == "file"
|
|||
|
&& this._sources.has(fileUriAbsPath)) {
|
|||
|
return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
|
|||
|
}
|
|||
|
|
|||
|
if ((!url.path || url.path == "/")
|
|||
|
&& this._sources.has("/" + aSource)) {
|
|||
|
return this.sourcesContent[this._sources.indexOf("/" + aSource)];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
throw new Error('"' + aSource + '" is not in the SourceMap.');
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Returns the generated line and column information for the original source,
|
|||
|
* line, and column positions provided. The only argument is an object with
|
|||
|
* the following properties:
|
|||
|
*
|
|||
|
* - source: The filename of the original source.
|
|||
|
* - line: The line number in the original source.
|
|||
|
* - column: The column number in the original source.
|
|||
|
*
|
|||
|
* and an object is returned with the following properties:
|
|||
|
*
|
|||
|
* - line: The line number in the generated source, or null.
|
|||
|
* - column: The column number in the generated source, or null.
|
|||
|
*/
|
|||
|
SourceMapConsumer.prototype.generatedPositionFor =
|
|||
|
function SourceMapConsumer_generatedPositionFor(aArgs) {
|
|||
|
var needle = {
|
|||
|
source: util.getArg(aArgs, 'source'),
|
|||
|
originalLine: util.getArg(aArgs, 'line'),
|
|||
|
originalColumn: util.getArg(aArgs, 'column')
|
|||
|
};
|
|||
|
|
|||
|
if (this.sourceRoot) {
|
|||
|
needle.source = util.relative(this.sourceRoot, needle.source);
|
|||
|
}
|
|||
|
|
|||
|
var mapping = this._findMapping(needle,
|
|||
|
this._originalMappings,
|
|||
|
"originalLine",
|
|||
|
"originalColumn",
|
|||
|
this._compareOriginalPositions);
|
|||
|
|
|||
|
if (mapping) {
|
|||
|
return {
|
|||
|
line: util.getArg(mapping, 'generatedLine', null),
|
|||
|
column: util.getArg(mapping, 'generatedColumn', null)
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
return {
|
|||
|
line: null,
|
|||
|
column: null
|
|||
|
};
|
|||
|
};
|
|||
|
|
|||
|
SourceMapConsumer.GENERATED_ORDER = 1;
|
|||
|
SourceMapConsumer.ORIGINAL_ORDER = 2;
|
|||
|
|
|||
|
/**
|
|||
|
* Iterate over each mapping between an original source/line/column and a
|
|||
|
* generated line/column in this source map.
|
|||
|
*
|
|||
|
* @param Function aCallback
|
|||
|
* The function that is called with each mapping.
|
|||
|
* @param Object aContext
|
|||
|
* Optional. If specified, this object will be the value of `this` every
|
|||
|
* time that `aCallback` is called.
|
|||
|
* @param aOrder
|
|||
|
* Either `SourceMapConsumer.GENERATED_ORDER` or
|
|||
|
* `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
|
|||
|
* iterate over the mappings sorted by the generated file's line/column
|
|||
|
* order or the original's source/line/column order, respectively. Defaults to
|
|||
|
* `SourceMapConsumer.GENERATED_ORDER`.
|
|||
|
*/
|
|||
|
SourceMapConsumer.prototype.eachMapping =
|
|||
|
function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
|
|||
|
var context = aContext || null;
|
|||
|
var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
|
|||
|
|
|||
|
var mappings;
|
|||
|
switch (order) {
|
|||
|
case SourceMapConsumer.GENERATED_ORDER:
|
|||
|
mappings = this._generatedMappings;
|
|||
|
break;
|
|||
|
case SourceMapConsumer.ORIGINAL_ORDER:
|
|||
|
mappings = this._originalMappings;
|
|||
|
break;
|
|||
|
default:
|
|||
|
throw new Error("Unknown order of iteration.");
|
|||
|
}
|
|||
|
|
|||
|
var sourceRoot = this.sourceRoot;
|
|||
|
mappings.map(function (mapping) {
|
|||
|
var source = mapping.source;
|
|||
|
if (source && sourceRoot) {
|
|||
|
source = util.join(sourceRoot, source);
|
|||
|
}
|
|||
|
return {
|
|||
|
source: source,
|
|||
|
generatedLine: mapping.generatedLine,
|
|||
|
generatedColumn: mapping.generatedColumn,
|
|||
|
originalLine: mapping.originalLine,
|
|||
|
originalColumn: mapping.originalColumn,
|
|||
|
name: mapping.name
|
|||
|
};
|
|||
|
}).forEach(aCallback, context);
|
|||
|
};
|
|||
|
|
|||
|
exports.SourceMapConsumer = SourceMapConsumer;
|
|||
|
|
|||
|
});
|
|||
|
/* -*- Mode: js; js-indent-level: 2; -*- */
|
|||
|
/*
|
|||
|
* Copyright 2011 Mozilla Foundation and contributors
|
|||
|
* Licensed under the New BSD license. See LICENSE or:
|
|||
|
* http://opensource.org/licenses/BSD-3-Clause
|
|||
|
*/
|
|||
|
define('source-map/binary-search', ['require', 'exports', 'module' , ], function(require, exports, module) {
|
|||
|
|
|||
|
/**
|
|||
|
* Recursive implementation of binary search.
|
|||
|
*
|
|||
|
* @param aLow Indices here and lower do not contain the needle.
|
|||
|
* @param aHigh Indices here and higher do not contain the needle.
|
|||
|
* @param aNeedle The element being searched for.
|
|||
|
* @param aHaystack The non-empty array being searched.
|
|||
|
* @param aCompare Function which takes two elements and returns -1, 0, or 1.
|
|||
|
*/
|
|||
|
function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare) {
|
|||
|
// This function terminates when one of the following is true:
|
|||
|
//
|
|||
|
// 1. We find the exact element we are looking for.
|
|||
|
//
|
|||
|
// 2. We did not find the exact element, but we can return the next
|
|||
|
// closest element that is less than that element.
|
|||
|
//
|
|||
|
// 3. We did not find the exact element, and there is no next-closest
|
|||
|
// element which is less than the one we are searching for, so we
|
|||
|
// return null.
|
|||
|
var mid = Math.floor((aHigh - aLow) / 2) + aLow;
|
|||
|
var cmp = aCompare(aNeedle, aHaystack[mid]);
|
|||
|
if (cmp === 0) {
|
|||
|
// Found the element we are looking for.
|
|||
|
return aHaystack[mid];
|
|||
|
}
|
|||
|
else if (cmp > 0) {
|
|||
|
// aHaystack[mid] is greater than our needle.
|
|||
|
if (aHigh - mid > 1) {
|
|||
|
// The element is in the upper half.
|
|||
|
return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare);
|
|||
|
}
|
|||
|
// We did not find an exact match, return the next closest one
|
|||
|
// (termination case 2).
|
|||
|
return aHaystack[mid];
|
|||
|
}
|
|||
|
else {
|
|||
|
// aHaystack[mid] is less than our needle.
|
|||
|
if (mid - aLow > 1) {
|
|||
|
// The element is in the lower half.
|
|||
|
return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare);
|
|||
|
}
|
|||
|
// The exact needle element was not found in this haystack. Determine if
|
|||
|
// we are in termination case (2) or (3) and return the appropriate thing.
|
|||
|
return aLow < 0
|
|||
|
? null
|
|||
|
: aHaystack[aLow];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* This is an implementation of binary search which will always try and return
|
|||
|
* the next lowest value checked if there is no exact hit. This is because
|
|||
|
* mappings between original and generated line/col pairs are single points,
|
|||
|
* and there is an implicit region between each of them, so a miss just means
|
|||
|
* that you aren't on the very start of a region.
|
|||
|
*
|
|||
|
* @param aNeedle The element you are looking for.
|
|||
|
* @param aHaystack The array that is being searched.
|
|||
|
* @param aCompare A function which takes the needle and an element in the
|
|||
|
* array and returns -1, 0, or 1 depending on whether the needle is less
|
|||
|
* than, equal to, or greater than the element, respectively.
|
|||
|
*/
|
|||
|
exports.search = function search(aNeedle, aHaystack, aCompare) {
|
|||
|
return aHaystack.length > 0
|
|||
|
? recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, aCompare)
|
|||
|
: null;
|
|||
|
};
|
|||
|
|
|||
|
});
|
|||
|
/* -*- Mode: js; js-indent-level: 2; -*- */
|
|||
|
/*
|
|||
|
* Copyright 2011 Mozilla Foundation and contributors
|
|||
|
* Licensed under the New BSD license. See LICENSE or:
|
|||
|
* http://opensource.org/licenses/BSD-3-Clause
|
|||
|
*/
|
|||
|
define('source-map/source-node', ['require', 'exports', 'module' , 'source-map/source-map-generator', 'source-map/util'], function(require, exports, module) {
|
|||
|
|
|||
|
var SourceMapGenerator = require('./source-map-generator').SourceMapGenerator;
|
|||
|
var util = require('./util');
|
|||
|
|
|||
|
/**
|
|||
|
* SourceNodes provide a way to abstract over interpolating/concatenating
|
|||
|
* snippets of generated JavaScript source code while maintaining the line and
|
|||
|
* column information associated with the original source code.
|
|||
|
*
|
|||
|
* @param aLine The original line number.
|
|||
|
* @param aColumn The original column number.
|
|||
|
* @param aSource The original source's filename.
|
|||
|
* @param aChunks Optional. An array of strings which are snippets of
|
|||
|
* generated JS, or other SourceNodes.
|
|||
|
* @param aName The original identifier.
|
|||
|
*/
|
|||
|
function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
|
|||
|
this.children = [];
|
|||
|
this.sourceContents = {};
|
|||
|
this.line = aLine === undefined ? null : aLine;
|
|||
|
this.column = aColumn === undefined ? null : aColumn;
|
|||
|
this.source = aSource === undefined ? null : aSource;
|
|||
|
this.name = aName === undefined ? null : aName;
|
|||
|
if (aChunks != null) this.add(aChunks);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Creates a SourceNode from generated code and a SourceMapConsumer.
|
|||
|
*
|
|||
|
* @param aGeneratedCode The generated code
|
|||
|
* @param aSourceMapConsumer The SourceMap for the generated code
|
|||
|
*/
|
|||
|
SourceNode.fromStringWithSourceMap =
|
|||
|
function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer) {
|
|||
|
// The SourceNode we want to fill with the generated code
|
|||
|
// and the SourceMap
|
|||
|
var node = new SourceNode();
|
|||
|
|
|||
|
// The generated code
|
|||
|
// Processed fragments are removed from this array.
|
|||
|
var remainingLines = aGeneratedCode.split('\n');
|
|||
|
|
|||
|
// We need to remember the position of "remainingLines"
|
|||
|
var lastGeneratedLine = 1, lastGeneratedColumn = 0;
|
|||
|
|
|||
|
// The generate SourceNodes we need a code range.
|
|||
|
// To extract it current and last mapping is used.
|
|||
|
// Here we store the last mapping.
|
|||
|
var lastMapping = null;
|
|||
|
|
|||
|
aSourceMapConsumer.eachMapping(function (mapping) {
|
|||
|
if (lastMapping === null) {
|
|||
|
// We add the generated code until the first mapping
|
|||
|
// to the SourceNode without any mapping.
|
|||
|
// Each line is added as separate string.
|
|||
|
while (lastGeneratedLine < mapping.generatedLine) {
|
|||
|
node.add(remainingLines.shift() + "\n");
|
|||
|
lastGeneratedLine++;
|
|||
|
}
|
|||
|
if (lastGeneratedColumn < mapping.generatedColumn) {
|
|||
|
var nextLine = remainingLines[0];
|
|||
|
node.add(nextLine.substr(0, mapping.generatedColumn));
|
|||
|
remainingLines[0] = nextLine.substr(mapping.generatedColumn);
|
|||
|
lastGeneratedColumn = mapping.generatedColumn;
|
|||
|
}
|
|||
|
} else {
|
|||
|
// We add the code from "lastMapping" to "mapping":
|
|||
|
// First check if there is a new line in between.
|
|||
|
if (lastGeneratedLine < mapping.generatedLine) {
|
|||
|
var code = "";
|
|||
|
// Associate full lines with "lastMapping"
|
|||
|
do {
|
|||
|
code += remainingLines.shift() + "\n";
|
|||
|
lastGeneratedLine++;
|
|||
|
lastGeneratedColumn = 0;
|
|||
|
} while (lastGeneratedLine < mapping.generatedLine);
|
|||
|
// When we reached the correct line, we add code until we
|
|||
|
// reach the correct column too.
|
|||
|
if (lastGeneratedColumn < mapping.generatedColumn) {
|
|||
|
var nextLine = remainingLines[0];
|
|||
|
code += nextLine.substr(0, mapping.generatedColumn);
|
|||
|
remainingLines[0] = nextLine.substr(mapping.generatedColumn);
|
|||
|
lastGeneratedColumn = mapping.generatedColumn;
|
|||
|
}
|
|||
|
// Create the SourceNode.
|
|||
|
addMappingWithCode(lastMapping, code);
|
|||
|
} else {
|
|||
|
// There is no new line in between.
|
|||
|
// Associate the code between "lastGeneratedColumn" and
|
|||
|
// "mapping.generatedColumn" with "lastMapping"
|
|||
|
var nextLine = remainingLines[0];
|
|||
|
var code = nextLine.substr(0, mapping.generatedColumn -
|
|||
|
lastGeneratedColumn);
|
|||
|
remainingLines[0] = nextLine.substr(mapping.generatedColumn -
|
|||
|
lastGeneratedColumn);
|
|||
|
lastGeneratedColumn = mapping.generatedColumn;
|
|||
|
addMappingWithCode(lastMapping, code);
|
|||
|
}
|
|||
|
}
|
|||
|
lastMapping = mapping;
|
|||
|
}, this);
|
|||
|
// We have processed all mappings.
|
|||
|
// Associate the remaining code in the current line with "lastMapping"
|
|||
|
// and add the remaining lines without any mapping
|
|||
|
addMappingWithCode(lastMapping, remainingLines.join("\n"));
|
|||
|
|
|||
|
// Copy sourcesContent into SourceNode
|
|||
|
aSourceMapConsumer.sources.forEach(function (sourceFile) {
|
|||
|
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
|
|||
|
if (content) {
|
|||
|
node.setSourceContent(sourceFile, content);
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
return node;
|
|||
|
|
|||
|
function addMappingWithCode(mapping, code) {
|
|||
|
if (mapping.source === undefined) {
|
|||
|
node.add(code);
|
|||
|
} else {
|
|||
|
node.add(new SourceNode(mapping.originalLine,
|
|||
|
mapping.originalColumn,
|
|||
|
mapping.source,
|
|||
|
code,
|
|||
|
mapping.name));
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Add a chunk of generated JS to this source node.
|
|||
|
*
|
|||
|
* @param aChunk A string snippet of generated JS code, another instance of
|
|||
|
* SourceNode, or an array where each member is one of those things.
|
|||
|
*/
|
|||
|
SourceNode.prototype.add = function SourceNode_add(aChunk) {
|
|||
|
if (Array.isArray(aChunk)) {
|
|||
|
aChunk.forEach(function (chunk) {
|
|||
|
this.add(chunk);
|
|||
|
}, this);
|
|||
|
}
|
|||
|
else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
|
|||
|
if (aChunk) {
|
|||
|
this.children.push(aChunk);
|
|||
|
}
|
|||
|
}
|
|||
|
else {
|
|||
|
throw new TypeError(
|
|||
|
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
|
|||
|
);
|
|||
|
}
|
|||
|
return this;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Add a chunk of generated JS to the beginning of this source node.
|
|||
|
*
|
|||
|
* @param aChunk A string snippet of generated JS code, another instance of
|
|||
|
* SourceNode, or an array where each member is one of those things.
|
|||
|
*/
|
|||
|
SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
|
|||
|
if (Array.isArray(aChunk)) {
|
|||
|
for (var i = aChunk.length-1; i >= 0; i--) {
|
|||
|
this.prepend(aChunk[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
|
|||
|
this.children.unshift(aChunk);
|
|||
|
}
|
|||
|
else {
|
|||
|
throw new TypeError(
|
|||
|
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
|
|||
|
);
|
|||
|
}
|
|||
|
return this;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Walk over the tree of JS snippets in this node and its children. The
|
|||
|
* walking function is called once for each snippet of JS and is passed that
|
|||
|
* snippet and the its original associated source's line/column location.
|
|||
|
*
|
|||
|
* @param aFn The traversal function.
|
|||
|
*/
|
|||
|
SourceNode.prototype.walk = function SourceNode_walk(aFn) {
|
|||
|
this.children.forEach(function (chunk) {
|
|||
|
if (chunk instanceof SourceNode) {
|
|||
|
chunk.walk(aFn);
|
|||
|
}
|
|||
|
else {
|
|||
|
if (chunk !== '') {
|
|||
|
aFn(chunk, { source: this.source,
|
|||
|
line: this.line,
|
|||
|
column: this.column,
|
|||
|
name: this.name });
|
|||
|
}
|
|||
|
}
|
|||
|
}, this);
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
|
|||
|
* each of `this.children`.
|
|||
|
*
|
|||
|
* @param aSep The separator.
|
|||
|
*/
|
|||
|
SourceNode.prototype.join = function SourceNode_join(aSep) {
|
|||
|
var newChildren;
|
|||
|
var i;
|
|||
|
var len = this.children.length;
|
|||
|
if (len > 0) {
|
|||
|
newChildren = [];
|
|||
|
for (i = 0; i < len-1; i++) {
|
|||
|
newChildren.push(this.children[i]);
|
|||
|
newChildren.push(aSep);
|
|||
|
}
|
|||
|
newChildren.push(this.children[i]);
|
|||
|
this.children = newChildren;
|
|||
|
}
|
|||
|
return this;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Call String.prototype.replace on the very right-most source snippet. Useful
|
|||
|
* for trimming whitespace from the end of a source node, etc.
|
|||
|
*
|
|||
|
* @param aPattern The pattern to replace.
|
|||
|
* @param aReplacement The thing to replace the pattern with.
|
|||
|
*/
|
|||
|
SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
|
|||
|
var lastChild = this.children[this.children.length - 1];
|
|||
|
if (lastChild instanceof SourceNode) {
|
|||
|
lastChild.replaceRight(aPattern, aReplacement);
|
|||
|
}
|
|||
|
else if (typeof lastChild === 'string') {
|
|||
|
this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
|
|||
|
}
|
|||
|
else {
|
|||
|
this.children.push(''.replace(aPattern, aReplacement));
|
|||
|
}
|
|||
|
return this;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Set the source content for a source file. This will be added to the SourceMapGenerator
|
|||
|
* in the sourcesContent field.
|
|||
|
*
|
|||
|
* @param aSourceFile The filename of the source file
|
|||
|
* @param aSourceContent The content of the source file
|
|||
|
*/
|
|||
|
SourceNode.prototype.setSourceContent =
|
|||
|
function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
|
|||
|
this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Walk over the tree of SourceNodes. The walking function is called for each
|
|||
|
* source file content and is passed the filename and source content.
|
|||
|
*
|
|||
|
* @param aFn The traversal function.
|
|||
|
*/
|
|||
|
SourceNode.prototype.walkSourceContents =
|
|||
|
function SourceNode_walkSourceContents(aFn) {
|
|||
|
this.children.forEach(function (chunk) {
|
|||
|
if (chunk instanceof SourceNode) {
|
|||
|
chunk.walkSourceContents(aFn);
|
|||
|
}
|
|||
|
}, this);
|
|||
|
Object.keys(this.sourceContents).forEach(function (sourceFileKey) {
|
|||
|
aFn(util.fromSetString(sourceFileKey), this.sourceContents[sourceFileKey]);
|
|||
|
}, this);
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Return the string representation of this source node. Walks over the tree
|
|||
|
* and concatenates all the various snippets together to one string.
|
|||
|
*/
|
|||
|
SourceNode.prototype.toString = function SourceNode_toString() {
|
|||
|
var str = "";
|
|||
|
this.walk(function (chunk) {
|
|||
|
str += chunk;
|
|||
|
});
|
|||
|
return str;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Returns the string representation of this source node along with a source
|
|||
|
* map.
|
|||
|
*/
|
|||
|
SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
|
|||
|
var generated = {
|
|||
|
code: "",
|
|||
|
line: 1,
|
|||
|
column: 0
|
|||
|
};
|
|||
|
var map = new SourceMapGenerator(aArgs);
|
|||
|
var sourceMappingActive = false;
|
|||
|
this.walk(function (chunk, original) {
|
|||
|
generated.code += chunk;
|
|||
|
if (original.source !== null
|
|||
|
&& original.line !== null
|
|||
|
&& original.column !== null) {
|
|||
|
map.addMapping({
|
|||
|
source: original.source,
|
|||
|
original: {
|
|||
|
line: original.line,
|
|||
|
column: original.column
|
|||
|
},
|
|||
|
generated: {
|
|||
|
line: generated.line,
|
|||
|
column: generated.column
|
|||
|
},
|
|||
|
name: original.name
|
|||
|
});
|
|||
|
sourceMappingActive = true;
|
|||
|
} else if (sourceMappingActive) {
|
|||
|
map.addMapping({
|
|||
|
generated: {
|
|||
|
line: generated.line,
|
|||
|
column: generated.column
|
|||
|
}
|
|||
|
});
|
|||
|
sourceMappingActive = false;
|
|||
|
}
|
|||
|
chunk.split('').forEach(function (ch) {
|
|||
|
if (ch === '\n') {
|
|||
|
generated.line++;
|
|||
|
generated.column = 0;
|
|||
|
} else {
|
|||
|
generated.column++;
|
|||
|
}
|
|||
|
});
|
|||
|
});
|
|||
|
this.walkSourceContents(function (sourceFile, sourceContent) {
|
|||
|
map.setSourceContent(sourceFile, sourceContent);
|
|||
|
});
|
|||
|
|
|||
|
return { code: generated.code, map: map };
|
|||
|
};
|
|||
|
|
|||
|
exports.SourceNode = SourceNode;
|
|||
|
|
|||
|
});
|
|||
|
/* -*- Mode: js; js-indent-level: 2; -*- */
|
|||
|
///////////////////////////////////////////////////////////////////////////////
|
|||
|
|
|||
|
window.sourceMap = {
|
|||
|
SourceMapConsumer: require('source-map/source-map-consumer').SourceMapConsumer,
|
|||
|
SourceMapGenerator: require('source-map/source-map-generator').SourceMapGenerator,
|
|||
|
SourceNode: require('source-map/source-node').SourceNode
|
|||
|
};
|
|||
|
MOZ_SourceMap = sourceMap;(function(exports,global){global["UglifyJS"]=exports;/***********************************************************************
|
|||
|
|
|||
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
|||
|
https://github.com/mishoo/UglifyJS2
|
|||
|
|
|||
|
-------------------------------- (C) ---------------------------------
|
|||
|
|
|||
|
Author: Mihai Bazon
|
|||
|
<mihai.bazon@gmail.com>
|
|||
|
http://mihai.bazon.net/blog
|
|||
|
|
|||
|
Distributed under the BSD license:
|
|||
|
|
|||
|
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
|||
|
|
|||
|
Redistribution and use in source and binary forms, with or without
|
|||
|
modification, are permitted provided that the following conditions
|
|||
|
are met:
|
|||
|
|
|||
|
* Redistributions of source code must retain the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer.
|
|||
|
|
|||
|
* Redistributions in binary form must reproduce the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer in the documentation and/or other materials
|
|||
|
provided with the distribution.
|
|||
|
|
|||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
|
|||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
|
|||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|||
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|||
|
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|||
|
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|||
|
SUCH DAMAGE.
|
|||
|
|
|||
|
***********************************************************************/
|
|||
|
"use strict";function array_to_hash(a){var ret=Object.create(null);for(var i=0;i<a.length;++i)ret[a[i]]=true;return ret}function slice(a,start){return Array.prototype.slice.call(a,start||0)}function characters(str){return str.split("")}function member(name,array){for(var i=array.length;--i>=0;)if(array[i]==name)return true;return false}function find_if(func,array){for(var i=0,n=array.length;i<n;++i){if(func(array[i]))return array[i]}}function repeat_string(str,i){if(i<=0)return"";if(i==1)return str;var d=repeat_string(str,i>>1);d+=d;if(i&1)d+=str;return d}function DefaultsError(msg,defs){Error.call(this,msg);this.msg=msg;this.defs=defs}DefaultsError.prototype=Object.create(Error.prototype);DefaultsError.prototype.constructor=DefaultsError;DefaultsError.croak=function(msg,defs){throw new DefaultsError(msg,defs)};function defaults(args,defs,croak){if(args===true)args={};var ret=args||{};if(croak)for(var i in ret)if(ret.hasOwnProperty(i)&&!defs.hasOwnProperty(i))DefaultsError.croak("`"+i+"` is not a supported option",defs);for(var i in defs)if(defs.hasOwnProperty(i)){ret[i]=args&&args.hasOwnProperty(i)?args[i]:defs[i]}return ret}function merge(obj,ext){for(var i in ext)if(ext.hasOwnProperty(i)){obj[i]=ext[i]}return obj}function noop(){}var MAP=function(){function MAP(a,f,backwards){var ret=[],top=[],i;function doit(){var val=f(a[i],i);var is_last=val instanceof Last;if(is_last)val=val.v;if(val instanceof AtTop){val=val.v;if(val instanceof Splice){top.push.apply(top,backwards?val.v.slice().reverse():val.v)}else{top.push(val)}}else if(val!==skip){if(val instanceof Splice){ret.push.apply(ret,backwards?val.v.slice().reverse():val.v)}else{ret.push(val)}}return is_last}if(a instanceof Array){if(backwards){for(i=a.length;--i>=0;)if(doit())break;ret.reverse();top.reverse()}else{for(i=0;i<a.length;++i)if(doit())break}}else{for(i in a)if(a.hasOwnProperty(i))if(doit())break}return top.concat(ret)}MAP.at_top=function(val){return new AtTop(val)};MAP.splice=function(val){return new Splice(val)};MAP.last=function(val){return new Last(val)};var skip=MAP.skip={};function AtTop(val){this.v=val}function Splice(val){this.v=val}function Last(val){this.v=val}return MAP}();function push_uniq(array,el){if(array.indexOf(el)<0)array.push(el)}function string_template(text,props){return text.replace(/\{(.+?)\}/g,function(str,p){return props[p]})}function remove(array,el){for(var i=array.length;--i>=0;){if(array[i]===el)array.splice(i,1)}}function mergeSort(array,cmp){if(array.length<2)return array.slice();function merge(a,b){var r=[],ai=0,bi=0,i=0;while(ai<a.length&&bi<b.length){cmp(a[ai],b[bi])<=0?r[i++]=a[ai++]:r[i++]=b[bi++]}if(ai<a.length)r.push.apply(r,a.slice(ai));if(bi<b.length)r.push.apply(r,b.slice(bi));return r}function _ms(a){if(a.length<=1)return a;var m=Math.floor(a.length/2),left=a.slice(0,m),right=a.slice(m);left=_ms(left);right=_ms(right);return merge(left,right)}return _ms(array)}function set_difference(a,b){return a.filter(function(el){return b.indexOf(el)<0})}function set_intersection(a,b){return a.filter(function(el){return b.indexOf(el)>=0})}function makePredicate(words){if(!(words instanceof Array))words=words.split(" ");var f="",cats=[];out:for(var i=0;i<words.length;++i){for(var j=0;j<cats.length;++j)if(cats[j][0].length==words[i].length){cats[j].push(words[i]);continue out}cats.push([words[i]])}function compareTo(arr){if(arr.length==1)return f+="return str === "+JSON.stringify(arr[0])+";";f+="switch(str){";for(var i=0;i<arr.length;++i)f+="case "+JSON.stringify(arr[i])+":";f+="return true}return false;"}if(cats.length>3){cats.sort(function(a,b){return b.length-a.length});f+="switch(str.length){";for(var i=0;i<cats.length;++i){var cat=cats[i];f+="case "+cat[0].length+":";compareTo(cat)}f+="}"}else{compareTo(words)}return new Function("str",f)}function all(array,predicate){for(var i=array.length;--i>=0;)if(!predicate(array[i]))return false;return true}function Dictionary(){this._values=Object.create(null);this._size=0}Dictionary.prototype={set:function(key,val){if(!this.has(key))++this._size;this._values["$"+key]=val;return this
|
|||
|
|
|||
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
|||
|
https://github.com/mishoo/UglifyJS2
|
|||
|
|
|||
|
-------------------------------- (C) ---------------------------------
|
|||
|
|
|||
|
Author: Mihai Bazon
|
|||
|
<mihai.bazon@gmail.com>
|
|||
|
http://mihai.bazon.net/blog
|
|||
|
|
|||
|
Distributed under the BSD license:
|
|||
|
|
|||
|
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
|||
|
|
|||
|
Redistribution and use in source and binary forms, with or without
|
|||
|
modification, are permitted provided that the following conditions
|
|||
|
are met:
|
|||
|
|
|||
|
* Redistributions of source code must retain the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer.
|
|||
|
|
|||
|
* Redistributions in binary form must reproduce the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer in the documentation and/or other materials
|
|||
|
provided with the distribution.
|
|||
|
|
|||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
|
|||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
|
|||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|||
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|||
|
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|||
|
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|||
|
SUCH DAMAGE.
|
|||
|
|
|||
|
***********************************************************************/
|
|||
|
"use strict";function DEFNODE(type,props,methods,base){if(arguments.length<4)base=AST_Node;if(!props)props=[];else props=props.split(/\s+/);var self_props=props;if(base&&base.PROPS)props=props.concat(base.PROPS);var code="return function AST_"+type+"(props){ if (props) { ";for(var i=props.length;--i>=0;){code+="this."+props[i]+" = props."+props[i]+";"}var proto=base&&new base;if(proto&&proto.initialize||methods&&methods.initialize)code+="this.initialize();";code+="}}";var ctor=new Function(code)();if(proto){ctor.prototype=proto;ctor.BASE=base}if(base)base.SUBCLASSES.push(ctor);ctor.prototype.CTOR=ctor;ctor.PROPS=props||null;ctor.SELF_PROPS=self_props;ctor.SUBCLASSES=[];if(type){ctor.prototype.TYPE=ctor.TYPE=type}if(methods)for(i in methods)if(methods.hasOwnProperty(i)){if(/^\$/.test(i)){ctor[i.substr(1)]=methods[i]}else{ctor.prototype[i]=methods[i]}}ctor.DEFMETHOD=function(name,method){this.prototype[name]=method};return ctor}var AST_Token=DEFNODE("Token","type value line col pos endpos nlb comments_before file",{},null);var AST_Node=DEFNODE("Node","start end",{clone:function(){return new this.CTOR(this)},$documentation:"Base class of all AST nodes",$propdoc:{start:"[AST_Token] The first token of this node",end:"[AST_Token] The last token of this node"},_walk:function(visitor){return visitor._visit(this)},walk:function(visitor){return this._walk(visitor)}},null);AST_Node.warn_function=null;AST_Node.warn=function(txt,props){if(AST_Node.warn_function)AST_Node.warn_function(string_template(txt,props))};var AST_Statement=DEFNODE("Statement",null,{$documentation:"Base class of all statements"});var AST_Debugger=DEFNODE("Debugger",null,{$documentation:"Represents a debugger statement"},AST_Statement);var AST_Directive=DEFNODE("Directive","value scope",{$documentation:'Represents a directive, like "use strict";',$propdoc:{value:"[string] The value of this directive as a plain string (it's not an AST_String!)",scope:"[AST_Scope/S] The scope that this directive affects"}},AST_Statement);var AST_SimpleStatement=DEFNODE("SimpleStatement","body",{$documentation:"A statement consisting of an expression, i.e. a = 1 + 2",$propdoc:{body:"[AST_Node] an expression node (should not be instanceof AST_Statement)"},_walk:function(visitor){return visitor._visit(this,function(){this.body._walk(visitor)})}},AST_Statement);function walk_body(node,visitor){if(node.body instanceof AST_Statement){node.body._walk(visitor)}else node.body.forEach(function(stat){stat._walk(visitor)})}var AST_Block=DEFNODE("Block","body",{$documentation:"A body of statements (usually bracketed)",$propdoc:{body:"[AST_Statement*] an array of statements"},_walk:function(visitor){return visitor._visit(this,function(){walk_body(this,visitor)})}},AST_Statement);var AST_BlockStatement=DEFNODE("BlockStatement",null,{$documentation:"A block statement"},AST_Block);var AST_EmptyStatement=DEFNODE("EmptyStatement",null,{$documentation:"The empty statement (empty block or simply a semicolon)",_walk:function(visitor){return visitor._visit(this)}},AST_Statement);var AST_StatementWithBody=DEFNODE("StatementWithBody","body",{$documentation:"Base class for all statements that contain one nested body: `For`, `ForIn`, `Do`, `While`, `With`",$propdoc:{body:"[AST_Statement] the body; this should always be present, even if it's an AST_EmptyStatement"},_walk:function(visitor){return visitor._visit(this,function(){this.body._walk(visitor)})}},AST_Statement);var AST_LabeledStatement=DEFNODE("LabeledStatement","label",{$documentation:"Statement with a label",$propdoc:{label:"[AST_Label] a label definition"},_walk:function(visitor){return visitor._visit(this,function(){this.label._walk(visitor);this.body._walk(visitor)})}},AST_StatementWithBody);var AST_IterationStatement=DEFNODE("IterationStatement",null,{$documentation:"Internal class. All loops inherit from it."},AST_StatementWithBody);var AST_DWLoop=DEFNODE("DWLoop","condition",{$documentation:"Base class for do/while statements",$propdoc:{condition:"[AST_Node] the loop condition. Should not be instanceof AST_Statement"},_walk:function(visito
|
|||
|
|
|||
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
|||
|
https://github.com/mishoo/UglifyJS2
|
|||
|
|
|||
|
-------------------------------- (C) ---------------------------------
|
|||
|
|
|||
|
Author: Mihai Bazon
|
|||
|
<mihai.bazon@gmail.com>
|
|||
|
http://mihai.bazon.net/blog
|
|||
|
|
|||
|
Distributed under the BSD license:
|
|||
|
|
|||
|
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
|||
|
Parser based on parse-js (http://marijn.haverbeke.nl/parse-js/).
|
|||
|
|
|||
|
Redistribution and use in source and binary forms, with or without
|
|||
|
modification, are permitted provided that the following conditions
|
|||
|
are met:
|
|||
|
|
|||
|
* Redistributions of source code must retain the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer.
|
|||
|
|
|||
|
* Redistributions in binary form must reproduce the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer in the documentation and/or other materials
|
|||
|
provided with the distribution.
|
|||
|
|
|||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
|
|||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
|
|||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|||
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|||
|
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|||
|
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|||
|
SUCH DAMAGE.
|
|||
|
|
|||
|
***********************************************************************/
|
|||
|
"use strict";var KEYWORDS="break case catch const continue debugger default delete do else finally for function if in instanceof new return switch throw try typeof var void while with";var KEYWORDS_ATOM="false null true";var RESERVED_WORDS="abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized this throws transient volatile yield"+" "+KEYWORDS_ATOM+" "+KEYWORDS;var KEYWORDS_BEFORE_EXPRESSION="return new delete throw else case";KEYWORDS=makePredicate(KEYWORDS);RESERVED_WORDS=makePredicate(RESERVED_WORDS);KEYWORDS_BEFORE_EXPRESSION=makePredicate(KEYWORDS_BEFORE_EXPRESSION);KEYWORDS_ATOM=makePredicate(KEYWORDS_ATOM);var OPERATOR_CHARS=makePredicate(characters("+-*&%=<>!?|~^"));var RE_HEX_NUMBER=/^0x[0-9a-f]+$/i;var RE_OCT_NUMBER=/^0[0-7]+$/;var RE_DEC_NUMBER=/^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i;var OPERATORS=makePredicate(["in","instanceof","typeof","new","void","delete","++","--","+","-","!","~","&","|","^","*","/","%",">>","<<",">>>","<",">","<=",">=","==","===","!=","!==","?","=","+=","-=","/=","*=","%=",">>=","<<=",">>>=","|=","^=","&=","&&","||"]);var WHITESPACE_CHARS=makePredicate(characters(" \n\r \f "));var PUNC_BEFORE_EXPRESSION=makePredicate(characters("[{(,.;:"));var PUNC_CHARS=makePredicate(characters("[]{}(),;:"));var REGEXP_MODIFIERS=makePredicate(characters("gmsiy"));var UNICODE={letter:new RegExp("[\\u0041-\\u005A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u0523\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0621-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971\\u0972\\u097B-\\u097F\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C33\\u0C35-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D28\\u0D2A-\\u0D39\\u0D3D\\u0D60\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E46\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC\\u0EDD\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8B\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10D0-\\u10FA\\u10FC\\u1100-\\u1159\\u115F-\\u11A2\\u11A8-\\u11F9\\u1200-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u1676\\u1681-\\u169A\\u16A0-\\u16EA\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1877\\u1880-
|
|||
|
if(toplevel){toplevel.body=toplevel.body.concat(body);toplevel.end=end}else{toplevel=new AST_Toplevel({start:start,body:body,end:end})}return toplevel}()}/***********************************************************************
|
|||
|
|
|||
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
|||
|
https://github.com/mishoo/UglifyJS2
|
|||
|
|
|||
|
-------------------------------- (C) ---------------------------------
|
|||
|
|
|||
|
Author: Mihai Bazon
|
|||
|
<mihai.bazon@gmail.com>
|
|||
|
http://mihai.bazon.net/blog
|
|||
|
|
|||
|
Distributed under the BSD license:
|
|||
|
|
|||
|
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
|||
|
|
|||
|
Redistribution and use in source and binary forms, with or without
|
|||
|
modification, are permitted provided that the following conditions
|
|||
|
are met:
|
|||
|
|
|||
|
* Redistributions of source code must retain the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer.
|
|||
|
|
|||
|
* Redistributions in binary form must reproduce the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer in the documentation and/or other materials
|
|||
|
provided with the distribution.
|
|||
|
|
|||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
|
|||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
|
|||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|||
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|||
|
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|||
|
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|||
|
SUCH DAMAGE.
|
|||
|
|
|||
|
***********************************************************************/
|
|||
|
"use strict";function TreeTransformer(before,after){TreeWalker.call(this);this.before=before;this.after=after}TreeTransformer.prototype=new TreeWalker;(function(undefined){function _(node,descend){node.DEFMETHOD("transform",function(tw,in_list){var x,y;tw.push(this);if(tw.before)x=tw.before(this,descend,in_list);if(x===undefined){if(!tw.after){x=this;descend(x,tw)}else{tw.stack[tw.stack.length-1]=x=this.clone();descend(x,tw);y=tw.after(x,in_list);if(y!==undefined)x=y}}tw.pop();return x})}function do_list(list,tw){return MAP(list,function(node){return node.transform(tw,true)})}_(AST_Node,noop);_(AST_LabeledStatement,function(self,tw){self.label=self.label.transform(tw);self.body=self.body.transform(tw)});_(AST_SimpleStatement,function(self,tw){self.body=self.body.transform(tw)});_(AST_Block,function(self,tw){self.body=do_list(self.body,tw)});_(AST_DWLoop,function(self,tw){self.condition=self.condition.transform(tw);self.body=self.body.transform(tw)});_(AST_For,function(self,tw){if(self.init)self.init=self.init.transform(tw);if(self.condition)self.condition=self.condition.transform(tw);if(self.step)self.step=self.step.transform(tw);self.body=self.body.transform(tw)});_(AST_ForIn,function(self,tw){self.init=self.init.transform(tw);self.object=self.object.transform(tw);self.body=self.body.transform(tw)});_(AST_With,function(self,tw){self.expression=self.expression.transform(tw);self.body=self.body.transform(tw)});_(AST_Exit,function(self,tw){if(self.value)self.value=self.value.transform(tw)});_(AST_LoopControl,function(self,tw){if(self.label)self.label=self.label.transform(tw)});_(AST_If,function(self,tw){self.condition=self.condition.transform(tw);self.body=self.body.transform(tw);if(self.alternative)self.alternative=self.alternative.transform(tw)});_(AST_Switch,function(self,tw){self.expression=self.expression.transform(tw);self.body=do_list(self.body,tw)});_(AST_Case,function(self,tw){self.expression=self.expression.transform(tw);self.body=do_list(self.body,tw)});_(AST_Try,function(self,tw){self.body=do_list(self.body,tw);if(self.bcatch)self.bcatch=self.bcatch.transform(tw);if(self.bfinally)self.bfinally=self.bfinally.transform(tw)});_(AST_Catch,function(self,tw){self.argname=self.argname.transform(tw);self.body=do_list(self.body,tw)});_(AST_Definitions,function(self,tw){self.definitions=do_list(self.definitions,tw)});_(AST_VarDef,function(self,tw){self.name=self.name.transform(tw);if(self.value)self.value=self.value.transform(tw)});_(AST_Lambda,function(self,tw){if(self.name)self.name=self.name.transform(tw);self.argnames=do_list(self.argnames,tw);self.body=do_list(self.body,tw)});_(AST_Call,function(self,tw){self.expression=self.expression.transform(tw);self.args=do_list(self.args,tw)});_(AST_Seq,function(self,tw){self.car=self.car.transform(tw);self.cdr=self.cdr.transform(tw)});_(AST_Dot,function(self,tw){self.expression=self.expression.transform(tw)});_(AST_Sub,function(self,tw){self.expression=self.expression.transform(tw);self.property=self.property.transform(tw)});_(AST_Unary,function(self,tw){self.expression=self.expression.transform(tw)});_(AST_Binary,function(self,tw){self.left=self.left.transform(tw);self.right=self.right.transform(tw)});_(AST_Conditional,function(self,tw){self.condition=self.condition.transform(tw);self.consequent=self.consequent.transform(tw);self.alternative=self.alternative.transform(tw)});_(AST_Array,function(self,tw){self.elements=do_list(self.elements,tw)});_(AST_Object,function(self,tw){self.properties=do_list(self.properties,tw)});_(AST_ObjectProperty,function(self,tw){self.value=self.value.transform(tw)})})();/***********************************************************************
|
|||
|
|
|||
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
|||
|
https://github.com/mishoo/UglifyJS2
|
|||
|
|
|||
|
-------------------------------- (C) ---------------------------------
|
|||
|
|
|||
|
Author: Mihai Bazon
|
|||
|
<mihai.bazon@gmail.com>
|
|||
|
http://mihai.bazon.net/blog
|
|||
|
|
|||
|
Distributed under the BSD license:
|
|||
|
|
|||
|
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
|||
|
|
|||
|
Redistribution and use in source and binary forms, with or without
|
|||
|
modification, are permitted provided that the following conditions
|
|||
|
are met:
|
|||
|
|
|||
|
* Redistributions of source code must retain the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer.
|
|||
|
|
|||
|
* Redistributions in binary form must reproduce the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer in the documentation and/or other materials
|
|||
|
provided with the distribution.
|
|||
|
|
|||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
|
|||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
|
|||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|||
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|||
|
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|||
|
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|||
|
SUCH DAMAGE.
|
|||
|
|
|||
|
***********************************************************************/
|
|||
|
"use strict";function SymbolDef(scope,index,orig){this.name=orig.name;this.orig=[orig];this.scope=scope;this.references=[];this.global=false;this.mangled_name=null;this.undeclared=false;this.constant=false;this.index=index}SymbolDef.prototype={unmangleable:function(options){return this.global&&!(options&&options.toplevel)||this.undeclared||!(options&&options.eval)&&(this.scope.uses_eval||this.scope.uses_with)},mangle:function(options){if(!this.mangled_name&&!this.unmangleable(options)){var s=this.scope;if(!options.screw_ie8&&this.orig[0]instanceof AST_SymbolLambda)s=s.parent_scope;this.mangled_name=s.next_mangled(options,this)}}};AST_Toplevel.DEFMETHOD("figure_out_scope",function(options){options=defaults(options,{screw_ie8:false});var self=this;var scope=self.parent_scope=null;var defun=null;var nesting=0;var tw=new TreeWalker(function(node,descend){if(options.screw_ie8&&node instanceof AST_Catch){var save_scope=scope;scope=new AST_Scope(node);scope.init_scope_vars(nesting);scope.parent_scope=save_scope;descend();scope=save_scope;return true}if(node instanceof AST_Scope){node.init_scope_vars(nesting);var save_scope=node.parent_scope=scope;var save_defun=defun;defun=scope=node;++nesting;descend();--nesting;scope=save_scope;defun=save_defun;return true}if(node instanceof AST_Directive){node.scope=scope;push_uniq(scope.directives,node.value);return true}if(node instanceof AST_With){for(var s=scope;s;s=s.parent_scope)s.uses_with=true;return}if(node instanceof AST_Symbol){node.scope=scope}if(node instanceof AST_SymbolLambda){defun.def_function(node)}else if(node instanceof AST_SymbolDefun){(node.scope=defun.parent_scope).def_function(node)}else if(node instanceof AST_SymbolVar||node instanceof AST_SymbolConst){var def=defun.def_variable(node);def.constant=node instanceof AST_SymbolConst;def.init=tw.parent().value}else if(node instanceof AST_SymbolCatch){(options.screw_ie8?scope:defun).def_variable(node)}});self.walk(tw);var func=null;var globals=self.globals=new Dictionary;var tw=new TreeWalker(function(node,descend){if(node instanceof AST_Lambda){var prev_func=func;func=node;descend();func=prev_func;return true}if(node instanceof AST_SymbolRef){var name=node.name;var sym=node.scope.find_variable(name);if(!sym){var g;if(globals.has(name)){g=globals.get(name)}else{g=new SymbolDef(self,globals.size(),node);g.undeclared=true;g.global=true;globals.set(name,g)}node.thedef=g;if(name=="eval"&&tw.parent()instanceof AST_Call){for(var s=node.scope;s&&!s.uses_eval;s=s.parent_scope)s.uses_eval=true}if(func&&name=="arguments"){func.uses_arguments=true}}else{node.thedef=sym}node.reference();return true}});self.walk(tw)});AST_Scope.DEFMETHOD("init_scope_vars",function(nesting){this.directives=[];this.variables=new Dictionary;this.functions=new Dictionary;this.uses_with=false;this.uses_eval=false;this.parent_scope=null;this.enclosed=[];this.cname=-1;this.nesting=nesting});AST_Scope.DEFMETHOD("strict",function(){return this.has_directive("use strict")});AST_Lambda.DEFMETHOD("init_scope_vars",function(){AST_Scope.prototype.init_scope_vars.apply(this,arguments);this.uses_arguments=false});AST_SymbolRef.DEFMETHOD("reference",function(){var def=this.definition();def.references.push(this);var s=this.scope;while(s){push_uniq(s.enclosed,def);if(s===def.scope)break;s=s.parent_scope}this.frame=this.scope.nesting-def.scope.nesting});AST_Scope.DEFMETHOD("find_variable",function(name){if(name instanceof AST_Symbol)name=name.name;return this.variables.get(name)||this.parent_scope&&this.parent_scope.find_variable(name)});AST_Scope.DEFMETHOD("has_directive",function(value){return this.parent_scope&&this.parent_scope.has_directive(value)||(this.directives.indexOf(value)>=0?this:null)});AST_Scope.DEFMETHOD("def_function",function(symbol){this.functions.set(symbol.name,this.def_variable(symbol))});AST_Scope.DEFMETHOD("def_variable",function(symbol){var def;if(!this.variables.has(symbol.name)){def=new SymbolDef(this,this.variables.size(),symbol);this.variables.set(symbol.name,def);def.global=!this.parent_scope}else{def=this.variables.get(symbol.name);def.orig
|
|||
|
|
|||
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
|||
|
https://github.com/mishoo/UglifyJS2
|
|||
|
|
|||
|
-------------------------------- (C) ---------------------------------
|
|||
|
|
|||
|
Author: Mihai Bazon
|
|||
|
<mihai.bazon@gmail.com>
|
|||
|
http://mihai.bazon.net/blog
|
|||
|
|
|||
|
Distributed under the BSD license:
|
|||
|
|
|||
|
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
|||
|
|
|||
|
Redistribution and use in source and binary forms, with or without
|
|||
|
modification, are permitted provided that the following conditions
|
|||
|
are met:
|
|||
|
|
|||
|
* Redistributions of source code must retain the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer.
|
|||
|
|
|||
|
* Redistributions in binary form must reproduce the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer in the documentation and/or other materials
|
|||
|
provided with the distribution.
|
|||
|
|
|||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
|
|||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
|
|||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|||
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|||
|
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|||
|
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|||
|
SUCH DAMAGE.
|
|||
|
|
|||
|
***********************************************************************/
|
|||
|
"use strict";function OutputStream(options){options=defaults(options,{indent_start:0,indent_level:4,quote_keys:false,space_colon:true,ascii_only:false,unescape_regexps:false,inline_script:false,width:80,max_line_len:32e3,beautify:false,source_map:null,bracketize:false,semicolons:true,comments:false,preserve_line:false,screw_ie8:false,preamble:null},true);var indentation=0;var current_col=0;var current_line=1;var current_pos=0;var OUTPUT="";function to_ascii(str,identifier){return str.replace(/[\u0080-\uffff]/g,function(ch){var code=ch.charCodeAt(0).toString(16);if(code.length<=2&&!identifier){while(code.length<2)code="0"+code;return"\\x"+code}else{while(code.length<4)code="0"+code;return"\\u"+code}})}function make_string(str){var dq=0,sq=0;str=str.replace(/[\\\b\f\n\r\t\x22\x27\u2028\u2029\0]/g,function(s){switch(s){case"\\":return"\\\\";case"\b":return"\\b";case"\f":return"\\f";case"\n":return"\\n";case"\r":return"\\r";case"\u2028":return"\\u2028";case"\u2029":return"\\u2029";case'"':++dq;return'"';case"'":++sq;return"'";case"\x00":return"\\x00"}return s});if(options.ascii_only)str=to_ascii(str);if(dq>sq)return"'"+str.replace(/\x27/g,"\\'")+"'";else return'"'+str.replace(/\x22/g,'\\"')+'"'}function encode_string(str){var ret=make_string(str);if(options.inline_script)ret=ret.replace(/<\x2fscript([>\/\t\n\f\r ])/gi,"<\\/script$1");return ret}function make_name(name){name=name.toString();if(options.ascii_only)name=to_ascii(name,true);return name}function make_indent(back){return repeat_string(" ",options.indent_start+indentation-back*options.indent_level)}var might_need_space=false;var might_need_semicolon=false;var last=null;function last_char(){return last.charAt(last.length-1)}function maybe_newline(){if(options.max_line_len&¤t_col>options.max_line_len)print("\n")}var requireSemicolonChars=makePredicate("( [ + * / - , .");function print(str){str=String(str);var ch=str.charAt(0);if(might_need_semicolon){if((!ch||";}".indexOf(ch)<0)&&!/[;]$/.test(last)){if(options.semicolons||requireSemicolonChars(ch)){OUTPUT+=";";current_col++;current_pos++}else{OUTPUT+="\n";current_pos++;current_line++;current_col=0}if(!options.beautify)might_need_space=false}might_need_semicolon=false;maybe_newline()}if(!options.beautify&&options.preserve_line&&stack[stack.length-1]){var target_line=stack[stack.length-1].start.line;while(current_line<target_line){OUTPUT+="\n";current_pos++;current_line++;current_col=0;might_need_space=false}}if(might_need_space){var prev=last_char();if(is_identifier_char(prev)&&(is_identifier_char(ch)||ch=="\\")||/^[\+\-\/]$/.test(ch)&&ch==prev){OUTPUT+=" ";current_col++;current_pos++}might_need_space=false}var a=str.split(/\r?\n/),n=a.length-1;current_line+=n;if(n==0){current_col+=a[n].length}else{current_col=a[n].length}current_pos+=str.length;last=str;OUTPUT+=str}var space=options.beautify?function(){print(" ")}:function(){might_need_space=true};var indent=options.beautify?function(half){if(options.beautify){print(make_indent(half?.5:0))}}:noop;var with_indent=options.beautify?function(col,cont){if(col===true)col=next_indent();var save_indentation=indentation;indentation=col;var ret=cont();indentation=save_indentation;return ret}:function(col,cont){return cont()};var newline=options.beautify?function(){print("\n")}:noop;var semicolon=options.beautify?function(){print(";")}:function(){might_need_semicolon=true};function force_semicolon(){might_need_semicolon=false;print(";")}function next_indent(){return indentation+options.indent_level}function with_block(cont){var ret;print("{");newline();with_indent(next_indent(),function(){ret=cont()});indent();print("}");return ret}function with_parens(cont){print("(");var ret=cont();print(")");return ret}function with_square(cont){print("[");var ret=cont();print("]");return ret}function comma(){print(",");space()}function colon(){print(":");if(options.space_colon)space()}var add_mapping=options.source_map?function(token,name){try{if(token)options.source_map.add(token.file||"?",current_line,current_col,token.line,token.col,!name&&token.type=="name"?token.value:name)}catch
|
|||
|
|
|||
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
|||
|
https://github.com/mishoo/UglifyJS2
|
|||
|
|
|||
|
-------------------------------- (C) ---------------------------------
|
|||
|
|
|||
|
Author: Mihai Bazon
|
|||
|
<mihai.bazon@gmail.com>
|
|||
|
http://mihai.bazon.net/blog
|
|||
|
|
|||
|
Distributed under the BSD license:
|
|||
|
|
|||
|
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
|||
|
|
|||
|
Redistribution and use in source and binary forms, with or without
|
|||
|
modification, are permitted provided that the following conditions
|
|||
|
are met:
|
|||
|
|
|||
|
* Redistributions of source code must retain the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer.
|
|||
|
|
|||
|
* Redistributions in binary form must reproduce the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer in the documentation and/or other materials
|
|||
|
provided with the distribution.
|
|||
|
|
|||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
|
|||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
|
|||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|||
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|||
|
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|||
|
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|||
|
SUCH DAMAGE.
|
|||
|
|
|||
|
***********************************************************************/
|
|||
|
"use strict";function Compressor(options,false_by_default){if(!(this instanceof Compressor))return new Compressor(options,false_by_default);TreeTransformer.call(this,this.before,this.after);this.options=defaults(options,{sequences:!false_by_default,properties:!false_by_default,dead_code:!false_by_default,drop_debugger:!false_by_default,unsafe:false,unsafe_comps:false,conditionals:!false_by_default,comparisons:!false_by_default,evaluate:!false_by_default,booleans:!false_by_default,loops:!false_by_default,unused:!false_by_default,hoist_funs:!false_by_default,keep_fargs:false,hoist_vars:false,if_return:!false_by_default,join_vars:!false_by_default,cascade:!false_by_default,side_effects:!false_by_default,pure_getters:false,pure_funcs:null,negate_iife:!false_by_default,screw_ie8:false,drop_console:false,angular:false,warnings:true,global_defs:{}},true)}Compressor.prototype=new TreeTransformer;merge(Compressor.prototype,{option:function(key){return this.options[key]},warn:function(){if(this.options.warnings)AST_Node.warn.apply(AST_Node,arguments)},before:function(node,descend,in_list){if(node._squeezed)return node;var was_scope=false;if(node instanceof AST_Scope){node=node.hoist_declarations(this);was_scope=true}descend(node,this);node=node.optimize(this);if(was_scope&&node instanceof AST_Scope){node.drop_unused(this);descend(node,this)}node._squeezed=true;return node}});(function(){function OPT(node,optimizer){node.DEFMETHOD("optimize",function(compressor){var self=this;if(self._optimized)return self;var opt=optimizer(self,compressor);opt._optimized=true;if(opt===self)return opt;return opt.transform(compressor)})}OPT(AST_Node,function(self,compressor){return self});AST_Node.DEFMETHOD("equivalent_to",function(node){return this.print_to_string()==node.print_to_string()});function make_node(ctor,orig,props){if(!props)props={};if(orig){if(!props.start)props.start=orig.start;if(!props.end)props.end=orig.end}return new ctor(props)}function make_node_from_constant(compressor,val,orig){if(val instanceof AST_Node)return val.transform(compressor);switch(typeof val){case"string":return make_node(AST_String,orig,{value:val}).optimize(compressor);case"number":return make_node(isNaN(val)?AST_NaN:AST_Number,orig,{value:val}).optimize(compressor);case"boolean":return make_node(val?AST_True:AST_False,orig).optimize(compressor);case"undefined":return make_node(AST_Undefined,orig).optimize(compressor);default:if(val===null){return make_node(AST_Null,orig).optimize(compressor)}if(val instanceof RegExp){return make_node(AST_RegExp,orig).optimize(compressor)}throw new Error(string_template("Can't handle constant of type: {type}",{type:typeof val}))}}function as_statement_array(thing){if(thing===null)return[];if(thing instanceof AST_BlockStatement)return thing.body;if(thing instanceof AST_EmptyStatement)return[];if(thing instanceof AST_Statement)return[thing];throw new Error("Can't convert thing to statement array")}function is_empty(thing){if(thing===null)return true;if(thing instanceof AST_EmptyStatement)return true;if(thing instanceof AST_BlockStatement)return thing.body.length==0;return false}function loop_body(x){if(x instanceof AST_Switch)return x;if(x instanceof AST_For||x instanceof AST_ForIn||x instanceof AST_DWLoop){return x.body instanceof AST_BlockStatement?x.body:x}return x}function tighten_body(statements,compressor){var CHANGED;do{CHANGED=false;if(compressor.option("angular")){statements=process_for_angular(statements)}statements=eliminate_spurious_blocks(statements);if(compressor.option("dead_code")){statements=eliminate_dead_code(statements,compressor)}if(compressor.option("if_return")){statements=handle_if_return(statements,compressor)}if(compressor.option("sequences")){statements=sequencesize(statements,compressor)}if(compressor.option("join_vars")){statements=join_consecutive_vars(statements,compressor)}}while(CHANGED);if(compressor.option("negate_iife")){negate_iifes(statements,compressor)}return statements;function process_for_angular(statements){function make_injector(func,name){return make_node(AST_SimpleStatement,func,{bod
|
|||
|
}if(is_empty(self.alternative)&&self.body instanceof AST_SimpleStatement){if(negated_is_best)return make_node(AST_SimpleStatement,self,{body:make_node(AST_Binary,self,{operator:"||",left:negated,right:self.body.body})}).transform(compressor);return make_node(AST_SimpleStatement,self,{body:make_node(AST_Binary,self,{operator:"&&",left:self.condition,right:self.body.body})}).transform(compressor)}if(self.body instanceof AST_EmptyStatement&&self.alternative&&self.alternative instanceof AST_SimpleStatement){return make_node(AST_SimpleStatement,self,{body:make_node(AST_Binary,self,{operator:"||",left:self.condition,right:self.alternative.body})}).transform(compressor)}if(self.body instanceof AST_Exit&&self.alternative instanceof AST_Exit&&self.body.TYPE==self.alternative.TYPE){return make_node(self.body.CTOR,self,{value:make_node(AST_Conditional,self,{condition:self.condition,consequent:self.body.value||make_node(AST_Undefined,self.body).optimize(compressor),alternative:self.alternative.value||make_node(AST_Undefined,self.alternative).optimize(compressor)})}).transform(compressor)}if(self.body instanceof AST_If&&!self.body.alternative&&!self.alternative){self.condition=make_node(AST_Binary,self.condition,{operator:"&&",left:self.condition,right:self.body.condition}).transform(compressor);self.body=self.body.body}if(aborts(self.body)){if(self.alternative){var alt=self.alternative;self.alternative=null;return make_node(AST_BlockStatement,self,{body:[self,alt]}).transform(compressor)}}if(aborts(self.alternative)){var body=self.body;self.body=self.alternative;self.condition=negated_is_best?negated:self.condition.negate(compressor);self.alternative=null;return make_node(AST_BlockStatement,self,{body:[self,body]}).transform(compressor)}return self});OPT(AST_Switch,function(self,compressor){if(self.body.length==0&&compressor.option("conditionals")){return make_node(AST_SimpleStatement,self,{body:self.expression}).transform(compressor)}for(;;){var last_branch=self.body[self.body.length-1];if(last_branch){var stat=last_branch.body[last_branch.body.length-1];if(stat instanceof AST_Break&&loop_body(compressor.loopcontrol_target(stat.label))===self)last_branch.body.pop();if(last_branch instanceof AST_Default&&last_branch.body.length==0){self.body.pop();continue}}break}var exp=self.expression.evaluate(compressor);out:if(exp.length==2)try{self.expression=exp[0];if(!compressor.option("dead_code"))break out;var value=exp[1];var in_if=false;var in_block=false;var started=false;var stopped=false;var ruined=false;var tt=new TreeTransformer(function(node,descend,in_list){if(node instanceof AST_Lambda||node instanceof AST_SimpleStatement){return node}else if(node instanceof AST_Switch&&node===self){node=node.clone();descend(node,this);return ruined?node:make_node(AST_BlockStatement,node,{body:node.body.reduce(function(a,branch){return a.concat(branch.body)},[])}).transform(compressor)}else if(node instanceof AST_If||node instanceof AST_Try){var save=in_if;in_if=!in_block;descend(node,this);in_if=save;return node}else if(node instanceof AST_StatementWithBody||node instanceof AST_Switch){var save=in_block;in_block=true;descend(node,this);in_block=save;return node}else if(node instanceof AST_Break&&this.loopcontrol_target(node.label)===self){if(in_if){ruined=true;return node}if(in_block)return node;stopped=true;return in_list?MAP.skip:make_node(AST_EmptyStatement,node)}else if(node instanceof AST_SwitchBranch&&this.parent()===self){if(stopped)return MAP.skip;if(node instanceof AST_Case){var exp=node.expression.evaluate(compressor);if(exp.length<2){throw self}if(exp[1]===value||started){started=true;if(aborts(node))stopped=true;descend(node,this);return node}return MAP.skip}descend(node,this);return node}});tt.stack=compressor.stack.slice();self=self.transform(tt)}catch(ex){if(ex!==self)throw ex}return self});OPT(AST_Case,function(self,compressor){self.body=tighten_body(self.body,compressor);return self});OPT(AST_Try,function(self,compressor){self.body=tighten_body(self.body,compressor);return self});AST_Definitions.DEFMETHOD("remove_initializers",f
|
|||
|
|
|||
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
|||
|
https://github.com/mishoo/UglifyJS2
|
|||
|
|
|||
|
-------------------------------- (C) ---------------------------------
|
|||
|
|
|||
|
Author: Mihai Bazon
|
|||
|
<mihai.bazon@gmail.com>
|
|||
|
http://mihai.bazon.net/blog
|
|||
|
|
|||
|
Distributed under the BSD license:
|
|||
|
|
|||
|
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
|||
|
|
|||
|
Redistribution and use in source and binary forms, with or without
|
|||
|
modification, are permitted provided that the following conditions
|
|||
|
are met:
|
|||
|
|
|||
|
* Redistributions of source code must retain the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer.
|
|||
|
|
|||
|
* Redistributions in binary form must reproduce the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer in the documentation and/or other materials
|
|||
|
provided with the distribution.
|
|||
|
|
|||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
|
|||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
|
|||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|||
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|||
|
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|||
|
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|||
|
SUCH DAMAGE.
|
|||
|
|
|||
|
***********************************************************************/
|
|||
|
"use strict";function SourceMap(options){options=defaults(options,{file:null,root:null,orig:null,orig_line_diff:0,dest_line_diff:0});var generator=new MOZ_SourceMap.SourceMapGenerator({file:options.file,sourceRoot:options.root});var orig_map=options.orig&&new MOZ_SourceMap.SourceMapConsumer(options.orig);function add(source,gen_line,gen_col,orig_line,orig_col,name){if(orig_map){var info=orig_map.originalPositionFor({line:orig_line,column:orig_col});if(info.source===null){return}source=info.source;orig_line=info.line;orig_col=info.column;name=info.name||name}generator.addMapping({generated:{line:gen_line+options.dest_line_diff,column:gen_col},original:{line:orig_line+options.orig_line_diff,column:orig_col},source:source,name:name})}return{add:add,get:function(){return generator},toString:function(){return generator.toString()}}}/***********************************************************************
|
|||
|
|
|||
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
|||
|
https://github.com/mishoo/UglifyJS2
|
|||
|
|
|||
|
-------------------------------- (C) ---------------------------------
|
|||
|
|
|||
|
Author: Mihai Bazon
|
|||
|
<mihai.bazon@gmail.com>
|
|||
|
http://mihai.bazon.net/blog
|
|||
|
|
|||
|
Distributed under the BSD license:
|
|||
|
|
|||
|
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
|||
|
|
|||
|
Redistribution and use in source and binary forms, with or without
|
|||
|
modification, are permitted provided that the following conditions
|
|||
|
are met:
|
|||
|
|
|||
|
* Redistributions of source code must retain the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer.
|
|||
|
|
|||
|
* Redistributions in binary form must reproduce the above
|
|||
|
copyright notice, this list of conditions and the following
|
|||
|
disclaimer in the documentation and/or other materials
|
|||
|
provided with the distribution.
|
|||
|
|
|||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
|
|||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|||
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
|
|||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|||
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|||
|
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|||
|
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|||
|
SUCH DAMAGE.
|
|||
|
|
|||
|
***********************************************************************/
|
|||
|
"use strict";(function(){var MOZ_TO_ME={ExpressionStatement:function(M){var expr=M.expression;if(expr.type==="Literal"&&typeof expr.value==="string"){return new AST_Directive({start:my_start_token(M),end:my_end_token(M),value:expr.value})}return new AST_SimpleStatement({start:my_start_token(M),end:my_end_token(M),body:from_moz(expr)})},TryStatement:function(M){var handlers=M.handlers||[M.handler];if(handlers.length>1||M.guardedHandlers&&M.guardedHandlers.length){throw new Error("Multiple catch clauses are not supported.")}return new AST_Try({start:my_start_token(M),end:my_end_token(M),body:from_moz(M.block).body,bcatch:from_moz(handlers[0]),bfinally:M.finalizer?new AST_Finally(from_moz(M.finalizer)):null})},Property:function(M){var key=M.key;var name=key.type=="Identifier"?key.name:key.value;var args={start:my_start_token(key),end:my_end_token(M.value),key:name,value:from_moz(M.value)};switch(M.kind){case"init":return new AST_ObjectKeyVal(args);case"set":args.value.name=from_moz(key);return new AST_ObjectSetter(args);case"get":args.value.name=from_moz(key);return new AST_ObjectGetter(args)}},ObjectExpression:function(M){return new AST_Object({start:my_start_token(M),end:my_end_token(M),properties:M.properties.map(function(prop){prop.type="Property";return from_moz(prop)})})},SequenceExpression:function(M){return AST_Seq.from_array(M.expressions.map(from_moz))},MemberExpression:function(M){return new(M.computed?AST_Sub:AST_Dot)({start:my_start_token(M),end:my_end_token(M),property:M.computed?from_moz(M.property):M.property.name,expression:from_moz(M.object)})},SwitchCase:function(M){return new(M.test?AST_Case:AST_Default)({start:my_start_token(M),end:my_end_token(M),expression:from_moz(M.test),body:M.consequent.map(from_moz)})},VariableDeclaration:function(M){return new(M.kind==="const"?AST_Const:AST_Var)({start:my_start_token(M),end:my_end_token(M),definitions:M.declarations.map(from_moz)})},Literal:function(M){var val=M.value,args={start:my_start_token(M),end:my_end_token(M)};if(val===null)return new AST_Null(args);switch(typeof val){case"string":args.value=val;return new AST_String(args);case"number":args.value=val;return new AST_Number(args);case"boolean":return new(val?AST_True:AST_False)(args);default:args.value=val;return new AST_RegExp(args)}},Identifier:function(M){var p=FROM_MOZ_STACK[FROM_MOZ_STACK.length-2];return new(p.type=="LabeledStatement"?AST_Label:p.type=="VariableDeclarator"&&p.id===M?p.kind=="const"?AST_SymbolConst:AST_SymbolVar:p.type=="FunctionExpression"?p.id===M?AST_SymbolLambda:AST_SymbolFunarg:p.type=="FunctionDeclaration"?p.id===M?AST_SymbolDefun:AST_SymbolFunarg:p.type=="CatchClause"?AST_SymbolCatch:p.type=="BreakStatement"||p.type=="ContinueStatement"?AST_LabelRef:AST_SymbolRef)({start:my_start_token(M),end:my_end_token(M),name:M.name})}};MOZ_TO_ME.UpdateExpression=MOZ_TO_ME.UnaryExpression=function To_Moz_Unary(M){var prefix="prefix"in M?M.prefix:M.type=="UnaryExpression"?true:false;return new(prefix?AST_UnaryPrefix:AST_UnaryPostfix)({start:my_start_token(M),end:my_end_token(M),operator:M.operator,expression:from_moz(M.argument)})};map("Program",AST_Toplevel,"body@body");map("EmptyStatement",AST_EmptyStatement);map("BlockStatement",AST_BlockStatement,"body@body");map("IfStatement",AST_If,"test>condition, consequent>body, alternate>alternative");map("LabeledStatement",AST_LabeledStatement,"label>label, body>body");map("BreakStatement",AST_Break,"label>label");map("ContinueStatement",AST_Continue,"label>label");map("WithStatement",AST_With,"object>expression, body>body");map("SwitchStatement",AST_Switch,"discriminant>expression, cases@body");map("ReturnStatement",AST_Return,"argument>value");map("ThrowStatement",AST_Throw,"argument>value");map("WhileStatement",AST_While,"test>condition, body>body");map("DoWhileStatement",AST_Do,"test>condition, body>body");map("ForStatement",AST_For,"init>init, test>condition, update>step, body>body");map("ForInStatement",AST_ForIn,"left>init, right>object, body>body");map("DebuggerStatement",AST_Debugger);map("FunctionDeclaration",AST_Defun,"id>name, params@
|