Created
December 10, 2018 19:54
-
-
Save eliihen/61e5b37e20573b9508713f888e22c227 to your computer and use it in GitHub Desktop.
See before: https://gist.github.com/esphen/805e0ccd14e8df37b5a504930b682a63#file-esnext-ts-before-js
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
var n = (function() { | |
function n() {} | |
return ( | |
(n.prototype.then = function(r, e) { | |
var o = new n(), | |
i = this.s; | |
if (i) { | |
var u = 1 & i ? r : e; | |
if (u) { | |
try { | |
t(o, 1, u(this.v)); | |
} catch (n) { | |
t(o, 2, n); | |
} | |
return o; | |
} | |
return this; | |
} | |
return ( | |
(this.o = function(n) { | |
try { | |
var i = n.v; | |
1 & n.s ? t(o, 1, r ? r(i) : i) : e ? t(o, 1, e(i)) : t(o, 2, i); | |
} catch (n) { | |
t(o, 2, n); | |
} | |
}), | |
o | |
); | |
}), | |
n | |
); | |
})(); | |
function t(r, e, o) { | |
if (!r.s) { | |
if (o instanceof n) { | |
if (!o.s) return void (o.o = t.bind(null, r, e)); | |
1 & e && (e = o.s), (o = o.v); | |
} | |
if (o && o.then) return void o.then(t.bind(null, r, e), t.bind(null, r, 2)); | |
(r.s = e), (r.v = o); | |
var i = r.o; | |
i && i(r); | |
} | |
} | |
function r(t) { | |
return t instanceof n && 1 & t.s; | |
} | |
function e(n, t) { | |
try { | |
var r = n(); | |
} catch (n) { | |
return t(!0, n); | |
} | |
return r && r.then | |
? r.then(t.bind(null, !1), t.bind(null, !0)) | |
: t(!1, value); | |
} | |
function o(n) { | |
var t = 'function' == typeof Symbol && n[Symbol.iterator], | |
r = 0; | |
return t | |
? t.call(n) | |
: { | |
next: function() { | |
return ( | |
n && r >= n.length && (n = void 0), { value: n && n[r++], done: !n } | |
); | |
}, | |
}; | |
} | |
function i(n) { | |
if (!Symbol.asyncIterator) | |
throw new TypeError('Symbol.asyncIterator is not defined.'); | |
var t, | |
r = n[Symbol.asyncIterator]; | |
return r | |
? r.call(n) | |
: ((n = o(n)), | |
(t = {}), | |
e('next'), | |
e('throw'), | |
e('return'), | |
(t[Symbol.asyncIterator] = function() { | |
return this; | |
}), | |
t); | |
function e(r) { | |
t[r] = | |
n[r] && | |
function(t) { | |
return new Promise(function(e, o) { | |
(function(n, t, r, e) { | |
Promise.resolve(e).then(function(t) { | |
n({ value: t, done: r }); | |
}, t); | |
})(e, o, (t = n[r](t)).done, t.value); | |
}); | |
}; | |
} | |
} | |
var u = function() { | |
try { | |
var o, | |
u, | |
f, | |
c, | |
h = [], | |
v = e( | |
function() { | |
return (function(n, t) { | |
try { | |
var r = n(); | |
} catch (n) { | |
return t(n); | |
} | |
return r && r.then ? r.then(void 0, t) : r; | |
})( | |
function() { | |
o = i([1, 2]); | |
var e = (function(e, o, i) { | |
for (var u; ; ) { | |
var f = e(); | |
if ((r(f) && (f = f.v), !f)) return c; | |
if (f.then) { | |
u = 0; | |
break; | |
} | |
var c = i(); | |
if (c && c.then) { | |
if (!r(c)) { | |
u = 1; | |
break; | |
} | |
c = c.s; | |
} | |
if (o) { | |
var h = o(); | |
if (h && h.then && !r(h)) { | |
u = 2; | |
break; | |
} | |
} | |
} | |
var v = new n(), | |
a = t.bind(null, v, 2); | |
return ( | |
(0 === u ? f.then(s) : 1 === u ? c.then(l) : h.then(d)).then( | |
void 0, | |
a, | |
), | |
v | |
); | |
function l(n) { | |
c = n; | |
do { | |
if (o && (h = o()) && h.then && !r(h)) | |
return void h.then(d).then(void 0, a); | |
if (!(f = e()) || (r(f) && !f.v)) return void t(v, 1, c); | |
if (f.then) return void f.then(s).then(void 0, a); | |
r((c = i())) && (c = c.v); | |
} while (!c || !c.then); | |
c.then(l).then(void 0, a); | |
} | |
function s(n) { | |
n | |
? (c = i()) && c.then | |
? c.then(l).then(void 0, a) | |
: l(c) | |
: t(v, 1, c); | |
} | |
function d() { | |
(f = e()) | |
? f.then | |
? f.then(s).then(void 0, a) | |
: s(f) | |
: t(v, 1, c); | |
} | |
})( | |
function() { | |
return !!Promise.resolve(o.next()).then(function(n) { | |
return !(u = n).done; | |
}); | |
}, | |
void 0, | |
function() { | |
h.push(u.value); | |
}, | |
); | |
return e && e.then ? e.then(function() {}) : void 0; | |
}, | |
function(n) { | |
f = { error: n }; | |
}, | |
); | |
}, | |
function(n, t) { | |
function r(r) { | |
if (n) throw t; | |
return t; | |
} | |
var i = e( | |
function() { | |
var n = (function() { | |
if (u && !u.done && (c = o.return)) | |
return Promise.resolve(c.call(o)).then(function() {}); | |
})(); | |
return n && n.then ? n.then(function() {}) : void 0; | |
}, | |
function(n, t) { | |
if (f) throw f.error; | |
if (n) throw t; | |
return t; | |
}, | |
); | |
return i && i.then ? i.then(r) : r(); | |
}, | |
); | |
return Promise.resolve( | |
v && v.then | |
? v.then(function(n) { | |
return h; | |
}) | |
: h, | |
); | |
} catch (n) { | |
return Promise.reject(n); | |
} | |
}; | |
u().then(console.log), (module.exports = u); | |
//# sourceMappingURL=esnext-ts.js.map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment