Advertisement
jkulvich

tstl_test

Jan 18th, 2023 (edited)
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.44 KB | None | 0 0
  1. -- TypeScript to LUA with async entry point.
  2. -- TS to LUA: https://typescripttolua.github.io/play
  3. -- LUA Minifier: https://goonlinetools.com/lua-minifier
  4. -- Run in ComputerCraft with: "pastebin run sEH08FYX"
  5. -- Alternative run: "wget run https://pastebin.com/raw/sEH08FYX"
  6. local a,b;do local c={__tostring=function(self)return("Symbol("..(self.description or""))..")"end}function a(d)return setmetatable({description=d},c)end;b={iterator=a("Symbol.iterator"),hasInstance=a("Symbol.hasInstance"),species=a("Symbol.species"),toStringTag=a("Symbol.toStringTag")}end;local function e(f,g)if type(g)~="table"then error("Right-hand side of 'instanceof' is not an object",0)end;if g[b.hasInstance]~=nil then return not not g[b.hasInstance](g,f)end;if type(f)=="table"then local h=f.constructor;while h~=nil do if h==g then return true end;h=h.____super end end;return false end;local function i(j,...)local k=setmetatable({},j.prototype)k:____constructor(...)return k end;local function l(self)local m={prototype={}}m.prototype.__index=m.prototype;m.prototype.constructor=m;return m end;local n=table.unpack or unpack;local function o(self,...)local p={...}local q=#p;if q==0 then return#self end;for r=#self,1,-1 do self[r+q]=self[r]end;for r=1,q do self[r]=p[r]end;return#self end;local function s(t,...)local u={...}return function(v,...)local w={...}o(w,n(u))return t(n(w))end end;local x;do local function y(self)local z;local A;local B=i(x,function(v,C,D)z=C;A=D end)return{promise=B,resolve=z,reject=A}end;local function E(self,F)return e(F,x)end;x=l()x.name="__TS__Promise"function x.prototype.____constructor(self,G)self.state=0;self.fulfilledCallbacks={}self.rejectedCallbacks={}self.finallyCallbacks={}do local function H(I)self:reject(I)end;local J,K=pcall(function()G(nil,s(self.resolve,self),s(self.reject,self))end)if not J then H(K)end end end;function x.resolve(L)local B=i(x,function()end)B.state=1;B.value=L;return B end;function x.reject(M)local B=i(x,function()end)B.state=2;B.rejectionReason=M;return B end;x.prototype["then"]=function(self,N,O)local P=y(nil)local B=P.promise;local z=P.resolve;local A=P.reject;local Q=self.state==1;local R=self.state==2;if N then local S=self:createPromiseResolvingCallback(N,z,A)local T=self.fulfilledCallbacks;T[#T+1]=S;if Q then S(nil,self.value)end else local U=self.fulfilledCallbacks;U[#U+1]=function(v,V)return z(nil,V)end end;if O then local S=self:createPromiseResolvingCallback(O,z,A)local W=self.rejectedCallbacks;W[#W+1]=S;if R then S(nil,self.rejectionReason)end else local X=self.rejectedCallbacks;X[#X+1]=function(v,Y)return A(nil,Y)end end;if Q then z(nil,self.value)end;if R then A(nil,self.rejectionReason)end;return B end;function x.prototype.catch(self,O)return self["then"](self,nil,O)end;function x.prototype.finally(self,Z)if Z then local _=self.finallyCallbacks;_[#_+1]=Z;if self.state~=0 then Z(nil)end end;return self end;function x.prototype.resolve(self,L)if e(L,x)then L["then"](L,function(v,V)return self:resolve(V)end,function(v,Y)return self:reject(Y)end)return end;if self.state==0 then self.state=1;self.value=L;for v,a0 in ipairs(self.fulfilledCallbacks)do a0(nil,L)end;for v,a0 in ipairs(self.finallyCallbacks)do a0(nil)end end end;function x.prototype.reject(self,M)if self.state==0 then self.state=2;self.rejectionReason=M;for v,a0 in ipairs(self.rejectedCallbacks)do a0(nil,M)end;for v,a0 in ipairs(self.finallyCallbacks)do a0(nil)end end end;function x.prototype.createPromiseResolvingCallback(self,a1,z,A)return function(v,a2)do local function H(I)A(nil,I)end;local J,K=pcall(function()self:handleCallbackData(a1(nil,a2),z,A)end)if not J then H(K)end end end end;function x.prototype.handleCallbackData(self,L,z,A)if E(nil,L)then local a3=L;if a3.state==1 then z(nil,a3.value)elseif a3.state==2 then A(nil,a3.rejectionReason)else L["then"](L,z,A)end else z(nil,L)end end end;local function a4(a5)return i(x,function(v,z,A)local a6,a7,a8,a9,aa;function a6(self,a2)local ab;if e(a2,x)then ab=a2 else ab=x.resolve(a2)end;return ab end;function a7(self,a2)local ac,ad=coroutine.resume(aa,a2)if ac then a8(nil,ad)else A(nil,ad)end end;function a8(self,ae)if a9 then return end;if coroutine.status(aa)=="dead"then z(nil,ae)else local af=a6(nil,ae)af["then"](af,a7,A)end end;a9=false;aa=coroutine.create(a5)local ac,ad=coroutine.resume(aa,function(v,V)a9=true;local ag=a6(nil,V)ag["then"](ag,z,A)end)if ac then a8(nil,ad)else A(nil,ad)end end)end;local function ah(F)return coroutine.yield(F)end(function()return a4(function(ai)print("YAY!")end)end)(nil)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement