Created
January 23, 2018 20:55
-
-
Save homam/1f17336d1b6323bda2728c5412d7775d to your computer and use it in GitHub Desktop.
This file has been truncated, but you can view the full file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
๏ปฟ | |
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.babel = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | |
},{}],2:[function(_dereq_,module,exports){ | |
// http://wiki.commonjs.org/wiki/Unit_Testing/1.0 | |
// | |
// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! | |
// | |
// Originally from narwhal.js (http://narwhaljs.org) | |
// Copyright (c) 2009 Thomas Robinson <280north.com> | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the 'Software'), to | |
// deal in the Software without restriction, including without limitation the | |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
// sell copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in | |
// all copies or substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
// when used in node, this will actually load the util module we depend on | |
// versus loading the builtin util module as happens otherwise | |
// this is a bug in node module loading as far as I am concerned | |
var util = _dereq_(13); | |
var pSlice = Array.prototype.slice; | |
var hasOwn = Object.prototype.hasOwnProperty; | |
// 1. The assert module provides functions that throw | |
// AssertionError's when particular conditions are not met. The | |
// assert module must conform to the following interface. | |
var assert = module.exports = ok; | |
// 2. The AssertionError is defined in assert. | |
// new assert.AssertionError({ message: message, | |
// actual: actual, | |
// expected: expected }) | |
assert.AssertionError = function AssertionError(options) { | |
this.name = 'AssertionError'; | |
this.actual = options.actual; | |
this.expected = options.expected; | |
this.operator = options.operator; | |
if (options.message) { | |
this.message = options.message; | |
this.generatedMessage = false; | |
} else { | |
this.message = getMessage(this); | |
this.generatedMessage = true; | |
} | |
var stackStartFunction = options.stackStartFunction || fail; | |
if (Error.captureStackTrace) { | |
Error.captureStackTrace(this, stackStartFunction); | |
} | |
else { | |
// non v8 browsers so we can have a stacktrace | |
var err = new Error(); | |
if (err.stack) { | |
var out = err.stack; | |
// try to strip useless frames | |
var fn_name = stackStartFunction.name; | |
var idx = out.indexOf('\n' + fn_name); | |
if (idx >= 0) { | |
// once we have located the function frame | |
// we need to strip out everything before it (and its line) | |
var next_line = out.indexOf('\n', idx + 1); | |
out = out.substring(next_line + 1); | |
} | |
this.stack = out; | |
} | |
} | |
}; | |
// assert.AssertionError instanceof Error | |
util.inherits(assert.AssertionError, Error); | |
function replacer(key, value) { | |
if (util.isUndefined(value)) { | |
return '' + value; | |
} | |
if (util.isNumber(value) && !isFinite(value)) { | |
return value.toString(); | |
} | |
if (util.isFunction(value) || util.isRegExp(value)) { | |
return value.toString(); | |
} | |
return value; | |
} | |
function truncate(s, n) { | |
if (util.isString(s)) { | |
return s.length < n ? s : s.slice(0, n); | |
} else { | |
return s; | |
} | |
} | |
function getMessage(self) { | |
return truncate(JSON.stringify(self.actual, replacer), 128) + ' ' + | |
self.operator + ' ' + | |
truncate(JSON.stringify(self.expected, replacer), 128); | |
} | |
// At present only the three keys mentioned above are used and | |
// understood by the spec. Implementations or sub modules can pass | |
// other keys to the AssertionError's constructor - they will be | |
// ignored. | |
// 3. All of the following functions must throw an AssertionError | |
// when a corresponding condition is not met, with a message that | |
// may be undefined if not provided. All assertion methods provide | |
// both the actual and expected values to the assertion error for | |
// display purposes. | |
function fail(actual, expected, message, operator, stackStartFunction) { | |
throw new assert.AssertionError({ | |
message: message, | |
actual: actual, | |
expected: expected, | |
operator: operator, | |
stackStartFunction: stackStartFunction | |
}); | |
} | |
// EXTENSION! allows for well behaved errors defined elsewhere. | |
assert.fail = fail; | |
// 4. Pure assertion tests whether a value is truthy, as determined | |
// by !!guard. | |
// assert.ok(guard, message_opt); | |
// This statement is equivalent to assert.equal(true, !!guard, | |
// message_opt);. To test strictly for the value true, use | |
// assert.strictEqual(true, guard, message_opt);. | |
function ok(value, message) { | |
if (!value) fail(value, true, message, '==', assert.ok); | |
} | |
assert.ok = ok; | |
// 5. The equality assertion tests shallow, coercive equality with | |
// ==. | |
// assert.equal(actual, expected, message_opt); | |
assert.equal = function equal(actual, expected, message) { | |
if (actual != expected) fail(actual, expected, message, '==', assert.equal); | |
}; | |
// 6. The non-equality assertion tests for whether two objects are not equal | |
// with != assert.notEqual(actual, expected, message_opt); | |
assert.notEqual = function notEqual(actual, expected, message) { | |
if (actual == expected) { | |
fail(actual, expected, message, '!=', assert.notEqual); | |
} | |
}; | |
// 7. The equivalence assertion tests a deep equality relation. | |
// assert.deepEqual(actual, expected, message_opt); | |
assert.deepEqual = function deepEqual(actual, expected, message) { | |
if (!_deepEqual(actual, expected)) { | |
fail(actual, expected, message, 'deepEqual', assert.deepEqual); | |
} | |
}; | |
function _deepEqual(actual, expected) { | |
// 7.1. All identical values are equivalent, as determined by ===. | |
if (actual === expected) { | |
return true; | |
} else if (util.isBuffer(actual) && util.isBuffer(expected)) { | |
if (actual.length != expected.length) return false; | |
for (var i = 0; i < actual.length; i++) { | |
if (actual[i] !== expected[i]) return false; | |
} | |
return true; | |
// 7.2. If the expected value is a Date object, the actual value is | |
// equivalent if it is also a Date object that refers to the same time. | |
} else if (util.isDate(actual) && util.isDate(expected)) { | |
return actual.getTime() === expected.getTime(); | |
// 7.3 If the expected value is a RegExp object, the actual value is | |
// equivalent if it is also a RegExp object with the same source and | |
// properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). | |
} else if (util.isRegExp(actual) && util.isRegExp(expected)) { | |
return actual.source === expected.source && | |
actual.global === expected.global && | |
actual.multiline === expected.multiline && | |
actual.lastIndex === expected.lastIndex && | |
actual.ignoreCase === expected.ignoreCase; | |
// 7.4. Other pairs that do not both pass typeof value == 'object', | |
// equivalence is determined by ==. | |
} else if (!util.isObject(actual) && !util.isObject(expected)) { | |
return actual == expected; | |
// 7.5 For all other Object pairs, including Array objects, equivalence is | |
// determined by having the same number of owned properties (as verified | |
// with Object.prototype.hasOwnProperty.call), the same set of keys | |
// (although not necessarily the same order), equivalent values for every | |
// corresponding key, and an identical 'prototype' property. Note: this | |
// accounts for both named and indexed properties on Arrays. | |
} else { | |
return objEquiv(actual, expected); | |
} | |
} | |
function isArguments(object) { | |
return Object.prototype.toString.call(object) == '[object Arguments]'; | |
} | |
function objEquiv(a, b) { | |
if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b)) | |
return false; | |
// an identical 'prototype' property. | |
if (a.prototype !== b.prototype) return false; | |
// if one is a primitive, the other must be same | |
if (util.isPrimitive(a) || util.isPrimitive(b)) { | |
return a === b; | |
} | |
var aIsArgs = isArguments(a), | |
bIsArgs = isArguments(b); | |
if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs)) | |
return false; | |
if (aIsArgs) { | |
a = pSlice.call(a); | |
b = pSlice.call(b); | |
return _deepEqual(a, b); | |
} | |
var ka = objectKeys(a), | |
kb = objectKeys(b), | |
key, i; | |
// having the same number of owned properties (keys incorporates | |
// hasOwnProperty) | |
if (ka.length != kb.length) | |
return false; | |
//the same set of keys (although not necessarily the same order), | |
ka.sort(); | |
kb.sort(); | |
//~~~cheap key test | |
for (i = ka.length - 1; i >= 0; i--) { | |
if (ka[i] != kb[i]) | |
return false; | |
} | |
//equivalent values for every corresponding key, and | |
//~~~possibly expensive deep test | |
for (i = ka.length - 1; i >= 0; i--) { | |
key = ka[i]; | |
if (!_deepEqual(a[key], b[key])) return false; | |
} | |
return true; | |
} | |
// 8. The non-equivalence assertion tests for any deep inequality. | |
// assert.notDeepEqual(actual, expected, message_opt); | |
assert.notDeepEqual = function notDeepEqual(actual, expected, message) { | |
if (_deepEqual(actual, expected)) { | |
fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); | |
} | |
}; | |
// 9. The strict equality assertion tests strict equality, as determined by ===. | |
// assert.strictEqual(actual, expected, message_opt); | |
assert.strictEqual = function strictEqual(actual, expected, message) { | |
if (actual !== expected) { | |
fail(actual, expected, message, '===', assert.strictEqual); | |
} | |
}; | |
// 10. The strict non-equality assertion tests for strict inequality, as | |
// determined by !==. assert.notStrictEqual(actual, expected, message_opt); | |
assert.notStrictEqual = function notStrictEqual(actual, expected, message) { | |
if (actual === expected) { | |
fail(actual, expected, message, '!==', assert.notStrictEqual); | |
} | |
}; | |
function expectedException(actual, expected) { | |
if (!actual || !expected) { | |
return false; | |
} | |
if (Object.prototype.toString.call(expected) == '[object RegExp]') { | |
return expected.test(actual); | |
} else if (actual instanceof expected) { | |
return true; | |
} else if (expected.call({}, actual) === true) { | |
return true; | |
} | |
return false; | |
} | |
function _throws(shouldThrow, block, expected, message) { | |
var actual; | |
if (util.isString(expected)) { | |
message = expected; | |
expected = null; | |
} | |
try { | |
block(); | |
} catch (e) { | |
actual = e; | |
} | |
message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + | |
(message ? ' ' + message : '.'); | |
if (shouldThrow && !actual) { | |
fail(actual, expected, 'Missing expected exception' + message); | |
} | |
if (!shouldThrow && expectedException(actual, expected)) { | |
fail(actual, expected, 'Got unwanted exception' + message); | |
} | |
if ((shouldThrow && actual && expected && | |
!expectedException(actual, expected)) || (!shouldThrow && actual)) { | |
throw actual; | |
} | |
} | |
// 11. Expected to throw an error: | |
// assert.throws(block, Error_opt, message_opt); | |
assert.throws = function(block, /*optional*/error, /*optional*/message) { | |
_throws.apply(this, [true].concat(pSlice.call(arguments))); | |
}; | |
// EXTENSION! This is annoying to write outside this module. | |
assert.doesNotThrow = function(block, /*optional*/message) { | |
_throws.apply(this, [false].concat(pSlice.call(arguments))); | |
}; | |
assert.ifError = function(err) { if (err) {throw err;}}; | |
var objectKeys = Object.keys || function (obj) { | |
var keys = []; | |
for (var key in obj) { | |
if (hasOwn.call(obj, key)) keys.push(key); | |
} | |
return keys; | |
}; | |
},{"13":13}],3:[function(_dereq_,module,exports){ | |
(function (global){ | |
/*! | |
* The buffer module from node.js, for the browser. | |
* | |
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> | |
* @license MIT | |
*/ | |
/* eslint-disable no-proto */ | |
var base64 = _dereq_(4) | |
var ieee754 = _dereq_(5) | |
var isArray = _dereq_(6) | |
exports.Buffer = Buffer | |
exports.SlowBuffer = SlowBuffer | |
exports.INSPECT_MAX_BYTES = 50 | |
Buffer.poolSize = 8192 // not used by this implementation | |
var rootParent = {} | |
/** | |
* If `Buffer.TYPED_ARRAY_SUPPORT`: | |
* === true Use Uint8Array implementation (fastest) | |
* === false Use Object implementation (most compatible, even IE6) | |
* | |
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, | |
* Opera 11.6+, iOS 4.2+. | |
* | |
* Due to various browser bugs, sometimes the Object implementation will be used even | |
* when the browser supports typed arrays. | |
* | |
* Note: | |
* | |
* - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, | |
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. | |
* | |
* - Safari 5-7 lacks support for changing the `Object.prototype.constructor` property | |
* on objects. | |
* | |
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. | |
* | |
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of | |
* incorrect length in some situations. | |
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they | |
* get the Object implementation, which is slower but behaves correctly. | |
*/ | |
Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined | |
? global.TYPED_ARRAY_SUPPORT | |
: typedArraySupport() | |
function typedArraySupport () { | |
function Bar () {} | |
try { | |
var arr = new Uint8Array(1) | |
arr.foo = function () { return 42 } | |
arr.constructor = Bar | |
return arr.foo() === 42 && // typed array instances can be augmented | |
arr.constructor === Bar && // constructor can be set | |
typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` | |
arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` | |
} catch (e) { | |
return false | |
} | |
} | |
function kMaxLength () { | |
return Buffer.TYPED_ARRAY_SUPPORT | |
? 0x7fffffff | |
: 0x3fffffff | |
} | |
/** | |
* Class: Buffer | |
* ============= | |
* | |
* The Buffer constructor returns instances of `Uint8Array` that are augmented | |
* with function properties for all the node `Buffer` API functions. We use | |
* `Uint8Array` so that square bracket notation works as expected -- it returns | |
* a single octet. | |
* | |
* By augmenting the instances, we can avoid modifying the `Uint8Array` | |
* prototype. | |
*/ | |
function Buffer (arg) { | |
if (!(this instanceof Buffer)) { | |
// Avoid going through an ArgumentsAdaptorTrampoline in the common case. | |
if (arguments.length > 1) return new Buffer(arg, arguments[1]) | |
return new Buffer(arg) | |
} | |
this.length = 0 | |
this.parent = undefined | |
// Common case. | |
if (typeof arg === 'number') { | |
return fromNumber(this, arg) | |
} | |
// Slightly less common case. | |
if (typeof arg === 'string') { | |
return fromString(this, arg, arguments.length > 1 ? arguments[1] : 'utf8') | |
} | |
// Unusual. | |
return fromObject(this, arg) | |
} | |
function fromNumber (that, length) { | |
that = allocate(that, length < 0 ? 0 : checked(length) | 0) | |
if (!Buffer.TYPED_ARRAY_SUPPORT) { | |
for (var i = 0; i < length; i++) { | |
that[i] = 0 | |
} | |
} | |
return that | |
} | |
function fromString (that, string, encoding) { | |
if (typeof encoding !== 'string' || encoding === '') encoding = 'utf8' | |
// Assumption: byteLength() return value is always < kMaxLength. | |
var length = byteLength(string, encoding) | 0 | |
that = allocate(that, length) | |
that.write(string, encoding) | |
return that | |
} | |
function fromObject (that, object) { | |
if (Buffer.isBuffer(object)) return fromBuffer(that, object) | |
if (isArray(object)) return fromArray(that, object) | |
if (object == null) { | |
throw new TypeError('must start with number, buffer, array or string') | |
} | |
if (typeof ArrayBuffer !== 'undefined') { | |
if (object.buffer instanceof ArrayBuffer) { | |
return fromTypedArray(that, object) | |
} | |
if (object instanceof ArrayBuffer) { | |
return fromArrayBuffer(that, object) | |
} | |
} | |
if (object.length) return fromArrayLike(that, object) | |
return fromJsonObject(that, object) | |
} | |
function fromBuffer (that, buffer) { | |
var length = checked(buffer.length) | 0 | |
that = allocate(that, length) | |
buffer.copy(that, 0, 0, length) | |
return that | |
} | |
function fromArray (that, array) { | |
var length = checked(array.length) | 0 | |
that = allocate(that, length) | |
for (var i = 0; i < length; i += 1) { | |
that[i] = array[i] & 255 | |
} | |
return that | |
} | |
// Duplicate of fromArray() to keep fromArray() monomorphic. | |
function fromTypedArray (that, array) { | |
var length = checked(array.length) | 0 | |
that = allocate(that, length) | |
// Truncating the elements is probably not what people expect from typed | |
// arrays with BYTES_PER_ELEMENT > 1 but it's compatible with the behavior | |
// of the old Buffer constructor. | |
for (var i = 0; i < length; i += 1) { | |
that[i] = array[i] & 255 | |
} | |
return that | |
} | |
function fromArrayBuffer (that, array) { | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
// Return an augmented `Uint8Array` instance, for best performance | |
array.byteLength | |
that = Buffer._augment(new Uint8Array(array)) | |
} else { | |
// Fallback: Return an object instance of the Buffer class | |
that = fromTypedArray(that, new Uint8Array(array)) | |
} | |
return that | |
} | |
function fromArrayLike (that, array) { | |
var length = checked(array.length) | 0 | |
that = allocate(that, length) | |
for (var i = 0; i < length; i += 1) { | |
that[i] = array[i] & 255 | |
} | |
return that | |
} | |
// Deserialize { type: 'Buffer', data: [1,2,3,...] } into a Buffer object. | |
// Returns a zero-length buffer for inputs that don't conform to the spec. | |
function fromJsonObject (that, object) { | |
var array | |
var length = 0 | |
if (object.type === 'Buffer' && isArray(object.data)) { | |
array = object.data | |
length = checked(array.length) | 0 | |
} | |
that = allocate(that, length) | |
for (var i = 0; i < length; i += 1) { | |
that[i] = array[i] & 255 | |
} | |
return that | |
} | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
Buffer.prototype.__proto__ = Uint8Array.prototype | |
Buffer.__proto__ = Uint8Array | |
} | |
function allocate (that, length) { | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
// Return an augmented `Uint8Array` instance, for best performance | |
that = Buffer._augment(new Uint8Array(length)) | |
that.__proto__ = Buffer.prototype | |
} else { | |
// Fallback: Return an object instance of the Buffer class | |
that.length = length | |
that._isBuffer = true | |
} | |
var fromPool = length !== 0 && length <= Buffer.poolSize >>> 1 | |
if (fromPool) that.parent = rootParent | |
return that | |
} | |
function checked (length) { | |
// Note: cannot use `length < kMaxLength` here because that fails when | |
// length is NaN (which is otherwise coerced to zero.) | |
if (length >= kMaxLength()) { | |
throw new RangeError('Attempt to allocate Buffer larger than maximum ' + | |
'size: 0x' + kMaxLength().toString(16) + ' bytes') | |
} | |
return length | 0 | |
} | |
function SlowBuffer (subject, encoding) { | |
if (!(this instanceof SlowBuffer)) return new SlowBuffer(subject, encoding) | |
var buf = new Buffer(subject, encoding) | |
delete buf.parent | |
return buf | |
} | |
Buffer.isBuffer = function isBuffer (b) { | |
return !!(b != null && b._isBuffer) | |
} | |
Buffer.compare = function compare (a, b) { | |
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { | |
throw new TypeError('Arguments must be Buffers') | |
} | |
if (a === b) return 0 | |
var x = a.length | |
var y = b.length | |
var i = 0 | |
var len = Math.min(x, y) | |
while (i < len) { | |
if (a[i] !== b[i]) break | |
++i | |
} | |
if (i !== len) { | |
x = a[i] | |
y = b[i] | |
} | |
if (x < y) return -1 | |
if (y < x) return 1 | |
return 0 | |
} | |
Buffer.isEncoding = function isEncoding (encoding) { | |
switch (String(encoding).toLowerCase()) { | |
case 'hex': | |
case 'utf8': | |
case 'utf-8': | |
case 'ascii': | |
case 'binary': | |
case 'base64': | |
case 'raw': | |
case 'ucs2': | |
case 'ucs-2': | |
case 'utf16le': | |
case 'utf-16le': | |
return true | |
default: | |
return false | |
} | |
} | |
Buffer.concat = function concat (list, length) { | |
if (!isArray(list)) throw new TypeError('list argument must be an Array of Buffers.') | |
if (list.length === 0) { | |
return new Buffer(0) | |
} | |
var i | |
if (length === undefined) { | |
length = 0 | |
for (i = 0; i < list.length; i++) { | |
length += list[i].length | |
} | |
} | |
var buf = new Buffer(length) | |
var pos = 0 | |
for (i = 0; i < list.length; i++) { | |
var item = list[i] | |
item.copy(buf, pos) | |
pos += item.length | |
} | |
return buf | |
} | |
function byteLength (string, encoding) { | |
if (typeof string !== 'string') string = '' + string | |
var len = string.length | |
if (len === 0) return 0 | |
// Use a for loop to avoid recursion | |
var loweredCase = false | |
for (;;) { | |
switch (encoding) { | |
case 'ascii': | |
case 'binary': | |
// Deprecated | |
case 'raw': | |
case 'raws': | |
return len | |
case 'utf8': | |
case 'utf-8': | |
return utf8ToBytes(string).length | |
case 'ucs2': | |
case 'ucs-2': | |
case 'utf16le': | |
case 'utf-16le': | |
return len * 2 | |
case 'hex': | |
return len >>> 1 | |
case 'base64': | |
return base64ToBytes(string).length | |
default: | |
if (loweredCase) return utf8ToBytes(string).length // assume utf8 | |
encoding = ('' + encoding).toLowerCase() | |
loweredCase = true | |
} | |
} | |
} | |
Buffer.byteLength = byteLength | |
// pre-set for values that may exist in the future | |
Buffer.prototype.length = undefined | |
Buffer.prototype.parent = undefined | |
function slowToString (encoding, start, end) { | |
var loweredCase = false | |
start = start | 0 | |
end = end === undefined || end === Infinity ? this.length : end | 0 | |
if (!encoding) encoding = 'utf8' | |
if (start < 0) start = 0 | |
if (end > this.length) end = this.length | |
if (end <= start) return '' | |
while (true) { | |
switch (encoding) { | |
case 'hex': | |
return hexSlice(this, start, end) | |
case 'utf8': | |
case 'utf-8': | |
return utf8Slice(this, start, end) | |
case 'ascii': | |
return asciiSlice(this, start, end) | |
case 'binary': | |
return binarySlice(this, start, end) | |
case 'base64': | |
return base64Slice(this, start, end) | |
case 'ucs2': | |
case 'ucs-2': | |
case 'utf16le': | |
case 'utf-16le': | |
return utf16leSlice(this, start, end) | |
default: | |
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) | |
encoding = (encoding + '').toLowerCase() | |
loweredCase = true | |
} | |
} | |
} | |
Buffer.prototype.toString = function toString () { | |
var length = this.length | 0 | |
if (length === 0) return '' | |
if (arguments.length === 0) return utf8Slice(this, 0, length) | |
return slowToString.apply(this, arguments) | |
} | |
Buffer.prototype.equals = function equals (b) { | |
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | |
if (this === b) return true | |
return Buffer.compare(this, b) === 0 | |
} | |
Buffer.prototype.inspect = function inspect () { | |
var str = '' | |
var max = exports.INSPECT_MAX_BYTES | |
if (this.length > 0) { | |
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') | |
if (this.length > max) str += ' ... ' | |
} | |
return '<Buffer ' + str + '>' | |
} | |
Buffer.prototype.compare = function compare (b) { | |
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | |
if (this === b) return 0 | |
return Buffer.compare(this, b) | |
} | |
Buffer.prototype.indexOf = function indexOf (val, byteOffset) { | |
if (byteOffset > 0x7fffffff) byteOffset = 0x7fffffff | |
else if (byteOffset < -0x80000000) byteOffset = -0x80000000 | |
byteOffset >>= 0 | |
if (this.length === 0) return -1 | |
if (byteOffset >= this.length) return -1 | |
// Negative offsets start from the end of the buffer | |
if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0) | |
if (typeof val === 'string') { | |
if (val.length === 0) return -1 // special case: looking for empty string always fails | |
return String.prototype.indexOf.call(this, val, byteOffset) | |
} | |
if (Buffer.isBuffer(val)) { | |
return arrayIndexOf(this, val, byteOffset) | |
} | |
if (typeof val === 'number') { | |
if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') { | |
return Uint8Array.prototype.indexOf.call(this, val, byteOffset) | |
} | |
return arrayIndexOf(this, [ val ], byteOffset) | |
} | |
function arrayIndexOf (arr, val, byteOffset) { | |
var foundIndex = -1 | |
for (var i = 0; byteOffset + i < arr.length; i++) { | |
if (arr[byteOffset + i] === val[foundIndex === -1 ? 0 : i - foundIndex]) { | |
if (foundIndex === -1) foundIndex = i | |
if (i - foundIndex + 1 === val.length) return byteOffset + foundIndex | |
} else { | |
foundIndex = -1 | |
} | |
} | |
return -1 | |
} | |
throw new TypeError('val must be string, number or Buffer') | |
} | |
// `get` is deprecated | |
Buffer.prototype.get = function get (offset) { | |
console.log('.get() is deprecated. Access using array indexes instead.') | |
return this.readUInt8(offset) | |
} | |
// `set` is deprecated | |
Buffer.prototype.set = function set (v, offset) { | |
console.log('.set() is deprecated. Access using array indexes instead.') | |
return this.writeUInt8(v, offset) | |
} | |
function hexWrite (buf, string, offset, length) { | |
offset = Number(offset) || 0 | |
var remaining = buf.length - offset | |
if (!length) { | |
length = remaining | |
} else { | |
length = Number(length) | |
if (length > remaining) { | |
length = remaining | |
} | |
} | |
// must be an even number of digits | |
var strLen = string.length | |
if (strLen % 2 !== 0) throw new Error('Invalid hex string') | |
if (length > strLen / 2) { | |
length = strLen / 2 | |
} | |
for (var i = 0; i < length; i++) { | |
var parsed = parseInt(string.substr(i * 2, 2), 16) | |
if (isNaN(parsed)) throw new Error('Invalid hex string') | |
buf[offset + i] = parsed | |
} | |
return i | |
} | |
function utf8Write (buf, string, offset, length) { | |
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) | |
} | |
function asciiWrite (buf, string, offset, length) { | |
return blitBuffer(asciiToBytes(string), buf, offset, length) | |
} | |
function binaryWrite (buf, string, offset, length) { | |
return asciiWrite(buf, string, offset, length) | |
} | |
function base64Write (buf, string, offset, length) { | |
return blitBuffer(base64ToBytes(string), buf, offset, length) | |
} | |
function ucs2Write (buf, string, offset, length) { | |
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) | |
} | |
Buffer.prototype.write = function write (string, offset, length, encoding) { | |
// Buffer#write(string) | |
if (offset === undefined) { | |
encoding = 'utf8' | |
length = this.length | |
offset = 0 | |
// Buffer#write(string, encoding) | |
} else if (length === undefined && typeof offset === 'string') { | |
encoding = offset | |
length = this.length | |
offset = 0 | |
// Buffer#write(string, offset[, length][, encoding]) | |
} else if (isFinite(offset)) { | |
offset = offset | 0 | |
if (isFinite(length)) { | |
length = length | 0 | |
if (encoding === undefined) encoding = 'utf8' | |
} else { | |
encoding = length | |
length = undefined | |
} | |
// legacy write(string, encoding, offset, length) - remove in v0.13 | |
} else { | |
var swap = encoding | |
encoding = offset | |
offset = length | 0 | |
length = swap | |
} | |
var remaining = this.length - offset | |
if (length === undefined || length > remaining) length = remaining | |
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { | |
throw new RangeError('attempt to write outside buffer bounds') | |
} | |
if (!encoding) encoding = 'utf8' | |
var loweredCase = false | |
for (;;) { | |
switch (encoding) { | |
case 'hex': | |
return hexWrite(this, string, offset, length) | |
case 'utf8': | |
case 'utf-8': | |
return utf8Write(this, string, offset, length) | |
case 'ascii': | |
return asciiWrite(this, string, offset, length) | |
case 'binary': | |
return binaryWrite(this, string, offset, length) | |
case 'base64': | |
// Warning: maxLength not taken into account in base64Write | |
return base64Write(this, string, offset, length) | |
case 'ucs2': | |
case 'ucs-2': | |
case 'utf16le': | |
case 'utf-16le': | |
return ucs2Write(this, string, offset, length) | |
default: | |
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) | |
encoding = ('' + encoding).toLowerCase() | |
loweredCase = true | |
} | |
} | |
} | |
Buffer.prototype.toJSON = function toJSON () { | |
return { | |
type: 'Buffer', | |
data: Array.prototype.slice.call(this._arr || this, 0) | |
} | |
} | |
function base64Slice (buf, start, end) { | |
if (start === 0 && end === buf.length) { | |
return base64.fromByteArray(buf) | |
} else { | |
return base64.fromByteArray(buf.slice(start, end)) | |
} | |
} | |
function utf8Slice (buf, start, end) { | |
end = Math.min(buf.length, end) | |
var res = [] | |
var i = start | |
while (i < end) { | |
var firstByte = buf[i] | |
var codePoint = null | |
var bytesPerSequence = (firstByte > 0xEF) ? 4 | |
: (firstByte > 0xDF) ? 3 | |
: (firstByte > 0xBF) ? 2 | |
: 1 | |
if (i + bytesPerSequence <= end) { | |
var secondByte, thirdByte, fourthByte, tempCodePoint | |
switch (bytesPerSequence) { | |
case 1: | |
if (firstByte < 0x80) { | |
codePoint = firstByte | |
} | |
break | |
case 2: | |
secondByte = buf[i + 1] | |
if ((secondByte & 0xC0) === 0x80) { | |
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) | |
if (tempCodePoint > 0x7F) { | |
codePoint = tempCodePoint | |
} | |
} | |
break | |
case 3: | |
secondByte = buf[i + 1] | |
thirdByte = buf[i + 2] | |
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { | |
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) | |
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { | |
codePoint = tempCodePoint | |
} | |
} | |
break | |
case 4: | |
secondByte = buf[i + 1] | |
thirdByte = buf[i + 2] | |
fourthByte = buf[i + 3] | |
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { | |
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) | |
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { | |
codePoint = tempCodePoint | |
} | |
} | |
} | |
} | |
if (codePoint === null) { | |
// we did not generate a valid codePoint so insert a | |
// replacement char (U+FFFD) and advance only 1 byte | |
codePoint = 0xFFFD | |
bytesPerSequence = 1 | |
} else if (codePoint > 0xFFFF) { | |
// encode to utf16 (surrogate pair dance) | |
codePoint -= 0x10000 | |
res.push(codePoint >>> 10 & 0x3FF | 0xD800) | |
codePoint = 0xDC00 | codePoint & 0x3FF | |
} | |
res.push(codePoint) | |
i += bytesPerSequence | |
} | |
return decodeCodePointsArray(res) | |
} | |
// Based on http://stackoverflow.com/a/22747272/680742, the browser with | |
// the lowest limit is Chrome, with 0x10000 args. | |
// We go 1 magnitude less, for safety | |
var MAX_ARGUMENTS_LENGTH = 0x1000 | |
function decodeCodePointsArray (codePoints) { | |
var len = codePoints.length | |
if (len <= MAX_ARGUMENTS_LENGTH) { | |
return String.fromCharCode.apply(String, codePoints) // avoid extra slice() | |
} | |
// Decode in chunks to avoid "call stack size exceeded". | |
var res = '' | |
var i = 0 | |
while (i < len) { | |
res += String.fromCharCode.apply( | |
String, | |
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) | |
) | |
} | |
return res | |
} | |
function asciiSlice (buf, start, end) { | |
var ret = '' | |
end = Math.min(buf.length, end) | |
for (var i = start; i < end; i++) { | |
ret += String.fromCharCode(buf[i] & 0x7F) | |
} | |
return ret | |
} | |
function binarySlice (buf, start, end) { | |
var ret = '' | |
end = Math.min(buf.length, end) | |
for (var i = start; i < end; i++) { | |
ret += String.fromCharCode(buf[i]) | |
} | |
return ret | |
} | |
function hexSlice (buf, start, end) { | |
var len = buf.length | |
if (!start || start < 0) start = 0 | |
if (!end || end < 0 || end > len) end = len | |
var out = '' | |
for (var i = start; i < end; i++) { | |
out += toHex(buf[i]) | |
} | |
return out | |
} | |
function utf16leSlice (buf, start, end) { | |
var bytes = buf.slice(start, end) | |
var res = '' | |
for (var i = 0; i < bytes.length; i += 2) { | |
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) | |
} | |
return res | |
} | |
Buffer.prototype.slice = function slice (start, end) { | |
var len = this.length | |
start = ~~start | |
end = end === undefined ? len : ~~end | |
if (start < 0) { | |
start += len | |
if (start < 0) start = 0 | |
} else if (start > len) { | |
start = len | |
} | |
if (end < 0) { | |
end += len | |
if (end < 0) end = 0 | |
} else if (end > len) { | |
end = len | |
} | |
if (end < start) end = start | |
var newBuf | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
newBuf = Buffer._augment(this.subarray(start, end)) | |
} else { | |
var sliceLen = end - start | |
newBuf = new Buffer(sliceLen, undefined) | |
for (var i = 0; i < sliceLen; i++) { | |
newBuf[i] = this[i + start] | |
} | |
} | |
if (newBuf.length) newBuf.parent = this.parent || this | |
return newBuf | |
} | |
/* | |
* Need to make sure that buffer isn't trying to write out of bounds. | |
*/ | |
function checkOffset (offset, ext, length) { | |
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') | |
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') | |
} | |
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { | |
offset = offset | 0 | |
byteLength = byteLength | 0 | |
if (!noAssert) checkOffset(offset, byteLength, this.length) | |
var val = this[offset] | |
var mul = 1 | |
var i = 0 | |
while (++i < byteLength && (mul *= 0x100)) { | |
val += this[offset + i] * mul | |
} | |
return val | |
} | |
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { | |
offset = offset | 0 | |
byteLength = byteLength | 0 | |
if (!noAssert) { | |
checkOffset(offset, byteLength, this.length) | |
} | |
var val = this[offset + --byteLength] | |
var mul = 1 | |
while (byteLength > 0 && (mul *= 0x100)) { | |
val += this[offset + --byteLength] * mul | |
} | |
return val | |
} | |
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 1, this.length) | |
return this[offset] | |
} | |
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 2, this.length) | |
return this[offset] | (this[offset + 1] << 8) | |
} | |
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 2, this.length) | |
return (this[offset] << 8) | this[offset + 1] | |
} | |
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 4, this.length) | |
return ((this[offset]) | | |
(this[offset + 1] << 8) | | |
(this[offset + 2] << 16)) + | |
(this[offset + 3] * 0x1000000) | |
} | |
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 4, this.length) | |
return (this[offset] * 0x1000000) + | |
((this[offset + 1] << 16) | | |
(this[offset + 2] << 8) | | |
this[offset + 3]) | |
} | |
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { | |
offset = offset | 0 | |
byteLength = byteLength | 0 | |
if (!noAssert) checkOffset(offset, byteLength, this.length) | |
var val = this[offset] | |
var mul = 1 | |
var i = 0 | |
while (++i < byteLength && (mul *= 0x100)) { | |
val += this[offset + i] * mul | |
} | |
mul *= 0x80 | |
if (val >= mul) val -= Math.pow(2, 8 * byteLength) | |
return val | |
} | |
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { | |
offset = offset | 0 | |
byteLength = byteLength | 0 | |
if (!noAssert) checkOffset(offset, byteLength, this.length) | |
var i = byteLength | |
var mul = 1 | |
var val = this[offset + --i] | |
while (i > 0 && (mul *= 0x100)) { | |
val += this[offset + --i] * mul | |
} | |
mul *= 0x80 | |
if (val >= mul) val -= Math.pow(2, 8 * byteLength) | |
return val | |
} | |
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 1, this.length) | |
if (!(this[offset] & 0x80)) return (this[offset]) | |
return ((0xff - this[offset] + 1) * -1) | |
} | |
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 2, this.length) | |
var val = this[offset] | (this[offset + 1] << 8) | |
return (val & 0x8000) ? val | 0xFFFF0000 : val | |
} | |
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 2, this.length) | |
var val = this[offset + 1] | (this[offset] << 8) | |
return (val & 0x8000) ? val | 0xFFFF0000 : val | |
} | |
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 4, this.length) | |
return (this[offset]) | | |
(this[offset + 1] << 8) | | |
(this[offset + 2] << 16) | | |
(this[offset + 3] << 24) | |
} | |
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 4, this.length) | |
return (this[offset] << 24) | | |
(this[offset + 1] << 16) | | |
(this[offset + 2] << 8) | | |
(this[offset + 3]) | |
} | |
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 4, this.length) | |
return ieee754.read(this, offset, true, 23, 4) | |
} | |
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 4, this.length) | |
return ieee754.read(this, offset, false, 23, 4) | |
} | |
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 8, this.length) | |
return ieee754.read(this, offset, true, 52, 8) | |
} | |
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { | |
if (!noAssert) checkOffset(offset, 8, this.length) | |
return ieee754.read(this, offset, false, 52, 8) | |
} | |
function checkInt (buf, value, offset, ext, max, min) { | |
if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance') | |
if (value > max || value < min) throw new RangeError('value is out of bounds') | |
if (offset + ext > buf.length) throw new RangeError('index out of range') | |
} | |
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { | |
value = +value | |
offset = offset | 0 | |
byteLength = byteLength | 0 | |
if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0) | |
var mul = 1 | |
var i = 0 | |
this[offset] = value & 0xFF | |
while (++i < byteLength && (mul *= 0x100)) { | |
this[offset + i] = (value / mul) & 0xFF | |
} | |
return offset + byteLength | |
} | |
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { | |
value = +value | |
offset = offset | 0 | |
byteLength = byteLength | 0 | |
if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0) | |
var i = byteLength - 1 | |
var mul = 1 | |
this[offset + i] = value & 0xFF | |
while (--i >= 0 && (mul *= 0x100)) { | |
this[offset + i] = (value / mul) & 0xFF | |
} | |
return offset + byteLength | |
} | |
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { | |
value = +value | |
offset = offset | 0 | |
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) | |
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) | |
this[offset] = (value & 0xff) | |
return offset + 1 | |
} | |
function objectWriteUInt16 (buf, value, offset, littleEndian) { | |
if (value < 0) value = 0xffff + value + 1 | |
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) { | |
buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> | |
(littleEndian ? i : 1 - i) * 8 | |
} | |
} | |
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { | |
value = +value | |
offset = offset | 0 | |
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset] = (value & 0xff) | |
this[offset + 1] = (value >>> 8) | |
} else { | |
objectWriteUInt16(this, value, offset, true) | |
} | |
return offset + 2 | |
} | |
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { | |
value = +value | |
offset = offset | 0 | |
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset] = (value >>> 8) | |
this[offset + 1] = (value & 0xff) | |
} else { | |
objectWriteUInt16(this, value, offset, false) | |
} | |
return offset + 2 | |
} | |
function objectWriteUInt32 (buf, value, offset, littleEndian) { | |
if (value < 0) value = 0xffffffff + value + 1 | |
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) { | |
buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff | |
} | |
} | |
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { | |
value = +value | |
offset = offset | 0 | |
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset + 3] = (value >>> 24) | |
this[offset + 2] = (value >>> 16) | |
this[offset + 1] = (value >>> 8) | |
this[offset] = (value & 0xff) | |
} else { | |
objectWriteUInt32(this, value, offset, true) | |
} | |
return offset + 4 | |
} | |
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { | |
value = +value | |
offset = offset | 0 | |
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset] = (value >>> 24) | |
this[offset + 1] = (value >>> 16) | |
this[offset + 2] = (value >>> 8) | |
this[offset + 3] = (value & 0xff) | |
} else { | |
objectWriteUInt32(this, value, offset, false) | |
} | |
return offset + 4 | |
} | |
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { | |
value = +value | |
offset = offset | 0 | |
if (!noAssert) { | |
var limit = Math.pow(2, 8 * byteLength - 1) | |
checkInt(this, value, offset, byteLength, limit - 1, -limit) | |
} | |
var i = 0 | |
var mul = 1 | |
var sub = value < 0 ? 1 : 0 | |
this[offset] = value & 0xFF | |
while (++i < byteLength && (mul *= 0x100)) { | |
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF | |
} | |
return offset + byteLength | |
} | |
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { | |
value = +value | |
offset = offset | 0 | |
if (!noAssert) { | |
var limit = Math.pow(2, 8 * byteLength - 1) | |
checkInt(this, value, offset, byteLength, limit - 1, -limit) | |
} | |
var i = byteLength - 1 | |
var mul = 1 | |
var sub = value < 0 ? 1 : 0 | |
this[offset + i] = value & 0xFF | |
while (--i >= 0 && (mul *= 0x100)) { | |
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF | |
} | |
return offset + byteLength | |
} | |
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { | |
value = +value | |
offset = offset | 0 | |
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) | |
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) | |
if (value < 0) value = 0xff + value + 1 | |
this[offset] = (value & 0xff) | |
return offset + 1 | |
} | |
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { | |
value = +value | |
offset = offset | 0 | |
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset] = (value & 0xff) | |
this[offset + 1] = (value >>> 8) | |
} else { | |
objectWriteUInt16(this, value, offset, true) | |
} | |
return offset + 2 | |
} | |
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { | |
value = +value | |
offset = offset | 0 | |
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset] = (value >>> 8) | |
this[offset + 1] = (value & 0xff) | |
} else { | |
objectWriteUInt16(this, value, offset, false) | |
} | |
return offset + 2 | |
} | |
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { | |
value = +value | |
offset = offset | 0 | |
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset] = (value & 0xff) | |
this[offset + 1] = (value >>> 8) | |
this[offset + 2] = (value >>> 16) | |
this[offset + 3] = (value >>> 24) | |
} else { | |
objectWriteUInt32(this, value, offset, true) | |
} | |
return offset + 4 | |
} | |
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { | |
value = +value | |
offset = offset | 0 | |
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) | |
if (value < 0) value = 0xffffffff + value + 1 | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
this[offset] = (value >>> 24) | |
this[offset + 1] = (value >>> 16) | |
this[offset + 2] = (value >>> 8) | |
this[offset + 3] = (value & 0xff) | |
} else { | |
objectWriteUInt32(this, value, offset, false) | |
} | |
return offset + 4 | |
} | |
function checkIEEE754 (buf, value, offset, ext, max, min) { | |
if (value > max || value < min) throw new RangeError('value is out of bounds') | |
if (offset + ext > buf.length) throw new RangeError('index out of range') | |
if (offset < 0) throw new RangeError('index out of range') | |
} | |
function writeFloat (buf, value, offset, littleEndian, noAssert) { | |
if (!noAssert) { | |
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) | |
} | |
ieee754.write(buf, value, offset, littleEndian, 23, 4) | |
return offset + 4 | |
} | |
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { | |
return writeFloat(this, value, offset, true, noAssert) | |
} | |
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { | |
return writeFloat(this, value, offset, false, noAssert) | |
} | |
function writeDouble (buf, value, offset, littleEndian, noAssert) { | |
if (!noAssert) { | |
checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) | |
} | |
ieee754.write(buf, value, offset, littleEndian, 52, 8) | |
return offset + 8 | |
} | |
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { | |
return writeDouble(this, value, offset, true, noAssert) | |
} | |
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { | |
return writeDouble(this, value, offset, false, noAssert) | |
} | |
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) | |
Buffer.prototype.copy = function copy (target, targetStart, start, end) { | |
if (!start) start = 0 | |
if (!end && end !== 0) end = this.length | |
if (targetStart >= target.length) targetStart = target.length | |
if (!targetStart) targetStart = 0 | |
if (end > 0 && end < start) end = start | |
// Copy 0 bytes; we're done | |
if (end === start) return 0 | |
if (target.length === 0 || this.length === 0) return 0 | |
// Fatal error conditions | |
if (targetStart < 0) { | |
throw new RangeError('targetStart out of bounds') | |
} | |
if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') | |
if (end < 0) throw new RangeError('sourceEnd out of bounds') | |
// Are we oob? | |
if (end > this.length) end = this.length | |
if (target.length - targetStart < end - start) { | |
end = target.length - targetStart + start | |
} | |
var len = end - start | |
var i | |
if (this === target && start < targetStart && targetStart < end) { | |
// descending copy from end | |
for (i = len - 1; i >= 0; i--) { | |
target[i + targetStart] = this[i + start] | |
} | |
} else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { | |
// ascending copy from start | |
for (i = 0; i < len; i++) { | |
target[i + targetStart] = this[i + start] | |
} | |
} else { | |
target._set(this.subarray(start, start + len), targetStart) | |
} | |
return len | |
} | |
// fill(value, start=0, end=buffer.length) | |
Buffer.prototype.fill = function fill (value, start, end) { | |
if (!value) value = 0 | |
if (!start) start = 0 | |
if (!end) end = this.length | |
if (end < start) throw new RangeError('end < start') | |
// Fill 0 bytes; we're done | |
if (end === start) return | |
if (this.length === 0) return | |
if (start < 0 || start >= this.length) throw new RangeError('start out of bounds') | |
if (end < 0 || end > this.length) throw new RangeError('end out of bounds') | |
var i | |
if (typeof value === 'number') { | |
for (i = start; i < end; i++) { | |
this[i] = value | |
} | |
} else { | |
var bytes = utf8ToBytes(value.toString()) | |
var len = bytes.length | |
for (i = start; i < end; i++) { | |
this[i] = bytes[i % len] | |
} | |
} | |
return this | |
} | |
/** | |
* Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance. | |
* Added in Node 0.12. Only available in browsers that support ArrayBuffer. | |
*/ | |
Buffer.prototype.toArrayBuffer = function toArrayBuffer () { | |
if (typeof Uint8Array !== 'undefined') { | |
if (Buffer.TYPED_ARRAY_SUPPORT) { | |
return (new Buffer(this)).buffer | |
} else { | |
var buf = new Uint8Array(this.length) | |
for (var i = 0, len = buf.length; i < len; i += 1) { | |
buf[i] = this[i] | |
} | |
return buf.buffer | |
} | |
} else { | |
throw new TypeError('Buffer.toArrayBuffer not supported in this browser') | |
} | |
} | |
// HELPER FUNCTIONS | |
// ================ | |
var BP = Buffer.prototype | |
/** | |
* Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods | |
*/ | |
Buffer._augment = function _augment (arr) { | |
arr.constructor = Buffer | |
arr._isBuffer = true | |
// save reference to original Uint8Array set method before overwriting | |
arr._set = arr.set | |
// deprecated | |
arr.get = BP.get | |
arr.set = BP.set | |
arr.write = BP.write | |
arr.toString = BP.toString | |
arr.toLocaleString = BP.toString | |
arr.toJSON = BP.toJSON | |
arr.equals = BP.equals | |
arr.compare = BP.compare | |
arr.indexOf = BP.indexOf | |
arr.copy = BP.copy | |
arr.slice = BP.slice | |
arr.readUIntLE = BP.readUIntLE | |
arr.readUIntBE = BP.readUIntBE | |
arr.readUInt8 = BP.readUInt8 | |
arr.readUInt16LE = BP.readUInt16LE | |
arr.readUInt16BE = BP.readUInt16BE | |
arr.readUInt32LE = BP.readUInt32LE | |
arr.readUInt32BE = BP.readUInt32BE | |
arr.readIntLE = BP.readIntLE | |
arr.readIntBE = BP.readIntBE | |
arr.readInt8 = BP.readInt8 | |
arr.readInt16LE = BP.readInt16LE | |
arr.readInt16BE = BP.readInt16BE | |
arr.readInt32LE = BP.readInt32LE | |
arr.readInt32BE = BP.readInt32BE | |
arr.readFloatLE = BP.readFloatLE | |
arr.readFloatBE = BP.readFloatBE | |
arr.readDoubleLE = BP.readDoubleLE | |
arr.readDoubleBE = BP.readDoubleBE | |
arr.writeUInt8 = BP.writeUInt8 | |
arr.writeUIntLE = BP.writeUIntLE | |
arr.writeUIntBE = BP.writeUIntBE | |
arr.writeUInt16LE = BP.writeUInt16LE | |
arr.writeUInt16BE = BP.writeUInt16BE | |
arr.writeUInt32LE = BP.writeUInt32LE | |
arr.writeUInt32BE = BP.writeUInt32BE | |
arr.writeIntLE = BP.writeIntLE | |
arr.writeIntBE = BP.writeIntBE | |
arr.writeInt8 = BP.writeInt8 | |
arr.writeInt16LE = BP.writeInt16LE | |
arr.writeInt16BE = BP.writeInt16BE | |
arr.writeInt32LE = BP.writeInt32LE | |
arr.writeInt32BE = BP.writeInt32BE | |
arr.writeFloatLE = BP.writeFloatLE | |
arr.writeFloatBE = BP.writeFloatBE | |
arr.writeDoubleLE = BP.writeDoubleLE | |
arr.writeDoubleBE = BP.writeDoubleBE | |
arr.fill = BP.fill | |
arr.inspect = BP.inspect | |
arr.toArrayBuffer = BP.toArrayBuffer | |
return arr | |
} | |
var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g | |
function base64clean (str) { | |
// Node strips out invalid characters like \n and \t from the string, base64-js does not | |
str = stringtrim(str).replace(INVALID_BASE64_RE, '') | |
// Node converts strings with length < 2 to '' | |
if (str.length < 2) return '' | |
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not | |
while (str.length % 4 !== 0) { | |
str = str + '=' | |
} | |
return str | |
} | |
function stringtrim (str) { | |
if (str.trim) return str.trim() | |
return str.replace(/^\s+|\s+$/g, '') | |
} | |
function toHex (n) { | |
if (n < 16) return '0' + n.toString(16) | |
return n.toString(16) | |
} | |
function utf8ToBytes (string, units) { | |
units = units || Infinity | |
var codePoint | |
var length = string.length | |
var leadSurrogate = null | |
var bytes = [] | |
for (var i = 0; i < length; i++) { | |
codePoint = string.charCodeAt(i) | |
// is surrogate component | |
if (codePoint > 0xD7FF && codePoint < 0xE000) { | |
// last char was a lead | |
if (!leadSurrogate) { | |
// no lead yet | |
if (codePoint > 0xDBFF) { | |
// unexpected trail | |
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | |
continue | |
} else if (i + 1 === length) { | |
// unpaired lead | |
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | |
continue | |
} | |
// valid lead | |
leadSurrogate = codePoint | |
continue | |
} | |
// 2 leads in a row | |
if (codePoint < 0xDC00) { | |
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | |
leadSurrogate = codePoint | |
continue | |
} | |
// valid surrogate pair | |
codePoint = leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00 | 0x10000 | |
} else if (leadSurrogate) { | |
// valid bmp char, but last char was a lead | |
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | |
} | |
leadSurrogate = null | |
// encode utf8 | |
if (codePoint < 0x80) { | |
if ((units -= 1) < 0) break | |
bytes.push(codePoint) | |
} else if (codePoint < 0x800) { | |
if ((units -= 2) < 0) break | |
bytes.push( | |
codePoint >> 0x6 | 0xC0, | |
codePoint & 0x3F | 0x80 | |
) | |
} else if (codePoint < 0x10000) { | |
if ((units -= 3) < 0) break | |
bytes.push( | |
codePoint >> 0xC | 0xE0, | |
codePoint >> 0x6 & 0x3F | 0x80, | |
codePoint & 0x3F | 0x80 | |
) | |
} else if (codePoint < 0x110000) { | |
if ((units -= 4) < 0) break | |
bytes.push( | |
codePoint >> 0x12 | 0xF0, | |
codePoint >> 0xC & 0x3F | 0x80, | |
codePoint >> 0x6 & 0x3F | 0x80, | |
codePoint & 0x3F | 0x80 | |
) | |
} else { | |
throw new Error('Invalid code point') | |
} | |
} | |
return bytes | |
} | |
function asciiToBytes (str) { | |
var byteArray = [] | |
for (var i = 0; i < str.length; i++) { | |
// Node's code seems to be doing this and not & 0x7F.. | |
byteArray.push(str.charCodeAt(i) & 0xFF) | |
} | |
return byteArray | |
} | |
function utf16leToBytes (str, units) { | |
var c, hi, lo | |
var byteArray = [] | |
for (var i = 0; i < str.length; i++) { | |
if ((units -= 2) < 0) break | |
c = str.charCodeAt(i) | |
hi = c >> 8 | |
lo = c % 256 | |
byteArray.push(lo) | |
byteArray.push(hi) | |
} | |
return byteArray | |
} | |
function base64ToBytes (str) { | |
return base64.toByteArray(base64clean(str)) | |
} | |
function blitBuffer (src, dst, offset, length) { | |
for (var i = 0; i < length; i++) { | |
if ((i + offset >= dst.length) || (i >= src.length)) break | |
dst[i + offset] = src[i] | |
} | |
return i | |
} | |
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | |
},{"4":4,"5":5,"6":6}],4:[function(_dereq_,module,exports){ | |
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | |
;(function (exports) { | |
'use strict'; | |
var Arr = (typeof Uint8Array !== 'undefined') | |
? Uint8Array | |
: Array | |
var PLUS = '+'.charCodeAt(0) | |
var SLASH = '/'.charCodeAt(0) | |
var NUMBER = '0'.charCodeAt(0) | |
var LOWER = 'a'.charCodeAt(0) | |
var UPPER = 'A'.charCodeAt(0) | |
var PLUS_URL_SAFE = '-'.charCodeAt(0) | |
var SLASH_URL_SAFE = '_'.charCodeAt(0) | |
function decode (elt) { | |
var code = elt.charCodeAt(0) | |
if (code === PLUS || | |
code === PLUS_URL_SAFE) | |
return 62 // '+' | |
if (code === SLASH || | |
code === SLASH_URL_SAFE) | |
return 63 // '/' | |
if (code < NUMBER) | |
return -1 //no match | |
if (code < NUMBER + 10) | |
return code - NUMBER + 26 + 26 | |
if (code < UPPER + 26) | |
return code - UPPER | |
if (code < LOWER + 26) | |
return code - LOWER + 26 | |
} | |
function b64ToByteArray (b64) { | |
var i, j, l, tmp, placeHolders, arr | |
if (b64.length % 4 > 0) { | |
throw new Error('Invalid string. Length must be a multiple of 4') | |
} | |
// the number of equal signs (place holders) | |
// if there are two placeholders, than the two characters before it | |
// represent one byte | |
// if there is only one, then the three characters before it represent 2 bytes | |
// this is just a cheap hack to not do indexOf twice | |
var len = b64.length | |
placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 | |
// base64 is 4/3 + up to two characters of the original data | |
arr = new Arr(b64.length * 3 / 4 - placeHolders) | |
// if there are placeholders, only get up to the last complete 4 chars | |
l = placeHolders > 0 ? b64.length - 4 : b64.length | |
var L = 0 | |
function push (v) { | |
arr[L++] = v | |
} | |
for (i = 0, j = 0; i < l; i += 4, j += 3) { | |
tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) | |
push((tmp & 0xFF0000) >> 16) | |
push((tmp & 0xFF00) >> 8) | |
push(tmp & 0xFF) | |
} | |
if (placeHolders === 2) { | |
tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) | |
push(tmp & 0xFF) | |
} else if (placeHolders === 1) { | |
tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) | |
push((tmp >> 8) & 0xFF) | |
push(tmp & 0xFF) | |
} | |
return arr | |
} | |
function uint8ToBase64 (uint8) { | |
var i, | |
extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes | |
output = "", | |
temp, length | |
function encode (num) { | |
return lookup.charAt(num) | |
} | |
function tripletToBase64 (num) { | |
return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) | |
} | |
// go through the array every three bytes, we'll deal with trailing stuff later | |
for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { | |
temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) | |
output += tripletToBase64(temp) | |
} | |
// pad the end with zeros, but make sure to not forget the extra bytes | |
switch (extraBytes) { | |
case 1: | |
temp = uint8[uint8.length - 1] | |
output += encode(temp >> 2) | |
output += encode((temp << 4) & 0x3F) | |
output += '==' | |
break | |
case 2: | |
temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) | |
output += encode(temp >> 10) | |
output += encode((temp >> 4) & 0x3F) | |
output += encode((temp << 2) & 0x3F) | |
output += '=' | |
break | |
} | |
return output | |
} | |
exports.toByteArray = b64ToByteArray | |
exports.fromByteArray = uint8ToBase64 | |
}(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) | |
},{}],5:[function(_dereq_,module,exports){ | |
exports.read = function (buffer, offset, isLE, mLen, nBytes) { | |
var e, m | |
var eLen = nBytes * 8 - mLen - 1 | |
var eMax = (1 << eLen) - 1 | |
var eBias = eMax >> 1 | |
var nBits = -7 | |
var i = isLE ? (nBytes - 1) : 0 | |
var d = isLE ? -1 : 1 | |
var s = buffer[offset + i] | |
i += d | |
e = s & ((1 << (-nBits)) - 1) | |
s >>= (-nBits) | |
nBits += eLen | |
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} | |
m = e & ((1 << (-nBits)) - 1) | |
e >>= (-nBits) | |
nBits += mLen | |
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} | |
if (e === 0) { | |
e = 1 - eBias | |
} else if (e === eMax) { | |
return m ? NaN : ((s ? -1 : 1) * Infinity) | |
} else { | |
m = m + Math.pow(2, mLen) | |
e = e - eBias | |
} | |
return (s ? -1 : 1) * m * Math.pow(2, e - mLen) | |
} | |
exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { | |
var e, m, c | |
var eLen = nBytes * 8 - mLen - 1 | |
var eMax = (1 << eLen) - 1 | |
var eBias = eMax >> 1 | |
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) | |
var i = isLE ? 0 : (nBytes - 1) | |
var d = isLE ? 1 : -1 | |
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 | |
value = Math.abs(value) | |
if (isNaN(value) || value === Infinity) { | |
m = isNaN(value) ? 1 : 0 | |
e = eMax | |
} else { | |
e = Math.floor(Math.log(value) / Math.LN2) | |
if (value * (c = Math.pow(2, -e)) < 1) { | |
e-- | |
c *= 2 | |
} | |
if (e + eBias >= 1) { | |
value += rt / c | |
} else { | |
value += rt * Math.pow(2, 1 - eBias) | |
} | |
if (value * c >= 2) { | |
e++ | |
c /= 2 | |
} | |
if (e + eBias >= eMax) { | |
m = 0 | |
e = eMax | |
} else if (e + eBias >= 1) { | |
m = (value * c - 1) * Math.pow(2, mLen) | |
e = e + eBias | |
} else { | |
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) | |
e = 0 | |
} | |
} | |
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} | |
e = (e << mLen) | m | |
eLen += mLen | |
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} | |
buffer[offset + i - d] |= s * 128 | |
} | |
},{}],6:[function(_dereq_,module,exports){ | |
/** | |
* isArray | |
*/ | |
var isArray = Array.isArray; | |
/** | |
* toString | |
*/ | |
var str = Object.prototype.toString; | |
/** | |
* Whether or not the given `val` | |
* is an array. | |
* | |
* example: | |
* | |
* isArray([]); | |
* // > true | |
* isArray(arguments); | |
* // > false | |
* isArray(''); | |
* // > false | |
* | |
* @param {mixed} val | |
* @return {bool} | |
*/ | |
module.exports = isArray || function (val) { | |
return !! val && '[object Array]' == str.call(val); | |
}; | |
},{}],7:[function(_dereq_,module,exports){ | |
if (typeof Object.create === 'function') { | |
// implementation from standard node.js 'util' module | |
module.exports = function inherits(ctor, superCtor) { | |
ctor.super_ = superCtor | |
ctor.prototype = Object.create(superCtor.prototype, { | |
constructor: { | |
value: ctor, | |
enumerable: false, | |
writable: true, | |
configurable: true | |
} | |
}); | |
}; | |
} else { | |
// old school shim for old browsers | |
module.exports = function inherits(ctor, superCtor) { | |
ctor.super_ = superCtor | |
var TempCtor = function () {} | |
TempCtor.prototype = superCtor.prototype | |
ctor.prototype = new TempCtor() | |
ctor.prototype.constructor = ctor | |
} | |
} | |
},{}],8:[function(_dereq_,module,exports){ | |
exports.endianness = function () { return 'LE' }; | |
exports.hostname = function () { | |
if (typeof location !== 'undefined') { | |
return location.hostname | |
} | |
else return ''; | |
}; | |
exports.loadavg = function () { return [] }; | |
exports.uptime = function () { return 0 }; | |
exports.freemem = function () { | |
return Number.MAX_VALUE; | |
}; | |
exports.totalmem = function () { | |
return Number.MAX_VALUE; | |
}; | |
exports.cpus = function () { return [] }; | |
exports.type = function () { return 'Browser' }; | |
exports.release = function () { | |
if (typeof navigator !== 'undefined') { | |
return navigator.appVersion; | |
} | |
return ''; | |
}; | |
exports.networkInterfaces | |
= exports.getNetworkInterfaces | |
= function () { return {} }; | |
exports.arch = function () { return 'javascript' }; | |
exports.platform = function () { return 'browser' }; | |
exports.tmpdir = exports.tmpDir = function () { | |
return '/tmp'; | |
}; | |
exports.EOL = '\n'; | |
},{}],9:[function(_dereq_,module,exports){ | |
(function (process){ | |
// Copyright Joyent, Inc. and other Node contributors. | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a | |
// copy of this software and associated documentation files (the | |
// "Software"), to deal in the Software without restriction, including | |
// without limitation the rights to use, copy, modify, merge, publish, | |
// distribute, sublicense, and/or sell copies of the Software, and to permit | |
// persons to whom the Software is furnished to do so, subject to the | |
// following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included | |
// in all copies or substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | |
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | |
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | |
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | |
// USE OR OTHER DEALINGS IN THE SOFTWARE. | |
// resolves . and .. elements in a path array with directory names there | |
// must be no slashes, empty elements, or device names (c:\) in the array | |
// (so also no leading and trailing slashes - it does not distinguish | |
// relative and absolute paths) | |
function normalizeArray(parts, allowAboveRoot) { | |
// if the path tries to go above the root, `up` ends up > 0 | |
var up = 0; | |
for (var i = parts.length - 1; i >= 0; i--) { | |
var last = parts[i]; | |
if (last === '.') { | |
parts.splice(i, 1); | |
} else if (last === '..') { | |
parts.splice(i, 1); | |
up++; | |
} else if (up) { | |
parts.splice(i, 1); | |
up--; | |
} | |
} | |
// if the path is allowed to go above the root, restore leading ..s | |
if (allowAboveRoot) { | |
for (; up--; up) { | |
parts.unshift('..'); | |
} | |
} | |
return parts; | |
} | |
// Split a filename into [root, dir, basename, ext], unix version | |
// 'root' is just a slash, or nothing. | |
var splitPathRe = | |
/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/; | |
var splitPath = function(filename) { | |
return splitPathRe.exec(filename).slice(1); | |
}; | |
// path.resolve([from ...], to) | |
// posix version | |
exports.resolve = function() { | |
var resolvedPath = '', | |
resolvedAbsolute = false; | |
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { | |
var path = (i >= 0) ? arguments[i] : process.cwd(); | |
// Skip empty and invalid entries | |
if (typeof path !== 'string') { | |
throw new TypeError('Arguments to path.resolve must be strings'); | |
} else if (!path) { | |
continue; | |
} | |
resolvedPath = path + '/' + resolvedPath; | |
resolvedAbsolute = path.charAt(0) === '/'; | |
} | |
// At this point the path should be resolved to a full absolute path, but | |
// handle relative paths to be safe (might happen when process.cwd() fails) | |
// Normalize the path | |
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { | |
return !!p; | |
}), !resolvedAbsolute).join('/'); | |
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; | |
}; | |
// path.normalize(path) | |
// posix version | |
exports.normalize = function(path) { | |
var isAbsolute = exports.isAbsolute(path), | |
trailingSlash = substr(path, -1) === '/'; | |
// Normalize the path | |
path = normalizeArray(filter(path.split('/'), function(p) { | |
return !!p; | |
}), !isAbsolute).join('/'); | |
if (!path && !isAbsolute) { | |
path = '.'; | |
} | |
if (path && trailingSlash) { | |
path += '/'; | |
} | |
return (isAbsolute ? '/' : '') + path; | |
}; | |
// posix version | |
exports.isAbsolute = function(path) { | |
return path.charAt(0) === '/'; | |
}; | |
// posix version | |
exports.join = function() { | |
var paths = Array.prototype.slice.call(arguments, 0); | |
return exports.normalize(filter(paths, function(p, index) { | |
if (typeof p !== 'string') { | |
throw new TypeError('Arguments to path.join must be strings'); | |
} | |
return p; | |
}).join('/')); | |
}; | |
// path.relative(from, to) | |
// posix version | |
exports.relative = function(from, to) { | |
from = exports.resolve(from).substr(1); | |
to = exports.resolve(to).substr(1); | |
function trim(arr) { | |
var start = 0; | |
for (; start < arr.length; start++) { | |
if (arr[start] !== '') break; | |
} | |
var end = arr.length - 1; | |
for (; end >= 0; end--) { | |
if (arr[end] !== '') break; | |
} | |
if (start > end) return []; | |
return arr.slice(start, end - start + 1); | |
} | |
var fromParts = trim(from.split('/')); | |
var toParts = trim(to.split('/')); | |
var length = Math.min(fromParts.length, toParts.length); | |
var samePartsLength = length; | |
for (var i = 0; i < length; i++) { | |
if (fromParts[i] !== toParts[i]) { | |
samePartsLength = i; | |
break; | |
} | |
} | |
var outputParts = []; | |
for (var i = samePartsLength; i < fromParts.length; i++) { | |
outputParts.push('..'); | |
} | |
outputParts = outputParts.concat(toParts.slice(samePartsLength)); | |
return outputParts.join('/'); | |
}; | |
exports.sep = '/'; | |
exports.delimiter = ':'; | |
exports.dirname = function(path) { | |
var result = splitPath(path), | |
root = result[0], | |
dir = result[1]; | |
if (!root && !dir) { | |
// No dirname whatsoever | |
return '.'; | |
} | |
if (dir) { | |
// It has a dirname, strip trailing slash | |
dir = dir.substr(0, dir.length - 1); | |
} | |
return root + dir; | |
}; | |
exports.basename = function(path, ext) { | |
var f = splitPath(path)[2]; | |
// TODO: make this comparison case-insensitive on windows? | |
if (ext && f.substr(-1 * ext.length) === ext) { | |
f = f.substr(0, f.length - ext.length); | |
} | |
return f; | |
}; | |
exports.extname = function(path) { | |
return splitPath(path)[3]; | |
}; | |
function filter (xs, f) { | |
if (xs.filter) return xs.filter(f); | |
var res = []; | |
for (var i = 0; i < xs.length; i++) { | |
if (f(xs[i], i, xs)) res.push(xs[i]); | |
} | |
return res; | |
} | |
// String.prototype.substr - negative index don't work in IE8 | |
var substr = 'ab'.substr(-1) === 'b' | |
? function (str, start, len) { return str.substr(start, len) } | |
: function (str, start, len) { | |
if (start < 0) start = str.length + start; | |
return str.substr(start, len); | |
} | |
; | |
}).call(this,_dereq_(10)) | |
},{"10":10}],10:[function(_dereq_,module,exports){ | |
// shim for using process in browser | |
var process = module.exports = {}; | |
var queue = []; | |
var draining = false; | |
var currentQueue; | |
var queueIndex = -1; | |
function cleanUpNextTick() { | |
draining = false; | |
if (currentQueue.length) { | |
queue = currentQueue.concat(queue); | |
} else { | |
queueIndex = -1; | |
} | |
if (queue.length) { | |
drainQueue(); | |
} | |
} | |
function drainQueue() { | |
if (draining) { | |
return; | |
} | |
var timeout = setTimeout(cleanUpNextTick); | |
draining = true; | |
var len = queue.length; | |
while(len) { | |
currentQueue = queue; | |
queue = []; | |
while (++queueIndex < len) { | |
if (currentQueue) { | |
currentQueue[queueIndex].run(); | |
} | |
} | |
queueIndex = -1; | |
len = queue.length; | |
} | |
currentQueue = null; | |
draining = false; | |
clearTimeout(timeout); | |
} | |
process.nextTick = function (fun) { | |
var args = new Array(arguments.length - 1); | |
if (arguments.length > 1) { | |
for (var i = 1; i < arguments.length; i++) { | |
args[i - 1] = arguments[i]; | |
} | |
} | |
queue.push(new Item(fun, args)); | |
if (queue.length === 1 && !draining) { | |
setTimeout(drainQueue, 0); | |
} | |
}; | |
// v8 likes predictible objects | |
function Item(fun, array) { | |
this.fun = fun; | |
this.array = array; | |
} | |
Item.prototype.run = function () { | |
this.fun.apply(null, this.array); | |
}; | |
process.title = 'browser'; | |
process.browser = true; | |
process.env = {}; | |
process.argv = []; | |
process.version = ''; // empty string to avoid regexp issues | |
process.versions = {}; | |
function noop() {} | |
process.on = noop; | |
process.addListener = noop; | |
process.once = noop; | |
process.off = noop; | |
process.removeListener = noop; | |
process.removeAllListeners = noop; | |
process.emit = noop; | |
process.binding = function (name) { | |
throw new Error('process.binding is not supported'); | |
}; | |
process.cwd = function () { return '/' }; | |
process.chdir = function (dir) { | |
throw new Error('process.chdir is not supported'); | |
}; | |
process.umask = function() { return 0; }; | |
},{}],11:[function(_dereq_,module,exports){ | |
exports.isatty = function () { return false; }; | |
function ReadStream() { | |
throw new Error('tty.ReadStream is not implemented'); | |
} | |
exports.ReadStream = ReadStream; | |
function WriteStream() { | |
throw new Error('tty.ReadStream is not implemented'); | |
} | |
exports.WriteStream = WriteStream; | |
},{}],12:[function(_dereq_,module,exports){ | |
module.exports = function isBuffer(arg) { | |
return arg && typeof arg === 'object' | |
&& typeof arg.copy === 'function' | |
&& typeof arg.fill === 'function' | |
&& typeof arg.readUInt8 === 'function'; | |
} | |
},{}],13:[function(_dereq_,module,exports){ | |
(function (process,global){ | |
// Copyright Joyent, Inc. and other Node contributors. | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a | |
// copy of this software and associated documentation files (the | |
// "Software"), to deal in the Software without restriction, including | |
// without limitation the rights to use, copy, modify, merge, publish, | |
// distribute, sublicense, and/or sell copies of the Software, and to permit | |
// persons to whom the Software is furnished to do so, subject to the | |
// following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included | |
// in all copies or substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | |
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | |
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | |
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | |
// USE OR OTHER DEALINGS IN THE SOFTWARE. | |
var formatRegExp = /%[sdj%]/g; | |
exports.format = function(f) { | |
if (!isString(f)) { | |
var objects = []; | |
for (var i = 0; i < arguments.length; i++) { | |
objects.push(inspect(arguments[i])); | |
} | |
return objects.join(' '); | |
} | |
var i = 1; | |
var args = arguments; | |
var len = args.length; | |
var str = String(f).replace(formatRegExp, function(x) { | |
if (x === '%%') return '%'; | |
if (i >= len) return x; | |
switch (x) { | |
case '%s': return String(args[i++]); | |
case '%d': return Number(args[i++]); | |
case '%j': | |
try { | |
return JSON.stringify(args[i++]); | |
} catch (_) { | |
return '[Circular]'; | |
} | |
default: | |
return x; | |
} | |
}); | |
for (var x = args[i]; i < len; x = args[++i]) { | |
if (isNull(x) || !isObject(x)) { | |
str += ' ' + x; | |
} else { | |
str += ' ' + inspect(x); | |
} | |
} | |
return str; | |
}; | |
// Mark that a method should not be used. | |
// Returns a modified function which warns once by default. | |
// If --no-deprecation is set, then it is a no-op. | |
exports.deprecate = function(fn, msg) { | |
// Allow for deprecating things in the process of starting up. | |
if (isUndefined(global.process)) { | |
return function() { | |
return exports.deprecate(fn, msg).apply(this, arguments); | |
}; | |
} | |
if (process.noDeprecation === true) { | |
return fn; | |
} | |
var warned = false; | |
function deprecated() { | |
if (!warned) { | |
if (process.throwDeprecation) { | |
throw new Error(msg); | |
} else if (process.traceDeprecation) { | |
console.trace(msg); | |
} else { | |
console.error(msg); | |
} | |
warned = true; | |
} | |
return fn.apply(this, arguments); | |
} | |
return deprecated; | |
}; | |
var debugs = {}; | |
var debugEnviron; | |
exports.debuglog = function(set) { | |
if (isUndefined(debugEnviron)) | |
debugEnviron = process.env.NODE_DEBUG || ''; | |
set = set.toUpperCase(); | |
if (!debugs[set]) { | |
if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { | |
var pid = process.pid; | |
debugs[set] = function() { | |
var msg = exports.format.apply(exports, arguments); | |
console.error('%s %d: %s', set, pid, msg); | |
}; | |
} else { | |
debugs[set] = function() {}; | |
} | |
} | |
return debugs[set]; | |
}; | |
/** | |
* Echos the value of a value. Trys to print the value out | |
* in the best way possible given the different types. | |
* | |
* @param {Object} obj The object to print out. | |
* @param {Object} opts Optional options object that alters the output. | |
*/ | |
/* legacy: obj, showHidden, depth, colors*/ | |
function inspect(obj, opts) { | |
// default options | |
var ctx = { | |
seen: [], | |
stylize: stylizeNoColor | |
}; | |
// legacy... | |
if (arguments.length >= 3) ctx.depth = arguments[2]; | |
if (arguments.length >= 4) ctx.colors = arguments[3]; | |
if (isBoolean(opts)) { | |
// legacy... | |
ctx.showHidden = opts; | |
} else if (opts) { | |
// got an "options" object | |
exports._extend(ctx, opts); | |
} | |
// set default options | |
if (isUndefined(ctx.showHidden)) ctx.showHidden = false; | |
if (isUndefined(ctx.depth)) ctx.depth = 2; | |
if (isUndefined(ctx.colors)) ctx.colors = false; | |
if (isUndefined(ctx.customInspect)) ctx.customInspect = true; | |
if (ctx.colors) ctx.stylize = stylizeWithColor; | |
return formatValue(ctx, obj, ctx.depth); | |
} | |
exports.inspect = inspect; | |
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics | |
inspect.colors = { | |
'bold' : [1, 22], | |
'italic' : [3, 23], | |
'underline' : [4, 24], | |
'inverse' : [7, 27], | |
'white' : [37, 39], | |
'grey' : [90, 39], | |
'black' : [30, 39], | |
'blue' : [34, 39], | |
'cyan' : [36, 39], | |
'green' : [32, 39], | |
'magenta' : [35, 39], | |
'red' : [31, 39], | |
'yellow' : [33, 39] | |
}; | |
// Don't use 'blue' not visible on cmd.exe | |
inspect.styles = { | |
'special': 'cyan', | |
'number': 'yellow', | |
'boolean': 'yellow', | |
'undefined': 'grey', | |
'null': 'bold', | |
'string': 'green', | |
'date': 'magenta', | |
// "name": intentionally not styling | |
'regexp': 'red' | |
}; | |
function stylizeWithColor(str, styleType) { | |
var style = inspect.styles[styleType]; | |
if (style) { | |
return '\u001b[' + inspect.colors[style][0] + 'm' + str + | |
'\u001b[' + inspect.colors[style][1] + 'm'; | |
} else { | |
return str; | |
} | |
} | |
function stylizeNoColor(str, styleType) { | |
return str; | |
} | |
function arrayToHash(array) { | |
var hash = {}; | |
array.forEach(function(val, idx) { | |
hash[val] = true; | |
}); | |
return hash; | |
} | |
function formatValue(ctx, value, recurseTimes) { | |
// Provide a hook for user-specified inspect functions. | |
// Check that value is an object with an inspect function on it | |
if (ctx.customInspect && | |
value && | |
isFunction(value.inspect) && | |
// Filter out the util module, it's inspect function is special | |
value.inspect !== exports.inspect && | |
// Also filter out any prototype objects using the circular check. | |
!(value.constructor && value.constructor.prototype === value)) { | |
var ret = value.inspect(recurseTimes, ctx); | |
if (!isString(ret)) { | |
ret = formatValue(ctx, ret, recurseTimes); | |
} | |
return ret; | |
} | |
// Primitive types cannot have properties | |
var primitive = formatPrimitive(ctx, value); | |
if (primitive) { | |
return primitive; | |
} | |
// Look up the keys of the object. | |
var keys = Object.keys(value); | |
var visibleKeys = arrayToHash(keys); | |
if (ctx.showHidden) { | |
keys = Object.getOwnPropertyNames(value); | |
} | |
// IE doesn't make error fields non-enumerable | |
// http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx | |
if (isError(value) | |
&& (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { | |
return formatError(value); | |
} | |
// Some type of object without properties can be shortcutted. | |
if (keys.length === 0) { | |
if (isFunction(value)) { | |
var name = value.name ? ': ' + value.name : ''; | |
return ctx.stylize('[Function' + name + ']', 'special'); | |
} | |
if (isRegExp(value)) { | |
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); | |
} | |
if (isDate(value)) { | |
return ctx.stylize(Date.prototype.toString.call(value), 'date'); | |
} | |
if (isError(value)) { | |
return formatError(value); | |
} | |
} | |
var base = '', array = false, braces = ['{', '}']; | |
// Make Array say that they are Array | |
if (isArray(value)) { | |
array = true; | |
braces = ['[', ']']; | |
} | |
// Make functions say that they are functions | |
if (isFunction(value)) { | |
var n = value.name ? ': ' + value.name : ''; | |
base = ' [Function' + n + ']'; | |
} | |
// Make RegExps say that they are RegExps | |
if (isRegExp(value)) { | |
base = ' ' + RegExp.prototype.toString.call(value); | |
} | |
// Make dates with properties first say the date | |
if (isDate(value)) { | |
base = ' ' + Date.prototype.toUTCString.call(value); | |
} | |
// Make error with message first say the error | |
if (isError(value)) { | |
base = ' ' + formatError(value); | |
} | |
if (keys.length === 0 && (!array || value.length == 0)) { | |
return braces[0] + base + braces[1]; | |
} | |
if (recurseTimes < 0) { | |
if (isRegExp(value)) { | |
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); | |
} else { | |
return ctx.stylize('[Object]', 'special'); | |
} | |
} | |
ctx.seen.push(value); | |
var output; | |
if (array) { | |
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); | |
} else { | |
output = keys.map(function(key) { | |
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); | |
}); | |
} | |
ctx.seen.pop(); | |
return reduceToSingleString(output, base, braces); | |
} | |
function formatPrimitive(ctx, value) { | |
if (isUndefined(value)) | |
return ctx.stylize('undefined', 'undefined'); | |
if (isString(value)) { | |
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') | |
.replace(/'/g, "\\'") | |
.replace(/\\"/g, '"') + '\''; | |
return ctx.stylize(simple, 'string'); | |
} | |
if (isNumber(value)) | |
return ctx.stylize('' + value, 'number'); | |
if (isBoolean(value)) | |
return ctx.stylize('' + value, 'boolean'); | |
// For some reason typeof null is "object", so special case here. | |
if (isNull(value)) | |
return ctx.stylize('null', 'null'); | |
} | |
function formatError(value) { | |
return '[' + Error.prototype.toString.call(value) + ']'; | |
} | |
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { | |
var output = []; | |
for (var i = 0, l = value.length; i < l; ++i) { | |
if (hasOwnProperty(value, String(i))) { | |
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, | |
String(i), true)); | |
} else { | |
output.push(''); | |
} | |
} | |
keys.forEach(function(key) { | |
if (!key.match(/^\d+$/)) { | |
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, | |
key, true)); | |
} | |
}); | |
return output; | |
} | |
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { | |
var name, str, desc; | |
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; | |
if (desc.get) { | |
if (desc.set) { | |
str = ctx.stylize('[Getter/Setter]', 'special'); | |
} else { | |
str = ctx.stylize('[Getter]', 'special'); | |
} | |
} else { | |
if (desc.set) { | |
str = ctx.stylize('[Setter]', 'special'); | |
} | |
} | |
if (!hasOwnProperty(visibleKeys, key)) { | |
name = '[' + key + ']'; | |
} | |
if (!str) { | |
if (ctx.seen.indexOf(desc.value) < 0) { | |
if (isNull(recurseTimes)) { | |
str = formatValue(ctx, desc.value, null); | |
} else { | |
str = formatValue(ctx, desc.value, recurseTimes - 1); | |
} | |
if (str.indexOf('\n') > -1) { | |
if (array) { | |
str = str.split('\n').map(function(line) { | |
return ' ' + line; | |
}).join('\n').substr(2); | |
} else { | |
str = '\n' + str.split('\n').map(function(line) { | |
return ' ' + line; | |
}).join('\n'); | |
} | |
} | |
} else { | |
str = ctx.stylize('[Circular]', 'special'); | |
} | |
} | |
if (isUndefined(name)) { | |
if (array && key.match(/^\d+$/)) { | |
return str; | |
} | |
name = JSON.stringify('' + key); | |
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { | |
name = name.substr(1, name.length - 2); | |
name = ctx.stylize(name, 'name'); | |
} else { | |
name = name.replace(/'/g, "\\'") | |
.replace(/\\"/g, '"') | |
.replace(/(^"|"$)/g, "'"); | |
name = ctx.stylize(name, 'string'); | |
} | |
} | |
return name + ': ' + str; | |
} | |
function reduceToSingleString(output, base, braces) { | |
var numLinesEst = 0; | |
var length = output.reduce(function(prev, cur) { | |
numLinesEst++; | |
if (cur.indexOf('\n') >= 0) numLinesEst++; | |
return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; | |
}, 0); | |
if (length > 60) { | |
return braces[0] + | |
(base === '' ? '' : base + '\n ') + | |
' ' + | |
output.join(',\n ') + | |
' ' + | |
braces[1]; | |
} | |
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; | |
} | |
// NOTE: These type checking functions intentionally don't use `instanceof` | |
// because it is fragile and can be easily faked with `Object.create()`. | |
function isArray(ar) { | |
return Array.isArray(ar); | |
} | |
exports.isArray = isArray; | |
function isBoolean(arg) { | |
return typeof arg === 'boolean'; | |
} | |
exports.isBoolean = isBoolean; | |
function isNull(arg) { | |
return arg === null; | |
} | |
exports.isNull = isNull; | |
function isNullOrUndefined(arg) { | |
return arg == null; | |
} | |
exports.isNullOrUndefined = isNullOrUndefined; | |
function isNumber(arg) { | |
return typeof arg === 'number'; | |
} | |
exports.isNumber = isNumber; | |
function isString(arg) { | |
return typeof arg === 'string'; | |
} | |
exports.isString = isString; | |
function isSymbol(arg) { | |
return typeof arg === 'symbol'; | |
} | |
exports.isSymbol = isSymbol; | |
function isUndefined(arg) { | |
return arg === void 0; | |
} | |
exports.isUndefined = isUndefined; | |
function isRegExp(re) { | |
return isObject(re) && objectToString(re) === '[object RegExp]'; | |
} | |
exports.isRegExp = isRegExp; | |
function isObject(arg) { | |
return typeof arg === 'object' && arg !== null; | |
} | |
exports.isObject = isObject; | |
function isDate(d) { | |
return isObject(d) && objectToString(d) === '[object Date]'; | |
} | |
exports.isDate = isDate; | |
function isError(e) { | |
return isObject(e) && | |
(objectToString(e) === '[object Error]' || e instanceof Error); | |
} | |
exports.isError = isError; | |
function isFunction(arg) { | |
return typeof arg === 'function'; | |
} | |
exports.isFunction = isFunction; | |
function isPrimitive(arg) { | |
return arg === null || | |
typeof arg === 'boolean' || | |
typeof arg === 'number' || | |
typeof arg === 'string' || | |
typeof arg === 'symbol' || // ES6 symbol | |
typeof arg === 'undefined'; | |
} | |
exports.isPrimitive = isPrimitive; | |
exports.isBuffer = _dereq_(12); | |
function objectToString(o) { | |
return Object.prototype.toString.call(o); | |
} | |
function pad(n) { | |
return n < 10 ? '0' + n.toString(10) : n.toString(10); | |
} | |
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', | |
'Oct', 'Nov', 'Dec']; | |
// 26 Feb 16:19:34 | |
function timestamp() { | |
var d = new Date(); | |
var time = [pad(d.getHours()), | |
pad(d.getMinutes()), | |
pad(d.getSeconds())].join(':'); | |
return [d.getDate(), months[d.getMonth()], time].join(' '); | |
} | |
// log is just a thin wrapper to console.log that prepends a timestamp | |
exports.log = function() { | |
console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); | |
}; | |
/** | |
* Inherit the prototype methods from one constructor into another. | |
* | |
* The Function.prototype.inherits from lang.js rewritten as a standalone | |
* function (not on Function.prototype). NOTE: If this file is to be loaded | |
* during bootstrapping this function needs to be rewritten using some native | |
* functions as prototype setup using normal JavaScript does not work as | |
* expected during bootstrapping (see mirror.js in r114903). | |
* | |
* @param {function} ctor Constructor function which needs to inherit the | |
* prototype. | |
* @param {function} superCtor Constructor function to inherit prototype from. | |
*/ | |
exports.inherits = _dereq_(7); | |
exports._extend = function(origin, add) { | |
// Don't do anything if add isn't an object | |
if (!add || !isObject(add)) return origin; | |
var keys = Object.keys(add); | |
var i = keys.length; | |
while (i--) { | |
origin[keys[i]] = add[keys[i]]; | |
} | |
return origin; | |
}; | |
function hasOwnProperty(obj, prop) { | |
return Object.prototype.hasOwnProperty.call(obj, prop); | |
} | |
}).call(this,_dereq_(10),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | |
},{"10":10,"12":12,"7":7}],14:[function(_dereq_,module,exports){ | |
(function (global){ | |
/* eslint no-new-func: 0 */ | |
"use strict"; | |
_dereq_(15); | |
var transform = module.exports = _dereq_(66); | |
/** | |
* Add `options` and `version` to `babel` global. | |
*/ | |
transform.options = _dereq_(49); | |
transform.version = _dereq_(603).version; | |
/** | |
* Add `transform` api to `babel` global. | |
*/ | |
transform.transform = transform; | |
/** | |
* Tranform and execute script, adding in inline sourcemaps. | |
*/ | |
transform.run = function (code) { | |
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | |
opts.sourceMaps = "inline"; | |
return new Function(transform(code, opts).code)(); | |
}; | |
/** | |
* Load scripts via xhr, and `transform` when complete (optional). | |
*/ | |
transform.load = function (url, callback, opts, hold) { | |
if (opts === undefined) opts = {}; | |
opts.filename = opts.filename || url; | |
var xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest(); | |
xhr.open("GET", url, true); | |
if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain"); | |
/** | |
* When successfully loaded, transform (optional), and call `callback`. | |
*/ | |
xhr.onreadystatechange = function () { | |
if (xhr.readyState !== 4) return; | |
var status = xhr.status; | |
if (status === 0 || status === 200) { | |
var param = [xhr.responseText, opts]; | |
if (!hold) transform.run.apply(transform, param); | |
if (callback) callback(param); | |
} else { | |
throw new Error("Could not load " + url); | |
} | |
}; | |
xhr.send(null); | |
}; | |
/** | |
* Load and transform all scripts of `types`. | |
* | |
* @example | |
* <script type="module"></script> | |
*/ | |
var runScripts = function runScripts() { | |
var scripts = []; | |
var types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"]; | |
var index = 0; | |
/** | |
* Transform and execute script. Ensures correct load order. | |
*/ | |
var exec = function exec() { | |
var param = scripts[index]; | |
if (param instanceof Array) { | |
transform.run.apply(transform, param); | |
index++; | |
exec(); | |
} | |
}; | |
/** | |
* Load, transform, and execute all scripts. | |
*/ | |
var run = function run(script, i) { | |
var opts = {}; | |
if (script.src) { | |
transform.load(script.src, function (param) { | |
scripts[i] = param; | |
exec(); | |
}, opts, true); | |
} else { | |
opts.filename = "embedded"; | |
scripts[i] = [script.innerHTML, opts]; | |
} | |
}; | |
// Collect scripts with Babel `types`. | |
var _scripts = global.document.getElementsByTagName("script"); | |
for (var i = 0; i < _scripts.length; ++i) { | |
var _script = _scripts[i]; | |
if (types.indexOf(_script.type) >= 0) scripts.push(_script); | |
} | |
for (i in scripts) { | |
run(scripts[i], i); | |
} | |
exec(); | |
}; | |
/** | |
* Register load event to transform and execute scripts. | |
*/ | |
if (global.addEventListener) { | |
global.addEventListener("DOMContentLoaded", runScripts, false); | |
} else if (global.attachEvent) { | |
global.attachEvent("onload", runScripts); | |
} | |
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | |
},{"15":15,"49":49,"603":603,"66":66}],15:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.register = register; | |
exports.polyfill = polyfill; | |
exports.transformFile = transformFile; | |
exports.transformFileSync = transformFileSync; | |
exports.parse = parse; | |
// istanbul ignore next | |
function _interopRequire(obj) { return obj && obj.__esModule ? obj["default"] : obj; } | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _lodashLangIsFunction = _dereq_(500); | |
var _lodashLangIsFunction2 = _interopRequireDefault(_lodashLangIsFunction); | |
var _transformation = _dereq_(66); | |
var _transformation2 = _interopRequireDefault(_transformation); | |
var _babylon = _dereq_(605); | |
var babylon = _interopRequireWildcard(_babylon); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _fs = _dereq_(1); | |
var _fs2 = _interopRequireDefault(_fs); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
exports.util = util; | |
exports.acorn = babylon; | |
exports.transform = _transformation2["default"]; | |
exports.pipeline = _transformation.pipeline; | |
exports.canCompile = _util.canCompile; | |
var _transformationFile = _dereq_(46); | |
exports.File = _interopRequire(_transformationFile); | |
var _transformationFileOptionsConfig = _dereq_(48); | |
exports.options = _interopRequire(_transformationFileOptionsConfig); | |
var _transformationPlugin = _dereq_(82); | |
exports.Plugin = _interopRequire(_transformationPlugin); | |
var _transformationTransformer = _dereq_(83); | |
exports.Transformer = _interopRequire(_transformationTransformer); | |
var _transformationPipeline = _dereq_(80); | |
exports.Pipeline = _interopRequire(_transformationPipeline); | |
var _traversal = _dereq_(148); | |
exports.traverse = _interopRequire(_traversal); | |
var _toolsBuildExternalHelpers = _dereq_(45); | |
exports.buildExternalHelpers = _interopRequire(_toolsBuildExternalHelpers); | |
var _package = _dereq_(603); | |
exports.version = _package.version; | |
exports.types = t; | |
/** | |
* Register Babel and polyfill globally. | |
*/ | |
function register(opts) { | |
var callback = _dereq_(17); | |
if (opts != null) callback(opts); | |
return callback; | |
} | |
/** | |
* Register polyfill globally. | |
*/ | |
function polyfill() { | |
_dereq_(44); | |
} | |
/** | |
* Asynchronously transform `filename` with optional `opts`, calls `callback` when complete. | |
*/ | |
function transformFile(filename, opts, callback) { | |
if (_lodashLangIsFunction2["default"](opts)) { | |
callback = opts; | |
opts = {}; | |
} | |
opts.filename = filename; | |
_fs2["default"].readFile(filename, function (err, code) { | |
if (err) return callback(err); | |
var result; | |
try { | |
result = _transformation2["default"](code, opts); | |
} catch (err) { | |
return callback(err); | |
} | |
callback(null, result); | |
}); | |
} | |
/** | |
* Synchronous form of `transformFile`. | |
*/ | |
function transformFileSync(filename) { | |
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | |
opts.filename = filename; | |
return _transformation2["default"](_fs2["default"].readFileSync(filename, "utf8"), opts); | |
} | |
/** | |
* Parse script with Babel's parser. | |
*/ | |
function parse(code) { | |
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | |
opts.allowHashBang = true; | |
opts.sourceType = "module"; | |
opts.ecmaVersion = Infinity; | |
opts.plugins = { | |
jsx: true, | |
flow: true | |
}; | |
opts.features = {}; | |
for (var key in _transformation2["default"].pipeline.transformers) { | |
opts.features[key] = true; | |
} | |
var ast = babylon.parse(code, opts); | |
if (opts.onToken) { | |
// istanbul ignore next | |
var _opts$onToken; | |
(_opts$onToken = opts.onToken).push.apply(_opts$onToken, ast.tokens); | |
} | |
if (opts.onComment) { | |
// istanbul ignore next | |
var _opts$onComment; | |
(_opts$onComment = opts.onComment).push.apply(_opts$onComment, ast.comments); | |
} | |
return ast.program; | |
} | |
},{"1":1,"148":148,"17":17,"179":179,"182":182,"44":44,"45":45,"46":46,"48":48,"500":500,"603":603,"605":605,"66":66,"80":80,"82":82,"83":83}],16:[function(_dereq_,module,exports){ | |
// required to safely use babel/register within a browserify codebase | |
"use strict"; | |
exports.__esModule = true; | |
_dereq_(44); | |
exports["default"] = function () {}; | |
module.exports = exports["default"]; | |
},{"44":44}],17:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequire(obj) { return obj && obj.__esModule ? obj["default"] : obj; } | |
_dereq_(44); | |
var _node = _dereq_(16); | |
exports["default"] = _interopRequire(_node); | |
module.exports = exports["default"]; | |
},{"16":16,"44":44}],18:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _repeating = _dereq_(584); | |
var _repeating2 = _interopRequireDefault(_repeating); | |
var _trimRight = _dereq_(601); | |
var _trimRight2 = _interopRequireDefault(_trimRight); | |
var _lodashLangIsBoolean = _dereq_(498); | |
var _lodashLangIsBoolean2 = _interopRequireDefault(_lodashLangIsBoolean); | |
var _lodashCollectionIncludes = _dereq_(413); | |
var _lodashCollectionIncludes2 = _interopRequireDefault(_lodashCollectionIncludes); | |
var _lodashLangIsNumber = _dereq_(502); | |
var _lodashLangIsNumber2 = _interopRequireDefault(_lodashLangIsNumber); | |
/** | |
* Buffer for collecting generated output. | |
*/ | |
var Buffer = (function () { | |
function Buffer(position, format) { | |
_classCallCheck(this, Buffer); | |
this.parenPushNewlineState = null; | |
this.position = position; | |
this._indent = format.indent.base; | |
this.format = format; | |
this.buf = ""; | |
} | |
/** | |
* Get the current trimmed buffer. | |
*/ | |
Buffer.prototype.get = function get() { | |
return _trimRight2["default"](this.buf); | |
}; | |
/** | |
* Get the current indent. | |
*/ | |
Buffer.prototype.getIndent = function getIndent() { | |
if (this.format.compact || this.format.concise) { | |
return ""; | |
} else { | |
return _repeating2["default"](this.format.indent.style, this._indent); | |
} | |
}; | |
/** | |
* Get the current indent size. | |
*/ | |
Buffer.prototype.indentSize = function indentSize() { | |
return this.getIndent().length; | |
}; | |
/** | |
* Increment indent size. | |
*/ | |
Buffer.prototype.indent = function indent() { | |
this._indent++; | |
}; | |
/** | |
* Decrement indent size. | |
*/ | |
Buffer.prototype.dedent = function dedent() { | |
this._indent--; | |
}; | |
/** | |
* Add a semicolon to the buffer. | |
*/ | |
Buffer.prototype.semicolon = function semicolon() { | |
this.push(";"); | |
}; | |
/** | |
* Ensure last character is a semicolon. | |
*/ | |
Buffer.prototype.ensureSemicolon = function ensureSemicolon() { | |
if (!this.isLast(";")) this.semicolon(); | |
}; | |
/** | |
* Add a right brace to the buffer. | |
*/ | |
Buffer.prototype.rightBrace = function rightBrace() { | |
this.newline(true); | |
this.push("}"); | |
}; | |
/** | |
* Add a keyword to the buffer. | |
*/ | |
Buffer.prototype.keyword = function keyword(name) { | |
this.push(name); | |
this.space(); | |
}; | |
/** | |
* Add a space to the buffer unless it is compact (override with force). | |
*/ | |
Buffer.prototype.space = function space(force) { | |
if (!force && this.format.compact) return; | |
if (force || this.buf && !this.isLast(" ") && !this.isLast("\n")) { | |
this.push(" "); | |
} | |
}; | |
/** | |
* Remove the last character. | |
*/ | |
Buffer.prototype.removeLast = function removeLast(cha) { | |
if (this.format.compact) return; | |
if (!this.isLast(cha)) return; | |
this.buf = this.buf.substr(0, this.buf.length - 1); | |
this.position.unshift(cha); | |
}; | |
/** | |
* Set some state that will be modified if a newline has been inserted before any | |
* non-space characters. | |
* | |
* This is to prevent breaking semantics for terminatorless separator nodes. eg: | |
* | |
* return foo; | |
* | |
* returns `foo`. But if we do: | |
* | |
* return | |
* foo; | |
* | |
* `undefined` will be returned and not `foo` due to the terminator. | |
*/ | |
Buffer.prototype.startTerminatorless = function startTerminatorless() { | |
return this.parenPushNewlineState = { | |
printed: false | |
}; | |
}; | |
/** | |
* Print an ending parentheses if a starting one has been printed. | |
*/ | |
Buffer.prototype.endTerminatorless = function endTerminatorless(state) { | |
if (state.printed) { | |
this.dedent(); | |
this.newline(); | |
this.push(")"); | |
} | |
}; | |
/** | |
* Add a newline (or many newlines), maintaining formatting. | |
* Strips multiple newlines if removeLast is true. | |
*/ | |
Buffer.prototype.newline = function newline(i, removeLast) { | |
if (this.format.compact || this.format.retainLines) return; | |
if (this.format.concise) { | |
this.space(); | |
return; | |
} | |
removeLast = removeLast || false; | |
if (_lodashLangIsNumber2["default"](i)) { | |
i = Math.min(2, i); | |
if (this.endsWith("{\n") || this.endsWith(":\n")) i--; | |
if (i <= 0) return; | |
while (i > 0) { | |
this._newline(removeLast); | |
i--; | |
} | |
return; | |
} | |
if (_lodashLangIsBoolean2["default"](i)) { | |
removeLast = i; | |
} | |
this._newline(removeLast); | |
}; | |
/** | |
* Adds a newline unless there is already two previous newlines. | |
*/ | |
Buffer.prototype._newline = function _newline(removeLast) { | |
// never allow more than two lines | |
if (this.endsWith("\n\n")) return; | |
// remove the last newline | |
if (removeLast && this.isLast("\n")) this.removeLast("\n"); | |
this.removeLast(" "); | |
this._removeSpacesAfterLastNewline(); | |
this._push("\n"); | |
}; | |
/** | |
* If buffer ends with a newline and some spaces after it, trim those spaces. | |
*/ | |
Buffer.prototype._removeSpacesAfterLastNewline = function _removeSpacesAfterLastNewline() { | |
var lastNewlineIndex = this.buf.lastIndexOf("\n"); | |
if (lastNewlineIndex === -1) { | |
return; | |
} | |
var index = this.buf.length - 1; | |
while (index > lastNewlineIndex) { | |
if (this.buf[index] !== " ") { | |
break; | |
} | |
index--; | |
} | |
if (index === lastNewlineIndex) { | |
this.buf = this.buf.substring(0, index + 1); | |
} | |
}; | |
/** | |
* Push a string to the buffer, maintaining indentation and newlines. | |
*/ | |
Buffer.prototype.push = function push(str, noIndent) { | |
if (!this.format.compact && this._indent && !noIndent && str !== "\n") { | |
// we have an indent level and we aren't pushing a newline | |
var indent = this.getIndent(); | |
// replace all newlines with newlines with the indentation | |
str = str.replace(/\n/g, "\n" + indent); | |
// we've got a newline before us so prepend on the indentation | |
if (this.isLast("\n")) this._push(indent); | |
} | |
this._push(str); | |
}; | |
/** | |
* Push a string to the buffer. | |
*/ | |
Buffer.prototype._push = function _push(str) { | |
// see startTerminatorless() instance method | |
var parenPushNewlineState = this.parenPushNewlineState; | |
if (parenPushNewlineState) { | |
for (var i = 0; i < str.length; i++) { | |
var cha = str[i]; | |
// we can ignore spaces since they wont interupt a terminatorless separator | |
if (cha === " ") continue; | |
this.parenPushNewlineState = null; | |
if (cha === "\n" || cha === "/") { | |
// we're going to break this terminator expression so we need to add a parentheses | |
this._push("("); | |
this.indent(); | |
parenPushNewlineState.printed = true; | |
} | |
break; | |
} | |
} | |
// | |
this.position.push(str); | |
this.buf += str; | |
}; | |
/** | |
* Test if the buffer ends with a string. | |
*/ | |
Buffer.prototype.endsWith = function endsWith(str) { | |
var buf = arguments.length <= 1 || arguments[1] === undefined ? this.buf : arguments[1]; | |
if (str.length === 1) { | |
return buf[buf.length - 1] === str; | |
} else { | |
return buf.slice(-str.length) === str; | |
} | |
}; | |
/** | |
* Test if a character is last in the buffer. | |
*/ | |
Buffer.prototype.isLast = function isLast(cha) { | |
if (this.format.compact) return false; | |
var buf = this.buf; | |
var last = buf[buf.length - 1]; | |
if (Array.isArray(cha)) { | |
return _lodashCollectionIncludes2["default"](cha, last); | |
} else { | |
return cha === last; | |
} | |
}; | |
return Buffer; | |
})(); | |
exports["default"] = Buffer; | |
module.exports = exports["default"]; | |
},{"413":413,"498":498,"502":502,"584":584,"601":601}],19:[function(_dereq_,module,exports){ | |
/** | |
* Print File.program | |
*/ | |
"use strict"; | |
exports.__esModule = true; | |
exports.File = File; | |
exports.Program = Program; | |
exports.BlockStatement = BlockStatement; | |
exports.Noop = Noop; | |
function File(node, print) { | |
print.plain(node.program); | |
} | |
/** | |
* Print all nodes in a Program.body. | |
*/ | |
function Program(node, print) { | |
print.sequence(node.body); | |
} | |
/** | |
* Print BlockStatement, collapses empty blocks, prints body. | |
*/ | |
function BlockStatement(node, print) { | |
this.push("{"); | |
if (node.body.length) { | |
this.newline(); | |
print.sequence(node.body, { indent: true }); | |
if (!this.format.retainLines) this.removeLast("\n"); | |
this.rightBrace(); | |
} else { | |
print.printInnerComments(); | |
this.push("}"); | |
} | |
} | |
/** | |
* What is my purpose? | |
* Why am I here? | |
* Why are any of us here? | |
* Does any of this really matter? | |
*/ | |
function Noop() {} | |
},{}],20:[function(_dereq_,module,exports){ | |
/** | |
* Print ClassDeclaration, prints decorators, typeParameters, extends, implements, and body. | |
*/ | |
"use strict"; | |
exports.__esModule = true; | |
exports.ClassDeclaration = ClassDeclaration; | |
exports.ClassBody = ClassBody; | |
exports.ClassProperty = ClassProperty; | |
exports.MethodDefinition = MethodDefinition; | |
function ClassDeclaration(node, print) { | |
print.list(node.decorators, { separator: "" }); | |
this.push("class"); | |
if (node.id) { | |
this.push(" "); | |
print.plain(node.id); | |
} | |
print.plain(node.typeParameters); | |
if (node.superClass) { | |
this.push(" extends "); | |
print.plain(node.superClass); | |
print.plain(node.superTypeParameters); | |
} | |
if (node["implements"]) { | |
this.push(" implements "); | |
print.join(node["implements"], { separator: ", " }); | |
} | |
this.space(); | |
print.plain(node.body); | |
} | |
/** | |
* Alias ClassDeclaration printer as ClassExpression. | |
*/ | |
exports.ClassExpression = ClassDeclaration; | |
/** | |
* Print ClassBody, collapses empty blocks, prints body. | |
*/ | |
function ClassBody(node, print) { | |
this.push("{"); | |
if (node.body.length === 0) { | |
print.printInnerComments(); | |
this.push("}"); | |
} else { | |
this.newline(); | |
this.indent(); | |
print.sequence(node.body); | |
this.dedent(); | |
this.rightBrace(); | |
} | |
} | |
/** | |
* Print ClassProperty, prints decorators, static, key, typeAnnotation, and value. | |
* Also: semicolons, deal with it. | |
*/ | |
function ClassProperty(node, print) { | |
print.list(node.decorators, { separator: "" }); | |
if (node["static"]) this.push("static "); | |
print.plain(node.key); | |
print.plain(node.typeAnnotation); | |
if (node.value) { | |
this.space(); | |
this.push("="); | |
this.space(); | |
print.plain(node.value); | |
} | |
this.semicolon(); | |
} | |
/** | |
* Print MethodDefinition, prints decorations, static, and method. | |
*/ | |
function MethodDefinition(node, print) { | |
print.list(node.decorators, { separator: "" }); | |
if (node["static"]) { | |
this.push("static "); | |
} | |
this._method(node, print); | |
} | |
},{}],21:[function(_dereq_,module,exports){ | |
/** | |
* Prints ComprehensionBlock, prints left and right. | |
*/ | |
"use strict"; | |
exports.__esModule = true; | |
exports.ComprehensionBlock = ComprehensionBlock; | |
exports.ComprehensionExpression = ComprehensionExpression; | |
function ComprehensionBlock(node, print) { | |
this.keyword("for"); | |
this.push("("); | |
print.plain(node.left); | |
this.push(" of "); | |
print.plain(node.right); | |
this.push(")"); | |
} | |
/** | |
* Prints ComprehensionExpression, prints blocks, filter, and body. Handles generators. | |
*/ | |
function ComprehensionExpression(node, print) { | |
this.push(node.generator ? "(" : "["); | |
print.join(node.blocks, { separator: " " }); | |
this.space(); | |
if (node.filter) { | |
this.keyword("if"); | |
this.push("("); | |
print.plain(node.filter); | |
this.push(")"); | |
this.space(); | |
} | |
print.plain(node.body); | |
this.push(node.generator ? ")" : "]"); | |
} | |
},{}],22:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.UnaryExpression = UnaryExpression; | |
exports.DoExpression = DoExpression; | |
exports.ParenthesizedExpression = ParenthesizedExpression; | |
exports.UpdateExpression = UpdateExpression; | |
exports.ConditionalExpression = ConditionalExpression; | |
exports.NewExpression = NewExpression; | |
exports.SequenceExpression = SequenceExpression; | |
exports.ThisExpression = ThisExpression; | |
exports.Super = Super; | |
exports.Decorator = Decorator; | |
exports.CallExpression = CallExpression; | |
exports.EmptyStatement = EmptyStatement; | |
exports.ExpressionStatement = ExpressionStatement; | |
exports.AssignmentPattern = AssignmentPattern; | |
exports.AssignmentExpression = AssignmentExpression; | |
exports.BindExpression = BindExpression; | |
exports.MemberExpression = MemberExpression; | |
exports.MetaProperty = MetaProperty; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _isInteger = _dereq_(398); | |
var _isInteger2 = _interopRequireDefault(_isInteger); | |
var _lodashLangIsNumber = _dereq_(502); | |
var _lodashLangIsNumber2 = _interopRequireDefault(_lodashLangIsNumber); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* RegExp for testing scientific notation in literals. | |
*/ | |
var SCIENTIFIC_NOTATION = /e/i; | |
/** | |
* RegExp for testing if a numeric literal is | |
* a BinaryIntegerLiteral, OctalIntegerLiteral or HexIntegerLiteral. | |
*/ | |
var NON_DECIMAL_NUMERIC_LITERAL = /^0(b|o|x)/i; | |
/** | |
* Prints UnaryExpression, prints operator and argument. | |
*/ | |
function UnaryExpression(node, print) { | |
var needsSpace = /[a-z]$/.test(node.operator); | |
var arg = node.argument; | |
if (t.isUpdateExpression(arg) || t.isUnaryExpression(arg)) { | |
needsSpace = true; | |
} | |
if (t.isUnaryExpression(arg) && arg.operator === "!") { | |
needsSpace = false; | |
} | |
this.push(node.operator); | |
if (needsSpace) this.push(" "); | |
print.plain(node.argument); | |
} | |
/** | |
* Prints DoExpression, prints body. | |
*/ | |
function DoExpression(node, print) { | |
this.push("do"); | |
this.space(); | |
print.plain(node.body); | |
} | |
/** | |
* Prints ParenthesizedExpression, prints expression. | |
*/ | |
function ParenthesizedExpression(node, print) { | |
this.push("("); | |
print.plain(node.expression); | |
this.push(")"); | |
} | |
/** | |
* Prints UpdateExpression, prints operator and argument. | |
*/ | |
function UpdateExpression(node, print) { | |
if (node.prefix) { | |
this.push(node.operator); | |
print.plain(node.argument); | |
} else { | |
print.plain(node.argument); | |
this.push(node.operator); | |
} | |
} | |
/** | |
* Prints ConditionalExpression, prints test, consequent, and alternate. | |
*/ | |
function ConditionalExpression(node, print) { | |
print.plain(node.test); | |
this.space(); | |
this.push("?"); | |
this.space(); | |
print.plain(node.consequent); | |
this.space(); | |
this.push(":"); | |
this.space(); | |
print.plain(node.alternate); | |
} | |
/** | |
* Prints NewExpression, prints callee and arguments. | |
*/ | |
function NewExpression(node, print) { | |
this.push("new "); | |
print.plain(node.callee); | |
this.push("("); | |
print.list(node.arguments); | |
this.push(")"); | |
} | |
/** | |
* Prints SequenceExpression.expressions. | |
*/ | |
function SequenceExpression(node, print) { | |
print.list(node.expressions); | |
} | |
/** | |
* Prints ThisExpression. | |
*/ | |
function ThisExpression() { | |
this.push("this"); | |
} | |
/** | |
* Prints Super. | |
*/ | |
function Super() { | |
this.push("super"); | |
} | |
/** | |
* Prints Decorator, prints expression. | |
*/ | |
function Decorator(node, print) { | |
this.push("@"); | |
print.plain(node.expression); | |
this.newline(); | |
} | |
/** | |
* Prints CallExpression, prints callee and arguments. | |
*/ | |
function CallExpression(node, print) { | |
print.plain(node.callee); | |
this.push("("); | |
var isPrettyCall = node._prettyCall && !this.format.retainLines && !this.format.compact; | |
var separator; | |
if (isPrettyCall) { | |
separator = ",\n"; | |
this.newline(); | |
this.indent(); | |
} | |
print.list(node.arguments, { separator: separator }); | |
if (isPrettyCall) { | |
this.newline(); | |
this.dedent(); | |
} | |
this.push(")"); | |
} | |
/** | |
* Builds yield or await expression printer. | |
* Prints delegate, all, and argument. | |
*/ | |
var buildYieldAwait = function buildYieldAwait(keyword) { | |
return function (node, print) { | |
this.push(keyword); | |
if (node.delegate || node.all) { | |
this.push("*"); | |
} | |
if (node.argument) { | |
this.push(" "); | |
var terminatorState = this.startTerminatorless(); | |
print.plain(node.argument); | |
this.endTerminatorless(terminatorState); | |
} | |
}; | |
}; | |
/** | |
* Create YieldExpression and AwaitExpression printers. | |
*/ | |
var YieldExpression = buildYieldAwait("yield"); | |
exports.YieldExpression = YieldExpression; | |
var AwaitExpression = buildYieldAwait("await"); | |
exports.AwaitExpression = AwaitExpression; | |
/** | |
* Prints EmptyStatement. | |
*/ | |
function EmptyStatement() { | |
this.semicolon(); | |
} | |
/** | |
* Prints ExpressionStatement, prints expression. | |
*/ | |
function ExpressionStatement(node, print) { | |
print.plain(node.expression); | |
this.semicolon(); | |
} | |
/** | |
* Prints AssignmentPattern, prints left and right. | |
*/ | |
function AssignmentPattern(node, print) { | |
print.plain(node.left); | |
this.push(" = "); | |
print.plain(node.right); | |
} | |
/** | |
* Prints AssignmentExpression, prints left, operator, and right. | |
*/ | |
function AssignmentExpression(node, print) { | |
// todo: add cases where the spaces can be dropped when in compact mode | |
print.plain(node.left); | |
var spaces = node.operator === "in" || node.operator === "instanceof"; | |
spaces = true; // todo: https://github.com/babel/babel/issues/1835 | |
this.space(spaces); | |
this.push(node.operator); | |
if (!spaces) { | |
// space is mandatory to avoid outputting <!-- | |
// http://javascript.spec.whatwg.org/#comment-syntax | |
spaces = node.operator === "<" && t.isUnaryExpression(node.right, { prefix: true, operator: "!" }) && t.isUnaryExpression(node.right.argument, { prefix: true, operator: "--" }); | |
} | |
this.space(spaces); | |
print.plain(node.right); | |
} | |
/** | |
* Prints BindExpression, prints object and callee. | |
*/ | |
function BindExpression(node, print) { | |
print.plain(node.object); | |
this.push("::"); | |
print.plain(node.callee); | |
} | |
/** | |
* Alias ClassDeclaration printer as ClassExpression, | |
* and AssignmentExpression printer as LogicalExpression. | |
*/ | |
exports.BinaryExpression = AssignmentExpression; | |
exports.LogicalExpression = AssignmentExpression; | |
/** | |
* Print MemberExpression, prints object, property, and value. Handles computed. | |
*/ | |
function MemberExpression(node, print) { | |
var obj = node.object; | |
print.plain(obj); | |
if (!node.computed && t.isMemberExpression(node.property)) { | |
throw new TypeError("Got a MemberExpression for MemberExpression property"); | |
} | |
var computed = node.computed; | |
if (t.isLiteral(node.property) && _lodashLangIsNumber2["default"](node.property.value)) { | |
computed = true; | |
} | |
if (computed) { | |
this.push("["); | |
print.plain(node.property); | |
this.push("]"); | |
} else { | |
if (t.isLiteral(node.object)) { | |
var val = this._Literal(node.object); | |
if (_isInteger2["default"](+val) && !SCIENTIFIC_NOTATION.test(val) && !this.endsWith(".") && !NON_DECIMAL_NUMERIC_LITERAL.test(val)) { | |
this.push("."); | |
} | |
} | |
this.push("."); | |
print.plain(node.property); | |
} | |
} | |
/** | |
* Print MetaProperty, prints meta and property. | |
*/ | |
function MetaProperty(node, print) { | |
print.plain(node.meta); | |
this.push("."); | |
print.plain(node.property); | |
} | |
},{"179":179,"398":398,"502":502}],23:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.AnyTypeAnnotation = AnyTypeAnnotation; | |
exports.ArrayTypeAnnotation = ArrayTypeAnnotation; | |
exports.BooleanTypeAnnotation = BooleanTypeAnnotation; | |
exports.BooleanLiteralTypeAnnotation = BooleanLiteralTypeAnnotation; | |
exports.DeclareClass = DeclareClass; | |
exports.DeclareFunction = DeclareFunction; | |
exports.DeclareModule = DeclareModule; | |
exports.DeclareVariable = DeclareVariable; | |
exports.FunctionTypeAnnotation = FunctionTypeAnnotation; | |
exports.FunctionTypeParam = FunctionTypeParam; | |
exports.InterfaceExtends = InterfaceExtends; | |
exports._interfaceish = _interfaceish; | |
exports.InterfaceDeclaration = InterfaceDeclaration; | |
exports.IntersectionTypeAnnotation = IntersectionTypeAnnotation; | |
exports.MixedTypeAnnotation = MixedTypeAnnotation; | |
exports.NullableTypeAnnotation = NullableTypeAnnotation; | |
exports.NumberTypeAnnotation = NumberTypeAnnotation; | |
exports.StringLiteralTypeAnnotation = StringLiteralTypeAnnotation; | |
exports.StringTypeAnnotation = StringTypeAnnotation; | |
exports.TupleTypeAnnotation = TupleTypeAnnotation; | |
exports.TypeofTypeAnnotation = TypeofTypeAnnotation; | |
exports.TypeAlias = TypeAlias; | |
exports.TypeAnnotation = TypeAnnotation; | |
exports.TypeParameterInstantiation = TypeParameterInstantiation; | |
exports.ObjectTypeAnnotation = ObjectTypeAnnotation; | |
exports.ObjectTypeCallProperty = ObjectTypeCallProperty; | |
exports.ObjectTypeIndexer = ObjectTypeIndexer; | |
exports.ObjectTypeProperty = ObjectTypeProperty; | |
exports.QualifiedTypeIdentifier = QualifiedTypeIdentifier; | |
exports.UnionTypeAnnotation = UnionTypeAnnotation; | |
exports.TypeCastExpression = TypeCastExpression; | |
exports.VoidTypeAnnotation = VoidTypeAnnotation; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* Prints AnyTypeAnnotation. | |
*/ | |
function AnyTypeAnnotation() { | |
this.push("any"); | |
} | |
/** | |
* Prints ArrayTypeAnnotation, prints elementType. | |
*/ | |
function ArrayTypeAnnotation(node, print) { | |
print.plain(node.elementType); | |
this.push("["); | |
this.push("]"); | |
} | |
/** | |
* Prints BooleanTypeAnnotation. | |
*/ | |
function BooleanTypeAnnotation() { | |
this.push("bool"); | |
} | |
/** | |
* Prints BooleanLiteralTypeAnnotation. | |
*/ | |
function BooleanLiteralTypeAnnotation(node) { | |
this.push(node.value ? "true" : "false"); | |
} | |
/** | |
* Prints DeclareClass, prints node. | |
*/ | |
function DeclareClass(node, print) { | |
this.push("declare class "); | |
this._interfaceish(node, print); | |
} | |
/** | |
* Prints DeclareFunction, prints id and id.typeAnnotation. | |
*/ | |
function DeclareFunction(node, print) { | |
this.push("declare function "); | |
print.plain(node.id); | |
print.plain(node.id.typeAnnotation.typeAnnotation); | |
this.semicolon(); | |
} | |
/** | |
* Prints DeclareModule, prints id and body. | |
*/ | |
function DeclareModule(node, print) { | |
this.push("declare module "); | |
print.plain(node.id); | |
this.space(); | |
print.plain(node.body); | |
} | |
/** | |
* Prints DeclareVariable, prints id and id.typeAnnotation. | |
*/ | |
function DeclareVariable(node, print) { | |
this.push("declare var "); | |
print.plain(node.id); | |
print.plain(node.id.typeAnnotation); | |
this.semicolon(); | |
} | |
/** | |
* Prints FunctionTypeAnnotation, prints typeParameters, params, and rest. | |
*/ | |
function FunctionTypeAnnotation(node, print, parent) { | |
print.plain(node.typeParameters); | |
this.push("("); | |
print.list(node.params); | |
if (node.rest) { | |
if (node.params.length) { | |
this.push(","); | |
this.space(); | |
} | |
this.push("..."); | |
print.plain(node.rest); | |
} | |
this.push(")"); | |
// this node type is overloaded, not sure why but it makes it EXTREMELY annoying | |
if (parent.type === "ObjectTypeProperty" || parent.type === "ObjectTypeCallProperty" || parent.type === "DeclareFunction") { | |
this.push(":"); | |
} else { | |
this.space(); | |
this.push("=>"); | |
} | |
this.space(); | |
print.plain(node.returnType); | |
} | |
/** | |
* Prints FunctionTypeParam, prints name and typeAnnotation, handles optional. | |
*/ | |
function FunctionTypeParam(node, print) { | |
print.plain(node.name); | |
if (node.optional) this.push("?"); | |
this.push(":"); | |
this.space(); | |
print.plain(node.typeAnnotation); | |
} | |
/** | |
* Prints InterfaceExtends, prints id and typeParameters. | |
*/ | |
function InterfaceExtends(node, print) { | |
print.plain(node.id); | |
print.plain(node.typeParameters); | |
} | |
/** | |
* Alias InterfaceExtends printer as ClassImplements, | |
* and InterfaceExtends printer as GenericTypeAnnotation. | |
*/ | |
exports.ClassImplements = InterfaceExtends; | |
exports.GenericTypeAnnotation = InterfaceExtends; | |
/** | |
* Prints interface-like node, prints id, typeParameters, extends, and body. | |
*/ | |
function _interfaceish(node, print) { | |
print.plain(node.id); | |
print.plain(node.typeParameters); | |
if (node["extends"].length) { | |
this.push(" extends "); | |
print.join(node["extends"], { separator: ", " }); | |
} | |
this.space(); | |
print.plain(node.body); | |
} | |
/** | |
* Prints InterfaceDeclaration, prints node. | |
*/ | |
function InterfaceDeclaration(node, print) { | |
this.push("interface "); | |
this._interfaceish(node, print); | |
} | |
/** | |
* Prints IntersectionTypeAnnotation, prints types. | |
*/ | |
function IntersectionTypeAnnotation(node, print) { | |
print.join(node.types, { separator: " & " }); | |
} | |
/** | |
* Prints MixedTypeAnnotation. | |
*/ | |
function MixedTypeAnnotation() { | |
this.push("mixed"); | |
} | |
/** | |
* Prints NullableTypeAnnotation, prints typeAnnotation. | |
*/ | |
function NullableTypeAnnotation(node, print) { | |
this.push("?"); | |
print.plain(node.typeAnnotation); | |
} | |
/** | |
* Prints NumberLiteralTypeAnnotation, prints value. | |
*/ | |
var _types2 = _dereq_(29); | |
exports.NumberLiteralTypeAnnotation = _types2.Literal; | |
/** | |
* Prints NumberTypeAnnotation. | |
*/ | |
function NumberTypeAnnotation() { | |
this.push("number"); | |
} | |
/** | |
* Prints StringLiteralTypeAnnotation, prints value. | |
*/ | |
function StringLiteralTypeAnnotation(node) { | |
this.push(this._stringLiteral(node.value)); | |
} | |
/** | |
* Prints StringTypeAnnotation. | |
*/ | |
function StringTypeAnnotation() { | |
this.push("string"); | |
} | |
/** | |
* Prints TupleTypeAnnotation, prints types. | |
*/ | |
function TupleTypeAnnotation(node, print) { | |
this.push("["); | |
print.join(node.types, { separator: ", " }); | |
this.push("]"); | |
} | |
/** | |
* Prints TypeofTypeAnnotation, prints argument. | |
*/ | |
function TypeofTypeAnnotation(node, print) { | |
this.push("typeof "); | |
print.plain(node.argument); | |
} | |
/** | |
* Prints TypeAlias, prints id, typeParameters, and right. | |
*/ | |
function TypeAlias(node, print) { | |
this.push("type "); | |
print.plain(node.id); | |
print.plain(node.typeParameters); | |
this.space(); | |
this.push("="); | |
this.space(); | |
print.plain(node.right); | |
this.semicolon(); | |
} | |
/** | |
* Prints TypeAnnotation, prints typeAnnotation, handles optional. | |
*/ | |
function TypeAnnotation(node, print) { | |
this.push(":"); | |
this.space(); | |
if (node.optional) this.push("?"); | |
print.plain(node.typeAnnotation); | |
} | |
/** | |
* Prints TypeParameterInstantiation, prints params. | |
*/ | |
function TypeParameterInstantiation(node, print) { | |
this.push("<"); | |
print.join(node.params, { | |
separator: ", ", | |
iterator: function iterator(node) { | |
print.plain(node.typeAnnotation); | |
} | |
}); | |
this.push(">"); | |
} | |
/** | |
* Alias TypeParameterInstantiation printer as TypeParameterDeclaration | |
*/ | |
exports.TypeParameterDeclaration = TypeParameterInstantiation; | |
/** | |
* Prints ObjectTypeAnnotation, prints properties, callProperties, and indexers. | |
*/ | |
function ObjectTypeAnnotation(node, print) { | |
// istanbul ignore next | |
var _this = this; | |
this.push("{"); | |
var props = node.properties.concat(node.callProperties, node.indexers); | |
if (props.length) { | |
this.space(); | |
print.list(props, { | |
separator: false, | |
indent: true, | |
iterator: function iterator() { | |
if (props.length !== 1) { | |
_this.semicolon(); | |
_this.space(); | |
} | |
} | |
}); | |
this.space(); | |
} | |
this.push("}"); | |
} | |
/** | |
* Prints ObjectTypeCallProperty, prints value, handles static. | |
*/ | |
function ObjectTypeCallProperty(node, print) { | |
if (node["static"]) this.push("static "); | |
print.plain(node.value); | |
} | |
/** | |
* Prints ObjectTypeIndexer, prints id, key, and value, handles static. | |
*/ | |
function ObjectTypeIndexer(node, print) { | |
if (node["static"]) this.push("static "); | |
this.push("["); | |
print.plain(node.id); | |
this.push(":"); | |
this.space(); | |
print.plain(node.key); | |
this.push("]"); | |
this.push(":"); | |
this.space(); | |
print.plain(node.value); | |
} | |
/** | |
* Prints ObjectTypeProperty, prints static, key, and value. | |
*/ | |
function ObjectTypeProperty(node, print) { | |
if (node["static"]) this.push("static "); | |
print.plain(node.key); | |
if (node.optional) this.push("?"); | |
if (!t.isFunctionTypeAnnotation(node.value)) { | |
this.push(":"); | |
this.space(); | |
} | |
print.plain(node.value); | |
} | |
/** | |
* Prints QualifiedTypeIdentifier, prints qualification and id. | |
*/ | |
function QualifiedTypeIdentifier(node, print) { | |
print.plain(node.qualification); | |
this.push("."); | |
print.plain(node.id); | |
} | |
/** | |
* Prints UnionTypeAnnotation, prints types. | |
*/ | |
function UnionTypeAnnotation(node, print) { | |
print.join(node.types, { separator: " | " }); | |
} | |
/** | |
* Prints TypeCastExpression, prints expression and typeAnnotation. | |
*/ | |
function TypeCastExpression(node, print) { | |
this.push("("); | |
print.plain(node.expression); | |
print.plain(node.typeAnnotation); | |
this.push(")"); | |
} | |
/** | |
* Prints VoidTypeAnnotation. | |
*/ | |
function VoidTypeAnnotation() { | |
this.push("void"); | |
} | |
},{"179":179,"29":29}],24:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.JSXAttribute = JSXAttribute; | |
exports.JSXIdentifier = JSXIdentifier; | |
exports.JSXNamespacedName = JSXNamespacedName; | |
exports.JSXMemberExpression = JSXMemberExpression; | |
exports.JSXSpreadAttribute = JSXSpreadAttribute; | |
exports.JSXExpressionContainer = JSXExpressionContainer; | |
exports.JSXElement = JSXElement; | |
exports.JSXOpeningElement = JSXOpeningElement; | |
exports.JSXClosingElement = JSXClosingElement; | |
exports.JSXEmptyExpression = JSXEmptyExpression; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* Prints JSXAttribute, prints name and value. | |
*/ | |
function JSXAttribute(node, print) { | |
print.plain(node.name); | |
if (node.value) { | |
this.push("="); | |
print.plain(node.value); | |
} | |
} | |
/** | |
* Prints JSXIdentifier, prints name. | |
*/ | |
function JSXIdentifier(node) { | |
this.push(node.name); | |
} | |
/** | |
* Prints JSXNamespacedName, prints namespace and name. | |
*/ | |
function JSXNamespacedName(node, print) { | |
print.plain(node.namespace); | |
this.push(":"); | |
print.plain(node.name); | |
} | |
/** | |
* Prints JSXMemberExpression, prints object and property. | |
*/ | |
function JSXMemberExpression(node, print) { | |
print.plain(node.object); | |
this.push("."); | |
print.plain(node.property); | |
} | |
/** | |
* Prints JSXSpreadAttribute, prints argument. | |
*/ | |
function JSXSpreadAttribute(node, print) { | |
this.push("{..."); | |
print.plain(node.argument); | |
this.push("}"); | |
} | |
/** | |
* Prints JSXExpressionContainer, prints expression. | |
*/ | |
function JSXExpressionContainer(node, print) { | |
this.push("{"); | |
print.plain(node.expression); | |
this.push("}"); | |
} | |
/** | |
* Prints JSXElement, prints openingElement, children, and closingElement. | |
*/ | |
function JSXElement(node, print) { | |
var open = node.openingElement; | |
print.plain(open); | |
if (open.selfClosing) return; | |
this.indent(); | |
var _arr = node.children; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var child = _arr[_i]; | |
if (t.isLiteral(child)) { | |
this.push(child.value, true); | |
} else { | |
print.plain(child); | |
} | |
} | |
this.dedent(); | |
print.plain(node.closingElement); | |
} | |
/** | |
* Prints JSXOpeningElement, prints name and attributes, handles selfClosing. | |
*/ | |
function JSXOpeningElement(node, print) { | |
this.push("<"); | |
print.plain(node.name); | |
if (node.attributes.length > 0) { | |
this.push(" "); | |
print.join(node.attributes, { separator: " " }); | |
} | |
this.push(node.selfClosing ? " />" : ">"); | |
} | |
/** | |
* Prints JSXClosingElement, prints name. | |
*/ | |
function JSXClosingElement(node, print) { | |
this.push("</"); | |
print.plain(node.name); | |
this.push(">"); | |
} | |
/** | |
* Prints JSXEmptyExpression. | |
*/ | |
function JSXEmptyExpression() {} | |
},{"179":179}],25:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports._params = _params; | |
exports._method = _method; | |
exports.FunctionExpression = FunctionExpression; | |
exports.ArrowFunctionExpression = ArrowFunctionExpression; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* Prints nodes with params, prints typeParameters, params, and returnType, handles optional params. | |
*/ | |
function _params(node, print) { | |
// istanbul ignore next | |
var _this = this; | |
print.plain(node.typeParameters); | |
this.push("("); | |
print.list(node.params, { | |
iterator: function iterator(node) { | |
if (node.optional) _this.push("?"); | |
print.plain(node.typeAnnotation); | |
} | |
}); | |
this.push(")"); | |
if (node.returnType) { | |
print.plain(node.returnType); | |
} | |
} | |
/** | |
* Prints method-like nodes, prints key, value, and body, handles async, generator, computed, and get or set. | |
*/ | |
function _method(node, print) { | |
var value = node.value; | |
var kind = node.kind; | |
var key = node.key; | |
if (kind === "method" || kind === "init") { | |
if (value.generator) { | |
this.push("*"); | |
} | |
} | |
if (kind === "get" || kind === "set") { | |
this.push(kind + " "); | |
} | |
if (value.async) this.push("async "); | |
if (node.computed) { | |
this.push("["); | |
print.plain(key); | |
this.push("]"); | |
} else { | |
print.plain(key); | |
} | |
this._params(value, print); | |
this.space(); | |
print.plain(value.body); | |
} | |
/** | |
* Prints FunctionExpression, prints id and body, handles async and generator. | |
*/ | |
function FunctionExpression(node, print) { | |
if (node.async) this.push("async "); | |
this.push("function"); | |
if (node.generator) this.push("*"); | |
if (node.id) { | |
this.push(" "); | |
print.plain(node.id); | |
} else { | |
this.space(); | |
} | |
this._params(node, print); | |
this.space(); | |
print.plain(node.body); | |
} | |
/** | |
* Alias FunctionExpression printer as FunctionDeclaration. | |
*/ | |
exports.FunctionDeclaration = FunctionExpression; | |
/** | |
* Prints ArrowFunctionExpression, prints params and body, handles async. | |
* Leaves out parentheses when single param. | |
*/ | |
function ArrowFunctionExpression(node, print) { | |
if (node.async) this.push("async "); | |
if (node.params.length === 1 && t.isIdentifier(node.params[0])) { | |
print.plain(node.params[0]); | |
} else { | |
this._params(node, print); | |
} | |
this.push(" => "); | |
var bodyNeedsParens = t.isObjectExpression(node.body); | |
if (bodyNeedsParens) { | |
this.push("("); | |
} | |
print.plain(node.body); | |
if (bodyNeedsParens) { | |
this.push(")"); | |
} | |
} | |
},{"179":179}],26:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.ImportSpecifier = ImportSpecifier; | |
exports.ImportDefaultSpecifier = ImportDefaultSpecifier; | |
exports.ExportDefaultSpecifier = ExportDefaultSpecifier; | |
exports.ExportSpecifier = ExportSpecifier; | |
exports.ExportNamespaceSpecifier = ExportNamespaceSpecifier; | |
exports.ExportAllDeclaration = ExportAllDeclaration; | |
exports.ExportNamedDeclaration = ExportNamedDeclaration; | |
exports.ExportDefaultDeclaration = ExportDefaultDeclaration; | |
exports.ImportDeclaration = ImportDeclaration; | |
exports.ImportNamespaceSpecifier = ImportNamespaceSpecifier; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* Prints ImportSpecifier, prints imported and local. | |
*/ | |
function ImportSpecifier(node, print) { | |
print.plain(node.imported); | |
if (node.local && node.local.name !== node.imported.name) { | |
this.push(" as "); | |
print.plain(node.local); | |
} | |
} | |
/** | |
* Prints ImportDefaultSpecifier, prints local. | |
*/ | |
function ImportDefaultSpecifier(node, print) { | |
print.plain(node.local); | |
} | |
/** | |
* Prints ExportDefaultSpecifier, prints exported. | |
*/ | |
function ExportDefaultSpecifier(node, print) { | |
print.plain(node.exported); | |
} | |
/** | |
* Prints ExportSpecifier, prints local and exported. | |
*/ | |
function ExportSpecifier(node, print) { | |
print.plain(node.local); | |
if (node.exported && node.local.name !== node.exported.name) { | |
this.push(" as "); | |
print.plain(node.exported); | |
} | |
} | |
/** | |
* Prints ExportNamespaceSpecifier, prints exported. | |
*/ | |
function ExportNamespaceSpecifier(node, print) { | |
this.push("* as "); | |
print.plain(node.exported); | |
} | |
/** | |
* Prints ExportAllDeclaration, prints exported and source. | |
*/ | |
function ExportAllDeclaration(node, print) { | |
this.push("export *"); | |
if (node.exported) { | |
this.push(" as "); | |
print.plain(node.exported); | |
} | |
this.push(" from "); | |
print.plain(node.source); | |
this.semicolon(); | |
} | |
/** | |
* Prints ExportNamedDeclaration, delegates to ExportDeclaration. | |
*/ | |
function ExportNamedDeclaration(node, print) { | |
this.push("export "); | |
ExportDeclaration.call(this, node, print); | |
} | |
/** | |
* Prints ExportDefaultDeclaration, delegates to ExportDeclaration. | |
*/ | |
function ExportDefaultDeclaration(node, print) { | |
this.push("export default "); | |
ExportDeclaration.call(this, node, print); | |
} | |
/** | |
* Prints ExportDeclaration, prints specifiers, declration, and source. | |
*/ | |
function ExportDeclaration(node, print) { | |
var specifiers = node.specifiers; | |
if (node.declaration) { | |
var declar = node.declaration; | |
print.plain(declar); | |
if (t.isStatement(declar) || t.isFunction(declar) || t.isClass(declar)) return; | |
} else { | |
if (node.exportKind === "type") { | |
this.push("type "); | |
} | |
var first = specifiers[0]; | |
var hasSpecial = false; | |
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) { | |
hasSpecial = true; | |
print.plain(specifiers.shift()); | |
if (specifiers.length) { | |
this.push(", "); | |
} | |
} | |
if (specifiers.length || !specifiers.length && !hasSpecial) { | |
this.push("{"); | |
if (specifiers.length) { | |
this.space(); | |
print.join(specifiers, { separator: ", " }); | |
this.space(); | |
} | |
this.push("}"); | |
} | |
if (node.source) { | |
this.push(" from "); | |
print.plain(node.source); | |
} | |
} | |
this.ensureSemicolon(); | |
} | |
/** | |
* Prints ImportDeclaration, prints specifiers and source, handles isType. | |
*/ | |
function ImportDeclaration(node, print) { | |
this.push("import "); | |
if (node.importKind === "type" || node.importKind === "typeof") { | |
this.push(node.importKind + " "); | |
} | |
var specfiers = node.specifiers; | |
if (specfiers && specfiers.length) { | |
var first = node.specifiers[0]; | |
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) { | |
print.plain(node.specifiers.shift()); | |
if (node.specifiers.length) { | |
this.push(", "); | |
} | |
} | |
if (node.specifiers.length) { | |
this.push("{"); | |
this.space(); | |
print.join(node.specifiers, { separator: ", " }); | |
this.space(); | |
this.push("}"); | |
} | |
this.push(" from "); | |
} | |
print.plain(node.source); | |
this.semicolon(); | |
} | |
/** | |
* Prints ImportNamespaceSpecifier, prints local. | |
*/ | |
function ImportNamespaceSpecifier(node, print) { | |
this.push("* as "); | |
print.plain(node.local); | |
} | |
},{"179":179}],27:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.WithStatement = WithStatement; | |
exports.IfStatement = IfStatement; | |
exports.ForStatement = ForStatement; | |
exports.WhileStatement = WhileStatement; | |
exports.DoWhileStatement = DoWhileStatement; | |
exports.LabeledStatement = LabeledStatement; | |
exports.TryStatement = TryStatement; | |
exports.CatchClause = CatchClause; | |
exports.SwitchStatement = SwitchStatement; | |
exports.SwitchCase = SwitchCase; | |
exports.DebuggerStatement = DebuggerStatement; | |
exports.VariableDeclaration = VariableDeclaration; | |
exports.VariableDeclarator = VariableDeclarator; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _repeating = _dereq_(584); | |
var _repeating2 = _interopRequireDefault(_repeating); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* Prints WithStatement, prints object and body. | |
*/ | |
function WithStatement(node, print) { | |
this.keyword("with"); | |
this.push("("); | |
print.plain(node.object); | |
this.push(")"); | |
print.block(node.body); | |
} | |
/** | |
* Prints IfStatement, prints test, consequent, and alternate. | |
*/ | |
function IfStatement(node, print) { | |
this.keyword("if"); | |
this.push("("); | |
print.plain(node.test); | |
this.push(")"); | |
this.space(); | |
print.indentOnComments(node.consequent); | |
if (node.alternate) { | |
if (this.isLast("}")) this.space(); | |
this.push("else "); | |
print.indentOnComments(node.alternate); | |
} | |
} | |
/** | |
* Prints ForStatement, prints init, test, update, and body. | |
*/ | |
function ForStatement(node, print) { | |
this.keyword("for"); | |
this.push("("); | |
print.plain(node.init); | |
this.push(";"); | |
if (node.test) { | |
this.space(); | |
print.plain(node.test); | |
} | |
this.push(";"); | |
if (node.update) { | |
this.space(); | |
print.plain(node.update); | |
} | |
this.push(")"); | |
print.block(node.body); | |
} | |
/** | |
* Prints WhileStatement, prints test and body. | |
*/ | |
function WhileStatement(node, print) { | |
this.keyword("while"); | |
this.push("("); | |
print.plain(node.test); | |
this.push(")"); | |
print.block(node.body); | |
} | |
/** | |
* Builds ForIn or ForOf statement printers. | |
* Prints left, right, and body. | |
*/ | |
var buildForXStatement = function buildForXStatement(op) { | |
return function (node, print) { | |
this.keyword("for"); | |
this.push("("); | |
print.plain(node.left); | |
this.push(" " + op + " "); | |
print.plain(node.right); | |
this.push(")"); | |
print.block(node.body); | |
}; | |
}; | |
/** | |
* Create ForInStatement and ForOfStatement printers. | |
*/ | |
var ForInStatement = buildForXStatement("in"); | |
exports.ForInStatement = ForInStatement; | |
var ForOfStatement = buildForXStatement("of"); | |
exports.ForOfStatement = ForOfStatement; | |
/** | |
* Prints DoWhileStatement, prints body and test. | |
*/ | |
function DoWhileStatement(node, print) { | |
this.push("do "); | |
print.plain(node.body); | |
this.space(); | |
this.keyword("while"); | |
this.push("("); | |
print.plain(node.test); | |
this.push(");"); | |
} | |
/** | |
* Builds continue, return, or break statement printers. | |
* Prints label (or key). | |
*/ | |
var buildLabelStatement = function buildLabelStatement(prefix) { | |
var key = arguments.length <= 1 || arguments[1] === undefined ? "label" : arguments[1]; | |
return function (node, print) { | |
this.push(prefix); | |
var label = node[key]; | |
if (label) { | |
this.push(" "); | |
var terminatorState = this.startTerminatorless(); | |
print.plain(label); | |
this.endTerminatorless(terminatorState); | |
} | |
this.semicolon(); | |
}; | |
}; | |
/** | |
* Create ContinueStatement, ReturnStatement, and BreakStatement printers. | |
*/ | |
var ContinueStatement = buildLabelStatement("continue"); | |
exports.ContinueStatement = ContinueStatement; | |
var ReturnStatement = buildLabelStatement("return", "argument"); | |
exports.ReturnStatement = ReturnStatement; | |
var BreakStatement = buildLabelStatement("break"); | |
exports.BreakStatement = BreakStatement; | |
var ThrowStatement = buildLabelStatement("throw", "argument"); | |
exports.ThrowStatement = ThrowStatement; | |
/** | |
* Prints LabeledStatement, prints label and body. | |
*/ | |
function LabeledStatement(node, print) { | |
print.plain(node.label); | |
this.push(": "); | |
print.plain(node.body); | |
} | |
/** | |
* Prints TryStatement, prints block, handlers, and finalizer. | |
*/ | |
function TryStatement(node, print) { | |
this.keyword("try"); | |
print.plain(node.block); | |
this.space(); | |
// Esprima bug puts the catch clause in a `handlers` array. | |
// see https://code.google.com/p/esprima/issues/detail?id=433 | |
// We run into this from regenerator generated ast. | |
if (node.handlers) { | |
print.plain(node.handlers[0]); | |
} else { | |
print.plain(node.handler); | |
} | |
if (node.finalizer) { | |
this.space(); | |
this.push("finally "); | |
print.plain(node.finalizer); | |
} | |
} | |
/** | |
* Prints CatchClause, prints param and body. | |
*/ | |
function CatchClause(node, print) { | |
this.keyword("catch"); | |
this.push("("); | |
print.plain(node.param); | |
this.push(") "); | |
print.plain(node.body); | |
} | |
/** | |
* Prints SwitchStatement, prints discriminant and cases. | |
*/ | |
function SwitchStatement(node, print) { | |
this.keyword("switch"); | |
this.push("("); | |
print.plain(node.discriminant); | |
this.push(")"); | |
this.space(); | |
this.push("{"); | |
print.sequence(node.cases, { | |
indent: true, | |
addNewlines: function addNewlines(leading, cas) { | |
if (!leading && node.cases[node.cases.length - 1] === cas) return -1; | |
} | |
}); | |
this.push("}"); | |
} | |
/** | |
* Prints SwitchCase, prints test and consequent. | |
*/ | |
function SwitchCase(node, print) { | |
if (node.test) { | |
this.push("case "); | |
print.plain(node.test); | |
this.push(":"); | |
} else { | |
this.push("default:"); | |
} | |
if (node.consequent.length) { | |
this.newline(); | |
print.sequence(node.consequent, { indent: true }); | |
} | |
} | |
/** | |
* Prints DebuggerStatement. | |
*/ | |
function DebuggerStatement() { | |
this.push("debugger;"); | |
} | |
/** | |
* Prints VariableDeclaration, prints declarations, handles kind and format. | |
*/ | |
function VariableDeclaration(node, print, parent) { | |
this.push(node.kind + " "); | |
var hasInits = false; | |
// don't add whitespace to loop heads | |
if (!t.isFor(parent)) { | |
var _arr = node.declarations; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var declar = _arr[_i]; | |
if (declar.init) { | |
// has an init so let's split it up over multiple lines | |
hasInits = true; | |
} | |
} | |
} | |
// | |
// use a pretty separator when we aren't in compact mode, have initializers and don't have retainLines on | |
// this will format declarations like: | |
// | |
// var foo = "bar", bar = "foo"; | |
// | |
// into | |
// | |
// var foo = "bar", | |
// bar = "foo"; | |
// | |
var sep; | |
if (!this.format.compact && !this.format.concise && hasInits && !this.format.retainLines) { | |
sep = ",\n" + _repeating2["default"](" ", node.kind.length + 1); | |
} | |
// | |
print.list(node.declarations, { separator: sep }); | |
if (t.isFor(parent)) { | |
// don't give semicolons to these nodes since they'll be inserted in the parent generator | |
if (parent.left === node || parent.init === node) return; | |
} | |
this.semicolon(); | |
} | |
/** | |
* Prints VariableDeclarator, handles id, id.typeAnnotation, and init. | |
*/ | |
function VariableDeclarator(node, print) { | |
print.plain(node.id); | |
print.plain(node.id.typeAnnotation); | |
if (node.init) { | |
this.space(); | |
this.push("="); | |
this.space(); | |
print.plain(node.init); | |
} | |
} | |
},{"179":179,"584":584}],28:[function(_dereq_,module,exports){ | |
/** | |
* Prints TaggedTemplateExpression, prints tag and quasi. | |
*/ | |
"use strict"; | |
exports.__esModule = true; | |
exports.TaggedTemplateExpression = TaggedTemplateExpression; | |
exports.TemplateElement = TemplateElement; | |
exports.TemplateLiteral = TemplateLiteral; | |
function TaggedTemplateExpression(node, print) { | |
print.plain(node.tag); | |
print.plain(node.quasi); | |
} | |
/** | |
* Prints TemplateElement, prints value. | |
*/ | |
function TemplateElement(node) { | |
this._push(node.value.raw); | |
} | |
/** | |
* Prints TemplateLiteral, prints quasis, and expressions. | |
*/ | |
function TemplateLiteral(node, print) { | |
this.push("`"); | |
var quasis = node.quasis; | |
var len = quasis.length; | |
for (var i = 0; i < len; i++) { | |
print.plain(quasis[i]); | |
if (i + 1 < len) { | |
this.push("${ "); | |
print.plain(node.expressions[i]); | |
this.push(" }"); | |
} | |
} | |
this._push("`"); | |
} | |
},{}],29:[function(_dereq_,module,exports){ | |
/* eslint quotes: 0 */ | |
"use strict"; | |
exports.__esModule = true; | |
exports.Identifier = Identifier; | |
exports.RestElement = RestElement; | |
exports.ObjectExpression = ObjectExpression; | |
exports.Property = Property; | |
exports.ArrayExpression = ArrayExpression; | |
exports.Literal = Literal; | |
exports._Literal = _Literal; | |
exports._stringLiteral = _stringLiteral; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* Prints Identifier, prints name. | |
*/ | |
function Identifier(node) { | |
this.push(node.name); | |
} | |
/** | |
* Prints RestElement, prints argument. | |
*/ | |
function RestElement(node, print) { | |
this.push("..."); | |
print.plain(node.argument); | |
} | |
/** | |
* Alias RestElement printer as SpreadElement, | |
* and RestElement printer as SpreadProperty. | |
*/ | |
exports.SpreadElement = RestElement; | |
exports.SpreadProperty = RestElement; | |
/** | |
* Prints ObjectExpression, prints properties. | |
*/ | |
function ObjectExpression(node, print) { | |
var props = node.properties; | |
this.push("{"); | |
print.printInnerComments(); | |
if (props.length) { | |
this.space(); | |
print.list(props, { indent: true }); | |
this.space(); | |
} | |
this.push("}"); | |
} | |
/** | |
* Alias ObjectExpression printer as ObjectPattern. | |
*/ | |
exports.ObjectPattern = ObjectExpression; | |
/** | |
* Prints Property, prints decorators, key, and value, handles kind, computed, and shorthand. | |
*/ | |
function Property(node, print) { | |
print.list(node.decorators, { separator: "" }); | |
if (node.method || node.kind === "get" || node.kind === "set") { | |
this._method(node, print); | |
} else { | |
if (node.computed) { | |
this.push("["); | |
print.plain(node.key); | |
this.push("]"); | |
} else { | |
// print `({ foo: foo = 5 } = {})` as `({ foo = 5 } = {});` | |
if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && node.key.name === node.value.left.name) { | |
print.plain(node.value); | |
return; | |
} | |
print.plain(node.key); | |
// shorthand! | |
if (node.shorthand && (t.isIdentifier(node.key) && t.isIdentifier(node.value) && node.key.name === node.value.name)) { | |
return; | |
} | |
} | |
this.push(":"); | |
this.space(); | |
print.plain(node.value); | |
} | |
} | |
/** | |
* Prints ArrayExpression, prints elements. | |
*/ | |
function ArrayExpression(node, print) { | |
var elems = node.elements; | |
var len = elems.length; | |
this.push("["); | |
print.printInnerComments(); | |
for (var i = 0; i < elems.length; i++) { | |
var elem = elems[i]; | |
if (elem) { | |
if (i > 0) this.space(); | |
print.plain(elem); | |
if (i < len - 1) this.push(","); | |
} else { | |
// If the array expression ends with a hole, that hole | |
// will be ignored by the interpreter, but if it ends with | |
// two (or more) holes, we need to write out two (or more) | |
// commas so that the resulting code is interpreted with | |
// both (all) of the holes. | |
this.push(","); | |
} | |
} | |
this.push("]"); | |
} | |
/** | |
* Alias ArrayExpression printer as ArrayPattern. | |
*/ | |
exports.ArrayPattern = ArrayExpression; | |
/** | |
* Prints Literal, prints value, regex, raw, handles val type. | |
*/ | |
function Literal(node) { | |
this.push(""); // hack: catch up indentation | |
this._push(this._Literal(node)); | |
} | |
function _Literal(node) { | |
var val = node.value; | |
if (node.regex) { | |
return "/" + node.regex.pattern + "/" + node.regex.flags; | |
} | |
// just use the raw property if our current value is equivalent to the one we got | |
// when we populated raw | |
if (node.raw != null && node.rawValue != null && val === node.rawValue) { | |
return node.raw; | |
} | |
switch (typeof val) { | |
case "string": | |
return this._stringLiteral(val); | |
case "number": | |
return val + ""; | |
case "boolean": | |
return val ? "true" : "false"; | |
default: | |
if (val === null) { | |
return "null"; | |
} else { | |
throw new Error("Invalid Literal type"); | |
} | |
} | |
} | |
/** | |
* Prints string literals, handles format. | |
*/ | |
function _stringLiteral(val) { | |
val = JSON.stringify(val); | |
// escape illegal js but valid json unicode characters | |
val = val.replace(/[\u000A\u000D\u2028\u2029]/g, function (c) { | |
return "\\u" + ("0000" + c.charCodeAt(0).toString(16)).slice(-4); | |
}); | |
if (this.format.quotes === "single") { | |
// remove double quotes | |
val = val.slice(1, -1); | |
// unescape double quotes | |
val = val.replace(/\\"/g, '"'); | |
// escape single quotes | |
val = val.replace(/'/g, "\\'"); | |
// add single quotes | |
val = "'" + val + "'"; | |
} | |
return val; | |
} | |
},{"179":179}],30:[function(_dereq_,module,exports){ | |
"use strict"; | |
// istanbul ignore next | |
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _detectIndent = _dereq_(391); | |
var _detectIndent2 = _interopRequireDefault(_detectIndent); | |
var _whitespace = _dereq_(37); | |
var _whitespace2 = _interopRequireDefault(_whitespace); | |
var _nodePrinter = _dereq_(33); | |
var _nodePrinter2 = _interopRequireDefault(_nodePrinter); | |
var _repeating = _dereq_(584); | |
var _repeating2 = _interopRequireDefault(_repeating); | |
var _sourceMap = _dereq_(36); | |
var _sourceMap2 = _interopRequireDefault(_sourceMap); | |
var _position = _dereq_(35); | |
var _position2 = _interopRequireDefault(_position); | |
var _messages = _dereq_(43); | |
var messages = _interopRequireWildcard(_messages); | |
var _buffer = _dereq_(18); | |
var _buffer2 = _interopRequireDefault(_buffer); | |
var _lodashObjectExtend = _dereq_(511); | |
var _lodashObjectExtend2 = _interopRequireDefault(_lodashObjectExtend); | |
var _lodashCollectionEach = _dereq_(411); | |
var _lodashCollectionEach2 = _interopRequireDefault(_lodashCollectionEach); | |
var _node2 = _dereq_(31); | |
var _node3 = _interopRequireDefault(_node2); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* Babel's code generator, turns an ast into code, maintaining sourcemaps, | |
* user preferences, and valid output. | |
*/ | |
var CodeGenerator = (function () { | |
function CodeGenerator(ast, opts, code) { | |
_classCallCheck(this, CodeGenerator); | |
opts = opts || {}; | |
this.comments = ast.comments || []; | |
this.tokens = ast.tokens || []; | |
this.format = CodeGenerator.normalizeOptions(code, opts, this.tokens); | |
this.opts = opts; | |
this.ast = ast; | |
this.whitespace = new _whitespace2["default"](this.tokens); | |
this.position = new _position2["default"](); | |
this.map = new _sourceMap2["default"](this.position, opts, code); | |
this.buffer = new _buffer2["default"](this.position, this.format); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
/** | |
* Normalize generator options, setting defaults. | |
* | |
* - Detects code indentation. | |
* - If `opts.compact = "auto"` and the code is over 100KB, `compact` will be set to `true`. | |
*/ | |
CodeGenerator.normalizeOptions = function normalizeOptions(code, opts, tokens) { | |
var style = " "; | |
if (code) { | |
var indent = _detectIndent2["default"](code).indent; | |
if (indent && indent !== " ") style = indent; | |
} | |
var format = { | |
shouldPrintComment: opts.shouldPrintComment, | |
retainLines: opts.retainLines, | |
comments: opts.comments == null || opts.comments, | |
compact: opts.compact, | |
quotes: CodeGenerator.findCommonStringDelimiter(code, tokens), | |
indent: { | |
adjustMultilineComment: true, | |
style: style, | |
base: 0 | |
} | |
}; | |
if (format.compact === "auto") { | |
format.compact = code.length > 100000; // 100KB | |
if (format.compact) { | |
console.error("[BABEL] " + messages.get("codeGeneratorDeopt", opts.filename, "100KB")); | |
} | |
} | |
if (format.compact) { | |
format.indent.adjustMultilineComment = false; | |
} | |
return format; | |
}; | |
/** | |
* Determine if input code uses more single or double quotes. | |
*/ | |
CodeGenerator.findCommonStringDelimiter = function findCommonStringDelimiter(code, tokens) { | |
var occurences = { | |
single: 0, | |
double: 0 | |
}; | |
var checked = 0; | |
for (var i = 0; i < tokens.length; i++) { | |
var token = tokens[i]; | |
if (token.type.label !== "string") continue; | |
var raw = code.slice(token.start, token.end); | |
if (raw[0] === "'") { | |
occurences.single++; | |
} else { | |
occurences.double++; | |
} | |
checked++; | |
if (checked >= 3) break; | |
} | |
if (occurences.single > occurences.double) { | |
return "single"; | |
} else { | |
return "double"; | |
} | |
}; | |
/** | |
* All node generators. | |
*/ | |
/** | |
* Generate code and sourcemap from ast. | |
* | |
* Appends comments that weren't attached to any node to the end of the generated output. | |
*/ | |
CodeGenerator.prototype.generate = function generate() { | |
var ast = this.ast; | |
this.print(ast); | |
if (ast.comments) { | |
var comments = []; | |
var _arr = ast.comments; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var comment = _arr[_i]; | |
if (!comment._displayed) comments.push(comment); | |
} | |
this._printComments(comments); | |
} | |
return { | |
map: this.map.get(), | |
code: this.buffer.get() | |
}; | |
}; | |
/** | |
* Build NodePrinter. | |
*/ | |
CodeGenerator.prototype.buildPrint = function buildPrint(parent) { | |
return new _nodePrinter2["default"](this, parent); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CodeGenerator.prototype.catchUp = function catchUp(node) { | |
// catch up to this nodes newline if we're behind | |
if (node.loc && this.format.retainLines && this.buffer.buf) { | |
while (this.position.line < node.loc.start.line) { | |
this._push("\n"); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CodeGenerator.prototype._printNewline = function _printNewline(leading, node, parent, opts) { | |
if (!opts.statement && !_node3["default"].isUserWhitespacable(node, parent)) { | |
return; | |
} | |
var lines = 0; | |
if (node.start != null && !node._ignoreUserWhitespace) { | |
// user node | |
if (leading) { | |
lines = this.whitespace.getNewlinesBefore(node); | |
} else { | |
lines = this.whitespace.getNewlinesAfter(node); | |
} | |
} else { | |
// generated node | |
if (!leading) lines++; // always include at least a single line after | |
if (opts.addNewlines) lines += opts.addNewlines(leading, node) || 0; | |
var needs = _node3["default"].needsWhitespaceAfter; | |
if (leading) needs = _node3["default"].needsWhitespaceBefore; | |
if (needs(node, parent)) lines++; | |
// generated nodes can't add starting file whitespace | |
if (!this.buffer.buf) lines = 0; | |
} | |
this.newline(lines); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CodeGenerator.prototype.print = function print(node, parent) { | |
var opts = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | |
if (!node) return; | |
if (parent && parent._compact) { | |
node._compact = true; | |
} | |
var oldConcise = this.format.concise; | |
if (node._compact) { | |
this.format.concise = true; | |
} | |
if (!this[node.type]) { | |
throw new ReferenceError("unknown node of type " + JSON.stringify(node.type) + " with constructor " + JSON.stringify(node && node.constructor.name)); | |
} | |
var needsParens = _node3["default"].needsParens(node, parent); | |
if (needsParens) this.push("("); | |
this.printLeadingComments(node, parent); | |
this.catchUp(node); | |
this._printNewline(true, node, parent, opts); | |
if (opts.before) opts.before(); | |
this.map.mark(node, "start"); | |
this[node.type](node, this.buildPrint(node), parent); | |
if (needsParens) this.push(")"); | |
this.map.mark(node, "end"); | |
if (opts.after) opts.after(); | |
this.format.concise = oldConcise; | |
this._printNewline(false, node, parent, opts); | |
this.printTrailingComments(node, parent); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CodeGenerator.prototype.printJoin = function printJoin(print, nodes) { | |
// istanbul ignore next | |
var _this = this; | |
var opts = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | |
if (!nodes || !nodes.length) return; | |
var len = nodes.length; | |
if (opts.indent) this.indent(); | |
var printOpts = { | |
statement: opts.statement, | |
addNewlines: opts.addNewlines, | |
after: function after() { | |
if (opts.iterator) { | |
opts.iterator(node, i); | |
} | |
if (opts.separator && i < len - 1) { | |
_this.push(opts.separator); | |
} | |
} | |
}; | |
for (var i = 0; i < nodes.length; i++) { | |
var node = nodes[i]; | |
print.plain(node, printOpts); | |
} | |
if (opts.indent) this.dedent(); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CodeGenerator.prototype.printAndIndentOnComments = function printAndIndentOnComments(print, node) { | |
var indent = !!node.leadingComments; | |
if (indent) this.indent(); | |
print.plain(node); | |
if (indent) this.dedent(); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CodeGenerator.prototype.printBlock = function printBlock(print, node) { | |
if (t.isEmptyStatement(node)) { | |
this.semicolon(); | |
} else { | |
this.push(" "); | |
print.plain(node); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CodeGenerator.prototype.generateComment = function generateComment(comment) { | |
var val = comment.value; | |
if (comment.type === "CommentLine") { | |
val = "//" + val; | |
} else { | |
val = "/*" + val + "*/"; | |
} | |
return val; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CodeGenerator.prototype.printTrailingComments = function printTrailingComments(node, parent) { | |
this._printComments(this.getComments("trailingComments", node, parent)); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CodeGenerator.prototype.printLeadingComments = function printLeadingComments(node, parent) { | |
this._printComments(this.getComments("leadingComments", node, parent)); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CodeGenerator.prototype.getComments = function getComments(key, node, parent) { | |
if (t.isExpressionStatement(parent)) { | |
return []; | |
} | |
var comments = []; | |
var nodes = [node]; | |
if (t.isExpressionStatement(node)) { | |
nodes.push(node.argument); | |
} | |
var _arr2 = nodes; | |
for (var _i2 = 0; _i2 < _arr2.length; _i2++) { | |
var _node = _arr2[_i2]; | |
comments = comments.concat(this._getComments(key, _node)); | |
} | |
return comments; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CodeGenerator.prototype._getComments = function _getComments(key, node) { | |
return node && node[key] || []; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CodeGenerator.prototype.shouldPrintComment = function shouldPrintComment(comment) { | |
if (this.format.shouldPrintComment) { | |
return this.format.shouldPrintComment(comment.value); | |
} else { | |
if (comment.value.indexOf("@license") >= 0 || comment.value.indexOf("@preserve") >= 0) { | |
return true; | |
} else { | |
return this.format.comments; | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CodeGenerator.prototype._printComments = function _printComments(comments) { | |
if (!comments || !comments.length) return; | |
var _arr3 = comments; | |
for (var _i3 = 0; _i3 < _arr3.length; _i3++) { | |
var comment = _arr3[_i3]; | |
if (!this.shouldPrintComment(comment)) continue; | |
if (comment._displayed) continue; | |
comment._displayed = true; | |
this.catchUp(comment); | |
// whitespace before | |
this.newline(this.whitespace.getNewlinesBefore(comment)); | |
var column = this.position.column; | |
var val = this.generateComment(comment); | |
if (column && !this.isLast(["\n", " ", "[", "{"])) { | |
this._push(" "); | |
column++; | |
} | |
// | |
if (comment.type === "CommentBlock" && this.format.indent.adjustMultilineComment) { | |
var offset = comment.loc && comment.loc.start.column; | |
if (offset) { | |
var newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g"); | |
val = val.replace(newlineRegex, "\n"); | |
} | |
var indent = Math.max(this.indentSize(), column); | |
val = val.replace(/\n/g, "\n" + _repeating2["default"](" ", indent)); | |
} | |
if (column === 0) { | |
val = this.getIndent() + val; | |
} | |
// force a newline for line comments when retainLines is set in case the next printed node | |
// doesn't catch up | |
if ((this.format.compact || this.format.retainLines) && comment.type === "CommentLine") { | |
val += "\n"; | |
} | |
// | |
this._push(val); | |
// whitespace after | |
this.newline(this.whitespace.getNewlinesAfter(comment)); | |
} | |
}; | |
_createClass(CodeGenerator, null, [{ | |
key: "generators", | |
value: { | |
templateLiterals: _dereq_(28), | |
comprehensions: _dereq_(21), | |
expressions: _dereq_(22), | |
statements: _dereq_(27), | |
classes: _dereq_(20), | |
methods: _dereq_(25), | |
modules: _dereq_(26), | |
types: _dereq_(29), | |
flow: _dereq_(23), | |
base: _dereq_(19), | |
jsx: _dereq_(24) | |
}, | |
enumerable: true | |
}]); | |
return CodeGenerator; | |
})(); | |
_lodashCollectionEach2["default"](_buffer2["default"].prototype, function (fn, key) { | |
CodeGenerator.prototype[key] = function () { | |
return fn.apply(this.buffer, arguments); | |
}; | |
}); | |
/** | |
* [Please add a description.] | |
*/ | |
_lodashCollectionEach2["default"](CodeGenerator.generators, function (generator) { | |
_lodashObjectExtend2["default"](CodeGenerator.prototype, generator); | |
}); | |
/** | |
* [Please add a description.] | |
*/ | |
module.exports = function (ast, opts, code) { | |
var gen = new CodeGenerator(ast, opts, code); | |
return gen.generate(); | |
}; | |
module.exports.CodeGenerator = CodeGenerator; | |
},{"179":179,"18":18,"19":19,"20":20,"21":21,"22":22,"23":23,"24":24,"25":25,"26":26,"27":27,"28":28,"29":29,"31":31,"33":33,"35":35,"36":36,"37":37,"391":391,"411":411,"43":43,"511":511,"584":584}],31:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _whitespace = _dereq_(34); | |
var _whitespace2 = _interopRequireDefault(_whitespace); | |
var _parentheses = _dereq_(32); | |
var parens = _interopRequireWildcard(_parentheses); | |
var _lodashCollectionEach = _dereq_(411); | |
var _lodashCollectionEach2 = _interopRequireDefault(_lodashCollectionEach); | |
var _lodashCollectionSome = _dereq_(416); | |
var _lodashCollectionSome2 = _interopRequireDefault(_lodashCollectionSome); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* Test if node matches a set of type-matcher pairs. | |
* @example | |
* find({ | |
* VariableDeclaration(node, parent) { | |
* return true; | |
* } | |
* }, node, parent); | |
*/ | |
var find = function find(obj, node, parent) { | |
if (!obj) return; | |
var result; | |
var types = Object.keys(obj); | |
for (var i = 0; i < types.length; i++) { | |
var type = types[i]; | |
if (t.is(type, node)) { | |
var fn = obj[type]; | |
result = fn(node, parent); | |
if (result != null) break; | |
} | |
} | |
return result; | |
}; | |
/** | |
* Whitespace and Parenthesis related methods for nodes. | |
*/ | |
var Node = (function () { | |
function Node(node, parent) { | |
_classCallCheck(this, Node); | |
this.parent = parent; | |
this.node = node; | |
} | |
/** | |
* Add all static methods from `Node` to `Node.prototype`. | |
*/ | |
/** | |
* Test if `node` can have whitespace set by the user. | |
*/ | |
Node.isUserWhitespacable = function isUserWhitespacable(node) { | |
return t.isUserWhitespacable(node); | |
}; | |
/** | |
* Test if a `node` requires whitespace. | |
*/ | |
Node.needsWhitespace = function needsWhitespace(node, parent, type) { | |
if (!node) return 0; | |
if (t.isExpressionStatement(node)) { | |
node = node.expression; | |
} | |
var linesInfo = find(_whitespace2["default"].nodes, node, parent); | |
if (!linesInfo) { | |
var items = find(_whitespace2["default"].list, node, parent); | |
if (items) { | |
for (var i = 0; i < items.length; i++) { | |
linesInfo = Node.needsWhitespace(items[i], node, type); | |
if (linesInfo) break; | |
} | |
} | |
} | |
return linesInfo && linesInfo[type] || 0; | |
}; | |
/** | |
* Test if a `node` requires whitespace before it. | |
*/ | |
Node.needsWhitespaceBefore = function needsWhitespaceBefore(node, parent) { | |
return Node.needsWhitespace(node, parent, "before"); | |
}; | |
/** | |
* Test if a `note` requires whitespace after it. | |
*/ | |
Node.needsWhitespaceAfter = function needsWhitespaceAfter(node, parent) { | |
return Node.needsWhitespace(node, parent, "after"); | |
}; | |
/** | |
* Test if a `node` needs parentheses around it. | |
*/ | |
Node.needsParens = function needsParens(node, parent) { | |
if (!parent) return false; | |
if (t.isNewExpression(parent) && parent.callee === node) { | |
if (t.isCallExpression(node)) return true; | |
var hasCall = _lodashCollectionSome2["default"](node, function (val) { | |
return t.isCallExpression(val); | |
}); | |
if (hasCall) return true; | |
} | |
return find(parens, node, parent); | |
}; | |
return Node; | |
})(); | |
exports["default"] = Node; | |
_lodashCollectionEach2["default"](Node, function (fn, key) { | |
Node.prototype[key] = function () { | |
// Avoid leaking arguments to prevent deoptimization | |
var args = new Array(arguments.length + 2); | |
args[0] = this.node; | |
args[1] = this.parent; | |
for (var i = 0; i < args.length; i++) { | |
args[i + 2] = arguments[i]; | |
} | |
return Node[key].apply(null, args); | |
}; | |
}); | |
module.exports = exports["default"]; | |
},{"179":179,"32":32,"34":34,"411":411,"416":416}],32:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.NullableTypeAnnotation = NullableTypeAnnotation; | |
exports.UpdateExpression = UpdateExpression; | |
exports.ObjectExpression = ObjectExpression; | |
exports.Binary = Binary; | |
exports.BinaryExpression = BinaryExpression; | |
exports.SequenceExpression = SequenceExpression; | |
exports.YieldExpression = YieldExpression; | |
exports.ClassExpression = ClassExpression; | |
exports.UnaryLike = UnaryLike; | |
exports.FunctionExpression = FunctionExpression; | |
exports.ConditionalExpression = ConditionalExpression; | |
exports.AssignmentExpression = AssignmentExpression; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _lodashCollectionEach = _dereq_(411); | |
var _lodashCollectionEach2 = _interopRequireDefault(_lodashCollectionEach); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* Create a mapping of operators to precendence. | |
* | |
* @example | |
* { "==": 6, "+": 9 } | |
*/ | |
var PRECEDENCE = {}; | |
_lodashCollectionEach2["default"]([["||"], ["&&"], ["|"], ["^"], ["&"], ["==", "===", "!=", "!=="], ["<", ">", "<=", ">=", "in", "instanceof"], [">>", "<<", ">>>"], ["+", "-"], ["*", "/", "%"], ["**"]], function (tier, i) { | |
_lodashCollectionEach2["default"](tier, function (op) { | |
PRECEDENCE[op] = i; | |
}); | |
}); | |
/** | |
* Test if NullableTypeAnnotation needs parentheses. | |
*/ | |
function NullableTypeAnnotation(node, parent) { | |
return t.isArrayTypeAnnotation(parent); | |
} | |
/** | |
* Alias NullableTypeAnnotation test as FunctionTypeAnnotation. | |
*/ | |
exports.FunctionTypeAnnotation = NullableTypeAnnotation; | |
/** | |
* Test if UpdateExpression needs parentheses. | |
*/ | |
function UpdateExpression(node, parent) { | |
if (t.isMemberExpression(parent) && parent.object === node) { | |
// (foo++).test() | |
return true; | |
} | |
} | |
/** | |
* Test if ObjectExpression needs parentheses. | |
*/ | |
function ObjectExpression(node, parent) { | |
if (t.isExpressionStatement(parent)) { | |
// ({ foo: "bar" }); | |
return true; | |
} | |
if (t.isMemberExpression(parent) && parent.object === node) { | |
// ({ foo: "bar" }).foo | |
return true; | |
} | |
return false; | |
} | |
/** | |
* Test if Binary needs parentheses. | |
*/ | |
function Binary(node, parent) { | |
if ((t.isCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node) { | |
return true; | |
} | |
if (t.isUnaryLike(parent)) { | |
return true; | |
} | |
if (t.isMemberExpression(parent) && parent.object === node) { | |
return true; | |
} | |
if (t.isBinary(parent)) { | |
var parentOp = parent.operator; | |
var parentPos = PRECEDENCE[parentOp]; | |
var nodeOp = node.operator; | |
var nodePos = PRECEDENCE[nodeOp]; | |
if (parentPos > nodePos) { | |
return true; | |
} | |
if (parentPos === nodePos && parent.right === node) { | |
return true; | |
} | |
} | |
} | |
/** | |
* Test if BinaryExpression needs parentheses. | |
*/ | |
function BinaryExpression(node, parent) { | |
if (node.operator === "in") { | |
// var i = (1 in []); | |
if (t.isVariableDeclarator(parent)) { | |
return true; | |
} | |
// for ((1 in []);;); | |
if (t.isFor(parent)) { | |
return true; | |
} | |
} | |
} | |
/** | |
* Test if SequenceExpression needs parentheses. | |
*/ | |
function SequenceExpression(node, parent) { | |
if (t.isForStatement(parent)) { | |
// Although parentheses wouldn't hurt around sequence | |
// expressions in the head of for loops, traditional style | |
// dictates that e.g. i++, j++ should not be wrapped with | |
// parentheses. | |
return false; | |
} | |
if (t.isExpressionStatement(parent) && parent.expression === node) { | |
return false; | |
} | |
// Otherwise err on the side of overparenthesization, adding | |
// explicit exceptions above if this proves overzealous. | |
return true; | |
} | |
/** | |
* Test if YieldExpression needs parentheses. | |
*/ | |
function YieldExpression(node, parent) { | |
return t.isBinary(parent) || t.isUnaryLike(parent) || t.isCallExpression(parent) || t.isMemberExpression(parent) || t.isNewExpression(parent) || t.isConditionalExpression(parent) || t.isYieldExpression(parent); | |
} | |
/** | |
* Test if ClassExpression needs parentheses. | |
*/ | |
function ClassExpression(node, parent) { | |
return t.isExpressionStatement(parent); | |
} | |
/** | |
* Test if UnaryLike needs parentheses. | |
*/ | |
function UnaryLike(node, parent) { | |
return t.isMemberExpression(parent) && parent.object === node; | |
} | |
/** | |
* Test if FunctionExpression needs parentheses. | |
*/ | |
function FunctionExpression(node, parent) { | |
// function () {}; | |
if (t.isExpressionStatement(parent)) { | |
return true; | |
} | |
// (function test() {}).name; | |
if (t.isMemberExpression(parent) && parent.object === node) { | |
return true; | |
} | |
// (function () {})(); | |
if (t.isCallExpression(parent) && parent.callee === node) { | |
return true; | |
} | |
} | |
/** | |
* Test if ConditionalExpression needs parentheses. | |
*/ | |
function ConditionalExpression(node, parent) { | |
if (t.isUnaryLike(parent)) { | |
return true; | |
} | |
if (t.isBinary(parent)) { | |
return true; | |
} | |
if (t.isCallExpression(parent) || t.isNewExpression(parent)) { | |
if (parent.callee === node) { | |
return true; | |
} | |
} | |
if (t.isConditionalExpression(parent) && parent.test === node) { | |
return true; | |
} | |
if (t.isMemberExpression(parent) && parent.object === node) { | |
return true; | |
} | |
return false; | |
} | |
/** | |
* Test if AssignmentExpression needs parentheses. | |
*/ | |
function AssignmentExpression(node) { | |
if (t.isObjectPattern(node.left)) { | |
return true; | |
} else { | |
return ConditionalExpression.apply(undefined, arguments); | |
} | |
} | |
},{"179":179,"411":411}],33:[function(_dereq_,module,exports){ | |
/** | |
* Printer for nodes, needs a `generator` and a `parent`. | |
*/ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var NodePrinter = (function () { | |
function NodePrinter(generator, parent) { | |
_classCallCheck(this, NodePrinter); | |
this.generator = generator; | |
this.parent = parent; | |
} | |
/** | |
* Description | |
*/ | |
NodePrinter.prototype.printInnerComments = function printInnerComments() { | |
if (!this.parent.innerComments) return; | |
var gen = this.generator; | |
gen.indent(); | |
gen._printComments(this.parent.innerComments); | |
gen.dedent(); | |
}; | |
/** | |
* Print a plain node. | |
*/ | |
NodePrinter.prototype.plain = function plain(node, opts) { | |
return this.generator.print(node, this.parent, opts); | |
}; | |
/** | |
* Print a sequence of nodes as statements. | |
*/ | |
NodePrinter.prototype.sequence = function sequence(nodes) { | |
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | |
opts.statement = true; | |
return this.generator.printJoin(this, nodes, opts); | |
}; | |
/** | |
* Print a sequence of nodes as expressions. | |
*/ | |
NodePrinter.prototype.join = function join(nodes, opts) { | |
return this.generator.printJoin(this, nodes, opts); | |
}; | |
/** | |
* Print a list of nodes, with a customizable separator (defaults to ","). | |
*/ | |
NodePrinter.prototype.list = function list(items) { | |
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | |
if (opts.separator == null) { | |
opts.separator = ","; | |
if (!this.generator.format.compact) opts.separator += " "; | |
} | |
return this.join(items, opts); | |
}; | |
/** | |
* Print a block-like node. | |
*/ | |
NodePrinter.prototype.block = function block(node) { | |
return this.generator.printBlock(this, node); | |
}; | |
/** | |
* Print node and indent comments. | |
*/ | |
NodePrinter.prototype.indentOnComments = function indentOnComments(node) { | |
return this.generator.printAndIndentOnComments(this, node); | |
}; | |
return NodePrinter; | |
})(); | |
exports["default"] = NodePrinter; | |
module.exports = exports["default"]; | |
},{}],34:[function(_dereq_,module,exports){ | |
"use strict"; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _lodashLangIsBoolean = _dereq_(498); | |
var _lodashLangIsBoolean2 = _interopRequireDefault(_lodashLangIsBoolean); | |
var _lodashCollectionEach = _dereq_(411); | |
var _lodashCollectionEach2 = _interopRequireDefault(_lodashCollectionEach); | |
var _lodashCollectionMap = _dereq_(414); | |
var _lodashCollectionMap2 = _interopRequireDefault(_lodashCollectionMap); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* Crawl a node to test if it contains a CallExpression, a Function, or a Helper. | |
* | |
* @example | |
* crawl(node) | |
* // { hasCall: false, hasFunction: true, hasHelper: false } | |
*/ | |
function crawl(node) { | |
var state = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | |
if (t.isMemberExpression(node)) { | |
crawl(node.object, state); | |
if (node.computed) crawl(node.property, state); | |
} else if (t.isBinary(node) || t.isAssignmentExpression(node)) { | |
crawl(node.left, state); | |
crawl(node.right, state); | |
} else if (t.isCallExpression(node)) { | |
state.hasCall = true; | |
crawl(node.callee, state); | |
} else if (t.isFunction(node)) { | |
state.hasFunction = true; | |
} else if (t.isIdentifier(node)) { | |
state.hasHelper = state.hasHelper || isHelper(node.callee); | |
} | |
return state; | |
} | |
/** | |
* Test if a node is or has a helper. | |
*/ | |
function isHelper(node) { | |
if (t.isMemberExpression(node)) { | |
return isHelper(node.object) || isHelper(node.property); | |
} else if (t.isIdentifier(node)) { | |
return node.name === "require" || node.name[0] === "_"; | |
} else if (t.isCallExpression(node)) { | |
return isHelper(node.callee); | |
} else if (t.isBinary(node) || t.isAssignmentExpression(node)) { | |
return t.isIdentifier(node.left) && isHelper(node.left) || isHelper(node.right); | |
} else { | |
return false; | |
} | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function isType(node) { | |
return t.isLiteral(node) || t.isObjectExpression(node) || t.isArrayExpression(node) || t.isIdentifier(node) || t.isMemberExpression(node); | |
} | |
/** | |
* Tests for node types that need whitespace. | |
*/ | |
exports.nodes = { | |
/** | |
* Test if AssignmentExpression needs whitespace. | |
*/ | |
AssignmentExpression: function AssignmentExpression(node) { | |
var state = crawl(node.right); | |
if (state.hasCall && state.hasHelper || state.hasFunction) { | |
return { | |
before: state.hasFunction, | |
after: true | |
}; | |
} | |
}, | |
/** | |
* Test if SwitchCase needs whitespace. | |
*/ | |
SwitchCase: function SwitchCase(node, parent) { | |
return { | |
before: node.consequent.length || parent.cases[0] === node | |
}; | |
}, | |
/** | |
* Test if LogicalExpression needs whitespace. | |
*/ | |
LogicalExpression: function LogicalExpression(node) { | |
if (t.isFunction(node.left) || t.isFunction(node.right)) { | |
return { | |
after: true | |
}; | |
} | |
}, | |
/** | |
* Test if Literal needs whitespace. | |
*/ | |
Literal: function Literal(node) { | |
if (node.value === "use strict") { | |
return { | |
after: true | |
}; | |
} | |
}, | |
/** | |
* Test if CallExpression needs whitespace. | |
*/ | |
CallExpression: function CallExpression(node) { | |
if (t.isFunction(node.callee) || isHelper(node)) { | |
return { | |
before: true, | |
after: true | |
}; | |
} | |
}, | |
/** | |
* Test if VariableDeclaration needs whitespace. | |
*/ | |
VariableDeclaration: function VariableDeclaration(node) { | |
for (var i = 0; i < node.declarations.length; i++) { | |
var declar = node.declarations[i]; | |
var enabled = isHelper(declar.id) && !isType(declar.init); | |
if (!enabled) { | |
var state = crawl(declar.init); | |
enabled = isHelper(declar.init) && state.hasCall || state.hasFunction; | |
} | |
if (enabled) { | |
return { | |
before: true, | |
after: true | |
}; | |
} | |
} | |
}, | |
/** | |
* Test if IfStatement needs whitespace. | |
*/ | |
IfStatement: function IfStatement(node) { | |
if (t.isBlockStatement(node.consequent)) { | |
return { | |
before: true, | |
after: true | |
}; | |
} | |
} | |
}; | |
/** | |
* Test if Property or SpreadProperty needs whitespace. | |
*/ | |
exports.nodes.Property = exports.nodes.SpreadProperty = function (node, parent) { | |
if (parent.properties[0] === node) { | |
return { | |
before: true | |
}; | |
} | |
}; | |
/** | |
* Returns lists from node types that need whitespace. | |
*/ | |
exports.list = { | |
/** | |
* Return VariableDeclaration declarations init properties. | |
*/ | |
VariableDeclaration: function VariableDeclaration(node) { | |
return _lodashCollectionMap2["default"](node.declarations, "init"); | |
}, | |
/** | |
* Return VariableDeclaration elements. | |
*/ | |
ArrayExpression: function ArrayExpression(node) { | |
return node.elements; | |
}, | |
/** | |
* Return VariableDeclaration properties. | |
*/ | |
ObjectExpression: function ObjectExpression(node) { | |
return node.properties; | |
} | |
}; | |
/** | |
* Add whitespace tests for nodes and their aliases. | |
*/ | |
_lodashCollectionEach2["default"]({ | |
Function: true, | |
Class: true, | |
Loop: true, | |
LabeledStatement: true, | |
SwitchStatement: true, | |
TryStatement: true | |
}, function (amounts, type) { | |
if (_lodashLangIsBoolean2["default"](amounts)) { | |
amounts = { after: amounts, before: amounts }; | |
} | |
_lodashCollectionEach2["default"]([type].concat(t.FLIPPED_ALIAS_KEYS[type] || []), function (type) { | |
exports.nodes[type] = function () { | |
return amounts; | |
}; | |
}); | |
}); | |
},{"179":179,"411":411,"414":414,"498":498}],35:[function(_dereq_,module,exports){ | |
/** | |
* Track current position in code generation. | |
*/ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var Position = (function () { | |
function Position() { | |
_classCallCheck(this, Position); | |
this.line = 1; | |
this.column = 0; | |
} | |
/** | |
* Push a string to the current position, mantaining the current line and column. | |
*/ | |
Position.prototype.push = function push(str) { | |
for (var i = 0; i < str.length; i++) { | |
if (str[i] === "\n") { | |
this.line++; | |
this.column = 0; | |
} else { | |
this.column++; | |
} | |
} | |
}; | |
/** | |
* Unshift a string from the current position, mantaining the current line and column. | |
*/ | |
Position.prototype.unshift = function unshift(str) { | |
for (var i = 0; i < str.length; i++) { | |
if (str[i] === "\n") { | |
this.line--; | |
} else { | |
this.column--; | |
} | |
} | |
}; | |
return Position; | |
})(); | |
exports["default"] = Position; | |
module.exports = exports["default"]; | |
},{}],36:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _sourceMap = _dereq_(599); | |
var _sourceMap2 = _interopRequireDefault(_sourceMap); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* Build a sourcemap. | |
*/ | |
var SourceMap = (function () { | |
function SourceMap(position, opts, code) { | |
_classCallCheck(this, SourceMap); | |
this.position = position; | |
this.opts = opts; | |
if (opts.sourceMaps) { | |
this.map = new _sourceMap2["default"].SourceMapGenerator({ | |
file: opts.sourceMapTarget, | |
sourceRoot: opts.sourceRoot | |
}); | |
this.map.setSourceContent(opts.sourceFileName, code); | |
} else { | |
this.map = null; | |
} | |
} | |
/** | |
* Get the sourcemap. | |
*/ | |
SourceMap.prototype.get = function get() { | |
var map = this.map; | |
if (map) { | |
return map.toJSON(); | |
} else { | |
return map; | |
} | |
}; | |
/** | |
* Mark a node's generated position, and add it to the sourcemap. | |
*/ | |
SourceMap.prototype.mark = function mark(node, type) { | |
var loc = node.loc; | |
if (!loc) return; // no location info | |
var map = this.map; | |
if (!map) return; // no source map | |
if (t.isProgram(node) || t.isFile(node)) return; // illegal mapping nodes | |
var position = this.position; | |
var generated = { | |
line: position.line, | |
column: position.column | |
}; | |
var original = loc[type]; | |
map.addMapping({ | |
source: this.opts.sourceFileName, | |
generated: generated, | |
original: original | |
}); | |
}; | |
return SourceMap; | |
})(); | |
exports["default"] = SourceMap; | |
module.exports = exports["default"]; | |
},{"179":179,"599":599}],37:[function(_dereq_,module,exports){ | |
/** | |
* Returns `i`th number from `base`, continuing from 0 when `max` is reached. | |
* Useful for shifting `for` loop by a fixed number but going over all items. | |
* | |
* @param {Number} i Current index in the loop | |
* @param {Number} base Start index for which to return 0 | |
* @param {Number} max Array length | |
* @returns {Number} shiftedIndex | |
*/ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
function getLookupIndex(i, base, max) { | |
i += base; | |
if (i >= max) { | |
i -= max; | |
} | |
return i; | |
} | |
/** | |
* Get whitespace around tokens. | |
*/ | |
var Whitespace = (function () { | |
function Whitespace(tokens) { | |
_classCallCheck(this, Whitespace); | |
this.tokens = tokens; | |
this.used = {}; | |
// Profiling this code shows that while generator passes over it, indexes | |
// returned by `getNewlinesBefore` and `getNewlinesAfter` are always increasing. | |
// We use this implementation detail for an optimization: instead of always | |
// starting to look from `this.tokens[0]`, we will start `for` loops from the | |
// previous successful match. We will enumerate all tokensโbut the common | |
// case will be much faster. | |
this._lastFoundIndex = 0; | |
} | |
/** | |
* Count all the newlines before a node. | |
*/ | |
Whitespace.prototype.getNewlinesBefore = function getNewlinesBefore(node) { | |
var startToken; | |
var endToken; | |
var tokens = this.tokens; | |
for (var j = 0; j < tokens.length; j++) { | |
// optimize for forward traversal by shifting for loop index | |
var i = getLookupIndex(j, this._lastFoundIndex, this.tokens.length); | |
var token = tokens[i]; | |
// this is the token this node starts with | |
if (node.start === token.start) { | |
startToken = tokens[i - 1]; | |
endToken = token; | |
this._lastFoundIndex = i; | |
break; | |
} | |
} | |
return this.getNewlinesBetween(startToken, endToken); | |
}; | |
/** | |
* Count all the newlines after a node. | |
*/ | |
Whitespace.prototype.getNewlinesAfter = function getNewlinesAfter(node) { | |
var startToken; | |
var endToken; | |
var tokens = this.tokens; | |
for (var j = 0; j < tokens.length; j++) { | |
// optimize for forward traversal by shifting for loop index | |
var i = getLookupIndex(j, this._lastFoundIndex, this.tokens.length); | |
var token = tokens[i]; | |
// this is the token this node ends with | |
if (node.end === token.end) { | |
startToken = token; | |
endToken = tokens[i + 1]; | |
if (endToken.type.label === ",") endToken = tokens[i + 2]; | |
this._lastFoundIndex = i; | |
break; | |
} | |
} | |
if (endToken && endToken.type.label === "eof") { | |
return 1; | |
} else { | |
var lines = this.getNewlinesBetween(startToken, endToken); | |
if (node.type === "CommentLine" && !lines) { | |
// line comment | |
return 1; | |
} else { | |
return lines; | |
} | |
} | |
}; | |
/** | |
* Count all the newlines between two tokens. | |
*/ | |
Whitespace.prototype.getNewlinesBetween = function getNewlinesBetween(startToken, endToken) { | |
if (!endToken || !endToken.loc) return 0; | |
var start = startToken ? startToken.loc.end.line : 1; | |
var end = endToken.loc.start.line; | |
var lines = 0; | |
for (var line = start; line < end; line++) { | |
if (typeof this.used[line] === "undefined") { | |
this.used[line] = true; | |
lines++; | |
} | |
} | |
return lines; | |
}; | |
return Whitespace; | |
})(); | |
exports["default"] = Whitespace; | |
module.exports = exports["default"]; | |
},{}],38:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _lineNumbers = _dereq_(403); | |
var _lineNumbers2 = _interopRequireDefault(_lineNumbers); | |
var _repeating = _dereq_(584); | |
var _repeating2 = _interopRequireDefault(_repeating); | |
var _jsTokens = _dereq_(401); | |
var _jsTokens2 = _interopRequireDefault(_jsTokens); | |
var _esutils = _dereq_(395); | |
var _esutils2 = _interopRequireDefault(_esutils); | |
var _chalk = _dereq_(200); | |
var _chalk2 = _interopRequireDefault(_chalk); | |
/** | |
* Chalk styles for token types. | |
*/ | |
var defs = { | |
string: _chalk2["default"].red, | |
punctuator: _chalk2["default"].bold, | |
curly: _chalk2["default"].green, | |
parens: _chalk2["default"].blue.bold, | |
square: _chalk2["default"].yellow, | |
keyword: _chalk2["default"].cyan, | |
number: _chalk2["default"].magenta, | |
regex: _chalk2["default"].magenta, | |
comment: _chalk2["default"].grey, | |
invalid: _chalk2["default"].inverse | |
}; | |
/** | |
* RegExp to test for newlines in terminal. | |
*/ | |
var NEWLINE = /\r\n|[\n\r\u2028\u2029]/; | |
/** | |
* Get the type of token, specifying punctuator type. | |
*/ | |
function getTokenType(match) { | |
var token = _jsTokens2["default"].matchToToken(match); | |
if (token.type === "name" && _esutils2["default"].keyword.isReservedWordES6(token.value)) { | |
return "keyword"; | |
} | |
if (token.type === "punctuator") { | |
switch (token.value) { | |
case "{": | |
case "}": | |
return "curly"; | |
case "(": | |
case ")": | |
return "parens"; | |
case "[": | |
case "]": | |
return "square"; | |
} | |
} | |
return token.type; | |
} | |
/** | |
* Highlight `text`. | |
*/ | |
function highlight(text) { | |
return text.replace(_jsTokens2["default"], function () { | |
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | |
args[_key] = arguments[_key]; | |
} | |
var type = getTokenType(args); | |
var colorize = defs[type]; | |
if (colorize) { | |
return args[0].split(NEWLINE).map(function (str) { | |
return colorize(str); | |
}).join("\n"); | |
} else { | |
return args[0]; | |
} | |
}); | |
} | |
/** | |
* Create a code frame, adding line numbers, code highlighting, and pointing to a given position. | |
*/ | |
exports["default"] = function (lines, lineNumber, colNumber) { | |
var opts = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | |
colNumber = Math.max(colNumber, 0); | |
var highlighted = opts.highlightCode && _chalk2["default"].supportsColor; | |
if (highlighted) lines = highlight(lines); | |
lines = lines.split(NEWLINE); | |
var start = Math.max(lineNumber - 3, 0); | |
var end = Math.min(lines.length, lineNumber + 3); | |
if (!lineNumber && !colNumber) { | |
start = 0; | |
end = lines.length; | |
} | |
var frame = _lineNumbers2["default"](lines.slice(start, end), { | |
start: start + 1, | |
before: " ", | |
after: " | ", | |
transform: function transform(params) { | |
if (params.number !== lineNumber) { | |
return; | |
} | |
if (colNumber) { | |
params.line += "\n" + params.before + _repeating2["default"](" ", params.width) + params.after + _repeating2["default"](" ", colNumber - 1) + "^"; | |
} | |
params.before = params.before.replace(/^./, ">"); | |
} | |
}).join("\n"); | |
if (highlighted) { | |
return _chalk2["default"].reset(frame); | |
} else { | |
return frame; | |
} | |
}; | |
module.exports = exports["default"]; | |
},{"200":200,"395":395,"401":401,"403":403,"584":584}],39:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _lodashObjectMerge = _dereq_(515); | |
var _lodashObjectMerge2 = _interopRequireDefault(_lodashObjectMerge); | |
/** | |
* Merge options. | |
*/ | |
exports["default"] = function (dest, src) { | |
if (!dest || !src) return; | |
return _lodashObjectMerge2["default"](dest, src, function (a, b) { | |
if (b && Array.isArray(a)) { | |
var c = a.slice(0); | |
for (var _iterator = b, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | |
var _ref; | |
if (_isArray) { | |
if (_i >= _iterator.length) break; | |
_ref = _iterator[_i++]; | |
} else { | |
_i = _iterator.next(); | |
if (_i.done) break; | |
_ref = _i.value; | |
} | |
var v = _ref; | |
if (a.indexOf(v) < 0) { | |
c.push(v); | |
} | |
} | |
return c; | |
} | |
}); | |
}; | |
module.exports = exports["default"]; | |
},{"515":515}],40:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* Normalize an AST. | |
* | |
* - Wrap `Program` node with a `File` node. | |
*/ | |
exports["default"] = function (ast, comments, tokens) { | |
if (ast && ast.type === "Program") { | |
return t.file(ast, comments || [], tokens || []); | |
} else { | |
throw new Error("Not a valid ast?"); | |
} | |
}; | |
module.exports = exports["default"]; | |
},{"179":179}],41:[function(_dereq_,module,exports){ | |
/** | |
* Create an object with a `null` prototype. | |
*/ | |
"use strict"; | |
exports.__esModule = true; | |
exports["default"] = function () { | |
return Object.create(null); | |
}; | |
module.exports = exports["default"]; | |
},{}],42:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _babylon = _dereq_(605); | |
var babylon = _interopRequireWildcard(_babylon); | |
/** | |
* Parse `code` with normalized options, collecting tokens and comments. | |
*/ | |
exports["default"] = function (code) { | |
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | |
var parseOpts = { | |
allowImportExportEverywhere: opts.looseModules, | |
allowReturnOutsideFunction: opts.looseModules, | |
allowHashBang: true, | |
ecmaVersion: 6, | |
strictMode: opts.strictMode, | |
sourceType: opts.sourceType, | |
locations: true, | |
features: opts.features || {}, | |
plugins: opts.plugins || {} | |
}; | |
if (opts.nonStandard) { | |
parseOpts.plugins.jsx = true; | |
parseOpts.plugins.flow = true; | |
} | |
return babylon.parse(code, parseOpts); | |
}; | |
module.exports = exports["default"]; | |
},{"605":605}],43:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.get = get; | |
exports.parseArgs = parseArgs; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _util = _dereq_(13); | |
var util = _interopRequireWildcard(_util); | |
/** | |
* Mapping of messages to be used in Babel. | |
* Messages can include $0-style placeholders. | |
*/ | |
var MESSAGES = { | |
tailCallReassignmentDeopt: "Function reference has been reassigned, so it will probably be dereferenced, therefore we can't optimise this with confidence", | |
JSXNamespacedTags: "Namespace tags are not supported. ReactJSX is not XML.", | |
classesIllegalBareSuper: "Illegal use of bare super", | |
classesIllegalSuperCall: "Direct super call is illegal in non-constructor, use super.$1() instead", | |
scopeDuplicateDeclaration: "Duplicate declaration $1", | |
settersNoRest: "Setters aren't allowed to have a rest", | |
noAssignmentsInForHead: "No assignments allowed in for-in/of head", | |
expectedMemberExpressionOrIdentifier: "Expected type MemberExpression or Identifier", | |
invalidParentForThisNode: "We don't know how to handle this node within the current parent - please open an issue", | |
readOnly: "$1 is read-only", | |
unknownForHead: "Unknown node type $1 in ForStatement", | |
didYouMean: "Did you mean $1?", | |
codeGeneratorDeopt: "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2.", | |
missingTemplatesDirectory: "no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues", | |
unsupportedOutputType: "Unsupported output type $1", | |
illegalMethodName: "Illegal method name $1", | |
lostTrackNodePath: "We lost track of this node's position, likely because the AST was directly manipulated", | |
modulesIllegalExportName: "Illegal export $1", | |
modulesDuplicateDeclarations: "Duplicate module declarations with the same source but in different scopes", | |
undeclaredVariable: "Reference to undeclared variable $1", | |
undeclaredVariableType: "Referencing a type alias outside of a type annotation", | |
undeclaredVariableSuggestion: "Reference to undeclared variable $1 - did you mean $2?", | |
traverseNeedsParent: "You must pass a scope and parentPath unless traversing a Program/File got a $1 node", | |
traverseVerifyRootFunction: "You passed `traverse()` a function when it expected a visitor object, are you sure you didn't mean `{ enter: Function }`?", | |
traverseVerifyVisitorProperty: "You passed `traverse()` a visitor object with the property $1 that has the invalid property $2", | |
traverseVerifyNodeType: "You gave us a visitor for the node type $1 but it's not a valid type", | |
pluginIllegalKind: "Illegal kind $1 for plugin $2", | |
pluginIllegalPosition: "Illegal position $1 for plugin $2", | |
pluginKeyCollision: "The plugin $1 collides with another of the same name", | |
pluginNotTransformer: "The plugin $1 didn't export a Plugin instance", | |
pluginUnknown: "Unknown plugin $1", | |
pluginNotFile: "Plugin $1 is resolving to a different Babel version than what is performing the transformation.", | |
pluginInvalidProperty: "Plugin $1 provided an invalid property of $2.", | |
pluginInvalidPropertyVisitor: "Define your visitor methods inside a `visitor` property like so:\n\n new Plugin(\"foobar\", {\n visitor: {\n // define your visitor methods here!\n }\n });\n" | |
}; | |
exports.MESSAGES = MESSAGES; | |
/** | |
* Get a message with $0 placeholders replaced by arguments. | |
*/ | |
function get(key) { | |
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | |
args[_key - 1] = arguments[_key]; | |
} | |
var msg = MESSAGES[key]; | |
if (!msg) throw new ReferenceError("Unknown message " + JSON.stringify(key)); | |
// stringify args | |
args = parseArgs(args); | |
// replace $0 placeholders with args | |
return msg.replace(/\$(\d+)/g, function (str, i) { | |
return args[--i]; | |
}); | |
} | |
/** | |
* Stingify arguments to be used inside messages. | |
*/ | |
function parseArgs(args) { | |
return args.map(function (val) { | |
if (val != null && val.inspect) { | |
return val.inspect(); | |
} else { | |
try { | |
return JSON.stringify(val) || val + ""; | |
} catch (e) { | |
return util.inspect(val); | |
} | |
} | |
}); | |
} | |
},{"13":13}],44:[function(_dereq_,module,exports){ | |
(function (global){ | |
"use strict"; | |
_dereq_(387); | |
_dereq_(577); | |
if (global._babelPolyfill) { | |
throw new Error("only one instance of babel/polyfill is allowed"); | |
} | |
global._babelPolyfill = true; | |
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | |
},{"387":387,"577":577}],45:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _generation = _dereq_(30); | |
var _generation2 = _interopRequireDefault(_generation); | |
var _messages = _dereq_(43); | |
var messages = _interopRequireWildcard(_messages); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _transformationFile = _dereq_(46); | |
var _transformationFile2 = _interopRequireDefault(_transformationFile); | |
var _lodashCollectionEach = _dereq_(411); | |
var _lodashCollectionEach2 = _interopRequireDefault(_lodashCollectionEach); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
function buildGlobal(namespace, builder) { | |
var body = []; | |
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body)); | |
var tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("helper-self-global")]))]); | |
body.push(t.variableDeclaration("var", [t.variableDeclarator(namespace, t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([])))])); | |
builder(body); | |
return tree; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function buildUmd(namespace, builder) { | |
var body = []; | |
body.push(t.variableDeclaration("var", [t.variableDeclarator(namespace, t.identifier("global"))])); | |
builder(body); | |
var container = util.template("umd-commonjs-strict", { | |
FACTORY_PARAMETERS: t.identifier("global"), | |
BROWSER_ARGUMENTS: t.assignmentExpression("=", t.memberExpression(t.identifier("root"), namespace), t.objectExpression({})), | |
COMMON_ARGUMENTS: t.identifier("exports"), | |
AMD_ARGUMENTS: t.arrayExpression([t.literal("exports")]), | |
FACTORY_BODY: body, | |
UMD_ROOT: t.identifier("this") | |
}); | |
return t.program([container]); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function buildVar(namespace, builder) { | |
var body = []; | |
body.push(t.variableDeclaration("var", [t.variableDeclarator(namespace, t.objectExpression({}))])); | |
builder(body); | |
return t.program(body); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function buildHelpers(body, namespace, whitelist) { | |
_lodashCollectionEach2["default"](_transformationFile2["default"].helpers, function (name) { | |
if (whitelist && whitelist.indexOf(name) === -1) return; | |
var key = t.identifier(t.toIdentifier(name)); | |
body.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(namespace, key), util.template("helper-" + name)))); | |
}); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
exports["default"] = function (whitelist) { | |
var outputType = arguments.length <= 1 || arguments[1] === undefined ? "global" : arguments[1]; | |
var namespace = t.identifier("babelHelpers"); | |
var builder = function builder(body) { | |
return buildHelpers(body, namespace, whitelist); | |
}; | |
var tree; | |
var build = ({ | |
global: buildGlobal, | |
umd: buildUmd, | |
"var": buildVar | |
})[outputType]; | |
if (build) { | |
tree = build(namespace, builder); | |
} else { | |
throw new Error(messages.get("unsupportedOutputType", outputType)); | |
} | |
return _generation2["default"](tree).code; | |
}; | |
module.exports = exports["default"]; | |
},{"179":179,"182":182,"30":30,"411":411,"43":43,"46":46}],46:[function(_dereq_,module,exports){ | |
(function (process){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _convertSourceMap = _dereq_(208); | |
var _convertSourceMap2 = _interopRequireDefault(_convertSourceMap); | |
var _modules = _dereq_(74); | |
var _modules2 = _interopRequireDefault(_modules); | |
var _optionsOptionManager = _dereq_(50); | |
var _optionsOptionManager2 = _interopRequireDefault(_optionsOptionManager); | |
var _pluginManager = _dereq_(52); | |
var _pluginManager2 = _interopRequireDefault(_pluginManager); | |
var _shebangRegex = _dereq_(587); | |
var _shebangRegex2 = _interopRequireDefault(_shebangRegex); | |
var _traversalPath = _dereq_(155); | |
var _traversalPath2 = _interopRequireDefault(_traversalPath); | |
var _lodashLangIsFunction = _dereq_(500); | |
var _lodashLangIsFunction2 = _interopRequireDefault(_lodashLangIsFunction); | |
var _sourceMap = _dereq_(599); | |
var _sourceMap2 = _interopRequireDefault(_sourceMap); | |
var _generation = _dereq_(30); | |
var _generation2 = _interopRequireDefault(_generation); | |
var _helpersCodeFrame = _dereq_(38); | |
var _helpersCodeFrame2 = _interopRequireDefault(_helpersCodeFrame); | |
var _lodashObjectDefaults = _dereq_(510); | |
var _lodashObjectDefaults2 = _interopRequireDefault(_lodashObjectDefaults); | |
var _lodashCollectionIncludes = _dereq_(413); | |
var _lodashCollectionIncludes2 = _interopRequireDefault(_lodashCollectionIncludes); | |
var _traversal = _dereq_(148); | |
var _traversal2 = _interopRequireDefault(_traversal); | |
var _tryResolve = _dereq_(602); | |
var _tryResolve2 = _interopRequireDefault(_tryResolve); | |
var _logger = _dereq_(47); | |
var _logger2 = _interopRequireDefault(_logger); | |
var _plugin = _dereq_(82); | |
var _plugin2 = _interopRequireDefault(_plugin); | |
var _helpersParse = _dereq_(42); | |
var _helpersParse2 = _interopRequireDefault(_helpersParse); | |
var _traversalHub = _dereq_(147); | |
var _traversalHub2 = _interopRequireDefault(_traversalHub); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _path = _dereq_(9); | |
var _path2 = _interopRequireDefault(_path); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var File = (function () { | |
function File(opts, pipeline) { | |
if (opts === undefined) opts = {}; | |
_classCallCheck(this, File); | |
this.transformerDependencies = {}; | |
this.dynamicImportTypes = {}; | |
this.dynamicImportIds = {}; | |
this.dynamicImports = []; | |
this.declarations = {}; | |
this.usedHelpers = {}; | |
this.dynamicData = {}; | |
this.data = {}; | |
this.ast = {}; | |
this.metadata = { | |
modules: { | |
imports: [], | |
exports: { | |
exported: [], | |
specifiers: [] | |
} | |
} | |
}; | |
this.hub = new _traversalHub2["default"](this); | |
this.pipeline = pipeline; | |
this.log = new _logger2["default"](this, opts.filename || "unknown"); | |
this.opts = this.initOptions(opts); | |
this.buildTransformers(); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.initOptions = function initOptions(opts) { | |
opts = new _optionsOptionManager2["default"](this.log, this.pipeline).init(opts); | |
if (opts.inputSourceMap) { | |
opts.sourceMaps = true; | |
} | |
if (opts.moduleId) { | |
opts.moduleIds = true; | |
} | |
opts.basename = _path2["default"].basename(opts.filename, _path2["default"].extname(opts.filename)); | |
opts.ignore = util.arrayify(opts.ignore, util.regexify); | |
if (opts.only) opts.only = util.arrayify(opts.only, util.regexify); | |
_lodashObjectDefaults2["default"](opts, { | |
moduleRoot: opts.sourceRoot | |
}); | |
_lodashObjectDefaults2["default"](opts, { | |
sourceRoot: opts.moduleRoot | |
}); | |
_lodashObjectDefaults2["default"](opts, { | |
filenameRelative: opts.filename | |
}); | |
_lodashObjectDefaults2["default"](opts, { | |
sourceFileName: opts.filenameRelative, | |
sourceMapTarget: opts.filenameRelative | |
}); | |
// | |
if (opts.externalHelpers) { | |
this.set("helpersNamespace", t.identifier("babelHelpers")); | |
} | |
return opts; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.isLoose = function isLoose(key) { | |
return _lodashCollectionIncludes2["default"](this.opts.loose, key); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.buildTransformers = function buildTransformers() { | |
var file = this; | |
var transformers = this.transformers = {}; | |
var secondaryStack = []; | |
var stack = []; | |
// build internal transformers | |
for (var key in this.pipeline.transformers) { | |
var transformer = this.pipeline.transformers[key]; | |
var pass = transformers[key] = transformer.buildPass(file); | |
if (pass.canTransform()) { | |
stack.push(pass); | |
if (transformer.metadata.secondPass) { | |
secondaryStack.push(pass); | |
} | |
if (transformer.manipulateOptions) { | |
transformer.manipulateOptions(file.opts, file); | |
} | |
} | |
} | |
// init plugins! | |
var beforePlugins = []; | |
var afterPlugins = []; | |
var pluginManager = new _pluginManager2["default"]({ | |
file: this, | |
transformers: this.transformers, | |
before: beforePlugins, | |
after: afterPlugins | |
}); | |
for (var i = 0; i < file.opts.plugins.length; i++) { | |
pluginManager.add(file.opts.plugins[i]); | |
} | |
stack = beforePlugins.concat(stack, afterPlugins); | |
// build transformer stack | |
this.uncollapsedTransformerStack = stack = stack.concat(secondaryStack); | |
// build dependency graph | |
var _arr = stack; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var pass = _arr[_i];var _arr2 = pass.plugin.dependencies; | |
for (var _i2 = 0; _i2 < _arr2.length; _i2++) { | |
var dep = _arr2[_i2]; | |
this.transformerDependencies[dep] = pass.key; | |
} | |
} | |
// collapse stack categories | |
this.transformerStack = this.collapseStack(stack); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.collapseStack = function collapseStack(_stack) { | |
var stack = []; | |
var ignore = []; | |
var _arr3 = _stack; | |
for (var _i3 = 0; _i3 < _arr3.length; _i3++) { | |
var pass = _arr3[_i3]; | |
// been merged | |
if (ignore.indexOf(pass) >= 0) continue; | |
var group = pass.plugin.metadata.group; | |
// can't merge | |
if (!pass.canTransform() || !group) { | |
stack.push(pass); | |
continue; | |
} | |
var mergeStack = []; | |
var _arr4 = _stack; | |
for (var _i4 = 0; _i4 < _arr4.length; _i4++) { | |
var _pass = _arr4[_i4]; | |
if (_pass.plugin.metadata.group === group) { | |
mergeStack.push(_pass); | |
ignore.push(_pass); | |
} | |
} | |
var visitors = []; | |
var _arr5 = mergeStack; | |
for (var _i5 = 0; _i5 < _arr5.length; _i5++) { | |
var _pass2 = _arr5[_i5]; | |
visitors.push(_pass2.plugin.visitor); | |
} | |
var visitor = _traversal2["default"].visitors.merge(visitors); | |
var mergePlugin = new _plugin2["default"](group, { visitor: visitor }); | |
stack.push(mergePlugin.buildPass(this)); | |
} | |
return stack; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.set = function set(key, val) { | |
return this.data[key] = val; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.setDynamic = function setDynamic(key, fn) { | |
this.dynamicData[key] = fn; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.get = function get(key) { | |
var data = this.data[key]; | |
if (data) { | |
return data; | |
} else { | |
var dynamic = this.dynamicData[key]; | |
if (dynamic) { | |
return this.set(key, dynamic()); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.resolveModuleSource = function resolveModuleSource(source) { | |
var resolveModuleSource = this.opts.resolveModuleSource; | |
if (resolveModuleSource) source = resolveModuleSource(source, this.opts.filename); | |
return source; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.addImport = function addImport(source, name, type) { | |
name = name || source; | |
var id = this.dynamicImportIds[name]; | |
if (!id) { | |
source = this.resolveModuleSource(source); | |
id = this.dynamicImportIds[name] = this.scope.generateUidIdentifier(name); | |
var specifiers = [t.importDefaultSpecifier(id)]; | |
var declar = t.importDeclaration(specifiers, t.literal(source)); | |
declar._blockHoist = 3; | |
if (type) { | |
var modules = this.dynamicImportTypes[type] = this.dynamicImportTypes[type] || []; | |
modules.push(declar); | |
} | |
if (this.transformers["es6.modules"].canTransform()) { | |
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports, this.scope); | |
this.moduleFormatter.hasLocalImports = true; | |
} else { | |
this.dynamicImports.push(declar); | |
} | |
} | |
return id; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.attachAuxiliaryComment = function attachAuxiliaryComment(node) { | |
var beforeComment = this.opts.auxiliaryCommentBefore; | |
if (beforeComment) { | |
node.leadingComments = node.leadingComments || []; | |
node.leadingComments.push({ | |
type: "CommentLine", | |
value: " " + beforeComment | |
}); | |
} | |
var afterComment = this.opts.auxiliaryCommentAfter; | |
if (afterComment) { | |
node.trailingComments = node.trailingComments || []; | |
node.trailingComments.push({ | |
type: "CommentLine", | |
value: " " + afterComment | |
}); | |
} | |
return node; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.addHelper = function addHelper(name) { | |
var isSolo = _lodashCollectionIncludes2["default"](File.soloHelpers, name); | |
if (!isSolo && !_lodashCollectionIncludes2["default"](File.helpers, name)) { | |
throw new ReferenceError("Unknown helper " + name); | |
} | |
var declar = this.declarations[name]; | |
if (declar) return declar; | |
this.usedHelpers[name] = true; | |
if (!isSolo) { | |
var generator = this.get("helperGenerator"); | |
var runtime = this.get("helpersNamespace"); | |
if (generator) { | |
return generator(name); | |
} else if (runtime) { | |
var id = t.identifier(t.toIdentifier(name)); | |
return t.memberExpression(runtime, id); | |
} | |
} | |
var ref = util.template("helper-" + name); | |
var uid = this.declarations[name] = this.scope.generateUidIdentifier(name); | |
if (t.isFunctionExpression(ref) && !ref.id) { | |
ref.body._compact = true; | |
ref._generated = true; | |
ref.id = uid; | |
ref.type = "FunctionDeclaration"; | |
this.attachAuxiliaryComment(ref); | |
this.path.unshiftContainer("body", ref); | |
} else { | |
ref._compact = true; | |
this.scope.push({ | |
id: uid, | |
init: ref, | |
unique: true | |
}); | |
} | |
return uid; | |
}; | |
File.prototype.addTemplateObject = function addTemplateObject(helperName, strings, raw) { | |
// Generate a unique name based on the string literals so we dedupe | |
// identical strings used in the program. | |
var stringIds = raw.elements.map(function (string) { | |
return string.value; | |
}); | |
var name = helperName + "_" + raw.elements.length + "_" + stringIds.join(","); | |
var declar = this.declarations[name]; | |
if (declar) return declar; | |
var uid = this.declarations[name] = this.scope.generateUidIdentifier("templateObject"); | |
var helperId = this.addHelper(helperName); | |
var init = t.callExpression(helperId, [strings, raw]); | |
init._compact = true; | |
this.scope.push({ | |
id: uid, | |
init: init, | |
_blockHoist: 1.9 // This ensures that we don't fail if not using function expression helpers | |
}); | |
return uid; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.errorWithNode = function errorWithNode(node, msg) { | |
var Error = arguments.length <= 2 || arguments[2] === undefined ? SyntaxError : arguments[2]; | |
var err; | |
var loc = node && (node.loc || node._loc); | |
if (loc) { | |
err = new Error("Line " + loc.start.line + ": " + msg); | |
err.loc = loc.start; | |
} else { | |
// todo: find errors with nodes inside to at least point to something | |
err = new Error("There's been an error on a dynamic node. This is almost certainly an internal error. Please report it."); | |
} | |
return err; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.mergeSourceMap = function mergeSourceMap(map) { | |
var opts = this.opts; | |
var inputMap = opts.inputSourceMap; | |
if (inputMap) { | |
map.sources[0] = inputMap.file; | |
var inputMapConsumer = new _sourceMap2["default"].SourceMapConsumer(inputMap); | |
var outputMapConsumer = new _sourceMap2["default"].SourceMapConsumer(map); | |
var outputMapGenerator = _sourceMap2["default"].SourceMapGenerator.fromSourceMap(outputMapConsumer); | |
outputMapGenerator.applySourceMap(inputMapConsumer); | |
var mergedMap = outputMapGenerator.toJSON(); | |
mergedMap.sources = inputMap.sources; | |
mergedMap.file = inputMap.file; | |
return mergedMap; | |
} | |
return map; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.getModuleFormatter = function getModuleFormatter(type) { | |
if (_lodashLangIsFunction2["default"](type) || !_modules2["default"][type]) { | |
this.log.deprecate("Custom module formatters are deprecated and will be removed in the next major. Please use Babel plugins instead."); | |
} | |
var ModuleFormatter = _lodashLangIsFunction2["default"](type) ? type : _modules2["default"][type]; | |
if (!ModuleFormatter) { | |
var loc = _tryResolve2["default"].relative(type); | |
if (loc) ModuleFormatter = _dereq_(loc); | |
} | |
if (!ModuleFormatter) { | |
throw new ReferenceError("Unknown module formatter type " + JSON.stringify(type)); | |
} | |
return new ModuleFormatter(this); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.parse = function parse(code) { | |
var opts = this.opts; | |
// | |
var parseOpts = { | |
highlightCode: opts.highlightCode, | |
nonStandard: opts.nonStandard, | |
sourceType: opts.sourceType, | |
filename: opts.filename, | |
plugins: {} | |
}; | |
var features = parseOpts.features = {}; | |
for (var key in this.transformers) { | |
var transformer = this.transformers[key]; | |
features[key] = transformer.canTransform(); | |
} | |
parseOpts.looseModules = this.isLoose("es6.modules"); | |
parseOpts.strictMode = features.strict; | |
this.log.debug("Parse start"); | |
var ast = _helpersParse2["default"](code, parseOpts); | |
this.log.debug("Parse stop"); | |
return ast; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype._addAst = function _addAst(ast) { | |
this.path = _traversalPath2["default"].get({ | |
hub: this.hub, | |
parentPath: null, | |
parent: ast, | |
container: ast, | |
key: "program" | |
}).setContext(); | |
this.scope = this.path.scope; | |
this.ast = ast; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.addAst = function addAst(ast) { | |
this.log.debug("Start set AST"); | |
this._addAst(ast); | |
this.log.debug("End set AST"); | |
this.log.debug("Start module formatter init"); | |
var modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules); | |
if (modFormatter.init && this.transformers["es6.modules"].canTransform()) { | |
modFormatter.init(); | |
} | |
this.log.debug("End module formatter init"); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.transform = function transform() { | |
this.call("pre"); | |
var _arr6 = this.transformerStack; | |
for (var _i6 = 0; _i6 < _arr6.length; _i6++) { | |
var pass = _arr6[_i6]; | |
pass.transform(); | |
} | |
this.call("post"); | |
return this.generate(); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.wrap = function wrap(code, callback) { | |
code = code + ""; | |
try { | |
if (this.shouldIgnore()) { | |
return this.makeResult({ code: code, ignored: true }); | |
} else { | |
return callback(); | |
} | |
} catch (err) { | |
if (err._babel) { | |
throw err; | |
} else { | |
err._babel = true; | |
} | |
var message = err.message = this.opts.filename + ": " + err.message; | |
var loc = err.loc; | |
if (loc) { | |
err.codeFrame = _helpersCodeFrame2["default"](code, loc.line, loc.column + 1, this.opts); | |
message += "\n" + err.codeFrame; | |
} | |
if (process.browser) { | |
// chrome has it's own pretty stringifier which doesn't use the stack property | |
// https://github.com/babel/babel/issues/2175 | |
err.message = message; | |
} | |
if (err.stack) { | |
var newStack = err.stack.replace(err.message, message); | |
try { | |
err.stack = newStack; | |
} catch (e) { | |
// `err.stack` may be a readonly property in some environments | |
} | |
} | |
throw err; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.addCode = function addCode(code) { | |
code = (code || "") + ""; | |
code = this.parseInputSourceMap(code); | |
this.code = code; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.parseCode = function parseCode() { | |
this.parseShebang(); | |
var ast = this.parse(this.code); | |
this.addAst(ast); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.shouldIgnore = function shouldIgnore() { | |
var opts = this.opts; | |
return util.shouldIgnore(opts.filename, opts.ignore, opts.only); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.call = function call(key) { | |
var _arr7 = this.uncollapsedTransformerStack; | |
for (var _i7 = 0; _i7 < _arr7.length; _i7++) { | |
var pass = _arr7[_i7]; | |
var fn = pass.plugin[key]; | |
if (fn) fn(this); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.parseInputSourceMap = function parseInputSourceMap(code) { | |
var opts = this.opts; | |
if (opts.inputSourceMap !== false) { | |
var inputMap = _convertSourceMap2["default"].fromSource(code); | |
if (inputMap) { | |
opts.inputSourceMap = inputMap.toObject(); | |
code = _convertSourceMap2["default"].removeComments(code); | |
} | |
} | |
return code; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.parseShebang = function parseShebang() { | |
var shebangMatch = _shebangRegex2["default"].exec(this.code); | |
if (shebangMatch) { | |
this.shebang = shebangMatch[0]; | |
this.code = this.code.replace(_shebangRegex2["default"], ""); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.makeResult = function makeResult(_ref) { | |
var code = _ref.code; | |
var _ref$map = _ref.map; | |
var map = _ref$map === undefined ? null : _ref$map; | |
var ast = _ref.ast; | |
var ignored = _ref.ignored; | |
var result = { | |
metadata: null, | |
ignored: !!ignored, | |
code: null, | |
ast: null, | |
map: map | |
}; | |
if (this.opts.code) { | |
result.code = code; | |
} | |
if (this.opts.ast) { | |
result.ast = ast; | |
} | |
if (this.opts.metadata) { | |
result.metadata = this.metadata; | |
result.metadata.usedHelpers = Object.keys(this.usedHelpers); | |
} | |
return result; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
File.prototype.generate = function generate() { | |
var opts = this.opts; | |
var ast = this.ast; | |
var result = { ast: ast }; | |
if (!opts.code) return this.makeResult(result); | |
this.log.debug("Generation start"); | |
var _result = _generation2["default"](ast, opts, this.code); | |
result.code = _result.code; | |
result.map = _result.map; | |
this.log.debug("Generation end"); | |
if (this.shebang) { | |
// add back shebang | |
result.code = this.shebang + "\n" + result.code; | |
} | |
if (result.map) { | |
result.map = this.mergeSourceMap(result.map); | |
} | |
if (opts.sourceMaps === "inline" || opts.sourceMaps === "both") { | |
result.code += "\n" + _convertSourceMap2["default"].fromObject(result.map).toComment(); | |
} | |
if (opts.sourceMaps === "inline") { | |
result.map = null; | |
} | |
return this.makeResult(result); | |
}; | |
_createClass(File, null, [{ | |
key: "helpers", | |
/** | |
* [Please add a description.] | |
*/ | |
value: ["inherits", "defaults", "create-class", "create-decorated-class", "create-decorated-object", "define-decorated-property-descriptor", "tagged-template-literal", "tagged-template-literal-loose", "to-array", "to-consumable-array", "sliced-to-array", "sliced-to-array-loose", "object-without-properties", "has-own", "slice", "bind", "define-property", "async-to-generator", "interop-export-wildcard", "interop-require-wildcard", "interop-require-default", "typeof", "extends", "get", "set", "new-arrow-check", "class-call-check", "object-destructuring-empty", "temporal-undefined", "temporal-assert-defined", "self-global", "typeof-react-element", "default-props", "instanceof", | |
// legacy | |
"interop-require"], | |
/** | |
* [Please add a description.] | |
*/ | |
enumerable: true | |
}, { | |
key: "soloHelpers", | |
value: [], | |
enumerable: true | |
}]); | |
return File; | |
})(); | |
exports["default"] = File; | |
module.exports = exports["default"]; | |
}).call(this,_dereq_(10)) | |
},{"10":10,"147":147,"148":148,"155":155,"179":179,"182":182,"208":208,"30":30,"38":38,"413":413,"42":42,"47":47,"50":50,"500":500,"510":510,"52":52,"587":587,"599":599,"602":602,"74":74,"82":82,"9":9}],47:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _debugNode = _dereq_(389); | |
var _debugNode2 = _interopRequireDefault(_debugNode); | |
var verboseDebug = _debugNode2["default"]("babel:verbose"); | |
var generalDebug = _debugNode2["default"]("babel"); | |
var seenDeprecatedMessages = []; | |
/** | |
* [Please add a description.] | |
*/ | |
var Logger = (function () { | |
function Logger(file, filename) { | |
_classCallCheck(this, Logger); | |
this.filename = filename; | |
this.file = file; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
Logger.prototype._buildMessage = function _buildMessage(msg) { | |
var parts = "[BABEL] " + this.filename; | |
if (msg) parts += ": " + msg; | |
return parts; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Logger.prototype.warn = function warn(msg) { | |
console.warn(this._buildMessage(msg)); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Logger.prototype.error = function error(msg) { | |
var Constructor = arguments.length <= 1 || arguments[1] === undefined ? Error : arguments[1]; | |
throw new Constructor(this._buildMessage(msg)); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Logger.prototype.deprecate = function deprecate(msg) { | |
if (this.file.opts && this.file.opts.suppressDeprecationMessages) return; | |
msg = this._buildMessage(msg); | |
// already seen this message | |
if (seenDeprecatedMessages.indexOf(msg) >= 0) return; | |
// make sure we don't see it again | |
seenDeprecatedMessages.push(msg); | |
console.error(msg); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Logger.prototype.verbose = function verbose(msg) { | |
if (verboseDebug.enabled) verboseDebug(this._buildMessage(msg)); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Logger.prototype.debug = function debug(msg) { | |
if (generalDebug.enabled) generalDebug(this._buildMessage(msg)); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Logger.prototype.deopt = function deopt(node, msg) { | |
this.debug(msg); | |
}; | |
return Logger; | |
})(); | |
exports["default"] = Logger; | |
module.exports = exports["default"]; | |
},{"389":389}],48:[function(_dereq_,module,exports){ | |
module.exports={ | |
"filename": { | |
"type": "filename", | |
"description": "filename to use when reading from stdin - this will be used in source-maps, errors etc", | |
"default": "unknown", | |
"shorthand": "f" | |
}, | |
"filenameRelative": { | |
"hidden": true, | |
"type": "string" | |
}, | |
"inputSourceMap": { | |
"hidden": true | |
}, | |
"extra": { | |
"hidden": true, | |
"default": {} | |
}, | |
"env": { | |
"hidden": true, | |
"default": {} | |
}, | |
"moduleId": { | |
"description": "specify a custom name for module ids", | |
"type": "string" | |
}, | |
"getModuleId": { | |
"hidden": true | |
}, | |
"retainLines": { | |
"type": "boolean", | |
"default": false, | |
"description": "retain line numbers - will result in really ugly code" | |
}, | |
"nonStandard": { | |
"type": "boolean", | |
"default": true, | |
"description": "enable/disable support for JSX and Flow (on by default)" | |
}, | |
"experimental": { | |
"type": "boolean", | |
"description": "allow use of experimental transformers", | |
"default": false | |
}, | |
"highlightCode": { | |
"description": "enable/disable ANSI syntax highlighting of code frames (on by default)", | |
"type": "boolean", | |
"default": true | |
}, | |
"suppressDeprecationMessages": { | |
"type": "boolean", | |
"default": false, | |
"hidden": true | |
}, | |
"resolveModuleSource": { | |
"hidden": true | |
}, | |
"stage": { | |
"description": "ECMAScript proposal stage version to allow [0-4]", | |
"shorthand": "e", | |
"type": "number", | |
"default": 2 | |
}, | |
"blacklist": { | |
"type": "transformerList", | |
"description": "blacklist of transformers to NOT use", | |
"shorthand": "b", | |
"default": [] | |
}, | |
"whitelist": { | |
"type": "transformerList", | |
"optional": true, | |
"description": "whitelist of transformers to ONLY use", | |
"shorthand": "l" | |
}, | |
"optional": { | |
"type": "transformerList", | |
"description": "list of optional transformers to enable", | |
"default": [] | |
}, | |
"modules": { | |
"type": "string", | |
"description": "module formatter type to use [common]", | |
"default": "common", | |
"shorthand": "m" | |
}, | |
"moduleIds": { | |
"type": "boolean", | |
"default": false, | |
"shorthand": "M", | |
"description": "insert an explicit id for modules" | |
}, | |
"loose": { | |
"type": "transformerList", | |
"description": "list of transformers to enable loose mode ON", | |
"shorthand": "L" | |
}, | |
"jsxPragma": { | |
"type": "string", | |
"description": "custom pragma to use with JSX (same functionality as @jsx comments)", | |
"default": "React.createElement", | |
"shorthand": "P" | |
}, | |
"plugins": { | |
"type": "list", | |
"description": "", | |
"default": [] | |
}, | |
"ignore": { | |
"type": "list", | |
"description": "list of glob paths to **not** compile", | |
"default": [] | |
}, | |
"only": { | |
"type": "list", | |
"description": "list of glob paths to **only** compile" | |
}, | |
"code": { | |
"hidden": true, | |
"default": true, | |
"type": "boolean" | |
}, | |
"metadata": { | |
"hidden": true, | |
"default": true, | |
"type": "boolean" | |
}, | |
"ast": { | |
"hidden": true, | |
"default": true, | |
"type": "boolean" | |
}, | |
"comments": { | |
"type": "boolean", | |
"default": true, | |
"description": "strip/output comments in generated output (on by default)" | |
}, | |
"shouldPrintComment": { | |
"hidden": true, | |
"description": "optional callback to control whether a comment should be inserted, when this is used the comments option is ignored" | |
}, | |
"compact": { | |
"type": "booleanString", | |
"default": "auto", | |
"description": "do not include superfluous whitespace characters and line terminators [true|false|auto]" | |
}, | |
"keepModuleIdExtensions": { | |
"type": "boolean", | |
"description": "keep extensions when generating module ids", | |
"default": false, | |
"shorthand": "k" | |
}, | |
"auxiliaryComment": { | |
"deprecated": "renamed to auxiliaryCommentBefore", | |
"shorthand": "a", | |
"alias": "auxiliaryCommentBefore" | |
}, | |
"auxiliaryCommentBefore": { | |
"type": "string", | |
"default": "", | |
"description": "attach a comment before all helper declarations and auxiliary code" | |
}, | |
"auxiliaryCommentAfter": { | |
"type": "string", | |
"default": "", | |
"description": "attach a comment after all helper declarations and auxiliary code" | |
}, | |
"externalHelpers": { | |
"type": "boolean", | |
"default": false, | |
"shorthand": "r", | |
"description": "uses a reference to `babelHelpers` instead of placing helpers at the top of your code." | |
}, | |
"metadataUsedHelpers": { | |
"deprecated": "Not required anymore as this is enabled by default", | |
"type": "boolean", | |
"default": false, | |
"hidden": true | |
}, | |
"sourceMap": { | |
"alias": "sourceMaps", | |
"hidden": true | |
}, | |
"sourceMaps": { | |
"type": "booleanString", | |
"description": "[true|false|inline]", | |
"default": false, | |
"shorthand": "s" | |
}, | |
"sourceMapName": { | |
"alias": "sourceMapTarget", | |
"description": "DEPRECATED - Please use sourceMapTarget" | |
}, | |
"sourceMapTarget": { | |
"type": "string", | |
"description": "set `file` on returned source map" | |
}, | |
"sourceFileName": { | |
"type": "string", | |
"description": "set `sources[0]` on returned source map" | |
}, | |
"sourceRoot": { | |
"type": "filename", | |
"description": "the root from which all sources are relative" | |
}, | |
"moduleRoot": { | |
"type": "filename", | |
"description": "optional prefix for the AMD module formatter that will be prepend to the filename on module definitions" | |
}, | |
"breakConfig": { | |
"type": "boolean", | |
"default": false, | |
"hidden": true, | |
"description": "stop trying to load .babelrc files" | |
}, | |
"babelrc": { | |
"description": "Specify a custom list of babelrc files to use", | |
"type": "list" | |
}, | |
"sourceType": { | |
"description": "", | |
"default": "module" | |
} | |
} | |
},{}],49:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.validateOption = validateOption; | |
exports.normaliseOptions = normaliseOptions; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _parsers = _dereq_(51); | |
var parsers = _interopRequireWildcard(_parsers); | |
var _config = _dereq_(48); | |
var _config2 = _interopRequireDefault(_config); | |
exports.config = _config2["default"]; | |
/** | |
* Validate an option. | |
*/ | |
function validateOption(key, val, pipeline) { | |
var opt = _config2["default"][key]; | |
var parser = opt && parsers[opt.type]; | |
if (parser && parser.validate) { | |
return parser.validate(key, val, pipeline); | |
} else { | |
return val; | |
} | |
} | |
/** | |
* Normalize all options. | |
*/ | |
function normaliseOptions() { | |
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | |
for (var key in options) { | |
var val = options[key]; | |
if (val == null) continue; | |
var opt = _config2["default"][key]; | |
if (!opt) continue; | |
var parser = parsers[opt.type]; | |
if (parser) val = parser(val); | |
options[key] = val; | |
} | |
return options; | |
} | |
},{"48":48,"51":51}],50:[function(_dereq_,module,exports){ | |
(function (process){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _index = _dereq_(49); | |
var _json5 = _dereq_(402); | |
var _json52 = _interopRequireDefault(_json5); | |
var _pathIsAbsolute = _dereq_(527); | |
var _pathIsAbsolute2 = _interopRequireDefault(_pathIsAbsolute); | |
var _pathExists = _dereq_(526); | |
var _pathExists2 = _interopRequireDefault(_pathExists); | |
var _lodashLangClone = _dereq_(494); | |
var _lodashLangClone2 = _interopRequireDefault(_lodashLangClone); | |
var _helpersMerge = _dereq_(39); | |
var _helpersMerge2 = _interopRequireDefault(_helpersMerge); | |
var _config = _dereq_(48); | |
var _config2 = _interopRequireDefault(_config); | |
var _path = _dereq_(9); | |
var _path2 = _interopRequireDefault(_path); | |
var _fs = _dereq_(1); | |
var _fs2 = _interopRequireDefault(_fs); | |
var existsCache = {}; | |
var jsonCache = {}; | |
var BABELIGNORE_FILENAME = ".babelignore"; | |
var BABELRC_FILENAME = ".babelrc"; | |
var PACKAGE_FILENAME = "package.json"; | |
function exists(filename) { | |
var cached = existsCache[filename]; | |
if (cached != null) { | |
return cached; | |
} else { | |
return existsCache[filename] = _pathExists2["default"].sync(filename); | |
} | |
} | |
var OptionManager = (function () { | |
function OptionManager(log, pipeline) { | |
_classCallCheck(this, OptionManager); | |
this.resolvedConfigs = []; | |
this.options = OptionManager.createBareOptions(); | |
this.pipeline = pipeline; | |
this.log = log; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
OptionManager.createBareOptions = function createBareOptions() { | |
var opts = {}; | |
for (var key in _config2["default"]) { | |
var opt = _config2["default"][key]; | |
opts[key] = _lodashLangClone2["default"](opt["default"]); | |
} | |
return opts; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
OptionManager.prototype.addConfig = function addConfig(loc, key) { | |
var json = arguments.length <= 2 || arguments[2] === undefined ? _json52["default"] : arguments[2]; | |
if (this.resolvedConfigs.indexOf(loc) >= 0) return; | |
var content = _fs2["default"].readFileSync(loc, "utf8"); | |
var opts; | |
try { | |
opts = jsonCache[content] = jsonCache[content] || json.parse(content); | |
if (key) opts = opts[key]; | |
} catch (err) { | |
err.message = loc + ": Error while parsing JSON - " + err.message; | |
throw err; | |
} | |
this.mergeOptions(opts, loc); | |
this.resolvedConfigs.push(loc); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
OptionManager.prototype.mergeOptions = function mergeOptions(opts) { | |
var alias = arguments.length <= 1 || arguments[1] === undefined ? "foreign" : arguments[1]; | |
if (!opts) return; | |
for (var key in opts) { | |
if (key[0] === "_") continue; | |
var option = _config2["default"][key]; | |
// check for an unknown option | |
if (!option) this.log.error("Unknown option: " + alias + "." + key, ReferenceError); | |
} | |
// normalise options | |
_index.normaliseOptions(opts); | |
// merge them into this current files options | |
_helpersMerge2["default"](this.options, opts); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
OptionManager.prototype.addIgnoreConfig = function addIgnoreConfig(loc) { | |
var file = _fs2["default"].readFileSync(loc, "utf8"); | |
var lines = file.split("\n"); | |
lines = lines.map(function (line) { | |
return line.replace(/#(.*?)$/, "").trim(); | |
}).filter(function (line) { | |
return !!line; | |
}); | |
this.mergeOptions({ ignore: lines }, loc); | |
}; | |
/** | |
* Description | |
*/ | |
OptionManager.prototype.findConfigs = function findConfigs(loc) { | |
if (!loc) return; | |
if (!_pathIsAbsolute2["default"](loc)) { | |
loc = _path2["default"].join(process.cwd(), loc); | |
} | |
while (loc !== (loc = _path2["default"].dirname(loc))) { | |
if (this.options.breakConfig) return; | |
var configLoc = _path2["default"].join(loc, BABELRC_FILENAME); | |
if (exists(configLoc)) this.addConfig(configLoc); | |
var pkgLoc = _path2["default"].join(loc, PACKAGE_FILENAME); | |
if (exists(pkgLoc)) this.addConfig(pkgLoc, "babel", JSON); | |
var ignoreLoc = _path2["default"].join(loc, BABELIGNORE_FILENAME); | |
if (exists(ignoreLoc)) this.addIgnoreConfig(ignoreLoc); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
OptionManager.prototype.normaliseOptions = function normaliseOptions() { | |
var opts = this.options; | |
for (var key in _config2["default"]) { | |
var option = _config2["default"][key]; | |
var val = opts[key]; | |
// optional | |
if (!val && option.optional) continue; | |
// deprecated | |
if (this.log && val && option.deprecated) { | |
this.log.deprecate("Deprecated option " + key + ": " + option.deprecated); | |
} | |
// validate | |
if (this.pipeline && val) { | |
val = _index.validateOption(key, val, this.pipeline); | |
} | |
// aaliases | |
if (option.alias) { | |
opts[option.alias] = opts[option.alias] || val; | |
} else { | |
opts[key] = val; | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
OptionManager.prototype.init = function init(opts) { | |
this.mergeOptions(opts, "direct"); | |
// babelrc option | |
if (opts.babelrc) { | |
var _arr = opts.babelrc; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var loc = _arr[_i];this.addConfig(loc); | |
} | |
} | |
// resolve all .babelrc files | |
if (opts.babelrc !== false) { | |
this.findConfigs(opts.filename); | |
} | |
// merge in env | |
var envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development"; | |
if (this.options.env) { | |
this.mergeOptions(this.options.env[envKey], "direct.env." + envKey); | |
} | |
// normalise | |
this.normaliseOptions(opts); | |
return this.options; | |
}; | |
return OptionManager; | |
})(); | |
exports["default"] = OptionManager; | |
module.exports = exports["default"]; | |
}).call(this,_dereq_(10)) | |
},{"1":1,"10":10,"39":39,"402":402,"48":48,"49":49,"494":494,"526":526,"527":527,"9":9}],51:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.transformerList = transformerList; | |
exports.number = number; | |
exports.boolean = boolean; | |
exports.booleanString = booleanString; | |
exports.list = list; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _slash = _dereq_(588); | |
var _slash2 = _interopRequireDefault(_slash); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
/** | |
* Get a transformer list from a value. | |
*/ | |
function transformerList(val) { | |
return util.arrayify(val); | |
} | |
/** | |
* Validate transformer list. Maps "all" to all transformer names. | |
*/ | |
transformerList.validate = function (key, val, pipeline) { | |
if (val.indexOf("all") >= 0 || val.indexOf(true) >= 0) { | |
val = Object.keys(pipeline.transformers); | |
} | |
return pipeline._ensureTransformerNames(key, val); | |
}; | |
/** | |
* Cast a value to a number. | |
*/ | |
function number(val) { | |
return +val; | |
} | |
/** | |
* Cast a value to a boolean. | |
*/ | |
var filename = _slash2["default"]; | |
exports.filename = filename; | |
/** | |
* [Please add a description.] | |
*/ | |
function boolean(val) { | |
return !!val; | |
} | |
/** | |
* Cast a boolean-like string to a boolean. | |
*/ | |
function booleanString(val) { | |
return util.booleanify(val); | |
} | |
/** | |
* Cast a value to an array, splitting strings by ",". | |
*/ | |
function list(val) { | |
return util.list(val); | |
} | |
},{"182":182,"588":588}],52:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _transformer = _dereq_(83); | |
var _transformer2 = _interopRequireDefault(_transformer); | |
var _plugin = _dereq_(82); | |
var _plugin2 = _interopRequireDefault(_plugin); | |
var _types = _dereq_(179); | |
var types = _interopRequireWildcard(_types); | |
var _messages = _dereq_(43); | |
var messages = _interopRequireWildcard(_messages); | |
var _tryResolve = _dereq_(602); | |
var _tryResolve2 = _interopRequireDefault(_tryResolve); | |
var _traversal = _dereq_(148); | |
var _traversal2 = _interopRequireDefault(_traversal); | |
var _helpersParse = _dereq_(42); | |
var _helpersParse2 = _interopRequireDefault(_helpersParse); | |
/** | |
* [Please add a description.] | |
*/ | |
var context = { | |
messages: messages, | |
Transformer: _transformer2["default"], | |
Plugin: _plugin2["default"], | |
types: types, | |
parse: _helpersParse2["default"], | |
traverse: _traversal2["default"] | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var PluginManager = (function () { | |
/** | |
* [Please add a description.] | |
*/ | |
PluginManager.memoisePluginContainer = function memoisePluginContainer(fn) { | |
for (var i = 0; i < PluginManager.memoisedPlugins.length; i++) { | |
var plugin = PluginManager.memoisedPlugins[i]; | |
if (plugin.container === fn) return plugin.transformer; | |
} | |
var transformer = fn(context); | |
PluginManager.memoisedPlugins.push({ | |
container: fn, | |
transformer: transformer | |
}); | |
return transformer; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
_createClass(PluginManager, null, [{ | |
key: "memoisedPlugins", | |
/** | |
* [Please add a description.] | |
*/ | |
value: [], | |
enumerable: true | |
}, { | |
key: "positions", | |
value: ["before", "after"], | |
/** | |
* [Please add a description.] | |
*/ | |
enumerable: true | |
}]); | |
function PluginManager() { | |
var _ref = arguments.length <= 0 || arguments[0] === undefined ? { transformers: {}, before: [], after: [] } : arguments[0]; | |
var file = _ref.file; | |
var transformers = _ref.transformers; | |
var before = _ref.before; | |
var after = _ref.after; | |
_classCallCheck(this, PluginManager); | |
this.transformers = transformers; | |
this.file = file; | |
this.before = before; | |
this.after = after; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
PluginManager.prototype.subnormaliseString = function subnormaliseString(name, position) { | |
// this is a plugin in the form of "foobar" or "foobar:after" | |
// where the optional colon is the delimiter for plugin position in the transformer stack | |
var match = name.match(/^(.*?):(after|before)$/); | |
if (match) { | |
; | |
name = match[1]; | |
position = match[2]; | |
}var loc = _tryResolve2["default"].relative("babel-plugin-" + name) || _tryResolve2["default"].relative(name); | |
if (loc) { | |
var plugin = _dereq_(loc); | |
return { | |
position: position, | |
plugin: plugin["default"] || plugin | |
}; | |
} else { | |
throw new ReferenceError(messages.get("pluginUnknown", name)); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
PluginManager.prototype.validate = function validate(name, plugin) { | |
// validate transformer key | |
var key = plugin.key; | |
if (this.transformers[key]) { | |
throw new ReferenceError(messages.get("pluginKeyCollision", key)); | |
} | |
// validate Transformer instance | |
if (!plugin.buildPass || plugin.constructor.name !== "Plugin") { | |
throw new TypeError(messages.get("pluginNotTransformer", name)); | |
} | |
// register as a plugin | |
plugin.metadata.plugin = true; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
PluginManager.prototype.add = function add(name) { | |
var position; | |
var plugin; | |
if (name) { | |
if (typeof name === "object" && name.transformer) { | |
plugin = name.transformer; | |
position = name.position; | |
} else if (typeof name !== "string") { | |
// not a string so we'll just assume that it's a direct Transformer instance, if not then | |
// the checks later on will complain | |
plugin = name; | |
} | |
if (typeof name === "string") { | |
var _subnormaliseString = this.subnormaliseString(name, position); | |
plugin = _subnormaliseString.plugin; | |
position = _subnormaliseString.position; | |
} | |
} else { | |
throw new TypeError(messages.get("pluginIllegalKind", typeof name, name)); | |
} | |
// default position | |
position = position || "before"; | |
// validate position | |
if (PluginManager.positions.indexOf(position) < 0) { | |
throw new TypeError(messages.get("pluginIllegalPosition", position, name)); | |
} | |
// allow plugin containers to be specified so they don't have to manually require | |
if (typeof plugin === "function") { | |
plugin = PluginManager.memoisePluginContainer(plugin); | |
} | |
// | |
this.validate(name, plugin); | |
// build! | |
var pass = this.transformers[plugin.key] = plugin.buildPass(this.file); | |
if (pass.canTransform()) { | |
var stack = position === "before" ? this.before : this.after; | |
stack.push(pass); | |
} | |
}; | |
return PluginManager; | |
})(); | |
exports["default"] = PluginManager; | |
module.exports = exports["default"]; | |
},{"148":148,"179":179,"42":42,"43":43,"602":602,"82":82,"83":83}],53:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _explodeAssignableExpression = _dereq_(58); | |
var _explodeAssignableExpression2 = _interopRequireDefault(_explodeAssignableExpression); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
exports["default"] = function (opts) { | |
var exports = {}; | |
/** | |
* [Please add a description.] | |
*/ | |
var isAssignment = function isAssignment(node) { | |
return node.operator === opts.operator + "="; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var buildAssignment = function buildAssignment(left, right) { | |
return t.assignmentExpression("=", left, right); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
exports.ExpressionStatement = function (node, parent, scope, file) { | |
// hit the `AssignmentExpression` one below | |
if (this.isCompletionRecord()) return; | |
var expr = node.expression; | |
if (!isAssignment(expr)) return; | |
var nodes = []; | |
var exploded = _explodeAssignableExpression2["default"](expr.left, nodes, file, scope, true); | |
nodes.push(t.expressionStatement(buildAssignment(exploded.ref, opts.build(exploded.uid, expr.right)))); | |
return nodes; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
exports.AssignmentExpression = function (node, parent, scope, file) { | |
if (!isAssignment(node)) return; | |
var nodes = []; | |
var exploded = _explodeAssignableExpression2["default"](node.left, nodes, file, scope); | |
nodes.push(buildAssignment(exploded.ref, opts.build(exploded.uid, node.right))); | |
return nodes; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
exports.BinaryExpression = function (node) { | |
if (node.operator !== opts.operator) return; | |
return opts.build(node.left, node.right); | |
}; | |
return exports; | |
}; | |
module.exports = exports["default"]; | |
},{"179":179,"58":58}],54:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports["default"] = build; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
function build(node, buildBody) { | |
var self = node.blocks.shift(); | |
if (!self) return; | |
var child = build(node, buildBody); | |
if (!child) { | |
// last item | |
child = buildBody(); | |
// add a filter as this is our final stop | |
if (node.filter) { | |
child = t.ifStatement(node.filter, t.blockStatement([child])); | |
} | |
} | |
return t.forOfStatement(t.variableDeclaration("let", [t.variableDeclarator(self.left)]), self.right, t.blockStatement([child])); | |
} | |
module.exports = exports["default"]; | |
},{"179":179}],55:[function(_dereq_,module,exports){ | |
// Based upon the excellent jsx-transpiler by Ingvar Stepanyan (RReverser) | |
// https://github.com/RReverser/jsx-transpiler | |
// jsx | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _lodashLangIsString = _dereq_(506); | |
var _lodashLangIsString2 = _interopRequireDefault(_lodashLangIsString); | |
var _messages = _dereq_(43); | |
var messages = _interopRequireWildcard(_messages); | |
var _esutils = _dereq_(395); | |
var _esutils2 = _interopRequireDefault(_esutils); | |
var _react = _dereq_(62); | |
var react = _interopRequireWildcard(_react); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
exports["default"] = function (opts) { | |
var visitor = {}; | |
/** | |
* [Please add a description.] | |
*/ | |
visitor.JSXIdentifier = function (node) { | |
if (node.name === "this" && this.isReferenced()) { | |
return t.thisExpression(); | |
} else if (_esutils2["default"].keyword.isIdentifierNameES6(node.name)) { | |
node.type = "Identifier"; | |
} else { | |
return t.literal(node.name); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
visitor.JSXNamespacedName = function () { | |
throw this.errorWithNode(messages.get("JSXNamespacedTags")); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
visitor.JSXMemberExpression = { | |
exit: function exit(node) { | |
node.computed = t.isLiteral(node.property); | |
node.type = "MemberExpression"; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
visitor.JSXExpressionContainer = function (node) { | |
return node.expression; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
visitor.JSXAttribute = { | |
enter: function enter(node) { | |
var value = node.value; | |
if (t.isLiteral(value) && _lodashLangIsString2["default"](value.value)) { | |
value.value = value.value.replace(/\n\s+/g, " "); | |
} | |
}, | |
exit: function exit(node) { | |
var value = node.value || t.literal(true); | |
return t.inherits(t.property("init", node.name, value), node); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
visitor.JSXOpeningElement = { | |
exit: function exit(node, parent, scope, file) { | |
parent.children = react.buildChildren(parent); | |
var tagExpr = node.name; | |
var args = []; | |
var tagName; | |
if (t.isIdentifier(tagExpr)) { | |
tagName = tagExpr.name; | |
} else if (t.isLiteral(tagExpr)) { | |
tagName = tagExpr.value; | |
} | |
var state = { | |
tagExpr: tagExpr, | |
tagName: tagName, | |
args: args | |
}; | |
if (opts.pre) { | |
opts.pre(state, file); | |
} | |
var attribs = node.attributes; | |
if (attribs.length) { | |
attribs = buildJSXOpeningElementAttributes(attribs, file); | |
} else { | |
attribs = t.literal(null); | |
} | |
args.push(attribs); | |
if (opts.post) { | |
opts.post(state, file); | |
} | |
return state.call || t.callExpression(state.callee, args); | |
} | |
}; | |
/** | |
* The logic for this is quite terse. It's because we need to | |
* support spread elements. We loop over all attributes, | |
* breaking on spreads, we then push a new object containg | |
* all prior attributes to an array for later processing. | |
*/ | |
var buildJSXOpeningElementAttributes = function buildJSXOpeningElementAttributes(attribs, file) { | |
var _props = []; | |
var objs = []; | |
var pushProps = function pushProps() { | |
if (!_props.length) return; | |
objs.push(t.objectExpression(_props)); | |
_props = []; | |
}; | |
while (attribs.length) { | |
var prop = attribs.shift(); | |
if (t.isJSXSpreadAttribute(prop)) { | |
pushProps(); | |
objs.push(prop.argument); | |
} else { | |
_props.push(prop); | |
} | |
} | |
pushProps(); | |
if (objs.length === 1) { | |
// only one object | |
attribs = objs[0]; | |
} else { | |
// looks like we have multiple objects | |
if (!t.isObjectExpression(objs[0])) { | |
objs.unshift(t.objectExpression([])); | |
} | |
// spread it | |
attribs = t.callExpression(file.addHelper("extends"), objs); | |
} | |
return attribs; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
visitor.JSXElement = { | |
exit: function exit(node) { | |
var callExpr = node.openingElement; | |
callExpr.arguments = callExpr.arguments.concat(node.children); | |
if (callExpr.arguments.length >= 3) { | |
callExpr._prettyCall = true; | |
} | |
return t.inherits(callExpr, node); | |
} | |
}; | |
return visitor; | |
}; | |
module.exports = exports["default"]; | |
},{"179":179,"395":395,"43":43,"506":506,"62":62}],56:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
enter: function enter(node, parent, scope, state) { | |
if (this.isThisExpression() || this.isReferencedIdentifier({ name: "arguments" })) { | |
state.found = true; | |
this.stop(); | |
} | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
Function: function Function() { | |
this.skip(); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
exports["default"] = function (node, scope) { | |
var container = t.functionExpression(null, [], node.body, node.generator, node.async); | |
var callee = container; | |
var args = []; | |
var state = { found: false }; | |
scope.traverse(node, visitor, state); | |
if (state.found) { | |
callee = t.memberExpression(container, t.identifier("apply")); | |
args = [t.thisExpression(), t.identifier("arguments")]; | |
} | |
var call = t.callExpression(callee, args); | |
if (node.generator) call = t.yieldExpression(call, true); | |
return t.returnStatement(call); | |
}; | |
module.exports = exports["default"]; | |
},{"179":179}],57:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.push = push; | |
exports.hasComputed = hasComputed; | |
exports.toComputedObjectFromClass = toComputedObjectFromClass; | |
exports.toClassObject = toClassObject; | |
exports.toDefineObject = toDefineObject; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _lodashCollectionEach = _dereq_(411); | |
var _lodashCollectionEach2 = _interopRequireDefault(_lodashCollectionEach); | |
var _lodashObjectHas = _dereq_(512); | |
var _lodashObjectHas2 = _interopRequireDefault(_lodashObjectHas); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
function push(mutatorMap, node, kind, file) { | |
var alias = t.toKeyAlias(node); | |
// | |
var map = {}; | |
if (_lodashObjectHas2["default"](mutatorMap, alias)) map = mutatorMap[alias]; | |
mutatorMap[alias] = map; | |
// | |
map._inherits = map._inherits || []; | |
map._inherits.push(node); | |
map._key = node.key; | |
if (node.computed) { | |
map._computed = true; | |
} | |
if (node.decorators) { | |
var decorators = map.decorators = map.decorators || t.arrayExpression([]); | |
decorators.elements = decorators.elements.concat(node.decorators.map(function (dec) { | |
return dec.expression; | |
}).reverse()); | |
} | |
if (map.value || map.initializer) { | |
throw file.errorWithNode(node, "Key conflict with sibling node"); | |
} | |
if (node.value) { | |
if (node.kind === "init") kind = "value"; | |
if (node.kind === "get") kind = "get"; | |
if (node.kind === "set") kind = "set"; | |
t.inheritsComments(node.value, node); | |
map[kind] = node.value; | |
} | |
return map; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function hasComputed(mutatorMap) { | |
for (var key in mutatorMap) { | |
if (mutatorMap[key]._computed) { | |
return true; | |
} | |
} | |
return false; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function toComputedObjectFromClass(obj) { | |
var objExpr = t.arrayExpression([]); | |
for (var i = 0; i < obj.properties.length; i++) { | |
var prop = obj.properties[i]; | |
var val = prop.value; | |
val.properties.unshift(t.property("init", t.identifier("key"), t.toComputedKey(prop))); | |
objExpr.elements.push(val); | |
} | |
return objExpr; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function toClassObject(mutatorMap) { | |
var objExpr = t.objectExpression([]); | |
_lodashCollectionEach2["default"](mutatorMap, function (map) { | |
var mapNode = t.objectExpression([]); | |
var propNode = t.property("init", map._key, mapNode, map._computed); | |
_lodashCollectionEach2["default"](map, function (node, key) { | |
if (key[0] === "_") return; | |
var inheritNode = node; | |
if (t.isMethodDefinition(node) || t.isClassProperty(node)) node = node.value; | |
var prop = t.property("init", t.identifier(key), node); | |
t.inheritsComments(prop, inheritNode); | |
t.removeComments(inheritNode); | |
mapNode.properties.push(prop); | |
}); | |
objExpr.properties.push(propNode); | |
}); | |
return objExpr; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function toDefineObject(mutatorMap) { | |
_lodashCollectionEach2["default"](mutatorMap, function (map) { | |
if (map.value) map.writable = t.literal(true); | |
map.configurable = t.literal(true); | |
map.enumerable = t.literal(true); | |
}); | |
return toClassObject(mutatorMap); | |
} | |
},{"179":179,"411":411,"512":512}],58:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var getObjRef = function getObjRef(node, nodes, file, scope) { | |
var ref; | |
if (t.isIdentifier(node)) { | |
if (scope.hasBinding(node.name)) { | |
// this variable is declared in scope so we can be 100% sure | |
// that evaluating it multiple times wont trigger a getter | |
// or something else | |
return node; | |
} else { | |
// could possibly trigger a getter so we need to only evaluate | |
// it once | |
ref = node; | |
} | |
} else if (t.isMemberExpression(node)) { | |
ref = node.object; | |
if (t.isIdentifier(ref) && scope.hasGlobal(ref.name)) { | |
// the object reference that we need to save is locally declared | |
// so as per the previous comment we can be 100% sure evaluating | |
// it multiple times will be safe | |
return ref; | |
} | |
} else { | |
throw new Error("We can't explode this node type " + node.type); | |
} | |
var temp = scope.generateUidIdentifierBasedOnNode(ref); | |
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(temp, ref)])); | |
return temp; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var getPropRef = function getPropRef(node, nodes, file, scope) { | |
var prop = node.property; | |
var key = t.toComputedKey(node, prop); | |
if (t.isLiteral(key)) return key; | |
var temp = scope.generateUidIdentifierBasedOnNode(prop); | |
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(temp, prop)])); | |
return temp; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
exports["default"] = function (node, nodes, file, scope, allowedSingleIdent) { | |
var obj; | |
if (t.isIdentifier(node) && allowedSingleIdent) { | |
obj = node; | |
} else { | |
obj = getObjRef(node, nodes, file, scope); | |
} | |
var ref, uid; | |
if (t.isIdentifier(node)) { | |
ref = node; | |
uid = obj; | |
} else { | |
var prop = getPropRef(node, nodes, file, scope); | |
var computed = node.computed || t.isLiteral(prop); | |
uid = ref = t.memberExpression(obj, prop, computed); | |
} | |
return { | |
uid: uid, | |
ref: ref | |
}; | |
}; | |
module.exports = exports["default"]; | |
},{"179":179}],59:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
exports["default"] = function (node) { | |
var lastNonDefault = 0; | |
for (var i = 0; i < node.params.length; i++) { | |
var param = node.params[i]; | |
if (!t.isAssignmentPattern(param) && !t.isRestElement(param)) { | |
lastNonDefault = i + 1; | |
} | |
} | |
return lastNonDefault; | |
}; | |
module.exports = exports["default"]; | |
},{"179":179}],60:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
exports["default"] = function (decorators, scope) { | |
for (var i = 0; i < decorators.length; i++) { | |
var decorator = decorators[i]; | |
var expression = decorator.expression; | |
if (!t.isMemberExpression(expression)) continue; | |
var temp = scope.maybeGenerateMemoised(expression.object); | |
var ref; | |
var nodes = []; | |
if (temp) { | |
ref = temp; | |
nodes.push(t.assignmentExpression("=", temp, expression.object)); | |
} else { | |
ref = expression.object; | |
} | |
nodes.push(t.callExpression(t.memberExpression(t.memberExpression(ref, expression.property, expression.computed), t.identifier("bind")), [ref])); | |
if (nodes.length === 1) { | |
decorator.expression = nodes[0]; | |
} else { | |
decorator.expression = t.sequenceExpression(nodes); | |
} | |
} | |
return decorators; | |
}; | |
module.exports = exports["default"]; | |
},{"179":179}],61:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.custom = custom; | |
exports.property = property; | |
exports.bare = bare; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _getFunctionArity = _dereq_(59); | |
var _getFunctionArity2 = _interopRequireDefault(_getFunctionArity); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
function visitIdentifier(context, node, scope, state) { | |
// check if this node matches our function id | |
if (node.name !== state.name) return; | |
// check that we don't have a local variable declared as that removes the need | |
// for the wrapper | |
var localDeclar = scope.getBindingIdentifier(state.name); | |
if (localDeclar !== state.outerDeclar) return; | |
state.selfReference = true; | |
context.stop(); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ReferencedIdentifier: function ReferencedIdentifier(node, parent, scope, state) { | |
visitIdentifier(this, node, scope, state); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
BindingIdentifier: function BindingIdentifier(node, parent, scope, state) { | |
visitIdentifier(this, node, scope, state); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var wrap = function wrap(state, method, id, scope) { | |
if (state.selfReference) { | |
if (scope.hasBinding(id.name) && !scope.hasGlobal(id.name)) { | |
// we can just munge the local binding | |
scope.rename(id.name); | |
} else { | |
// need to add a wrapper since we can't change the references | |
var templateName = "property-method-assignment-wrapper"; | |
if (method.generator) templateName += "-generator"; | |
var template = util.template(templateName, { | |
FUNCTION: method, | |
FUNCTION_ID: id, | |
FUNCTION_KEY: scope.generateUidIdentifier(id.name) | |
}); | |
template.callee._skipModulesRemap = true; | |
// shim in dummy params to retain function arity, if you try to read the | |
// source then you'll get the original since it's proxied so it's all good | |
var params = template.callee.body.body[0].params; | |
for (var i = 0, len = _getFunctionArity2["default"](method); i < len; i++) { | |
params.push(scope.generateUidIdentifier("x")); | |
} | |
return template; | |
} | |
} | |
method.id = id; | |
scope.getProgramParent().references[id.name] = true; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var visit = function visit(node, name, scope) { | |
var state = { | |
selfAssignment: false, | |
selfReference: false, | |
outerDeclar: scope.getBindingIdentifier(name), | |
references: [], | |
name: name | |
}; | |
// check to see if we have a local binding of the id we're setting inside of | |
// the function, this is important as there are caveats associated | |
var binding = scope.getOwnBinding(name); | |
if (binding) { | |
if (binding.kind === "param") { | |
// safari will blow up in strict mode with code like: | |
// | |
// var t = function t(t) {}; | |
// | |
// with the error: | |
// | |
// Cannot declare a parameter named 't' as it shadows the name of a | |
// strict mode function. | |
// | |
// this isn't to the spec and they've invented this behaviour which is | |
// **extremely** annoying so we avoid setting the name if it has a param | |
// with the same id | |
state.selfReference = true; | |
} else { | |
// otherwise it's defined somewhere in scope like: | |
// | |
// var t = function () { | |
// var t = 2; | |
// }; | |
// | |
// so we can safely just set the id and move along as it shadows the | |
// bound function id | |
} | |
} else if (state.outerDeclar || scope.hasGlobal(name)) { | |
scope.traverse(node, visitor, state); | |
} | |
return state; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
function custom(node, id, scope) { | |
var state = visit(node, id.name, scope); | |
return wrap(state, node, id, scope); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function property(node, file, scope) { | |
var key = t.toComputedKey(node, node.key); | |
if (!t.isLiteral(key)) return; // we can't set a function id with this | |
var name = t.toBindingIdentifierName(key.value); | |
var id = t.identifier(name); | |
var method = node.value; | |
var state = visit(method, name, scope); | |
node.value = wrap(state, method, id, scope) || method; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function bare(node, parent, scope) { | |
// has an `id` so we don't need to infer one | |
if (node.id) return; | |
var id; | |
if (t.isProperty(parent) && parent.kind === "init" && (!parent.computed || t.isLiteral(parent.key))) { | |
// { foo() {} }; | |
id = parent.key; | |
} else if (t.isVariableDeclarator(parent)) { | |
// var foo = function () {}; | |
id = parent.id; | |
if (t.isIdentifier(id)) { | |
var binding = scope.parent.getBinding(id.name); | |
if (binding && binding.constant && scope.getBinding(id.name) === binding) { | |
// always going to reference this method | |
node.id = id; | |
return; | |
} | |
} | |
} else { | |
return; | |
} | |
var name; | |
if (t.isLiteral(id)) { | |
name = id.value; | |
} else if (t.isIdentifier(id)) { | |
name = id.name; | |
} else { | |
return; | |
} | |
name = t.toBindingIdentifierName(name); | |
id = t.identifier(name); | |
var state = visit(node, name, scope); | |
return wrap(state, node, id, scope); | |
} | |
},{"179":179,"182":182,"59":59}],62:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.isCompatTag = isCompatTag; | |
exports.buildChildren = buildChildren; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var isReactComponent = t.buildMatchMemberExpression("React.Component"); | |
exports.isReactComponent = isReactComponent; | |
/** | |
* [Please add a description.] | |
*/ | |
function isCompatTag(tagName) { | |
return tagName && /^[a-z]|\-/.test(tagName); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function cleanJSXElementLiteralChild(child, args) { | |
var lines = child.value.split(/\r\n|\n|\r/); | |
var lastNonEmptyLine = 0; | |
for (var i = 0; i < lines.length; i++) { | |
if (lines[i].match(/[^ \t]/)) { | |
lastNonEmptyLine = i; | |
} | |
} | |
var str = ""; | |
for (var i = 0; i < lines.length; i++) { | |
var line = lines[i]; | |
var isFirstLine = i === 0; | |
var isLastLine = i === lines.length - 1; | |
var isLastNonEmptyLine = i === lastNonEmptyLine; | |
// replace rendered whitespace tabs with spaces | |
var trimmedLine = line.replace(/\t/g, " "); | |
// trim whitespace touching a newline | |
if (!isFirstLine) { | |
trimmedLine = trimmedLine.replace(/^[ ]+/, ""); | |
} | |
// trim whitespace touching an endline | |
if (!isLastLine) { | |
trimmedLine = trimmedLine.replace(/[ ]+$/, ""); | |
} | |
if (trimmedLine) { | |
if (!isLastNonEmptyLine) { | |
trimmedLine += " "; | |
} | |
str += trimmedLine; | |
} | |
} | |
if (str) args.push(t.literal(str)); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function buildChildren(node) { | |
var elems = []; | |
for (var i = 0; i < node.children.length; i++) { | |
var child = node.children[i]; | |
if (t.isLiteral(child) && typeof child.value === "string") { | |
cleanJSXElementLiteralChild(child, elems); | |
continue; | |
} | |
if (t.isJSXExpressionContainer(child)) child = child.expression; | |
if (t.isJSXEmptyExpression(child)) continue; | |
elems.push(child); | |
} | |
return elems; | |
} | |
},{"179":179}],63:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.is = is; | |
exports.pullFlag = pullFlag; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _lodashArrayPull = _dereq_(408); | |
var _lodashArrayPull2 = _interopRequireDefault(_lodashArrayPull); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
function is(node, flag) { | |
return t.isLiteral(node) && node.regex && node.regex.flags.indexOf(flag) >= 0; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function pullFlag(node, flag) { | |
var flags = node.regex.flags.split(""); | |
if (node.regex.flags.indexOf(flag) < 0) return; | |
_lodashArrayPull2["default"](flags, flag); | |
node.regex.flags = flags.join(""); | |
} | |
},{"179":179,"408":408}],64:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var awaitVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Function: function Function() { | |
this.skip(); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
AwaitExpression: function AwaitExpression(node) { | |
node.type = "YieldExpression"; | |
if (node.all) { | |
// await* foo; -> yield Promise.all(foo); | |
node.all = false; | |
node.argument = t.callExpression(t.memberExpression(t.identifier("Promise"), t.identifier("all")), [node.argument]); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var referenceVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ReferencedIdentifier: function ReferencedIdentifier(node, parent, scope, state) { | |
var name = state.id.name; | |
if (node.name === name && scope.bindingIdentifierEquals(name, state.id)) { | |
return state.ref = state.ref || scope.generateUidIdentifier(name); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
exports["default"] = function (path, callId) { | |
var node = path.node; | |
node.async = false; | |
node.generator = true; | |
path.traverse(awaitVisitor, state); | |
var call = t.callExpression(callId, [node]); | |
var id = node.id; | |
node.id = null; | |
if (t.isFunctionDeclaration(node)) { | |
var declar = t.variableDeclaration("let", [t.variableDeclarator(id, call)]); | |
declar._blockHoist = true; | |
return declar; | |
} else { | |
if (id) { | |
var state = { id: id }; | |
path.traverse(referenceVisitor, state); | |
if (state.ref) { | |
path.scope.parent.push({ id: state.ref }); | |
return t.assignmentExpression("=", state.ref, call); | |
} | |
} | |
return call; | |
} | |
}; | |
module.exports = exports["default"]; | |
},{"179":179}],65:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _messages = _dereq_(43); | |
var messages = _interopRequireWildcard(_messages); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
function isIllegalBareSuper(node, parent) { | |
if (!t.isSuper(node)) return false; | |
if (t.isMemberExpression(parent, { computed: false })) return false; | |
if (t.isCallExpression(parent, { callee: node })) return false; | |
return true; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function isMemberExpressionSuper(node) { | |
return t.isMemberExpression(node) && t.isSuper(node.object); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
enter: function enter(node, parent, scope, state) { | |
var topLevel = state.topLevel; | |
var self = state.self; | |
if (t.isFunction(node) && !t.isArrowFunctionExpression(node)) { | |
// we need to call traverseLevel again so we're context aware | |
self.traverseLevel(this, false); | |
return this.skip(); | |
} | |
if (t.isProperty(node, { method: true }) || t.isMethodDefinition(node)) { | |
// break on object methods | |
return this.skip(); | |
} | |
var getThisReference = topLevel ? | |
// top level so `this` is the instance | |
t.thisExpression : | |
// not in the top level so we need to create a reference | |
self.getThisReference.bind(self); | |
var callback = self.specHandle; | |
if (self.isLoose) callback = self.looseHandle; | |
var result = callback.call(self, this, getThisReference); | |
if (result) this.hasSuper = true; | |
if (result === true) return; | |
return result; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var ReplaceSupers = (function () { | |
function ReplaceSupers(opts) { | |
var inClass = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; | |
_classCallCheck(this, ReplaceSupers); | |
this.topLevelThisReference = opts.topLevelThisReference; | |
this.methodPath = opts.methodPath; | |
this.methodNode = opts.methodNode; | |
this.superRef = opts.superRef; | |
this.isStatic = opts.isStatic; | |
this.hasSuper = false; | |
this.inClass = inClass; | |
this.isLoose = opts.isLoose; | |
this.scope = opts.scope; | |
this.file = opts.file; | |
this.opts = opts; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
ReplaceSupers.prototype.getObjectRef = function getObjectRef() { | |
return this.opts.objectRef || this.opts.getObjectRef(); | |
}; | |
/** | |
* Sets a super class value of the named property. | |
* | |
* @example | |
* | |
* _set(Object.getPrototypeOf(CLASS.prototype), "METHOD", "VALUE", this) | |
* | |
*/ | |
ReplaceSupers.prototype.setSuperProperty = function setSuperProperty(property, value, isComputed, thisExpression) { | |
return t.callExpression(this.file.addHelper("set"), [t.callExpression(t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")), [this.isStatic ? this.getObjectRef() : t.memberExpression(this.getObjectRef(), t.identifier("prototype"))]), isComputed ? property : t.literal(property.name), value, thisExpression]); | |
}; | |
/** | |
* Gets a node representing the super class value of the named property. | |
* | |
* @example | |
* | |
* _get(Object.getPrototypeOf(CLASS.prototype), "METHOD", this) | |
* | |
*/ | |
ReplaceSupers.prototype.getSuperProperty = function getSuperProperty(property, isComputed, thisExpression) { | |
return t.callExpression(this.file.addHelper("get"), [t.callExpression(t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")), [this.isStatic ? this.getObjectRef() : t.memberExpression(this.getObjectRef(), t.identifier("prototype"))]), isComputed ? property : t.literal(property.name), thisExpression]); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ReplaceSupers.prototype.replace = function replace() { | |
this.traverseLevel(this.methodPath.get("value"), true); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ReplaceSupers.prototype.traverseLevel = function traverseLevel(path, topLevel) { | |
var state = { self: this, topLevel: topLevel }; | |
path.traverse(visitor, state); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ReplaceSupers.prototype.getThisReference = function getThisReference() { | |
if (this.topLevelThisReference) { | |
return this.topLevelThisReference; | |
} else { | |
var ref = this.topLevelThisReference = this.scope.generateUidIdentifier("this"); | |
this.methodNode.value.body.body.unshift(t.variableDeclaration("var", [t.variableDeclarator(this.topLevelThisReference, t.thisExpression())])); | |
return ref; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ReplaceSupers.prototype.getLooseSuperProperty = function getLooseSuperProperty(id, parent) { | |
var methodNode = this.methodNode; | |
var methodName = methodNode.key; | |
var superRef = this.superRef || t.identifier("Function"); | |
if (parent.property === id) { | |
return; | |
} else if (t.isCallExpression(parent, { callee: id })) { | |
// super(); -> objectRef.prototype.MethodName.call(this); | |
parent.arguments.unshift(t.thisExpression()); | |
if (methodName.name === "constructor") { | |
// constructor() { super(); } | |
if (parent.arguments.length === 2 && t.isSpreadElement(parent.arguments[1]) && t.isIdentifier(parent.arguments[1].argument, { name: "arguments" })) { | |
// special case single arguments spread | |
parent.arguments[1] = parent.arguments[1].argument; | |
return t.memberExpression(superRef, t.identifier("apply")); | |
} else { | |
return t.memberExpression(superRef, t.identifier("call")); | |
} | |
} else { | |
id = superRef; | |
// foo() { super(); } | |
if (!methodNode["static"]) { | |
id = t.memberExpression(id, t.identifier("prototype")); | |
} | |
id = t.memberExpression(id, methodName, methodNode.computed); | |
return t.memberExpression(id, t.identifier("call")); | |
} | |
} else if (t.isMemberExpression(parent) && !methodNode["static"]) { | |
// super.test -> objectRef.prototype.test | |
return t.memberExpression(superRef, t.identifier("prototype")); | |
} else { | |
return superRef; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ReplaceSupers.prototype.looseHandle = function looseHandle(path, getThisReference) { | |
var node = path.node; | |
if (path.isSuper()) { | |
return this.getLooseSuperProperty(node, path.parent); | |
} else if (path.isCallExpression()) { | |
var callee = node.callee; | |
if (!t.isMemberExpression(callee)) return; | |
if (!t.isSuper(callee.object)) return; | |
// super.test(); -> objectRef.prototype.MethodName.call(this); | |
t.appendToMemberExpression(callee, t.identifier("call")); | |
node.arguments.unshift(getThisReference()); | |
return true; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ReplaceSupers.prototype.specHandleAssignmentExpression = function specHandleAssignmentExpression(ref, path, node, getThisReference) { | |
if (node.operator === "=") { | |
// super.name = "val"; -> _set(Object.getPrototypeOf(objectRef.prototype), "name", this); | |
return this.setSuperProperty(node.left.property, node.right, node.left.computed, getThisReference()); | |
} else { | |
// super.age += 2; -> var _ref = super.age; super.age = _ref + 2; | |
ref = ref || path.scope.generateUidIdentifier("ref"); | |
return [t.variableDeclaration("var", [t.variableDeclarator(ref, node.left)]), t.expressionStatement(t.assignmentExpression("=", node.left, t.binaryExpression(node.operator[0], ref, node.right)))]; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ReplaceSupers.prototype.specHandle = function specHandle(path, getThisReference) { | |
var methodNode = this.methodNode; | |
var property; | |
var computed; | |
var args; | |
var thisReference; | |
var parent = path.parent; | |
var node = path.node; | |
if (isIllegalBareSuper(node, parent)) { | |
throw path.errorWithNode(messages.get("classesIllegalBareSuper")); | |
} | |
if (t.isCallExpression(node)) { | |
var callee = node.callee; | |
if (t.isSuper(callee)) { | |
// super(); -> _get(Object.getPrototypeOf(objectRef), "MethodName", this).call(this); | |
property = methodNode.key; | |
computed = methodNode.computed; | |
args = node.arguments; | |
// bare `super` call is illegal inside non-constructors | |
// - https://esdiscuss.org/topic/super-call-in-methods | |
// - https://twitter.com/wycats/status/544553184396836864 | |
if (methodNode.key.name !== "constructor" || !this.inClass) { | |
var methodName = methodNode.key.name || "METHOD_NAME"; | |
throw this.file.errorWithNode(node, messages.get("classesIllegalSuperCall", methodName)); | |
} | |
} else if (isMemberExpressionSuper(callee)) { | |
// super.test(); -> _get(Object.getPrototypeOf(objectRef.prototype), "test", this).call(this); | |
property = callee.property; | |
computed = callee.computed; | |
args = node.arguments; | |
} | |
} else if (t.isMemberExpression(node) && t.isSuper(node.object)) { | |
// super.name; -> _get(Object.getPrototypeOf(objectRef.prototype), "name", this); | |
property = node.property; | |
computed = node.computed; | |
} else if (t.isUpdateExpression(node) && isMemberExpressionSuper(node.argument)) { | |
var binary = t.binaryExpression(node.operator[0], node.argument, t.literal(1)); | |
if (node.prefix) { | |
// ++super.foo; -> super.foo += 1; | |
return this.specHandleAssignmentExpression(null, path, binary, getThisReference); | |
} else { | |
// super.foo++; -> var _ref = super.foo; super.foo = _ref + 1; | |
var ref = path.scope.generateUidIdentifier("ref"); | |
return this.specHandleAssignmentExpression(ref, path, binary, getThisReference).concat(t.expressionStatement(ref)); | |
} | |
} else if (t.isAssignmentExpression(node) && isMemberExpressionSuper(node.left)) { | |
return this.specHandleAssignmentExpression(null, path, node, getThisReference); | |
} | |
if (!property) return; | |
thisReference = getThisReference(); | |
var superProperty = this.getSuperProperty(property, computed, thisReference); | |
if (args) { | |
if (args.length === 1 && t.isSpreadElement(args[0])) { | |
// super(...arguments); | |
return t.callExpression(t.memberExpression(superProperty, t.identifier("apply")), [thisReference, args[0].argument]); | |
} else { | |
return t.callExpression(t.memberExpression(superProperty, t.identifier("call")), [thisReference].concat(args)); | |
} | |
} else { | |
return superProperty; | |
} | |
}; | |
return ReplaceSupers; | |
})(); | |
exports["default"] = ReplaceSupers; | |
module.exports = exports["default"]; | |
},{"179":179,"43":43}],66:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _pipeline = _dereq_(80); | |
var _pipeline2 = _interopRequireDefault(_pipeline); | |
/** | |
* [Please add a description.] | |
*/ | |
/** | |
* [Please add a description.] | |
*/ | |
var _transformers = _dereq_(126); | |
var _transformers2 = _interopRequireDefault(_transformers); | |
/** | |
* [Please add a description.] | |
*/ | |
var _transformersDeprecated = _dereq_(85); | |
var _transformersDeprecated2 = _interopRequireDefault(_transformersDeprecated); | |
/** | |
* [Please add a description.] | |
*/ | |
var _transformersAliases = _dereq_(84); | |
var _transformersAliases2 = _interopRequireDefault(_transformersAliases); | |
/** | |
* [Please add a description.] | |
*/ | |
var _transformersFilters = _dereq_(125); | |
var filters = _interopRequireWildcard(_transformersFilters); | |
var pipeline = new _pipeline2["default"](); | |
for (var key in _transformers2["default"]) { | |
var transformer = _transformers2["default"][key]; | |
if (typeof transformer === "object") { | |
var metadata = transformer.metadata = transformer.metadata || {}; | |
metadata.group = metadata.group || "builtin-basic"; | |
} | |
} | |
pipeline.addTransformers(_transformers2["default"]); | |
pipeline.addDeprecated(_transformersDeprecated2["default"]); | |
pipeline.addAliases(_transformersAliases2["default"]); | |
pipeline.addFilter(filters.internal); | |
pipeline.addFilter(filters.blacklist); | |
pipeline.addFilter(filters.whitelist); | |
pipeline.addFilter(filters.stage); | |
pipeline.addFilter(filters.optional); | |
/** | |
* [Please add a description.] | |
*/ | |
var transform = pipeline.transform.bind(pipeline); | |
transform.fromAst = pipeline.transformFromAst.bind(pipeline); | |
transform.pipeline = pipeline; | |
exports["default"] = transform; | |
module.exports = exports["default"]; | |
},{"125":125,"126":126,"80":80,"84":84,"85":85}],67:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _libMetadata = _dereq_(75); | |
var metadataVisitor = _interopRequireWildcard(_libMetadata); | |
var _messages = _dereq_(43); | |
var messages = _interopRequireWildcard(_messages); | |
var _libRemaps = _dereq_(76); | |
var _libRemaps2 = _interopRequireDefault(_libRemaps); | |
var _helpersObject = _dereq_(41); | |
var _helpersObject2 = _interopRequireDefault(_helpersObject); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var DefaultFormatter = (function () { | |
function DefaultFormatter(file) { | |
_classCallCheck(this, DefaultFormatter); | |
// object containg all module sources with the scope that they're contained in | |
this.sourceScopes = _helpersObject2["default"](); | |
// ids for use in module ids | |
this.defaultIds = _helpersObject2["default"](); | |
this.ids = _helpersObject2["default"](); | |
// contains reference aliases for live bindings | |
this.remaps = new _libRemaps2["default"](file, this); | |
this.scope = file.scope; | |
this.file = file; | |
this.hasNonDefaultExports = false; | |
this.hasLocalExports = false; | |
this.hasLocalImports = false; | |
this.localExports = _helpersObject2["default"](); | |
this.localImports = _helpersObject2["default"](); | |
this.metadata = file.metadata.modules; | |
this.getMetadata(); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.addScope = function addScope(path) { | |
var source = path.node.source && path.node.source.value; | |
if (!source) return; | |
var existingScope = this.sourceScopes[source]; | |
if (existingScope && existingScope !== path.scope) { | |
throw path.errorWithNode(messages.get("modulesDuplicateDeclarations")); | |
} | |
this.sourceScopes[source] = path.scope; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.isModuleType = function isModuleType(node, type) { | |
var modules = this.file.dynamicImportTypes[type]; | |
return modules && modules.indexOf(node) >= 0; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.transform = function transform() { | |
this.remapAssignments(); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.doDefaultExportInterop = function doDefaultExportInterop(node) { | |
return (t.isExportDefaultDeclaration(node) || t.isSpecifierDefault(node)) && !this.noInteropRequireExport && !this.hasNonDefaultExports; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.getMetadata = function getMetadata() { | |
var has = false; | |
var _arr = this.file.ast.program.body; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var node = _arr[_i]; | |
if (t.isModuleDeclaration(node)) { | |
has = true; | |
break; | |
} | |
} | |
if (has || this.isLoose()) { | |
this.file.path.traverse(metadataVisitor, this); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.remapAssignments = function remapAssignments() { | |
if (this.hasLocalExports || this.hasLocalImports) { | |
this.remaps.run(); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.remapExportAssignment = function remapExportAssignment(node, exported) { | |
var assign = node; | |
for (var i = 0; i < exported.length; i++) { | |
assign = t.assignmentExpression("=", t.memberExpression(t.identifier("exports"), exported[i]), assign); | |
} | |
return assign; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype._addExport = function _addExport(name, exported) { | |
var info = this.localExports[name] = this.localExports[name] || { | |
binding: this.scope.getBindingIdentifier(name), | |
exported: [] | |
}; | |
info.exported.push(exported); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.getExport = function getExport(node, scope) { | |
if (!t.isIdentifier(node)) return; | |
var local = this.localExports[node.name]; | |
if (local && local.binding === scope.getBindingIdentifier(node.name)) { | |
return local.exported; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.getModuleName = function getModuleName() { | |
var opts = this.file.opts; | |
// moduleId is n/a if a `getModuleId()` is provided | |
if (opts.moduleId != null && !opts.getModuleId) { | |
return opts.moduleId; | |
} | |
var filenameRelative = opts.filenameRelative; | |
var moduleName = ""; | |
if (opts.moduleRoot != null) { | |
moduleName = opts.moduleRoot + "/"; | |
} | |
if (!opts.filenameRelative) { | |
return moduleName + opts.filename.replace(/^\//, ""); | |
} | |
if (opts.sourceRoot != null) { | |
// remove sourceRoot from filename | |
var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?"); | |
filenameRelative = filenameRelative.replace(sourceRootRegEx, ""); | |
} | |
if (!opts.keepModuleIdExtensions) { | |
// remove extension | |
filenameRelative = filenameRelative.replace(/\.(\w*?)$/, ""); | |
} | |
moduleName += filenameRelative; | |
// normalize path separators | |
moduleName = moduleName.replace(/\\/g, "/"); | |
if (opts.getModuleId) { | |
// If return is falsy, assume they want us to use our generated default name | |
return opts.getModuleId(moduleName) || moduleName; | |
} else { | |
return moduleName; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype._pushStatement = function _pushStatement(ref, nodes) { | |
if (t.isClass(ref) || t.isFunction(ref)) { | |
if (ref.id) { | |
nodes.push(t.toStatement(ref)); | |
ref = ref.id; | |
} | |
} | |
return ref; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype._hoistExport = function _hoistExport(declar, assign, priority) { | |
if (t.isFunctionDeclaration(declar)) { | |
assign._blockHoist = priority || 2; | |
} | |
return assign; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.getExternalReference = function getExternalReference(node, nodes) { | |
var ids = this.ids; | |
var id = node.source.value; | |
if (ids[id]) { | |
return ids[id]; | |
} else { | |
return this.ids[id] = this._getExternalReference(node, nodes); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.checkExportIdentifier = function checkExportIdentifier(node) { | |
if (t.isIdentifier(node, { name: "__esModule" })) { | |
throw this.file.errorWithNode(node, messages.get("modulesIllegalExportName", node.name)); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.exportAllDeclaration = function exportAllDeclaration(node, nodes) { | |
var ref = this.getExternalReference(node, nodes); | |
nodes.push(this.buildExportsWildcard(ref, node)); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.isLoose = function isLoose() { | |
return this.file.isLoose("es6.modules"); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.exportSpecifier = function exportSpecifier(specifier, node, nodes) { | |
if (node.source) { | |
var ref = this.getExternalReference(node, nodes); | |
if (specifier.local.name === "default" && !this.noInteropRequireExport) { | |
// importing a default so we need to normalize it | |
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]); | |
} else { | |
ref = t.memberExpression(ref, specifier.local); | |
if (!this.isLoose()) { | |
nodes.push(this.buildExportsFromAssignment(specifier.exported, ref, node)); | |
return; | |
} | |
} | |
// export { foo } from "test"; | |
nodes.push(this.buildExportsAssignment(specifier.exported, ref, node)); | |
} else { | |
// export { foo }; | |
nodes.push(this.buildExportsAssignment(specifier.exported, specifier.local, node)); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.buildExportsWildcard = function buildExportsWildcard(objectIdentifier) { | |
return t.expressionStatement(t.callExpression(this.file.addHelper("defaults"), [t.identifier("exports"), t.callExpression(this.file.addHelper("interop-export-wildcard"), [objectIdentifier, this.file.addHelper("defaults")])])); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.buildExportsFromAssignment = function buildExportsFromAssignment(id, init) { | |
this.checkExportIdentifier(id); | |
return util.template("exports-from-assign", { | |
INIT: init, | |
ID: t.literal(id.name) | |
}, true); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.buildExportsAssignment = function buildExportsAssignment(id, init) { | |
this.checkExportIdentifier(id); | |
return util.template("exports-assign", { | |
VALUE: init, | |
KEY: id | |
}, true); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DefaultFormatter.prototype.exportDeclaration = function exportDeclaration(node, nodes) { | |
var declar = node.declaration; | |
var id = declar.id; | |
if (t.isExportDefaultDeclaration(node)) { | |
id = t.identifier("default"); | |
} | |
var assign; | |
if (t.isVariableDeclaration(declar)) { | |
for (var i = 0; i < declar.declarations.length; i++) { | |
var decl = declar.declarations[i]; | |
decl.init = this.buildExportsAssignment(decl.id, decl.init, node).expression; | |
var newDeclar = t.variableDeclaration(declar.kind, [decl]); | |
if (i === 0) t.inherits(newDeclar, declar); | |
nodes.push(newDeclar); | |
} | |
} else { | |
var ref = declar; | |
if (t.isFunctionDeclaration(declar) || t.isClassDeclaration(declar)) { | |
ref = declar.id; | |
nodes.push(declar); | |
} | |
assign = this.buildExportsAssignment(id, ref, node); | |
nodes.push(assign); | |
this._hoistExport(declar, assign); | |
} | |
}; | |
return DefaultFormatter; | |
})(); | |
exports["default"] = DefaultFormatter; | |
module.exports = exports["default"]; | |
},{"179":179,"182":182,"41":41,"43":43,"75":75,"76":76}],68:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
/** | |
* [Please add a description.] | |
*/ | |
exports["default"] = function (Parent) { | |
var Constructor = function Constructor() { | |
this.noInteropRequireImport = true; | |
this.noInteropRequireExport = true; | |
Parent.apply(this, arguments); | |
}; | |
util.inherits(Constructor, Parent); | |
return Constructor; | |
}; | |
module.exports = exports["default"]; | |
},{"182":182}],69:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _amd = _dereq_(70); | |
var _amd2 = _interopRequireDefault(_amd); | |
var _strict = _dereq_(68); | |
var _strict2 = _interopRequireDefault(_strict); | |
/** | |
* [Please add a description.] | |
*/ | |
exports["default"] = _strict2["default"](_amd2["default"]); | |
module.exports = exports["default"]; | |
},{"68":68,"70":70}],70:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
// istanbul ignore next | |
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | |
var _default = _dereq_(67); | |
var _default2 = _interopRequireDefault(_default); | |
var _common = _dereq_(72); | |
var _common2 = _interopRequireDefault(_common); | |
var _lodashCollectionIncludes = _dereq_(413); | |
var _lodashCollectionIncludes2 = _interopRequireDefault(_lodashCollectionIncludes); | |
var _lodashObjectValues = _dereq_(517); | |
var _lodashObjectValues2 = _interopRequireDefault(_lodashObjectValues); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var AMDFormatter = (function (_DefaultFormatter) { | |
_inherits(AMDFormatter, _DefaultFormatter); | |
function AMDFormatter() { | |
_classCallCheck(this, AMDFormatter); | |
_DefaultFormatter.apply(this, arguments); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
AMDFormatter.prototype.setup = function setup() { | |
_common2["default"].prototype._setup.call(this, this.hasNonDefaultExports); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
AMDFormatter.prototype.buildDependencyLiterals = function buildDependencyLiterals() { | |
var names = []; | |
for (var name in this.ids) { | |
names.push(t.literal(name)); | |
} | |
return names; | |
}; | |
/** | |
* Wrap the entire body in a `define` wrapper. | |
*/ | |
AMDFormatter.prototype.transform = function transform(program) { | |
_common2["default"].prototype.transform.apply(this, arguments); | |
var body = program.body; | |
// build an array of module names | |
var names = [t.literal("exports")]; | |
if (this.passModuleArg) names.push(t.literal("module")); | |
names = names.concat(this.buildDependencyLiterals()); | |
names = t.arrayExpression(names); | |
// build up define container | |
var params = _lodashObjectValues2["default"](this.ids); | |
if (this.passModuleArg) params.unshift(t.identifier("module")); | |
params.unshift(t.identifier("exports")); | |
var container = t.functionExpression(null, params, t.blockStatement(body)); | |
var defineArgs = [names, container]; | |
var moduleName = this.getModuleName(); | |
if (moduleName) defineArgs.unshift(t.literal(moduleName)); | |
var call = t.callExpression(t.identifier("define"), defineArgs); | |
program.body = [t.expressionStatement(call)]; | |
}; | |
/** | |
* Get the AMD module name that we'll prepend to the wrapper | |
* to define this module | |
*/ | |
AMDFormatter.prototype.getModuleName = function getModuleName() { | |
if (this.file.opts.moduleIds) { | |
return _default2["default"].prototype.getModuleName.apply(this, arguments); | |
} else { | |
return null; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
AMDFormatter.prototype._getExternalReference = function _getExternalReference(node) { | |
return this.scope.generateUidIdentifier(node.source.value); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
AMDFormatter.prototype.importDeclaration = function importDeclaration(node) { | |
this.getExternalReference(node); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
AMDFormatter.prototype.importSpecifier = function importSpecifier(specifier, node, nodes, scope) { | |
var key = node.source.value; | |
var ref = this.getExternalReference(node); | |
if (t.isImportNamespaceSpecifier(specifier) || t.isImportDefaultSpecifier(specifier)) { | |
this.defaultIds[key] = specifier.local; | |
} | |
if (this.isModuleType(node, "absolute")) { | |
// absolute module reference | |
} else if (this.isModuleType(node, "absoluteDefault")) { | |
// prevent unnecessary renaming of dynamic imports | |
this.ids[node.source.value] = ref; | |
ref = t.memberExpression(ref, t.identifier("default")); | |
} else if (t.isImportNamespaceSpecifier(specifier)) { | |
// import * as bar from "foo"; | |
} else if (!_lodashCollectionIncludes2["default"](this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) { | |
// import foo from "foo"; | |
var uid = scope.generateUidIdentifier(specifier.local.name); | |
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref]))])); | |
ref = t.memberExpression(uid, t.identifier("default")); | |
} else { | |
// import { foo } from "foo"; | |
var imported = specifier.imported; | |
if (t.isSpecifierDefault(specifier)) imported = t.identifier("default"); | |
ref = t.memberExpression(ref, imported); | |
} | |
this.remaps.add(scope, specifier.local.name, ref); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
AMDFormatter.prototype.exportSpecifier = function exportSpecifier(specifier, node, nodes) { | |
if (this.doDefaultExportInterop(specifier)) { | |
this.passModuleArg = true; | |
if (specifier.exported !== specifier.local && !node.source) { | |
nodes.push(util.template("exports-default-assign", { | |
VALUE: specifier.local | |
}, true)); | |
return; | |
} | |
} | |
_common2["default"].prototype.exportSpecifier.apply(this, arguments); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
AMDFormatter.prototype.exportDeclaration = function exportDeclaration(node, nodes) { | |
if (this.doDefaultExportInterop(node)) { | |
this.passModuleArg = true; | |
var declar = node.declaration; | |
var assign = util.template("exports-default-assign", { | |
VALUE: this._pushStatement(declar, nodes) | |
}, true); | |
if (t.isFunctionDeclaration(declar)) { | |
// we can hoist this assignment to the top of the file | |
assign._blockHoist = 3; | |
} | |
nodes.push(assign); | |
return; | |
} | |
_default2["default"].prototype.exportDeclaration.apply(this, arguments); | |
}; | |
return AMDFormatter; | |
})(_default2["default"]); | |
exports["default"] = AMDFormatter; | |
module.exports = exports["default"]; | |
},{"179":179,"182":182,"413":413,"517":517,"67":67,"72":72}],71:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _common = _dereq_(72); | |
var _common2 = _interopRequireDefault(_common); | |
var _strict = _dereq_(68); | |
var _strict2 = _interopRequireDefault(_strict); | |
/** | |
* [Please add a description.] | |
*/ | |
exports["default"] = _strict2["default"](_common2["default"]); | |
module.exports = exports["default"]; | |
},{"68":68,"72":72}],72:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
// istanbul ignore next | |
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | |
var _default = _dereq_(67); | |
var _default2 = _interopRequireDefault(_default); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var CommonJSFormatter = (function (_DefaultFormatter) { | |
_inherits(CommonJSFormatter, _DefaultFormatter); | |
function CommonJSFormatter() { | |
_classCallCheck(this, CommonJSFormatter); | |
_DefaultFormatter.apply(this, arguments); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
CommonJSFormatter.prototype.setup = function setup() { | |
this._setup(this.hasLocalExports); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CommonJSFormatter.prototype._setup = function _setup(conditional) { | |
var file = this.file; | |
var scope = file.scope; | |
scope.rename("module"); | |
scope.rename("exports"); | |
if (!this.noInteropRequireImport && conditional) { | |
var templateName = "exports-module-declaration"; | |
if (this.file.isLoose("es6.modules")) templateName += "-loose"; | |
var declar = util.template(templateName, true); | |
declar._blockHoist = 3; | |
file.path.unshiftContainer("body", [declar]); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CommonJSFormatter.prototype.transform = function transform(program) { | |
_default2["default"].prototype.transform.apply(this, arguments); | |
if (this.hasDefaultOnlyExport) { | |
program.body.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier("module"), t.identifier("exports")), t.memberExpression(t.identifier("exports"), t.identifier("default"))))); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CommonJSFormatter.prototype.importSpecifier = function importSpecifier(specifier, node, nodes, scope) { | |
var variableName = specifier.local; | |
var ref = this.getExternalReference(node, nodes); | |
// import foo from "foo"; | |
if (t.isSpecifierDefault(specifier)) { | |
if (this.isModuleType(node, "absolute")) { | |
// absolute module reference | |
} else if (this.isModuleType(node, "absoluteDefault")) { | |
this.remaps.add(scope, variableName.name, ref); | |
} else if (this.noInteropRequireImport) { | |
this.remaps.add(scope, variableName.name, t.memberExpression(ref, t.identifier("default"))); | |
} else { | |
var uid = this.scope.generateUidIdentifierBasedOnNode(node, "import"); | |
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref]))])); | |
this.remaps.add(scope, variableName.name, t.memberExpression(uid, t.identifier("default"))); | |
} | |
} else { | |
if (t.isImportNamespaceSpecifier(specifier)) { | |
if (!this.noInteropRequireImport) { | |
ref = t.callExpression(this.file.addHelper("interop-require-wildcard"), [ref]); | |
} | |
// import * as bar from "foo"; | |
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(variableName, ref)])); | |
} else { | |
// import { foo } from "foo"; | |
this.remaps.add(scope, variableName.name, t.memberExpression(ref, t.identifier(specifier.imported.name))); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CommonJSFormatter.prototype.importDeclaration = function importDeclaration(node, nodes) { | |
// import "foo"; | |
nodes.push(util.template("require", { | |
MODULE_NAME: node.source | |
}, true)); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CommonJSFormatter.prototype.exportSpecifier = function exportSpecifier(specifier) { | |
if (this.doDefaultExportInterop(specifier)) { | |
this.hasDefaultOnlyExport = true; | |
} | |
_default2["default"].prototype.exportSpecifier.apply(this, arguments); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CommonJSFormatter.prototype.exportDeclaration = function exportDeclaration(node) { | |
if (this.doDefaultExportInterop(node)) { | |
this.hasDefaultOnlyExport = true; | |
} | |
_default2["default"].prototype.exportDeclaration.apply(this, arguments); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
CommonJSFormatter.prototype._getExternalReference = function _getExternalReference(node, nodes) { | |
var call = t.callExpression(t.identifier("require"), [node.source]); | |
var uid; | |
if (this.isModuleType(node, "absolute")) { | |
// absolute module reference | |
} else if (this.isModuleType(node, "absoluteDefault")) { | |
call = t.memberExpression(call, t.identifier("default")); | |
} else { | |
uid = this.scope.generateUidIdentifierBasedOnNode(node, "import"); | |
} | |
uid = uid || node.specifiers[0].local; | |
var declar = t.variableDeclaration("var", [t.variableDeclarator(uid, call)]); | |
nodes.push(declar); | |
return uid; | |
}; | |
return CommonJSFormatter; | |
})(_default2["default"]); | |
exports["default"] = CommonJSFormatter; | |
module.exports = exports["default"]; | |
},{"179":179,"182":182,"67":67}],73:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
// istanbul ignore next | |
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | |
var _default = _dereq_(67); | |
var _default2 = _interopRequireDefault(_default); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var IgnoreFormatter = (function (_DefaultFormatter) { | |
_inherits(IgnoreFormatter, _DefaultFormatter); | |
function IgnoreFormatter() { | |
_classCallCheck(this, IgnoreFormatter); | |
_DefaultFormatter.apply(this, arguments); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
IgnoreFormatter.prototype.exportDeclaration = function exportDeclaration(node, nodes) { | |
var declar = t.toStatement(node.declaration, true); | |
if (declar) nodes.push(t.inherits(declar, node)); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
IgnoreFormatter.prototype.exportAllDeclaration = function exportAllDeclaration() {}; | |
IgnoreFormatter.prototype.importDeclaration = function importDeclaration() {}; | |
IgnoreFormatter.prototype.importSpecifier = function importSpecifier() {}; | |
IgnoreFormatter.prototype.exportSpecifier = function exportSpecifier() {}; | |
IgnoreFormatter.prototype.transform = function transform() {}; | |
return IgnoreFormatter; | |
})(_default2["default"]); | |
exports["default"] = IgnoreFormatter; | |
module.exports = exports["default"]; | |
},{"179":179,"67":67}],74:[function(_dereq_,module,exports){ | |
/** | |
* [Please add a description.] | |
*/ | |
"use strict"; | |
exports.__esModule = true; | |
exports["default"] = { | |
commonStrict: _dereq_(71), | |
amdStrict: _dereq_(69), | |
umdStrict: _dereq_(78), | |
common: _dereq_(72), | |
system: _dereq_(77), | |
ignore: _dereq_(73), | |
amd: _dereq_(70), | |
umd: _dereq_(79) | |
}; | |
module.exports = exports["default"]; | |
},{"69":69,"70":70,"71":71,"72":72,"73":73,"77":77,"78":78,"79":79}],75:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.ExportDeclaration = ExportDeclaration; | |
exports.Scope = Scope; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _lodashObjectExtend = _dereq_(511); | |
var _lodashObjectExtend2 = _interopRequireDefault(_lodashObjectExtend); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var ModuleDeclaration = { | |
enter: function enter(node, parent, scope, formatter) { | |
if (node.source) { | |
node.source.value = formatter.file.resolveModuleSource(node.source.value); | |
formatter.addScope(this); | |
} | |
} | |
}; | |
exports.ModuleDeclaration = ModuleDeclaration; | |
/** | |
* [Please add a description.] | |
*/ | |
var ImportDeclaration = { | |
exit: function exit(node, parent, scope, formatter) { | |
formatter.hasLocalImports = true; | |
var specifiers = []; | |
var imported = []; | |
formatter.metadata.imports.push({ | |
source: node.source.value, | |
imported: imported, | |
specifiers: specifiers | |
}); | |
var _arr = this.get("specifiers"); | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var specifier = _arr[_i]; | |
var ids = specifier.getBindingIdentifiers(); | |
_lodashObjectExtend2["default"](formatter.localImports, ids); | |
var local = specifier.node.local.name; | |
if (specifier.isImportDefaultSpecifier()) { | |
imported.push("default"); | |
specifiers.push({ | |
kind: "named", | |
imported: "default", | |
local: local | |
}); | |
} | |
if (specifier.isImportSpecifier()) { | |
var importedName = specifier.node.imported.name; | |
imported.push(importedName); | |
specifiers.push({ | |
kind: "named", | |
imported: importedName, | |
local: local | |
}); | |
} | |
if (specifier.isImportNamespaceSpecifier()) { | |
imported.push("*"); | |
specifiers.push({ | |
kind: "namespace", | |
local: local | |
}); | |
} | |
} | |
} | |
}; | |
exports.ImportDeclaration = ImportDeclaration; | |
/** | |
* [Please add a description.] | |
*/ | |
function ExportDeclaration(node, parent, scope, formatter) { | |
formatter.hasLocalExports = true; | |
var source = node.source ? node.source.value : null; | |
var exports = formatter.metadata.exports; | |
// export function foo() {} | |
// export var foo = "bar"; | |
var declar = this.get("declaration"); | |
if (declar.isStatement()) { | |
var bindings = declar.getBindingIdentifiers(); | |
for (var name in bindings) { | |
var binding = bindings[name]; | |
formatter._addExport(name, binding); | |
exports.exported.push(name); | |
exports.specifiers.push({ | |
kind: "local", | |
local: name, | |
exported: this.isExportDefaultDeclaration() ? "default" : name | |
}); | |
} | |
} | |
if (this.isExportNamedDeclaration() && node.specifiers) { | |
var _arr2 = node.specifiers; | |
for (var _i2 = 0; _i2 < _arr2.length; _i2++) { | |
var specifier = _arr2[_i2]; | |
var exported = specifier.exported.name; | |
exports.exported.push(exported); | |
// export foo from "bar"; | |
if (t.isExportDefaultSpecifier(specifier)) { | |
exports.specifiers.push({ | |
kind: "external", | |
local: exported, | |
exported: exported, | |
source: source | |
}); | |
} | |
// export * as foo from "bar"; | |
if (t.isExportNamespaceSpecifier(specifier)) { | |
exports.specifiers.push({ | |
kind: "external-namespace", | |
exported: exported, | |
source: source | |
}); | |
} | |
var local = specifier.local; | |
if (!local) continue; | |
formatter._addExport(local.name, specifier.exported); | |
// export { foo } from "bar"; | |
// export { foo as bar } from "bar"; | |
if (source) { | |
exports.specifiers.push({ | |
kind: "external", | |
local: local.name, | |
exported: exported, | |
source: source | |
}); | |
} | |
// export { foo }; | |
// export { foo as bar }; | |
if (!source) { | |
exports.specifiers.push({ | |
kind: "local", | |
local: local.name, | |
exported: exported | |
}); | |
} | |
} | |
} | |
// export * from "bar"; | |
if (this.isExportAllDeclaration()) { | |
exports.specifiers.push({ | |
kind: "external-all", | |
source: source | |
}); | |
} | |
if (!t.isExportDefaultDeclaration(node) && !declar.isTypeAlias()) { | |
var onlyDefault = node.specifiers && node.specifiers.length === 1 && t.isSpecifierDefault(node.specifiers[0]); | |
if (!onlyDefault) { | |
formatter.hasNonDefaultExports = true; | |
} | |
} | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function Scope(node, parent, scope, formatter) { | |
if (!formatter.isLoose()) { | |
this.skip(); | |
} | |
} | |
},{"179":179,"511":511}],76:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var remapVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
enter: function enter(node) { | |
if (node._skipModulesRemap) { | |
return this.skip(); | |
} | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
ReferencedIdentifier: function ReferencedIdentifier(node, parent, scope, remaps) { | |
var formatter = remaps.formatter; | |
var remap = remaps.get(scope, node.name); | |
if (!remap || node === remap) return; | |
if (!scope.hasBinding(node.name) || scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) { | |
if (!formatter.isLoose() && this.key === "callee" && this.parentPath.isCallExpression()) { | |
return t.sequenceExpression([t.literal(0), remap]); | |
} else { | |
return remap; | |
} | |
} | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
AssignmentExpression: { | |
exit: function exit(node, parent, scope, _ref) { | |
var formatter = _ref.formatter; | |
if (!node._ignoreModulesRemap) { | |
var exported = formatter.getExport(node.left, scope); | |
if (exported) { | |
return formatter.remapExportAssignment(node, exported); | |
} | |
} | |
} | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
UpdateExpression: function UpdateExpression(node, parent, scope, _ref2) { | |
var formatter = _ref2.formatter; | |
var exported = formatter.getExport(node.argument, scope); | |
if (!exported) return; | |
this.skip(); | |
// expand to long file assignment expression | |
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1)); | |
// remap this assignment expression | |
var remapped = formatter.remapExportAssignment(assign, exported); | |
// we don't need to change the result | |
if (t.isExpressionStatement(parent) || node.prefix) { | |
return remapped; | |
} | |
var nodes = []; | |
nodes.push(remapped); | |
var operator; | |
if (node.operator === "--") { | |
operator = "+"; | |
} else { | |
// "++" | |
operator = "-"; | |
} | |
nodes.push(t.binaryExpression(operator, node.argument, t.literal(1))); | |
return t.sequenceExpression(nodes); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var Remaps = (function () { | |
function Remaps(file, formatter) { | |
_classCallCheck(this, Remaps); | |
this.formatter = formatter; | |
this.file = file; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
Remaps.prototype.run = function run() { | |
this.file.path.traverse(remapVisitor, this); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Remaps.prototype._getKey = function _getKey(name) { | |
return name + ":moduleRemap"; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Remaps.prototype.get = function get(scope, name) { | |
return scope.getData(this._getKey(name)); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Remaps.prototype.add = function add(scope, name, val) { | |
if (this.all) { | |
this.all.push({ | |
name: name, | |
scope: scope, | |
node: val | |
}); | |
} | |
return scope.setData(this._getKey(name), val); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Remaps.prototype.remove = function remove(scope, name) { | |
return scope.removeData(this._getKey(name)); | |
}; | |
/** | |
* These methods are used by the system module formatter who needs access to all the remaps | |
* so it can process them into it's specific setter method. We don't do this by default since | |
* no other module formatters need access to this. | |
*/ | |
Remaps.prototype.getAll = function getAll() { | |
return this.all; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Remaps.prototype.clearAll = function clearAll() { | |
if (this.all) { | |
var _arr = this.all; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var remap = _arr[_i]; | |
remap.scope.removeData(this._getKey(remap.name)); | |
} | |
} | |
this.all = []; | |
}; | |
return Remaps; | |
})(); | |
exports["default"] = Remaps; | |
module.exports = exports["default"]; | |
},{"179":179}],77:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
// istanbul ignore next | |
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | |
var _default = _dereq_(67); | |
var _default2 = _interopRequireDefault(_default); | |
var _amd = _dereq_(70); | |
var _amd2 = _interopRequireDefault(_amd); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _lodashArrayLast = _dereq_(407); | |
var _lodashArrayLast2 = _interopRequireDefault(_lodashArrayLast); | |
var _lodashCollectionMap = _dereq_(414); | |
var _lodashCollectionMap2 = _interopRequireDefault(_lodashCollectionMap); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var hoistVariablesVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Function: function Function() { | |
// nothing inside is accessible | |
this.skip(); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
VariableDeclaration: function VariableDeclaration(node, parent, scope, state) { | |
if (node.kind !== "var" && !t.isProgram(parent)) { | |
// let, const | |
// can't be accessed | |
return; | |
} | |
// ignore block hoisted nodes as these can be left in | |
if (state.formatter._canHoist(node)) return; | |
var nodes = []; | |
for (var i = 0; i < node.declarations.length; i++) { | |
var declar = node.declarations[i]; | |
state.hoistDeclarators.push(t.variableDeclarator(declar.id)); | |
if (declar.init) { | |
// no initializer so we can just hoist it as-is | |
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init)); | |
nodes.push(assign); | |
} | |
} | |
// for (var i in test) | |
if (t.isFor(parent) && parent.left === node) { | |
return node.declarations[0].id; | |
} | |
return nodes; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var hoistFunctionsVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Function: function Function() { | |
this.skip(); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
enter: function enter(node, parent, scope, state) { | |
if (t.isFunctionDeclaration(node) || state.formatter._canHoist(node)) { | |
state.handlerBody.push(node); | |
this.dangerouslyRemove(); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var runnerSettersVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
enter: function enter(node, parent, scope, state) { | |
if (node._importSource === state.source) { | |
if (t.isVariableDeclaration(node)) { | |
var _arr = node.declarations; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var declar = _arr[_i]; | |
state.hoistDeclarators.push(t.variableDeclarator(declar.id)); | |
state.nodes.push(t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init))); | |
} | |
} else { | |
state.nodes.push(node); | |
} | |
this.dangerouslyRemove(); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var SystemFormatter = (function (_AMDFormatter) { | |
_inherits(SystemFormatter, _AMDFormatter); | |
function SystemFormatter(file) { | |
_classCallCheck(this, SystemFormatter); | |
_AMDFormatter.call(this, file); | |
this._setters = null; | |
this.exportIdentifier = file.scope.generateUidIdentifier("export"); | |
this.noInteropRequireExport = true; | |
this.noInteropRequireImport = true; | |
this.remaps.clearAll(); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
SystemFormatter.prototype._addImportSource = function _addImportSource(node, exportNode) { | |
if (node) node._importSource = exportNode.source && exportNode.source.value; | |
return node; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
SystemFormatter.prototype.buildExportsWildcard = function buildExportsWildcard(objectIdentifier, node) { | |
var leftIdentifier = this.scope.generateUidIdentifier("key"); | |
var valIdentifier = t.memberExpression(objectIdentifier, leftIdentifier, true); | |
var left = t.variableDeclaration("var", [t.variableDeclarator(leftIdentifier)]); | |
var right = objectIdentifier; | |
var block = t.blockStatement([t.ifStatement(t.binaryExpression("!==", leftIdentifier, t.literal("default")), t.expressionStatement(this._buildExportCall(leftIdentifier, valIdentifier)))]); | |
return this._addImportSource(t.forInStatement(left, right, block), node); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
SystemFormatter.prototype.buildExportsAssignment = function buildExportsAssignment(id, init, node) { | |
var call = this._buildExportCall(t.literal(id.name), init, true); | |
return this._addImportSource(call, node); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
SystemFormatter.prototype.buildExportsFromAssignment = function buildExportsFromAssignment() { | |
return this.buildExportsAssignment.apply(this, arguments); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
SystemFormatter.prototype.remapExportAssignment = function remapExportAssignment(node, exported) { | |
var assign = node; | |
for (var i = 0; i < exported.length; i++) { | |
assign = this._buildExportCall(t.literal(exported[i].name), assign); | |
} | |
return assign; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
SystemFormatter.prototype._buildExportCall = function _buildExportCall(id, init, isStatement) { | |
var call = t.callExpression(this.exportIdentifier, [id, init]); | |
if (isStatement) { | |
return t.expressionStatement(call); | |
} else { | |
return call; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
SystemFormatter.prototype.importSpecifier = function importSpecifier(specifier, node, nodes) { | |
_amd2["default"].prototype.importSpecifier.apply(this, arguments); | |
var _arr2 = this.remaps.getAll(); | |
for (var _i2 = 0; _i2 < _arr2.length; _i2++) { | |
var remap = _arr2[_i2]; | |
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(t.identifier(remap.name), remap.node)])); | |
} | |
this.remaps.clearAll(); | |
this._addImportSource(_lodashArrayLast2["default"](nodes), node); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
SystemFormatter.prototype._buildRunnerSetters = function _buildRunnerSetters(block, hoistDeclarators) { | |
var scope = this.file.scope; | |
return t.arrayExpression(_lodashCollectionMap2["default"](this.ids, function (uid, source) { | |
var state = { | |
hoistDeclarators: hoistDeclarators, | |
source: source, | |
nodes: [] | |
}; | |
scope.traverse(block, runnerSettersVisitor, state); | |
return t.functionExpression(null, [uid], t.blockStatement(state.nodes)); | |
})); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
SystemFormatter.prototype._canHoist = function _canHoist(node) { | |
return node._blockHoist && !this.file.dynamicImports.length; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
SystemFormatter.prototype.transform = function transform(program) { | |
_default2["default"].prototype.transform.apply(this, arguments); | |
var hoistDeclarators = []; | |
var moduleName = this.getModuleName(); | |
var moduleNameLiteral = t.literal(moduleName); | |
var block = t.blockStatement(program.body); | |
var setterListNode = this._buildRunnerSetters(block, hoistDeclarators); | |
this._setters = setterListNode; | |
var runner = util.template("system", { | |
MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()), | |
EXPORT_IDENTIFIER: this.exportIdentifier, | |
MODULE_NAME: moduleNameLiteral, | |
SETTERS: setterListNode, | |
EXECUTE: t.functionExpression(null, [], block) | |
}, true); | |
var handlerBody = runner.expression.arguments[2].body.body; | |
if (!moduleName) runner.expression.arguments.shift(); | |
var returnStatement = handlerBody.pop(); | |
// hoist up all variable declarations | |
this.file.scope.traverse(block, hoistVariablesVisitor, { | |
formatter: this, | |
hoistDeclarators: hoistDeclarators | |
}); | |
if (hoistDeclarators.length) { | |
var hoistDeclar = t.variableDeclaration("var", hoistDeclarators); | |
hoistDeclar._blockHoist = true; | |
handlerBody.unshift(hoistDeclar); | |
} | |
// hoist up function declarations for circular references | |
this.file.scope.traverse(block, hoistFunctionsVisitor, { | |
formatter: this, | |
handlerBody: handlerBody | |
}); | |
handlerBody.push(returnStatement); | |
program.body = [runner]; | |
}; | |
return SystemFormatter; | |
})(_amd2["default"]); | |
exports["default"] = SystemFormatter; | |
module.exports = exports["default"]; | |
},{"179":179,"182":182,"407":407,"414":414,"67":67,"70":70}],78:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _umd = _dereq_(79); | |
var _umd2 = _interopRequireDefault(_umd); | |
var _strict = _dereq_(68); | |
var _strict2 = _interopRequireDefault(_strict); | |
/** | |
* [Please add a description.] | |
*/ | |
exports["default"] = _strict2["default"](_umd2["default"]); | |
module.exports = exports["default"]; | |
},{"68":68,"79":79}],79:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
// istanbul ignore next | |
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | |
var _default = _dereq_(67); | |
var _default2 = _interopRequireDefault(_default); | |
var _amd = _dereq_(70); | |
var _amd2 = _interopRequireDefault(_amd); | |
var _lodashObjectValues = _dereq_(517); | |
var _lodashObjectValues2 = _interopRequireDefault(_lodashObjectValues); | |
var _path = _dereq_(9); | |
var _path2 = _interopRequireDefault(_path); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var UMDFormatter = (function (_AMDFormatter) { | |
_inherits(UMDFormatter, _AMDFormatter); | |
function UMDFormatter() { | |
_classCallCheck(this, UMDFormatter); | |
_AMDFormatter.apply(this, arguments); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
UMDFormatter.prototype.transform = function transform(program) { | |
_default2["default"].prototype.transform.apply(this, arguments); | |
var body = program.body; | |
// build an array of module names | |
var names = []; | |
for (var _name in this.ids) { | |
names.push(t.literal(_name)); | |
} | |
// factory | |
var ids = _lodashObjectValues2["default"](this.ids); | |
var args = [t.identifier("exports")]; | |
if (this.passModuleArg) args.push(t.identifier("module")); | |
args = args.concat(ids); | |
var factory = t.functionExpression(null, args, t.blockStatement(body)); | |
// amd | |
var defineArgs = [t.literal("exports")]; | |
if (this.passModuleArg) defineArgs.push(t.literal("module")); | |
defineArgs = defineArgs.concat(names); | |
defineArgs = [t.arrayExpression(defineArgs)]; | |
// common | |
var testExports = util.template("test-exports"); | |
var testModule = util.template("test-module"); | |
var commonTests = this.passModuleArg ? t.logicalExpression("&&", testExports, testModule) : testExports; | |
var commonArgs = [t.identifier("exports")]; | |
if (this.passModuleArg) commonArgs.push(t.identifier("module")); | |
commonArgs = commonArgs.concat(names.map(function (name) { | |
return t.callExpression(t.identifier("require"), [name]); | |
})); | |
// globals | |
var browserArgs = []; | |
if (this.passModuleArg) browserArgs.push(t.identifier("mod")); | |
for (var _name2 in this.ids) { | |
var id = this.defaultIds[_name2] || t.identifier(t.toIdentifier(_path2["default"].basename(_name2, _path2["default"].extname(_name2)))); | |
browserArgs.push(t.memberExpression(t.identifier("global"), id)); | |
} | |
// | |
var moduleName = this.getModuleName(); | |
if (moduleName) defineArgs.unshift(t.literal(moduleName)); | |
// | |
var globalArg = this.file.opts.basename; | |
if (moduleName) globalArg = moduleName; | |
globalArg = t.identifier(t.toIdentifier(globalArg)); | |
var runner = util.template("umd-runner-body", { | |
AMD_ARGUMENTS: defineArgs, | |
COMMON_TEST: commonTests, | |
COMMON_ARGUMENTS: commonArgs, | |
BROWSER_ARGUMENTS: browserArgs, | |
GLOBAL_ARG: globalArg | |
}); | |
// | |
program.body = [t.expressionStatement(t.callExpression(runner, [t.thisExpression(), factory]))]; | |
}; | |
return UMDFormatter; | |
})(_amd2["default"]); | |
exports["default"] = UMDFormatter; | |
module.exports = exports["default"]; | |
},{"179":179,"182":182,"517":517,"67":67,"70":70,"9":9}],80:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _filePluginManager = _dereq_(52); | |
var _filePluginManager2 = _interopRequireDefault(_filePluginManager); | |
var _helpersNormalizeAst = _dereq_(40); | |
var _helpersNormalizeAst2 = _interopRequireDefault(_helpersNormalizeAst); | |
var _plugin = _dereq_(82); | |
var _plugin2 = _interopRequireDefault(_plugin); | |
var _lodashObjectAssign = _dereq_(509); | |
var _lodashObjectAssign2 = _interopRequireDefault(_lodashObjectAssign); | |
var _helpersObject = _dereq_(41); | |
var _helpersObject2 = _interopRequireDefault(_helpersObject); | |
var _file = _dereq_(46); | |
var _file2 = _interopRequireDefault(_file); | |
/** | |
* [Please add a description.] | |
*/ | |
var Pipeline = (function () { | |
function Pipeline() { | |
_classCallCheck(this, Pipeline); | |
this.transformers = _helpersObject2["default"](); | |
this.namespaces = _helpersObject2["default"](); | |
this.deprecated = _helpersObject2["default"](); | |
this.aliases = _helpersObject2["default"](); | |
this.filters = []; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
Pipeline.prototype.addTransformers = function addTransformers(transformers) { | |
for (var key in transformers) { | |
this.addTransformer(key, transformers[key]); | |
} | |
return this; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Pipeline.prototype.addTransformer = function addTransformer(key, plugin) { | |
if (this.transformers[key]) throw new Error(); // todo: error | |
var namespace = key.split(".")[0]; | |
this.namespaces[namespace] = this.namespaces[namespace] || []; | |
this.namespaces[namespace].push(key); | |
this.namespaces[key] = namespace; | |
if (typeof plugin === "function") { | |
plugin = _filePluginManager2["default"].memoisePluginContainer(plugin); | |
plugin.key = key; | |
plugin.metadata.optional = true; | |
if (key === "react.displayName") { | |
plugin.metadata.optional = false; | |
} | |
} else { | |
plugin = new _plugin2["default"](key, plugin); | |
} | |
this.transformers[key] = plugin; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Pipeline.prototype.addAliases = function addAliases(names) { | |
_lodashObjectAssign2["default"](this.aliases, names); | |
return this; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Pipeline.prototype.addDeprecated = function addDeprecated(names) { | |
_lodashObjectAssign2["default"](this.deprecated, names); | |
return this; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Pipeline.prototype.addFilter = function addFilter(filter) { | |
this.filters.push(filter); | |
return this; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Pipeline.prototype.canTransform = function canTransform(plugin, fileOpts) { | |
if (plugin.metadata.plugin) { | |
return true; | |
} | |
var _arr = this.filters; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var filter = _arr[_i]; | |
var result = filter(plugin, fileOpts); | |
if (result != null) return result; | |
} | |
return true; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Pipeline.prototype.analyze = function analyze(code) { | |
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | |
opts.code = false; | |
return this.transform(code, opts); | |
}; | |
/** | |
* Build dependency graph by recursing `metadata.modules`. WIP. | |
*/ | |
Pipeline.prototype.pretransform = function pretransform(code, opts) { | |
var file = new _file2["default"](opts, this); | |
return file.wrap(code, function () { | |
file.addCode(code); | |
file.parseCode(code); | |
return file; | |
}); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Pipeline.prototype.transform = function transform(code, opts) { | |
var file = new _file2["default"](opts, this); | |
return file.wrap(code, function () { | |
file.addCode(code); | |
file.parseCode(code); | |
return file.transform(); | |
}); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Pipeline.prototype.transformFromAst = function transformFromAst(ast, code, opts) { | |
ast = _helpersNormalizeAst2["default"](ast); | |
var file = new _file2["default"](opts, this); | |
return file.wrap(code, function () { | |
file.addCode(code); | |
file.addAst(ast); | |
return file.transform(); | |
}); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Pipeline.prototype._ensureTransformerNames = function _ensureTransformerNames(type, rawKeys) { | |
var keys = []; | |
for (var i = 0; i < rawKeys.length; i++) { | |
var key = rawKeys[i]; | |
var deprecatedKey = this.deprecated[key]; | |
var aliasKey = this.aliases[key]; | |
if (aliasKey) { | |
keys.push(aliasKey); | |
} else if (deprecatedKey) { | |
// deprecated key, remap it to the new one | |
console.error("[BABEL] The transformer " + key + " has been renamed to " + deprecatedKey); | |
rawKeys.push(deprecatedKey); | |
} else if (this.transformers[key]) { | |
// valid key | |
keys.push(key); | |
} else if (this.namespaces[key]) { | |
// namespace, append all transformers within this namespace | |
keys = keys.concat(this.namespaces[key]); | |
} else { | |
// invalid key | |
throw new ReferenceError("Unknown transformer " + key + " specified in " + type); | |
} | |
} | |
return keys; | |
}; | |
return Pipeline; | |
})(); | |
exports["default"] = Pipeline; | |
module.exports = exports["default"]; | |
},{"40":40,"41":41,"46":46,"509":509,"52":52,"82":82}],81:[function(_dereq_,module,exports){ | |
/** | |
* This class is responsible for traversing over the provided `File`s | |
* AST and running it's parent transformers handlers over it. | |
*/ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _traversal = _dereq_(148); | |
var _traversal2 = _interopRequireDefault(_traversal); | |
var PluginPass = (function () { | |
function PluginPass(file, plugin) { | |
_classCallCheck(this, PluginPass); | |
this.plugin = plugin; | |
this.file = file; | |
this.key = plugin.key; | |
if (this.canTransform() && plugin.metadata.experimental && !file.opts.experimental) { | |
file.log.warn("THE TRANSFORMER " + this.key + " HAS BEEN MARKED AS EXPERIMENTAL AND IS WIP. USE AT YOUR OWN RISK. " + "THIS WILL HIGHLY LIKELY BREAK YOUR CODE SO USE WITH **EXTREME** CAUTION. ENABLE THE " + "`experimental` OPTION TO IGNORE THIS WARNING."); | |
} | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
PluginPass.prototype.canTransform = function canTransform() { | |
return this.file.transformerDependencies[this.key] || this.file.pipeline.canTransform(this.plugin, this.file.opts); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
PluginPass.prototype.transform = function transform() { | |
var file = this.file; | |
file.log.debug("Start transformer " + this.key); | |
_traversal2["default"](file.ast, this.plugin.visitor, file.scope, file); | |
file.log.debug("Finish transformer " + this.key); | |
}; | |
return PluginPass; | |
})(); | |
exports["default"] = PluginPass; | |
module.exports = exports["default"]; | |
},{"148":148}],82:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _pluginPass = _dereq_(81); | |
var _pluginPass2 = _interopRequireDefault(_pluginPass); | |
var _messages = _dereq_(43); | |
var messages = _interopRequireWildcard(_messages); | |
var _traversal = _dereq_(148); | |
var _traversal2 = _interopRequireDefault(_traversal); | |
var _lodashObjectAssign = _dereq_(509); | |
var _lodashObjectAssign2 = _interopRequireDefault(_lodashObjectAssign); | |
var _lodashLangClone = _dereq_(494); | |
var _lodashLangClone2 = _interopRequireDefault(_lodashLangClone); | |
var _file = _dereq_(46); | |
var _file2 = _interopRequireDefault(_file); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var VALID_PLUGIN_PROPERTIES = ["visitor", "metadata", "manipulateOptions", "post", "pre"]; | |
var VALID_METADATA_PROPERTIES = ["dependencies", "optional", "stage", "group", "experimental", "secondPass"]; | |
/** | |
* [Please add a description.] | |
*/ | |
var Plugin = (function () { | |
function Plugin(key, plugin) { | |
_classCallCheck(this, Plugin); | |
Plugin.validate(key, plugin); | |
plugin = _lodashObjectAssign2["default"]({}, plugin); | |
var take = function take(key) { | |
var val = plugin[key]; | |
delete plugin[key]; | |
return val; | |
}; | |
this.manipulateOptions = take("manipulateOptions"); | |
this.metadata = take("metadata") || {}; | |
this.dependencies = this.metadata.dependencies || []; | |
this.post = take("post"); | |
this.pre = take("pre"); | |
// | |
if (this.metadata.stage != null) { | |
this.metadata.optional = true; | |
} | |
// | |
this.visitor = this.normalize(_lodashLangClone2["default"](take("visitor")) || {}); | |
this.key = key; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
Plugin.validate = function validate(name, plugin) { | |
for (var key in plugin) { | |
if (key[0] === "_") continue; | |
if (VALID_PLUGIN_PROPERTIES.indexOf(key) >= 0) continue; | |
var msgType = "pluginInvalidProperty"; | |
if (t.TYPES.indexOf(key) >= 0) msgType = "pluginInvalidPropertyVisitor"; | |
throw new Error(messages.get(msgType, name, key)); | |
} | |
for (var key in plugin.metadata) { | |
if (VALID_METADATA_PROPERTIES.indexOf(key) >= 0) continue; | |
throw new Error(messages.get("pluginInvalidProperty", name, "metadata." + key)); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Plugin.prototype.normalize = function normalize(visitor) { | |
_traversal2["default"].explode(visitor); | |
return visitor; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
Plugin.prototype.buildPass = function buildPass(file) { | |
// validate Transformer instance | |
if (!(file instanceof _file2["default"])) { | |
throw new TypeError(messages.get("pluginNotFile", this.key)); | |
} | |
return new _pluginPass2["default"](file, this); | |
}; | |
return Plugin; | |
})(); | |
exports["default"] = Plugin; | |
module.exports = exports["default"]; | |
},{"148":148,"179":179,"43":43,"46":46,"494":494,"509":509,"81":81}],83:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _plugin = _dereq_(82); | |
var _plugin2 = _interopRequireDefault(_plugin); | |
/** | |
* [Please add a description.] | |
*/ | |
var Transformer = function Transformer(key, obj) { | |
_classCallCheck(this, Transformer); | |
var plugin = {}; | |
plugin.metadata = obj.metadata; | |
delete obj.metadata; | |
plugin.visitor = obj; | |
return new _plugin2["default"](key, plugin); | |
}; | |
exports["default"] = Transformer; | |
module.exports = exports["default"]; | |
},{"82":82}],84:[function(_dereq_,module,exports){ | |
module.exports={ | |
"useStrict": "strict", | |
"es5.runtime": "runtime", | |
"es6.runtime": "runtime", | |
"minification.inlineExpressions": "minification.constantFolding" | |
} | |
},{}],85:[function(_dereq_,module,exports){ | |
module.exports={ | |
"selfContained": "runtime", | |
"unicode-regex": "regex.unicode", | |
"spec.typeofSymbol": "es6.spec.symbols", | |
"es6.symbols": "es6.spec.symbols", | |
"es6.blockScopingTDZ": "es6.spec.blockScoping", | |
"utility.inlineExpressions": "minification.constantFolding", | |
"utility.deadCodeElimination": "minification.deadCodeElimination", | |
"utility.removeConsoleCalls": "minification.removeConsole", | |
"utility.removeDebugger": "minification.removeDebugger", | |
"es6.parameters.rest": "es6.parameters", | |
"es6.parameters.default": "es6.parameters" | |
} | |
},{}],86:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
group: "builtin-trailing" | |
}; | |
exports.metadata = metadata; | |
/** | |
* Turn member expression reserved word properties into literals. | |
* | |
* @example | |
* | |
* **In** | |
* | |
* ```javascript | |
* foo.catch; | |
* ``` | |
* | |
* **Out** | |
* | |
* ```javascript | |
* foo["catch"]; | |
* ``` | |
*/ | |
var visitor = { | |
/** | |
* Look for non-computed properties with names that are not valid identifiers. | |
* Turn them into computed properties with literal names. | |
*/ | |
MemberExpression: { | |
exit: function exit(node) { | |
var prop = node.property; | |
if (!node.computed && t.isIdentifier(prop) && !t.isValidIdentifier(prop.name)) { | |
// foo.default -> foo["default"] | |
node.property = t.literal(prop.name); | |
node.computed = true; | |
} | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],87:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
group: "builtin-trailing" | |
}; | |
exports.metadata = metadata; | |
/** | |
* Turn reserved word properties into literals. | |
* | |
* **In** | |
* | |
* ```javascript | |
* var foo = { | |
* catch: function () {} | |
* }; | |
* ``` | |
* | |
* **Out** | |
* | |
* ```javascript | |
* var foo = { | |
* "catch": function () {} | |
* }; | |
* ``` | |
*/ | |
var visitor = { | |
/** | |
* Look for non-computed keys with names that are not valid identifiers. | |
* Turn them into literals. | |
*/ | |
Property: { | |
exit: function exit(node) { | |
var key = node.key; | |
if (!node.computed && t.isIdentifier(key) && !t.isValidIdentifier(key.name)) { | |
// default: "bar" -> "default": "bar" | |
node.key = t.literal(key.name); | |
} | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],88:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _helpersDefineMap = _dereq_(57); | |
var defineMap = _interopRequireWildcard(_helpersDefineMap); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* Turn [object initializer mutators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Method_definitions) | |
* into `Object.defineProperties`. | |
* | |
* **In** | |
* | |
* ```javascript | |
* var foo = { | |
* get bar() { | |
* return "bar"; | |
* } | |
* }; | |
* ``` | |
* | |
* **Out** | |
* | |
* ```javascript | |
* var foo = Object.defineProperties({}, { | |
* bar: { | |
* get: function () { | |
* return "bar"; | |
* }, | |
* enumerable: true, | |
* configurable: true | |
* } | |
* }); | |
* ``` | |
*/ | |
var visitor = { | |
/** | |
* Look for getters and setters on an object. | |
* Filter them out and wrap the object with an `Object.defineProperties` that | |
* defines the getters and setters. | |
*/ | |
ObjectExpression: function ObjectExpression(node, parent, scope, file) { | |
var hasAny = false; | |
var _arr = node.properties; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var prop = _arr[_i]; | |
if (prop.kind === "get" || prop.kind === "set") { | |
hasAny = true; | |
break; | |
} | |
} | |
if (!hasAny) return; | |
var mutatorMap = {}; | |
node.properties = node.properties.filter(function (prop) { | |
if (prop.kind === "get" || prop.kind === "set") { | |
defineMap.push(mutatorMap, prop, prop.kind, file); | |
return false; | |
} else { | |
return true; | |
} | |
}); | |
return t.callExpression(t.memberExpression(t.identifier("Object"), t.identifier("defineProperties")), [node, defineMap.toDefineObject(mutatorMap)]); | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179,"57":57}],89:[function(_dereq_,module,exports){ | |
/** | |
* Turn arrow functions into normal functions. | |
* | |
* @example | |
* | |
* **In** | |
* | |
* ```javascript | |
* arr.map(x => x * x); | |
* ``` | |
* | |
* **Out** | |
* | |
* ```javascript | |
* arr.map(function (x) { | |
* return x * x; | |
* }); | |
*/ | |
"use strict"; | |
exports.__esModule = true; | |
var visitor = { | |
/** | |
* Look for arrow functions and mark them as "shadow functions". | |
* @see /transformation/transformers/internal/shadow-functions.js | |
*/ | |
ArrowFunctionExpression: function ArrowFunctionExpression(node) { | |
this.ensureBlock(); | |
node.expression = false; | |
node.type = "FunctionExpression"; | |
node.shadow = node.shadow || true; | |
} | |
}; | |
exports.visitor = visitor; | |
},{}],90:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _traversal = _dereq_(148); | |
var _traversal2 = _interopRequireDefault(_traversal); | |
var _helpersObject = _dereq_(41); | |
var _helpersObject2 = _interopRequireDefault(_helpersObject); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var _lodashObjectValues = _dereq_(517); | |
var _lodashObjectValues2 = _interopRequireDefault(_lodashObjectValues); | |
var _lodashObjectExtend = _dereq_(511); | |
var _lodashObjectExtend2 = _interopRequireDefault(_lodashObjectExtend); | |
/** | |
* [Please add a description.] | |
*/ | |
function isLet(node, parent) { | |
if (!t.isVariableDeclaration(node)) return false; | |
if (node._let) return true; | |
if (node.kind !== "let") return false; | |
// https://github.com/babel/babel/issues/255 | |
if (isLetInitable(node, parent)) { | |
for (var i = 0; i < node.declarations.length; i++) { | |
var declar = node.declarations[i]; | |
declar.init = declar.init || t.identifier("undefined"); | |
} | |
} | |
node._let = true; | |
node.kind = "var"; | |
return true; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function isLetInitable(node, parent) { | |
return !t.isFor(parent) || !t.isFor(parent, { left: node }); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function isVar(node, parent) { | |
return t.isVariableDeclaration(node, { kind: "var" }) && !isLet(node, parent); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function standardizeLets(declars) { | |
var _arr = declars; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var declar = _arr[_i]; | |
delete declar._let; | |
} | |
} | |
var metadata = { | |
group: "builtin-advanced" | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
VariableDeclaration: function VariableDeclaration(node, parent, scope, file) { | |
if (!isLet(node, parent)) return; | |
if (isLetInitable(node) && file.transformers["es6.spec.blockScoping"].canTransform()) { | |
var nodes = [node]; | |
for (var i = 0; i < node.declarations.length; i++) { | |
var decl = node.declarations[i]; | |
if (decl.init) { | |
var assign = t.assignmentExpression("=", decl.id, decl.init); | |
assign._ignoreBlockScopingTDZ = true; | |
nodes.push(t.expressionStatement(assign)); | |
} | |
decl.init = file.addHelper("temporal-undefined"); | |
} | |
node._blockHoist = 2; | |
return nodes; | |
} | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
Loop: function Loop(node, parent, scope, file) { | |
var init = node.left || node.init; | |
if (isLet(init, node)) { | |
t.ensureBlock(node); | |
node.body._letDeclarators = [init]; | |
} | |
var blockScoping = new BlockScoping(this, this.get("body"), parent, scope, file); | |
return blockScoping.run(); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
"BlockStatement|Program": function BlockStatementProgram(block, parent, scope, file) { | |
if (!t.isLoop(parent)) { | |
var blockScoping = new BlockScoping(null, this, parent, scope, file); | |
blockScoping.run(); | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
/** | |
* [Please add a description.] | |
*/ | |
function replace(node, parent, scope, remaps) { | |
var remap = remaps[node.name]; | |
if (!remap) return; | |
var ownBinding = scope.getBindingIdentifier(node.name); | |
if (ownBinding === remap.binding) { | |
node.name = remap.uid; | |
} else { | |
// scope already has it's own binding that doesn't | |
// match the one we have a stored replacement for | |
if (this) this.skip(); | |
} | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
var replaceVisitor = { | |
ReferencedIdentifier: replace, | |
/** | |
* [Please add a description.] | |
*/ | |
AssignmentExpression: function AssignmentExpression(node, parent, scope, remaps) { | |
var ids = this.getBindingIdentifiers(); | |
for (var name in ids) { | |
replace(ids[name], node, scope, remaps); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
function traverseReplace(node, parent, scope, remaps) { | |
if (t.isIdentifier(node)) { | |
replace(node, parent, scope, remaps); | |
} | |
if (t.isAssignmentExpression(node)) { | |
var ids = t.getBindingIdentifiers(node); | |
for (var name in ids) { | |
replace(ids[name], parent, scope, remaps); | |
} | |
} | |
scope.traverse(node, replaceVisitor, remaps); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
var letReferenceBlockVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Function: function Function(node, parent, scope, state) { | |
this.traverse(letReferenceFunctionVisitor, state); | |
return this.skip(); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var letReferenceFunctionVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ReferencedIdentifier: function ReferencedIdentifier(node, parent, scope, state) { | |
var ref = state.letReferences[node.name]; | |
// not a part of our scope | |
if (!ref) return; | |
// this scope has a variable with the same name so it couldn't belong | |
// to our let scope | |
var localBinding = scope.getBindingIdentifier(node.name); | |
if (localBinding && localBinding !== ref) return; | |
state.closurify = true; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var hoistVarDeclarationsVisitor = { | |
enter: function enter(node, parent, scope, self) { | |
if (this.isForStatement()) { | |
if (isVar(node.init, node)) { | |
var nodes = self.pushDeclar(node.init); | |
if (nodes.length === 1) { | |
node.init = nodes[0]; | |
} else { | |
node.init = t.sequenceExpression(nodes); | |
} | |
} | |
} else if (this.isFor()) { | |
if (isVar(node.left, node)) { | |
self.pushDeclar(node.left); | |
node.left = node.left.declarations[0].id; | |
} | |
} else if (isVar(node, parent)) { | |
return self.pushDeclar(node).map(t.expressionStatement); | |
} else if (this.isFunction()) { | |
return this.skip(); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var loopLabelVisitor = { | |
LabeledStatement: function LabeledStatement(node, parent, scope, state) { | |
state.innerLabels.push(node.label.name); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var continuationVisitor = { | |
enter: function enter(node, parent, scope, state) { | |
if (this.isAssignmentExpression() || this.isUpdateExpression()) { | |
var bindings = this.getBindingIdentifiers(); | |
for (var name in bindings) { | |
if (state.outsideReferences[name] !== scope.getBindingIdentifier(name)) continue; | |
state.reassignments[name] = true; | |
} | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var loopNodeTo = function loopNodeTo(node) { | |
if (t.isBreakStatement(node)) { | |
return "break"; | |
} else if (t.isContinueStatement(node)) { | |
return "continue"; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var loopVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Loop: function Loop(node, parent, scope, state) { | |
var oldIgnoreLabeless = state.ignoreLabeless; | |
state.ignoreLabeless = true; | |
this.traverse(loopVisitor, state); | |
state.ignoreLabeless = oldIgnoreLabeless; | |
this.skip(); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
Function: function Function() { | |
this.skip(); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
SwitchCase: function SwitchCase(node, parent, scope, state) { | |
var oldInSwitchCase = state.inSwitchCase; | |
state.inSwitchCase = true; | |
this.traverse(loopVisitor, state); | |
state.inSwitchCase = oldInSwitchCase; | |
this.skip(); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
enter: function enter(node, parent, scope, state) { | |
var replace; | |
var loopText = loopNodeTo(node); | |
if (loopText) { | |
if (node.label) { | |
// we shouldn't be transforming this because it exists somewhere inside | |
if (state.innerLabels.indexOf(node.label.name) >= 0) { | |
return; | |
} | |
loopText = loopText + "|" + node.label.name; | |
} else { | |
// we shouldn't be transforming these statements because | |
// they don't refer to the actual loop we're scopifying | |
if (state.ignoreLabeless) return; | |
// | |
if (state.inSwitchCase) return; | |
// break statements mean something different in this context | |
if (t.isBreakStatement(node) && t.isSwitchCase(parent)) return; | |
} | |
state.hasBreakContinue = true; | |
state.map[loopText] = node; | |
replace = t.literal(loopText); | |
} | |
if (this.isReturnStatement()) { | |
state.hasReturn = true; | |
replace = t.objectExpression([t.property("init", t.identifier("v"), node.argument || t.identifier("undefined"))]); | |
} | |
if (replace) { | |
replace = t.returnStatement(replace); | |
this.skip(); | |
return t.inherits(replace, node); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var BlockScoping = (function () { | |
function BlockScoping(loopPath, blockPath, parent, scope, file) { | |
_classCallCheck(this, BlockScoping); | |
this.parent = parent; | |
this.scope = scope; | |
this.file = file; | |
this.blockPath = blockPath; | |
this.block = blockPath.node; | |
this.outsideLetReferences = _helpersObject2["default"](); | |
this.hasLetReferences = false; | |
this.letReferences = this.block._letReferences = _helpersObject2["default"](); | |
this.body = []; | |
if (loopPath) { | |
this.loopParent = loopPath.parent; | |
this.loopLabel = t.isLabeledStatement(this.loopParent) && this.loopParent.label; | |
this.loopPath = loopPath; | |
this.loop = loopPath.node; | |
} | |
} | |
/** | |
* Start the ball rolling. | |
*/ | |
BlockScoping.prototype.run = function run() { | |
var block = this.block; | |
if (block._letDone) return; | |
block._letDone = true; | |
var needsClosure = this.getLetReferences(); | |
// this is a block within a `Function/Program` so we can safely leave it be | |
if (t.isFunction(this.parent) || t.isProgram(this.block)) return; | |
// we can skip everything | |
if (!this.hasLetReferences) return; | |
if (needsClosure) { | |
this.wrapClosure(); | |
} else { | |
this.remap(); | |
} | |
if (this.loopLabel && !t.isLabeledStatement(this.loopParent)) { | |
return t.labeledStatement(this.loopLabel, this.loop); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
BlockScoping.prototype.remap = function remap() { | |
var hasRemaps = false; | |
var letRefs = this.letReferences; | |
var scope = this.scope; | |
// alright, so since we aren't wrapping this block in a closure | |
// we have to check if any of our let variables collide with | |
// those in upper scopes and then if they do, generate a uid | |
// for them and replace all references with it | |
var remaps = _helpersObject2["default"](); | |
for (var key in letRefs) { | |
// just an Identifier node we collected in `getLetReferences` | |
// this is the defining identifier of a declaration | |
var ref = letRefs[key]; | |
// todo: could skip this if the colliding binding is in another function | |
if (scope.parentHasBinding(key) || scope.hasGlobal(key)) { | |
var uid = scope.generateUidIdentifier(ref.name).name; | |
ref.name = uid; | |
hasRemaps = true; | |
remaps[key] = remaps[uid] = { | |
binding: ref, | |
uid: uid | |
}; | |
} | |
} | |
if (!hasRemaps) return; | |
// | |
var loop = this.loop; | |
if (loop) { | |
traverseReplace(loop.right, loop, scope, remaps); | |
traverseReplace(loop.test, loop, scope, remaps); | |
traverseReplace(loop.update, loop, scope, remaps); | |
} | |
this.blockPath.traverse(replaceVisitor, remaps); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
BlockScoping.prototype.wrapClosure = function wrapClosure() { | |
var block = this.block; | |
var outsideRefs = this.outsideLetReferences; | |
// remap loop heads with colliding variables | |
if (this.loop) { | |
for (var name in outsideRefs) { | |
var id = outsideRefs[name]; | |
if (this.scope.hasGlobal(id.name) || this.scope.parentHasBinding(id.name)) { | |
delete outsideRefs[id.name]; | |
delete this.letReferences[id.name]; | |
this.scope.rename(id.name); | |
this.letReferences[id.name] = id; | |
outsideRefs[id.name] = id; | |
} | |
} | |
} | |
// if we're inside of a for loop then we search to see if there are any | |
// `break`s, `continue`s, `return`s etc | |
this.has = this.checkLoop(); | |
// hoist var references to retain scope | |
this.hoistVarDeclarations(); | |
// turn outsideLetReferences into an array | |
var params = _lodashObjectValues2["default"](outsideRefs); | |
var args = _lodashObjectValues2["default"](outsideRefs); | |
// build the closure that we're going to wrap the block with | |
var fn = t.functionExpression(null, params, t.blockStatement(block.body)); | |
fn.shadow = true; | |
// continuation | |
this.addContinuations(fn); | |
// replace the current block body with the one we're going to build | |
block.body = this.body; | |
var ref = fn; | |
if (this.loop) { | |
ref = this.scope.generateUidIdentifier("loop"); | |
this.loopPath.insertBefore(t.variableDeclaration("var", [t.variableDeclarator(ref, fn)])); | |
} | |
// build a call and a unique id that we can assign the return value to | |
var call = t.callExpression(ref, args); | |
var ret = this.scope.generateUidIdentifier("ret"); | |
// handle generators | |
var hasYield = _traversal2["default"].hasType(fn.body, this.scope, "YieldExpression", t.FUNCTION_TYPES); | |
if (hasYield) { | |
fn.generator = true; | |
call = t.yieldExpression(call, true); | |
} | |
// handlers async functions | |
var hasAsync = _traversal2["default"].hasType(fn.body, this.scope, "AwaitExpression", t.FUNCTION_TYPES); | |
if (hasAsync) { | |
fn.async = true; | |
call = t.awaitExpression(call); | |
} | |
this.buildClosure(ret, call); | |
}; | |
/** | |
* Push the closure to the body. | |
*/ | |
BlockScoping.prototype.buildClosure = function buildClosure(ret, call) { | |
var has = this.has; | |
if (has.hasReturn || has.hasBreakContinue) { | |
this.buildHas(ret, call); | |
} else { | |
this.body.push(t.expressionStatement(call)); | |
} | |
}; | |
/** | |
* If any of the outer let variables are reassigned then we need to rename them in | |
* the closure so we can get direct access to the outer variable to continue the | |
* iteration with bindings based on each iteration. | |
* | |
* Reference: https://github.com/babel/babel/issues/1078 | |
*/ | |
BlockScoping.prototype.addContinuations = function addContinuations(fn) { | |
var state = { | |
reassignments: {}, | |
outsideReferences: this.outsideLetReferences | |
}; | |
this.scope.traverse(fn, continuationVisitor, state); | |
for (var i = 0; i < fn.params.length; i++) { | |
var param = fn.params[i]; | |
if (!state.reassignments[param.name]) continue; | |
var newParam = this.scope.generateUidIdentifier(param.name); | |
fn.params[i] = newParam; | |
this.scope.rename(param.name, newParam.name, fn); | |
// assign outer reference as it's been modified internally and needs to be retained | |
fn.body.body.push(t.expressionStatement(t.assignmentExpression("=", param, newParam))); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
BlockScoping.prototype.getLetReferences = function getLetReferences() { | |
var block = this.block; | |
var declarators = block._letDeclarators || []; | |
// | |
for (var i = 0; i < declarators.length; i++) { | |
var declar = declarators[i]; | |
_lodashObjectExtend2["default"](this.outsideLetReferences, t.getBindingIdentifiers(declar)); | |
} | |
// | |
if (block.body) { | |
for (var i = 0; i < block.body.length; i++) { | |
var declar = block.body[i]; | |
if (isLet(declar, block)) { | |
declarators = declarators.concat(declar.declarations); | |
} | |
} | |
} | |
// | |
for (var i = 0; i < declarators.length; i++) { | |
var declar = declarators[i]; | |
var keys = t.getBindingIdentifiers(declar); | |
_lodashObjectExtend2["default"](this.letReferences, keys); | |
this.hasLetReferences = true; | |
} | |
// no let references so we can just quit | |
if (!this.hasLetReferences) return; | |
// set let references to plain var references | |
standardizeLets(declarators); | |
var state = { | |
letReferences: this.letReferences, | |
closurify: false | |
}; | |
// traverse through this block, stopping on functions and checking if they | |
// contain any local let references | |
this.blockPath.traverse(letReferenceBlockVisitor, state); | |
return state.closurify; | |
}; | |
/** | |
* If we're inside of a loop then traverse it and check if it has one of | |
* the following node types `ReturnStatement`, `BreakStatement`, | |
* `ContinueStatement` and replace it with a return value that we can track | |
* later on. | |
* | |
* @returns {Object} | |
*/ | |
BlockScoping.prototype.checkLoop = function checkLoop() { | |
var state = { | |
hasBreakContinue: false, | |
ignoreLabeless: false, | |
inSwitchCase: false, | |
innerLabels: [], | |
hasReturn: false, | |
isLoop: !!this.loop, | |
map: {} | |
}; | |
this.blockPath.traverse(loopLabelVisitor, state); | |
this.blockPath.traverse(loopVisitor, state); | |
return state; | |
}; | |
/** | |
* Hoist all var declarations in this block to before it so they retain scope | |
* once we wrap everything in a closure. | |
*/ | |
BlockScoping.prototype.hoistVarDeclarations = function hoistVarDeclarations() { | |
this.blockPath.traverse(hoistVarDeclarationsVisitor, this); | |
}; | |
/** | |
* Turn a `VariableDeclaration` into an array of `AssignmentExpressions` with | |
* their declarations hoisted to before the closure wrapper. | |
*/ | |
BlockScoping.prototype.pushDeclar = function pushDeclar(node) { | |
var declars = []; | |
var names = t.getBindingIdentifiers(node); | |
for (var name in names) { | |
declars.push(t.variableDeclarator(names[name])); | |
} | |
this.body.push(t.variableDeclaration(node.kind, declars)); | |
var replace = []; | |
for (var i = 0; i < node.declarations.length; i++) { | |
var declar = node.declarations[i]; | |
if (!declar.init) continue; | |
var expr = t.assignmentExpression("=", declar.id, declar.init); | |
replace.push(t.inherits(expr, declar)); | |
} | |
return replace; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
BlockScoping.prototype.buildHas = function buildHas(ret, call) { | |
var body = this.body; | |
body.push(t.variableDeclaration("var", [t.variableDeclarator(ret, call)])); | |
var retCheck; | |
var has = this.has; | |
var cases = []; | |
if (has.hasReturn) { | |
// typeof ret === "object" | |
retCheck = util.template("let-scoping-return", { | |
RETURN: ret | |
}); | |
} | |
if (has.hasBreakContinue) { | |
for (var key in has.map) { | |
cases.push(t.switchCase(t.literal(key), [has.map[key]])); | |
} | |
if (has.hasReturn) { | |
cases.push(t.switchCase(null, [retCheck])); | |
} | |
if (cases.length === 1) { | |
var single = cases[0]; | |
body.push(this.file.attachAuxiliaryComment(t.ifStatement(t.binaryExpression("===", ret, single.test), single.consequent[0]))); | |
} else { | |
// https://github.com/babel/babel/issues/998 | |
for (var i = 0; i < cases.length; i++) { | |
var caseConsequent = cases[i].consequent[0]; | |
if (t.isBreakStatement(caseConsequent) && !caseConsequent.label) { | |
caseConsequent.label = this.loopLabel = this.loopLabel || this.file.scope.generateUidIdentifier("loop"); | |
} | |
} | |
body.push(this.file.attachAuxiliaryComment(t.switchStatement(ret, cases))); | |
} | |
} else { | |
if (has.hasReturn) { | |
body.push(this.file.attachAuxiliaryComment(retCheck)); | |
} | |
} | |
}; | |
return BlockScoping; | |
})(); | |
},{"148":148,"179":179,"182":182,"41":41,"511":511,"517":517}],91:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _loose = _dereq_(92); | |
var _loose2 = _interopRequireDefault(_loose); | |
var _vanilla = _dereq_(93); | |
var _vanilla2 = _interopRequireDefault(_vanilla); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var _helpersNameMethod = _dereq_(61); | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ClassDeclaration: function ClassDeclaration(node) { | |
return t.variableDeclaration("let", [t.variableDeclarator(node.id, t.toExpression(node))]); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
ClassExpression: function ClassExpression(node, parent, scope, file) { | |
var inferred = _helpersNameMethod.bare(node, parent, scope); | |
if (inferred) return inferred; | |
if (file.isLoose("es6.classes")) { | |
return new _loose2["default"](this, file).run(); | |
} else { | |
return new _vanilla2["default"](this, file).run(); | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179,"61":61,"92":92,"93":93}],92:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
// istanbul ignore next | |
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | |
var _vanilla = _dereq_(93); | |
var _vanilla2 = _interopRequireDefault(_vanilla); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var LooseClassTransformer = (function (_VanillaTransformer) { | |
_inherits(LooseClassTransformer, _VanillaTransformer); | |
function LooseClassTransformer() { | |
_classCallCheck(this, LooseClassTransformer); | |
_VanillaTransformer.apply(this, arguments); | |
this.isLoose = true; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
LooseClassTransformer.prototype._processMethod = function _processMethod(node) { | |
if (!node.decorators) { | |
// use assignments instead of define properties for loose classes | |
var classRef = this.classRef; | |
if (!node["static"]) classRef = t.memberExpression(classRef, t.identifier("prototype")); | |
var methodName = t.memberExpression(classRef, node.key, node.computed || t.isLiteral(node.key)); | |
var expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value)); | |
t.inheritsComments(expr, node); | |
this.body.push(expr); | |
return true; | |
} | |
}; | |
return LooseClassTransformer; | |
})(_vanilla2["default"]); | |
exports["default"] = LooseClassTransformer; | |
module.exports = exports["default"]; | |
},{"179":179,"93":93}],93:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _helpersMemoiseDecorators = _dereq_(60); | |
var _helpersMemoiseDecorators2 = _interopRequireDefault(_helpersMemoiseDecorators); | |
var _helpersReplaceSupers = _dereq_(65); | |
var _helpersReplaceSupers2 = _interopRequireDefault(_helpersReplaceSupers); | |
var _helpersNameMethod = _dereq_(61); | |
var nameMethod = _interopRequireWildcard(_helpersNameMethod); | |
var _helpersDefineMap = _dereq_(57); | |
var defineMap = _interopRequireWildcard(_helpersDefineMap); | |
var _messages = _dereq_(43); | |
var messages = _interopRequireWildcard(_messages); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var PROPERTY_COLLISION_METHOD_NAME = "__initializeProperties"; | |
/** | |
* [Please add a description.] | |
*/ | |
var collectPropertyReferencesVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Identifier: { | |
enter: function enter(node, parent, scope, state) { | |
if (this.parentPath.isClassProperty({ key: node })) { | |
return; | |
} | |
if (this.isReferenced() && scope.getBinding(node.name) === state.scope.getBinding(node.name)) { | |
state.references[node.name] = true; | |
} | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var verifyConstructorVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
MethodDefinition: function MethodDefinition() { | |
this.skip(); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
Property: function Property(node) { | |
if (node.method) this.skip(); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
CallExpression: { | |
exit: function exit(node, parent, scope, state) { | |
if (this.get("callee").isSuper()) { | |
state.hasBareSuper = true; | |
state.bareSuper = this; | |
if (!state.isDerived) { | |
throw this.errorWithNode("super call is only allowed in derived constructor"); | |
} | |
} | |
} | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
"FunctionDeclaration|FunctionExpression": function FunctionDeclarationFunctionExpression() { | |
this.skip(); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
ThisExpression: function ThisExpression(node, parent, scope, state) { | |
if (state.isDerived && !state.hasBareSuper) { | |
if (this.inShadow()) { | |
// https://github.com/babel/babel/issues/1920 | |
var thisAlias = state.constructorPath.getData("this"); | |
if (!thisAlias) { | |
thisAlias = state.constructorPath.setData("this", state.constructorPath.scope.generateUidIdentifier("this")); | |
} | |
return thisAlias; | |
} else { | |
throw this.errorWithNode("'this' is not allowed before super()"); | |
} | |
} | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
Super: function Super(node, parent, scope, state) { | |
if (state.isDerived && !state.hasBareSuper && !this.parentPath.isCallExpression({ callee: node })) { | |
throw this.errorWithNode("'super.*' is not allowed before super()"); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var ClassTransformer = (function () { | |
function ClassTransformer(path, file) { | |
_classCallCheck(this, ClassTransformer); | |
this.parent = path.parent; | |
this.scope = path.scope; | |
this.node = path.node; | |
this.path = path; | |
this.file = file; | |
this.clearDescriptors(); | |
this.instancePropBody = []; | |
this.instancePropRefs = {}; | |
this.staticPropBody = []; | |
this.body = []; | |
this.pushedConstructor = false; | |
this.pushedInherits = false; | |
this.hasDecorators = false; | |
this.isLoose = false; | |
// class id | |
this.classId = this.node.id; | |
// this is the name of the binding that will **always** reference the class we've constructed | |
this.classRef = this.node.id || this.scope.generateUidIdentifier("class"); | |
// this is a direct reference to the class we're building, class decorators can shadow the classRef | |
this.directRef = null; | |
this.superName = this.node.superClass || t.identifier("Function"); | |
this.isDerived = !!this.node.superClass; | |
} | |
/** | |
* [Please add a description.] | |
* @returns {Array} | |
*/ | |
ClassTransformer.prototype.run = function run() { | |
var superName = this.superName; | |
var file = this.file; | |
// | |
var body = this.body; | |
// | |
var constructorBody = this.constructorBody = t.blockStatement([]); | |
this.constructor = this.buildConstructor(); | |
// | |
var closureParams = []; | |
var closureArgs = []; | |
// | |
if (this.isDerived) { | |
closureArgs.push(superName); | |
superName = this.scope.generateUidIdentifierBasedOnNode(superName); | |
closureParams.push(superName); | |
this.superName = superName; | |
} | |
// | |
var decorators = this.node.decorators; | |
if (decorators) { | |
// this is so super calls and the decorators have access to the raw function | |
this.directRef = this.scope.generateUidIdentifier(this.classRef); | |
} else { | |
this.directRef = this.classRef; | |
} | |
// | |
this.buildBody(); | |
// make sure this class isn't directly called | |
constructorBody.body.unshift(t.expressionStatement(t.callExpression(file.addHelper("class-call-check"), [t.thisExpression(), this.directRef]))); | |
// | |
this.pushDecorators(); | |
body = body.concat(this.staticPropBody); | |
if (this.classId) { | |
// named class with only a constructor | |
if (body.length === 1) return t.toExpression(body[0]); | |
} | |
// | |
body.push(t.returnStatement(this.classRef)); | |
var container = t.functionExpression(null, closureParams, t.blockStatement(body)); | |
container.shadow = true; | |
return t.callExpression(container, closureArgs); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ClassTransformer.prototype.buildConstructor = function buildConstructor() { | |
var func = t.functionDeclaration(this.classRef, [], this.constructorBody); | |
t.inherits(func, this.node); | |
return func; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ClassTransformer.prototype.pushToMap = function pushToMap(node, enumerable) { | |
var kind = arguments.length <= 2 || arguments[2] === undefined ? "value" : arguments[2]; | |
var mutatorMap; | |
if (node["static"]) { | |
this.hasStaticDescriptors = true; | |
mutatorMap = this.staticMutatorMap; | |
} else { | |
this.hasInstanceDescriptors = true; | |
mutatorMap = this.instanceMutatorMap; | |
} | |
var map = defineMap.push(mutatorMap, node, kind, this.file); | |
if (enumerable) { | |
map.enumerable = t.literal(true); | |
} | |
if (map.decorators) { | |
this.hasDecorators = true; | |
} | |
}; | |
/** | |
* [Please add a description.] | |
* https://www.youtube.com/watch?v=fWNaR-rxAic | |
*/ | |
ClassTransformer.prototype.constructorMeMaybe = function constructorMeMaybe() { | |
var hasConstructor = false; | |
var paths = this.path.get("body.body"); | |
var _arr = paths; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var path = _arr[_i]; | |
hasConstructor = path.equals("kind", "constructor"); | |
if (hasConstructor) break; | |
} | |
if (hasConstructor) return; | |
var constructor; | |
if (this.isDerived) { | |
constructor = util.template("class-derived-default-constructor"); | |
} else { | |
constructor = t.functionExpression(null, [], t.blockStatement([])); | |
} | |
this.path.get("body").unshiftContainer("body", t.methodDefinition(t.identifier("constructor"), constructor, "constructor")); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ClassTransformer.prototype.buildBody = function buildBody() { | |
this.constructorMeMaybe(); | |
this.pushBody(); | |
this.placePropertyInitializers(); | |
if (this.userConstructor) { | |
var constructorBody = this.constructorBody; | |
constructorBody.body = constructorBody.body.concat(this.userConstructor.body.body); | |
t.inherits(this.constructor, this.userConstructor); | |
t.inherits(constructorBody, this.userConstructor.body); | |
} | |
this.pushDescriptors(); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ClassTransformer.prototype.pushBody = function pushBody() { | |
var classBodyPaths = this.path.get("body.body"); | |
var _arr2 = classBodyPaths; | |
for (var _i2 = 0; _i2 < _arr2.length; _i2++) { | |
var path = _arr2[_i2]; | |
var node = path.node; | |
if (node.decorators) { | |
_helpersMemoiseDecorators2["default"](node.decorators, this.scope); | |
} | |
if (t.isMethodDefinition(node)) { | |
var isConstructor = node.kind === "constructor"; | |
if (isConstructor) this.verifyConstructor(path); | |
var replaceSupers = new _helpersReplaceSupers2["default"]({ | |
methodPath: path, | |
methodNode: node, | |
objectRef: this.directRef, | |
superRef: this.superName, | |
isStatic: node["static"], | |
isLoose: this.isLoose, | |
scope: this.scope, | |
file: this.file | |
}, true); | |
replaceSupers.replace(); | |
if (isConstructor) { | |
this.pushConstructor(node, path); | |
} else { | |
this.pushMethod(node, path); | |
} | |
} else if (t.isClassProperty(node)) { | |
this.pushProperty(node, path); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ClassTransformer.prototype.clearDescriptors = function clearDescriptors() { | |
this.hasInstanceDescriptors = false; | |
this.hasStaticDescriptors = false; | |
this.instanceMutatorMap = {}; | |
this.staticMutatorMap = {}; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ClassTransformer.prototype.pushDescriptors = function pushDescriptors() { | |
this.pushInherits(); | |
var body = this.body; | |
var instanceProps; | |
var staticProps; | |
var classHelper = "create-class"; | |
if (this.hasDecorators) classHelper = "create-decorated-class"; | |
if (this.hasInstanceDescriptors) { | |
instanceProps = defineMap.toClassObject(this.instanceMutatorMap); | |
} | |
if (this.hasStaticDescriptors) { | |
staticProps = defineMap.toClassObject(this.staticMutatorMap); | |
} | |
if (instanceProps || staticProps) { | |
if (instanceProps) instanceProps = defineMap.toComputedObjectFromClass(instanceProps); | |
if (staticProps) staticProps = defineMap.toComputedObjectFromClass(staticProps); | |
var nullNode = t.literal(null); | |
// (Constructor, instanceDescriptors, staticDescriptors, instanceInitializers, staticInitializers) | |
var args = [this.classRef, nullNode, nullNode, nullNode, nullNode]; | |
if (instanceProps) args[1] = instanceProps; | |
if (staticProps) args[2] = staticProps; | |
if (this.instanceInitializersId) { | |
args[3] = this.instanceInitializersId; | |
body.unshift(this.buildObjectAssignment(this.instanceInitializersId)); | |
} | |
if (this.staticInitializersId) { | |
args[4] = this.staticInitializersId; | |
body.unshift(this.buildObjectAssignment(this.staticInitializersId)); | |
} | |
var lastNonNullIndex = 0; | |
for (var i = 0; i < args.length; i++) { | |
if (args[i] !== nullNode) lastNonNullIndex = i; | |
} | |
args = args.slice(0, lastNonNullIndex + 1); | |
body.push(t.expressionStatement(t.callExpression(this.file.addHelper(classHelper), args))); | |
} | |
this.clearDescriptors(); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ClassTransformer.prototype.buildObjectAssignment = function buildObjectAssignment(id) { | |
return t.variableDeclaration("var", [t.variableDeclarator(id, t.objectExpression([]))]); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ClassTransformer.prototype.placePropertyInitializers = function placePropertyInitializers() { | |
var body = this.instancePropBody; | |
if (!body.length) return; | |
if (this.hasPropertyCollision()) { | |
var call = t.expressionStatement(t.callExpression(t.memberExpression(t.thisExpression(), t.identifier(PROPERTY_COLLISION_METHOD_NAME)), [])); | |
this.pushMethod(t.methodDefinition(t.identifier(PROPERTY_COLLISION_METHOD_NAME), t.functionExpression(null, [], t.blockStatement(body))), null, true); | |
if (this.isDerived) { | |
this.bareSuper.insertAfter(call); | |
} else { | |
this.constructorBody.body.unshift(call); | |
} | |
} else { | |
if (this.isDerived) { | |
this.bareSuper.insertAfter(body); | |
} else { | |
this.constructorBody.body = body.concat(this.constructorBody.body); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ClassTransformer.prototype.hasPropertyCollision = function hasPropertyCollision() { | |
if (this.userConstructorPath) { | |
for (var name in this.instancePropRefs) { | |
if (this.userConstructorPath.scope.hasOwnBinding(name)) { | |
return true; | |
} | |
} | |
} | |
return false; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ClassTransformer.prototype.verifyConstructor = function verifyConstructor(path) { | |
var state = { | |
constructorPath: path.get("value"), | |
hasBareSuper: false, | |
bareSuper: null, | |
isDerived: this.isDerived, | |
file: this.file | |
}; | |
state.constructorPath.traverse(verifyConstructorVisitor, state); | |
var thisAlias = state.constructorPath.getData("this"); | |
if (thisAlias && state.bareSuper) { | |
state.bareSuper.insertAfter(t.variableDeclaration("var", [t.variableDeclarator(thisAlias, t.thisExpression())])); | |
} | |
this.bareSuper = state.bareSuper; | |
if (!state.hasBareSuper && this.isDerived) { | |
throw path.errorWithNode("Derived constructor must call super()"); | |
} | |
}; | |
/** | |
* Push a method to its respective mutatorMap. | |
*/ | |
ClassTransformer.prototype.pushMethod = function pushMethod(node, path, allowedIllegal) { | |
if (!allowedIllegal && t.isLiteral(t.toComputedKey(node), { value: PROPERTY_COLLISION_METHOD_NAME })) { | |
throw this.file.errorWithNode(node, messages.get("illegalMethodName", PROPERTY_COLLISION_METHOD_NAME)); | |
} | |
if (node.kind === "method") { | |
nameMethod.property(node, this.file, path ? path.get("value").scope : this.scope); | |
if (this._processMethod(node)) return; | |
} | |
this.pushToMap(node); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ClassTransformer.prototype._processMethod = function _processMethod() { | |
return false; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ClassTransformer.prototype.pushProperty = function pushProperty(node, path) { | |
path.traverse(collectPropertyReferencesVisitor, { | |
references: this.instancePropRefs, | |
scope: this.scope | |
}); | |
if (node.decorators) { | |
var body = []; | |
if (node.value) { | |
body.push(t.returnStatement(node.value)); | |
node.value = t.functionExpression(null, [], t.blockStatement(body)); | |
} else { | |
node.value = t.literal(null); | |
} | |
this.pushToMap(node, true, "initializer"); | |
var initializers; | |
var target; | |
if (node["static"]) { | |
initializers = this.staticInitializersId = this.staticInitializersId || this.scope.generateUidIdentifier("staticInitializers"); | |
body = this.staticPropBody; | |
target = this.classRef; | |
} else { | |
initializers = this.instanceInitializersId = this.instanceInitializersId || this.scope.generateUidIdentifier("instanceInitializers"); | |
body = this.instancePropBody; | |
target = t.thisExpression(); | |
} | |
body.push(t.expressionStatement(t.callExpression(this.file.addHelper("define-decorated-property-descriptor"), [target, t.literal(node.key.name), initializers]))); | |
} else { | |
if (!node.value && !node.decorators) return; | |
if (node["static"]) { | |
// can just be added to the static map | |
this.pushToMap(node, true); | |
} else if (node.value) { | |
// add this to the instancePropBody which will be added after the super call in a derived constructor | |
// or at the start of a constructor for a non-derived constructor | |
this.instancePropBody.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.thisExpression(), node.key), node.value))); | |
} | |
} | |
}; | |
/** | |
* Replace the constructor body of our class. | |
*/ | |
ClassTransformer.prototype.pushConstructor = function pushConstructor(method, path) { | |
// https://github.com/babel/babel/issues/1077 | |
var fnPath = path.get("value"); | |
if (fnPath.scope.hasOwnBinding(this.classRef.name)) { | |
fnPath.scope.rename(this.classRef.name); | |
} | |
var construct = this.constructor; | |
var fn = method.value; | |
this.userConstructorPath = fnPath; | |
this.userConstructor = fn; | |
this.hasConstructor = true; | |
t.inheritsComments(construct, method); | |
construct._ignoreUserWhitespace = true; | |
construct.params = fn.params; | |
t.inherits(construct.body, fn.body); | |
// push constructor to body | |
this._pushConstructor(); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
ClassTransformer.prototype._pushConstructor = function _pushConstructor() { | |
if (this.pushedConstructor) return; | |
this.pushedConstructor = true; | |
// we haven't pushed any descriptors yet | |
if (this.hasInstanceDescriptors || this.hasStaticDescriptors) { | |
this.pushDescriptors(); | |
} | |
this.body.push(this.constructor); | |
this.pushInherits(); | |
}; | |
/** | |
* Push inherits helper to body. | |
*/ | |
ClassTransformer.prototype.pushInherits = function pushInherits() { | |
if (!this.isDerived || this.pushedInherits) return; | |
// Unshift to ensure that the constructor inheritance is set up before | |
// any properties can be assigned to the prototype. | |
this.pushedInherits = true; | |
this.body.unshift(t.expressionStatement(t.callExpression(this.file.addHelper("inherits"), [this.classRef, this.superName]))); | |
}; | |
/** | |
* Push decorators to body. | |
*/ | |
ClassTransformer.prototype.pushDecorators = function pushDecorators() { | |
var decorators = this.node.decorators; | |
if (!decorators) return; | |
this.body.push(t.variableDeclaration("var", [t.variableDeclarator(this.directRef, this.classRef)])); | |
// reverse the decorators so we execute them in the right order | |
decorators = decorators.reverse(); | |
var _arr3 = decorators; | |
for (var _i3 = 0; _i3 < _arr3.length; _i3++) { | |
var decorator = _arr3[_i3]; | |
var decoratorNode = util.template("class-decorator", { | |
DECORATOR: decorator.expression, | |
CLASS_REF: this.classRef | |
}, true); | |
decoratorNode.expression._ignoreModulesRemap = true; | |
this.body.push(decoratorNode); | |
} | |
}; | |
return ClassTransformer; | |
})(); | |
exports["default"] = ClassTransformer; | |
module.exports = exports["default"]; | |
},{"179":179,"182":182,"43":43,"57":57,"60":60,"61":61,"65":65}],94:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _messages = _dereq_(43); | |
var messages = _interopRequireWildcard(_messages); | |
/** | |
* Turn constants into variables. | |
* Ensure there are no constant violations in any scope. | |
* | |
* @example | |
* | |
* **In** | |
* | |
* ```javascript | |
* const MULTIPLIER = 5; | |
* ``` | |
* | |
* **Out** | |
* | |
* ```javascript | |
* var MULTIPLIER = 5; | |
* ``` | |
*/ | |
var visitor = { | |
/** | |
* Look for any constants (or modules) in scope. | |
* If they have any `constantViolations` throw an error. | |
*/ | |
Scope: function Scope(node, parent, scope) { | |
for (var name in scope.bindings) { | |
var binding = scope.bindings[name]; | |
// not a constant | |
if (binding.kind !== "const" && binding.kind !== "module") continue; | |
var _arr = binding.constantViolations; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var violation = _arr[_i]; | |
throw violation.errorWithNode(messages.get("readOnly", name)); | |
} | |
} | |
}, | |
/** | |
* Look for constants. | |
* Turn them into `let` variables. | |
*/ | |
VariableDeclaration: function VariableDeclaration(node) { | |
if (node.kind === "const") node.kind = "let"; | |
} | |
}; | |
exports.visitor = visitor; | |
},{"43":43}],95:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _messages = _dereq_(43); | |
var messages = _interopRequireWildcard(_messages); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
group: "builtin-advanced" | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ForXStatement: function ForXStatement(node, parent, scope, file) { | |
var left = node.left; | |
if (t.isPattern(left)) { | |
// for ({ length: k } in { abc: 3 }); | |
var temp = scope.generateUidIdentifier("ref"); | |
node.left = t.variableDeclaration("var", [t.variableDeclarator(temp)]); | |
this.ensureBlock(); | |
node.body.body.unshift(t.variableDeclaration("var", [t.variableDeclarator(left, temp)])); | |
return; | |
} | |
if (!t.isVariableDeclaration(left)) return; | |
var pattern = left.declarations[0].id; | |
if (!t.isPattern(pattern)) return; | |
var key = scope.generateUidIdentifier("ref"); | |
node.left = t.variableDeclaration(left.kind, [t.variableDeclarator(key, null)]); | |
var nodes = []; | |
var destructuring = new DestructuringTransformer({ | |
kind: left.kind, | |
file: file, | |
scope: scope, | |
nodes: nodes | |
}); | |
destructuring.init(pattern, key); | |
this.ensureBlock(); | |
var block = node.body; | |
block.body = nodes.concat(block.body); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
Function: function Function(node, parent, scope, file) { | |
var hasDestructuring = false; | |
var _arr = node.params; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var pattern = _arr[_i]; | |
if (t.isPattern(pattern)) { | |
hasDestructuring = true; | |
break; | |
} | |
} | |
if (!hasDestructuring) return; | |
var nodes = []; | |
for (var i = 0; i < node.params.length; i++) { | |
var pattern = node.params[i]; | |
if (!t.isPattern(pattern)) continue; | |
var ref = scope.generateUidIdentifier("ref"); | |
if (t.isAssignmentPattern(pattern)) { | |
var _pattern = pattern; | |
pattern = pattern.left; | |
_pattern.left = ref; | |
} else { | |
node.params[i] = ref; | |
} | |
t.inherits(ref, pattern); | |
var destructuring = new DestructuringTransformer({ | |
blockHoist: node.params.length - i, | |
nodes: nodes, | |
scope: scope, | |
file: file, | |
kind: "let" | |
}); | |
destructuring.init(pattern, ref); | |
} | |
this.ensureBlock(); | |
var block = node.body; | |
block.body = nodes.concat(block.body); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
CatchClause: function CatchClause(node, parent, scope, file) { | |
var pattern = node.param; | |
if (!t.isPattern(pattern)) return; | |
var ref = scope.generateUidIdentifier("ref"); | |
node.param = ref; | |
var nodes = []; | |
var destructuring = new DestructuringTransformer({ | |
kind: "let", | |
file: file, | |
scope: scope, | |
nodes: nodes | |
}); | |
destructuring.init(pattern, ref); | |
node.body.body = nodes.concat(node.body.body); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
AssignmentExpression: function AssignmentExpression(node, parent, scope, file) { | |
if (!t.isPattern(node.left)) return; | |
var nodes = []; | |
var destructuring = new DestructuringTransformer({ | |
operator: node.operator, | |
file: file, | |
scope: scope, | |
nodes: nodes | |
}); | |
var ref; | |
if (this.isCompletionRecord() || !this.parentPath.isExpressionStatement()) { | |
ref = scope.generateUidIdentifierBasedOnNode(node.right, "ref"); | |
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(ref, node.right)])); | |
if (t.isArrayExpression(node.right)) { | |
destructuring.arrays[ref.name] = true; | |
} | |
} | |
destructuring.init(node.left, ref || node.right); | |
if (ref) { | |
nodes.push(t.expressionStatement(ref)); | |
} | |
return nodes; | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
VariableDeclaration: function VariableDeclaration(node, parent, scope, file) { | |
if (t.isForXStatement(parent)) return; | |
if (!variableDeclarationHasPattern(node)) return; | |
var nodes = []; | |
var declar; | |
for (var i = 0; i < node.declarations.length; i++) { | |
declar = node.declarations[i]; | |
var patternId = declar.init; | |
var pattern = declar.id; | |
var destructuring = new DestructuringTransformer({ | |
nodes: nodes, | |
scope: scope, | |
kind: node.kind, | |
file: file | |
}); | |
if (t.isPattern(pattern)) { | |
destructuring.init(pattern, patternId); | |
if (+i !== node.declarations.length - 1) { | |
// we aren't the last declarator so let's just make the | |
// last transformed node inherit from us | |
t.inherits(nodes[nodes.length - 1], declar); | |
} | |
} else { | |
nodes.push(t.inherits(destructuring.buildVariableAssignment(declar.id, declar.init), declar)); | |
} | |
} | |
if (!t.isProgram(parent) && !t.isBlockStatement(parent)) { | |
// https://github.com/babel/babel/issues/113 | |
// for (let [x] = [0]; false;) {} | |
declar = null; | |
for (i = 0; i < nodes.length; i++) { | |
node = nodes[i]; | |
declar = declar || t.variableDeclaration(node.kind, []); | |
if (!t.isVariableDeclaration(node) && declar.kind !== node.kind) { | |
throw file.errorWithNode(node, messages.get("invalidParentForThisNode")); | |
} | |
declar.declarations = declar.declarations.concat(node.declarations); | |
} | |
return declar; | |
} | |
return nodes; | |
} | |
}; | |
exports.visitor = visitor; | |
/** | |
* Test if a VariableDeclaration's declarations contains any Patterns. | |
*/ | |
function variableDeclarationHasPattern(node) { | |
for (var i = 0; i < node.declarations.length; i++) { | |
if (t.isPattern(node.declarations[i].id)) { | |
return true; | |
} | |
} | |
return false; | |
} | |
/** | |
* Test if an ArrayPattern's elements contain any RestElements. | |
*/ | |
function hasRest(pattern) { | |
for (var i = 0; i < pattern.elements.length; i++) { | |
if (t.isRestElement(pattern.elements[i])) { | |
return true; | |
} | |
} | |
return false; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
var arrayUnpackVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ReferencedIdentifier: function ReferencedIdentifier(node, parent, scope, state) { | |
if (state.bindings[node.name]) { | |
state.deopt = true; | |
this.stop(); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var DestructuringTransformer = (function () { | |
function DestructuringTransformer(opts) { | |
_classCallCheck(this, DestructuringTransformer); | |
this.blockHoist = opts.blockHoist; | |
this.operator = opts.operator; | |
this.arrays = {}; | |
this.nodes = opts.nodes || []; | |
this.scope = opts.scope; | |
this.file = opts.file; | |
this.kind = opts.kind; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
DestructuringTransformer.prototype.buildVariableAssignment = function buildVariableAssignment(id, init) { | |
var op = this.operator; | |
if (t.isMemberExpression(id)) op = "="; | |
var node; | |
if (op) { | |
node = t.expressionStatement(t.assignmentExpression(op, id, init)); | |
} else { | |
node = t.variableDeclaration(this.kind, [t.variableDeclarator(id, init)]); | |
} | |
node._blockHoist = this.blockHoist; | |
return node; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DestructuringTransformer.prototype.buildVariableDeclaration = function buildVariableDeclaration(id, init) { | |
var declar = t.variableDeclaration("var", [t.variableDeclarator(id, init)]); | |
declar._blockHoist = this.blockHoist; | |
return declar; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DestructuringTransformer.prototype.push = function push(id, init) { | |
if (t.isObjectPattern(id)) { | |
this.pushObjectPattern(id, init); | |
} else if (t.isArrayPattern(id)) { | |
this.pushArrayPattern(id, init); | |
} else if (t.isAssignmentPattern(id)) { | |
this.pushAssignmentPattern(id, init); | |
} else { | |
this.nodes.push(this.buildVariableAssignment(id, init)); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DestructuringTransformer.prototype.toArray = function toArray(node, count) { | |
if (this.file.isLoose("es6.destructuring") || t.isIdentifier(node) && this.arrays[node.name]) { | |
return node; | |
} else { | |
return this.scope.toArray(node, count); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DestructuringTransformer.prototype.pushAssignmentPattern = function pushAssignmentPattern(pattern, valueRef) { | |
// we need to assign the current value of the assignment to avoid evaluating | |
// it more than once | |
var tempValueRef = this.scope.generateUidIdentifierBasedOnNode(valueRef); | |
var declar = t.variableDeclaration("var", [t.variableDeclarator(tempValueRef, valueRef)]); | |
declar._blockHoist = this.blockHoist; | |
this.nodes.push(declar); | |
// | |
var tempConditional = t.conditionalExpression(t.binaryExpression("===", tempValueRef, t.identifier("undefined")), pattern.right, tempValueRef); | |
var left = pattern.left; | |
if (t.isPattern(left)) { | |
var tempValueDefault = t.expressionStatement(t.assignmentExpression("=", tempValueRef, tempConditional)); | |
tempValueDefault._blockHoist = this.blockHoist; | |
this.nodes.push(tempValueDefault); | |
this.push(left, tempValueRef); | |
} else { | |
this.nodes.push(this.buildVariableAssignment(left, tempConditional)); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DestructuringTransformer.prototype.pushObjectSpread = function pushObjectSpread(pattern, objRef, spreadProp, spreadPropIndex) { | |
// get all the keys that appear in this object before the current spread | |
var keys = []; | |
for (var i = 0; i < pattern.properties.length; i++) { | |
var prop = pattern.properties[i]; | |
// we've exceeded the index of the spread property to all properties to the | |
// right need to be ignored | |
if (i >= spreadPropIndex) break; | |
// ignore other spread properties | |
if (t.isSpreadProperty(prop)) continue; | |
var key = prop.key; | |
if (t.isIdentifier(key) && !prop.computed) key = t.literal(prop.key.name); | |
keys.push(key); | |
} | |
keys = t.arrayExpression(keys); | |
// | |
var value = t.callExpression(this.file.addHelper("object-without-properties"), [objRef, keys]); | |
this.nodes.push(this.buildVariableAssignment(spreadProp.argument, value)); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DestructuringTransformer.prototype.pushObjectProperty = function pushObjectProperty(prop, propRef) { | |
if (t.isLiteral(prop.key)) prop.computed = true; | |
var pattern = prop.value; | |
var objRef = t.memberExpression(propRef, prop.key, prop.computed); | |
if (t.isPattern(pattern)) { | |
this.push(pattern, objRef); | |
} else { | |
this.nodes.push(this.buildVariableAssignment(pattern, objRef)); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DestructuringTransformer.prototype.pushObjectPattern = function pushObjectPattern(pattern, objRef) { | |
// https://github.com/babel/babel/issues/681 | |
if (!pattern.properties.length) { | |
this.nodes.push(t.expressionStatement(t.callExpression(this.file.addHelper("object-destructuring-empty"), [objRef]))); | |
} | |
// if we have more than one properties in this pattern and the objectRef is a | |
// member expression then we need to assign it to a temporary variable so it's | |
// only evaluated once | |
if (pattern.properties.length > 1 && !this.scope.isStatic(objRef)) { | |
var temp = this.scope.generateUidIdentifierBasedOnNode(objRef); | |
this.nodes.push(this.buildVariableDeclaration(temp, objRef)); | |
objRef = temp; | |
} | |
// | |
for (var i = 0; i < pattern.properties.length; i++) { | |
var prop = pattern.properties[i]; | |
if (t.isSpreadProperty(prop)) { | |
this.pushObjectSpread(pattern, objRef, prop, i); | |
} else { | |
this.pushObjectProperty(prop, objRef); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DestructuringTransformer.prototype.canUnpackArrayPattern = function canUnpackArrayPattern(pattern, arr) { | |
// not an array so there's no way we can deal with this | |
if (!t.isArrayExpression(arr)) return false; | |
// pattern has less elements than the array and doesn't have a rest so some | |
// elements wont be evaluated | |
if (pattern.elements.length > arr.elements.length) return; | |
if (pattern.elements.length < arr.elements.length && !hasRest(pattern)) return false; | |
var _arr2 = pattern.elements; | |
for (var _i2 = 0; _i2 < _arr2.length; _i2++) { | |
var elem = _arr2[_i2]; | |
// deopt on holes | |
if (!elem) return false; | |
// deopt on member expressions as they may be included in the RHS | |
if (t.isMemberExpression(elem)) return false; | |
} | |
var _arr3 = arr.elements; | |
for (var _i3 = 0; _i3 < _arr3.length; _i3++) { | |
var elem = _arr3[_i3]; | |
// deopt on spread elements | |
if (t.isSpreadElement(elem)) return false; | |
} | |
// deopt on reference to left side identifiers | |
var bindings = t.getBindingIdentifiers(pattern); | |
var state = { deopt: false, bindings: bindings }; | |
this.scope.traverse(arr, arrayUnpackVisitor, state); | |
return !state.deopt; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DestructuringTransformer.prototype.pushUnpackedArrayPattern = function pushUnpackedArrayPattern(pattern, arr) { | |
for (var i = 0; i < pattern.elements.length; i++) { | |
var elem = pattern.elements[i]; | |
if (t.isRestElement(elem)) { | |
this.push(elem.argument, t.arrayExpression(arr.elements.slice(i))); | |
} else { | |
this.push(elem, arr.elements[i]); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DestructuringTransformer.prototype.pushArrayPattern = function pushArrayPattern(pattern, arrayRef) { | |
if (!pattern.elements) return; | |
// optimise basic array destructuring of an array expression | |
// | |
// we can't do this to a pattern of unequal size to it's right hand | |
// array expression as then there will be values that wont be evaluated | |
// | |
// eg: var [a, b] = [1, 2]; | |
if (this.canUnpackArrayPattern(pattern, arrayRef)) { | |
return this.pushUnpackedArrayPattern(pattern, arrayRef); | |
} | |
// if we have a rest then we need all the elements so don't tell | |
// `scope.toArray` to only get a certain amount | |
var count = !hasRest(pattern) && pattern.elements.length; | |
// so we need to ensure that the `arrayRef` is an array, `scope.toArray` will | |
// return a locally bound identifier if it's been inferred to be an array, | |
// otherwise it'll be a call to a helper that will ensure it's one | |
var toArray = this.toArray(arrayRef, count); | |
if (t.isIdentifier(toArray)) { | |
// we've been given an identifier so it must have been inferred to be an | |
// array | |
arrayRef = toArray; | |
} else { | |
arrayRef = this.scope.generateUidIdentifierBasedOnNode(arrayRef); | |
this.arrays[arrayRef.name] = true; | |
this.nodes.push(this.buildVariableDeclaration(arrayRef, toArray)); | |
} | |
// | |
for (var i = 0; i < pattern.elements.length; i++) { | |
var elem = pattern.elements[i]; | |
// hole | |
if (!elem) continue; | |
var elemRef; | |
if (t.isRestElement(elem)) { | |
elemRef = this.toArray(arrayRef); | |
if (i > 0) { | |
elemRef = t.callExpression(t.memberExpression(elemRef, t.identifier("slice")), [t.literal(i)]); | |
} | |
// set the element to the rest element argument since we've dealt with it | |
// being a rest already | |
elem = elem.argument; | |
} else { | |
elemRef = t.memberExpression(arrayRef, t.literal(i), true); | |
} | |
this.push(elem, elemRef); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
DestructuringTransformer.prototype.init = function init(pattern, ref) { | |
// trying to destructure a value that we can't evaluate more than once so we | |
// need to save it to a variable | |
if (!t.isArrayExpression(ref) && !t.isMemberExpression(ref)) { | |
var memo = this.scope.maybeGenerateMemoised(ref, true); | |
if (memo) { | |
this.nodes.push(this.buildVariableDeclaration(memo, ref)); | |
ref = memo; | |
} | |
} | |
// | |
this.push(pattern, ref); | |
return this.nodes; | |
}; | |
return DestructuringTransformer; | |
})(); | |
},{"179":179,"43":43}],96:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports._ForOfStatementArray = _ForOfStatementArray; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _messages = _dereq_(43); | |
var messages = _interopRequireWildcard(_messages); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ForOfStatement: function ForOfStatement(node, parent, scope, file) { | |
if (this.get("right").isArrayExpression()) { | |
return _ForOfStatementArray.call(this, node, scope, file); | |
} | |
var callback = spec; | |
if (file.isLoose("es6.forOf")) callback = loose; | |
var build = callback(node, parent, scope, file); | |
var declar = build.declar; | |
var loop = build.loop; | |
var block = loop.body; | |
// ensure that it's a block so we can take all its statements | |
this.ensureBlock(); | |
// add the value declaration to the new loop body | |
if (declar) { | |
block.body.push(declar); | |
} | |
// push the rest of the original loop body onto our new body | |
block.body = block.body.concat(node.body.body); | |
t.inherits(loop, node); | |
t.inherits(loop.body, node.body); | |
if (build.replaceParent) { | |
this.parentPath.replaceWithMultiple(build.node); | |
this.dangerouslyRemove(); | |
} else { | |
return build.node; | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
/** | |
* [Please add a description.] | |
*/ | |
function _ForOfStatementArray(node, scope) { | |
var nodes = []; | |
var right = node.right; | |
if (!t.isIdentifier(right) || !scope.hasBinding(right.name)) { | |
var uid = scope.generateUidIdentifier("arr"); | |
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(uid, right)])); | |
right = uid; | |
} | |
var iterationKey = scope.generateUidIdentifier("i"); | |
var loop = util.template("for-of-array", { | |
BODY: node.body, | |
KEY: iterationKey, | |
ARR: right | |
}); | |
t.inherits(loop, node); | |
t.ensureBlock(loop); | |
var iterationValue = t.memberExpression(right, iterationKey, true); | |
var left = node.left; | |
if (t.isVariableDeclaration(left)) { | |
left.declarations[0].init = iterationValue; | |
loop.body.body.unshift(left); | |
} else { | |
loop.body.body.unshift(t.expressionStatement(t.assignmentExpression("=", left, iterationValue))); | |
} | |
if (this.parentPath.isLabeledStatement()) { | |
loop = t.labeledStatement(this.parentPath.node.label, loop); | |
} | |
nodes.push(loop); | |
return nodes; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
var loose = function loose(node, parent, scope, file) { | |
var left = node.left; | |
var declar, id; | |
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) { | |
// for (i of test), for ({ i } of test) | |
id = left; | |
} else if (t.isVariableDeclaration(left)) { | |
// for (var i of test) | |
id = scope.generateUidIdentifier("ref"); | |
declar = t.variableDeclaration(left.kind, [t.variableDeclarator(left.declarations[0].id, id)]); | |
} else { | |
throw file.errorWithNode(left, messages.get("unknownForHead", left.type)); | |
} | |
var iteratorKey = scope.generateUidIdentifier("iterator"); | |
var isArrayKey = scope.generateUidIdentifier("isArray"); | |
var loop = util.template("for-of-loose", { | |
LOOP_OBJECT: iteratorKey, | |
IS_ARRAY: isArrayKey, | |
OBJECT: node.right, | |
INDEX: scope.generateUidIdentifier("i"), | |
ID: id | |
}); | |
if (!declar) { | |
// no declaration so we need to remove the variable declaration at the top of | |
// the for-of-loose template | |
loop.body.body.shift(); | |
} | |
// | |
return { | |
declar: declar, | |
node: loop, | |
loop: loop | |
}; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var spec = function spec(node, parent, scope, file) { | |
var left = node.left; | |
var declar; | |
var stepKey = scope.generateUidIdentifier("step"); | |
var stepValue = t.memberExpression(stepKey, t.identifier("value")); | |
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) { | |
// for (i of test), for ({ i } of test) | |
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue)); | |
} else if (t.isVariableDeclaration(left)) { | |
// for (var i of test) | |
declar = t.variableDeclaration(left.kind, [t.variableDeclarator(left.declarations[0].id, stepValue)]); | |
} else { | |
throw file.errorWithNode(left, messages.get("unknownForHead", left.type)); | |
} | |
// | |
var iteratorKey = scope.generateUidIdentifier("iterator"); | |
var template = util.template("for-of", { | |
ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"), | |
ITERATOR_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"), | |
ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"), | |
ITERATOR_KEY: iteratorKey, | |
STEP_KEY: stepKey, | |
OBJECT: node.right, | |
BODY: null | |
}); | |
var isLabeledParent = t.isLabeledStatement(parent); | |
var tryBody = template[3].block.body; | |
var loop = tryBody[0]; | |
if (isLabeledParent) { | |
tryBody[0] = t.labeledStatement(parent.label, loop); | |
} | |
// | |
return { | |
replaceParent: isLabeledParent, | |
declar: declar, | |
loop: loop, | |
node: template | |
}; | |
}; | |
},{"179":179,"182":182,"43":43}],97:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
var metadata = { | |
group: "builtin-pre" | |
}; | |
exports.metadata = metadata; | |
var visitor = { | |
Literal: function Literal(node) { | |
// number octal like 0b10 or 0o70 | |
if (typeof node.value === "number" && /^0[ob]/i.test(node.raw)) { | |
node.raw = undefined; | |
} | |
// unicode escape | |
if (typeof node.value === "string" && /\\[u]/gi.test(node.raw)) { | |
node.raw = undefined; | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{}],98:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
function keepBlockHoist(node, nodes) { | |
if (node._blockHoist) { | |
for (var i = 0; i < nodes.length; i++) { | |
nodes[i]._blockHoist = node._blockHoist; | |
} | |
} | |
} | |
var metadata = { | |
group: "builtin-modules" | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ImportDeclaration: function ImportDeclaration(node, parent, scope, file) { | |
// flow type | |
if (node.importKind === "type" || node.importKind === "typeof") return; | |
var nodes = []; | |
if (node.specifiers.length) { | |
var _arr = node.specifiers; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var specifier = _arr[_i]; | |
file.moduleFormatter.importSpecifier(specifier, node, nodes, scope); | |
} | |
} else { | |
file.moduleFormatter.importDeclaration(node, nodes, scope); | |
} | |
if (nodes.length === 1) { | |
// inherit `_blockHoist` - this is for `_blockHoist` in File.prototype.addImport | |
nodes[0]._blockHoist = node._blockHoist; | |
} | |
return nodes; | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
ExportAllDeclaration: function ExportAllDeclaration(node, parent, scope, file) { | |
var nodes = []; | |
file.moduleFormatter.exportAllDeclaration(node, nodes, scope); | |
keepBlockHoist(node, nodes); | |
return nodes; | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
ExportDefaultDeclaration: function ExportDefaultDeclaration(node, parent, scope, file) { | |
var nodes = []; | |
file.moduleFormatter.exportDeclaration(node, nodes, scope); | |
keepBlockHoist(node, nodes); | |
return nodes; | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
ExportNamedDeclaration: function ExportNamedDeclaration(node, parent, scope, file) { | |
// flow type | |
if (this.get("declaration").isTypeAlias()) return; | |
var nodes = []; | |
if (node.declaration) { | |
// make sure variable exports have an initializer | |
// this is done here to avoid duplicating it in the module formatters | |
if (t.isVariableDeclaration(node.declaration)) { | |
var declar = node.declaration.declarations[0]; | |
declar.init = declar.init || t.identifier("undefined"); | |
} | |
file.moduleFormatter.exportDeclaration(node, nodes, scope); | |
} else if (node.specifiers) { | |
for (var i = 0; i < node.specifiers.length; i++) { | |
file.moduleFormatter.exportSpecifier(node.specifiers[i], node, nodes, scope); | |
} | |
} | |
keepBlockHoist(node, nodes); | |
return nodes; | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],99:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _helpersReplaceSupers = _dereq_(65); | |
var _helpersReplaceSupers2 = _interopRequireDefault(_helpersReplaceSupers); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
function Property(path, node, scope, getObjectRef, file) { | |
if (!node.method && node.kind === "init") return; | |
if (!t.isFunction(node.value)) return; | |
var replaceSupers = new _helpersReplaceSupers2["default"]({ | |
getObjectRef: getObjectRef, | |
methodNode: node, | |
methodPath: path, | |
isStatic: true, | |
scope: scope, | |
file: file | |
}); | |
replaceSupers.replace(); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ObjectExpression: function ObjectExpression(node, parent, scope, file) { | |
var objectRef; | |
var getObjectRef = function getObjectRef() { | |
return objectRef = objectRef || scope.generateUidIdentifier("obj"); | |
}; | |
var propPaths = this.get("properties"); | |
for (var i = 0; i < node.properties.length; i++) { | |
Property(propPaths[i], node.properties[i], scope, getObjectRef, file); | |
} | |
if (objectRef) { | |
scope.push({ id: objectRef }); | |
return t.assignmentExpression("=", objectRef, node); | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179,"65":65}],100:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _helpersCallDelegate = _dereq_(56); | |
var _helpersCallDelegate2 = _interopRequireDefault(_helpersCallDelegate); | |
var _helpersGetFunctionArity = _dereq_(59); | |
var _helpersGetFunctionArity2 = _interopRequireDefault(_helpersGetFunctionArity); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var hasDefaults = function hasDefaults(node) { | |
for (var i = 0; i < node.params.length; i++) { | |
if (!t.isIdentifier(node.params[i])) return true; | |
} | |
return false; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var iifeVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ReferencedIdentifier: function ReferencedIdentifier(node, parent, scope, state) { | |
if (node.name !== "eval") { | |
if (!state.scope.hasOwnBinding(node.name)) return; | |
if (state.scope.bindingIdentifierEquals(node.name, node)) return; | |
} | |
state.iife = true; | |
this.stop(); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Function: function Function(node, parent, scope, file) { | |
if (!hasDefaults(node)) return; | |
// ensure it's a block, useful for arrow functions | |
this.ensureBlock(); | |
var state = { | |
iife: false, | |
scope: scope | |
}; | |
var body = []; | |
// | |
var argsIdentifier = t.identifier("arguments"); | |
argsIdentifier._shadowedFunctionLiteral = this; | |
// push a default parameter definition | |
function pushDefNode(left, right, i) { | |
var defNode; | |
if (exceedsLastNonDefault(i) || t.isPattern(left) || file.transformers["es6.spec.blockScoping"].canTransform()) { | |
defNode = util.template("default-parameter", { | |
VARIABLE_NAME: left, | |
DEFAULT_VALUE: right, | |
ARGUMENT_KEY: t.literal(i), | |
ARGUMENTS: argsIdentifier | |
}, true); | |
} else { | |
defNode = util.template("default-parameter-assign", { | |
VARIABLE_NAME: left, | |
DEFAULT_VALUE: right | |
}, true); | |
} | |
defNode._blockHoist = node.params.length - i; | |
body.push(defNode); | |
} | |
// check if an index exceeds the functions arity | |
function exceedsLastNonDefault(i) { | |
return i + 1 > lastNonDefaultParam; | |
} | |
// | |
var lastNonDefaultParam = _helpersGetFunctionArity2["default"](node); | |
// | |
var params = this.get("params"); | |
for (var i = 0; i < params.length; i++) { | |
var param = params[i]; | |
if (!param.isAssignmentPattern()) { | |
if (!param.isIdentifier()) { | |
param.traverse(iifeVisitor, state); | |
} | |
if (file.transformers["es6.spec.blockScoping"].canTransform() && param.isIdentifier()) { | |
pushDefNode(param.node, t.identifier("undefined"), i); | |
} | |
continue; | |
} | |
var left = param.get("left"); | |
var right = param.get("right"); | |
if (exceedsLastNonDefault(i) || left.isPattern()) { | |
var placeholder = scope.generateUidIdentifier("x"); | |
placeholder._isDefaultPlaceholder = true; | |
node.params[i] = placeholder; | |
} else { | |
node.params[i] = left.node; | |
} | |
if (!state.iife) { | |
if (right.isIdentifier() && scope.hasOwnBinding(right.node.name)) { | |
state.iife = true; | |
} else { | |
right.traverse(iifeVisitor, state); | |
} | |
} | |
pushDefNode(left.node, right.node, i); | |
} | |
// we need to cut off all trailing default parameters | |
node.params = node.params.slice(0, lastNonDefaultParam); | |
if (state.iife) { | |
body.push(_helpersCallDelegate2["default"](node, scope)); | |
node.body = t.blockStatement(body); | |
} else { | |
node.body.body = body.concat(node.body.body); | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179,"182":182,"56":56,"59":59}],101:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _traversalVisitors = _dereq_(168); | |
var visitors = _interopRequireWildcard(_traversalVisitors); | |
var _default = _dereq_(100); | |
var def = _interopRequireWildcard(_default); | |
var _rest = _dereq_(102); | |
var rest = _interopRequireWildcard(_rest); | |
var metadata = { | |
group: "builtin-advanced" | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = visitors.merge([rest.visitor, def.visitor]); | |
exports.visitor = visitor; | |
},{"100":100,"102":102,"168":168}],102:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var memberExpressionOptimisationVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Scope: function Scope(node, parent, scope, state) { | |
// check if this scope has a local binding that will shadow the rest parameter | |
if (!scope.bindingIdentifierEquals(state.name, state.outerBinding)) { | |
this.skip(); | |
} | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
Flow: function Flow() { | |
// don't touch reference in type annotations | |
this.skip(); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
Function: function Function(node, parent, scope, state) { | |
// skip over functions as whatever `arguments` we reference inside will refer | |
// to the wrong function | |
var oldNoOptimise = state.noOptimise; | |
state.noOptimise = true; | |
this.traverse(memberExpressionOptimisationVisitor, state); | |
state.noOptimise = oldNoOptimise; | |
this.skip(); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
ReferencedIdentifier: function ReferencedIdentifier(node, parent, scope, state) { | |
// we can't guarantee the purity of arguments | |
if (node.name === "arguments") { | |
state.deopted = true; | |
} | |
// is this a referenced identifier and is it referencing the rest parameter? | |
if (node.name !== state.name) return; | |
if (state.noOptimise) { | |
state.deopted = true; | |
} else { | |
if (this.parentPath.isMemberExpression({ computed: true, object: node })) { | |
// if we know that this member expression is referencing a number then we can safely | |
// optimise it | |
var prop = this.parentPath.get("property"); | |
if (prop.isBaseType("number")) { | |
state.candidates.push(this); | |
return; | |
} | |
} | |
// optimise single spread args in calls | |
if (this.parentPath.isSpreadElement() && state.offset === 0) { | |
var call = this.parentPath.parentPath; | |
if (call.isCallExpression() && call.node.arguments.length === 1) { | |
state.candidates.push(this); | |
return; | |
} | |
} | |
state.references.push(this); | |
} | |
}, | |
/** | |
* Deopt on use of a binding identifier with the same name as our rest param. | |
* | |
* See https://github.com/babel/babel/issues/2091 | |
*/ | |
BindingIdentifier: function BindingIdentifier(node, parent, scope, state) { | |
if (node.name === state.name) { | |
state.deopted = true; | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
function optimiseMemberExpression(parent, offset) { | |
if (offset === 0) return; | |
var newExpr; | |
var prop = parent.property; | |
if (t.isLiteral(prop)) { | |
prop.value += offset; | |
prop.raw = String(prop.value); | |
} else { | |
// // UnaryExpression, BinaryExpression | |
newExpr = t.binaryExpression("+", prop, t.literal(offset)); | |
parent.property = newExpr; | |
} | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function hasRest(node) { | |
return t.isRestElement(node.params[node.params.length - 1]); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Function: function Function(node, parent, scope) { | |
if (!hasRest(node)) return; | |
var restParam = node.params.pop(); | |
var rest = restParam.argument; | |
var argsId = t.identifier("arguments"); | |
// otherwise `arguments` will be remapped in arrow functions | |
argsId._shadowedFunctionLiteral = this; | |
// support patterns | |
if (t.isPattern(rest)) { | |
var pattern = rest; | |
rest = scope.generateUidIdentifier("ref"); | |
var declar = t.variableDeclaration("let", pattern.elements.map(function (elem, index) { | |
var accessExpr = t.memberExpression(rest, t.literal(index), true); | |
return t.variableDeclarator(elem, accessExpr); | |
})); | |
node.body.body.unshift(declar); | |
} | |
// check and optimise for extremely common cases | |
var state = { | |
references: [], | |
offset: node.params.length, | |
argumentsNode: argsId, | |
outerBinding: scope.getBindingIdentifier(rest.name), | |
// candidate member expressions we could optimise if there are no other references | |
candidates: [], | |
// local rest binding name | |
name: rest.name, | |
// whether any references to the rest parameter were made in a function | |
deopted: false | |
}; | |
this.traverse(memberExpressionOptimisationVisitor, state); | |
if (!state.deopted && !state.references.length) { | |
// we only have shorthands and there are no other references | |
if (state.candidates.length) { | |
var _arr = state.candidates; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var candidate = _arr[_i]; | |
candidate.replaceWith(argsId); | |
if (candidate.parentPath.isMemberExpression()) { | |
optimiseMemberExpression(candidate.parent, state.offset); | |
} | |
} | |
} | |
return; | |
} else { | |
state.references = state.references.concat(state.candidates); | |
} | |
// deopt shadowed functions as transforms like regenerator may try touch the allocation loop | |
state.deopted = state.deopted || !!node.shadow; | |
// | |
var start = t.literal(node.params.length); | |
var key = scope.generateUidIdentifier("key"); | |
var len = scope.generateUidIdentifier("len"); | |
var arrKey = key; | |
var arrLen = len; | |
if (node.params.length) { | |
// this method has additional params, so we need to subtract | |
// the index of the current argument position from the | |
// position in the array that we want to populate | |
arrKey = t.binaryExpression("-", key, start); | |
// we need to work out the size of the array that we're | |
// going to store all the rest parameters | |
// | |
// we need to add a check to avoid constructing the array | |
// with <0 if there are less arguments than params as it'll | |
// cause an error | |
arrLen = t.conditionalExpression(t.binaryExpression(">", len, start), t.binaryExpression("-", len, start), t.literal(0)); | |
} | |
var loop = util.template("rest", { | |
ARRAY_TYPE: restParam.typeAnnotation, | |
ARGUMENTS: argsId, | |
ARRAY_KEY: arrKey, | |
ARRAY_LEN: arrLen, | |
START: start, | |
ARRAY: rest, | |
KEY: key, | |
LEN: len | |
}); | |
if (state.deopted) { | |
loop._blockHoist = node.params.length + 1; | |
node.body.body.unshift(loop); | |
} else { | |
// perform allocation at the lowest common denominator of all references | |
loop._blockHoist = 1; | |
var target = this.getEarliestCommonAncestorFrom(state.references).getStatementParent(); | |
// don't perform the allocation inside a loop | |
var highestLoop; | |
target.findParent(function (path) { | |
if (path.isLoop()) { | |
highestLoop = path; | |
} else if (path.isFunction()) { | |
// stop crawling up for functions | |
return true; | |
} | |
}); | |
if (highestLoop) target = highestLoop; | |
target.insertBefore(loop); | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179,"182":182}],103:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
function loose(node, body, objId) { | |
var _arr = node.properties; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var prop = _arr[_i]; | |
body.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(objId, prop.key, prop.computed || t.isLiteral(prop.key)), prop.value))); | |
} | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function spec(node, body, objId, initProps, file) { | |
// add a simple assignment for all Symbol member expressions due to symbol polyfill limitations | |
// otherwise use Object.defineProperty | |
var _arr2 = node.properties; | |
for (var _i2 = 0; _i2 < _arr2.length; _i2++) { | |
var prop = _arr2[_i2]; | |
// this wont work with Object.defineProperty | |
if (t.isLiteral(t.toComputedKey(prop), { value: "__proto__" })) { | |
initProps.push(prop); | |
continue; | |
} | |
var key = prop.key; | |
if (t.isIdentifier(key) && !prop.computed) { | |
key = t.literal(key.name); | |
} | |
var bodyNode = t.callExpression(file.addHelper("define-property"), [objId, key, prop.value]); | |
body.push(t.expressionStatement(bodyNode)); | |
} | |
// only one node and it's a Object.defineProperty that returns the object | |
if (body.length === 1) { | |
var first = body[0].expression; | |
if (t.isCallExpression(first)) { | |
first.arguments[0] = t.objectExpression(initProps); | |
return first; | |
} | |
} | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ObjectExpression: { | |
exit: function exit(node, parent, scope, file) { | |
var hasComputed = false; | |
var _arr3 = node.properties; | |
for (var _i3 = 0; _i3 < _arr3.length; _i3++) { | |
var prop = _arr3[_i3]; | |
hasComputed = t.isProperty(prop, { computed: true, kind: "init" }); | |
if (hasComputed) break; | |
} | |
if (!hasComputed) return; | |
// put all getters/setters into the first object expression as well as all initialisers up | |
// to the first computed property | |
var initProps = []; | |
var stopInits = false; | |
node.properties = node.properties.filter(function (prop) { | |
if (prop.computed) { | |
stopInits = true; | |
} | |
if (prop.kind !== "init" || !stopInits) { | |
initProps.push(prop); | |
return false; | |
} else { | |
return true; | |
} | |
}); | |
// | |
var objId = scope.generateUidIdentifierBasedOnNode(parent); | |
// | |
var body = []; | |
// | |
var callback = spec; | |
if (file.isLoose("es6.properties.computed")) callback = loose; | |
var result = callback(node, body, objId, initProps, file); | |
if (result) return result; | |
// | |
body.unshift(t.variableDeclaration("var", [t.variableDeclarator(objId, t.objectExpression(initProps))])); | |
body.push(t.expressionStatement(objId)); | |
return body; | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],104:[function(_dereq_,module,exports){ | |
/** | |
* [Please add a description.] | |
*/ | |
"use strict"; | |
exports.__esModule = true; | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Property: function Property(node) { | |
if (node.method) { | |
node.method = false; | |
} | |
if (node.shorthand) { | |
node.shorthand = false; | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{}],105:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _helpersRegex = _dereq_(63); | |
var regex = _interopRequireWildcard(_helpersRegex); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Literal: function Literal(node) { | |
if (!regex.is(node, "y")) return; | |
return t.newExpression(t.identifier("RegExp"), [t.literal(node.regex.pattern), t.literal(node.regex.flags)]); | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179,"63":63}],106:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _regexpuRewritePattern = _dereq_(583); | |
var _regexpuRewritePattern2 = _interopRequireDefault(_regexpuRewritePattern); | |
var _helpersRegex = _dereq_(63); | |
var regex = _interopRequireWildcard(_helpersRegex); | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Literal: function Literal(node) { | |
if (!regex.is(node, "u")) return; | |
node.regex.pattern = _regexpuRewritePattern2["default"](node.regex.pattern, node.regex.flags); | |
regex.pullFlag(node, "u"); | |
} | |
}; | |
exports.visitor = visitor; | |
},{"583":583,"63":63}],107:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
group: "builtin-pre", | |
optional: true | |
}; | |
exports.metadata = metadata; | |
var visitor = { | |
ArrowFunctionExpression: function ArrowFunctionExpression(node, parent, scope, file) { | |
if (node.shadow) return; | |
node.shadow = { "this": false }; | |
var boundThis = t.thisExpression(); | |
boundThis._forceShadow = this; | |
// make sure that arrow function won't be instantiated | |
t.ensureBlock(node); | |
this.get("body").unshiftContainer("body", t.expressionStatement(t.callExpression(file.addHelper("new-arrow-check"), [t.thisExpression(), boundThis]))); | |
return t.callExpression(t.memberExpression(node, t.identifier("bind")), [t.thisExpression()]); | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],108:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
function buildAssert(node, file) { | |
return t.callExpression(file.addHelper("temporal-assert-defined"), [node, t.literal(node.name), file.addHelper("temporal-undefined")]); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function references(node, scope, state) { | |
var declared = state.letRefs[node.name]; | |
if (!declared) return false; | |
// declared node is different in this scope | |
return scope.getBindingIdentifier(node.name) === declared; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
var refVisitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ReferencedIdentifier: function ReferencedIdentifier(node, parent, scope, state) { | |
if (t.isFor(parent) && parent.left === node) return; | |
if (!references(node, scope, state)) return; | |
var assert = buildAssert(node, state.file); | |
this.skip(); | |
if (t.isUpdateExpression(parent)) { | |
if (parent._ignoreBlockScopingTDZ) return; | |
this.parentPath.replaceWith(t.sequenceExpression([assert, parent])); | |
} else { | |
return t.logicalExpression("&&", assert, node); | |
} | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
AssignmentExpression: { | |
exit: function exit(node, parent, scope, state) { | |
if (node._ignoreBlockScopingTDZ) return; | |
var nodes = []; | |
var ids = this.getBindingIdentifiers(); | |
for (var name in ids) { | |
var id = ids[name]; | |
if (references(id, scope, state)) { | |
nodes.push(buildAssert(id, state.file)); | |
} | |
} | |
if (nodes.length) { | |
node._ignoreBlockScopingTDZ = true; | |
nodes.push(node); | |
return nodes.map(t.expressionStatement); | |
} | |
} | |
} | |
}; | |
var metadata = { | |
optional: true, | |
group: "builtin-advanced" | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
"Program|Loop|BlockStatement": { | |
exit: function exit(node, parent, scope, file) { | |
var letRefs = node._letReferences; | |
if (!letRefs) return; | |
this.traverse(refVisitor, { | |
letRefs: letRefs, | |
file: file | |
}); | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],109:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
group: "builtin-pre", | |
optional: true | |
}; | |
exports.metadata = metadata; | |
var visitor = { | |
Program: function Program() { | |
var id = this.scope.generateUidIdentifier("null"); | |
this.unshiftContainer("body", [t.variableDeclaration("var", [t.variableDeclarator(id, t.literal(null))]), t.exportNamedDeclaration(null, [t.exportSpecifier(id, t.identifier("__proto__"))])]); | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],110:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
optional: true | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
UnaryExpression: function UnaryExpression(node, parent, scope, file) { | |
if (node._ignoreSpecSymbols) return; | |
if (this.parentPath.isBinaryExpression() && t.EQUALITY_BINARY_OPERATORS.indexOf(parent.operator) >= 0) { | |
// optimise `typeof foo === "string"` since we can determine that they'll never need to handle symbols | |
var opposite = this.getOpposite(); | |
if (opposite.isLiteral() && opposite.node.value !== "symbol" && opposite.node.value !== "object") return; | |
} | |
if (node.operator === "typeof") { | |
var call = t.callExpression(file.addHelper("typeof"), [node.argument]); | |
if (this.get("argument").isIdentifier()) { | |
var undefLiteral = t.literal("undefined"); | |
var unary = t.unaryExpression("typeof", node.argument); | |
unary._ignoreSpecSymbols = true; | |
return t.conditionalExpression(t.binaryExpression("===", unary, undefLiteral), undefLiteral, call); | |
} else { | |
return call; | |
} | |
} | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
BinaryExpression: function BinaryExpression(node, parent, scope, file) { | |
if (node.operator === "instanceof") { | |
return t.callExpression(file.addHelper("instanceof"), [node.left, node.right]); | |
} | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
"VariableDeclaration|FunctionDeclaration": function VariableDeclarationFunctionDeclaration(node) { | |
if (node._generated) this.skip(); | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],111:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
optional: true, | |
group: "builtin-pre" | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
TemplateLiteral: function TemplateLiteral(node, parent) { | |
if (t.isTaggedTemplateExpression(parent)) return; | |
for (var i = 0; i < node.expressions.length; i++) { | |
node.expressions[i] = t.callExpression(t.identifier("String"), [node.expressions[i]]); | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],112:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
function getSpreadLiteral(spread, scope) { | |
if (scope.hub.file.isLoose("es6.spread") && !t.isIdentifier(spread.argument, { name: "arguments" })) { | |
return spread.argument; | |
} else { | |
return scope.toArray(spread.argument, true); | |
} | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function hasSpread(nodes) { | |
for (var i = 0; i < nodes.length; i++) { | |
if (t.isSpreadElement(nodes[i])) { | |
return true; | |
} | |
} | |
return false; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function build(props, scope) { | |
var nodes = []; | |
var _props = []; | |
var push = function push() { | |
if (!_props.length) return; | |
nodes.push(t.arrayExpression(_props)); | |
_props = []; | |
}; | |
for (var i = 0; i < props.length; i++) { | |
var prop = props[i]; | |
if (t.isSpreadElement(prop)) { | |
push(); | |
nodes.push(getSpreadLiteral(prop, scope)); | |
} else { | |
_props.push(prop); | |
} | |
} | |
push(); | |
return nodes; | |
} | |
var metadata = { | |
group: "builtin-advanced" | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ArrayExpression: function ArrayExpression(node, parent, scope) { | |
var elements = node.elements; | |
if (!hasSpread(elements)) return; | |
var nodes = build(elements, scope); | |
var first = nodes.shift(); | |
if (!t.isArrayExpression(first)) { | |
nodes.unshift(first); | |
first = t.arrayExpression([]); | |
} | |
return t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
CallExpression: function CallExpression(node, parent, scope) { | |
var args = node.arguments; | |
if (!hasSpread(args)) return; | |
var contextLiteral = t.identifier("undefined"); | |
node.arguments = []; | |
var nodes; | |
if (args.length === 1 && args[0].argument.name === "arguments") { | |
nodes = [args[0].argument]; | |
} else { | |
nodes = build(args, scope); | |
} | |
var first = nodes.shift(); | |
if (nodes.length) { | |
node.arguments.push(t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes)); | |
} else { | |
node.arguments.push(first); | |
} | |
var callee = node.callee; | |
if (this.get("callee").isMemberExpression()) { | |
var temp = scope.maybeGenerateMemoised(callee.object); | |
if (temp) { | |
callee.object = t.assignmentExpression("=", temp, callee.object); | |
contextLiteral = temp; | |
} else { | |
contextLiteral = callee.object; | |
} | |
t.appendToMemberExpression(callee, t.identifier("apply")); | |
} else { | |
node.callee = t.memberExpression(node.callee, t.identifier("apply")); | |
} | |
node.arguments.unshift(contextLiteral); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
NewExpression: function NewExpression(node, parent, scope, file) { | |
var args = node.arguments; | |
if (!hasSpread(args)) return; | |
var nodes = build(args, scope); | |
var context = t.arrayExpression([t.literal(null)]); | |
args = t.callExpression(t.memberExpression(context, t.identifier("concat")), nodes); | |
return t.newExpression(t.callExpression(t.memberExpression(file.addHelper("bind"), t.identifier("apply")), [node.callee, args]), []); | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],113:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
// istanbul ignore next | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var _lodashCollectionReduceRight = _dereq_(415); | |
var _lodashCollectionReduceRight2 = _interopRequireDefault(_lodashCollectionReduceRight); | |
var _messages = _dereq_(43); | |
var messages = _interopRequireWildcard(_messages); | |
var _lodashArrayFlatten = _dereq_(406); | |
var _lodashArrayFlatten2 = _interopRequireDefault(_lodashArrayFlatten); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _lodashCollectionMap = _dereq_(414); | |
var _lodashCollectionMap2 = _interopRequireDefault(_lodashCollectionMap); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
group: "builtin-trailing" | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Function: function Function(node, parent, scope, file) { | |
if (node.generator || node.async) return; | |
var tailCall = new TailCallTransformer(this, scope, file); | |
tailCall.run(); | |
} | |
}; | |
exports.visitor = visitor; | |
/** | |
* [Please add a description.] | |
*/ | |
function returnBlock(expr) { | |
return t.blockStatement([t.returnStatement(expr)]); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
enter: function enter(node, parent) { | |
if (t.isTryStatement(parent)) { | |
if (node === parent.block) { | |
this.skip(); | |
} else if (parent.finalizer && node !== parent.finalizer) { | |
this.skip(); | |
} | |
} | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
ReturnStatement: function ReturnStatement(node, parent, scope, state) { | |
return state.subTransform(node.argument); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
Function: function Function() { | |
this.skip(); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
VariableDeclaration: function VariableDeclaration(node, parent, scope, state) { | |
state.vars.push(node); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
ThisExpression: function ThisExpression(node, parent, scope, state) { | |
if (!state.isShadowed) { | |
state.needsThis = true; | |
state.thisPaths.push(this); | |
} | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
ReferencedIdentifier: function ReferencedIdentifier(node, parent, scope, state) { | |
if (node.name === "arguments" && (!state.isShadowed || node._shadowedFunctionLiteral)) { | |
state.needsArguments = true; | |
state.argumentsPaths.push(this); | |
} | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var TailCallTransformer = (function () { | |
function TailCallTransformer(path, scope, file) { | |
_classCallCheck(this, TailCallTransformer); | |
this.hasTailRecursion = false; | |
this.needsArguments = false; | |
this.argumentsPaths = []; | |
this.setsArguments = false; | |
this.needsThis = false; | |
this.thisPaths = []; | |
this.isShadowed = path.isArrowFunctionExpression() || path.is("shadow"); | |
this.ownerId = path.node.id; | |
this.vars = []; | |
this.scope = scope; | |
this.path = path; | |
this.file = file; | |
this.node = path.node; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
TailCallTransformer.prototype.getArgumentsId = function getArgumentsId() { | |
return this.argumentsId = this.argumentsId || this.scope.generateUidIdentifier("arguments"); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
TailCallTransformer.prototype.getThisId = function getThisId() { | |
return this.thisId = this.thisId || this.scope.generateUidIdentifier("this"); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
TailCallTransformer.prototype.getLeftId = function getLeftId() { | |
return this.leftId = this.leftId || this.scope.generateUidIdentifier("left"); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
TailCallTransformer.prototype.getFunctionId = function getFunctionId() { | |
return this.functionId = this.functionId || this.scope.generateUidIdentifier("function"); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
TailCallTransformer.prototype.getAgainId = function getAgainId() { | |
return this.againId = this.againId || this.scope.generateUidIdentifier("again"); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
TailCallTransformer.prototype.getParams = function getParams() { | |
var params = this.params; | |
if (!params) { | |
params = this.node.params; | |
this.paramDecls = []; | |
for (var i = 0; i < params.length; i++) { | |
var param = params[i]; | |
if (!param._isDefaultPlaceholder) { | |
this.paramDecls.push(t.variableDeclarator(param, params[i] = this.scope.generateUidIdentifier("x"))); | |
} | |
} | |
} | |
return this.params = params; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
TailCallTransformer.prototype.hasDeopt = function hasDeopt() { | |
// check if the ownerId has been reassigned, if it has then it's not safe to | |
// perform optimisations | |
var ownerIdInfo = this.scope.getBinding(this.ownerId.name); | |
return ownerIdInfo && !ownerIdInfo.constant; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
TailCallTransformer.prototype.run = function run() { | |
var node = this.node; | |
// only tail recursion can be optimized as for now, so we can skip anonymous | |
// functions entirely | |
var ownerId = this.ownerId; | |
if (!ownerId) return; | |
// traverse the function and look for tail recursion | |
this.path.traverse(visitor, this); | |
// has no tail call recursion | |
if (!this.hasTailRecursion) return; | |
// the function binding isn't constant so we can't be sure that it's the same function :( | |
if (this.hasDeopt()) { | |
this.file.log.deopt(node, messages.get("tailCallReassignmentDeopt")); | |
return; | |
} | |
// | |
var body = this.path.ensureBlock().body; | |
for (var i = 0; i < body.length; i++) { | |
var bodyNode = body[i]; | |
if (!t.isFunctionDeclaration(bodyNode)) continue; | |
bodyNode = body[i] = t.variableDeclaration("var", [t.variableDeclarator(bodyNode.id, t.toExpression(bodyNode))]); | |
bodyNode._blockHoist = 2; | |
} | |
var paramDecls = this.paramDecls; | |
if (paramDecls.length > 0) { | |
var paramDecl = t.variableDeclaration("var", paramDecls); | |
paramDecl._blockHoist = Infinity; | |
body.unshift(paramDecl); | |
} | |
body.unshift(t.expressionStatement(t.assignmentExpression("=", this.getAgainId(), t.literal(false)))); | |
node.body = util.template("tail-call-body", { | |
FUNCTION_ID: this.getFunctionId(), | |
AGAIN_ID: this.getAgainId(), | |
BLOCK: node.body | |
}); | |
var topVars = []; | |
if (this.needsThis) { | |
var _arr = this.thisPaths; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var path = _arr[_i]; | |
path.replaceWith(this.getThisId()); | |
} | |
topVars.push(t.variableDeclarator(this.getThisId(), t.thisExpression())); | |
} | |
if (this.needsArguments || this.setsArguments) { | |
var _arr2 = this.argumentsPaths; | |
for (var _i2 = 0; _i2 < _arr2.length; _i2++) { | |
var _path = _arr2[_i2]; | |
_path.replaceWith(this.argumentsId); | |
} | |
var decl = t.variableDeclarator(this.argumentsId); | |
if (this.argumentsId) { | |
decl.init = t.identifier("arguments"); | |
decl.init._shadowedFunctionLiteral = this.path; | |
} | |
topVars.push(decl); | |
} | |
var leftId = this.leftId; | |
if (leftId) { | |
topVars.push(t.variableDeclarator(leftId)); | |
} | |
if (topVars.length > 0) { | |
node.body.body.unshift(t.variableDeclaration("var", topVars)); | |
} | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
TailCallTransformer.prototype.subTransform = function subTransform(node) { | |
if (!node) return; | |
var handler = this["subTransform" + node.type]; | |
if (handler) return handler.call(this, node); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
TailCallTransformer.prototype.subTransformConditionalExpression = function subTransformConditionalExpression(node) { | |
var callConsequent = this.subTransform(node.consequent); | |
var callAlternate = this.subTransform(node.alternate); | |
if (!callConsequent && !callAlternate) { | |
return; | |
} | |
// if ternary operator had tail recursion in value, convert to optimized if-statement | |
node.type = "IfStatement"; | |
node.consequent = callConsequent ? t.toBlock(callConsequent) : returnBlock(node.consequent); | |
if (callAlternate) { | |
node.alternate = t.isIfStatement(callAlternate) ? callAlternate : t.toBlock(callAlternate); | |
} else { | |
node.alternate = returnBlock(node.alternate); | |
} | |
return [node]; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
TailCallTransformer.prototype.subTransformLogicalExpression = function subTransformLogicalExpression(node) { | |
// only call in right-value of can be optimized | |
var callRight = this.subTransform(node.right); | |
if (!callRight) return; | |
// cache left value as it might have side-effects | |
var leftId = this.getLeftId(); | |
var testExpr = t.assignmentExpression("=", leftId, node.left); | |
if (node.operator === "&&") { | |
testExpr = t.unaryExpression("!", testExpr); | |
} | |
return [t.ifStatement(testExpr, returnBlock(leftId))].concat(callRight); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
TailCallTransformer.prototype.subTransformSequenceExpression = function subTransformSequenceExpression(node) { | |
var seq = node.expressions; | |
// only last element can be optimized | |
var lastCall = this.subTransform(seq[seq.length - 1]); | |
if (!lastCall) { | |
return; | |
} | |
// remove converted expression from sequence | |
// and convert to regular expression if needed | |
if (--seq.length === 1) { | |
node = seq[0]; | |
} | |
return [t.expressionStatement(node)].concat(lastCall); | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
TailCallTransformer.prototype.subTransformCallExpression = function subTransformCallExpression(node) { | |
var callee = node.callee; | |
var thisBinding, args; | |
if (t.isMemberExpression(callee, { computed: false }) && t.isIdentifier(callee.property)) { | |
switch (callee.property.name) { | |
case "call": | |
args = t.arrayExpression(node.arguments.slice(1)); | |
break; | |
case "apply": | |
args = node.arguments[1] || t.identifier("undefined"); | |
this.needsArguments = true; | |
break; | |
default: | |
return; | |
} | |
thisBinding = node.arguments[0]; | |
callee = callee.object; | |
} | |
// only tail recursion can be optimized as for now | |
if (!t.isIdentifier(callee) || !this.scope.bindingIdentifierEquals(callee.name, this.ownerId)) { | |
return; | |
} | |
this.hasTailRecursion = true; | |
if (this.hasDeopt()) return; | |
var body = []; | |
if (this.needsThis && !t.isThisExpression(thisBinding)) { | |
body.push(t.expressionStatement(t.assignmentExpression("=", this.getThisId(), thisBinding || t.identifier("undefined")))); | |
} | |
if (!args) { | |
args = t.arrayExpression(node.arguments); | |
} | |
var argumentsId = this.getArgumentsId(); | |
var params = this.getParams(); | |
if (this.needsArguments) { | |
body.push(t.expressionStatement(t.assignmentExpression("=", argumentsId, args))); | |
} | |
if (t.isArrayExpression(args)) { | |
var elems = args.elements; | |
// pad out the args so all the function args are reset - https://github.com/babel/babel/issues/1938 | |
while (elems.length < params.length) { | |
elems.push(t.identifier("undefined")); | |
} | |
for (var i = 0; i < elems.length; i++) { | |
var param = params[i]; | |
var elem = elems[i]; | |
if (param && !param._isDefaultPlaceholder) { | |
elems[i] = t.assignmentExpression("=", param, elem); | |
} else { | |
// exceeds parameters but push it anyway to ensure correct execution | |
} | |
} | |
if (!this.needsArguments) { | |
var _arr3 = elems; | |
for (var _i3 = 0; _i3 < _arr3.length; _i3++) { | |
var elem = _arr3[_i3]; | |
// only push expressions that we really need, this will skip pure arguments that exceed the | |
// parameter length of the current function | |
if (!this.scope.isPure(elem)) { | |
body.push(t.expressionStatement(elem)); | |
} | |
} | |
} | |
} else { | |
this.setsArguments = true; | |
for (var i = 0; i < params.length; i++) { | |
var param = params[i]; | |
if (!param._isDefaultPlaceholder) { | |
body.push(t.expressionStatement(t.assignmentExpression("=", param, t.memberExpression(argumentsId, t.literal(i), true)))); | |
} | |
} | |
} | |
body.push(t.expressionStatement(t.assignmentExpression("=", this.getAgainId(), t.literal(true)))); | |
if (this.vars.length > 0) { | |
var declarations = _lodashArrayFlatten2["default"](_lodashCollectionMap2["default"](this.vars, function (decl) { | |
return decl.declarations; | |
})); | |
var assignment = _lodashCollectionReduceRight2["default"](declarations, function (expr, decl) { | |
return t.assignmentExpression("=", decl.id, expr); | |
}, t.identifier("undefined")); | |
var statement = t.expressionStatement(assignment); | |
body.push(statement); | |
} | |
body.push(t.continueStatement(this.getFunctionId())); | |
return body; | |
}; | |
return TailCallTransformer; | |
})(); | |
},{"179":179,"182":182,"406":406,"414":414,"415":415,"43":43}],114:[function(_dereq_,module,exports){ | |
/* eslint no-unused-vars: 0 */ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
group: "builtin-pre" | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
function isString(node) { | |
return t.isLiteral(node) && typeof node.value === "string"; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function buildBinaryExpression(left, right) { | |
var node = t.binaryExpression("+", left, right); | |
node._templateLiteralProduced = true; | |
return node; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function crawl(path) { | |
if (path.is("_templateLiteralProduced")) { | |
crawl(path.get("left")); | |
crawl(path.get("right")); | |
} else if (!path.isBaseType("string") && !path.isBaseType("number")) { | |
path.replaceWith(t.callExpression(t.identifier("String"), [path.node])); | |
} | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
TaggedTemplateExpression: function TaggedTemplateExpression(node, parent, scope, file) { | |
var quasi = node.quasi; | |
var args = []; | |
var strings = []; | |
var raw = []; | |
var _arr = quasi.quasis; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var elem = _arr[_i]; | |
strings.push(t.literal(elem.value.cooked)); | |
raw.push(t.literal(elem.value.raw)); | |
} | |
strings = t.arrayExpression(strings); | |
raw = t.arrayExpression(raw); | |
var templateName = "tagged-template-literal"; | |
if (file.isLoose("es6.templateLiterals")) templateName += "-loose"; | |
var templateObject = file.addTemplateObject(templateName, strings, raw); | |
args.push(templateObject); | |
args = args.concat(quasi.expressions); | |
return t.callExpression(node.tag, args); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
TemplateLiteral: function TemplateLiteral(node, parent, scope, file) { | |
var nodes = []; | |
var _arr2 = node.quasis; | |
for (var _i2 = 0; _i2 < _arr2.length; _i2++) { | |
var elem = _arr2[_i2]; | |
nodes.push(t.literal(elem.value.cooked)); | |
var expr = node.expressions.shift(); | |
if (expr) nodes.push(expr); | |
} | |
// filter out empty string literals | |
nodes = nodes.filter(function (n) { | |
return !t.isLiteral(n, { value: "" }); | |
}); | |
// since `+` is left-to-right associative | |
// ensure the first node is a string if first/second isn't | |
if (!isString(nodes[0]) && !isString(nodes[1])) { | |
nodes.unshift(t.literal("")); | |
} | |
if (nodes.length > 1) { | |
var root = buildBinaryExpression(nodes.shift(), nodes.shift()); | |
var _arr3 = nodes; | |
for (var _i3 = 0; _i3 < _arr3.length; _i3++) { | |
var _node = _arr3[_i3]; | |
root = buildBinaryExpression(root, _node); | |
} | |
this.replaceWith(root); | |
//crawl(this); | |
} else { | |
return nodes[0]; | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],115:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
var metadata = { | |
stage: 3 | |
}; | |
exports.metadata = metadata; | |
},{}],116:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
var metadata = { | |
stage: 1, | |
dependencies: ["es6.classes"] | |
}; | |
exports.metadata = metadata; | |
},{}],117:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _helpersBuildComprehension = _dereq_(54); | |
var _helpersBuildComprehension2 = _interopRequireDefault(_helpersBuildComprehension); | |
var _traversal = _dereq_(148); | |
var _traversal2 = _interopRequireDefault(_traversal); | |
var _util = _dereq_(182); | |
var util = _interopRequireWildcard(_util); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
stage: 0 | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ComprehensionExpression: function ComprehensionExpression(node, parent, scope) { | |
var callback = array; | |
if (node.generator) callback = generator; | |
return callback(node, parent, scope); | |
} | |
}; | |
exports.visitor = visitor; | |
/** | |
* [Please add a description.] | |
*/ | |
function generator(node) { | |
var body = []; | |
var container = t.functionExpression(null, [], t.blockStatement(body), true); | |
container.shadow = true; | |
body.push(_helpersBuildComprehension2["default"](node, function () { | |
return t.expressionStatement(t.yieldExpression(node.body)); | |
})); | |
return t.callExpression(container, []); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function array(node, parent, scope) { | |
var uid = scope.generateUidIdentifierBasedOnNode(parent); | |
var container = util.template("array-comprehension-container", { | |
KEY: uid | |
}); | |
container.callee.shadow = true; | |
var block = container.callee.body; | |
var body = block.body; | |
if (_traversal2["default"].hasType(node, scope, "YieldExpression", t.FUNCTION_TYPES)) { | |
container.callee.generator = true; | |
container = t.yieldExpression(container, true); | |
} | |
var returnStatement = body.pop(); | |
body.push(_helpersBuildComprehension2["default"](node, function () { | |
return util.template("array-push", { | |
STATEMENT: node.body, | |
KEY: uid | |
}, true); | |
})); | |
body.push(returnStatement); | |
return container; | |
} | |
},{"148":148,"179":179,"182":182,"54":54}],118:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _helpersMemoiseDecorators = _dereq_(60); | |
var _helpersMemoiseDecorators2 = _interopRequireDefault(_helpersMemoiseDecorators); | |
var _helpersDefineMap = _dereq_(57); | |
var defineMap = _interopRequireWildcard(_helpersDefineMap); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
dependencies: ["es6.classes"], | |
optional: true, | |
stage: 1 | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ObjectExpression: function ObjectExpression(node, parent, scope, file) { | |
var hasDecorators = false; | |
for (var i = 0; i < node.properties.length; i++) { | |
var prop = node.properties[i]; | |
if (prop.decorators) { | |
hasDecorators = true; | |
break; | |
} | |
} | |
if (!hasDecorators) return; | |
var mutatorMap = {}; | |
for (var i = 0; i < node.properties.length; i++) { | |
var prop = node.properties[i]; | |
if (prop.decorators) _helpersMemoiseDecorators2["default"](prop.decorators, scope); | |
if (prop.kind === "init" && !prop.method) { | |
prop.kind = ""; | |
prop.value = t.functionExpression(null, [], t.blockStatement([t.returnStatement(prop.value)])); | |
} | |
defineMap.push(mutatorMap, prop, "initializer", file); | |
} | |
var obj = defineMap.toClassObject(mutatorMap); | |
obj = defineMap.toComputedObjectFromClass(obj); | |
return t.callExpression(file.addHelper("create-decorated-object"), [obj]); | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179,"57":57,"60":60}],119:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
optional: true, | |
stage: 0 | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
DoExpression: function DoExpression(node) { | |
var body = node.body.body; | |
if (body.length) { | |
return body; | |
} else { | |
return t.identifier("undefined"); | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],120:[function(_dereq_,module,exports){ | |
// https://github.com/rwaldron/exponentiation-operator | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _helpersBuildBinaryAssignmentOperatorTransformer = _dereq_(53); | |
var _helpersBuildBinaryAssignmentOperatorTransformer2 = _interopRequireDefault(_helpersBuildBinaryAssignmentOperatorTransformer); | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
stage: 3 | |
}; | |
exports.metadata = metadata; | |
var MATH_POW = t.memberExpression(t.identifier("Math"), t.identifier("pow")); | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = _helpersBuildBinaryAssignmentOperatorTransformer2["default"]({ | |
operator: "**", | |
/** | |
* [Please add a description.] | |
*/ | |
build: function build(left, right) { | |
return t.callExpression(MATH_POW, [left, right]); | |
} | |
}); | |
exports.visitor = visitor; | |
},{"179":179,"53":53}],121:[function(_dereq_,module,exports){ | |
// https://github.com/leebyron/ecmascript-more-export-from | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
stage: 1 | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
function build(node, nodes, scope) { | |
var first = node.specifiers[0]; | |
if (!t.isExportNamespaceSpecifier(first) && !t.isExportDefaultSpecifier(first)) return; | |
var specifier = node.specifiers.shift(); | |
var uid = scope.generateUidIdentifier(specifier.exported.name); | |
var newSpecifier; | |
if (t.isExportNamespaceSpecifier(specifier)) { | |
newSpecifier = t.importNamespaceSpecifier(uid); | |
} else { | |
newSpecifier = t.importDefaultSpecifier(uid); | |
} | |
nodes.push(t.importDeclaration([newSpecifier], node.source)); | |
nodes.push(t.exportNamedDeclaration(null, [t.exportSpecifier(uid, specifier.exported)])); | |
build(node, nodes, scope); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ExportNamedDeclaration: function ExportNamedDeclaration(node, parent, scope) { | |
var nodes = []; | |
build(node, nodes, scope); | |
if (!nodes.length) return; | |
if (node.specifiers.length >= 1) { | |
nodes.push(node); | |
} | |
return nodes; | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],122:[function(_dereq_,module,exports){ | |
// https://github.com/zenparsing/es-function-bind | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
optional: true, | |
stage: 0 | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
function getTempId(scope) { | |
var id = scope.path.getData("functionBind"); | |
if (id) return id; | |
id = scope.generateDeclaredUidIdentifier("context"); | |
return scope.path.setData("functionBind", id); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function getStaticContext(bind, scope) { | |
var object = bind.object || bind.callee.object; | |
return scope.isStatic(object) && object; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function inferBindContext(bind, scope) { | |
var staticContext = getStaticContext(bind, scope); | |
if (staticContext) return staticContext; | |
var tempId = getTempId(scope); | |
if (bind.object) { | |
bind.callee = t.sequenceExpression([t.assignmentExpression("=", tempId, bind.object), bind.callee]); | |
} else { | |
bind.callee.object = t.assignmentExpression("=", tempId, bind.callee.object); | |
} | |
return tempId; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
CallExpression: function CallExpression(node, parent, scope) { | |
var bind = node.callee; | |
if (!t.isBindExpression(bind)) return; | |
var context = inferBindContext(bind, scope); | |
node.callee = t.memberExpression(bind.callee, t.identifier("call")); | |
node.arguments.unshift(context); | |
}, | |
/** | |
* [Please add a description.] | |
*/ | |
BindExpression: function BindExpression(node, parent, scope) { | |
var context = inferBindContext(node, scope); | |
return t.callExpression(t.memberExpression(node.callee, t.identifier("bind")), [context]); | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],123:[function(_dereq_,module,exports){ | |
// https://github.com/sebmarkbage/ecmascript-rest-spread | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
stage: 2, | |
dependencies: ["es6.destructuring"] | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var hasSpread = function hasSpread(node) { | |
for (var i = 0; i < node.properties.length; i++) { | |
if (t.isSpreadProperty(node.properties[i])) { | |
return true; | |
} | |
} | |
return false; | |
}; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
ObjectExpression: function ObjectExpression(node, parent, scope, file) { | |
if (!hasSpread(node)) return; | |
var args = []; | |
var props = []; | |
var push = function push() { | |
if (!props.length) return; | |
args.push(t.objectExpression(props)); | |
props = []; | |
}; | |
for (var i = 0; i < node.properties.length; i++) { | |
var prop = node.properties[i]; | |
if (t.isSpreadProperty(prop)) { | |
push(); | |
args.push(prop.argument); | |
} else { | |
props.push(prop); | |
} | |
} | |
push(); | |
if (!t.isObjectExpression(args[0])) { | |
args.unshift(t.objectExpression([])); | |
} | |
return t.callExpression(file.addHelper("extends"), args); | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],124:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
var metadata = { | |
stage: 2 | |
}; | |
exports.metadata = metadata; | |
},{}],125:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports.internal = internal; | |
exports.blacklist = blacklist; | |
exports.whitelist = whitelist; | |
exports.stage = stage; | |
exports.optional = optional; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _lodashCollectionIncludes = _dereq_(413); | |
var _lodashCollectionIncludes2 = _interopRequireDefault(_lodashCollectionIncludes); | |
/** | |
* [Please add a description.] | |
*/ | |
function internal(transformer) { | |
if (transformer.key[0] === "_") return true; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function blacklist(transformer, opts) { | |
var blacklist = opts.blacklist; | |
if (blacklist.length && _lodashCollectionIncludes2["default"](blacklist, transformer.key)) return false; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function whitelist(transformer, opts) { | |
var whitelist = opts.whitelist; | |
if (whitelist) return _lodashCollectionIncludes2["default"](whitelist, transformer.key); | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function stage(transformer, opts) { | |
var stage = transformer.metadata.stage; | |
if (stage != null && stage >= opts.stage) return true; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function optional(transformer, opts) { | |
if (transformer.metadata.optional && !_lodashCollectionIncludes2["default"](opts.optional, transformer.key)) return false; | |
} | |
},{"413":413}],126:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
exports["default"] = { | |
//- builtin-prepass | |
"minification.constantFolding": _dereq_(183), | |
//- builtin-pre | |
strict: _dereq_(142), | |
eval: _dereq_(185), | |
_validation: _dereq_(132), | |
_hoistDirectives: _dereq_(128), | |
"minification.removeDebugger": _dereq_(194), | |
"minification.removeConsole": _dereq_(193), | |
"utility.inlineEnvironmentVariables": _dereq_(186), | |
"minification.deadCodeElimination": _dereq_(184), | |
_modules: _dereq_(130), | |
"react.displayName": _dereq_(192), | |
"es6.spec.modules": _dereq_(109), | |
"es6.spec.arrowFunctions": _dereq_(107), | |
"es6.spec.templateLiterals": _dereq_(111), | |
"es6.templateLiterals": _dereq_(114), | |
"es6.literals": _dereq_(97), | |
"validation.undeclaredVariableCheck": _dereq_(197), | |
//- builtin-basic | |
// this is where the bulk of the ES6 transformations take place, none of them require traversal state | |
// so they can all be concatenated together for performance | |
"spec.functionName": _dereq_(144), | |
"es7.classProperties": _dereq_(116), | |
"es7.trailingFunctionCommas": _dereq_(124), | |
"es7.asyncFunctions": _dereq_(115), | |
"es7.decorators": _dereq_(118), | |
"validation.react": _dereq_(145), | |
"es6.arrowFunctions": _dereq_(89), | |
"spec.blockScopedFunctions": _dereq_(143), | |
"optimisation.react.constantElements": _dereq_(191), | |
"optimisation.react.inlineElements": _dereq_(135), | |
"es7.comprehensions": _dereq_(117), | |
"es6.classes": _dereq_(91), | |
asyncToGenerator: _dereq_(136), | |
bluebirdCoroutines: _dereq_(137), | |
"es6.objectSuper": _dereq_(99), | |
"es7.objectRestSpread": _dereq_(123), | |
"es7.exponentiationOperator": _dereq_(120), | |
"es5.properties.mutators": _dereq_(88), | |
"es6.properties.shorthand": _dereq_(104), | |
"es6.properties.computed": _dereq_(103), | |
"optimisation.flow.forOf": _dereq_(133), | |
"es6.forOf": _dereq_(96), | |
"es6.regex.sticky": _dereq_(105), | |
"es6.regex.unicode": _dereq_(106), | |
"es6.constants": _dereq_(94), | |
"es7.exportExtensions": _dereq_(121), | |
"spec.protoToAssign": _dereq_(190), | |
"es7.doExpressions": _dereq_(119), | |
"es6.spec.symbols": _dereq_(110), | |
"es7.functionBind": _dereq_(122), | |
"spec.undefinedToVoid": _dereq_(199), | |
//- builtin-advanced | |
"es6.spread": _dereq_(112), | |
"es6.parameters": _dereq_(101), | |
"es6.destructuring": _dereq_(95), | |
"es6.blockScoping": _dereq_(90), | |
"es6.spec.blockScoping": _dereq_(108), | |
reactCompat: _dereq_(139), | |
react: _dereq_(140), | |
regenerator: _dereq_(141), | |
// es6 syntax transformation is **forbidden** past this point since regenerator will chuck a massive | |
// hissy fit | |
//- builtin-modules | |
runtime: _dereq_(196), | |
"es6.modules": _dereq_(98), | |
_moduleFormatter: _dereq_(129), | |
//- builtin-trailing | |
// these clean up the output and do finishing up transformations, it's important to note that by this | |
// stage you can't import any new modules or insert new ES6 as all those transformers have already | |
// been ran | |
"es6.tailCall": _dereq_(113), | |
_shadowFunctions: _dereq_(131), | |
"es3.propertyLiterals": _dereq_(87), | |
"es3.memberExpressionLiterals": _dereq_(86), | |
"minification.memberExpressionLiterals": _dereq_(188), | |
"minification.propertyLiterals": _dereq_(189), | |
_blockHoist: _dereq_(127), | |
jscript: _dereq_(187), | |
flow: _dereq_(138), | |
"optimisation.modules.system": _dereq_(134) | |
}; | |
module.exports = exports["default"]; | |
},{"101":101,"103":103,"104":104,"105":105,"106":106,"107":107,"108":108,"109":109,"110":110,"111":111,"112":112,"113":113,"114":114,"115":115,"116":116,"117":117,"118":118,"119":119,"120":120,"121":121,"122":122,"123":123,"124":124,"127":127,"128":128,"129":129,"130":130,"131":131,"132":132,"133":133,"134":134,"135":135,"136":136,"137":137,"138":138,"139":139,"140":140,"141":141,"142":142,"143":143,"144":144,"145":145,"183":183,"184":184,"185":185,"186":186,"187":187,"188":188,"189":189,"190":190,"191":191,"192":192,"193":193,"194":194,"196":196,"197":197,"199":199,"86":86,"87":87,"88":88,"89":89,"90":90,"91":91,"94":94,"95":95,"96":96,"97":97,"98":98,"99":99}],127:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
var _lodashCollectionSortBy = _dereq_(417); | |
var _lodashCollectionSortBy2 = _interopRequireDefault(_lodashCollectionSortBy); | |
var metadata = { | |
group: "builtin-trailing" | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
* | |
* Priority: | |
* | |
* - 0 We want this to be at the **very** bottom | |
* - 1 Default node position | |
* - 2 Priority over normal nodes | |
* - 3 We want this to be at the **very** top | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Block: { | |
exit: function exit(node) { | |
var hasChange = false; | |
for (var i = 0; i < node.body.length; i++) { | |
var bodyNode = node.body[i]; | |
if (bodyNode && bodyNode._blockHoist != null) { | |
hasChange = true; | |
break; | |
} | |
} | |
if (!hasChange) return; | |
node.body = _lodashCollectionSortBy2["default"](node.body, function (bodyNode) { | |
var priority = bodyNode && bodyNode._blockHoist; | |
if (priority == null) priority = 1; | |
if (priority === true) priority = 2; | |
// Higher priorities should move toward the top. | |
return -1 * priority; | |
}); | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{"417":417}],128:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
var metadata = { | |
group: "builtin-pre" | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Block: { | |
exit: function exit(node) { | |
for (var i = 0; i < node.body.length; i++) { | |
var bodyNode = node.body[i]; | |
if (t.isExpressionStatement(bodyNode) && t.isLiteral(bodyNode.expression)) { | |
bodyNode._blockHoist = Infinity; | |
} else { | |
return; | |
} | |
} | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{"179":179}],129:[function(_dereq_,module,exports){ | |
"use strict"; | |
exports.__esModule = true; | |
var metadata = { | |
group: "builtin-modules" | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ | |
Program: { | |
exit: function exit(program, parent, scope, file) { | |
// ensure that these are at the top, just like normal imports | |
var _arr = file.dynamicImports; | |
for (var _i = 0; _i < _arr.length; _i++) { | |
var node = _arr[_i]; | |
node._blockHoist = 3; | |
} | |
program.body = file.dynamicImports.concat(program.body); | |
if (!file.transformers["es6.modules"].canTransform()) return; | |
if (file.moduleFormatter.transform) { | |
file.moduleFormatter.transform(program); | |
} | |
} | |
} | |
}; | |
exports.visitor = visitor; | |
},{}],130:[function(_dereq_,module,exports){ | |
// in this transformer we have to split up classes and function declarations | |
// from their exports. why? because sometimes we need to replace classes with | |
// nodes that aren't allowed in the same contexts. also, if you're exporting | |
// a generator function as a default then regenerator will destroy the export | |
// declaration and leave a variable declaration in it's place... yeah, handy. | |
"use strict"; | |
exports.__esModule = true; | |
// istanbul ignore next | |
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } | |
var _types = _dereq_(179); | |
var t = _interopRequireWildcard(_types); | |
/** | |
* [Please add a description.] | |
*/ | |
function getDeclar(node) { | |
var declar = node.declaration; | |
t.inheritsComments(declar, node); | |
t.removeComments(node); | |
declar._ignoreUserWhitespace = true; | |
return declar; | |
} | |
/** | |
* [Please add a description.] | |
*/ | |
function buildExportSpecifier(id) { | |
return t.exportSpecifier(cloneIdentifier(id), cloneIdentifier(id)); | |
} | |
function cloneIdentifier(_ref) { | |
var name = _ref.name; | |
var loc = _ref.loc; | |
var id = t.identifier(name); | |
id._loc = loc; | |
return id; | |
} | |
var metadata = { | |
group: "builtin-pre" | |
}; | |
exports.metadata = metadata; | |
/** | |
* [Please add a description.] | |
*/ | |
var visitor = { | |
/** | |
* [Please add a description.] | |
*/ |