{“ast”:null,“code”:“'use strict';nnfunction _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }nnvar immediate = require('immediate');n/* istanbul ignore next */nnnfunction INTERNAL() {}nnvar handlers = {};nvar REJECTED = ['REJECTED'];nvar FULFILLED = ['FULFILLED'];nvar PENDING = ['PENDING'];nmodule.exports = Promise;nnfunction Promise(resolver) {n if (typeof resolver !== 'function') {n throw new TypeError('resolver must be a function');n }nn this.state = PENDING;n this.queue = [];n this.outcome = void 0;nn if (resolver !== INTERNAL) {n safelyResolveThenable(this, resolver);n }n}nnPromise.prototype = function (callback) {n if (typeof callback !== 'function') {n return this;n }nn var p = this.constructor;n return this.then(resolve, reject);nn function resolve(value) {n function yes() {n return value;n }nn return p.resolve(callback()).then(yes);n }nn function reject(reason) {n function no() {n throw reason;n }nn return p.resolve(callback()).then(no);n }n};nnPromise.prototype = function (onRejected) {n return this.then(null, onRejected);n};nnPromise.prototype.then = function (onFulfilled, onRejected) {n if (typeof onFulfilled !== 'function' && this.state === FULFILLED || typeof onRejected !== 'function' && this.state === REJECTED) {n return this;n }nn var promise = new this.constructor(INTERNAL);nn if (this.state !== PENDING) {n var resolver = this.state === FULFILLED ? onFulfilled : onRejected;n unwrap(promise, resolver, this.outcome);n } else {n this.queue.push(new QueueItem(promise, onFulfilled, onRejected));n }nn return promise;n};nnfunction QueueItem(promise, onFulfilled, onRejected) {n this.promise = promise;nn if (typeof onFulfilled === 'function') {n this.onFulfilled = onFulfilled;n this.callFulfilled = this.otherCallFulfilled;n }nn if (typeof onRejected === 'function') {n this.onRejected = onRejected;n this.callRejected = this.otherCallRejected;n }n}nnQueueItem.prototype.callFulfilled = function (value) {n handlers.resolve(this.promise, value);n};nnQueueItem.prototype.otherCallFulfilled = function (value) {n unwrap(this.promise, this.onFulfilled, value);n};nnQueueItem.prototype.callRejected = function (value) {n handlers.reject(this.promise, value);n};nnQueueItem.prototype.otherCallRejected = function (value) {n unwrap(this.promise, this.onRejected, value);n};nnfunction unwrap(promise, func, value) {n immediate(function () {n var returnValue;nn try {n returnValue = func(value);n } catch (e) {n return handlers.reject(promise, e);n }nn if (returnValue === promise) {n handlers.reject(promise, new TypeError('Cannot resolve promise with itself'));n } else {n handlers.resolve(promise, returnValue);n }n });n}nnhandlers.resolve = function (self, value) {n var result = tryCatch(getThen, value);nn if (result.status === 'error') {n return handlers.reject(self, result.value);n }nn var thenable = result.value;nn if (thenable) {n safelyResolveThenable(self, thenable);n } else {n self.state = FULFILLED;n self.outcome = value;n var i = -1;n var len = self.queue.length;nn while (++i < len) {n self.queue.callFulfilled(value);n }n }nn return self;n};nnhandlers.reject = function (self, error) {n self.state = REJECTED;n self.outcome = error;n var i = -1;n var len = self.queue.length;nn while (++i < len) {n self.queue.callRejected(error);n }nn return self;n};nnfunction getThen(obj) {n // Make
sure we only access the accessor once as required by the specn var then = obj && obj.then;nn if (obj && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof then === 'function') {n return function appyThen() {n then.apply(obj, arguments);n };n }n}nnfunction safelyResolveThenable(self, thenable) {n // Either fulfill, reject or reject with errorn var called = false;nn function onError(value) {n if (called) {n return;n }nn called = true;n handlers.reject(self, value);n }nn function onSuccess(value) {n if (called) {n return;n }nn called = true;n handlers.resolve(self, value);n }nn function tryToUnwrap() {n thenable(onSuccess, onError);n }nn var result = tryCatch(tryToUnwrap);nn if (result.status === 'error') {n onError(result.value);n }n}nnfunction tryCatch(func, value) {n var out = {};nn try {n out.value = func(value);n out.status = 'success';n } catch (e) {n out.status = 'error';n out.value = e;n }nn return out;n}nnPromise.resolve = resolve;nnfunction resolve(value) {n if (value instanceof this) {n return value;n }nn return handlers.resolve(new this(INTERNAL), value);n}nnPromise.reject = reject;nnfunction reject(reason) {n var promise = new this(INTERNAL);n return handlers.reject(promise, reason);n}nnPromise.all = all;nnfunction all(iterable) {n var self = this;nn if (Object.prototype.toString.call(iterable) !== '[object Array]') {n return this.reject(new TypeError('must be an array'));n }nn var len = iterable.length;n var called = false;nn if (!len) {n return this.resolve([]);n }nn var values = new Array(len);n var resolved = 0;n var i = -1;n var promise = new this(INTERNAL);nn while (++i < len) {n allResolver(iterable, i);n }nn return promise;nn function allResolver(value, i) {n self.resolve(value).then(resolveFromAll, function (error) {n if (!called) {n called = true;n handlers.reject(promise, error);n }n });nn function resolveFromAll(outValue) {n values = outValue;nn if (++resolved === len && !called) {n called = true;n handlers.resolve(promise, values);n }n }n }n}nnPromise.race = race;nnfunction race(iterable) {n var self = this;nn if (Object.prototype.toString.call(iterable) !== '[object Array]') {n return this.reject(new TypeError('must be an array'));n }nn var len = iterable.length;n var called = false;nn if (!len) {n return this.resolve([]);n }nn var i = -1;n var promise = new this(INTERNAL);nn while (++i < len) {n resolver(iterable);n }nn return promise;nn function resolver(value) {n self.resolve(value).then(function (response) {n if (!called) {n called = true;n handlers.resolve(promise, response);n }n }, function (error) {n if (!called) {n called = true;n handlers.reject(promise, error);n }n });n }n}”,“map”:null,“metadata”:{},“sourceType”:“module”}