@laot/bridge 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ltbridge-v1.0.6.zip +0 -0
- package/dist/ltbridge.js +24 -24
- package/dist/modules.dat +1 -1
- package/package.json +3 -2
- package/dist/ltbridge-v1.0.5.zip +0 -0
|
Binary file
|
package/dist/ltbridge.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
`)});let m=/(?:^|[^a-zA-Z0-9_.:"'\]])(LT\.[a-zA-Z0-9_.]+|[a-zA-Z0-9_]+)/g,S;for(;(S=m.exec(p))!==null;){let F=S[1];F.startsWith("LT.")&&(F=F.substring(3));let $=F.split("."),G="";for(let A of $){G=G?G+"."+A:A;let R="@"+G.replace(/\./g,"/"),N=G.replace(/\./g,"/");if(n.includes(R)&&R!==o?a.add(R):n.includes(N)&&N!==o?a.add(N):n.includes(G)&&G!==o&&a.add(G),g&&g[G]){let V=g[G];if(V.length===1)V[0]!==o&&a.add(V[0]);else if(G.includes(".")){let j=G.split(".")[0].toLowerCase(),
|
|
4
|
-
\x1B[33m! Circular dependency detected involving '${o}'.\x1B[0m`);return}if(l.add(o),!d[o]){console.log(`\x1B[31m\u2716 Trying to resolve '${o}' but it does not exist in LTBridge.\x1B[0m`),l.delete(o);return}let g=c(o,u);t[o]=g;for(let L of g)s(L);l.delete(o),i.add(o),e.push(o)}for(let o of k)s(o);return{sequence:e,graph:t}}
|
|
5
|
-
`," ","\r"],
|
|
6
|
-
`,t:" ",'"':'"',"'":"'","\\":"\\"},
|
|
2
|
+
var re=(k,u)=>()=>(u||k((u={exports:{}}).exports,u),u.exports);var we=re((ft,pn)=>{pn.exports={name:"@laot/bridge",version:"1.0.7",description:"LTBridge CLI for fetching and bundling FiveM modules.",license:"MIT",repository:{type:"git",url:"https://github.com/laot7490/ltbridge.git"},author:"laot",keywords:["fivem","lua","bridge","module-manager","bundler","cli","gta5","redm","laot","ltbridge"],main:"dist/ltbridge.js",scripts:{build:"node scripts/compiler.js && esbuild bin/ltbridge.js --bundle --minify --platform=node --target=node18 --packages=external --outfile=dist/ltbridge.js",zip:"node scripts/zip-dist.js",prepublishOnly:"npm run build && npm run zip"},bin:{ltbridge:"./dist/ltbridge.js"},files:["dist","LICENSE","README.md"],dependencies:{chokidar:"^5.0.0",commander:"^11.0.0","fs-extra":"^11.1.1",prompts:"^2.4.2"},devDependencies:{esbuild:"^0.25.0"}}});var De=re((dt,Oe)=>{var hn=/__LT_VERSION\s*=\s*'[^']*'/g,mn=/__LT_DISABLE_DEBUG\s*=\s*(true|false)/g;function kn(k,{version:u,disableDebug:d}={}){if(!k)return k;let n=k;return u&&(n=n.replace(hn,`__LT_VERSION = '${u}'`)),d!==void 0&&(n=n.replace(mn,`__LT_DISABLE_DEBUG = ${d?"true":"false"}`)),n}Oe.exports={applyBuildConstants:kn}});var ue=re((Tt,Ue)=>{var qe=require("fs"),gn=require("path"),Fe=null;function Ae(){if(Fe)return Fe;let k=gn.join(__dirname,"..","dist","modules.dat");return qe.existsSync(k)||(console.log("\x1B[31m\u2716 LTBridge is not compiled. Please run 'npm run build' first.\x1B[0m"),process.exit(1)),Fe=JSON.parse(qe.readFileSync(k,"utf8")),Fe}function Ln(){return Ae().registry}function Sn(k){return Ae().modules[k]}Ue.exports={getModuleRegistry:Ln,getDatabase:Ae,getModuleData:Sn}});var Ie=re((mt,Ke)=>{var pt=require("fs"),ht=require("path"),{getModuleRegistry:bn,getModuleData:We}=ue();function yn(k,u){let d=bn(),n=Object.keys(d),i=new Set,l=new Set,e=[],t={};function c(o,g){let L=We(o);if(!L)return[];if(L.meta&&Array.isArray(L.meta.dependencies))return L.meta.dependencies;let a=new Set,p="";["shared","client","server"].forEach(F=>{L[F]&&L[F].code&&(p+=L[F].code+`
|
|
3
|
+
`)});let m=/(?:^|[^a-zA-Z0-9_.:"'\]])(LT\.[a-zA-Z0-9_.]+|[a-zA-Z0-9_]+)/g,S;for(;(S=m.exec(p))!==null;){let F=S[1];F.startsWith("LT.")&&(F=F.substring(3));let $=F.split("."),G="";for(let A of $){G=G?G+"."+A:A;let R="@"+G.replace(/\./g,"/"),N=G.replace(/\./g,"/");if(n.includes(R)&&R!==o?a.add(R):n.includes(N)&&N!==o?a.add(N):n.includes(G)&&G!==o&&a.add(G),g&&g[G]){let V=g[G];if(V.length===1)V[0]!==o&&a.add(V[0]);else if(G.includes(".")){let j=G.split(".")[0].toLowerCase(),D=V.find(X=>X.toLowerCase().includes(j));D&&D!==o&&a.add(D)}else{let D=V.find(X=>{let Y=We(X);if(!Y)return!1;let ee=!1;return["shared","client","server"].forEach(te=>{Y[te]&&Y[te].stubs&&Y[te].stubs.some(z=>z.metadata&&z.metadata.global)&&(ee=!0)}),ee})||V[0];D!==o&&a.add(D)}}}}let w=d[o];if(w){let $=w.replace(/\\/g,"/").split("/");for(;$.length>1;){$.pop();let G=$[$.length-1],A=G,R="@"+G;o!==A&&n.includes(A)&&a.add(A),o!==R&&n.includes(R)&&a.add(R)}}return Array.from(a)}function s(o){if(i.has(o))return;if(l.has(o)){console.log(`
|
|
4
|
+
\x1B[33m! Circular dependency detected involving '${o}'.\x1B[0m`);return}if(l.add(o),!d[o]){console.log(`\x1B[31m\u2716 Trying to resolve '${o}' but it does not exist in LTBridge.\x1B[0m`),l.delete(o);return}let g=c(o,u);t[o]=g;for(let L of g)s(L);l.delete(o),i.add(o),e.push(o)}for(let o of k)s(o);return{sequence:e,graph:t}}Ke.exports={resolveDependencies:yn}});var Xe=re((kt,Ge)=>{var ge=console.log,J=function(k,u){if(!k)throw u};function _n(k,u){if(!k)return 0;var d=k.toString().split(".");return d.length>1?parseInt(d[0],u)+parseInt(d[1],u)/Math.pow(u,d[1].length):parseInt(d[0],u)}var En=[" ",`
|
|
5
|
+
`," ","\r"],Cn={r:"\r",n:`
|
|
6
|
+
`,t:" ",'"':'"',"'":"'","\\":"\\"},ze=new Proxy(Cn,{get(k,u){return _n(u)}}),wn=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","_","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],Pe=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","_","a","b","c","d","e","f","g","t","u","v","w","h","i","j","k","l","m","n","o","p","q","r","s","x","y","z"],he=["0","1","2","3","4","5","6","7","8","9"],Fn=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","A","B","C","D","E","F"],Gn=["+","-","*",")",";","/","^","%","#",",","{","}",":","[","]","(",".","`"],Bn=["~","=",">","<"],xn=["+","-","*","/","^","..","%","//"],$n=["+=","-=","*=","/=","^=","..=","%=","//="],Ze=["and","break","do","else","elseif","end","false","for","function","goto","if","in","local","nil","not","or","repeat","return","then","true","until","while","continue"],me=["continue","goto"],Rn=["else","elseif","until","end"],An=["-","not","#","~"],Je=["+","-","*","/","%","^","#","//","&","|","~","<<",">>","..",".",":",">","<","<=",">=","~=","==","+=","-=","*=","/=","%=","^=","..=","//=","and","or"],In=11,Me={"^":[13,12],"%":[10,10],"//":[10,10],"/":[10,10],"*":[10,10],"+":[9,9],"-":[9,9],"..":[8,7],">>":[7,7],"<<":[7,7],"&":[6,6],"~":[5,5],"|":[4,4],"==":[3,3],"~=":[3,3],">=":[3,3],"<=":[3,3],">":[3,3],"<":[3,3],"+=":[3,3],"-=":[3,3],"*=":[3,3],"/=":[3,3],"^=":[3,3],"%=":[3,3],"..=":[3,3],"//=":[3,3],and:[2,2],or:[1,1]};function Mn(k){let u=0,d=k.length,n=[];function i(a){return a=a||0,u<=d?k.substr(u+a,1):""}function l(){if(u<=d){let a=k.substr(u,1);return u++,a}else return""}function e(a){let p=0,m=1,S=1;for(;p<=u;)k.substr(p,1)==`
|
|
7
7
|
`?(m++,S=1):S++;let w;for(w=0;w<n.length;w++){let F=n[w];ge(`${F.Type}<${F.Source}>`)}throw`file<${m}:${S}>: ${a}`}function t(a){for(;;){let p=l();if(p=="")e("Unfinished long string.");else if(p=="]"){let m=!0,S;for(S=1;S<=a;S++)if(i()=="=")u++;else{m=!1;break}if(m&&l()=="]")return}}}function c(){let a=u;for(;i()=="=";)u++;if(i()=="[")return u++,u-a-1;u=a}let s=0,o=0,g=0;function L(a){g++;let p=k.substr(o,u-o),m=null;a=="Number"&&(p=p.replace(/[\_]+/g,""),p.substr(0,2).toLowerCase()=="0x"?(m="hex",parseInt(p,16)<999999999999&&(p=parseInt(p,16))):p.substr(0,2).toLowerCase()=="0b"&&(m="bin",parseInt(p.substr(2),2)<999999999999&&(p=parseInt(p.substr(2),2))));let S={Type:a,LeadingWhite:k.substr(s,o-s),Source:p};return m!==null&&(S.NType=m),n.push(S),s=u,o=u,S}for(;;){for(s=u;;){let p=i();if(p=="")break;if(p=="-")if(i(1)=="-")if(u+=2,i()=="["){u++;let m=c();if(m!=null)t(m),s=u;else for(;;){let S=l();if(S==""||S==`
|
|
8
8
|
`)break}}else for(;;){let m=l();if(m==""||m==`
|
|
9
|
-
`)break}else break;else if(
|
|
10
|
-
`?(h++,T=0):T++;if(b==r)break;f++}return`${h}:${T+1}`}function e(){let r=i();return`<${r.Type} \`${r.Source}\`> at: ${l(r)}`}function t(){let r=i();return r.Type=="Eof"||r.Type=="Keyword"&&Fn.includes(r.Source)}function c(){return Gn.includes(i().Source)||!1}function s(){return He.includes(i().Source)||!1}function o(r,h){let T=i();if(T.Type==r&&(h==null||T.Source==h))return n();if(T.Type=="Keyword"&&r=="Ident"&&me.includes(T.Source)&&(h==null||T.Source==h))return n();{let f;for(f=-3;f<=3;f++)ge(`Tokens[${f}] = \`${i(f).Source}\``);throw h?`${l(T)}: \`${h}\` expected.`:`${l(T)}: ${r} expected.`}}function g(r){let h=r.GetFirstToken,T=r.GetLastToken,f=r;return r.GetFirstToken=function(){let b=h(f);return J(b),b},r.GetLastToken=function(){let b=T(f);return J(b),b},r}let L,a;function p(r,h){let T=[a(r,h)],f=[];for(;i().Source==",";)f.push(n()),T.push(a(r,h));return[T,f]}function m(r,h){let T=i();if(T.Source=="("){let f=n(),b=a(r,h),_=o("Symbol",")"),y;return y=g({Type:"ParenExpr",Expression:b,Token_OpenParen:f,Token_CloseParen:_,GetFirstToken:()=>y.Token_OpenParen,GetLastToken:()=>y.Token_CloseParen}),y}else if(T.Type=="Ident"||T.Type=="Keyword"&&me.includes(T.Source)){let f;return f=g({Type:"VariableExpr",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),r[f.Token.Source]!=null&&r[f.Token.Source]?.Tokens?.push!=null?(r[f.Token.Source].Tokens.push(f.Token),r[f.Token.Source].UseCountIncrease()):h[f.Token.Source]!=null&&h[f.Token.Source]?.Tokens?.push!=null&&(h[f.Token.Source].Tokens.push(f.Token),h[f.Token.Source].UseCountIncrease()),f}else throw ge(e()),`${l(T)}: Unexpected symbol. ${T.Type} ${T.Source}`}function S(r,h){let T=o("Symbol","{"),f=[],b=[];for(;i().Source!="}";){let E,B;if(i().Source=="["){let C=n(),M=a(r,h),P=o("Symbol","]"),x=o("Symbol","="),Z=a(r,h);E=M.Token&&M.Token.Source,B=Z,f.push({EntryType:"Index",Index:M,Value:Z,Token_OpenBracket:C,Token_CloseBracket:P,Token_Equals:x})}else if((i().Type=="Ident"||i().Type=="Keyword"&&me.includes(i().Source))&&i(1).Source=="="){let C=n(),M=n(),P=a(r,h);E=C,B=P,f.push({EntryType:"Field",Field:C,Value:P,Token_Equals:M})}else{let C=a(r,h);f.push({EntryType:"Value",Value:C})}if(i().Source==","||i().Source==";")b.push(n());else break}let _=o("Symbol","}"),y;return y=g({Type:"TableLiteral",EntryList:f,Token_SeperatorList:b,Token_OpenBrace:T,Token_CloseBrace:_,GetFirstToken:()=>y.Token_OpenBrace,GetLastToken:()=>y.Token_CloseBrace}),y}function w(r,h){let T=[],f=[];if(i().Type=="Ident"||i().Type=="Keyword"&&me.includes(i().Source)){let b=n();if(h&&i().Source=="<"&&i(2).Source==">"){let _=i(1).Source;b.Attribute={LeadingWhite:i().LeadingWhite,Source:`<${_}>`},n(),n(),n()}T.push(b)}else if(i().Source=="..."&&r)return[T,f,n()];for(;i().Source==",";){if(f.push(n()),i().Source=="..."&&r)return[T,f,n()];{let b=o("Ident");if(h&&i().Source=="<"&&i(2).Source==">"){let _=i(1).Source;b.Attribute={LeadingWhite:i().LeadingWhite,Source:`<${_}>`},n(),n(),n()}T.push(b)}}return[T,f]}function F(r,h,T){let f=L(h,T),b=i();if(b.Type=="Keyword"&&b.Source==r)return n(),[f,b];throw ge(b.Type,b.Source),`${l(b)}: ${r} expected.`}function $(r,h,T,f){let b=n(),_,y;if(!r){_=[],y=[];let I=o("Ident");for(_.push(I);i().Source==".";)y.push(n()),_.push(o("Ident"));i().Source==":"&&(y.push(n()),_.push(o("Ident")))}let E=o("Symbol","("),[B,C,M]=w(!0),P=o("Symbol",")"),[x,Z]=F("end",h,T),oe;return oe=g({Type:r==!0?"FunctionLiteral":"FunctionStat",NameChain:_,ArgList:B,Body:x,Token_Function:b,Token_NameChainSeperator:y,Token_OpenParen:E,Token_Varg:M,Token_ArgCommaList:C,Token_CloseParen:P,Token_End:Z,GetFirstToken:()=>oe.Token_Function,GetLastToken:()=>oe.Token_End}),oe}function G(r,h){let T=i();if(T.Source=="("){let f=n(),b=[],_=[];for(;i().Source!=")"&&(b.push(a(r,h)),i().Source==",");)_.push(n());let y=o("Symbol",")"),E;return E=g({CallType:"ArgCall",ArgList:b,Token_CommaList:_,Token_OpenParen:f,Token_CloseParen:y,GetFirstToken:()=>E.Token_OpenParen,GetLastToken:()=>E.Token_CloseParen}),E}else if(T.Source=="{"){let f;return f=g({CallType:"TableCall",TableExpr:a(r,h),GetFirstToken:()=>f.TableExpr.GetFirstToken(),GetLastToken:()=>f.TableExpr.GetLastToken()}),f}else if(T.Type=="String"){let f;return f=g({CallType:"StringCall",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else throw"Function arguments expected."}function A(r,h){let T=m(r,h);for(J(T,"nil prefixexpr");;){let f=i();if(f.Source=="."){let b=n(),_=o("Ident"),y;y=g({Type:"FieldExpr",Base:T,Field:_,Token_Dot:b,GetFirstToken:()=>y.Base.GetFirstToken(),GetLastToken:()=>y.Field}),T=y}else if(f.Source==":"){let b=n(),_=o("Ident"),y=G(r,h),E;E=g({Type:"MethodExpr",Base:T,Method:_,FunctionArguments:y,Token_Colon:b,GetFirstToken:()=>E.Base.GetFirstToken(),GetLastToken:()=>E.FunctionArguments.GetLastToken()}),T=E}else if(f.Source=="["){let b=n(),_=a(r,h),y=o("Symbol","]"),E;E=g({Type:"IndexExpr",Base:T,Index:_,Token_OpenBracket:b,Token_CloseBracket:y,GetFirstToken:()=>E.Base.GetFirstToken(),GetLastToken:()=>E.Token_CloseBracket}),T=E}else if(f.Source=="{"||f.Source=="("||f.Type=="String"){let b;b=g({Type:"CallExpr",Base:T,FunctionArguments:G(r,h),GetFirstToken:()=>b.Base.GetFirstToken(),GetLastToken:()=>b.FunctionArguments.GetLastToken()}),T=b}else if(wn.includes(f.Source)){let b=n(),_=a(r,h),y;y=g({Type:"CompoundStat",Base:T,Token_Compound:b,Rhs:_,Lhs:T,GetFirstToken:()=>y.Base.GetFirstToken(),GetLastToken:()=>y.Rhs.GetLastToken()}),T=y}else return T}}function R(r,h){let T=i();if(T.Type=="Number"){let f;return f=g({Type:"NumberLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Type=="String"){let f;return f=g({Type:"StringLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Type=="Hash"){let f;return f=g({Type:"HashLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Source=="nil"){let f;return f=g({Type:"NilLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Source=="true"||T.Source=="false"){let f;return f=g({Type:"BooleanLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Source=="..."){let f;return f=g({Type:"VargLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else return T.Source=="{"?S(r,h):T.Source=="function"?$(!0,r,h):T.Source=="if"?j(!0,r,h):A(r,h)}function N(r,h,T){let f;if(c()){let b=n(),_=N(Bn,h,T),y;y=g({Type:"UnopExpr",Token_Op:b,Rhs:_,GetFirstToken:()=>y.Token_Op,GetLastToken:()=>y.Rhs.GetLastToken()}),f=y}else f=R(h,T),J(f,"nil sipleexpr");for(;s()&&Me[i().Source]!=null&&Me[i().Source][0]>r;){let b=n(),_=N(Me[b.Source][1],h,T);J(_,"RhsNeeded");let y;y=g({Type:"BinopExpr",Lhs:f,Rhs:_,Token_Op:b,GetFirstToken:()=>y.Lhs.GetFirstToken(),GetLastToken:()=>y.Rhs.GetLastToken()}),f=y}return f}a=(r,h)=>N(0,r,h);function V(r,h){let T=A(r,h);if(T.Type=="MethodExpr"||T.Type=="CallExpr"){let f;return f=g({Type:"CallExprStat",Expression:T,GetFirstToken:()=>f.Expression.GetFirstToken(),GetLastToken:()=>f.Expression.GetLastToken()}),f}else{if(T.Type=="CompoundStat")return T;{let f=[T],b=[];for(T.IsStat=!0;i().Source==",";){b.push(n());let C=A(r,h);if(C.Type=="MethodExpr"||C.Type=="CallExpr")throw"Bad left hand side of asignment";C.IsStat=!0,f.push(C)}let _=o("Symbol","="),y=[a(r,h)],E=[];for(;i().Source==",";)E.push(n()),y.push(a(r,h));let B;return B=g({Type:"AssignmentStat",Rhs:y,Lhs:f,Token_Equals:_,Token_LhsSeperatorList:b,Token_RhsSeperatorList:E,GetFirstToken:()=>B.Lhs[0].GetFirstToken(),GetLastToken:()=>B.Rhs[B.Rhs.length-1].GetLastToken()}),B}}}function j(r,h,T){let f=n(),b=a(h,T),_=o("Keyword","then"),y=r?a(h,T):L(h,T),E=[];for(;i().Source=="elseif"||i().Source=="else";){let M=n(),P,x;M.Source=="elseif"&&(P=a(h,T),x=o("Keyword","then"));let Z=r?a(h,T):L(h,T);if(E.push({Condition:P,Body:Z,ClauseType:M.Source,Token:M,Token_Then:x}),M.Source=="else")break}let B=r?null:o("Keyword","end"),C;return C=g({Type:r?"IfExpr":"IfStat",Condition:b,Body:y,ElseClauseList:E,Token_If:f,Token_Then:_,Token_End:B,GetFirstToken:()=>C.Token_If,GetLastToken:()=>C.Token_End}),C}function O(r,h){let T=n(),[f,b]=F("end",r,h),_;return _=g({Type:"DoStat",Body:f,Token_Do:T,Token_End:b,GetFirstToken:()=>_.Token_Do,GetLastToken:()=>_.Token_End}),_}function X(r,h){let T=n(),f=a(r,h),b=o("Keyword","do"),[_,y]=F("end",r,h),E;return E=g({Type:"WhileStat",Condition:f,Body:_,Token_While:T,Token_Do:b,Token_End:y,GetFirstToken:()=>E.Token_While,GetLastToken:()=>E.Token_End}),E}function Y(r,h){let T=n(),[f,b]=w(),_=[];if(i().Source=="="){let y=n(),[E,B]=p(r,h);if(E.length<2||E.length>3)throw"Expected 2 or 3 values for range bounds";let C=o("Keyword","do"),[M,P]=F("end",r,h),x;return x=g({Type:"NumericForStat",VarList:f,RangeList:E,Body:M,Token_For:T,Token_VarCommaList:b,Token_Equals:y,Token_RangeCommaList:B,Token_Do:C,Token_End:P,GetFirstToken:()=>x.Token_For,GetLastToken:()=>x.Token_End}),x}else if(i().Source=="in"){let y=n(),[E,B]=p(r,h),C=o("Keyword","do"),[M,P]=F("end",r,h),x;return x=g({Type:"GenericForStat",VarList:f,GeneratorList:E,Body:M,Token_For:T,Token_VarCommaList:b,Token_In:y,Token_GeneratorCommaList:B,Token_Do:C,Token_End:P,GetFirstToken:()=>x.Token_For,GetLastToken:()=>x.Token_End}),x}}function ee(r,h){let T=n(),[f,b]=F("until",r),_=a(r,h),y;return y=g({Type:"RepeatStat",Body:f,Condition:_,Token_Repeat:T,Token_Until:b,GetFirstToken:()=>y.Token_Repeat,GetLastToken:()=>y.Condition.GetLastToken()}),y}function te(r,h){let T=n();if(i().Source=="function"){let f=$(!1,r,h,!0);if(f.NameChain.length>1)throw l(f.Token_NameChainSeperator[0])+": `(` expected.";let b;return b=g({Type:"LocalFunctionStat",FunctionStat:f,Token_Local:T,GetFirstToken:()=>b.Token_Local,GetLastToken:()=>b.FunctionStat.GetLastToken()}),b}else if(i().Type=="Ident"||i().Type=="Keyword"&&me.includes(i().Source)){let[f,b]=w(!1,!0),_=[],y=[],E;if(i().Source=="="){E=n();let[C,M]=p(r,h);_=C,y=M}let B;return B=g({Type:"LocalVarStat",VarList:f,ExprList:_,Token_Local:T,Token_Equals:E,Token_VarCommaList:b,Token_ExprCommaList:y,GetFirstToken:()=>B.Token_Local,GetLastToken:function(){return B.ExprList.length>0?B.ExprList[B.ExprList.length-1].GetLastToken():B.VarList[B.VarList.length-1]}}),B}else throw"`function` or ident expected"}function z(r,h){let T=n(),f,b;t()||i().Source==";"?(f=[],b=[]):[f,b]=p(r,h);let _;return _={Type:"ReturnStat",ExprList:f,Token_Return:T,Token_CommaList:b,GetFirstToken:()=>_.Token_Return,GetLastToken:function(){return _.ExprList.length>0?_.ExprList[_.ExprList.length-1].GetLastToken():_.Token_Return}},_}function ce(){let r=n(),h;return h={Type:"BreakStat",Token_Break:r,GetFirstToken:()=>h.Token_Break,GetLastToken:()=>h.Token_Break},h}function _e(r,h){if(i(1).Source=="(")return[!1,V(r,h)];let T=n(),f;return f={Type:"ContinueStat",Token_Continue:T,GetFirstToken:()=>f.Token_Continue,GetLastToken:()=>f.Token_Continue},[!0,f]}function H(){let r=n(),h;i().Type=="Keyword"?h=o("Keyword"):h=o("Ident");let T;return T={Type:"GotoStat",Token_Goto:r,Token_Label:h,GetFirstToken:()=>T.Token_Goto,GetLastToken:()=>T.Token_Label},T}function Re(){let r=n(),h;i().Type=="Keyword"?h=o("Keyword"):h=o("Ident");let T=o("Symbol","::"),f;return f={Type:"LabelStat",Token_ColonsLeft:r,Token_Label:h,Token_ColonsRight:T,GetFirstToken:()=>f.Token_ColonsLeft,GetLastToken:()=>f.Token_ColonsRight},f}function Ee(r,h){let T=i();return T.Source=="if"?[!1,j(!1,r,h)]:T.Source=="while"?[!1,X(r,h)]:T.Source=="do"?[!1,O(r,h)]:T.Source=="for"?[!1,Y(r,h)]:T.Source=="repeat"?[!1,ee(r,h)]:T.Source=="function"?[!1,$(!1,r,h)]:T.Source=="local"?[!1,te(r,h)]:T.Source=="return"?[!0,z(r,h)]:T.Source=="break"?[!0,ce(r,h)]:T.Source=="continue"?_e(r,h):T.Source=="goto"?[!1,H()]:T.Source=="::"?[!1,Re()]:[!1,V(r,h)]}let Te=1;return L=function(r,h){let T=[],f=[],b=!1,_={},y={};if(h!=null)for(let[P,x]of Object.entries(h))y[P]=x;if(r!=null)for(let[P,x]of Object.entries(r))y[P]=x;let E,B=0;for(;!b&&!t();){E&&E==i()&&ge(`INFINITE LOOP POSSIBLE ON STATEMENT ${E.Source} :`,E),E=i();let[P,x]=Ee(_,y);if(x)switch(T.push(x),x.Type){case"LocalVarStat":x.VarList.forEach(I=>{I.UseCount=0,I.Number=B++,_[I.Source]=I;let ie=[];function U(){I.UseCount++,ie.forEach(q=>{q.UseCount=I.UseCount})}I.Tokens={},I.Tokens.push=q=>{q.UseCountIncrease=U,q.UseCount=I.UseCount,q.Tokens=I.Tokens,ie.push(q)},I.Tokens.get=()=>ie,I.UseCountIncrease=U});break;case"LocalFunctionStat":let oe=x.FunctionStat.NameChain;if(oe.length===1){let U=function(){I.UseCount++,ie.forEach(q=>{q.UseCount=I.UseCount})};var M=U;let I=oe[0];I.UseCount=0,I.Number=B++,_[I.Source]=I;let ie=[];I.Tokens={},I.Tokens.push=q=>{q.UseCountIncrease=U,q.UseCount=I.UseCount,q.Tokens=I.Tokens,ie.push(q)},I.Tokens.get=()=>ie,I.UseCountIncrease=U}break;default:break}let Z=i();Z.Type=="Symbol"&&Z.Source==";"&&(f[T.length-1]=n())}let C;return C={Type:"StatList",StatementList:T,SemicolonList:f,GetFirstToken:function(){if(C.StatementList.length!=0)return C.StatementList[0]?.GetFirstToken()},GetLastToken:function(){if(C.StatementList.length!=0)return C.SemicolonList[C.StatementList.length-1]?C.SemicolonList[C.StatementList.length-1]:C.StatementList[C.StatementList.length-1].GetLastToken()}},C},L([],[])}function ke(k,u){let d={BinopExpr:!0,UnopExpr:!0,NumberLiteral:!0,StringLiteral:!0,NilLiteral:!0,BooleanLiteral:!0,VargLiteral:!0,HashLiteral:!0,FieldExpr:!0,IndexExpr:!0,MethodExpr:!0,CallExpr:!0,FunctionLiteral:!0,VariableExpr:!0,ParenExpr:!0,TableLiteral:!0},n={StatList:!0,BreakStat:!0,ContinueStat:!0,LabelStat:!0,GotoStat:!0,ReturnStat:!0,LocalVarStat:!0,LocalFunctionStat:!0,FunctionStat:!0,RepeatStat:!0,GenericForStat:!0,NumericForStat:!0,WhileStat:!0,DoStat:!0,IfStat:!0,CallExprStat:!0,AssignmentStat:!0,CompoundStat:!0};for(var[i,l]of Object.entries(u))if(!(i==="VisitStat"||i==="VisitExpr")&&!n[i]&&!d[i])throw`Invalid visitor target: \`${i}\``;function e(o){if(o!=null){let g=u[o.Type];if(typeof g=="function")return g(o);if(g&&g.Pre)return g.Pre(o)}}function t(o){let g=u[o.Type];if(g&&typeof g=="object"&&g.Post)return g.Post(o)}let c,s;c=function(o){if(!e(o)){if(o.Type=="BinopExpr")c(o.Lhs),c(o.Rhs);else if(o.Type=="UnopExpr")c(o.Rhs);else if(!(o.Type=="NumberLiteral"||o.Type=="StringLiteral"||o.Type=="NilLiteral"||o.Type=="BooleanLiteral"||o.Type=="VargLiteral"||o.Type=="HashLiteral")){if(o.Type=="FieldExpr")c(o.Base);else if(o.Type=="IndexExpr")c(o.Base),c(o.Index);else if(o.Type=="MethodExpr"||o.Type=="CallExpr")c(o.Base),o.FunctionArguments.CallType=="ArgCall"?o.FunctionArguments.ArgList.forEach((g,L)=>{c(g)}):o.FunctionArguments.CallType=="TableCall"&&c(o.FunctionArguments.TableExpr);else if(o.Type=="FunctionLiteral")s(o.Body);else if(o.Type!="VariableExpr")if(o.Type=="ParenExpr")c(o.Expression);else if(o.Type=="TableLiteral")o.EntryList.forEach((g,L)=>{if(g.EntryType=="Field")c(g.Value);else if(g.EntryType=="Index")c(g.Index),c(g.Value);else if(g.EntryType=="Value")c(g.Value);else throw"unreachable"});else if(o.Type=="CompoundStat")c(o.Lhs),c(o.Rhs);else if(o.Type=="IfExpr")c(o.Condition),c(o.Body),o.ElseClauseList.forEach(g=>{g.Condition!=null&&c(g.Condition),c(g.Body)});else throw`unreachable, type: ${o.Type}: ${o}`}t(o)}},s=function(o){if(!e(o)){if(o.Type=="StatList")o.StatementList.forEach((g,L)=>{if(g!=null){if(g===null||g.Type===null)return;g.Remove=()=>{o.StatementList[L]=null},s(g)}});else if(o.Type!="BreakStat"){if(o.Type!="ContinueStat"){if(o.Type!="GotoStat"){if(o.Type!="LabelStat")if(o.Type=="ReturnStat")o.ExprList.forEach((g,L)=>{c(g)});else if(o.Type=="LocalVarStat")o.Token_Equals&&o.ExprList.forEach((g,L)=>{c(g)});else if(o.Type=="LocalFunctionStat")s(o.FunctionStat.Body);else if(o.Type=="FunctionStat")s(o.Body);else if(o.Type=="RepeatStat")s(o.Body),c(o.Condition);else if(o.Type=="GenericForStat")o.GeneratorList.forEach((g,L)=>{c(g)}),s(o.Body);else if(o.Type=="NumericForStat")o.RangeList.forEach((g,L)=>{c(g)}),s(o.Body);else if(o.Type=="WhileStat")c(o.Condition),s(o.Body);else if(o.Type=="DoStat")s(o.Body);else if(o.Type=="IfStat")c(o.Condition),s(o.Body),o.ElseClauseList.forEach(g=>{g.Condition!=null&&c(g.Condition),s(g.Body)});else if(o.Type=="CallExprStat")c(o.Expression);else if(o.Type=="CompoundStat")c(o.Lhs),c(o.Rhs);else if(o.Type=="AssignmentStat")o.Lhs.forEach(g=>{c(g)}),o.Rhs.forEach(g=>{c(g)});else throw"Unreachable code. Got "+o.Type}}}t(o)}},u.VisitStat=s,u.VisitExpr=c,n[k.Type]?s(k):c(k)}function Rn(k){let u=[],d,n=0;function i(){return n++,n}function l(){d={ParentScope:d,ChildScopeList:[],VariableList:[],BeginLocation:i(),Depth:null,GetVar:null},d.ParentScope?(d.Depth=d.ParentScope.Depth+1,d.ParentScope.ChildScopeList.push(d)):d.Depth=1;let a=d;d.GetVar=function(p){for(let m of a.VariableList)if(m.Name==p)return m;if(a.ParentScope)return a.ParentScope.GetVar(p);for(let m of u)if(m.Name==p)return m}}function e(){let a=d;return a.EndLocation=i(),a.VariableList.forEach(p=>{p.ScopeEndLocation=a.EndLocation}),d=a.ParentScope,a}l();function t(a,p,m){J(m,"Missing localInfo"),J(a,"Missing local var name");let S={Type:"Local",Name:a,RenameList:[p],AssignedTo:!1,Info:m,Scope:d,BeginLocation:i(),EndLocation:i(),ReferenceLocationList:[i()]};return S.Rename=function(w){S.Name=w,S.RenameList.forEach(F=>{F(w)})},d.VariableList.push(S),S}function c(a){for(let m of u)if(m.Name==a)return m;let p={Type:"Global",Name:a,RenameList:[],AssignedTo:!1,Scope:null,BeginLocation:i(),EndLocation:i(),ReferenceLocationList:[]};return p.Rename=function(m){p.Name=m,p.RenameList.forEach(S=>{S(m)})},u.push(p),p}function s(a,p){J(a,"Missing var name");let m=c(a);return m.RenameList.push(p),m}function o(a,p){let m;for(m=a.VariableList.length-1;m>=0;m--)if(a.VariableList[m].Name==p)return a.VariableList[m];if(a.ParentScope){let S=o(a.ParentScope,p);if(S)return S}}function g(a,p){J(a,"Missing var name");let m=o(d,a);m?m.RenameList.push(p):m=s(a,p);let S=i();return m.EndLocation=S,m.ReferenceLocationList.push(m.EndLocation),m}let L={};return L.FunctionLiteral={Pre:function(a){l(),a.ArgList.forEach((p,m)=>{let S=t(p.Source,function(w,F){F||(p.Source=w)},{Type:"Argument",Index:m});p.var=S})},Post:function(a){e()}},L.VariableExpr=function(a){a.Variable=g(a.Token.Source,function(p,m=!1){m&&a.IsStat||(a.Token.Source=p)})},L.StatList={Pre:function(a){l()},Post:function(a){a.SkipPop||e()}},L.LocalVarStat={Post:function(a){a.VarList.forEach((p,m)=>{t(p.Source,function(S){a.VarList[m].Source=S},{Type:"Local",Expr:a.ExprList})})}},L.LocalFunctionStat={Pre:function(a){t(a.FunctionStat.NameChain[0].Source,function(p){a.FunctionStat.NameChain[0].Source=p},{Type:"LocalFunction"}),l(),a.FunctionStat.ArgList.forEach((p,m)=>{t(p.Source,function(S){p.Source=S},{Type:"Argument",Index:m})})},Post:function(){e()}},L.FunctionStat={Pre:function(a){let p=a.NameChain,m;p.length==1?o(d,p[0].Source)?m=g(p[0].Source,function(S){p[0].Source=S}):m=s(p[0].Source,function(S){p[0].Source=S}):m=g(p[0].Source,function(S){p[0].Source=S}),m.AssignedTo=!0,l(),a.ArgList.forEach((S,w)=>{t(S.Source,function(F){S.Source=F},{Type:"Argument",Index:w})})},Post:function(){e()}},L.GenericForStat={Pre:function(a){return a.GeneratorList.forEach(p=>{ke(p,L)}),l(),a.VarList.forEach((p,m)=>{t(p.Source,function(S){p.Source=S},{Type:"ForRange",Index:m})}),ke(a.Body,L),e(),!0}},L.NumericForStat={Pre:function(a){return a.RangeList.forEach(p=>{ke(p,L)}),l(),a.VarList.forEach((p,m)=>{t(p.Source,function(S){p.Source=S},{Type:"ForRange",Index:m})}),ke(a.Body,L),e(),!0}},L.RepeatStat={Pre:function(a){a.Body.SkipPop=!0},Post:function(a){e()}},L.AssignmentStat={Post:function(a){a.Lhs.forEach(p=>{p.Variable!=null&&(p.Variable.AssignedTo=!0)})}},ke(k,L),[u,e()]}function An(k){let u,d,n="",i=e=>typeof e?.LeadingWhite!="string"?" ":e.LeadingWhite;function l(e){if(e.LeadingWhite==null||e.Source==null)throw`Bad token: tk=${e} | lwhite=${e.LeadingWhite} | source=${e.Source}`;n=`${n}${e.LeadingWhite}${e.Source}`}return d=function(e){if(e.Type=="BinopExpr")d(e.Lhs),l(e.Token_Op),d(e.Rhs);else if(e.Type=="UnopExpr")l(e.Token_Op),d(e.Rhs);else if(e.Type=="NumberLiteral"||e.Type=="StringLiteral"||e.Type=="NilLiteral"||e.Type=="BooleanLiteral"||e.Type=="VargLiteral"||e.Type=="HashLiteral")l(e.Token);else if(e.Type=="FieldExpr")d(e.Base),l(e.Token_Dot),l(e.Field);else if(e.Type=="IndexExpr")d(e.Base),l(e.Token_OpenBracket),d(e.Index),l(e.Token_CloseBracket);else if(e.Type=="MethodExpr"||e.Type=="CallExpr")d(e.Base),e.Type=="MethodExpr"&&(l(e.Token_Colon),l(e.Method)),e.FunctionArguments.CallType=="StringCall"?l(e.FunctionArguments.Token):e.FunctionArguments.CallType=="ArgCall"?(l(e.FunctionArguments.Token_OpenParen),e.FunctionArguments.ArgList.forEach((t,c)=>{d(t);let s=e.FunctionArguments.Token_CommaList[c];s!=null&&l(s)}),l(e.FunctionArguments.Token_CloseParen)):e.FunctionArguments.CallType=="TableCall"&&d(e.FunctionArguments.TableExpr);else if(e.Type=="FunctionLiteral")l(e.Token_Function),l(e.Token_OpenParen),e.ArgList.forEach((t,c)=>{l(t);let s=e.Token_ArgCommaList[c];s!=null&&l(s)}),e.Token_Varg!=null&&l(e.Token_Varg),l(e.Token_CloseParen),u(e.Body),l(e.Token_End);else if(e.Type=="VariableExpr")l(e.Token);else if(e.Type=="ParenExpr")l(e.Token_OpenParen),d(e.Expression),l(e.Token_CloseParen);else if(e.Type=="TableLiteral")l(e.Token_OpenBrace),e.EntryList.forEach((t,c)=>{if(t.EntryType=="Field")l(t.Field),l(t.Token_Equals),d(t.Value);else if(t.EntryType=="Index")l(t.Token_OpenBracket),d(t.Index),l(t.Token_CloseBracket),l(t.Token_Equals),d(t.Value);else if(t.EntryType=="Value")d(t.Value);else throw"unreachable";let s=e.Token_SeperatorList[c];s!=null&&l(s)}),l(e.Token_CloseBrace);else if(e.Type=="CompoundStat")u(e);else if(e.Type=="IfExpr")l(e.Token_If),d(e.Condition),l(e.Token_Then),d(e.Body),e.ElseClauseList.forEach(t=>{l(t.Token),t.Condition!=null&&(d(t.Condition),l(t.Token_Then)),d(t.Body)});else throw`unreachable, type: ${e.Type}: ${e}`},u=function(e){if(e==null)throw`STAT IS NIL! ${e}`;if(!(e.Type==="StatList"&&e.StatementList.length===0)){if(e.WrapInDo){let t=i(e.GetFirstToken());e.GetFirstToken().LeadingWhite="",n+=`${t}do `}e.Type=="StatList"?e.StatementList.forEach((t,c)=>{t===null||t.Type===null||(t.Remove=()=>{e.StatementList[c]=null},u(t),e.SemicolonList[c]&&l(e.SemicolonList[c]))}):e.Type=="BreakStat"?l(e.Token_Break):e.Type=="ContinueStat"?l(e.Token_Continue):e.Type=="GotoStat"?(l(e.Token_Goto),l(e.Token_Label)):e.Type=="LabelStat"?(l(e.Token_ColonsLeft),l(e.Token_Label),l(e.Token_ColonsRight)):e.Type=="ReturnStat"?(l(e.Token_Return),e.ExprList.forEach((t,c)=>{d(t),e.Token_CommaList[c]&&l(e.Token_CommaList[c])})):e.Type=="LocalVarStat"?(l(e.Token_Local),e.VarList.forEach((t,c)=>{l(t),t.Attribute!=null&&l(t.Attribute);let s=e.Token_VarCommaList[c];s!=null&&l(s)}),e.Token_Equals!=null&&(l(e.Token_Equals),e.ExprList.forEach((t,c)=>{d(t);let s=e.Token_ExprCommaList[c];s!=null&&l(s)}))):e.Type=="LocalFunctionStat"?(l(e.Token_Local),l(e.FunctionStat.Token_Function),l(e.FunctionStat.NameChain[0]),l(e.FunctionStat.Token_OpenParen),e.FunctionStat.ArgList.forEach((t,c)=>{l(t);let s=e.FunctionStat.Token_ArgCommaList[c];s!=null&&l(s)}),e.FunctionStat.Token_Varg&&l(e.FunctionStat.Token_Varg),l(e.FunctionStat.Token_CloseParen),u(e.FunctionStat.Body),l(e.FunctionStat.Token_End)):e.Type=="FunctionStat"?(l(e.Token_Function),e.NameChain.forEach((t,c)=>{l(t);let s=e.Token_NameChainSeperator[c];s!=null&&l(s)}),l(e.Token_OpenParen),e.ArgList.forEach((t,c)=>{l(t);let s=e.Token_ArgCommaList[c];s!=null&&l(s)}),e.Token_Varg&&l(e.Token_Varg),l(e.Token_CloseParen),u(e.Body),l(e.Token_End)):e.Type=="RepeatStat"?(l(e.Token_Repeat),u(e.Body),l(e.Token_Until),d(e.Condition)):e.Type=="GenericForStat"?(l(e.Token_For),e.VarList.forEach((t,c)=>{l(t);let s=e.Token_VarCommaList[c];s!=null&&l(s)}),l(e.Token_In),e.GeneratorList.forEach((t,c)=>{d(t);let s=e.Token_GeneratorCommaList[c];s!=null&&l(s)}),l(e.Token_Do),u(e.Body),l(e.Token_End)):e.Type=="NumericForStat"?(l(e.Token_For),e.VarList.forEach((t,c)=>{l(t);let s=e.Token_VarCommaList[c];s!=null&&l(s)}),l(e.Token_Equals),e.RangeList.forEach((t,c)=>{d(t);let s=e.Token_RangeCommaList[c];s!=null&&l(s)}),l(e.Token_Do),u(e.Body),l(e.Token_End)):e.Type=="WhileStat"?(l(e.Token_While),d(e.Condition),l(e.Token_Do),u(e.Body),l(e.Token_End)):e.Type=="DoStat"?(l(e.Token_Do),u(e.Body),l(e.Token_End)):e.Type=="IfStat"?(l(e.Token_If),d(e.Condition),l(e.Token_Then),u(e.Body),e.ElseClauseList.forEach(t=>{l(t.Token),t.Condition!=null&&(d(t.Condition),l(t.Token_Then)),u(t.Body)}),l(e.Token_End)):e.Type=="CallExprStat"?d(e.Expression):e.Type=="CompoundStat"?(d(e.Lhs),l(e.Token_Compound),d(e.Rhs),e.Type="CompoundStat"):e.Type=="AssignmentStat"?(e.Lhs.forEach((t,c)=>{d(t);let s=e.Token_LhsSeperatorList[c];s!=null&&l(s)}),l(e.Token_Equals),e.Rhs.forEach((t,c)=>{d(t);let s=e.Token_RhsSeperatorList[c];s!=null&&l(s)})):J(!1,"unreachable"),e.WrapInDo&&(n+=" end ")}},u(k),n}function In(k){let u,d;function n(e){e&&(e.LeadingWhite="")}function i(e,t,c=!1){n(t);let s=(typeof e.Source=="string"?e.Source:e.Source.toString()).substr(e.Source.length-1,1),o=(typeof t.Source=="string"?t.Source:t.Source.toString()).substr(0,1);s=="-"&&o=="-"||Pe.includes(s)&&Pe.includes(o)||c&&s==")"&&o=="("?t.LeadingWhite=c?";":" ":t.LeadingWhite=""}function l(e,t,c){u(t),n(c);let s=t.GetFirstToken(),o=t.GetLastToken();s!=null?(i(e,s),i(o,c)):i(e,c)}d=function(e){if(e.Type==="BinopExpr")d(e.Lhs),d(e.Rhs),e.Lhs.Type=="NumberLiteral"&&e.Token_Op.Source==".."?e.Token_Op.LeadingWhite=" ":(n(e.Token_Op),i(e.Lhs.GetLastToken(),e.Token_Op)),i(e.Token_Op,e.Rhs.GetFirstToken());else if(e.Type==="UnopExpr")n(e.Token_Op),d(e.Rhs),i(e.Token_Op,e.Rhs.GetFirstToken());else if(e.Type==="NumberLiteral"||e.Type==="StringLiteral"||e.Type==="NilLiteral"||e.Type==="BooleanLiteral"||e.Type==="VargLiteral"||e.Type==="HashLiteral")n(e.Token);else if(e.Type=="FieldExpr")d(e.Base),n(e.Token_Dot),n(e.Field);else if(e.Type=="IndexExpr")d(e.Base),n(e.Token_OpenBracket),d(e.Index),n(e.Token_CloseBracket);else if(e.Type=="MethodExpr"||e.Type=="CallExpr")d(e.Base),e.Type=="MethodExpr"&&(n(e.Token_Colon),n(e.Method)),e.FunctionArguments.CallType=="StringCall"?n(e.FunctionArguments.Token):e.FunctionArguments.CallType=="ArgCall"?(n(e.FunctionArguments.Token_OpenParen),e.FunctionArguments.ArgList.forEach((t,c)=>{d(t);let s=e.FunctionArguments.Token_CommaList[c];s!=null&&n(s)}),n(e.FunctionArguments.Token_CloseParen)):e.FunctionArguments.CallType=="TableCall"&&d(e.FunctionArguments.TableExpr);else if(e.Type=="FunctionLiteral")n(e.Token_Function),n(e.Token_OpenParen),e.ArgList.forEach((t,c)=>{n(t);let s=e.Token_ArgCommaList[c];s!=null&&n(s)}),e.Token_Varg!=null&&n(e.Token_Varg),n(e.Token_CloseParen),l(e.Token_CloseParen,e.Body,e.Token_End);else if(e.Type=="VariableExpr")n(e.Token);else if(e.Type=="ParenExpr")n(e.Token_OpenParen),d(e.Expression),n(e.Token_CloseParen);else if(e.Type=="IfExpr"){n(e.Token_If),d(e.Condition),i(e.Token_If,e.Condition.GetFirstToken()),i(e.Condition.GetLastToken(),e.Token_Then);let t=e.Token_Then,c=e.Body;e.ElseClauseList.forEach((s,o)=>{i(t,c.GetFirstToken()),i(c.GetLastToken(),s.Token),t=s.Token,s.Condition!=null&&(d(s.Condition),i(s.Token,s.Condition.GetFirstToken()),i(s.Condition.GetLastToken(),s.Token_Then),t=s.Token_Then),d(s.Body),c=s.Body}),i(t,c.GetFirstToken())}else if(e.Type=="TableLiteral")n(e.Token_OpenBrace),e.EntryList.forEach((t,c)=>{t.EntryType=="Field"?(n(t.Field),n(t.Token_Equals),d(t.Value)):t.EntryType=="Index"?(n(t.Token_OpenBracket),d(t.Index),n(t.Token_CloseBracket),n(t.Token_Equals),d(t.Value)):t.EntryType=="Value"?d(t.Value):J(!1,"unreachable");let s=e.Token_SeperatorList[c];s!=null&&n(s)}),e.Token_SeperatorList[e.EntryList.length-1]=null,n(e.Token_CloseBrace);else throw`unreachable, type: ${e.Type}:${e} ${console.trace()}`},u=function(e){if(e.Type=="StatList"){let t;for(t=0;t<=e.StatementList.length;t++){let c=e.StatementList[t];if(c==null)continue;u(c),n(c.GetFirstToken());let s=e.StatementList[t-1];if(s!=null){let o={")":["(","["],"]":["(","["]};if(e.SemicolonList[t-1]){let g=s.GetLastToken().Source,L=c.GetFirstToken().Source;(o[g]===null||o[g]===void 0||!o[g].includes(L))&&(e.SemicolonList[t-1]=null)}e.SemicolonList[t-1]||i(s.GetLastToken(),c.GetFirstToken(),!0)}}e.SemicolonList[e.StatementList.length-1]=null,e.StatementList.length>0&&n(e.StatementList[0].GetFirstToken())}else if(e.Type=="BreakStat")n(e.Token_Break);else if(e.Type=="ContinueStat")n(e.Token_Continue);else if(e.Type=="GotoStat")n(e.Token_Goto),i(e.Token_Goto,e.Token_Label);else if(e.Type=="LabelStat")n(e.Token_ColonsLeft),n(e.Token_Label),n(e.Token_ColonsRight);else if(e.Type=="ReturnStat")n(e.Token_Return),e.ExprList.forEach((t,c)=>{d(t),e.Token_CommaList[c]!=null&&n(e.Token_CommaList[c])}),e.ExprList.length>0&&i(e.Token_Return,e.ExprList[0].GetFirstToken());else if(e.Type=="LocalVarStat"){n(e.Token_Local);let t=!1;e.VarList.forEach((c,s)=>{s==0?i(e.Token_Local,c):n(c),c.Attribute&&(n(c.Attribute),s+1==e.VarList.length&&(t=!0));let o=e.Token_VarCommaList[s];o!=null&&n(o)}),e.Token_Equals!=null&&(t||n(e.Token_Equals),e.ExprList.forEach((c,s)=>{d(c);let o=e.Token_ExprCommaList[s];o!=null&&n(o)}))}else if(e.Type=="LocalFunctionStat")n(e.Token_Local),i(e.Token_Local,e.FunctionStat.Token_Function),i(e.FunctionStat.Token_Function,e.FunctionStat.NameChain[0]),i(e.FunctionStat.NameChain[0],e.FunctionStat.Token_OpenParen),e.FunctionStat.ArgList.forEach((t,c)=>{n(t);let s=e.FunctionStat.Token_ArgCommaList[c];s!=null&&n(s)}),e.FunctionStat.Token_Varg&&n(e.FunctionStat.Token_Varg),n(e.FunctionStat.Token_CloseParen),l(e.FunctionStat.Token_CloseParen,e.FunctionStat.Body,e.FunctionStat.Token_End);else if(e.Type=="FunctionStat")n(e.Token_Function),e.NameChain.forEach((t,c)=>{c==0?i(e.Token_Function,t):n(t);let s=e.Token_NameChainSeperator[c];s!=null&&n(s)}),n(e.Token_OpenParen),e.ArgList.forEach((t,c)=>{n(t);let s=e.Token_ArgCommaList[c];s!=null&&n(s)}),e.Token_Varg&&n(e.Token_Varg),n(e.Token_CloseParen),l(e.Token_CloseParen,e.Body,e.Token_End);else if(e.Type=="RepeatStat")n(e.Token_Repeat),l(e.Token_Repeat,e.Body,e.Token_Until),d(e.Condition),i(e.Token_Until,e.Condition.GetFirstToken());else if(e.Type=="GenericForStat")n(e.Token_For),e.VarList.forEach((t,c)=>{c==0?i(e.Token_For,t):n(t);let s=e.Token_VarCommaList[c];s!=null&&n(s)}),i(e.VarList[e.VarList.length-1],e.Token_In),e.GeneratorList.forEach((t,c)=>{d(t),c==0&&i(e.Token_In,t.GetFirstToken());let s=e.Token_GeneratorCommaList[c];s!=null&&n(s)}),i(e.GeneratorList[e.GeneratorList.length-1].GetLastToken(),e.Token_Do),l(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="NumericForStat")n(e.Token_For),e.VarList.forEach((t,c)=>{c==0?i(e.Token_For,t):n(t);let s=e.Token_VarCommaList[c];s!=null&&n(s)}),i(e.VarList[e.VarList.length-1],e.Token_Equals),e.RangeList.forEach((t,c)=>{d(t),c==0&&i(e.Token_Equals,t.GetFirstToken());let s=e.Token_RangeCommaList[c];s!=null&&n(s)}),i(e.RangeList[e.RangeList.length-1].GetLastToken(),e.Token_Do),l(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="WhileStat")n(e.Token_While),d(e.Condition),n(e.Token_Do),i(e.Token_While,e.Condition.GetFirstToken()),i(e.Condition.GetLastToken(),e.Token_Do),l(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="DoStat")n(e.Token_Do),n(e.Token_End),l(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="IfStat"){n(e.Token_If),d(e.Condition),i(e.Token_If,e.Condition.GetFirstToken()),i(e.Condition.GetLastToken(),e.Token_Then);let t=e.Token_Then,c=e.Body;e.ElseClauseList.forEach((s,o)=>{l(t,c,s.Token),t=s.Token,s.Condition!=null&&(d(s.Condition),i(s.Token,s.Condition.GetFirstToken()),i(s.Condition.GetLastToken(),s.Token_Then),t=s.Token_Then),u(s.Body),c=s.Body}),l(t,c,e.Token_End)}else if(e.Type=="CallExprStat")d(e.Expression);else if(e.Type=="CompoundStat")d(e.Lhs),n(e.Token_Compound),d(e.Rhs),i(e.Lhs.GetLastToken(),e.Token_Compound),i(e.Token_Compound,e.Rhs.GetFirstToken());else if(e.Type=="AssignmentStat")e.Lhs.forEach((t,c)=>{d(t);let s=e.Token_LhsSeperatorList[c];s!=null&&n(s)}),n(e.Token_Equals),e.Rhs.forEach((t,c)=>{d(t);let s=e.Token_RhsSeperatorList[c];s!=null&&n(s)});else return d(e)},u(k)}var se=[],v;for(v=97;v<=122;v++)se.push(String.fromCharCode(v));for(v=65;v<=90;v++)se.push(String.fromCharCode(v));for(v=48;v<=57;v++)se.push(String.fromCharCode(v));se.push("_");var Le=[];for(v=97;v<=122;v++)Le.push(String.fromCharCode(v));for(v=65;v<=90;v++)Le.push(String.fromCharCode(v));function Ke(k){let u="",d=k%Le.length;for(k=(k-d)/Le.length,u=`${u}${Le[d]}`;k>0;){let n=k%se.length;k=(k-n)/se.length,u=`${u}${se[n]}`}return u}function Mn(k,u,d){let n=[];for(var[i,l]of Object.entries(ze))n[i]=!0;let e=[],t=[];k.forEach(L=>{L.AssignedTo&&d?e.push(L):n[L.Name]=!0});function c(L){L.VariableList.forEach(a=>{e.push(a),t.push(a)}),L.ChildScopeList.forEach(a=>{c(a)})}c(u),e.forEach(L=>{L.UsedNameArray=[]}),e.sort((L,a)=>L-a);let s=0,o=[];function g(L){let a=o[L];if(a==null){for(a=Ke(s),s++;n[a];)a=Ke(s),s++;o[L]=a}return a}e.forEach((L,a)=>{L.Renamed=!0;let p=0;for(;L.UsedNameArray[p];)p++;L.Rename(g(p)),L.Scope?e.forEach(m=>{m.Renamed||(!m.Scope||m.Scope.Depth<L.Scope.Depth?m.ReferenceLocationList.some(S=>S>=L.BeginLocation&&S<=L.ScopeEndLocation?(m.UsedNameArray[p]=!0,!0):!1):m.Scope.Depth>L.Scope.Depth?L.ReferenceLocationList.some(S=>S>=m.BeginLocation&&S<=m.ScopeEndLocation?(m.UsedNameArray[p]=!0,!0):!1):L.BeginLocation<m.EndLocation&&L.EndLocation>m.BeginLocation&&(m.UsedNameArray[p]=!0))}):e.forEach(m=>{if(!m.Renamed)if(m.Type=="Global")m.UsedNameArray[p]=!0;else if(m.Type=="Local")L.ReferenceLocationList.some(S=>S>=m.BeginLocation&&S<=m.ScopeEndLocation?(m.UsedNameArray[p]=!0,!0):!1);else throw"Unreachable"})})}var Ze={};Ze.Minify=function(k,u){let d=$n(k),[n,i]=Rn(d);u.RenameVariables==!0&&Mn(n,i,u.RenameGlobals),u.SolveMath==!0&&SolveMath(d),In(d);let l=An(d);return l=`${l}`,l};try{Ge!=null&&Ge.exports!=null&&(Ge.exports.Minify=Ze.Minify)}catch{}});var Xe=le((ft,Qe)=>{var Ne=require("fs-extra"),Pn=require("path");function Nn(k,u,d,n,i=!1){let l=["fxmanifest.lua","__resource.lua"],e=null;for(let m of l){let S=Pn.join(k,m);if(Ne.existsSync(S)){e=S;break}}if(!e){console.log("\x1B[33m! No fxmanifest.lua or __resource.lua found. Skipping manifest injection.\x1B[0m");return}let t=Ne.readFileSync(e,"utf8"),c=!1,s=(m,S)=>{let w=m.replace("_scripts","_script").replace("files","file"),F=m,$=new RegExp(`^\\s*${F}\\s*\\{`,"m"),G=t.match($);if(G){let N=G.index,V=t.indexOf("}",N),j=V!==-1?t.substring(N,V):t.substring(N);if(j.includes(`'ltbridge/modules/${S}'`)||j.includes(`"ltbridge/modules/${S}"`))return;let O=`${G[0]}
|
|
11
|
-
'ltbridge/modules/${S}',`;t=t.replace(G[0],
|
|
9
|
+
`)break}else break;else if(En.includes(p))u++;else break}o=u;let a=l();if(a==""){L("Eof");break}else if(a=="'"||a=='"'){for(;;){let p=l();if(p=="\\"){let m=l();if(ze[m]==null)throw`Invalid Escape Sequence \`${m}\`.`}else{if(p==a)break;if(p=="")throw"Unfinished string!"}}L("String")}else if(a=="`"){for(;;){let p=l();if(p=="\\"){let m=l();if(ze[m]==null)throw`Invalid Escape Sequence \`${m}\`.`}else{if(p==a)break;if(p=="")throw"Unfinished string!"}}L("Hash")}else if(wn.includes(a)){for(;Pe.includes(i());)u++;Ze.includes(k.substr(o,u-o))?L("Keyword"):L("Ident")}else if(he.includes(a)||a=="."&&he.includes(i())){if(a=="0"&&i().toLowerCase()=="x")for(u++;Fn.includes(i())||i()==="_";)u++;else if(a=="0"&&i().toLowerCase()=="b")for(u++;i()==="0"||i()==="1"||i()==="_";)u++;else{for(;he.includes(i())||i()==="_";)u++;if(i()==".")for(u++;he.includes(i());)u++;if(i()=="e"||i()=="E")for(u++,(i()=="-"||i()=="+")&&u++;he.includes(i());)u++}L("Number")}else if(a=="["){let p=c();p!=null?(t(p),L("String")):L("Symbol")}else if(a==".")i()=="."&&(l(),(i()=="."||i()=="=")&&l()),L("Symbol");else if(a+i()=="//")l(),i()=="="&&l(),L("Symbol");else if(a+i()=="::")l(),L("Symbol");else if(Je.includes(a+i()))l(),L("Symbol");else if(Bn.includes(a))i()=="="&&u++,L("Symbol");else if(xn.includes(a)&&i()=="=")l(),L("Symbol");else if(Gn.includes(a))L("Symbol");else throw`Bad symbol \`${a}\` in source. ${u}`}return n}function Pn(k){let u=Mn(k),d=0;function n(){let r=u[d];return d<u.length&&d++,r}function i(r){return r=d+(r||0),u[r]||u[u.length-1]}function l(r){let h=1,T=0,f=0;for(;;){let b=u[f],_;b==r?_=b.LeadingWhite:_=b.LeadingWhite+b.Source;let y;for(y=0;y<=_.length;y++)_.substr(y,1)==`
|
|
10
|
+
`?(h++,T=0):T++;if(b==r)break;f++}return`${h}:${T+1}`}function e(){let r=i();return`<${r.Type} \`${r.Source}\`> at: ${l(r)}`}function t(){let r=i();return r.Type=="Eof"||r.Type=="Keyword"&&Rn.includes(r.Source)}function c(){return An.includes(i().Source)||!1}function s(){return Je.includes(i().Source)||!1}function o(r,h){let T=i();if(T.Type==r&&(h==null||T.Source==h))return n();if(T.Type=="Keyword"&&r=="Ident"&&me.includes(T.Source)&&(h==null||T.Source==h))return n();{let f;for(f=-3;f<=3;f++)ge(`Tokens[${f}] = \`${i(f).Source}\``);throw h?`${l(T)}: \`${h}\` expected.`:`${l(T)}: ${r} expected.`}}function g(r){let h=r.GetFirstToken,T=r.GetLastToken,f=r;return r.GetFirstToken=function(){let b=h(f);return J(b),b},r.GetLastToken=function(){let b=T(f);return J(b),b},r}let L,a;function p(r,h){let T=[a(r,h)],f=[];for(;i().Source==",";)f.push(n()),T.push(a(r,h));return[T,f]}function m(r,h){let T=i();if(T.Source=="("){let f=n(),b=a(r,h),_=o("Symbol",")"),y;return y=g({Type:"ParenExpr",Expression:b,Token_OpenParen:f,Token_CloseParen:_,GetFirstToken:()=>y.Token_OpenParen,GetLastToken:()=>y.Token_CloseParen}),y}else if(T.Type=="Ident"||T.Type=="Keyword"&&me.includes(T.Source)){let f;return f=g({Type:"VariableExpr",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),r[f.Token.Source]!=null&&r[f.Token.Source]?.Tokens?.push!=null?(r[f.Token.Source].Tokens.push(f.Token),r[f.Token.Source].UseCountIncrease()):h[f.Token.Source]!=null&&h[f.Token.Source]?.Tokens?.push!=null&&(h[f.Token.Source].Tokens.push(f.Token),h[f.Token.Source].UseCountIncrease()),f}else throw ge(e()),`${l(T)}: Unexpected symbol. ${T.Type} ${T.Source}`}function S(r,h){let T=o("Symbol","{"),f=[],b=[];for(;i().Source!="}";){let E,B;if(i().Source=="["){let C=n(),M=a(r,h),P=o("Symbol","]"),x=o("Symbol","="),Z=a(r,h);E=M.Token&&M.Token.Source,B=Z,f.push({EntryType:"Index",Index:M,Value:Z,Token_OpenBracket:C,Token_CloseBracket:P,Token_Equals:x})}else if((i().Type=="Ident"||i().Type=="Keyword"&&me.includes(i().Source))&&i(1).Source=="="){let C=n(),M=n(),P=a(r,h);E=C,B=P,f.push({EntryType:"Field",Field:C,Value:P,Token_Equals:M})}else{let C=a(r,h);f.push({EntryType:"Value",Value:C})}if(i().Source==","||i().Source==";")b.push(n());else break}let _=o("Symbol","}"),y;return y=g({Type:"TableLiteral",EntryList:f,Token_SeperatorList:b,Token_OpenBrace:T,Token_CloseBrace:_,GetFirstToken:()=>y.Token_OpenBrace,GetLastToken:()=>y.Token_CloseBrace}),y}function w(r,h){let T=[],f=[];if(i().Type=="Ident"||i().Type=="Keyword"&&me.includes(i().Source)){let b=n();if(h&&i().Source=="<"&&i(2).Source==">"){let _=i(1).Source;b.Attribute={LeadingWhite:i().LeadingWhite,Source:`<${_}>`},n(),n(),n()}T.push(b)}else if(i().Source=="..."&&r)return[T,f,n()];for(;i().Source==",";){if(f.push(n()),i().Source=="..."&&r)return[T,f,n()];{let b=o("Ident");if(h&&i().Source=="<"&&i(2).Source==">"){let _=i(1).Source;b.Attribute={LeadingWhite:i().LeadingWhite,Source:`<${_}>`},n(),n(),n()}T.push(b)}}return[T,f]}function F(r,h,T){let f=L(h,T),b=i();if(b.Type=="Keyword"&&b.Source==r)return n(),[f,b];throw ge(b.Type,b.Source),`${l(b)}: ${r} expected.`}function $(r,h,T,f){let b=n(),_,y;if(!r){_=[],y=[];let I=o("Ident");for(_.push(I);i().Source==".";)y.push(n()),_.push(o("Ident"));i().Source==":"&&(y.push(n()),_.push(o("Ident")))}let E=o("Symbol","("),[B,C,M]=w(!0),P=o("Symbol",")"),[x,Z]=F("end",h,T),oe;return oe=g({Type:r==!0?"FunctionLiteral":"FunctionStat",NameChain:_,ArgList:B,Body:x,Token_Function:b,Token_NameChainSeperator:y,Token_OpenParen:E,Token_Varg:M,Token_ArgCommaList:C,Token_CloseParen:P,Token_End:Z,GetFirstToken:()=>oe.Token_Function,GetLastToken:()=>oe.Token_End}),oe}function G(r,h){let T=i();if(T.Source=="("){let f=n(),b=[],_=[];for(;i().Source!=")"&&(b.push(a(r,h)),i().Source==",");)_.push(n());let y=o("Symbol",")"),E;return E=g({CallType:"ArgCall",ArgList:b,Token_CommaList:_,Token_OpenParen:f,Token_CloseParen:y,GetFirstToken:()=>E.Token_OpenParen,GetLastToken:()=>E.Token_CloseParen}),E}else if(T.Source=="{"){let f;return f=g({CallType:"TableCall",TableExpr:a(r,h),GetFirstToken:()=>f.TableExpr.GetFirstToken(),GetLastToken:()=>f.TableExpr.GetLastToken()}),f}else if(T.Type=="String"){let f;return f=g({CallType:"StringCall",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else throw"Function arguments expected."}function A(r,h){let T=m(r,h);for(J(T,"nil prefixexpr");;){let f=i();if(f.Source=="."){let b=n(),_=o("Ident"),y;y=g({Type:"FieldExpr",Base:T,Field:_,Token_Dot:b,GetFirstToken:()=>y.Base.GetFirstToken(),GetLastToken:()=>y.Field}),T=y}else if(f.Source==":"){let b=n(),_=o("Ident"),y=G(r,h),E;E=g({Type:"MethodExpr",Base:T,Method:_,FunctionArguments:y,Token_Colon:b,GetFirstToken:()=>E.Base.GetFirstToken(),GetLastToken:()=>E.FunctionArguments.GetLastToken()}),T=E}else if(f.Source=="["){let b=n(),_=a(r,h),y=o("Symbol","]"),E;E=g({Type:"IndexExpr",Base:T,Index:_,Token_OpenBracket:b,Token_CloseBracket:y,GetFirstToken:()=>E.Base.GetFirstToken(),GetLastToken:()=>E.Token_CloseBracket}),T=E}else if(f.Source=="{"||f.Source=="("||f.Type=="String"){let b;b=g({Type:"CallExpr",Base:T,FunctionArguments:G(r,h),GetFirstToken:()=>b.Base.GetFirstToken(),GetLastToken:()=>b.FunctionArguments.GetLastToken()}),T=b}else if($n.includes(f.Source)){let b=n(),_=a(r,h),y;y=g({Type:"CompoundStat",Base:T,Token_Compound:b,Rhs:_,Lhs:T,GetFirstToken:()=>y.Base.GetFirstToken(),GetLastToken:()=>y.Rhs.GetLastToken()}),T=y}else return T}}function R(r,h){let T=i();if(T.Type=="Number"){let f;return f=g({Type:"NumberLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Type=="String"){let f;return f=g({Type:"StringLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Type=="Hash"){let f;return f=g({Type:"HashLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Source=="nil"){let f;return f=g({Type:"NilLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Source=="true"||T.Source=="false"){let f;return f=g({Type:"BooleanLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Source=="..."){let f;return f=g({Type:"VargLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else return T.Source=="{"?S(r,h):T.Source=="function"?$(!0,r,h):T.Source=="if"?j(!0,r,h):A(r,h)}function N(r,h,T){let f;if(c()){let b=n(),_=N(In,h,T),y;y=g({Type:"UnopExpr",Token_Op:b,Rhs:_,GetFirstToken:()=>y.Token_Op,GetLastToken:()=>y.Rhs.GetLastToken()}),f=y}else f=R(h,T),J(f,"nil sipleexpr");for(;s()&&Me[i().Source]!=null&&Me[i().Source][0]>r;){let b=n(),_=N(Me[b.Source][1],h,T);J(_,"RhsNeeded");let y;y=g({Type:"BinopExpr",Lhs:f,Rhs:_,Token_Op:b,GetFirstToken:()=>y.Lhs.GetFirstToken(),GetLastToken:()=>y.Rhs.GetLastToken()}),f=y}return f}a=(r,h)=>N(0,r,h);function V(r,h){let T=A(r,h);if(T.Type=="MethodExpr"||T.Type=="CallExpr"){let f;return f=g({Type:"CallExprStat",Expression:T,GetFirstToken:()=>f.Expression.GetFirstToken(),GetLastToken:()=>f.Expression.GetLastToken()}),f}else{if(T.Type=="CompoundStat")return T;{let f=[T],b=[];for(T.IsStat=!0;i().Source==",";){b.push(n());let C=A(r,h);if(C.Type=="MethodExpr"||C.Type=="CallExpr")throw"Bad left hand side of asignment";C.IsStat=!0,f.push(C)}let _=o("Symbol","="),y=[a(r,h)],E=[];for(;i().Source==",";)E.push(n()),y.push(a(r,h));let B;return B=g({Type:"AssignmentStat",Rhs:y,Lhs:f,Token_Equals:_,Token_LhsSeperatorList:b,Token_RhsSeperatorList:E,GetFirstToken:()=>B.Lhs[0].GetFirstToken(),GetLastToken:()=>B.Rhs[B.Rhs.length-1].GetLastToken()}),B}}}function j(r,h,T){let f=n(),b=a(h,T),_=o("Keyword","then"),y=r?a(h,T):L(h,T),E=[];for(;i().Source=="elseif"||i().Source=="else";){let M=n(),P,x;M.Source=="elseif"&&(P=a(h,T),x=o("Keyword","then"));let Z=r?a(h,T):L(h,T);if(E.push({Condition:P,Body:Z,ClauseType:M.Source,Token:M,Token_Then:x}),M.Source=="else")break}let B=r?null:o("Keyword","end"),C;return C=g({Type:r?"IfExpr":"IfStat",Condition:b,Body:y,ElseClauseList:E,Token_If:f,Token_Then:_,Token_End:B,GetFirstToken:()=>C.Token_If,GetLastToken:()=>C.Token_End}),C}function D(r,h){let T=n(),[f,b]=F("end",r,h),_;return _=g({Type:"DoStat",Body:f,Token_Do:T,Token_End:b,GetFirstToken:()=>_.Token_Do,GetLastToken:()=>_.Token_End}),_}function X(r,h){let T=n(),f=a(r,h),b=o("Keyword","do"),[_,y]=F("end",r,h),E;return E=g({Type:"WhileStat",Condition:f,Body:_,Token_While:T,Token_Do:b,Token_End:y,GetFirstToken:()=>E.Token_While,GetLastToken:()=>E.Token_End}),E}function Y(r,h){let T=n(),[f,b]=w(),_=[];if(i().Source=="="){let y=n(),[E,B]=p(r,h);if(E.length<2||E.length>3)throw"Expected 2 or 3 values for range bounds";let C=o("Keyword","do"),[M,P]=F("end",r,h),x;return x=g({Type:"NumericForStat",VarList:f,RangeList:E,Body:M,Token_For:T,Token_VarCommaList:b,Token_Equals:y,Token_RangeCommaList:B,Token_Do:C,Token_End:P,GetFirstToken:()=>x.Token_For,GetLastToken:()=>x.Token_End}),x}else if(i().Source=="in"){let y=n(),[E,B]=p(r,h),C=o("Keyword","do"),[M,P]=F("end",r,h),x;return x=g({Type:"GenericForStat",VarList:f,GeneratorList:E,Body:M,Token_For:T,Token_VarCommaList:b,Token_In:y,Token_GeneratorCommaList:B,Token_Do:C,Token_End:P,GetFirstToken:()=>x.Token_For,GetLastToken:()=>x.Token_End}),x}}function ee(r,h){let T=n(),[f,b]=F("until",r),_=a(r,h),y;return y=g({Type:"RepeatStat",Body:f,Condition:_,Token_Repeat:T,Token_Until:b,GetFirstToken:()=>y.Token_Repeat,GetLastToken:()=>y.Condition.GetLastToken()}),y}function te(r,h){let T=n();if(i().Source=="function"){let f=$(!1,r,h,!0);if(f.NameChain.length>1)throw l(f.Token_NameChainSeperator[0])+": `(` expected.";let b;return b=g({Type:"LocalFunctionStat",FunctionStat:f,Token_Local:T,GetFirstToken:()=>b.Token_Local,GetLastToken:()=>b.FunctionStat.GetLastToken()}),b}else if(i().Type=="Ident"||i().Type=="Keyword"&&me.includes(i().Source)){let[f,b]=w(!1,!0),_=[],y=[],E;if(i().Source=="="){E=n();let[C,M]=p(r,h);_=C,y=M}let B;return B=g({Type:"LocalVarStat",VarList:f,ExprList:_,Token_Local:T,Token_Equals:E,Token_VarCommaList:b,Token_ExprCommaList:y,GetFirstToken:()=>B.Token_Local,GetLastToken:function(){return B.ExprList.length>0?B.ExprList[B.ExprList.length-1].GetLastToken():B.VarList[B.VarList.length-1]}}),B}else throw"`function` or ident expected"}function z(r,h){let T=n(),f,b;t()||i().Source==";"?(f=[],b=[]):[f,b]=p(r,h);let _;return _={Type:"ReturnStat",ExprList:f,Token_Return:T,Token_CommaList:b,GetFirstToken:()=>_.Token_Return,GetLastToken:function(){return _.ExprList.length>0?_.ExprList[_.ExprList.length-1].GetLastToken():_.Token_Return}},_}function ce(){let r=n(),h;return h={Type:"BreakStat",Token_Break:r,GetFirstToken:()=>h.Token_Break,GetLastToken:()=>h.Token_Break},h}function _e(r,h){if(i(1).Source=="(")return[!1,V(r,h)];let T=n(),f;return f={Type:"ContinueStat",Token_Continue:T,GetFirstToken:()=>f.Token_Continue,GetLastToken:()=>f.Token_Continue},[!0,f]}function H(){let r=n(),h;i().Type=="Keyword"?h=o("Keyword"):h=o("Ident");let T;return T={Type:"GotoStat",Token_Goto:r,Token_Label:h,GetFirstToken:()=>T.Token_Goto,GetLastToken:()=>T.Token_Label},T}function Re(){let r=n(),h;i().Type=="Keyword"?h=o("Keyword"):h=o("Ident");let T=o("Symbol","::"),f;return f={Type:"LabelStat",Token_ColonsLeft:r,Token_Label:h,Token_ColonsRight:T,GetFirstToken:()=>f.Token_ColonsLeft,GetLastToken:()=>f.Token_ColonsRight},f}function Ee(r,h){let T=i();return T.Source=="if"?[!1,j(!1,r,h)]:T.Source=="while"?[!1,X(r,h)]:T.Source=="do"?[!1,D(r,h)]:T.Source=="for"?[!1,Y(r,h)]:T.Source=="repeat"?[!1,ee(r,h)]:T.Source=="function"?[!1,$(!1,r,h)]:T.Source=="local"?[!1,te(r,h)]:T.Source=="return"?[!0,z(r,h)]:T.Source=="break"?[!0,ce(r,h)]:T.Source=="continue"?_e(r,h):T.Source=="goto"?[!1,H()]:T.Source=="::"?[!1,Re()]:[!1,V(r,h)]}let Te=1;return L=function(r,h){let T=[],f=[],b=!1,_={},y={};if(h!=null)for(let[P,x]of Object.entries(h))y[P]=x;if(r!=null)for(let[P,x]of Object.entries(r))y[P]=x;let E,B=0;for(;!b&&!t();){E&&E==i()&&ge(`INFINITE LOOP POSSIBLE ON STATEMENT ${E.Source} :`,E),E=i();let[P,x]=Ee(_,y);if(x)switch(T.push(x),x.Type){case"LocalVarStat":x.VarList.forEach(I=>{I.UseCount=0,I.Number=B++,_[I.Source]=I;let ie=[];function U(){I.UseCount++,ie.forEach(q=>{q.UseCount=I.UseCount})}I.Tokens={},I.Tokens.push=q=>{q.UseCountIncrease=U,q.UseCount=I.UseCount,q.Tokens=I.Tokens,ie.push(q)},I.Tokens.get=()=>ie,I.UseCountIncrease=U});break;case"LocalFunctionStat":let oe=x.FunctionStat.NameChain;if(oe.length===1){let U=function(){I.UseCount++,ie.forEach(q=>{q.UseCount=I.UseCount})};var M=U;let I=oe[0];I.UseCount=0,I.Number=B++,_[I.Source]=I;let ie=[];I.Tokens={},I.Tokens.push=q=>{q.UseCountIncrease=U,q.UseCount=I.UseCount,q.Tokens=I.Tokens,ie.push(q)},I.Tokens.get=()=>ie,I.UseCountIncrease=U}break;default:break}let Z=i();Z.Type=="Symbol"&&Z.Source==";"&&(f[T.length-1]=n())}let C;return C={Type:"StatList",StatementList:T,SemicolonList:f,GetFirstToken:function(){if(C.StatementList.length!=0)return C.StatementList[0]?.GetFirstToken()},GetLastToken:function(){if(C.StatementList.length!=0)return C.SemicolonList[C.StatementList.length-1]?C.SemicolonList[C.StatementList.length-1]:C.StatementList[C.StatementList.length-1].GetLastToken()}},C},L([],[])}function ke(k,u){let d={BinopExpr:!0,UnopExpr:!0,NumberLiteral:!0,StringLiteral:!0,NilLiteral:!0,BooleanLiteral:!0,VargLiteral:!0,HashLiteral:!0,FieldExpr:!0,IndexExpr:!0,MethodExpr:!0,CallExpr:!0,FunctionLiteral:!0,VariableExpr:!0,ParenExpr:!0,TableLiteral:!0},n={StatList:!0,BreakStat:!0,ContinueStat:!0,LabelStat:!0,GotoStat:!0,ReturnStat:!0,LocalVarStat:!0,LocalFunctionStat:!0,FunctionStat:!0,RepeatStat:!0,GenericForStat:!0,NumericForStat:!0,WhileStat:!0,DoStat:!0,IfStat:!0,CallExprStat:!0,AssignmentStat:!0,CompoundStat:!0};for(var[i,l]of Object.entries(u))if(!(i==="VisitStat"||i==="VisitExpr")&&!n[i]&&!d[i])throw`Invalid visitor target: \`${i}\``;function e(o){if(o!=null){let g=u[o.Type];if(typeof g=="function")return g(o);if(g&&g.Pre)return g.Pre(o)}}function t(o){let g=u[o.Type];if(g&&typeof g=="object"&&g.Post)return g.Post(o)}let c,s;c=function(o){if(!e(o)){if(o.Type=="BinopExpr")c(o.Lhs),c(o.Rhs);else if(o.Type=="UnopExpr")c(o.Rhs);else if(!(o.Type=="NumberLiteral"||o.Type=="StringLiteral"||o.Type=="NilLiteral"||o.Type=="BooleanLiteral"||o.Type=="VargLiteral"||o.Type=="HashLiteral")){if(o.Type=="FieldExpr")c(o.Base);else if(o.Type=="IndexExpr")c(o.Base),c(o.Index);else if(o.Type=="MethodExpr"||o.Type=="CallExpr")c(o.Base),o.FunctionArguments.CallType=="ArgCall"?o.FunctionArguments.ArgList.forEach((g,L)=>{c(g)}):o.FunctionArguments.CallType=="TableCall"&&c(o.FunctionArguments.TableExpr);else if(o.Type=="FunctionLiteral")s(o.Body);else if(o.Type!="VariableExpr")if(o.Type=="ParenExpr")c(o.Expression);else if(o.Type=="TableLiteral")o.EntryList.forEach((g,L)=>{if(g.EntryType=="Field")c(g.Value);else if(g.EntryType=="Index")c(g.Index),c(g.Value);else if(g.EntryType=="Value")c(g.Value);else throw"unreachable"});else if(o.Type=="CompoundStat")c(o.Lhs),c(o.Rhs);else if(o.Type=="IfExpr")c(o.Condition),c(o.Body),o.ElseClauseList.forEach(g=>{g.Condition!=null&&c(g.Condition),c(g.Body)});else throw`unreachable, type: ${o.Type}: ${o}`}t(o)}},s=function(o){if(!e(o)){if(o.Type=="StatList")o.StatementList.forEach((g,L)=>{if(g!=null){if(g===null||g.Type===null)return;g.Remove=()=>{o.StatementList[L]=null},s(g)}});else if(o.Type!="BreakStat"){if(o.Type!="ContinueStat"){if(o.Type!="GotoStat"){if(o.Type!="LabelStat")if(o.Type=="ReturnStat")o.ExprList.forEach((g,L)=>{c(g)});else if(o.Type=="LocalVarStat")o.Token_Equals&&o.ExprList.forEach((g,L)=>{c(g)});else if(o.Type=="LocalFunctionStat")s(o.FunctionStat.Body);else if(o.Type=="FunctionStat")s(o.Body);else if(o.Type=="RepeatStat")s(o.Body),c(o.Condition);else if(o.Type=="GenericForStat")o.GeneratorList.forEach((g,L)=>{c(g)}),s(o.Body);else if(o.Type=="NumericForStat")o.RangeList.forEach((g,L)=>{c(g)}),s(o.Body);else if(o.Type=="WhileStat")c(o.Condition),s(o.Body);else if(o.Type=="DoStat")s(o.Body);else if(o.Type=="IfStat")c(o.Condition),s(o.Body),o.ElseClauseList.forEach(g=>{g.Condition!=null&&c(g.Condition),s(g.Body)});else if(o.Type=="CallExprStat")c(o.Expression);else if(o.Type=="CompoundStat")c(o.Lhs),c(o.Rhs);else if(o.Type=="AssignmentStat")o.Lhs.forEach(g=>{c(g)}),o.Rhs.forEach(g=>{c(g)});else throw"Unreachable code. Got "+o.Type}}}t(o)}},u.VisitStat=s,u.VisitExpr=c,n[k.Type]?s(k):c(k)}function Nn(k){let u=[],d,n=0;function i(){return n++,n}function l(){d={ParentScope:d,ChildScopeList:[],VariableList:[],BeginLocation:i(),Depth:null,GetVar:null},d.ParentScope?(d.Depth=d.ParentScope.Depth+1,d.ParentScope.ChildScopeList.push(d)):d.Depth=1;let a=d;d.GetVar=function(p){for(let m of a.VariableList)if(m.Name==p)return m;if(a.ParentScope)return a.ParentScope.GetVar(p);for(let m of u)if(m.Name==p)return m}}function e(){let a=d;return a.EndLocation=i(),a.VariableList.forEach(p=>{p.ScopeEndLocation=a.EndLocation}),d=a.ParentScope,a}l();function t(a,p,m){J(m,"Missing localInfo"),J(a,"Missing local var name");let S={Type:"Local",Name:a,RenameList:[p],AssignedTo:!1,Info:m,Scope:d,BeginLocation:i(),EndLocation:i(),ReferenceLocationList:[i()]};return S.Rename=function(w){S.Name=w,S.RenameList.forEach(F=>{F(w)})},d.VariableList.push(S),S}function c(a){for(let m of u)if(m.Name==a)return m;let p={Type:"Global",Name:a,RenameList:[],AssignedTo:!1,Scope:null,BeginLocation:i(),EndLocation:i(),ReferenceLocationList:[]};return p.Rename=function(m){p.Name=m,p.RenameList.forEach(S=>{S(m)})},u.push(p),p}function s(a,p){J(a,"Missing var name");let m=c(a);return m.RenameList.push(p),m}function o(a,p){let m;for(m=a.VariableList.length-1;m>=0;m--)if(a.VariableList[m].Name==p)return a.VariableList[m];if(a.ParentScope){let S=o(a.ParentScope,p);if(S)return S}}function g(a,p){J(a,"Missing var name");let m=o(d,a);m?m.RenameList.push(p):m=s(a,p);let S=i();return m.EndLocation=S,m.ReferenceLocationList.push(m.EndLocation),m}let L={};return L.FunctionLiteral={Pre:function(a){l(),a.ArgList.forEach((p,m)=>{let S=t(p.Source,function(w,F){F||(p.Source=w)},{Type:"Argument",Index:m});p.var=S})},Post:function(a){e()}},L.VariableExpr=function(a){a.Variable=g(a.Token.Source,function(p,m=!1){m&&a.IsStat||(a.Token.Source=p)})},L.StatList={Pre:function(a){l()},Post:function(a){a.SkipPop||e()}},L.LocalVarStat={Post:function(a){a.VarList.forEach((p,m)=>{t(p.Source,function(S){a.VarList[m].Source=S},{Type:"Local",Expr:a.ExprList})})}},L.LocalFunctionStat={Pre:function(a){t(a.FunctionStat.NameChain[0].Source,function(p){a.FunctionStat.NameChain[0].Source=p},{Type:"LocalFunction"}),l(),a.FunctionStat.ArgList.forEach((p,m)=>{t(p.Source,function(S){p.Source=S},{Type:"Argument",Index:m})})},Post:function(){e()}},L.FunctionStat={Pre:function(a){let p=a.NameChain,m;p.length==1?o(d,p[0].Source)?m=g(p[0].Source,function(S){p[0].Source=S}):m=s(p[0].Source,function(S){p[0].Source=S}):m=g(p[0].Source,function(S){p[0].Source=S}),m.AssignedTo=!0,l(),a.ArgList.forEach((S,w)=>{t(S.Source,function(F){S.Source=F},{Type:"Argument",Index:w})})},Post:function(){e()}},L.GenericForStat={Pre:function(a){return a.GeneratorList.forEach(p=>{ke(p,L)}),l(),a.VarList.forEach((p,m)=>{t(p.Source,function(S){p.Source=S},{Type:"ForRange",Index:m})}),ke(a.Body,L),e(),!0}},L.NumericForStat={Pre:function(a){return a.RangeList.forEach(p=>{ke(p,L)}),l(),a.VarList.forEach((p,m)=>{t(p.Source,function(S){p.Source=S},{Type:"ForRange",Index:m})}),ke(a.Body,L),e(),!0}},L.RepeatStat={Pre:function(a){a.Body.SkipPop=!0},Post:function(a){e()}},L.AssignmentStat={Post:function(a){a.Lhs.forEach(p=>{p.Variable!=null&&(p.Variable.AssignedTo=!0)})}},ke(k,L),[u,e()]}function Vn(k){let u,d,n="",i=e=>typeof e?.LeadingWhite!="string"?" ":e.LeadingWhite;function l(e){if(e.LeadingWhite==null||e.Source==null)throw`Bad token: tk=${e} | lwhite=${e.LeadingWhite} | source=${e.Source}`;n=`${n}${e.LeadingWhite}${e.Source}`}return d=function(e){if(e.Type=="BinopExpr")d(e.Lhs),l(e.Token_Op),d(e.Rhs);else if(e.Type=="UnopExpr")l(e.Token_Op),d(e.Rhs);else if(e.Type=="NumberLiteral"||e.Type=="StringLiteral"||e.Type=="NilLiteral"||e.Type=="BooleanLiteral"||e.Type=="VargLiteral"||e.Type=="HashLiteral")l(e.Token);else if(e.Type=="FieldExpr")d(e.Base),l(e.Token_Dot),l(e.Field);else if(e.Type=="IndexExpr")d(e.Base),l(e.Token_OpenBracket),d(e.Index),l(e.Token_CloseBracket);else if(e.Type=="MethodExpr"||e.Type=="CallExpr")d(e.Base),e.Type=="MethodExpr"&&(l(e.Token_Colon),l(e.Method)),e.FunctionArguments.CallType=="StringCall"?l(e.FunctionArguments.Token):e.FunctionArguments.CallType=="ArgCall"?(l(e.FunctionArguments.Token_OpenParen),e.FunctionArguments.ArgList.forEach((t,c)=>{d(t);let s=e.FunctionArguments.Token_CommaList[c];s!=null&&l(s)}),l(e.FunctionArguments.Token_CloseParen)):e.FunctionArguments.CallType=="TableCall"&&d(e.FunctionArguments.TableExpr);else if(e.Type=="FunctionLiteral")l(e.Token_Function),l(e.Token_OpenParen),e.ArgList.forEach((t,c)=>{l(t);let s=e.Token_ArgCommaList[c];s!=null&&l(s)}),e.Token_Varg!=null&&l(e.Token_Varg),l(e.Token_CloseParen),u(e.Body),l(e.Token_End);else if(e.Type=="VariableExpr")l(e.Token);else if(e.Type=="ParenExpr")l(e.Token_OpenParen),d(e.Expression),l(e.Token_CloseParen);else if(e.Type=="TableLiteral")l(e.Token_OpenBrace),e.EntryList.forEach((t,c)=>{if(t.EntryType=="Field")l(t.Field),l(t.Token_Equals),d(t.Value);else if(t.EntryType=="Index")l(t.Token_OpenBracket),d(t.Index),l(t.Token_CloseBracket),l(t.Token_Equals),d(t.Value);else if(t.EntryType=="Value")d(t.Value);else throw"unreachable";let s=e.Token_SeperatorList[c];s!=null&&l(s)}),l(e.Token_CloseBrace);else if(e.Type=="CompoundStat")u(e);else if(e.Type=="IfExpr")l(e.Token_If),d(e.Condition),l(e.Token_Then),d(e.Body),e.ElseClauseList.forEach(t=>{l(t.Token),t.Condition!=null&&(d(t.Condition),l(t.Token_Then)),d(t.Body)});else throw`unreachable, type: ${e.Type}: ${e}`},u=function(e){if(e==null)throw`STAT IS NIL! ${e}`;if(!(e.Type==="StatList"&&e.StatementList.length===0)){if(e.WrapInDo){let t=i(e.GetFirstToken());e.GetFirstToken().LeadingWhite="",n+=`${t}do `}e.Type=="StatList"?e.StatementList.forEach((t,c)=>{t===null||t.Type===null||(t.Remove=()=>{e.StatementList[c]=null},u(t),e.SemicolonList[c]&&l(e.SemicolonList[c]))}):e.Type=="BreakStat"?l(e.Token_Break):e.Type=="ContinueStat"?l(e.Token_Continue):e.Type=="GotoStat"?(l(e.Token_Goto),l(e.Token_Label)):e.Type=="LabelStat"?(l(e.Token_ColonsLeft),l(e.Token_Label),l(e.Token_ColonsRight)):e.Type=="ReturnStat"?(l(e.Token_Return),e.ExprList.forEach((t,c)=>{d(t),e.Token_CommaList[c]&&l(e.Token_CommaList[c])})):e.Type=="LocalVarStat"?(l(e.Token_Local),e.VarList.forEach((t,c)=>{l(t),t.Attribute!=null&&l(t.Attribute);let s=e.Token_VarCommaList[c];s!=null&&l(s)}),e.Token_Equals!=null&&(l(e.Token_Equals),e.ExprList.forEach((t,c)=>{d(t);let s=e.Token_ExprCommaList[c];s!=null&&l(s)}))):e.Type=="LocalFunctionStat"?(l(e.Token_Local),l(e.FunctionStat.Token_Function),l(e.FunctionStat.NameChain[0]),l(e.FunctionStat.Token_OpenParen),e.FunctionStat.ArgList.forEach((t,c)=>{l(t);let s=e.FunctionStat.Token_ArgCommaList[c];s!=null&&l(s)}),e.FunctionStat.Token_Varg&&l(e.FunctionStat.Token_Varg),l(e.FunctionStat.Token_CloseParen),u(e.FunctionStat.Body),l(e.FunctionStat.Token_End)):e.Type=="FunctionStat"?(l(e.Token_Function),e.NameChain.forEach((t,c)=>{l(t);let s=e.Token_NameChainSeperator[c];s!=null&&l(s)}),l(e.Token_OpenParen),e.ArgList.forEach((t,c)=>{l(t);let s=e.Token_ArgCommaList[c];s!=null&&l(s)}),e.Token_Varg&&l(e.Token_Varg),l(e.Token_CloseParen),u(e.Body),l(e.Token_End)):e.Type=="RepeatStat"?(l(e.Token_Repeat),u(e.Body),l(e.Token_Until),d(e.Condition)):e.Type=="GenericForStat"?(l(e.Token_For),e.VarList.forEach((t,c)=>{l(t);let s=e.Token_VarCommaList[c];s!=null&&l(s)}),l(e.Token_In),e.GeneratorList.forEach((t,c)=>{d(t);let s=e.Token_GeneratorCommaList[c];s!=null&&l(s)}),l(e.Token_Do),u(e.Body),l(e.Token_End)):e.Type=="NumericForStat"?(l(e.Token_For),e.VarList.forEach((t,c)=>{l(t);let s=e.Token_VarCommaList[c];s!=null&&l(s)}),l(e.Token_Equals),e.RangeList.forEach((t,c)=>{d(t);let s=e.Token_RangeCommaList[c];s!=null&&l(s)}),l(e.Token_Do),u(e.Body),l(e.Token_End)):e.Type=="WhileStat"?(l(e.Token_While),d(e.Condition),l(e.Token_Do),u(e.Body),l(e.Token_End)):e.Type=="DoStat"?(l(e.Token_Do),u(e.Body),l(e.Token_End)):e.Type=="IfStat"?(l(e.Token_If),d(e.Condition),l(e.Token_Then),u(e.Body),e.ElseClauseList.forEach(t=>{l(t.Token),t.Condition!=null&&(d(t.Condition),l(t.Token_Then)),u(t.Body)}),l(e.Token_End)):e.Type=="CallExprStat"?d(e.Expression):e.Type=="CompoundStat"?(d(e.Lhs),l(e.Token_Compound),d(e.Rhs),e.Type="CompoundStat"):e.Type=="AssignmentStat"?(e.Lhs.forEach((t,c)=>{d(t);let s=e.Token_LhsSeperatorList[c];s!=null&&l(s)}),l(e.Token_Equals),e.Rhs.forEach((t,c)=>{d(t);let s=e.Token_RhsSeperatorList[c];s!=null&&l(s)})):J(!1,"unreachable"),e.WrapInDo&&(n+=" end ")}},u(k),n}function vn(k){let u,d;function n(e){e&&(e.LeadingWhite="")}function i(e,t,c=!1){n(t);let s=(typeof e.Source=="string"?e.Source:e.Source.toString()).substr(e.Source.length-1,1),o=(typeof t.Source=="string"?t.Source:t.Source.toString()).substr(0,1);s=="-"&&o=="-"||Pe.includes(s)&&Pe.includes(o)||c&&s==")"&&o=="("?t.LeadingWhite=c?";":" ":t.LeadingWhite=""}function l(e,t,c){u(t),n(c);let s=t.GetFirstToken(),o=t.GetLastToken();s!=null?(i(e,s),i(o,c)):i(e,c)}d=function(e){if(e.Type==="BinopExpr")d(e.Lhs),d(e.Rhs),e.Lhs.Type=="NumberLiteral"&&e.Token_Op.Source==".."?e.Token_Op.LeadingWhite=" ":(n(e.Token_Op),i(e.Lhs.GetLastToken(),e.Token_Op)),i(e.Token_Op,e.Rhs.GetFirstToken());else if(e.Type==="UnopExpr")n(e.Token_Op),d(e.Rhs),i(e.Token_Op,e.Rhs.GetFirstToken());else if(e.Type==="NumberLiteral"||e.Type==="StringLiteral"||e.Type==="NilLiteral"||e.Type==="BooleanLiteral"||e.Type==="VargLiteral"||e.Type==="HashLiteral")n(e.Token);else if(e.Type=="FieldExpr")d(e.Base),n(e.Token_Dot),n(e.Field);else if(e.Type=="IndexExpr")d(e.Base),n(e.Token_OpenBracket),d(e.Index),n(e.Token_CloseBracket);else if(e.Type=="MethodExpr"||e.Type=="CallExpr")d(e.Base),e.Type=="MethodExpr"&&(n(e.Token_Colon),n(e.Method)),e.FunctionArguments.CallType=="StringCall"?n(e.FunctionArguments.Token):e.FunctionArguments.CallType=="ArgCall"?(n(e.FunctionArguments.Token_OpenParen),e.FunctionArguments.ArgList.forEach((t,c)=>{d(t);let s=e.FunctionArguments.Token_CommaList[c];s!=null&&n(s)}),n(e.FunctionArguments.Token_CloseParen)):e.FunctionArguments.CallType=="TableCall"&&d(e.FunctionArguments.TableExpr);else if(e.Type=="FunctionLiteral")n(e.Token_Function),n(e.Token_OpenParen),e.ArgList.forEach((t,c)=>{n(t);let s=e.Token_ArgCommaList[c];s!=null&&n(s)}),e.Token_Varg!=null&&n(e.Token_Varg),n(e.Token_CloseParen),l(e.Token_CloseParen,e.Body,e.Token_End);else if(e.Type=="VariableExpr")n(e.Token);else if(e.Type=="ParenExpr")n(e.Token_OpenParen),d(e.Expression),n(e.Token_CloseParen);else if(e.Type=="IfExpr"){n(e.Token_If),d(e.Condition),i(e.Token_If,e.Condition.GetFirstToken()),i(e.Condition.GetLastToken(),e.Token_Then);let t=e.Token_Then,c=e.Body;e.ElseClauseList.forEach((s,o)=>{i(t,c.GetFirstToken()),i(c.GetLastToken(),s.Token),t=s.Token,s.Condition!=null&&(d(s.Condition),i(s.Token,s.Condition.GetFirstToken()),i(s.Condition.GetLastToken(),s.Token_Then),t=s.Token_Then),d(s.Body),c=s.Body}),i(t,c.GetFirstToken())}else if(e.Type=="TableLiteral")n(e.Token_OpenBrace),e.EntryList.forEach((t,c)=>{t.EntryType=="Field"?(n(t.Field),n(t.Token_Equals),d(t.Value)):t.EntryType=="Index"?(n(t.Token_OpenBracket),d(t.Index),n(t.Token_CloseBracket),n(t.Token_Equals),d(t.Value)):t.EntryType=="Value"?d(t.Value):J(!1,"unreachable");let s=e.Token_SeperatorList[c];s!=null&&n(s)}),e.Token_SeperatorList[e.EntryList.length-1]=null,n(e.Token_CloseBrace);else throw`unreachable, type: ${e.Type}:${e} ${console.trace()}`},u=function(e){if(e.Type=="StatList"){let t;for(t=0;t<=e.StatementList.length;t++){let c=e.StatementList[t];if(c==null)continue;u(c),n(c.GetFirstToken());let s=e.StatementList[t-1];if(s!=null){let o={")":["(","["],"]":["(","["]};if(e.SemicolonList[t-1]){let g=s.GetLastToken().Source,L=c.GetFirstToken().Source;(o[g]===null||o[g]===void 0||!o[g].includes(L))&&(e.SemicolonList[t-1]=null)}e.SemicolonList[t-1]||i(s.GetLastToken(),c.GetFirstToken(),!0)}}e.SemicolonList[e.StatementList.length-1]=null,e.StatementList.length>0&&n(e.StatementList[0].GetFirstToken())}else if(e.Type=="BreakStat")n(e.Token_Break);else if(e.Type=="ContinueStat")n(e.Token_Continue);else if(e.Type=="GotoStat")n(e.Token_Goto),i(e.Token_Goto,e.Token_Label);else if(e.Type=="LabelStat")n(e.Token_ColonsLeft),n(e.Token_Label),n(e.Token_ColonsRight);else if(e.Type=="ReturnStat")n(e.Token_Return),e.ExprList.forEach((t,c)=>{d(t),e.Token_CommaList[c]!=null&&n(e.Token_CommaList[c])}),e.ExprList.length>0&&i(e.Token_Return,e.ExprList[0].GetFirstToken());else if(e.Type=="LocalVarStat"){n(e.Token_Local);let t=!1;e.VarList.forEach((c,s)=>{s==0?i(e.Token_Local,c):n(c),c.Attribute&&(n(c.Attribute),s+1==e.VarList.length&&(t=!0));let o=e.Token_VarCommaList[s];o!=null&&n(o)}),e.Token_Equals!=null&&(t||n(e.Token_Equals),e.ExprList.forEach((c,s)=>{d(c);let o=e.Token_ExprCommaList[s];o!=null&&n(o)}))}else if(e.Type=="LocalFunctionStat")n(e.Token_Local),i(e.Token_Local,e.FunctionStat.Token_Function),i(e.FunctionStat.Token_Function,e.FunctionStat.NameChain[0]),i(e.FunctionStat.NameChain[0],e.FunctionStat.Token_OpenParen),e.FunctionStat.ArgList.forEach((t,c)=>{n(t);let s=e.FunctionStat.Token_ArgCommaList[c];s!=null&&n(s)}),e.FunctionStat.Token_Varg&&n(e.FunctionStat.Token_Varg),n(e.FunctionStat.Token_CloseParen),l(e.FunctionStat.Token_CloseParen,e.FunctionStat.Body,e.FunctionStat.Token_End);else if(e.Type=="FunctionStat")n(e.Token_Function),e.NameChain.forEach((t,c)=>{c==0?i(e.Token_Function,t):n(t);let s=e.Token_NameChainSeperator[c];s!=null&&n(s)}),n(e.Token_OpenParen),e.ArgList.forEach((t,c)=>{n(t);let s=e.Token_ArgCommaList[c];s!=null&&n(s)}),e.Token_Varg&&n(e.Token_Varg),n(e.Token_CloseParen),l(e.Token_CloseParen,e.Body,e.Token_End);else if(e.Type=="RepeatStat")n(e.Token_Repeat),l(e.Token_Repeat,e.Body,e.Token_Until),d(e.Condition),i(e.Token_Until,e.Condition.GetFirstToken());else if(e.Type=="GenericForStat")n(e.Token_For),e.VarList.forEach((t,c)=>{c==0?i(e.Token_For,t):n(t);let s=e.Token_VarCommaList[c];s!=null&&n(s)}),i(e.VarList[e.VarList.length-1],e.Token_In),e.GeneratorList.forEach((t,c)=>{d(t),c==0&&i(e.Token_In,t.GetFirstToken());let s=e.Token_GeneratorCommaList[c];s!=null&&n(s)}),i(e.GeneratorList[e.GeneratorList.length-1].GetLastToken(),e.Token_Do),l(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="NumericForStat")n(e.Token_For),e.VarList.forEach((t,c)=>{c==0?i(e.Token_For,t):n(t);let s=e.Token_VarCommaList[c];s!=null&&n(s)}),i(e.VarList[e.VarList.length-1],e.Token_Equals),e.RangeList.forEach((t,c)=>{d(t),c==0&&i(e.Token_Equals,t.GetFirstToken());let s=e.Token_RangeCommaList[c];s!=null&&n(s)}),i(e.RangeList[e.RangeList.length-1].GetLastToken(),e.Token_Do),l(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="WhileStat")n(e.Token_While),d(e.Condition),n(e.Token_Do),i(e.Token_While,e.Condition.GetFirstToken()),i(e.Condition.GetLastToken(),e.Token_Do),l(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="DoStat")n(e.Token_Do),n(e.Token_End),l(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="IfStat"){n(e.Token_If),d(e.Condition),i(e.Token_If,e.Condition.GetFirstToken()),i(e.Condition.GetLastToken(),e.Token_Then);let t=e.Token_Then,c=e.Body;e.ElseClauseList.forEach((s,o)=>{l(t,c,s.Token),t=s.Token,s.Condition!=null&&(d(s.Condition),i(s.Token,s.Condition.GetFirstToken()),i(s.Condition.GetLastToken(),s.Token_Then),t=s.Token_Then),u(s.Body),c=s.Body}),l(t,c,e.Token_End)}else if(e.Type=="CallExprStat")d(e.Expression);else if(e.Type=="CompoundStat")d(e.Lhs),n(e.Token_Compound),d(e.Rhs),i(e.Lhs.GetLastToken(),e.Token_Compound),i(e.Token_Compound,e.Rhs.GetFirstToken());else if(e.Type=="AssignmentStat")e.Lhs.forEach((t,c)=>{d(t);let s=e.Token_LhsSeperatorList[c];s!=null&&n(s)}),n(e.Token_Equals),e.Rhs.forEach((t,c)=>{d(t);let s=e.Token_RhsSeperatorList[c];s!=null&&n(s)});else return d(e)},u(k)}var se=[],v;for(v=97;v<=122;v++)se.push(String.fromCharCode(v));for(v=65;v<=90;v++)se.push(String.fromCharCode(v));for(v=48;v<=57;v++)se.push(String.fromCharCode(v));se.push("_");var Le=[];for(v=97;v<=122;v++)Le.push(String.fromCharCode(v));for(v=65;v<=90;v++)Le.push(String.fromCharCode(v));function He(k){let u="",d=k%Le.length;for(k=(k-d)/Le.length,u=`${u}${Le[d]}`;k>0;){let n=k%se.length;k=(k-n)/se.length,u=`${u}${se[n]}`}return u}function jn(k,u,d){let n=[];for(var[i,l]of Object.entries(Ze))n[i]=!0;let e=[],t=[];k.forEach(L=>{L.AssignedTo&&d?e.push(L):n[L.Name]=!0});function c(L){L.VariableList.forEach(a=>{e.push(a),t.push(a)}),L.ChildScopeList.forEach(a=>{c(a)})}c(u),e.forEach(L=>{L.UsedNameArray=[]}),e.sort((L,a)=>L-a);let s=0,o=[];function g(L){let a=o[L];if(a==null){for(a=He(s),s++;n[a];)a=He(s),s++;o[L]=a}return a}e.forEach((L,a)=>{L.Renamed=!0;let p=0;for(;L.UsedNameArray[p];)p++;L.Rename(g(p)),L.Scope?e.forEach(m=>{m.Renamed||(!m.Scope||m.Scope.Depth<L.Scope.Depth?m.ReferenceLocationList.some(S=>S>=L.BeginLocation&&S<=L.ScopeEndLocation?(m.UsedNameArray[p]=!0,!0):!1):m.Scope.Depth>L.Scope.Depth?L.ReferenceLocationList.some(S=>S>=m.BeginLocation&&S<=m.ScopeEndLocation?(m.UsedNameArray[p]=!0,!0):!1):L.BeginLocation<m.EndLocation&&L.EndLocation>m.BeginLocation&&(m.UsedNameArray[p]=!0))}):e.forEach(m=>{if(!m.Renamed)if(m.Type=="Global")m.UsedNameArray[p]=!0;else if(m.Type=="Local")L.ReferenceLocationList.some(S=>S>=m.BeginLocation&&S<=m.ScopeEndLocation?(m.UsedNameArray[p]=!0,!0):!1);else throw"Unreachable"})})}var Qe={};Qe.Minify=function(k,u){let d=Pn(k),[n,i]=Nn(d);u.RenameVariables==!0&&jn(n,i,u.RenameGlobals),u.SolveMath==!0&&SolveMath(d),vn(d);let l=Vn(d);return l=`${l}`,l};try{Ge!=null&&Ge.exports!=null&&(Ge.exports.Minify=Qe.Minify)}catch{}});var en=re((gt,Ye)=>{var Ne=require("fs-extra"),On=require("path");function Dn(k,u,d,n,i=!1){let l=["fxmanifest.lua","__resource.lua"],e=null;for(let m of l){let S=On.join(k,m);if(Ne.existsSync(S)){e=S;break}}if(!e){console.log("\x1B[33m! No fxmanifest.lua or __resource.lua found. Skipping manifest injection.\x1B[0m");return}let t=Ne.readFileSync(e,"utf8"),c=!1,s=(m,S)=>{let w=m.replace("_scripts","_script").replace("files","file"),F=m,$=new RegExp(`^\\s*${F}\\s*\\{`,"m"),G=t.match($);if(G){let N=G.index,V=t.indexOf("}",N),j=V!==-1?t.substring(N,V):t.substring(N);if(j.includes(`'ltbridge/modules/${S}'`)||j.includes(`"ltbridge/modules/${S}"`))return;let D=`${G[0]}
|
|
11
|
+
'ltbridge/modules/${S}',`;t=t.replace(G[0],D),c=!0;return}let A=new RegExp(`^\\s*${w}\\s+(['"].+?['"])`,"m"),R=t.match(A);if(R){if(R[0].includes(`'ltbridge/modules/${S}'`)||R[0].includes(`"ltbridge/modules/${S}"`))return;let N=R[1],V=`${F} {
|
|
12
12
|
'ltbridge/modules/${S}',
|
|
13
13
|
${N}
|
|
14
14
|
}`;t=t.replace(R[0],V),c=!0;return}t+=`
|
|
@@ -23,7 +23,7 @@ ${F} {
|
|
|
23
23
|
|
|
24
24
|
escrow_ignore {
|
|
25
25
|
'ltbridge/**/*.lua'
|
|
26
|
-
}`,c=!0})(),i&&(n||u)?s("files","imports/**/*.lua"):(o("imports/**/*.lua"),o("modules/**/*.lua")),c&&(Ne.writeFileSync(e,t),console.log("\x1B[32m\u2713 Updated manifest.\x1B[0m"))}
|
|
26
|
+
}`,c=!0})(),i&&(n||u)?s("files","imports/**/*.lua"):(o("imports/**/*.lua"),o("modules/**/*.lua")),c&&(Ne.writeFileSync(e,t),console.log("\x1B[32m\u2713 Updated manifest.\x1B[0m"))}Ye.exports={injectManifest:Dn}});var rn=re((Lt,on)=>{var W=require("fs-extra"),K=require("path"),{applyBuildConstants:qn}=De(),Be=null;function nn(){if(Be)return Be;let{getDatabase:k}=ue();return Be=k().exportMap,Be}function tn(k){let{getDatabase:u}=ue(),d=u(),n=[],i=new Set;for(let[s,o]of Object.entries(d.modules)){o.ns&&i.add(`LT.${o.ns} = LT.${o.ns} or {}`);let g=L=>{if(L&&L.stubs)for(let a of L.stubs)a.stubCode&&!a.metadata.internal&&n.push(a.stubCode)};g(o.shared),g(o.client),g(o.server)}let l=K.join(k,"ltbridge");W.ensureDirSync(l);let e=`--- @meta
|
|
27
27
|
--- LT Bridge API Reference
|
|
28
28
|
--- Auto-generated stub file for IDE intellisense.
|
|
29
29
|
--- Do NOT include this file in your fxmanifest.
|
|
@@ -35,7 +35,7 @@ escrow_ignore {
|
|
|
35
35
|
`,c=e+t+n.join(`
|
|
36
36
|
|
|
37
37
|
`)+`
|
|
38
|
-
`;W.writeFileSync(K.join(l,"api.lua"),c)}function
|
|
38
|
+
`;W.writeFileSync(K.join(l,"api.lua"),c)}function Un(k,u,d={}){let{version:n}=we();if(u.version!==n){console.log(`\x1B[36m\u2139 LTBridge version updated (${u.version||"unknown"} -> ${n}). Regenerating API stubs...\x1B[0m`),tn(k),u.version=n;let r=K.join(k,"ltbridge","ltbridge.config.json");W.writeFileSync(r,JSON.stringify(u,null,2))}let i=Date.now(),l=u.modules||[],e=u.minify!==!1,t=u.buildAsBundle!==!0,c=[],{resolveDependencies:s}=Ie();l.length>0&&(c=s(l,nn()).sequence),c=["__init__",...c.filter(r=>r!=="__init__")];let{getModuleData:o}=ue(),g=!1,L=!1,a=!1,p={},m={},S=[],w=r=>{let h=o(r);if(!h)return;let T=h.ns,f=E=>{let B=h[E];if(B){if(B.stubs)for(let x of B.stubs)p[x.funcName]=T,m[x.funcName]=x.metadata;let C=B.code,M=`
|
|
39
39
|
-- Module: ${r} (${E}.lua)
|
|
40
40
|
`,P=C;return e||(P=C.split(`
|
|
41
41
|
`).map(x=>x.trim().length>0&&!t?" "+x:x).join(`
|
|
@@ -44,7 +44,7 @@ escrow_ignore {
|
|
|
44
44
|
${P}
|
|
45
45
|
end
|
|
46
46
|
`}return null},b=f("shared"),_=f("client"),y=f("server");(b||_||y)&&(S.push({modName:r,ns:T,shared:b||"",client:_||"",server:y||""}),b&&(a=!0),_&&(g=!0),y&&(L=!0))};d.details&&(console.log(`
|
|
47
|
-
\x1B[1m\x1B[35m\u{1F4E6} Bundling Sequence (${c.length} modules):\x1B[0m`),c.forEach((r,h)=>console.log(` \x1B[90m${(h+1).toString().padStart(2,"0")}.\x1B[0m ${r}`)),console.log(""));for(let r of c)w(r);let F=
|
|
47
|
+
\x1B[1m\x1B[35m\u{1F4E6} Bundling Sequence (${c.length} modules):\x1B[0m`),c.forEach((r,h)=>console.log(` \x1B[90m${(h+1).toString().padStart(2,"0")}.\x1B[0m ${r}`)),console.log(""));for(let r of c)w(r);let F=Xe(),$=(r,h)=>{if(!e)return r;try{return F.Minify(r,{RenameVariables:!0,RenameGlobals:!1,SolveMath:!1})}catch(T){return console.log(`\x1B[33m! Minification failed for ${h}. Emitting unminified code. Error: ${T.message}\x1B[0m`),r}},G=["LT","QBCore","ESX","QBX","exports"],A=new Set,R=r=>{let h=/^([a-zA-Z_][a-zA-Z0-9_]*)\s*=/gm,T;for(;(T=h.exec(r))!==null;){let f=T[1];G.includes(f)||A.add(f)}},N=u.debug===!1||u.debug===void 0;for(let r of S)r.shared&&(r.shared=qn(r.shared,{version:n,disableDebug:N}));if(e)for(let r of S)r.shared&&R(r.shared),r.client&&R(r.client),r.server&&R(r.server);let V=require("crypto"),j=r=>V.createHash("md5").update(r).digest("hex").substring(0,5),D={},X=new Set;for(let r of A){let h=j(r),T=0;for(;X.has(h);)T++,h=j(r+T);X.add(h),D[r]="__"+h}let Y=r=>{if(!r)return r;let h=Object.keys(D);if(h.length===0)return r;let T=h.sort((b,_)=>_.length-b.length).map(b=>b.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),f=new RegExp(`\\[\\[[\\s\\S]*?\\]\\]|'(?:[^'\\\\]|\\\\.)*'|"(?:[^"\\\\]|\\\\.)*"|\\b(${T.join("|")})\\b`,"g");return r.replace(f,(b,_)=>_&&D[_]?D[_]:b)};if(e)for(let r of S)r.shared=Y(r.shared),r.client=Y(r.client),r.server=Y(r.server);let ee={shared:new Set,client:new Set,server:new Set},te=(r,h)=>{if(!r)return r;let T=Object.keys(p).sort((y,E)=>E.length-y.length);if(T.length===0)return r;let f=r,b=new Set,_="";for(let y of T){let E=p[y],B=E?`LT.${E}.`:"LT.",C=m[y]||{};if(e&&C.internal){if(!D[y]){let pe=j(y),Ce=0;for(;X.has(pe);)Ce++,pe=j(y+Ce);X.add(pe),D[y]="__"+pe}let U=D[y],q=new RegExp(`(^|[^a-zA-Z0-9_.:"'])(${y})(\\s*[=().,\\[\\]])`,"g");f=f.replace(q,`$1${U}$3`);continue}let M=`${B}${y}`,P=!!E;if(C.export){if(M=`${B}${C.export}`,C.global){let U=C.global===!0?C.export:C.global;_+=`LT.${U} = ${M}
|
|
48
48
|
`}}else C.global&&(M=`LT.${C.global===!0?y:C.global}`,P=!1);let x=new RegExp(`\\b${y}\\b`).test(r);if(P&&x&&(h?h.add(`LT.${E} = LT.${E} or {}`):b.add(`LT.${E} = LT.${E} or {}`)),C.alias&&x&&C.alias.forEach(U=>{_+=`${B}${U} = ${M}
|
|
49
49
|
`}),!x)continue;let Z=new RegExp(`(^[ \\t]*function\\s+)${y}(\\s*\\()`,"gm");f=f.replace(Z,`$1${M}$2`);let oe=B.replace(/\./g,"\\."),I=new RegExp(`\\b${oe}(${y})(\\s*\\()`,"g");f=f.replace(I,"$1$2");let ie=new RegExp(`(^|[^a-zA-Z0-9_.:"'])(${y})(\\s*\\()`,"g");f=f.replace(ie,(U,q,pe,Ce)=>q.trim().endsWith("function")?U:`${q}${M}${Ce}`)}return h?f+(_.length>0?`
|
|
50
50
|
-- Exports
|
|
@@ -63,7 +63,7 @@ These files were automatically generated and/or minified by LTBridge.
|
|
|
63
63
|
Repository: https://github.com/laot7490/ltbridge
|
|
64
64
|
Last Build Time: ${new Date().toLocaleString()}
|
|
65
65
|
LTBridge Version: ${n}
|
|
66
|
-
`;W.writeFileSync(K.join(_e,"README.txt"),Re);let{injectManifest:Ee}=
|
|
66
|
+
`;W.writeFileSync(K.join(_e,"README.txt"),Re);let{injectManifest:Ee}=en(),Te=r=>`--[[
|
|
67
67
|
* @license LT Bridge
|
|
68
68
|
* ${r.toLowerCase()}.lua
|
|
69
69
|
*
|
|
@@ -85,12 +85,12 @@ for _, modPathSuffix in ipairs(loadSequence) do
|
|
|
85
85
|
if chunk then
|
|
86
86
|
local fn, err = load(chunk, "@@" .. GetCurrentResourceName() .. "/" .. modPath)
|
|
87
87
|
if not fn then
|
|
88
|
-
print("^
|
|
88
|
+
print("^6[LTBridge ${n}] ^1ERROR: Syntax error in module: " .. modPath .. "\\n" .. tostring(err) .. "^7")
|
|
89
89
|
else
|
|
90
90
|
fn()
|
|
91
91
|
end
|
|
92
92
|
else
|
|
93
|
-
print("^
|
|
93
|
+
print("^6[LTBridge ${n}] ^1ERROR: Module file not found: " .. modPathSuffix .. "^7")
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
96
|
`;a&&W.writeFileSync(K.join(H,"shared.lua"),h("Shared",r.shared)),g&&W.writeFileSync(K.join(H,"client.lua"),h("Client",r.client)),L&&W.writeFileSync(K.join(H,"server.lua"),h("Server",r.server)),Ee(k,g,L,a,!0)}else{let r=h=>`LT = LT or {}
|
|
@@ -101,20 +101,20 @@ end
|
|
|
101
101
|
`);a&&W.writeFileSync(K.join(H,"shared.lua"),Te("Shared")+`--- @diagnostic disable
|
|
102
102
|
`+r("shared")+z.shared),g&&W.writeFileSync(K.join(H,"client.lua"),Te("Client")+`--- @diagnostic disable
|
|
103
103
|
`+r("client")+z.client),L&&W.writeFileSync(K.join(H,"server.lua"),Te("Server")+`--- @diagnostic disable
|
|
104
|
-
`+r("server")+z.server),Ee(k,g,L,a,!1)}console.log(`\x1B[32m\u2713\x1B[0m ${c.length} modules bundled in ${Date.now()-i}ms`)}function Ve(k,u){let d=k.split("/"),n="uncategorized",i=k;return k==="__init__"?(n="Core",i="init"):d.length>1?(n=d.slice(0,-1).join("/").replace(/^@/,""),i=d[d.length-1]):k.startsWith("@")?(n=k.replace(/^@/,""),i="init"):i=k.replace(/^@/,""),i==="init"?`imports/${n}/${u}.lua`:`imports/${n}/${i}/${u}.lua`}
|
|
104
|
+
`+r("server")+z.server),Ee(k,g,L,a,!1)}console.log(`\x1B[32m\u2713\x1B[0m ${c.length} modules bundled in ${Date.now()-i}ms`)}function Ve(k,u){let d=k.split("/"),n="uncategorized",i=k;return k==="__init__"?(n="Core",i="init"):d.length>1?(n=d.slice(0,-1).join("/").replace(/^@/,""),i=d[d.length-1]):k.startsWith("@")?(n=k.replace(/^@/,""),i="init"):i=k.replace(/^@/,""),i==="init"?`imports/${n}/${u}.lua`:`imports/${n}/${i}/${u}.lua`}on.exports={rebuildBundle:Un,generateFullApi:tn,getModuleExportMap:nn}});var dn=re((St,fn)=>{var O=require("fs-extra"),ne=require("path"),{version:xe}=we(),{rebuildBundle:de,generateFullApi:ln,getModuleExportMap:Se}=rn(),{resolveDependencies:je}=Ie(),{getModuleRegistry:ae,getModuleData:$e}=ue(),ve=require("prompts"),le=ne.join("ltbridge","ltbridge.config.json");async function Wn(k,u={}){let d=ne.join(k,le);if(O.existsSync(d)&&!(await ve({type:"confirm",name:"value",message:"LTBridge is already initialized. Do you want to overwrite the configuration?",initial:!1})).value){console.log("\x1B[33m! Initialization cancelled.\x1B[0m");return}console.log(`
|
|
105
105
|
\x1B[36m\u26A1 ltbridge v${xe}\x1B[0m \x1B[32mInitializing project...\x1B[0m
|
|
106
|
-
`);let i=u.minify!==!1,l=u.debug===!0,e=!1;if(!process.argv.includes("--no-minify")&&!process.argv.includes("--debug")){let s=await ve([{type:"select",name:"buildMode",message:"Build Output Mode:",choices:[{title:"Individual (Separate files per module)",value:!1},{title:"Bundle (Combine all into 3 files)",value:!0}],initial:0},{type:"select",name:"minify",message:"Bundled code minification:",choices:[{title:"Enabled (Compact production code)",value:!0},{title:"Disabled (Readable development code)",value:!1}],initial:0},{type:"select",name:"debug",message:"Runtime debug mode:",choices:[{title:"Disabled (Recommended for production)",value:!1},{title:"Enabled (Detailed logs and helper outputs)",value:!0}],initial:0}]);s.buildMode!==void 0&&(e=s.buildMode),s.minify!==void 0&&(i=s.minify),s.debug!==void 0&&(l=s.debug)}let c={version:xe,buildAsBundle:e,debug:l,minify:i,modules:[]};
|
|
107
|
-
\x1B[32m\u2713 Created configuration: ${
|
|
108
|
-
`),
|
|
109
|
-
\x1B[36m\u26A1 ltbridge v${xe}\x1B[0m \x1B[32mbuilding for production...\x1B[0m`),de(k,d,u)}function
|
|
110
|
-
\x1B[36m\u26A1 ltbridge v${xe}\x1B[0m \x1B[32mwatching for changes...\x1B[0m`),e(!0),require("chokidar").watch(k,{ignored:[/(^|[\/\\])\../,/node_modules/,/ltbridge[\/\\]modules[\/\\]imports/,/ltbridge[\/\\]api\.lua/,/ltbridge[\/\\]shared\.lua/,/ltbridge[\/\\]client\.lua/,/ltbridge[\/\\]server\.lua/],persistent:!0,ignoreInitial:!0}).on("all",(s,o)=>{if(!o)return;let g=o.replace(/\\/g,"/");if(g.endsWith("ltbridge/ltbridge.config.json")||g.endsWith("ltbridge.config.json"))try{let L=
|
|
106
|
+
`);let i=u.minify!==!1,l=u.debug===!0,e=!1;if(!process.argv.includes("--no-minify")&&!process.argv.includes("--debug")){let s=await ve([{type:"select",name:"buildMode",message:"Build Output Mode:",choices:[{title:"Individual (Separate files per module)",value:!1},{title:"Bundle (Combine all into 3 files)",value:!0}],initial:0},{type:"select",name:"minify",message:"Bundled code minification:",choices:[{title:"Enabled (Compact production code)",value:!0},{title:"Disabled (Readable development code)",value:!1}],initial:0},{type:"select",name:"debug",message:"Runtime debug mode:",choices:[{title:"Disabled (Recommended for production)",value:!1},{title:"Enabled (Detailed logs and helper outputs)",value:!0}],initial:0}]);s.buildMode!==void 0&&(e=s.buildMode),s.minify!==void 0&&(i=s.minify),s.debug!==void 0&&(l=s.debug)}let c={version:xe,buildAsBundle:e,debug:l,minify:i,modules:[]};O.ensureDirSync(ne.dirname(d)),O.writeFileSync(d,JSON.stringify(c,null,2)),console.log(`
|
|
107
|
+
\x1B[32m\u2713 Created configuration: ${le}\x1B[0m`),console.log(`\x1B[90m\u2139 Build Mode: ${e?"bundle":"individual"}\x1B[0m`),console.log(`\x1B[90m\u2139 Minify: ${i?"enabled":"disabled"}\x1B[0m`),console.log(`\x1B[90m\u2139 Debug: ${l?"enabled":"disabled"}\x1B[0m
|
|
108
|
+
`),ln(k)}function be(k){let u=ne.join(k,le);return O.existsSync(u)||(console.log("\x1B[31m\u2716 Not an LTBridge initialized directory. Run 'ltbridge init' first.\x1B[0m"),process.exit(1)),JSON.parse(O.readFileSync(u,"utf-8"))}function ye(k,u){let d=ne.join(k,le);O.writeFileSync(d,JSON.stringify(u,null,2))}function sn(k,u){if(!k.endsWith("*")){let i=an(k,u);return i?[i]:[]}let d=k.replace(/\\/g,"/").replace(/^@/,"").replace(/\*$/,"").toLowerCase(),n=[];for(let i of Object.keys(u)){if(i==="__init__")continue;if(i.replace(/^@/,"").toLowerCase().startsWith(d)){let e=!1,t=$e(i);t&&t.meta&&(e=t.meta.internal===!0),e||n.push(i)}}return n}function an(k,u){if(u[k])return k;let d=k.replace(/\\/g,"/").replace(/^@/,"").toLowerCase(),n=[];for(let e of Object.keys(u)){if(e.replace(/^@/,"").toLowerCase()===d)return e;let c=e.split("/"),s=c[c.length-1].toLowerCase();(s===d||s===d.replace(/^@/,""))&&n.push(e)}if(n.length===1)return n[0];n.length>1&&(console.log(`\x1B[31m\u2716 Ambiguous module name '${k}'.\x1B[0m`),console.log("\x1B[90m\u2139 Did you mean one of these?\x1B[0m"),n.forEach(e=>console.log(` - ${e.replace(/^@/,"")}`)),process.exit(1));let i=Se(),l=k.replace(/^LT\./,"");if(i[l]){let e=i[l];if(e.length===1)return e[0];console.log(`\x1B[31m\u2716 Ambiguous export name '${k}' provided by multiple modules.\x1B[0m`),console.log("\x1B[90m\u2139 Please use the full module path to add it:\x1B[0m"),e.forEach(t=>console.log(` - ltbridge add ${t.replace(/^@/,"")}`)),process.exit(1)}return null}function Kn(k,u){let d=be(k),n=ae(),i=sn(u,n);i.length===0&&(console.log(`\x1B[31m\u2716 No modules found matching '${u}'.\x1B[0m`),process.exit(1));let l=0,e=!1;for(let t of i){if(t==="__init__")continue;let c=!1,s=$e(t);if(s&&s.meta&&(c=s.meta.internal===!0),c){u.endsWith("*")||(console.log(`\x1B[31m\u2716 Cannot manually add internal ghost module '${t}'.\x1B[0m`),console.log("\x1B[90m\u2139 Ghost modules are active and managed purely as auto-dependencies behind the scenes.\x1B[0m"),e=!0);continue}if(d.modules.includes(t)){u.endsWith("*")||console.log(`\x1B[90m\u2139 Module '${t}' is already added.\x1B[0m`);continue}d.modules.push(t),console.log(`\x1B[32m\u2713 Added module '${t}'.\x1B[0m`),l++}l>0?(ye(k,d),de(k,d,{skipApi:!0})):u.endsWith("*")&&console.log("\x1B[90m\u2139 All matching modules are already added.\x1B[0m")}function zn(k,u){let d=be(k),n=ae(),i=sn(u,n);i.length===0&&(console.log(`\x1B[31m\u2716 No modules found matching '${u}'.\x1B[0m`),process.exit(1));let l=0;for(let e of i){if(!d.modules.includes(e)){u.endsWith("*")||console.log(`\x1B[90m\u2139 Module '${e}' is not currently added.\x1B[0m`);continue}d.modules=d.modules.filter(t=>t!==e),console.log(`\x1B[33m- Removed module '${e}'.\x1B[0m`),l++}l>0?(ye(k,d),de(k,d,{skipApi:!0})):u.endsWith("*")&&console.log("\x1B[90m\u2139 No matching modules were currently added.\x1B[0m")}function Hn(k,u={}){let d=be(k);console.log(`
|
|
109
|
+
\x1B[36m\u26A1 ltbridge v${xe}\x1B[0m \x1B[32mbuilding for production...\x1B[0m`),de(k,d,u)}function cn(k){let u=new Set;function d(n){if(!O.existsSync(n))return;let i=O.readdirSync(n);for(let l of i){if(l==="ltbridge"||l==="node_modules"||l===".git")continue;let e=ne.join(n,l);if(O.statSync(e).isDirectory())d(e);else if(l.endsWith(".lua")){let c=O.readFileSync(e,"utf8"),s=/LT\.([a-zA-Z0-9_.]+)/g,o;for(;(o=s.exec(c))!==null;){let g=o[1];u.add(g);let L=g.split("."),a="";for(let p of L)a=a?a+"."+p:p,u.add(a)}}}}return d(k),u}function un(k){let u=ae(),d=Object.keys(u),n=Se(),i=new Set;for(let l of k){let e="@"+l.replace(/\./g,"/");if(d.includes(e)){i.add(e);continue}if(n[l]){let t=n[l];if(t.length===1)i.add(t[0]);else if(l.includes(".")){let c=l.split(".")[0].toLowerCase(),s=t.find(o=>o.toLowerCase().includes(c));s&&i.add(s)}else{let c=require("fs"),s=require("path"),o=t.find(g=>{let L=u[g];if(!L)return!1;let a=s.join(L,"server.lua");return c.existsSync(a)&&c.readFileSync(a,"utf8").includes("@ltbridge global")});i.add(o||t[0])}}}return i}function Zn(k){let u=be(k);console.log("\x1B[90m\u2139 Scanning project for unused LT modules...\x1B[0m");let d=cn(k),n=un(d),i=[],l=[];for(let e of u.modules)n.has(e)?i.push(e):l.push(e);l.length>0?(console.log(`\x1B[32m\u2713 Pruned ${l.length} unused modules: ${l.join(", ")}\x1B[0m`),u.modules=i,ye(k,u)):console.log("\x1B[90m\u2139 No unused modules found. Everything is tightly integrated!\x1B[0m"),de(k,u,{skipApi:!0})}var fe=null;function Jn(k,u={}){let d=ae(),n=Object.keys(d),i="",l=ne.join(k,le);O.existsSync(l)&&(i=O.readFileSync(l,"utf-8"));function e(s=!1){let o=be(k),g=cn(k),L=un(g),a=!1,p=new Set(o.modules),m=[];for(let w of L)p.has(w)||(p.add(w),m.push(w),a=!0);let S=[];for(let w of o.modules)L.has(w)||(p.delete(w),S.push(w),a=!0);(a||s)&&(a&&(o.modules=Array.from(p)),i=JSON.stringify(o,null,2),a&&ye(k,o),de(k,o,{skipApi:!0,...u}))}console.log(`
|
|
110
|
+
\x1B[36m\u26A1 ltbridge v${xe}\x1B[0m \x1B[32mwatching for changes...\x1B[0m`),e(!0),require("chokidar").watch(k,{ignored:[/(^|[\/\\])\../,/node_modules/,/ltbridge[\/\\]modules[\/\\]imports/,/ltbridge[\/\\]api\.lua/,/ltbridge[\/\\]shared\.lua/,/ltbridge[\/\\]client\.lua/,/ltbridge[\/\\]server\.lua/],persistent:!0,ignoreInitial:!0}).on("all",(s,o)=>{if(!o)return;let g=o.replace(/\\/g,"/");if(g.endsWith("ltbridge/ltbridge.config.json")||g.endsWith("ltbridge.config.json"))try{let L=O.readFileSync(l,"utf-8");if(L===i)return;i=L,fe&&clearTimeout(fe),fe=setTimeout(()=>{e(!0)},300);return}catch{return}g.includes("ltbridge/")&&!g.endsWith("ltbridge.config.json")||(fe&&clearTimeout(fe),fe=setTimeout(()=>{try{e()}catch(L){console.log(`\x1B[31m\u2716 Watcher error: ${L.message}\x1B[0m`)}},300))})}function Qn(k){let u=ae(),d=Object.keys(u).filter(a=>{if(a==="__init__")return!1;let p=$e(a);return!(p&&p.meta&&p.meta.internal===!0)}),n=null,i=ne.join(k,le);if(O.existsSync(i))try{n=JSON.parse(O.readFileSync(i,"utf-8"))}catch{}let l=n?new Set(n.modules):new Set,e=new Set,t={};if(n&&n.modules){let{graph:a}=je(n.modules,Se());for(let[p,m]of Object.entries(a))for(let S of m)e.add(S),t[S]||(t[S]=[]),t[S].includes(p)||t[S].push(p)}let c=new Set(d),s=new Set([...l].filter(a=>c.has(a))),o=new Set([...e].filter(a=>c.has(a)&&!s.has(a))),g=s.size+o.size;if(console.log(`
|
|
111
111
|
\x1B[1m\x1B[36m\u2139 LTBridge Modules List (${s.size} manual + ${o.size} auto = ${g} active / ${d.length} total)\x1B[0m
|
|
112
112
|
`),d.length===0){console.log(" No modules found in the repository.");return}let L={};for(let a of d){let p=u[a],m=[];if(p){let F=p.split("/");for(let $=0;$<F.length-1;$++){let G=F[$];(G.startsWith("@")||G.startsWith("#"))&&(G=G.substring(1)),m.push(G)}}let S=m.length>0?m.join(" / "):"Uncategorized",w=a.split("/").pop();L[S]||(L[S]=[]),L[S].push({mod:a,name:w})}for(let a of Object.keys(L).sort()){console.log(`
|
|
113
113
|
\x1B[1m\x1B[35m\u{1F4C1} ${a}\x1B[0m`);let p=L[a],S="@"+a.split(" / ").pop(),F=(p.length>1?p.filter($=>$.mod!==S):p).sort(($,G)=>$.name.localeCompare(G.name));for(let{mod:$,name:G}of F){let A=l.has($),R=e.has($),N=" ",V="\x1B[90m";A?(N="\u2714",V="\x1B[32m"):R&&(N="\u2699",V="\x1B[33m"),process.stdout.write(` ${V}${N} ${G.padEnd(30)}\x1B[0m`),R&&!A?process.stdout.write(" \x1B[90m\u2699 Auto-Dependency\x1B[0m"):R&&A&&process.stdout.write(" \x1B[90m(Also a Dependency)\x1B[0m"),process.stdout.write(`
|
|
114
114
|
`)}}console.log(`
|
|
115
115
|
\x1B[90m(\u2714 = Installed | \u2699 = Auto Dependency)\x1B[0m
|
|
116
|
-
`)}async function
|
|
116
|
+
`)}async function Xn(k){let u=ae(),d=Object.keys(u).filter(m=>{if(m==="__init__")return!1;let S=$e(m);return!(S&&S.meta&&S.meta.internal===!0)}),n=null,i=ne.join(k,le);if(O.existsSync(i))try{n=JSON.parse(O.readFileSync(i,"utf-8"))}catch{}if(!n){console.log("\x1B[31m\u2716 Not an LTBridge initialized directory. Run 'ltbridge init' first.\x1B[0m");return}let l=new Set(n.modules||[]),{graph:e}=je(n.modules||[],Se()),t=new Set,c={};for(let[m,S]of Object.entries(e))for(let w of S)t.add(w),c[w]||(c[w]=[]),c[w].includes(m)||c[w].push(m);let s={};for(let m of d){let S=u[m],w=[];if(S){let G=S.split("/");for(let A=0;A<G.length-1;A++){let R=G[A];(R.startsWith("@")||R.startsWith("#"))&&(R=R.substring(1)),w.push(R)}}let F=w.length>0?w.join(" / "):"Uncategorized",$=m.split("/").pop();s[F]||(s[F]=[]),s[F].push({mod:m,name:$})}let o=[];for(let m of Object.keys(s).sort()){o.push({title:`\x1B[1m\x1B[36m--- ${m.toUpperCase()} ---\x1B[0m`,value:`__group_${m}__`,disabled:!0});let S=s[m],F="@"+m.split(" / ").pop(),G=(S.length>1?S.filter(A=>A.mod!==F):S).sort((A,R)=>A.name.localeCompare(R.name));for(let{mod:A,name:R}of G){let N=l.has(A),V=t.has(A),j=R;V&&!N?j=`${j} \x1B[90m(\u2699 Auto-Dependency [INCLUDED])\x1B[0m`:V&&N&&(j=`${j} \x1B[90m(Also a Dependency)\x1B[0m`),o.push({title:j,value:A,selected:N,disabled:V&&!N})}}let g=await ve({type:"multiselect",name:"selectedModules",message:"Select LTBridge modules",choices:o,instructions:!1,hint:"- [Space] select. [Return] submit",min:0});if(!g.selectedModules){console.log("\x1B[90m\u2139 Module selection cancelled.\x1B[0m");return}let L=g.selectedModules.filter(m=>!m.startsWith("__group_")),a=L.filter(m=>!l.has(m)),p=Array.from(l).filter(m=>!L.includes(m));if(a.length===0&&p.length===0){console.log("\x1B[90m\u2139 No changes made to module selection.\x1B[0m");return}a.length>0&&console.log(`\x1B[32m\u2713 Adding: ${a.join(", ")}\x1B[0m`),p.length>0&&console.log(`\x1B[33m- Removing: ${p.join(", ")}\x1B[0m`),n.modules=L,ye(k,n),de(k,n,{skipApi:!0})}function Yn(k,u){let d=ae(),n=an(u,d);n||(console.log(`\x1B[31m\u2716 Module '${u}' does not exist in the repository.\x1B[0m`),process.exit(1));let i=ne.join(k,le);if(!O.existsSync(i)){console.log("\x1B[31m\u2716 Not an LTBridge initialized directory. Run 'ltbridge init' first.\x1B[0m");return}let l={modules:[]};try{l=JSON.parse(O.readFileSync(i,"utf-8"))}catch{}let e=new Set(l.modules||[]),{graph:t}=je(l.modules||[],Se()),c={};for(let[L,a]of Object.entries(t))for(let p of a)c[p]||(c[p]=[]),c[p].includes(L)||c[p].push(L);let s=e.has(n),o=c[n]||[],g=o.length>0;if(console.log(`
|
|
117
117
|
\x1B[1m\x1B[36m\u2139 Why is '${n}' included in your project?\x1B[0m`),!s&&!g){console.log(` \x1B[90m\u25CB This module is NOT currently included in your project build.\x1B[0m
|
|
118
|
-
`);return}if(s&&console.log(" \x1B[32m\u2714 You explicitly added it to your ltbridge.config.json\x1B[0m"),g){console.log(" \x1B[33m\u2699 It is automatically included as a dependency for the following modules:\x1B[0m");for(let L of o)console.log(` - ${L}`)}console.log("")}
|
|
119
|
-
\x1B[36m\u26A1 ltbridge\x1B[0m \x1B[32mRegenerating API stubs...\x1B[0m`),
|
|
120
|
-
`)});Q.command("add <name>").description("Add a module to your project").action(k=>{
|
|
118
|
+
`);return}if(s&&console.log(" \x1B[32m\u2714 You explicitly added it to your ltbridge.config.json\x1B[0m"),g){console.log(" \x1B[33m\u2699 It is automatically included as a dependency for the following modules:\x1B[0m");for(let L of o)console.log(` - ${L}`)}console.log("")}fn.exports={initProject:Wn,addModule:Kn,removeModule:zn,refreshModules:Hn,pruneModules:Zn,watchProject:Jn,generateFullApi:ln,listModules:Qn,interactiveSelect:Xn,explainModule:Yn}});var{program:Q}=require("commander"),{version:et}=we(),{initProject:nt,addModule:tt,removeModule:ot,refreshModules:it,pruneModules:rt,watchProject:lt,generateFullApi:Tn,listModules:st,interactiveSelect:at,explainModule:ct}=dn();Q.name("ltbridge").description("LT Bridge CLI tool for managing Lua modules and intellisense stubs").version(et);Q.command("init").description("Initialize LTBridge in the current directory and generate Master API stubs").option("--no-minify","Disable minification").option("--debug","Enable debug mode").action(async k=>{let u=process.cwd();await nt(u,k)});Q.command("build").alias("refresh").alias("install").alias("sync").description("Resolve dependencies, rebuild bundles, and regenerate API stubs").option("-w, --watch","Watch project mode for continuous bundling").option("-d, --details","Show detailed bundling sequence").action(k=>{let u=process.cwd();k.watch?lt(u,k):it(u,k)});Q.command("api").description("Regenerate the API stubs for IDE intellisense (Internal use for developers)").action(()=>{let k=process.cwd();console.log(`
|
|
119
|
+
\x1B[36m\u26A1 ltbridge\x1B[0m \x1B[32mRegenerating API stubs...\x1B[0m`),Tn(k),console.log(`\x1B[32m\u2713 API reference successfully updated.\x1B[0m
|
|
120
|
+
`)});Q.command("add <name>").description("Add a module to your project").action(k=>{tt(process.cwd(),k)});Q.command("remove <name>").description("Remove a module from your project").action(k=>{ot(process.cwd(),k)});Q.command("why <name>").alias("explain").description("Explain why a module is included in your project (dependency graph)").action(k=>{ct(process.cwd(),k)});Q.command("list").description("List installed and available modules").action(()=>{st(process.cwd())});Q.command("prune").description("Prune unused modules from your project bundles").action(()=>{rt(process.cwd())});Q.command("api").description("Standalone: Regenerate the Comprehensive Master API stubs").action(()=>{Tn(process.cwd())});process.argv.length<=2?at(process.cwd()):Q.parse(process.argv);
|