@laot/bridge 1.3.0 → 1.3.3
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/README.md +7 -1
- package/dist/ltbridge.js +52 -42
- package/dist/modules.dat +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
[](https://github.com/laot7490/ltbridge/releases)
|
|
6
6
|
[](https://github.com/laot7490/ltbridge/graphs/contributors)
|
|
7
7
|
[](https://github.com/laot7490/ltbridge/blob/main/LICENSE)
|
|
8
|
+
[](https://laot7490.gitbook.io/ltbridge)
|
|
8
9
|
|
|
9
10
|
A next-generation **FiveM Script Bridge & Module Manager** designed to be incredibly fast, clean, and bloat-free.
|
|
10
11
|
|
|
11
|
-
Unlike traditional monolithic libraries that force every script to load hundreds of unused functions into memory, **LTBridge** acts as a smart build tool. It lets you maintain a central repository of your favorite utilities (like Inventory, Framework, Notify) and compiles **only the exact code you actually use** right into your FiveM resource.
|
|
12
|
+
Unlike traditional monolithic libraries that force every script to load hundreds of unused functions into memory, **LTBridge** acts as a smart build tool. It lets you maintain a central repository of your favorite utilities (like Inventory, Framework, Notify) and compiles **only the exact code you actually use** right into your FiveM resource.
|
|
12
13
|
|
|
13
14
|
By eliminating slow cross-resource exports and memory bloat, LTBridge helps you build highly independent, lightning-fast scripts with a perfect development experience.
|
|
14
15
|
|
|
@@ -53,6 +54,8 @@ npx @laot/bridge [command]
|
|
|
53
54
|
local name, lastname = LT.Framework.GetPlayerName()
|
|
54
55
|
```
|
|
55
56
|
|
|
57
|
+
*For the full walkthrough, see [Quick Start on GitBook](https://laot7490.gitbook.io/ltbridge/getting-started/quick-start).*
|
|
58
|
+
|
|
56
59
|
## ⚙️ Configuration (`ltbridge/ltbridge.config.json`)
|
|
57
60
|
|
|
58
61
|
When you run `init`, LTBridge creates a simple JSON config.
|
|
@@ -68,6 +71,8 @@ When you run `init`, LTBridge walks you through bundle mode, minify, and debug o
|
|
|
68
71
|
|
|
69
72
|
## 🛠️ Commands
|
|
70
73
|
|
|
74
|
+
Full command reference with examples: [CLI Commands on GitBook](https://laot7490.gitbook.io/ltbridge/cli/commands).
|
|
75
|
+
|
|
71
76
|
| Command | Alias | Description |
|
|
72
77
|
| --- | --- | --- |
|
|
73
78
|
| `ltbridge` | - | **Interactive Menu**: Manage your modules visually. |
|
|
@@ -108,3 +113,4 @@ A huge thanks to the **[community_bridge](https://github.com/TheOrderFivem)** pr
|
|
|
108
113
|
> ```json
|
|
109
114
|
> "Lua.workspace.ignoreDir": ["**/ltbridge/modules/**"]
|
|
110
115
|
> ```
|
|
116
|
+
> See also: [IDE Setup on GitBook](https://laot7490.gitbook.io/ltbridge/getting-started/ide-setup) for autocomplete and workspace configuration.
|
package/dist/ltbridge.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
\x1B[33m! Circular dependency detected involving '${s}'.\x1B[0m`);return}if(t.add(s),!a[s]){console.log(`\x1B[31m\u2716 Trying to resolve '${s}' but it does not exist in LTBridge.\x1B[0m`),t.delete(s);return}let c=Xe(s);e[s]=c;for(let f of c)o(f);t.delete(s),n.add(s),r.push(s)}for(let s of u)o(s);return{sequence:r,graph:e}}Ye.exports={resolveDependencies:Jn,getModuleDependencies:Xe}});var ln=
|
|
2
|
+
var U=(u,i)=>()=>(i||u((i={exports:{}}).exports,i),i.exports);var xe=U((ro,On)=>{On.exports={name:"@laot/bridge",version:"1.3.3",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 Je=U((lo,He)=>{var jn=/__LT_VERSION\s*=\s*'[^']*'/g,qn=/__LT_DISABLE_DEBUG\s*=\s*(true|false)/g;function Un(u,{version:i,disableDebug:a}={}){if(!u)return u;let n=u;return i&&(n=n.replace(jn,`__LT_VERSION = '${i}'`)),a!==void 0&&(n=n.replace(qn,`__LT_DISABLE_DEBUG = ${a?"true":"false"}`)),n}He.exports={applyBuildConstants:Un}});var ne=U((so,Qe)=>{var Ze=require("fs"),Wn=require("path"),Be=null;function Ne(){if(Be)return Be;let u=Wn.join(__dirname,"..","dist","modules.dat");return Ze.existsSync(u)||(console.log("\x1B[31m\u2716 LTBridge is not compiled. Please run 'npm run build' first.\x1B[0m"),process.exit(1)),Be=JSON.parse(Ze.readFileSync(u,"utf8")),Be}function Dn(){return Ne().registry}function Kn(u){return Ne().modules[u]}Qe.exports={getModuleRegistry:Dn,getDatabase:Ne,getModuleData:Kn}});var Ge=U((uo,Ye)=>{var{getModuleRegistry:zn,getModuleData:Hn}=ne();function Xe(u){let i=Hn(u);return i?Array.isArray(i.dependencies)?i.dependencies:i.meta&&Array.isArray(i.meta.dependencies)?i.meta.dependencies:[]:[]}function Jn(u,i){let a=zn(),n=new Set,t=new Set,r=[],e={};function o(s){if(n.has(s))return;if(t.has(s)){console.log(`
|
|
3
|
+
\x1B[33m! Circular dependency detected involving '${s}'.\x1B[0m`);return}if(t.add(s),!a[s]){console.log(`\x1B[31m\u2716 Trying to resolve '${s}' but it does not exist in LTBridge.\x1B[0m`),t.delete(s);return}let c=Xe(s);e[s]=c;for(let f of c)o(f);t.delete(s),n.add(s),r.push(s)}for(let s of u)o(s);return{sequence:r,graph:e}}Ye.exports={resolveDependencies:Jn,getModuleDependencies:Xe}});var ln=U((ao,$e)=>{var Se=console.log,W=function(u,i){if(!u)throw i};function Zn(u,i){if(!u)return 0;var a=u.toString().split(".");return a.length>1?parseInt(a[0],i)+parseInt(a[1],i)/Math.pow(i,a[1].length):parseInt(a[0],i)}var Qn=[" ",`
|
|
4
4
|
`," ","\r"],Xn={r:"\r",n:`
|
|
5
5
|
`,t:" ",'"':'"',"'":"'","\\":"\\"},en=new Proxy(Xn,{get(u,i){return Zn(i)}}),Yn=["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"],me=["0","1","2","3","4","5","6","7","8","9"],et=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","A","B","C","D","E","F"],nt=["+","-","*",")",";","/","^","%","#",",","{","}",":","[","]","(",".","`"],tt=["~","=",">","<"],ot=["+","-","*","/","^","..","%","//"],it=["+=","-=","*=","/=","^=","..=","%=","//="],tn=["and","break","do","else","elseif","end","false","for","function","goto","if","in","local","nil","not","or","repeat","return","then","true","until","while","continue"],ke=["continue","goto"],rt=["else","elseif","until","end"],lt=["-","not","#","~"],on=["+","-","*","/","%","^","#","//","&","|","~","<<",">>","..",".",":",">","<","<=",">=","~=","==","+=","-=","*=","/=","%=","^=","..=","//=","and","or"],st=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 ut(u){let i=0,a=u.length,n=[];function t(d){return d=d||0,i<=a?u.substr(i+d,1):""}function r(){if(i<=a){let d=u.substr(i,1);return i++,d}else return""}function e(d){let p=0,h=1,y=1;for(;p<=i;)u.substr(p,1)==`
|
|
6
6
|
`?(h++,y=1):y++;let w;for(w=0;w<n.length;w++){let G=n[w];Se(`${G.Type}<${G.Source}>`)}throw`file<${h}:${y}>: ${d}`}function o(d){for(;;){let p=r();if(p=="")e("Unfinished long string.");else if(p=="]"){let h=!0,y;for(y=1;y<=d;y++)if(t()=="=")i++;else{h=!1;break}if(h&&r()=="]")return}}}function s(){let d=i;for(;t()=="=";)i++;if(t()=="[")return i++,i-d-1;i=d}let c=0,f=0,S=0;function k(d){S++;let p=u.substr(f,i-f),h=null;d=="Number"&&(p=p.replace(/[\_]+/g,""),p.substr(0,2).toLowerCase()=="0x"?(h="hex",parseInt(p,16)<999999999999&&(p=parseInt(p,16))):p.substr(0,2).toLowerCase()=="0b"&&(h="bin",parseInt(p.substr(2),2)<999999999999&&(p=parseInt(p.substr(2),2))));let y={Type:d,LeadingWhite:u.substr(c,f-c),Source:p};return h!==null&&(y.NType=h),n.push(y),c=i,f=i,y}for(;;){for(c=i;;){let p=t();if(p=="")break;if(p=="-")if(t(1)=="-")if(i+=2,t()=="["){i++;let h=s();if(h!=null)o(h),c=i;else for(;;){let y=r();if(y==""||y==`
|
|
7
7
|
`)break}}else for(;;){let h=r();if(h==""||h==`
|
|
8
8
|
`)break}else break;else if(Qn.includes(p))i++;else break}f=i;let d=r();if(d==""){k("Eof");break}else if(d=="'"||d=='"'){for(;;){let p=r();if(p=="\\"){let h=r();if(en[h]==null)throw`Invalid Escape Sequence \`${h}\`.`}else{if(p==d)break;if(p=="")throw"Unfinished string!"}}k("String")}else if(d=="`"){for(;;){let p=r();if(p=="\\"){let h=r();if(en[h]==null)throw`Invalid Escape Sequence \`${h}\`.`}else{if(p==d)break;if(p=="")throw"Unfinished string!"}}k("Hash")}else if(Yn.includes(d)){for(;Pe.includes(t());)i++;tn.includes(u.substr(f,i-f))?k("Keyword"):k("Ident")}else if(me.includes(d)||d=="."&&me.includes(t())){if(d=="0"&&t().toLowerCase()=="x")for(i++;et.includes(t())||t()==="_";)i++;else if(d=="0"&&t().toLowerCase()=="b")for(i++;t()==="0"||t()==="1"||t()==="_";)i++;else{for(;me.includes(t())||t()==="_";)i++;if(t()==".")for(i++;me.includes(t());)i++;if(t()=="e"||t()=="E")for(i++,(t()=="-"||t()=="+")&&i++;me.includes(t());)i++}k("Number")}else if(d=="["){let p=s();p!=null?(o(p),k("String")):k("Symbol")}else if(d==".")t()=="."&&(r(),(t()=="."||t()=="=")&&r()),k("Symbol");else if(d+t()=="//")r(),t()=="="&&r(),k("Symbol");else if(d+t()=="::")r(),k("Symbol");else if(on.includes(d+t()))r(),k("Symbol");else if(tt.includes(d))t()=="="&&i++,k("Symbol");else if(ot.includes(d)&&t()=="=")r(),k("Symbol");else if(nt.includes(d))k("Symbol");else throw`Bad symbol \`${d}\` in source. ${i}`}return n}function at(u){let i=ut(u),a=0;function n(){let m=i[a];return a<i.length&&a++,m}function t(m){return m=a+(m||0),i[m]||i[i.length-1]}function r(m){let g=1,l=0,T=0;for(;;){let L=i[T],b;L==m?b=L.LeadingWhite:b=L.LeadingWhite+L.Source;let _;for(_=0;_<=b.length;_++)b.substr(_,1)==`
|
|
9
|
-
`?(g++,l=0):l++;if(L==m)break;T++}return`${g}:${l+1}`}function e(){let m=t();return`<${m.Type} \`${m.Source}\`> at: ${r(m)}`}function o(){let m=t();return m.Type=="Eof"||m.Type=="Keyword"&&rt.includes(m.Source)}function s(){return lt.includes(t().Source)||!1}function c(){return on.includes(t().Source)||!1}function f(m,g){let l=t();if(l.Type==m&&(g==null||l.Source==g))return n();if(l.Type=="Keyword"&&m=="Ident"&&ke.includes(l.Source)&&(g==null||l.Source==g))return n();{let T;for(T=-3;T<=3;T++)Se(`Tokens[${T}] = \`${t(T).Source}\``);throw g?`${r(l)}: \`${g}\` expected.`:`${r(l)}: ${m} expected.`}}function S(m){let g=m.GetFirstToken,l=m.GetLastToken,T=m;return m.GetFirstToken=function(){let L=g(T);return D(L),L},m.GetLastToken=function(){let L=l(T);return D(L),L},m}let k,d;function p(m,g){let l=[d(m,g)],T=[];for(;t().Source==",";)T.push(n()),l.push(d(m,g));return[l,T]}function h(m,g){let l=t();if(l.Source=="("){let T=n(),L=d(m,g),b=f("Symbol",")"),_;return _=S({Type:"ParenExpr",Expression:L,Token_OpenParen:T,Token_CloseParen:b,GetFirstToken:()=>_.Token_OpenParen,GetLastToken:()=>_.Token_CloseParen}),_}else if(l.Type=="Ident"||l.Type=="Keyword"&&ke.includes(l.Source)){let T;return T=S({Type:"VariableExpr",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),m[T.Token.Source]!=null&&m[T.Token.Source]?.Tokens?.push!=null?(m[T.Token.Source].Tokens.push(T.Token),m[T.Token.Source].UseCountIncrease()):g[T.Token.Source]!=null&&g[T.Token.Source]?.Tokens?.push!=null&&(g[T.Token.Source].Tokens.push(T.Token),g[T.Token.Source].UseCountIncrease()),T}else throw Se(e()),`${r(l)}: Unexpected symbol. ${l.Type} ${l.Source}`}function y(m,g){let l=f("Symbol","{"),T=[],L=[];for(;t().Source!="}";){let E,C;if(t().Source=="["){let F=n(),$=d(m,g),B=f("Symbol","]"),x=f("Symbol","="),V=d(m,g);E=$.Token&&$.Token.Source,C=V,T.push({EntryType:"Index",Index:$,Value:V,Token_OpenBracket:F,Token_CloseBracket:B,Token_Equals:x})}else if((t().Type=="Ident"||t().Type=="Keyword"&&ke.includes(t().Source))&&t(1).Source=="="){let F=n(),$=n(),B=d(m,g);E=F,C=B,T.push({EntryType:"Field",Field:F,Value:B,Token_Equals:$})}else{let F=d(m,g);T.push({EntryType:"Value",Value:F})}if(t().Source==","||t().Source==";")L.push(n());else break}let b=f("Symbol","}"),_;return _=S({Type:"TableLiteral",EntryList:T,Token_SeperatorList:L,Token_OpenBrace:l,Token_CloseBrace:b,GetFirstToken:()=>_.Token_OpenBrace,GetLastToken:()=>_.Token_CloseBrace}),_}function w(m,g){let l=[],T=[];if(t().Type=="Ident"||t().Type=="Keyword"&&ke.includes(t().Source)){let L=n();if(g&&t().Source=="<"&&t(2).Source==">"){let b=t(1).Source;L.Attribute={LeadingWhite:t().LeadingWhite,Source:`<${b}>`},n(),n(),n()}l.push(L)}else if(t().Source=="..."&&m)return[l,T,n()];for(;t().Source==",";){if(T.push(n()),t().Source=="..."&&m)return[l,T,n()];{let L=f("Ident");if(g&&t().Source=="<"&&t(2).Source==">"){let b=t(1).Source;L.Attribute={LeadingWhite:t().LeadingWhite,Source:`<${b}>`},n(),n(),n()}l.push(L)}}return[l,T]}function G(m,g,l){let T=k(g,l),L=t();if(L.Type=="Keyword"&&L.Source==m)return n(),[T,L];throw Se(L.Type,L.Source),`${r(L)}: ${m} expected.`}function R(m,g,l,T){let L=n(),b,_;if(!m){b=[],_=[];let A=f("Ident");for(b.push(A);t().Source==".";)_.push(n()),b.push(f("Ident"));t().Source==":"&&(_.push(n()),b.push(f("Ident")))}let E=f("Symbol","("),[C,F,$]=w(!0),B=f("Symbol",")"),[x,V]=G("end",g,l),P;return P=S({Type:m==!0?"FunctionLiteral":"FunctionStat",NameChain:b,ArgList:C,Body:x,Token_Function:L,Token_NameChainSeperator:_,Token_OpenParen:E,Token_Varg:$,Token_ArgCommaList:F,Token_CloseParen:B,Token_End:V,GetFirstToken:()=>P.Token_Function,GetLastToken:()=>P.Token_End}),P}function j(m,g){let l=t();if(l.Source=="("){let T=n(),L=[],b=[];for(;t().Source!=")"&&(L.push(d(m,g)),t().Source==",");)b.push(n());let _=f("Symbol",")"),E;return E=S({CallType:"ArgCall",ArgList:L,Token_CommaList:b,Token_OpenParen:T,Token_CloseParen:_,GetFirstToken:()=>E.Token_OpenParen,GetLastToken:()=>E.Token_CloseParen}),E}else if(l.Source=="{"){let T;return T=S({CallType:"TableCall",TableExpr:d(m,g),GetFirstToken:()=>T.TableExpr.GetFirstToken(),GetLastToken:()=>T.TableExpr.GetLastToken()}),T}else if(l.Type=="String"){let T;return T=S({CallType:"StringCall",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else throw"Function arguments expected."}function te(m,g){let l=h(m,g);for(D(l,"nil prefixexpr");;){let T=t();if(T.Source=="."){let L=n(),b=f("Ident"),_;_=S({Type:"FieldExpr",Base:l,Field:b,Token_Dot:L,GetFirstToken:()=>_.Base.GetFirstToken(),GetLastToken:()=>_.Field}),l=_}else if(T.Source==":"){let L=n(),b=f("Ident"),_=j(m,g),E;E=S({Type:"MethodExpr",Base:l,Method:b,FunctionArguments:_,Token_Colon:L,GetFirstToken:()=>E.Base.GetFirstToken(),GetLastToken:()=>E.FunctionArguments.GetLastToken()}),l=E}else if(T.Source=="["){let L=n(),b=d(m,g),_=f("Symbol","]"),E;E=S({Type:"IndexExpr",Base:l,Index:b,Token_OpenBracket:L,Token_CloseBracket:_,GetFirstToken:()=>E.Base.GetFirstToken(),GetLastToken:()=>E.Token_CloseBracket}),l=E}else if(T.Source=="{"||T.Source=="("||T.Type=="String"){let L;L=S({Type:"CallExpr",Base:l,FunctionArguments:j(m,g),GetFirstToken:()=>L.Base.GetFirstToken(),GetLastToken:()=>L.FunctionArguments.GetLastToken()}),l=L}else if(it.includes(T.Source)){let L=n(),b=d(m,g),_;_=S({Type:"CompoundStat",Base:l,Token_Compound:L,Rhs:b,Lhs:l,GetFirstToken:()=>_.Base.GetFirstToken(),GetLastToken:()=>_.Rhs.GetLastToken()}),l=_}else return l}}function H(m,g){let l=t();if(l.Type=="Number"){let T;return T=S({Type:"NumberLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(l.Type=="String"){let T;return T=S({Type:"StringLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(l.Type=="Hash"){let T;return T=S({Type:"HashLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(l.Source=="nil"){let T;return T=S({Type:"NilLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(l.Source=="true"||l.Source=="false"){let T;return T=S({Type:"BooleanLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(l.Source=="..."){let T;return T=S({Type:"VargLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else return l.Source=="{"?y(m,g):l.Source=="function"?R(!0,m,g):l.Source=="if"?Ee(!0,m,g):te(m,g)}function q(m,g,l){let T;if(s()){let L=n(),b=q(st,g,l),_;_=S({Type:"UnopExpr",Token_Op:L,Rhs:b,GetFirstToken:()=>_.Token_Op,GetLastToken:()=>_.Rhs.GetLastToken()}),T=_}else T=H(g,l),D(T,"nil sipleexpr");for(;c()&&Me[t().Source]!=null&&Me[t().Source][0]>m;){let L=n(),b=q(Me[L.Source][1],g,l);D(b,"RhsNeeded");let _;_=S({Type:"BinopExpr",Lhs:T,Rhs:b,Token_Op:L,GetFirstToken:()=>_.Lhs.GetFirstToken(),GetLastToken:()=>_.Rhs.GetLastToken()}),T=_}return T}d=(m,g)=>q(0,m,g);function re(m,g){let l=te(m,g);if(l.Type=="MethodExpr"||l.Type=="CallExpr"){let T;return T=S({Type:"CallExprStat",Expression:l,GetFirstToken:()=>T.Expression.GetFirstToken(),GetLastToken:()=>T.Expression.GetLastToken()}),T}else{if(l.Type=="CompoundStat")return l;{let T=[l],L=[];for(l.IsStat=!0;t().Source==",";){L.push(n());let F=te(m,g);if(F.Type=="MethodExpr"||F.Type=="CallExpr")throw"Bad left hand side of asignment";F.IsStat=!0,T.push(F)}let b=f("Symbol","="),_=[d(m,g)],E=[];for(;t().Source==",";)E.push(n()),_.push(d(m,g));let C;return C=S({Type:"AssignmentStat",Rhs:_,Lhs:T,Token_Equals:b,Token_LhsSeperatorList:L,Token_RhsSeperatorList:E,GetFirstToken:()=>C.Lhs[0].GetFirstToken(),GetLastToken:()=>C.Rhs[C.Rhs.length-1].GetLastToken()}),C}}}function Ee(m,g,l){let T=n(),L=d(g,l),b=f("Keyword","then"),_=m?d(g,l):k(g,l),E=[];for(;t().Source=="elseif"||t().Source=="else";){let $=n(),B,x;$.Source=="elseif"&&(B=d(g,l),x=f("Keyword","then"));let V=m?d(g,l):k(g,l);if(E.push({Condition:B,Body:V,ClauseType:$.Source,Token:$,Token_Then:x}),$.Source=="else")break}let C=m?null:f("Keyword","end"),F;return F=S({Type:m?"IfExpr":"IfStat",Condition:L,Body:_,ElseClauseList:E,Token_If:T,Token_Then:b,Token_End:C,GetFirstToken:()=>F.Token_If,GetLastToken:()=>F.Token_End}),F}function le(m,g){let l=n(),[T,L]=G("end",m,g),b;return b=S({Type:"DoStat",Body:T,Token_Do:l,Token_End:L,GetFirstToken:()=>b.Token_Do,GetLastToken:()=>b.Token_End}),b}function J(m,g){let l=n(),T=d(m,g),L=f("Keyword","do"),[b,_]=G("end",m,g),E;return E=S({Type:"WhileStat",Condition:T,Body:b,Token_While:l,Token_Do:L,Token_End:_,GetFirstToken:()=>E.Token_While,GetLastToken:()=>E.Token_End}),E}function se(m,g){let l=n(),[T,L]=w(),b=[];if(t().Source=="="){let _=n(),[E,C]=p(m,g);if(E.length<2||E.length>3)throw"Expected 2 or 3 values for range bounds";let F=f("Keyword","do"),[$,B]=G("end",m,g),x;return x=S({Type:"NumericForStat",VarList:T,RangeList:E,Body:$,Token_For:l,Token_VarCommaList:L,Token_Equals:_,Token_RangeCommaList:C,Token_Do:F,Token_End:B,GetFirstToken:()=>x.Token_For,GetLastToken:()=>x.Token_End}),x}else if(t().Source=="in"){let _=n(),[E,C]=p(m,g),F=f("Keyword","do"),[$,B]=G("end",m,g),x;return x=S({Type:"GenericForStat",VarList:T,GeneratorList:E,Body:$,Token_For:l,Token_VarCommaList:L,Token_In:_,Token_GeneratorCommaList:C,Token_Do:F,Token_End:B,GetFirstToken:()=>x.Token_For,GetLastToken:()=>x.Token_End}),x}}function de(m,g){let l=n(),[T,L]=G("until",m),b=d(m,g),_;return _=S({Type:"RepeatStat",Body:T,Condition:b,Token_Repeat:l,Token_Until:L,GetFirstToken:()=>_.Token_Repeat,GetLastToken:()=>_.Condition.GetLastToken()}),_}function oe(m,g){let l=n();if(t().Source=="function"){let T=R(!1,m,g,!0);if(T.NameChain.length>1)throw r(T.Token_NameChainSeperator[0])+": `(` expected.";let L;return L=S({Type:"LocalFunctionStat",FunctionStat:T,Token_Local:l,GetFirstToken:()=>L.Token_Local,GetLastToken:()=>L.FunctionStat.GetLastToken()}),L}else if(t().Type=="Ident"||t().Type=="Keyword"&&ke.includes(t().Source)){let[T,L]=w(!1,!0),b=[],_=[],E;if(t().Source=="="){E=n();let[F,$]=p(m,g);b=F,_=$}let C;return C=S({Type:"LocalVarStat",VarList:T,ExprList:b,Token_Local:l,Token_Equals:E,Token_VarCommaList:L,Token_ExprCommaList:_,GetFirstToken:()=>C.Token_Local,GetLastToken:function(){return C.ExprList.length>0?C.ExprList[C.ExprList.length-1].GetLastToken():C.VarList[C.VarList.length-1]}}),C}else throw"`function` or ident expected"}function Te(m,g){let l=n(),T,L;o()||t().Source==";"?(T=[],L=[]):[T,L]=p(m,g);let b;return b={Type:"ReturnStat",ExprList:T,Token_Return:l,Token_CommaList:L,GetFirstToken:()=>b.Token_Return,GetLastToken:function(){return b.ExprList.length>0?b.ExprList[b.ExprList.length-1].GetLastToken():b.Token_Return}},b}function X(){let m=n(),g;return g={Type:"BreakStat",Token_Break:m,GetFirstToken:()=>g.Token_Break,GetLastToken:()=>g.Token_Break},g}function ue(m,g){if(t(1).Source=="(")return[!1,re(m,g)];let l=n(),T;return T={Type:"ContinueStat",Token_Continue:l,GetFirstToken:()=>T.Token_Continue,GetLastToken:()=>T.Token_Continue},[!0,T]}function Ce(){let m=n(),g;t().Type=="Keyword"?g=f("Keyword"):g=f("Ident");let l;return l={Type:"GotoStat",Token_Goto:m,Token_Label:g,GetFirstToken:()=>l.Token_Goto,GetLastToken:()=>l.Token_Label},l}function pe(){let m=n(),g;t().Type=="Keyword"?g=f("Keyword"):g=f("Ident");let l=f("Symbol","::"),T;return T={Type:"LabelStat",Token_ColonsLeft:m,Token_Label:g,Token_ColonsRight:l,GetFirstToken:()=>T.Token_ColonsLeft,GetLastToken:()=>T.Token_ColonsRight},T}function U(m,g){let l=t();return l.Source=="if"?[!1,Ee(!1,m,g)]:l.Source=="while"?[!1,J(m,g)]:l.Source=="do"?[!1,le(m,g)]:l.Source=="for"?[!1,se(m,g)]:l.Source=="repeat"?[!1,de(m,g)]:l.Source=="function"?[!1,R(!1,m,g)]:l.Source=="local"?[!1,oe(m,g)]:l.Source=="return"?[!0,Te(m,g)]:l.Source=="break"?[!0,X(m,g)]:l.Source=="continue"?ue(m,g):l.Source=="goto"?[!1,Ce()]:l.Source=="::"?[!1,pe()]:[!1,re(m,g)]}let ze=1;return k=function(m,g){let l=[],T=[],L=!1,b={},_={};if(g!=null)for(let[B,x]of Object.entries(g))_[B]=x;if(m!=null)for(let[B,x]of Object.entries(m))_[B]=x;let E,C=0;for(;!L&&!o();){E&&E==t()&&Se(`INFINITE LOOP POSSIBLE ON STATEMENT ${E.Source} :`,E),E=t();let[B,x]=U(b,_);if(x)switch(l.push(x),x.Type){case"LocalVarStat":x.VarList.forEach(A=>{A.UseCount=0,A.Number=C++,b[A.Source]=A;let Z=[];function Y(){A.UseCount++,Z.forEach(O=>{O.UseCount=A.UseCount})}A.Tokens={},A.Tokens.push=O=>{O.UseCountIncrease=Y,O.UseCount=A.UseCount,O.Tokens=A.Tokens,Z.push(O)},A.Tokens.get=()=>Z,A.UseCountIncrease=Y});break;case"LocalFunctionStat":let P=x.FunctionStat.NameChain;if(P.length===1){let Y=function(){A.UseCount++,Z.forEach(O=>{O.UseCount=A.UseCount})};var $=Y;let A=P[0];A.UseCount=0,A.Number=C++,b[A.Source]=A;let Z=[];A.Tokens={},A.Tokens.push=O=>{O.UseCountIncrease=Y,O.UseCount=A.UseCount,O.Tokens=A.Tokens,Z.push(O)},A.Tokens.get=()=>Z,A.UseCountIncrease=Y}break;default:break}let V=t();V.Type=="Symbol"&&V.Source==";"&&(T[l.length-1]=n())}let F;return F={Type:"StatList",StatementList:l,SemicolonList:T,GetFirstToken:function(){if(F.StatementList.length!=0)return F.StatementList[0]?.GetFirstToken()},GetLastToken:function(){if(F.StatementList.length!=0)return F.SemicolonList[F.StatementList.length-1]?F.SemicolonList[F.StatementList.length-1]:F.StatementList[F.StatementList.length-1].GetLastToken()}},F},k([],[])}function ge(u,i){let a={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[t,r]of Object.entries(i))if(!(t==="VisitStat"||t==="VisitExpr")&&!n[t]&&!a[t])throw`Invalid visitor target: \`${t}\``;function e(f){if(f!=null){let S=i[f.Type];if(typeof S=="function")return S(f);if(S&&S.Pre)return S.Pre(f)}}function o(f){let S=i[f.Type];if(S&&typeof S=="object"&&S.Post)return S.Post(f)}let s,c;s=function(f){if(!e(f)){if(f.Type=="BinopExpr")s(f.Lhs),s(f.Rhs);else if(f.Type=="UnopExpr")s(f.Rhs);else if(!(f.Type=="NumberLiteral"||f.Type=="StringLiteral"||f.Type=="NilLiteral"||f.Type=="BooleanLiteral"||f.Type=="VargLiteral"||f.Type=="HashLiteral")){if(f.Type=="FieldExpr")s(f.Base);else if(f.Type=="IndexExpr")s(f.Base),s(f.Index);else if(f.Type=="MethodExpr"||f.Type=="CallExpr")s(f.Base),f.FunctionArguments.CallType=="ArgCall"?f.FunctionArguments.ArgList.forEach((S,k)=>{s(S)}):f.FunctionArguments.CallType=="TableCall"&&s(f.FunctionArguments.TableExpr);else if(f.Type=="FunctionLiteral")c(f.Body);else if(f.Type!="VariableExpr")if(f.Type=="ParenExpr")s(f.Expression);else if(f.Type=="TableLiteral")f.EntryList.forEach((S,k)=>{if(S.EntryType=="Field")s(S.Value);else if(S.EntryType=="Index")s(S.Index),s(S.Value);else if(S.EntryType=="Value")s(S.Value);else throw"unreachable"});else if(f.Type=="CompoundStat")s(f.Lhs),s(f.Rhs);else if(f.Type=="IfExpr")s(f.Condition),s(f.Body),f.ElseClauseList.forEach(S=>{S.Condition!=null&&s(S.Condition),s(S.Body)});else throw`unreachable, type: ${f.Type}: ${f}`}o(f)}},c=function(f){if(!e(f)){if(f.Type=="StatList")f.StatementList.forEach((S,k)=>{if(S!=null){if(S===null||S.Type===null)return;S.Remove=()=>{f.StatementList[k]=null},c(S)}});else if(f.Type!="BreakStat"){if(f.Type!="ContinueStat"){if(f.Type!="GotoStat"){if(f.Type!="LabelStat")if(f.Type=="ReturnStat")f.ExprList.forEach((S,k)=>{s(S)});else if(f.Type=="LocalVarStat")f.Token_Equals&&f.ExprList.forEach((S,k)=>{s(S)});else if(f.Type=="LocalFunctionStat")c(f.FunctionStat.Body);else if(f.Type=="FunctionStat")c(f.Body);else if(f.Type=="RepeatStat")c(f.Body),s(f.Condition);else if(f.Type=="GenericForStat")f.GeneratorList.forEach((S,k)=>{s(S)}),c(f.Body);else if(f.Type=="NumericForStat")f.RangeList.forEach((S,k)=>{s(S)}),c(f.Body);else if(f.Type=="WhileStat")s(f.Condition),c(f.Body);else if(f.Type=="DoStat")c(f.Body);else if(f.Type=="IfStat")s(f.Condition),c(f.Body),f.ElseClauseList.forEach(S=>{S.Condition!=null&&s(S.Condition),c(S.Body)});else if(f.Type=="CallExprStat")s(f.Expression);else if(f.Type=="CompoundStat")s(f.Lhs),s(f.Rhs);else if(f.Type=="AssignmentStat")f.Lhs.forEach(S=>{s(S)}),f.Rhs.forEach(S=>{s(S)});else throw"Unreachable code. Got "+f.Type}}}o(f)}},i.VisitStat=c,i.VisitExpr=s,n[u.Type]?c(u):s(u)}function ct(u){let i=[],a,n=0;function t(){return n++,n}function r(){a={ParentScope:a,ChildScopeList:[],VariableList:[],BeginLocation:t(),Depth:null,GetVar:null},a.ParentScope?(a.Depth=a.ParentScope.Depth+1,a.ParentScope.ChildScopeList.push(a)):a.Depth=1;let d=a;a.GetVar=function(p){for(let h of d.VariableList)if(h.Name==p)return h;if(d.ParentScope)return d.ParentScope.GetVar(p);for(let h of i)if(h.Name==p)return h}}function e(){let d=a;return d.EndLocation=t(),d.VariableList.forEach(p=>{p.ScopeEndLocation=d.EndLocation}),a=d.ParentScope,d}r();function o(d,p,h){D(h,"Missing localInfo"),D(d,"Missing local var name");let y={Type:"Local",Name:d,RenameList:[p],AssignedTo:!1,Info:h,Scope:a,BeginLocation:t(),EndLocation:t(),ReferenceLocationList:[t()]};return y.Rename=function(w){y.Name=w,y.RenameList.forEach(G=>{G(w)})},a.VariableList.push(y),y}function s(d){for(let h of i)if(h.Name==d)return h;let p={Type:"Global",Name:d,RenameList:[],AssignedTo:!1,Scope:null,BeginLocation:t(),EndLocation:t(),ReferenceLocationList:[]};return p.Rename=function(h){p.Name=h,p.RenameList.forEach(y=>{y(h)})},i.push(p),p}function c(d,p){D(d,"Missing var name");let h=s(d);return h.RenameList.push(p),h}function f(d,p){let h;for(h=d.VariableList.length-1;h>=0;h--)if(d.VariableList[h].Name==p)return d.VariableList[h];if(d.ParentScope){let y=f(d.ParentScope,p);if(y)return y}}function S(d,p){D(d,"Missing var name");let h=f(a,d);h?h.RenameList.push(p):h=c(d,p);let y=t();return h.EndLocation=y,h.ReferenceLocationList.push(h.EndLocation),h}let k={};return k.FunctionLiteral={Pre:function(d){r(),d.ArgList.forEach((p,h)=>{let y=o(p.Source,function(w,G){G||(p.Source=w)},{Type:"Argument",Index:h});p.var=y})},Post:function(d){e()}},k.VariableExpr=function(d){d.Variable=S(d.Token.Source,function(p,h=!1){h&&d.IsStat||(d.Token.Source=p)})},k.StatList={Pre:function(d){r()},Post:function(d){d.SkipPop||e()}},k.LocalVarStat={Post:function(d){d.VarList.forEach((p,h)=>{o(p.Source,function(y){d.VarList[h].Source=y},{Type:"Local",Expr:d.ExprList})})}},k.LocalFunctionStat={Pre:function(d){o(d.FunctionStat.NameChain[0].Source,function(p){d.FunctionStat.NameChain[0].Source=p},{Type:"LocalFunction"}),r(),d.FunctionStat.ArgList.forEach((p,h)=>{o(p.Source,function(y){p.Source=y},{Type:"Argument",Index:h})})},Post:function(){e()}},k.FunctionStat={Pre:function(d){let p=d.NameChain,h;p.length==1?f(a,p[0].Source)?h=S(p[0].Source,function(y){p[0].Source=y}):h=c(p[0].Source,function(y){p[0].Source=y}):h=S(p[0].Source,function(y){p[0].Source=y}),h.AssignedTo=!0,r(),d.ArgList.forEach((y,w)=>{o(y.Source,function(G){y.Source=G},{Type:"Argument",Index:w})})},Post:function(){e()}},k.GenericForStat={Pre:function(d){return d.GeneratorList.forEach(p=>{ge(p,k)}),r(),d.VarList.forEach((p,h)=>{o(p.Source,function(y){p.Source=y},{Type:"ForRange",Index:h})}),ge(d.Body,k),e(),!0}},k.NumericForStat={Pre:function(d){return d.RangeList.forEach(p=>{ge(p,k)}),r(),d.VarList.forEach((p,h)=>{o(p.Source,function(y){p.Source=y},{Type:"ForRange",Index:h})}),ge(d.Body,k),e(),!0}},k.RepeatStat={Pre:function(d){d.Body.SkipPop=!0},Post:function(d){e()}},k.AssignmentStat={Post:function(d){d.Lhs.forEach(p=>{p.Variable!=null&&(p.Variable.AssignedTo=!0)})}},ge(u,k),[i,e()]}function ft(u){let i,a,n="",t=e=>typeof e?.LeadingWhite!="string"?" ":e.LeadingWhite;function r(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 a=function(e){if(e.Type=="BinopExpr")a(e.Lhs),r(e.Token_Op),a(e.Rhs);else if(e.Type=="UnopExpr")r(e.Token_Op),a(e.Rhs);else if(e.Type=="NumberLiteral"||e.Type=="StringLiteral"||e.Type=="NilLiteral"||e.Type=="BooleanLiteral"||e.Type=="VargLiteral"||e.Type=="HashLiteral")r(e.Token);else if(e.Type=="FieldExpr")a(e.Base),r(e.Token_Dot),r(e.Field);else if(e.Type=="IndexExpr")a(e.Base),r(e.Token_OpenBracket),a(e.Index),r(e.Token_CloseBracket);else if(e.Type=="MethodExpr"||e.Type=="CallExpr")a(e.Base),e.Type=="MethodExpr"&&(r(e.Token_Colon),r(e.Method)),e.FunctionArguments.CallType=="StringCall"?r(e.FunctionArguments.Token):e.FunctionArguments.CallType=="ArgCall"?(r(e.FunctionArguments.Token_OpenParen),e.FunctionArguments.ArgList.forEach((o,s)=>{a(o);let c=e.FunctionArguments.Token_CommaList[s];c!=null&&r(c)}),r(e.FunctionArguments.Token_CloseParen)):e.FunctionArguments.CallType=="TableCall"&&a(e.FunctionArguments.TableExpr);else if(e.Type=="FunctionLiteral")r(e.Token_Function),r(e.Token_OpenParen),e.ArgList.forEach((o,s)=>{r(o);let c=e.Token_ArgCommaList[s];c!=null&&r(c)}),e.Token_Varg!=null&&r(e.Token_Varg),r(e.Token_CloseParen),i(e.Body),r(e.Token_End);else if(e.Type=="VariableExpr")r(e.Token);else if(e.Type=="ParenExpr")r(e.Token_OpenParen),a(e.Expression),r(e.Token_CloseParen);else if(e.Type=="TableLiteral")r(e.Token_OpenBrace),e.EntryList.forEach((o,s)=>{if(o.EntryType=="Field")r(o.Field),r(o.Token_Equals),a(o.Value);else if(o.EntryType=="Index")r(o.Token_OpenBracket),a(o.Index),r(o.Token_CloseBracket),r(o.Token_Equals),a(o.Value);else if(o.EntryType=="Value")a(o.Value);else throw"unreachable";let c=e.Token_SeperatorList[s];c!=null&&r(c)}),r(e.Token_CloseBrace);else if(e.Type=="CompoundStat")i(e);else if(e.Type=="IfExpr")r(e.Token_If),a(e.Condition),r(e.Token_Then),a(e.Body),e.ElseClauseList.forEach(o=>{r(o.Token),o.Condition!=null&&(a(o.Condition),r(o.Token_Then)),a(o.Body)});else throw`unreachable, type: ${e.Type}: ${e}`},i=function(e){if(e==null)throw`STAT IS NIL! ${e}`;if(!(e.Type==="StatList"&&e.StatementList.length===0)){if(e.WrapInDo){let o=t(e.GetFirstToken());e.GetFirstToken().LeadingWhite="",n+=`${o}do `}e.Type=="StatList"?e.StatementList.forEach((o,s)=>{o===null||o.Type===null||(o.Remove=()=>{e.StatementList[s]=null},i(o),e.SemicolonList[s]&&r(e.SemicolonList[s]))}):e.Type=="BreakStat"?r(e.Token_Break):e.Type=="ContinueStat"?r(e.Token_Continue):e.Type=="GotoStat"?(r(e.Token_Goto),r(e.Token_Label)):e.Type=="LabelStat"?(r(e.Token_ColonsLeft),r(e.Token_Label),r(e.Token_ColonsRight)):e.Type=="ReturnStat"?(r(e.Token_Return),e.ExprList.forEach((o,s)=>{a(o),e.Token_CommaList[s]&&r(e.Token_CommaList[s])})):e.Type=="LocalVarStat"?(r(e.Token_Local),e.VarList.forEach((o,s)=>{r(o),o.Attribute!=null&&r(o.Attribute);let c=e.Token_VarCommaList[s];c!=null&&r(c)}),e.Token_Equals!=null&&(r(e.Token_Equals),e.ExprList.forEach((o,s)=>{a(o);let c=e.Token_ExprCommaList[s];c!=null&&r(c)}))):e.Type=="LocalFunctionStat"?(r(e.Token_Local),r(e.FunctionStat.Token_Function),r(e.FunctionStat.NameChain[0]),r(e.FunctionStat.Token_OpenParen),e.FunctionStat.ArgList.forEach((o,s)=>{r(o);let c=e.FunctionStat.Token_ArgCommaList[s];c!=null&&r(c)}),e.FunctionStat.Token_Varg&&r(e.FunctionStat.Token_Varg),r(e.FunctionStat.Token_CloseParen),i(e.FunctionStat.Body),r(e.FunctionStat.Token_End)):e.Type=="FunctionStat"?(r(e.Token_Function),e.NameChain.forEach((o,s)=>{r(o);let c=e.Token_NameChainSeperator[s];c!=null&&r(c)}),r(e.Token_OpenParen),e.ArgList.forEach((o,s)=>{r(o);let c=e.Token_ArgCommaList[s];c!=null&&r(c)}),e.Token_Varg&&r(e.Token_Varg),r(e.Token_CloseParen),i(e.Body),r(e.Token_End)):e.Type=="RepeatStat"?(r(e.Token_Repeat),i(e.Body),r(e.Token_Until),a(e.Condition)):e.Type=="GenericForStat"?(r(e.Token_For),e.VarList.forEach((o,s)=>{r(o);let c=e.Token_VarCommaList[s];c!=null&&r(c)}),r(e.Token_In),e.GeneratorList.forEach((o,s)=>{a(o);let c=e.Token_GeneratorCommaList[s];c!=null&&r(c)}),r(e.Token_Do),i(e.Body),r(e.Token_End)):e.Type=="NumericForStat"?(r(e.Token_For),e.VarList.forEach((o,s)=>{r(o);let c=e.Token_VarCommaList[s];c!=null&&r(c)}),r(e.Token_Equals),e.RangeList.forEach((o,s)=>{a(o);let c=e.Token_RangeCommaList[s];c!=null&&r(c)}),r(e.Token_Do),i(e.Body),r(e.Token_End)):e.Type=="WhileStat"?(r(e.Token_While),a(e.Condition),r(e.Token_Do),i(e.Body),r(e.Token_End)):e.Type=="DoStat"?(r(e.Token_Do),i(e.Body),r(e.Token_End)):e.Type=="IfStat"?(r(e.Token_If),a(e.Condition),r(e.Token_Then),i(e.Body),e.ElseClauseList.forEach(o=>{r(o.Token),o.Condition!=null&&(a(o.Condition),r(o.Token_Then)),i(o.Body)}),r(e.Token_End)):e.Type=="CallExprStat"?a(e.Expression):e.Type=="CompoundStat"?(a(e.Lhs),r(e.Token_Compound),a(e.Rhs),e.Type="CompoundStat"):e.Type=="AssignmentStat"?(e.Lhs.forEach((o,s)=>{a(o);let c=e.Token_LhsSeperatorList[s];c!=null&&r(c)}),r(e.Token_Equals),e.Rhs.forEach((o,s)=>{a(o);let c=e.Token_RhsSeperatorList[s];c!=null&&r(c)})):D(!1,"unreachable"),e.WrapInDo&&(n+=" end ")}},i(u),n}function dt(u){let i,a;function n(e){e&&(e.LeadingWhite="")}function t(e,o,s=!1){n(o);let c=(typeof e.Source=="string"?e.Source:e.Source.toString()).substr(e.Source.length-1,1),f=(typeof o.Source=="string"?o.Source:o.Source.toString()).substr(0,1);c=="-"&&f=="-"||Pe.includes(c)&&Pe.includes(f)||s&&c==")"&&f=="("?o.LeadingWhite=s?";":" ":o.LeadingWhite=""}function r(e,o,s){i(o),n(s);let c=o.GetFirstToken(),f=o.GetLastToken();c!=null?(t(e,c),t(f,s)):t(e,s)}a=function(e){if(e.Type==="BinopExpr")a(e.Lhs),a(e.Rhs),e.Lhs.Type=="NumberLiteral"&&e.Token_Op.Source==".."?e.Token_Op.LeadingWhite=" ":(n(e.Token_Op),t(e.Lhs.GetLastToken(),e.Token_Op)),t(e.Token_Op,e.Rhs.GetFirstToken());else if(e.Type==="UnopExpr")n(e.Token_Op),a(e.Rhs),t(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")a(e.Base),n(e.Token_Dot),n(e.Field);else if(e.Type=="IndexExpr")a(e.Base),n(e.Token_OpenBracket),a(e.Index),n(e.Token_CloseBracket);else if(e.Type=="MethodExpr"||e.Type=="CallExpr")a(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((o,s)=>{a(o);let c=e.FunctionArguments.Token_CommaList[s];c!=null&&n(c)}),n(e.FunctionArguments.Token_CloseParen)):e.FunctionArguments.CallType=="TableCall"&&a(e.FunctionArguments.TableExpr);else if(e.Type=="FunctionLiteral")n(e.Token_Function),n(e.Token_OpenParen),e.ArgList.forEach((o,s)=>{n(o);let c=e.Token_ArgCommaList[s];c!=null&&n(c)}),e.Token_Varg!=null&&n(e.Token_Varg),n(e.Token_CloseParen),r(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),a(e.Expression),n(e.Token_CloseParen);else if(e.Type=="IfExpr"){n(e.Token_If),a(e.Condition),t(e.Token_If,e.Condition.GetFirstToken()),t(e.Condition.GetLastToken(),e.Token_Then);let o=e.Token_Then,s=e.Body;e.ElseClauseList.forEach((c,f)=>{t(o,s.GetFirstToken()),t(s.GetLastToken(),c.Token),o=c.Token,c.Condition!=null&&(a(c.Condition),t(c.Token,c.Condition.GetFirstToken()),t(c.Condition.GetLastToken(),c.Token_Then),o=c.Token_Then),a(c.Body),s=c.Body}),t(o,s.GetFirstToken())}else if(e.Type=="TableLiteral")n(e.Token_OpenBrace),e.EntryList.forEach((o,s)=>{o.EntryType=="Field"?(n(o.Field),n(o.Token_Equals),a(o.Value)):o.EntryType=="Index"?(n(o.Token_OpenBracket),a(o.Index),n(o.Token_CloseBracket),n(o.Token_Equals),a(o.Value)):o.EntryType=="Value"?a(o.Value):D(!1,"unreachable");let c=e.Token_SeperatorList[s];c!=null&&n(c)}),e.Token_SeperatorList[e.EntryList.length-1]=null,n(e.Token_CloseBrace);else throw`unreachable, type: ${e.Type}:${e} ${console.trace()}`},i=function(e){if(e.Type=="StatList"){let o;for(o=0;o<=e.StatementList.length;o++){let s=e.StatementList[o];if(s==null)continue;i(s),n(s.GetFirstToken());let c=e.StatementList[o-1];if(c!=null){let f={")":["(","["],"]":["(","["]};if(e.SemicolonList[o-1]){let S=c.GetLastToken().Source,k=s.GetFirstToken().Source;(f[S]===null||f[S]===void 0||!f[S].includes(k))&&(e.SemicolonList[o-1]=null)}e.SemicolonList[o-1]||t(c.GetLastToken(),s.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),t(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((o,s)=>{a(o),e.Token_CommaList[s]!=null&&n(e.Token_CommaList[s])}),e.ExprList.length>0&&t(e.Token_Return,e.ExprList[0].GetFirstToken());else if(e.Type=="LocalVarStat"){n(e.Token_Local);let o=!1;e.VarList.forEach((s,c)=>{c==0?t(e.Token_Local,s):n(s),s.Attribute&&(n(s.Attribute),c+1==e.VarList.length&&(o=!0));let f=e.Token_VarCommaList[c];f!=null&&n(f)}),e.Token_Equals!=null&&(o||n(e.Token_Equals),e.ExprList.forEach((s,c)=>{a(s);let f=e.Token_ExprCommaList[c];f!=null&&n(f)}))}else if(e.Type=="LocalFunctionStat")n(e.Token_Local),t(e.Token_Local,e.FunctionStat.Token_Function),t(e.FunctionStat.Token_Function,e.FunctionStat.NameChain[0]),t(e.FunctionStat.NameChain[0],e.FunctionStat.Token_OpenParen),e.FunctionStat.ArgList.forEach((o,s)=>{n(o);let c=e.FunctionStat.Token_ArgCommaList[s];c!=null&&n(c)}),e.FunctionStat.Token_Varg&&n(e.FunctionStat.Token_Varg),n(e.FunctionStat.Token_CloseParen),r(e.FunctionStat.Token_CloseParen,e.FunctionStat.Body,e.FunctionStat.Token_End);else if(e.Type=="FunctionStat")n(e.Token_Function),e.NameChain.forEach((o,s)=>{s==0?t(e.Token_Function,o):n(o);let c=e.Token_NameChainSeperator[s];c!=null&&n(c)}),n(e.Token_OpenParen),e.ArgList.forEach((o,s)=>{n(o);let c=e.Token_ArgCommaList[s];c!=null&&n(c)}),e.Token_Varg&&n(e.Token_Varg),n(e.Token_CloseParen),r(e.Token_CloseParen,e.Body,e.Token_End);else if(e.Type=="RepeatStat")n(e.Token_Repeat),r(e.Token_Repeat,e.Body,e.Token_Until),a(e.Condition),t(e.Token_Until,e.Condition.GetFirstToken());else if(e.Type=="GenericForStat")n(e.Token_For),e.VarList.forEach((o,s)=>{s==0?t(e.Token_For,o):n(o);let c=e.Token_VarCommaList[s];c!=null&&n(c)}),t(e.VarList[e.VarList.length-1],e.Token_In),e.GeneratorList.forEach((o,s)=>{a(o),s==0&&t(e.Token_In,o.GetFirstToken());let c=e.Token_GeneratorCommaList[s];c!=null&&n(c)}),t(e.GeneratorList[e.GeneratorList.length-1].GetLastToken(),e.Token_Do),r(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="NumericForStat")n(e.Token_For),e.VarList.forEach((o,s)=>{s==0?t(e.Token_For,o):n(o);let c=e.Token_VarCommaList[s];c!=null&&n(c)}),t(e.VarList[e.VarList.length-1],e.Token_Equals),e.RangeList.forEach((o,s)=>{a(o),s==0&&t(e.Token_Equals,o.GetFirstToken());let c=e.Token_RangeCommaList[s];c!=null&&n(c)}),t(e.RangeList[e.RangeList.length-1].GetLastToken(),e.Token_Do),r(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="WhileStat")n(e.Token_While),a(e.Condition),n(e.Token_Do),t(e.Token_While,e.Condition.GetFirstToken()),t(e.Condition.GetLastToken(),e.Token_Do),r(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="DoStat")n(e.Token_Do),n(e.Token_End),r(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="IfStat"){n(e.Token_If),a(e.Condition),t(e.Token_If,e.Condition.GetFirstToken()),t(e.Condition.GetLastToken(),e.Token_Then);let o=e.Token_Then,s=e.Body;e.ElseClauseList.forEach((c,f)=>{r(o,s,c.Token),o=c.Token,c.Condition!=null&&(a(c.Condition),t(c.Token,c.Condition.GetFirstToken()),t(c.Condition.GetLastToken(),c.Token_Then),o=c.Token_Then),i(c.Body),s=c.Body}),r(o,s,e.Token_End)}else if(e.Type=="CallExprStat")a(e.Expression);else if(e.Type=="CompoundStat")a(e.Lhs),n(e.Token_Compound),a(e.Rhs),t(e.Lhs.GetLastToken(),e.Token_Compound),t(e.Token_Compound,e.Rhs.GetFirstToken());else if(e.Type=="AssignmentStat")e.Lhs.forEach((o,s)=>{a(o);let c=e.Token_LhsSeperatorList[s];c!=null&&n(c)}),n(e.Token_Equals),e.Rhs.forEach((o,s)=>{a(o);let c=e.Token_RhsSeperatorList[s];c!=null&&n(c)});else return a(e)},i(u)}var ie=[],N;for(N=97;N<=122;N++)ie.push(String.fromCharCode(N));for(N=65;N<=90;N++)ie.push(String.fromCharCode(N));for(N=48;N<=57;N++)ie.push(String.fromCharCode(N));ie.push("_");var Le=[];for(N=97;N<=122;N++)Le.push(String.fromCharCode(N));for(N=65;N<=90;N++)Le.push(String.fromCharCode(N));function nn(u){let i="",a=u%Le.length;for(u=(u-a)/Le.length,i=`${i}${Le[a]}`;u>0;){let n=u%ie.length;u=(u-n)/ie.length,i=`${i}${ie[n]}`}return i}function Tt(u,i,a){let n=[];for(var[t,r]of Object.entries(tn))n[t]=!0;let e=[],o=[];u.forEach(k=>{k.AssignedTo&&a?e.push(k):n[k.Name]=!0});function s(k){k.VariableList.forEach(d=>{e.push(d),o.push(d)}),k.ChildScopeList.forEach(d=>{s(d)})}s(i),e.forEach(k=>{k.UsedNameArray=[]}),e.sort((k,d)=>k-d);let c=0,f=[];function S(k){let d=f[k];if(d==null){for(d=nn(c),c++;n[d];)d=nn(c),c++;f[k]=d}return d}e.forEach((k,d)=>{k.Renamed=!0;let p=0;for(;k.UsedNameArray[p];)p++;k.Rename(S(p)),k.Scope?e.forEach(h=>{h.Renamed||(!h.Scope||h.Scope.Depth<k.Scope.Depth?h.ReferenceLocationList.some(y=>y>=k.BeginLocation&&y<=k.ScopeEndLocation?(h.UsedNameArray[p]=!0,!0):!1):h.Scope.Depth>k.Scope.Depth?k.ReferenceLocationList.some(y=>y>=h.BeginLocation&&y<=h.ScopeEndLocation?(h.UsedNameArray[p]=!0,!0):!1):k.BeginLocation<h.EndLocation&&k.EndLocation>h.BeginLocation&&(h.UsedNameArray[p]=!0))}):e.forEach(h=>{if(!h.Renamed)if(h.Type=="Global")h.UsedNameArray[p]=!0;else if(h.Type=="Local")k.ReferenceLocationList.some(y=>y>=h.BeginLocation&&y<=h.ScopeEndLocation?(h.UsedNameArray[p]=!0,!0):!1);else throw"Unreachable"})})}var rn={};rn.Minify=function(u,i){let a=at(u),[n,t]=ct(a);i.RenameVariables==!0&&Tt(n,t,i.RenameGlobals),i.SolveMath==!0&&SolveMath(a),dt(a);let r=ft(a);return r=`${r}`,r};try{$e!=null&&$e.exports!=null&&($e.exports.Minify=rn.Minify)}catch{}});var cn=W((co,an)=>{var Ve=require("fs-extra"),pt=require("path");function un(u,i){let a=0,n=i,t=u.length,r=!1,e="";for(;n<t;){let o=u[n];if(r){if(o==="\\"){n+=2;continue}o===e&&(r=!1)}else{if(o==='"'||o==="'"){r=!0,e=o,n++;continue}if(o==="{")a++;else if(o==="}"&&(a--,a===0))return n}n++}return-1}function sn(u,i){let a=new RegExp(`^\\s*${i}\\s*\\{`,"m"),n=u.match(a);if(!n)return null;let t=n.index,r=u.indexOf("{",t);if(r===-1)return null;let e=un(u,r);return e===-1?null:{header:n[0],blockStart:t,blockEnd:e,blockContent:u.substring(t,e+1)}}function ht(u,i,a,n,t=!1){let r=["fxmanifest.lua","__resource.lua"],e=null;for(let h of r){let y=pt.join(u,h);if(Ve.existsSync(y)){e=y;break}}if(!e){console.log("\x1B[33m! No fxmanifest.lua or __resource.lua found. Skipping manifest injection.\x1B[0m");return}let o=Ve.readFileSync(e,"utf8"),s=!1,c=(h,y)=>{let w=h.replace("_scripts","_script").replace("files","file"),G=h,R=`'ltbridge/modules/${y}'`,j=sn(o,G);if(j){if(j.blockContent.includes(R))return;let q=o.indexOf("{",j.blockStart);o=o.substring(0,q+1)+`
|
|
10
|
-
${
|
|
11
|
-
${
|
|
9
|
+
`?(g++,l=0):l++;if(L==m)break;T++}return`${g}:${l+1}`}function e(){let m=t();return`<${m.Type} \`${m.Source}\`> at: ${r(m)}`}function o(){let m=t();return m.Type=="Eof"||m.Type=="Keyword"&&rt.includes(m.Source)}function s(){return lt.includes(t().Source)||!1}function c(){return on.includes(t().Source)||!1}function f(m,g){let l=t();if(l.Type==m&&(g==null||l.Source==g))return n();if(l.Type=="Keyword"&&m=="Ident"&&ke.includes(l.Source)&&(g==null||l.Source==g))return n();{let T;for(T=-3;T<=3;T++)Se(`Tokens[${T}] = \`${t(T).Source}\``);throw g?`${r(l)}: \`${g}\` expected.`:`${r(l)}: ${m} expected.`}}function S(m){let g=m.GetFirstToken,l=m.GetLastToken,T=m;return m.GetFirstToken=function(){let L=g(T);return W(L),L},m.GetLastToken=function(){let L=l(T);return W(L),L},m}let k,d;function p(m,g){let l=[d(m,g)],T=[];for(;t().Source==",";)T.push(n()),l.push(d(m,g));return[l,T]}function h(m,g){let l=t();if(l.Source=="("){let T=n(),L=d(m,g),b=f("Symbol",")"),_;return _=S({Type:"ParenExpr",Expression:L,Token_OpenParen:T,Token_CloseParen:b,GetFirstToken:()=>_.Token_OpenParen,GetLastToken:()=>_.Token_CloseParen}),_}else if(l.Type=="Ident"||l.Type=="Keyword"&&ke.includes(l.Source)){let T;return T=S({Type:"VariableExpr",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),m[T.Token.Source]!=null&&m[T.Token.Source]?.Tokens?.push!=null?(m[T.Token.Source].Tokens.push(T.Token),m[T.Token.Source].UseCountIncrease()):g[T.Token.Source]!=null&&g[T.Token.Source]?.Tokens?.push!=null&&(g[T.Token.Source].Tokens.push(T.Token),g[T.Token.Source].UseCountIncrease()),T}else throw Se(e()),`${r(l)}: Unexpected symbol. ${l.Type} ${l.Source}`}function y(m,g){let l=f("Symbol","{"),T=[],L=[];for(;t().Source!="}";){let E,C;if(t().Source=="["){let F=n(),$=d(m,g),B=f("Symbol","]"),x=f("Symbol","="),V=d(m,g);E=$.Token&&$.Token.Source,C=V,T.push({EntryType:"Index",Index:$,Value:V,Token_OpenBracket:F,Token_CloseBracket:B,Token_Equals:x})}else if((t().Type=="Ident"||t().Type=="Keyword"&&ke.includes(t().Source))&&t(1).Source=="="){let F=n(),$=n(),B=d(m,g);E=F,C=B,T.push({EntryType:"Field",Field:F,Value:B,Token_Equals:$})}else{let F=d(m,g);T.push({EntryType:"Value",Value:F})}if(t().Source==","||t().Source==";")L.push(n());else break}let b=f("Symbol","}"),_;return _=S({Type:"TableLiteral",EntryList:T,Token_SeperatorList:L,Token_OpenBrace:l,Token_CloseBrace:b,GetFirstToken:()=>_.Token_OpenBrace,GetLastToken:()=>_.Token_CloseBrace}),_}function w(m,g){let l=[],T=[];if(t().Type=="Ident"||t().Type=="Keyword"&&ke.includes(t().Source)){let L=n();if(g&&t().Source=="<"&&t(2).Source==">"){let b=t(1).Source;L.Attribute={LeadingWhite:t().LeadingWhite,Source:`<${b}>`},n(),n(),n()}l.push(L)}else if(t().Source=="..."&&m)return[l,T,n()];for(;t().Source==",";){if(T.push(n()),t().Source=="..."&&m)return[l,T,n()];{let L=f("Ident");if(g&&t().Source=="<"&&t(2).Source==">"){let b=t(1).Source;L.Attribute={LeadingWhite:t().LeadingWhite,Source:`<${b}>`},n(),n(),n()}l.push(L)}}return[l,T]}function G(m,g,l){let T=k(g,l),L=t();if(L.Type=="Keyword"&&L.Source==m)return n(),[T,L];throw Se(L.Type,L.Source),`${r(L)}: ${m} expected.`}function A(m,g,l,T){let L=n(),b,_;if(!m){b=[],_=[];let R=f("Ident");for(b.push(R);t().Source==".";)_.push(n()),b.push(f("Ident"));t().Source==":"&&(_.push(n()),b.push(f("Ident")))}let E=f("Symbol","("),[C,F,$]=w(!0),B=f("Symbol",")"),[x,V]=G("end",g,l),P;return P=S({Type:m==!0?"FunctionLiteral":"FunctionStat",NameChain:b,ArgList:C,Body:x,Token_Function:L,Token_NameChainSeperator:_,Token_OpenParen:E,Token_Varg:$,Token_ArgCommaList:F,Token_CloseParen:B,Token_End:V,GetFirstToken:()=>P.Token_Function,GetLastToken:()=>P.Token_End}),P}function j(m,g){let l=t();if(l.Source=="("){let T=n(),L=[],b=[];for(;t().Source!=")"&&(L.push(d(m,g)),t().Source==",");)b.push(n());let _=f("Symbol",")"),E;return E=S({CallType:"ArgCall",ArgList:L,Token_CommaList:b,Token_OpenParen:T,Token_CloseParen:_,GetFirstToken:()=>E.Token_OpenParen,GetLastToken:()=>E.Token_CloseParen}),E}else if(l.Source=="{"){let T;return T=S({CallType:"TableCall",TableExpr:d(m,g),GetFirstToken:()=>T.TableExpr.GetFirstToken(),GetLastToken:()=>T.TableExpr.GetLastToken()}),T}else if(l.Type=="String"){let T;return T=S({CallType:"StringCall",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else throw"Function arguments expected."}function te(m,g){let l=h(m,g);for(W(l,"nil prefixexpr");;){let T=t();if(T.Source=="."){let L=n(),b=f("Ident"),_;_=S({Type:"FieldExpr",Base:l,Field:b,Token_Dot:L,GetFirstToken:()=>_.Base.GetFirstToken(),GetLastToken:()=>_.Field}),l=_}else if(T.Source==":"){let L=n(),b=f("Ident"),_=j(m,g),E;E=S({Type:"MethodExpr",Base:l,Method:b,FunctionArguments:_,Token_Colon:L,GetFirstToken:()=>E.Base.GetFirstToken(),GetLastToken:()=>E.FunctionArguments.GetLastToken()}),l=E}else if(T.Source=="["){let L=n(),b=d(m,g),_=f("Symbol","]"),E;E=S({Type:"IndexExpr",Base:l,Index:b,Token_OpenBracket:L,Token_CloseBracket:_,GetFirstToken:()=>E.Base.GetFirstToken(),GetLastToken:()=>E.Token_CloseBracket}),l=E}else if(T.Source=="{"||T.Source=="("||T.Type=="String"){let L;L=S({Type:"CallExpr",Base:l,FunctionArguments:j(m,g),GetFirstToken:()=>L.Base.GetFirstToken(),GetLastToken:()=>L.FunctionArguments.GetLastToken()}),l=L}else if(it.includes(T.Source)){let L=n(),b=d(m,g),_;_=S({Type:"CompoundStat",Base:l,Token_Compound:L,Rhs:b,Lhs:l,GetFirstToken:()=>_.Base.GetFirstToken(),GetLastToken:()=>_.Rhs.GetLastToken()}),l=_}else return l}}function H(m,g){let l=t();if(l.Type=="Number"){let T;return T=S({Type:"NumberLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(l.Type=="String"){let T;return T=S({Type:"StringLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(l.Type=="Hash"){let T;return T=S({Type:"HashLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(l.Source=="nil"){let T;return T=S({Type:"NilLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(l.Source=="true"||l.Source=="false"){let T;return T=S({Type:"BooleanLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(l.Source=="..."){let T;return T=S({Type:"VargLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else return l.Source=="{"?y(m,g):l.Source=="function"?A(!0,m,g):l.Source=="if"?Ee(!0,m,g):te(m,g)}function q(m,g,l){let T;if(s()){let L=n(),b=q(st,g,l),_;_=S({Type:"UnopExpr",Token_Op:L,Rhs:b,GetFirstToken:()=>_.Token_Op,GetLastToken:()=>_.Rhs.GetLastToken()}),T=_}else T=H(g,l),W(T,"nil sipleexpr");for(;c()&&Me[t().Source]!=null&&Me[t().Source][0]>m;){let L=n(),b=q(Me[L.Source][1],g,l);W(b,"RhsNeeded");let _;_=S({Type:"BinopExpr",Lhs:T,Rhs:b,Token_Op:L,GetFirstToken:()=>_.Lhs.GetFirstToken(),GetLastToken:()=>_.Rhs.GetLastToken()}),T=_}return T}d=(m,g)=>q(0,m,g);function re(m,g){let l=te(m,g);if(l.Type=="MethodExpr"||l.Type=="CallExpr"){let T;return T=S({Type:"CallExprStat",Expression:l,GetFirstToken:()=>T.Expression.GetFirstToken(),GetLastToken:()=>T.Expression.GetLastToken()}),T}else{if(l.Type=="CompoundStat")return l;{let T=[l],L=[];for(l.IsStat=!0;t().Source==",";){L.push(n());let F=te(m,g);if(F.Type=="MethodExpr"||F.Type=="CallExpr")throw"Bad left hand side of asignment";F.IsStat=!0,T.push(F)}let b=f("Symbol","="),_=[d(m,g)],E=[];for(;t().Source==",";)E.push(n()),_.push(d(m,g));let C;return C=S({Type:"AssignmentStat",Rhs:_,Lhs:T,Token_Equals:b,Token_LhsSeperatorList:L,Token_RhsSeperatorList:E,GetFirstToken:()=>C.Lhs[0].GetFirstToken(),GetLastToken:()=>C.Rhs[C.Rhs.length-1].GetLastToken()}),C}}}function Ee(m,g,l){let T=n(),L=d(g,l),b=f("Keyword","then"),_=m?d(g,l):k(g,l),E=[];for(;t().Source=="elseif"||t().Source=="else";){let $=n(),B,x;$.Source=="elseif"&&(B=d(g,l),x=f("Keyword","then"));let V=m?d(g,l):k(g,l);if(E.push({Condition:B,Body:V,ClauseType:$.Source,Token:$,Token_Then:x}),$.Source=="else")break}let C=m?null:f("Keyword","end"),F;return F=S({Type:m?"IfExpr":"IfStat",Condition:L,Body:_,ElseClauseList:E,Token_If:T,Token_Then:b,Token_End:C,GetFirstToken:()=>F.Token_If,GetLastToken:()=>F.Token_End}),F}function le(m,g){let l=n(),[T,L]=G("end",m,g),b;return b=S({Type:"DoStat",Body:T,Token_Do:l,Token_End:L,GetFirstToken:()=>b.Token_Do,GetLastToken:()=>b.Token_End}),b}function J(m,g){let l=n(),T=d(m,g),L=f("Keyword","do"),[b,_]=G("end",m,g),E;return E=S({Type:"WhileStat",Condition:T,Body:b,Token_While:l,Token_Do:L,Token_End:_,GetFirstToken:()=>E.Token_While,GetLastToken:()=>E.Token_End}),E}function se(m,g){let l=n(),[T,L]=w(),b=[];if(t().Source=="="){let _=n(),[E,C]=p(m,g);if(E.length<2||E.length>3)throw"Expected 2 or 3 values for range bounds";let F=f("Keyword","do"),[$,B]=G("end",m,g),x;return x=S({Type:"NumericForStat",VarList:T,RangeList:E,Body:$,Token_For:l,Token_VarCommaList:L,Token_Equals:_,Token_RangeCommaList:C,Token_Do:F,Token_End:B,GetFirstToken:()=>x.Token_For,GetLastToken:()=>x.Token_End}),x}else if(t().Source=="in"){let _=n(),[E,C]=p(m,g),F=f("Keyword","do"),[$,B]=G("end",m,g),x;return x=S({Type:"GenericForStat",VarList:T,GeneratorList:E,Body:$,Token_For:l,Token_VarCommaList:L,Token_In:_,Token_GeneratorCommaList:C,Token_Do:F,Token_End:B,GetFirstToken:()=>x.Token_For,GetLastToken:()=>x.Token_End}),x}}function de(m,g){let l=n(),[T,L]=G("until",m),b=d(m,g),_;return _=S({Type:"RepeatStat",Body:T,Condition:b,Token_Repeat:l,Token_Until:L,GetFirstToken:()=>_.Token_Repeat,GetLastToken:()=>_.Condition.GetLastToken()}),_}function oe(m,g){let l=n();if(t().Source=="function"){let T=A(!1,m,g,!0);if(T.NameChain.length>1)throw r(T.Token_NameChainSeperator[0])+": `(` expected.";let L;return L=S({Type:"LocalFunctionStat",FunctionStat:T,Token_Local:l,GetFirstToken:()=>L.Token_Local,GetLastToken:()=>L.FunctionStat.GetLastToken()}),L}else if(t().Type=="Ident"||t().Type=="Keyword"&&ke.includes(t().Source)){let[T,L]=w(!1,!0),b=[],_=[],E;if(t().Source=="="){E=n();let[F,$]=p(m,g);b=F,_=$}let C;return C=S({Type:"LocalVarStat",VarList:T,ExprList:b,Token_Local:l,Token_Equals:E,Token_VarCommaList:L,Token_ExprCommaList:_,GetFirstToken:()=>C.Token_Local,GetLastToken:function(){return C.ExprList.length>0?C.ExprList[C.ExprList.length-1].GetLastToken():C.VarList[C.VarList.length-1]}}),C}else throw"`function` or ident expected"}function Te(m,g){let l=n(),T,L;o()||t().Source==";"?(T=[],L=[]):[T,L]=p(m,g);let b;return b={Type:"ReturnStat",ExprList:T,Token_Return:l,Token_CommaList:L,GetFirstToken:()=>b.Token_Return,GetLastToken:function(){return b.ExprList.length>0?b.ExprList[b.ExprList.length-1].GetLastToken():b.Token_Return}},b}function X(){let m=n(),g;return g={Type:"BreakStat",Token_Break:m,GetFirstToken:()=>g.Token_Break,GetLastToken:()=>g.Token_Break},g}function ue(m,g){if(t(1).Source=="(")return[!1,re(m,g)];let l=n(),T;return T={Type:"ContinueStat",Token_Continue:l,GetFirstToken:()=>T.Token_Continue,GetLastToken:()=>T.Token_Continue},[!0,T]}function Ce(){let m=n(),g;t().Type=="Keyword"?g=f("Keyword"):g=f("Ident");let l;return l={Type:"GotoStat",Token_Goto:m,Token_Label:g,GetFirstToken:()=>l.Token_Goto,GetLastToken:()=>l.Token_Label},l}function pe(){let m=n(),g;t().Type=="Keyword"?g=f("Keyword"):g=f("Ident");let l=f("Symbol","::"),T;return T={Type:"LabelStat",Token_ColonsLeft:m,Token_Label:g,Token_ColonsRight:l,GetFirstToken:()=>T.Token_ColonsLeft,GetLastToken:()=>T.Token_ColonsRight},T}function D(m,g){let l=t();return l.Source=="if"?[!1,Ee(!1,m,g)]:l.Source=="while"?[!1,J(m,g)]:l.Source=="do"?[!1,le(m,g)]:l.Source=="for"?[!1,se(m,g)]:l.Source=="repeat"?[!1,de(m,g)]:l.Source=="function"?[!1,A(!1,m,g)]:l.Source=="local"?[!1,oe(m,g)]:l.Source=="return"?[!0,Te(m,g)]:l.Source=="break"?[!0,X(m,g)]:l.Source=="continue"?ue(m,g):l.Source=="goto"?[!1,Ce()]:l.Source=="::"?[!1,pe()]:[!1,re(m,g)]}let ze=1;return k=function(m,g){let l=[],T=[],L=!1,b={},_={};if(g!=null)for(let[B,x]of Object.entries(g))_[B]=x;if(m!=null)for(let[B,x]of Object.entries(m))_[B]=x;let E,C=0;for(;!L&&!o();){E&&E==t()&&Se(`INFINITE LOOP POSSIBLE ON STATEMENT ${E.Source} :`,E),E=t();let[B,x]=D(b,_);if(x)switch(l.push(x),x.Type){case"LocalVarStat":x.VarList.forEach(R=>{R.UseCount=0,R.Number=C++,b[R.Source]=R;let Z=[];function Y(){R.UseCount++,Z.forEach(O=>{O.UseCount=R.UseCount})}R.Tokens={},R.Tokens.push=O=>{O.UseCountIncrease=Y,O.UseCount=R.UseCount,O.Tokens=R.Tokens,Z.push(O)},R.Tokens.get=()=>Z,R.UseCountIncrease=Y});break;case"LocalFunctionStat":let P=x.FunctionStat.NameChain;if(P.length===1){let Y=function(){R.UseCount++,Z.forEach(O=>{O.UseCount=R.UseCount})};var $=Y;let R=P[0];R.UseCount=0,R.Number=C++,b[R.Source]=R;let Z=[];R.Tokens={},R.Tokens.push=O=>{O.UseCountIncrease=Y,O.UseCount=R.UseCount,O.Tokens=R.Tokens,Z.push(O)},R.Tokens.get=()=>Z,R.UseCountIncrease=Y}break;default:break}let V=t();V.Type=="Symbol"&&V.Source==";"&&(T[l.length-1]=n())}let F;return F={Type:"StatList",StatementList:l,SemicolonList:T,GetFirstToken:function(){if(F.StatementList.length!=0)return F.StatementList[0]?.GetFirstToken()},GetLastToken:function(){if(F.StatementList.length!=0)return F.SemicolonList[F.StatementList.length-1]?F.SemicolonList[F.StatementList.length-1]:F.StatementList[F.StatementList.length-1].GetLastToken()}},F},k([],[])}function ge(u,i){let a={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[t,r]of Object.entries(i))if(!(t==="VisitStat"||t==="VisitExpr")&&!n[t]&&!a[t])throw`Invalid visitor target: \`${t}\``;function e(f){if(f!=null){let S=i[f.Type];if(typeof S=="function")return S(f);if(S&&S.Pre)return S.Pre(f)}}function o(f){let S=i[f.Type];if(S&&typeof S=="object"&&S.Post)return S.Post(f)}let s,c;s=function(f){if(!e(f)){if(f.Type=="BinopExpr")s(f.Lhs),s(f.Rhs);else if(f.Type=="UnopExpr")s(f.Rhs);else if(!(f.Type=="NumberLiteral"||f.Type=="StringLiteral"||f.Type=="NilLiteral"||f.Type=="BooleanLiteral"||f.Type=="VargLiteral"||f.Type=="HashLiteral")){if(f.Type=="FieldExpr")s(f.Base);else if(f.Type=="IndexExpr")s(f.Base),s(f.Index);else if(f.Type=="MethodExpr"||f.Type=="CallExpr")s(f.Base),f.FunctionArguments.CallType=="ArgCall"?f.FunctionArguments.ArgList.forEach((S,k)=>{s(S)}):f.FunctionArguments.CallType=="TableCall"&&s(f.FunctionArguments.TableExpr);else if(f.Type=="FunctionLiteral")c(f.Body);else if(f.Type!="VariableExpr")if(f.Type=="ParenExpr")s(f.Expression);else if(f.Type=="TableLiteral")f.EntryList.forEach((S,k)=>{if(S.EntryType=="Field")s(S.Value);else if(S.EntryType=="Index")s(S.Index),s(S.Value);else if(S.EntryType=="Value")s(S.Value);else throw"unreachable"});else if(f.Type=="CompoundStat")s(f.Lhs),s(f.Rhs);else if(f.Type=="IfExpr")s(f.Condition),s(f.Body),f.ElseClauseList.forEach(S=>{S.Condition!=null&&s(S.Condition),s(S.Body)});else throw`unreachable, type: ${f.Type}: ${f}`}o(f)}},c=function(f){if(!e(f)){if(f.Type=="StatList")f.StatementList.forEach((S,k)=>{if(S!=null){if(S===null||S.Type===null)return;S.Remove=()=>{f.StatementList[k]=null},c(S)}});else if(f.Type!="BreakStat"){if(f.Type!="ContinueStat"){if(f.Type!="GotoStat"){if(f.Type!="LabelStat")if(f.Type=="ReturnStat")f.ExprList.forEach((S,k)=>{s(S)});else if(f.Type=="LocalVarStat")f.Token_Equals&&f.ExprList.forEach((S,k)=>{s(S)});else if(f.Type=="LocalFunctionStat")c(f.FunctionStat.Body);else if(f.Type=="FunctionStat")c(f.Body);else if(f.Type=="RepeatStat")c(f.Body),s(f.Condition);else if(f.Type=="GenericForStat")f.GeneratorList.forEach((S,k)=>{s(S)}),c(f.Body);else if(f.Type=="NumericForStat")f.RangeList.forEach((S,k)=>{s(S)}),c(f.Body);else if(f.Type=="WhileStat")s(f.Condition),c(f.Body);else if(f.Type=="DoStat")c(f.Body);else if(f.Type=="IfStat")s(f.Condition),c(f.Body),f.ElseClauseList.forEach(S=>{S.Condition!=null&&s(S.Condition),c(S.Body)});else if(f.Type=="CallExprStat")s(f.Expression);else if(f.Type=="CompoundStat")s(f.Lhs),s(f.Rhs);else if(f.Type=="AssignmentStat")f.Lhs.forEach(S=>{s(S)}),f.Rhs.forEach(S=>{s(S)});else throw"Unreachable code. Got "+f.Type}}}o(f)}},i.VisitStat=c,i.VisitExpr=s,n[u.Type]?c(u):s(u)}function ct(u){let i=[],a,n=0;function t(){return n++,n}function r(){a={ParentScope:a,ChildScopeList:[],VariableList:[],BeginLocation:t(),Depth:null,GetVar:null},a.ParentScope?(a.Depth=a.ParentScope.Depth+1,a.ParentScope.ChildScopeList.push(a)):a.Depth=1;let d=a;a.GetVar=function(p){for(let h of d.VariableList)if(h.Name==p)return h;if(d.ParentScope)return d.ParentScope.GetVar(p);for(let h of i)if(h.Name==p)return h}}function e(){let d=a;return d.EndLocation=t(),d.VariableList.forEach(p=>{p.ScopeEndLocation=d.EndLocation}),a=d.ParentScope,d}r();function o(d,p,h){W(h,"Missing localInfo"),W(d,"Missing local var name");let y={Type:"Local",Name:d,RenameList:[p],AssignedTo:!1,Info:h,Scope:a,BeginLocation:t(),EndLocation:t(),ReferenceLocationList:[t()]};return y.Rename=function(w){y.Name=w,y.RenameList.forEach(G=>{G(w)})},a.VariableList.push(y),y}function s(d){for(let h of i)if(h.Name==d)return h;let p={Type:"Global",Name:d,RenameList:[],AssignedTo:!1,Scope:null,BeginLocation:t(),EndLocation:t(),ReferenceLocationList:[]};return p.Rename=function(h){p.Name=h,p.RenameList.forEach(y=>{y(h)})},i.push(p),p}function c(d,p){W(d,"Missing var name");let h=s(d);return h.RenameList.push(p),h}function f(d,p){let h;for(h=d.VariableList.length-1;h>=0;h--)if(d.VariableList[h].Name==p)return d.VariableList[h];if(d.ParentScope){let y=f(d.ParentScope,p);if(y)return y}}function S(d,p){W(d,"Missing var name");let h=f(a,d);h?h.RenameList.push(p):h=c(d,p);let y=t();return h.EndLocation=y,h.ReferenceLocationList.push(h.EndLocation),h}let k={};return k.FunctionLiteral={Pre:function(d){r(),d.ArgList.forEach((p,h)=>{let y=o(p.Source,function(w,G){G||(p.Source=w)},{Type:"Argument",Index:h});p.var=y})},Post:function(d){e()}},k.VariableExpr=function(d){d.Variable=S(d.Token.Source,function(p,h=!1){h&&d.IsStat||(d.Token.Source=p)})},k.StatList={Pre:function(d){r()},Post:function(d){d.SkipPop||e()}},k.LocalVarStat={Post:function(d){d.VarList.forEach((p,h)=>{o(p.Source,function(y){d.VarList[h].Source=y},{Type:"Local",Expr:d.ExprList})})}},k.LocalFunctionStat={Pre:function(d){o(d.FunctionStat.NameChain[0].Source,function(p){d.FunctionStat.NameChain[0].Source=p},{Type:"LocalFunction"}),r(),d.FunctionStat.ArgList.forEach((p,h)=>{o(p.Source,function(y){p.Source=y},{Type:"Argument",Index:h})})},Post:function(){e()}},k.FunctionStat={Pre:function(d){let p=d.NameChain,h;p.length==1?f(a,p[0].Source)?h=S(p[0].Source,function(y){p[0].Source=y}):h=c(p[0].Source,function(y){p[0].Source=y}):h=S(p[0].Source,function(y){p[0].Source=y}),h.AssignedTo=!0,r(),d.ArgList.forEach((y,w)=>{o(y.Source,function(G){y.Source=G},{Type:"Argument",Index:w})})},Post:function(){e()}},k.GenericForStat={Pre:function(d){return d.GeneratorList.forEach(p=>{ge(p,k)}),r(),d.VarList.forEach((p,h)=>{o(p.Source,function(y){p.Source=y},{Type:"ForRange",Index:h})}),ge(d.Body,k),e(),!0}},k.NumericForStat={Pre:function(d){return d.RangeList.forEach(p=>{ge(p,k)}),r(),d.VarList.forEach((p,h)=>{o(p.Source,function(y){p.Source=y},{Type:"ForRange",Index:h})}),ge(d.Body,k),e(),!0}},k.RepeatStat={Pre:function(d){d.Body.SkipPop=!0},Post:function(d){e()}},k.AssignmentStat={Post:function(d){d.Lhs.forEach(p=>{p.Variable!=null&&(p.Variable.AssignedTo=!0)})}},ge(u,k),[i,e()]}function ft(u){let i,a,n="",t=e=>typeof e?.LeadingWhite!="string"?" ":e.LeadingWhite;function r(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 a=function(e){if(e.Type=="BinopExpr")a(e.Lhs),r(e.Token_Op),a(e.Rhs);else if(e.Type=="UnopExpr")r(e.Token_Op),a(e.Rhs);else if(e.Type=="NumberLiteral"||e.Type=="StringLiteral"||e.Type=="NilLiteral"||e.Type=="BooleanLiteral"||e.Type=="VargLiteral"||e.Type=="HashLiteral")r(e.Token);else if(e.Type=="FieldExpr")a(e.Base),r(e.Token_Dot),r(e.Field);else if(e.Type=="IndexExpr")a(e.Base),r(e.Token_OpenBracket),a(e.Index),r(e.Token_CloseBracket);else if(e.Type=="MethodExpr"||e.Type=="CallExpr")a(e.Base),e.Type=="MethodExpr"&&(r(e.Token_Colon),r(e.Method)),e.FunctionArguments.CallType=="StringCall"?r(e.FunctionArguments.Token):e.FunctionArguments.CallType=="ArgCall"?(r(e.FunctionArguments.Token_OpenParen),e.FunctionArguments.ArgList.forEach((o,s)=>{a(o);let c=e.FunctionArguments.Token_CommaList[s];c!=null&&r(c)}),r(e.FunctionArguments.Token_CloseParen)):e.FunctionArguments.CallType=="TableCall"&&a(e.FunctionArguments.TableExpr);else if(e.Type=="FunctionLiteral")r(e.Token_Function),r(e.Token_OpenParen),e.ArgList.forEach((o,s)=>{r(o);let c=e.Token_ArgCommaList[s];c!=null&&r(c)}),e.Token_Varg!=null&&r(e.Token_Varg),r(e.Token_CloseParen),i(e.Body),r(e.Token_End);else if(e.Type=="VariableExpr")r(e.Token);else if(e.Type=="ParenExpr")r(e.Token_OpenParen),a(e.Expression),r(e.Token_CloseParen);else if(e.Type=="TableLiteral")r(e.Token_OpenBrace),e.EntryList.forEach((o,s)=>{if(o.EntryType=="Field")r(o.Field),r(o.Token_Equals),a(o.Value);else if(o.EntryType=="Index")r(o.Token_OpenBracket),a(o.Index),r(o.Token_CloseBracket),r(o.Token_Equals),a(o.Value);else if(o.EntryType=="Value")a(o.Value);else throw"unreachable";let c=e.Token_SeperatorList[s];c!=null&&r(c)}),r(e.Token_CloseBrace);else if(e.Type=="CompoundStat")i(e);else if(e.Type=="IfExpr")r(e.Token_If),a(e.Condition),r(e.Token_Then),a(e.Body),e.ElseClauseList.forEach(o=>{r(o.Token),o.Condition!=null&&(a(o.Condition),r(o.Token_Then)),a(o.Body)});else throw`unreachable, type: ${e.Type}: ${e}`},i=function(e){if(e==null)throw`STAT IS NIL! ${e}`;if(!(e.Type==="StatList"&&e.StatementList.length===0)){if(e.WrapInDo){let o=t(e.GetFirstToken());e.GetFirstToken().LeadingWhite="",n+=`${o}do `}e.Type=="StatList"?e.StatementList.forEach((o,s)=>{o===null||o.Type===null||(o.Remove=()=>{e.StatementList[s]=null},i(o),e.SemicolonList[s]&&r(e.SemicolonList[s]))}):e.Type=="BreakStat"?r(e.Token_Break):e.Type=="ContinueStat"?r(e.Token_Continue):e.Type=="GotoStat"?(r(e.Token_Goto),r(e.Token_Label)):e.Type=="LabelStat"?(r(e.Token_ColonsLeft),r(e.Token_Label),r(e.Token_ColonsRight)):e.Type=="ReturnStat"?(r(e.Token_Return),e.ExprList.forEach((o,s)=>{a(o),e.Token_CommaList[s]&&r(e.Token_CommaList[s])})):e.Type=="LocalVarStat"?(r(e.Token_Local),e.VarList.forEach((o,s)=>{r(o),o.Attribute!=null&&r(o.Attribute);let c=e.Token_VarCommaList[s];c!=null&&r(c)}),e.Token_Equals!=null&&(r(e.Token_Equals),e.ExprList.forEach((o,s)=>{a(o);let c=e.Token_ExprCommaList[s];c!=null&&r(c)}))):e.Type=="LocalFunctionStat"?(r(e.Token_Local),r(e.FunctionStat.Token_Function),r(e.FunctionStat.NameChain[0]),r(e.FunctionStat.Token_OpenParen),e.FunctionStat.ArgList.forEach((o,s)=>{r(o);let c=e.FunctionStat.Token_ArgCommaList[s];c!=null&&r(c)}),e.FunctionStat.Token_Varg&&r(e.FunctionStat.Token_Varg),r(e.FunctionStat.Token_CloseParen),i(e.FunctionStat.Body),r(e.FunctionStat.Token_End)):e.Type=="FunctionStat"?(r(e.Token_Function),e.NameChain.forEach((o,s)=>{r(o);let c=e.Token_NameChainSeperator[s];c!=null&&r(c)}),r(e.Token_OpenParen),e.ArgList.forEach((o,s)=>{r(o);let c=e.Token_ArgCommaList[s];c!=null&&r(c)}),e.Token_Varg&&r(e.Token_Varg),r(e.Token_CloseParen),i(e.Body),r(e.Token_End)):e.Type=="RepeatStat"?(r(e.Token_Repeat),i(e.Body),r(e.Token_Until),a(e.Condition)):e.Type=="GenericForStat"?(r(e.Token_For),e.VarList.forEach((o,s)=>{r(o);let c=e.Token_VarCommaList[s];c!=null&&r(c)}),r(e.Token_In),e.GeneratorList.forEach((o,s)=>{a(o);let c=e.Token_GeneratorCommaList[s];c!=null&&r(c)}),r(e.Token_Do),i(e.Body),r(e.Token_End)):e.Type=="NumericForStat"?(r(e.Token_For),e.VarList.forEach((o,s)=>{r(o);let c=e.Token_VarCommaList[s];c!=null&&r(c)}),r(e.Token_Equals),e.RangeList.forEach((o,s)=>{a(o);let c=e.Token_RangeCommaList[s];c!=null&&r(c)}),r(e.Token_Do),i(e.Body),r(e.Token_End)):e.Type=="WhileStat"?(r(e.Token_While),a(e.Condition),r(e.Token_Do),i(e.Body),r(e.Token_End)):e.Type=="DoStat"?(r(e.Token_Do),i(e.Body),r(e.Token_End)):e.Type=="IfStat"?(r(e.Token_If),a(e.Condition),r(e.Token_Then),i(e.Body),e.ElseClauseList.forEach(o=>{r(o.Token),o.Condition!=null&&(a(o.Condition),r(o.Token_Then)),i(o.Body)}),r(e.Token_End)):e.Type=="CallExprStat"?a(e.Expression):e.Type=="CompoundStat"?(a(e.Lhs),r(e.Token_Compound),a(e.Rhs),e.Type="CompoundStat"):e.Type=="AssignmentStat"?(e.Lhs.forEach((o,s)=>{a(o);let c=e.Token_LhsSeperatorList[s];c!=null&&r(c)}),r(e.Token_Equals),e.Rhs.forEach((o,s)=>{a(o);let c=e.Token_RhsSeperatorList[s];c!=null&&r(c)})):W(!1,"unreachable"),e.WrapInDo&&(n+=" end ")}},i(u),n}function dt(u){let i,a;function n(e){e&&(e.LeadingWhite="")}function t(e,o,s=!1){n(o);let c=(typeof e.Source=="string"?e.Source:e.Source.toString()).substr(e.Source.length-1,1),f=(typeof o.Source=="string"?o.Source:o.Source.toString()).substr(0,1);c=="-"&&f=="-"||Pe.includes(c)&&Pe.includes(f)||s&&c==")"&&f=="("?o.LeadingWhite=s?";":" ":o.LeadingWhite=""}function r(e,o,s){i(o),n(s);let c=o.GetFirstToken(),f=o.GetLastToken();c!=null?(t(e,c),t(f,s)):t(e,s)}a=function(e){if(e.Type==="BinopExpr")a(e.Lhs),a(e.Rhs),e.Lhs.Type=="NumberLiteral"&&e.Token_Op.Source==".."?e.Token_Op.LeadingWhite=" ":(n(e.Token_Op),t(e.Lhs.GetLastToken(),e.Token_Op)),t(e.Token_Op,e.Rhs.GetFirstToken());else if(e.Type==="UnopExpr")n(e.Token_Op),a(e.Rhs),t(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")a(e.Base),n(e.Token_Dot),n(e.Field);else if(e.Type=="IndexExpr")a(e.Base),n(e.Token_OpenBracket),a(e.Index),n(e.Token_CloseBracket);else if(e.Type=="MethodExpr"||e.Type=="CallExpr")a(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((o,s)=>{a(o);let c=e.FunctionArguments.Token_CommaList[s];c!=null&&n(c)}),n(e.FunctionArguments.Token_CloseParen)):e.FunctionArguments.CallType=="TableCall"&&a(e.FunctionArguments.TableExpr);else if(e.Type=="FunctionLiteral")n(e.Token_Function),n(e.Token_OpenParen),e.ArgList.forEach((o,s)=>{n(o);let c=e.Token_ArgCommaList[s];c!=null&&n(c)}),e.Token_Varg!=null&&n(e.Token_Varg),n(e.Token_CloseParen),r(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),a(e.Expression),n(e.Token_CloseParen);else if(e.Type=="IfExpr"){n(e.Token_If),a(e.Condition),t(e.Token_If,e.Condition.GetFirstToken()),t(e.Condition.GetLastToken(),e.Token_Then);let o=e.Token_Then,s=e.Body;e.ElseClauseList.forEach((c,f)=>{t(o,s.GetFirstToken()),t(s.GetLastToken(),c.Token),o=c.Token,c.Condition!=null&&(a(c.Condition),t(c.Token,c.Condition.GetFirstToken()),t(c.Condition.GetLastToken(),c.Token_Then),o=c.Token_Then),a(c.Body),s=c.Body}),t(o,s.GetFirstToken())}else if(e.Type=="TableLiteral")n(e.Token_OpenBrace),e.EntryList.forEach((o,s)=>{o.EntryType=="Field"?(n(o.Field),n(o.Token_Equals),a(o.Value)):o.EntryType=="Index"?(n(o.Token_OpenBracket),a(o.Index),n(o.Token_CloseBracket),n(o.Token_Equals),a(o.Value)):o.EntryType=="Value"?a(o.Value):W(!1,"unreachable");let c=e.Token_SeperatorList[s];c!=null&&n(c)}),e.Token_SeperatorList[e.EntryList.length-1]=null,n(e.Token_CloseBrace);else throw`unreachable, type: ${e.Type}:${e} ${console.trace()}`},i=function(e){if(e.Type=="StatList"){let o;for(o=0;o<=e.StatementList.length;o++){let s=e.StatementList[o];if(s==null)continue;i(s),n(s.GetFirstToken());let c=e.StatementList[o-1];if(c!=null){let f={")":["(","["],"]":["(","["]};if(e.SemicolonList[o-1]){let S=c.GetLastToken().Source,k=s.GetFirstToken().Source;(f[S]===null||f[S]===void 0||!f[S].includes(k))&&(e.SemicolonList[o-1]=null)}e.SemicolonList[o-1]||t(c.GetLastToken(),s.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),t(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((o,s)=>{a(o),e.Token_CommaList[s]!=null&&n(e.Token_CommaList[s])}),e.ExprList.length>0&&t(e.Token_Return,e.ExprList[0].GetFirstToken());else if(e.Type=="LocalVarStat"){n(e.Token_Local);let o=!1;e.VarList.forEach((s,c)=>{c==0?t(e.Token_Local,s):n(s),s.Attribute&&(n(s.Attribute),c+1==e.VarList.length&&(o=!0));let f=e.Token_VarCommaList[c];f!=null&&n(f)}),e.Token_Equals!=null&&(o||n(e.Token_Equals),e.ExprList.forEach((s,c)=>{a(s);let f=e.Token_ExprCommaList[c];f!=null&&n(f)}))}else if(e.Type=="LocalFunctionStat")n(e.Token_Local),t(e.Token_Local,e.FunctionStat.Token_Function),t(e.FunctionStat.Token_Function,e.FunctionStat.NameChain[0]),t(e.FunctionStat.NameChain[0],e.FunctionStat.Token_OpenParen),e.FunctionStat.ArgList.forEach((o,s)=>{n(o);let c=e.FunctionStat.Token_ArgCommaList[s];c!=null&&n(c)}),e.FunctionStat.Token_Varg&&n(e.FunctionStat.Token_Varg),n(e.FunctionStat.Token_CloseParen),r(e.FunctionStat.Token_CloseParen,e.FunctionStat.Body,e.FunctionStat.Token_End);else if(e.Type=="FunctionStat")n(e.Token_Function),e.NameChain.forEach((o,s)=>{s==0?t(e.Token_Function,o):n(o);let c=e.Token_NameChainSeperator[s];c!=null&&n(c)}),n(e.Token_OpenParen),e.ArgList.forEach((o,s)=>{n(o);let c=e.Token_ArgCommaList[s];c!=null&&n(c)}),e.Token_Varg&&n(e.Token_Varg),n(e.Token_CloseParen),r(e.Token_CloseParen,e.Body,e.Token_End);else if(e.Type=="RepeatStat")n(e.Token_Repeat),r(e.Token_Repeat,e.Body,e.Token_Until),a(e.Condition),t(e.Token_Until,e.Condition.GetFirstToken());else if(e.Type=="GenericForStat")n(e.Token_For),e.VarList.forEach((o,s)=>{s==0?t(e.Token_For,o):n(o);let c=e.Token_VarCommaList[s];c!=null&&n(c)}),t(e.VarList[e.VarList.length-1],e.Token_In),e.GeneratorList.forEach((o,s)=>{a(o),s==0&&t(e.Token_In,o.GetFirstToken());let c=e.Token_GeneratorCommaList[s];c!=null&&n(c)}),t(e.GeneratorList[e.GeneratorList.length-1].GetLastToken(),e.Token_Do),r(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="NumericForStat")n(e.Token_For),e.VarList.forEach((o,s)=>{s==0?t(e.Token_For,o):n(o);let c=e.Token_VarCommaList[s];c!=null&&n(c)}),t(e.VarList[e.VarList.length-1],e.Token_Equals),e.RangeList.forEach((o,s)=>{a(o),s==0&&t(e.Token_Equals,o.GetFirstToken());let c=e.Token_RangeCommaList[s];c!=null&&n(c)}),t(e.RangeList[e.RangeList.length-1].GetLastToken(),e.Token_Do),r(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="WhileStat")n(e.Token_While),a(e.Condition),n(e.Token_Do),t(e.Token_While,e.Condition.GetFirstToken()),t(e.Condition.GetLastToken(),e.Token_Do),r(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="DoStat")n(e.Token_Do),n(e.Token_End),r(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="IfStat"){n(e.Token_If),a(e.Condition),t(e.Token_If,e.Condition.GetFirstToken()),t(e.Condition.GetLastToken(),e.Token_Then);let o=e.Token_Then,s=e.Body;e.ElseClauseList.forEach((c,f)=>{r(o,s,c.Token),o=c.Token,c.Condition!=null&&(a(c.Condition),t(c.Token,c.Condition.GetFirstToken()),t(c.Condition.GetLastToken(),c.Token_Then),o=c.Token_Then),i(c.Body),s=c.Body}),r(o,s,e.Token_End)}else if(e.Type=="CallExprStat")a(e.Expression);else if(e.Type=="CompoundStat")a(e.Lhs),n(e.Token_Compound),a(e.Rhs),t(e.Lhs.GetLastToken(),e.Token_Compound),t(e.Token_Compound,e.Rhs.GetFirstToken());else if(e.Type=="AssignmentStat")e.Lhs.forEach((o,s)=>{a(o);let c=e.Token_LhsSeperatorList[s];c!=null&&n(c)}),n(e.Token_Equals),e.Rhs.forEach((o,s)=>{a(o);let c=e.Token_RhsSeperatorList[s];c!=null&&n(c)});else return a(e)},i(u)}var ie=[],I;for(I=97;I<=122;I++)ie.push(String.fromCharCode(I));for(I=65;I<=90;I++)ie.push(String.fromCharCode(I));for(I=48;I<=57;I++)ie.push(String.fromCharCode(I));ie.push("_");var Le=[];for(I=97;I<=122;I++)Le.push(String.fromCharCode(I));for(I=65;I<=90;I++)Le.push(String.fromCharCode(I));function nn(u){let i="",a=u%Le.length;for(u=(u-a)/Le.length,i=`${i}${Le[a]}`;u>0;){let n=u%ie.length;u=(u-n)/ie.length,i=`${i}${ie[n]}`}return i}function Tt(u,i,a){let n=[];for(var[t,r]of Object.entries(tn))n[t]=!0;let e=[],o=[];u.forEach(k=>{k.AssignedTo&&a?e.push(k):n[k.Name]=!0});function s(k){k.VariableList.forEach(d=>{e.push(d),o.push(d)}),k.ChildScopeList.forEach(d=>{s(d)})}s(i),e.forEach(k=>{k.UsedNameArray=[]}),e.sort((k,d)=>k-d);let c=0,f=[];function S(k){let d=f[k];if(d==null){for(d=nn(c),c++;n[d];)d=nn(c),c++;f[k]=d}return d}e.forEach((k,d)=>{k.Renamed=!0;let p=0;for(;k.UsedNameArray[p];)p++;k.Rename(S(p)),k.Scope?e.forEach(h=>{h.Renamed||(!h.Scope||h.Scope.Depth<k.Scope.Depth?h.ReferenceLocationList.some(y=>y>=k.BeginLocation&&y<=k.ScopeEndLocation?(h.UsedNameArray[p]=!0,!0):!1):h.Scope.Depth>k.Scope.Depth?k.ReferenceLocationList.some(y=>y>=h.BeginLocation&&y<=h.ScopeEndLocation?(h.UsedNameArray[p]=!0,!0):!1):k.BeginLocation<h.EndLocation&&k.EndLocation>h.BeginLocation&&(h.UsedNameArray[p]=!0))}):e.forEach(h=>{if(!h.Renamed)if(h.Type=="Global")h.UsedNameArray[p]=!0;else if(h.Type=="Local")k.ReferenceLocationList.some(y=>y>=h.BeginLocation&&y<=h.ScopeEndLocation?(h.UsedNameArray[p]=!0,!0):!1);else throw"Unreachable"})})}var rn={};rn.Minify=function(u,i){let a=at(u),[n,t]=ct(a);i.RenameVariables==!0&&Tt(n,t,i.RenameGlobals),i.SolveMath==!0&&SolveMath(a),dt(a);let r=ft(a);return r=`${r}`,r};try{$e!=null&&$e.exports!=null&&($e.exports.Minify=rn.Minify)}catch{}});var cn=U((co,an)=>{var Ve=require("fs-extra"),pt=require("path");function un(u,i){let a=0,n=i,t=u.length,r=!1,e="";for(;n<t;){let o=u[n];if(r){if(o==="\\"){n+=2;continue}o===e&&(r=!1)}else{if(o==='"'||o==="'"){r=!0,e=o,n++;continue}if(o==="{")a++;else if(o==="}"&&(a--,a===0))return n}n++}return-1}function sn(u,i){let a=new RegExp(`^\\s*${i}\\s*\\{`,"m"),n=u.match(a);if(!n)return null;let t=n.index,r=u.indexOf("{",t);if(r===-1)return null;let e=un(u,r);return e===-1?null:{header:n[0],blockStart:t,blockEnd:e,blockContent:u.substring(t,e+1)}}function ht(u,i,a,n,t=!1){let r=["fxmanifest.lua","__resource.lua"],e=null;for(let h of r){let y=pt.join(u,h);if(Ve.existsSync(y)){e=y;break}}if(!e){console.log("\x1B[33m! No fxmanifest.lua or __resource.lua found. Skipping manifest injection.\x1B[0m");return}let o=Ve.readFileSync(e,"utf8"),s=!1,c=(h,y)=>{let w=h.replace("_scripts","_script").replace("files","file"),G=h,A=`'ltbridge/modules/${y}'`,j=sn(o,G);if(j){if(j.blockContent.includes(A))return;let q=o.indexOf("{",j.blockStart);o=o.substring(0,q+1)+`
|
|
10
|
+
${A},`+o.substring(q+1),s=!0;return}let te=new RegExp(`^\\s*${w}\\s+(['"].+?['"])`,"m"),H=o.match(te);if(H){if(H[0].includes(A))return;let q=H[1],re=`${G} {
|
|
11
|
+
${A},
|
|
12
12
|
${q}
|
|
13
13
|
}`;o=o.replace(H[0],re),s=!0;return}o+=`
|
|
14
14
|
|
|
15
15
|
${G} {
|
|
16
|
-
${
|
|
16
|
+
${A}
|
|
17
17
|
}`,s=!0},f=h=>{let y=h.replace(/[*.]/g,"\\$&"),w=new RegExp(`\\s*['"]ltbridge\\/modules\\/${y}['"],?`,"g");w.test(o)&&(o=o.replace(w,""),s=!0)},S="shared.lua",k="client.lua",d="server.lua";n?c("shared_scripts",S):f(S),i?c("client_scripts",k):f(k),a?c("server_scripts",d):f(d),(()=>{if(o.includes("'ltbridge/**/*.lua'")||o.includes('"ltbridge/**/*.lua"'))return;let h=sn(o,"escrow_ignore");if(h){let G=o.indexOf("{",h.blockStart);o=o.substring(0,G+1)+`
|
|
18
|
-
'ltbridge/**/*.lua',`+o.substring(G+1),s=!0;return}let y=/^(\s*)escrow_ignore\s+(['"].+?['"])/m,w=o.match(y);if(w){let
|
|
18
|
+
'ltbridge/**/*.lua',`+o.substring(G+1),s=!0;return}let y=/^(\s*)escrow_ignore\s+(['"].+?['"])/m,w=o.match(y);if(w){let A=`escrow_ignore {
|
|
19
19
|
'ltbridge/**/*.lua',
|
|
20
20
|
${w[2]}
|
|
21
|
-
}`;o=o.replace(w[0],
|
|
21
|
+
}`;o=o.replace(w[0],A),s=!0;return}o+=`
|
|
22
22
|
|
|
23
23
|
escrow_ignore {
|
|
24
24
|
'ltbridge/**/*.lua'
|
|
25
|
-
}`,s=!0})(),t&&(n||i)?c("files","imports/**/*.lua"):(f("imports/**/*.lua"),f("modules/**/*.lua")),s&&(Ve.writeFileSync(e,o),console.log("\x1B[32m\u2713 Updated manifest.\x1B[0m"))}an.exports={injectManifest:ht,findBlockEnd:un}});var Oe=
|
|
25
|
+
}`,s=!0})(),t&&(n||i)?c("files","imports/**/*.lua"):(f("imports/**/*.lua"),f("modules/**/*.lua")),s&&(Ve.writeFileSync(e,o),console.log("\x1B[32m\u2713 Updated manifest.\x1B[0m"))}an.exports={injectManifest:ht,findBlockEnd:un}});var Oe=U((fo,pn)=>{var v=require("fs-extra"),K=require("path"),{applyBuildConstants:mt}=Je(),Re=null;function fn(){if(Re)return Re;let{getDatabase:u}=ne();return Re=u().exportMap,Re}function dn(u){let{getDatabase:i}=ne(),a=i(),n=[],t=new Set,r=new Map;for(let[S,k]of Object.entries(a.modules)){k.ns&&t.add(`LT.${k.ns} = LT.${k.ns} or {}`);let d=h=>{if(!(!h||!h.types))for(let y of h.types)y&&y.className&&y.code&&r.set(y.className,y.code)},p=h=>{if(h&&h.stubs)for(let y of h.stubs)y.stubCode&&!y.metadata.internal&&n.push(y.stubCode)};d(k.shared),d(k.client),d(k.server),p(k.shared),p(k.client),p(k.server)}let e=K.join(u,"ltbridge");v.ensureDirSync(e);let o=`--- @meta
|
|
26
26
|
--- LT Bridge API Reference
|
|
27
27
|
--- Auto-generated stub file for IDE intellisense.
|
|
28
28
|
--- Do NOT include this file in your fxmanifest.
|
|
@@ -38,7 +38,7 @@ escrow_ignore {
|
|
|
38
38
|
`:"",f=o+s+c+n.join(`
|
|
39
39
|
|
|
40
40
|
`)+`
|
|
41
|
-
`;v.writeFileSync(K.join(e,"api.lua"),f)}function kt(u,i,a={}){let{version:n}=xe(),t=a.skipApi===!0;if(i.version!==n){t?console.log(`\x1B[36m\u2139 LTBridge version updated (${i.version||"unknown"} -> ${n}). Run 'ltbridge api' to refresh API stubs.\x1B[0m`):(console.log(`\x1B[36m\u2139 LTBridge version updated (${i.version||"unknown"} -> ${n}). Regenerating API stubs...\x1B[0m`),dn(u)),i.version=n;let l=K.join(u,"ltbridge","ltbridge.config.json");v.writeFileSync(l,JSON.stringify(i,null,2))}let r=Date.now(),e=i.modules||[],o=i.minify
|
|
41
|
+
`;v.writeFileSync(K.join(e,"api.lua"),f)}function kt(u,i,a={}){let{version:n}=xe(),t=a.skipApi===!0;if(i.version!==n){t?console.log(`\x1B[36m\u2139 LTBridge version updated (${i.version||"unknown"} -> ${n}). Run 'ltbridge api' to refresh API stubs.\x1B[0m`):(console.log(`\x1B[36m\u2139 LTBridge version updated (${i.version||"unknown"} -> ${n}). Regenerating API stubs...\x1B[0m`),dn(u)),i.version=n;let l=K.join(u,"ltbridge","ltbridge.config.json");v.writeFileSync(l,JSON.stringify(i,null,2))}let r=Date.now(),e=i.modules||[],o=i.minify===!0,s=i.buildAsBundle!==!0,c=[],{resolveDependencies:f}=Ge();e.length>0&&(c=f(e,fn()).sequence),c=["__init__",...c.filter(l=>l!=="__init__")];let{getModuleData:S}=ne(),k=!1,d=!1,p=!1,h={},y={},w=[],G=l=>{let T=S(l);if(!T)return;let L=T.ns,b=F=>{let $=T[F];if($){if($.stubs)for(let P of $.stubs)h[P.funcName]=L,y[P.funcName]=P.metadata;let B=$.code,x=`
|
|
42
42
|
-- Module: ${l} (${F}.lua)
|
|
43
43
|
`,V=B;return o||(V=B.split(`
|
|
44
44
|
`).map(P=>P.trim().length>0&&!s?" "+P:P).join(`
|
|
@@ -47,9 +47,9 @@ escrow_ignore {
|
|
|
47
47
|
${V}
|
|
48
48
|
end
|
|
49
49
|
`}return null},_=b("shared"),E=b("client"),C=b("server");(_||E||C)&&(w.push({modName:l,ns:L,shared:_||"",client:E||"",server:C||""}),_&&(p=!0),E&&(k=!0),C&&(d=!0))};a.details&&(console.log(`
|
|
50
|
-
\x1B[1m\x1B[35m\u{1F4E6} Bundling Sequence (${c.length} modules):\x1B[0m`),c.forEach((l,T)=>console.log(` \x1B[90m${(T+1).toString().padStart(2,"0")}.\x1B[0m ${l}`)),console.log(""));for(let l of c)G(l);let
|
|
50
|
+
\x1B[1m\x1B[35m\u{1F4E6} Bundling Sequence (${c.length} modules):\x1B[0m`),c.forEach((l,T)=>console.log(` \x1B[90m${(T+1).toString().padStart(2,"0")}.\x1B[0m ${l}`)),console.log(""));for(let l of c)G(l);let A=ln(),j=(l,T)=>{if(!o)return l;try{return A.Minify(l,{RenameVariables:!0,RenameGlobals:!1,SolveMath:!1})}catch(L){return console.log(`\x1B[33m! Minification failed for ${T}. Emitting unminified code. Error: ${L.message}\x1B[0m`),l}},te=["LT","QBCore","ESX","QBX","exports"],H=new Set,q=l=>{let T=/^([a-zA-Z_][a-zA-Z0-9_]*)\s*=/gm,L;for(;(L=T.exec(l))!==null;){let b=L[1];te.includes(b)||H.add(b)}},re=i.debug===!1||i.debug===void 0;for(let l of w)l.shared&&(l.shared=mt(l.shared,{version:n,disableDebug:re}));if(o)for(let l of w)l.shared&&q(l.shared),l.client&&q(l.client),l.server&&q(l.server);let Ee=require("crypto"),le=l=>Ee.createHash("md5").update(l).digest("hex").substring(0,5),J={},se=new Set;for(let l of H){let T=le(l),L=0;for(;se.has(T);)L++,T=le(l+L);se.add(T),J[l]="__"+T}let de=l=>{if(!l)return l;let T=Object.keys(J);if(T.length===0)return l;let L=T.sort((_,E)=>E.length-_.length).map(_=>_.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),b=new RegExp(`\\[\\[[\\s\\S]*?\\]\\]|'(?:[^'\\\\]|\\\\.)*'|"(?:[^"\\\\]|\\\\.)*"|\\b(${L.join("|")})\\b`,"g");return l.replace(b,(_,E)=>E&&J[E]?J[E]:_)};if(o)for(let l of w)l.shared=de(l.shared),l.client=de(l.client),l.server=de(l.server);let oe={shared:new Set,client:new Set,server:new Set},Te=(l,T)=>{if(!l)return l;let L=Object.keys(h).sort((C,F)=>F.length-C.length);if(L.length===0)return l;let b=l,_=new Set,E="";for(let C of L){let F=h[C],$=F?`LT.${F}.`:"LT.",B=y[C]||{};if(o&&B.internal){if(!J[C]){let he=le(C),we=0;for(;se.has(he);)we++,he=le(C+we);se.add(he),J[C]="__"+he}let ee=J[C],Fe=new RegExp(`(^|[^a-zA-Z0-9_.:"'])(${C})(\\s*[=().,\\[\\]])`,"g");b=b.replace(Fe,`$1${ee}$3`);continue}let x=`${$}${C}`,V=!!F;if(B.export){if(x=`${$}${B.export}`,B.global){let ee=B.global===!0?B.export:B.global;E+=`LT.${ee} = ${x}
|
|
51
51
|
`}}else B.global&&(x=`LT.${B.global===!0?C:B.global}`,V=!1);let P=new RegExp(`\\b${C}\\b`).test(l);if(V&&P&&(T?T.add(`LT.${F} = LT.${F} or {}`):_.add(`LT.${F} = LT.${F} or {}`)),B.alias&&P&&B.alias.forEach(ee=>{E+=`${$}${ee} = ${x}
|
|
52
|
-
`}),!P)continue;let
|
|
52
|
+
`}),!P)continue;let R=new RegExp(`(^[ \\t]*function\\s+)${C}(\\s*\\()`,"gm");b=b.replace(R,`$1${x}$2`);let Z=$.replace(/\./g,"\\."),Y=new RegExp(`\\b${Z}(${C})(\\s*\\()`,"g");b=b.replace(Y,"$1$2");let O=new RegExp(`(^|[^a-zA-Z0-9_.:"'])(${C})(\\s*\\()`,"g");b=b.replace(O,(ee,Fe,he,we)=>Fe.trim().endsWith("function")?ee:`${Fe}${x}${we}`)}return T?b+(E.length>0?`
|
|
53
53
|
-- Exports
|
|
54
54
|
${E}`:""):`LT = LT or {}
|
|
55
55
|
`+Array.from(_).join(`
|
|
@@ -61,11 +61,11 @@ ${E}`:""):`LT = LT or {}
|
|
|
61
61
|
${E}`:"")},X={shared:"",client:"",server:""},ue=[];for(let l of w)l.shared=Te(l.shared,s?null:oe.shared),l.client=Te(l.client,s?null:oe.client),l.server=Te(l.server,s?null:oe.server),s?(l.shared&&ue.push({path:ve(l.modName,"shared"),content:j(l.shared,`${l.modName} shared.lua`),type:"shared",ns:l.ns}),l.client&&ue.push({path:ve(l.modName,"client"),content:j(l.client,`${l.modName} client.lua`),type:"client",ns:l.ns}),l.server&&ue.push({path:ve(l.modName,"server"),content:j(l.server,`${l.modName} server.lua`),type:"server",ns:l.ns})):(l.shared&&(X.shared+=j(l.shared,`${l.modName} shared.lua`)+`
|
|
62
62
|
`),l.client&&(X.client+=j(l.client,`${l.modName} client.lua`)+`
|
|
63
63
|
`),l.server&&(X.server+=j(l.server,`${l.modName} server.lua`)+`
|
|
64
|
-
`));let Ce=K.join(u,"ltbridge"),pe=new Set,
|
|
64
|
+
`));let Ce=K.join(u,"ltbridge"),pe=new Set,D=(l,T)=>{let L=l.replace(/\\/g,"/"),b=K.join(Ce,L);if(v.ensureDirSync(K.dirname(b)),v.existsSync(b))try{if(v.readFileSync(b,"utf8")===T){pe.add(L);return}}catch{}v.writeFileSync(b,T),pe.add(L)},ze=`=== LTBridge Auto-Generated Modules ===
|
|
65
65
|
These files were automatically generated and/or minified by LTBridge.
|
|
66
66
|
Repository: https://github.com/laot7490/ltbridge
|
|
67
67
|
LTBridge Version: ${n}
|
|
68
|
-
`;
|
|
68
|
+
`;D("README.txt",ze);let{injectManifest:m}=cn(),g=l=>`--[[
|
|
69
69
|
* @license LT Bridge
|
|
70
70
|
* ${l.toLowerCase()}.lua
|
|
71
71
|
*
|
|
@@ -75,50 +75,60 @@ LTBridge Version: ${n}
|
|
|
75
75
|
* LICENSE file in the root directory of this source tree.
|
|
76
76
|
]]
|
|
77
77
|
|
|
78
|
-
`;if(s){let l={shared:[],client:[],server:[]};for(let L of ue){let b="modules/"+L.path.replace(/\\/g,"/");
|
|
78
|
+
`;if(s){let l={shared:[],client:[],server:[]};for(let L of ue){let b="modules/"+L.path.replace(/\\/g,"/");D(b,g(L.type)+`--- @diagnostic disable
|
|
79
79
|
`+L.content);let _=L.path.replace(/\\/g,"/").replace(/^imports\//,"");l[L.type].push(` "${_}"`)}let T=(L,b)=>b.length===0?"":`-- LTBridge Auto-Generated ${L} Loader
|
|
80
|
-
|
|
80
|
+
|
|
81
|
+
local RESOURCE <const> = GetCurrentResourceName()
|
|
82
|
+
local BASE_PATH <const> = "ltbridge/modules/imports/"
|
|
83
|
+
|
|
84
|
+
local modules = {
|
|
81
85
|
${b.join(`,
|
|
82
86
|
`)}
|
|
83
87
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
local
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
else
|
|
95
|
-
print("^6[LTBridge ${n}] ^1ERROR: Module file not found: " .. modPathSuffix .. "^7")
|
|
88
|
+
|
|
89
|
+
local function loadModule(path)
|
|
90
|
+
local fullPath = BASE_PATH .. path
|
|
91
|
+
local content = LoadResourceFile(RESOURCE, fullPath)
|
|
92
|
+
if not content then
|
|
93
|
+
return print(("^6[LTBridge ${n}] ^1ERROR: Module file not found: %s^7"):format(path))
|
|
94
|
+
end
|
|
95
|
+
local chunk, err = load(content, ("@@%s/%s"):format(RESOURCE, fullPath))
|
|
96
|
+
if not chunk then
|
|
97
|
+
return print(("^6[LTBridge ${n}] ^1ERROR: Syntax error in module: %s\\n%s^7"):format(fullPath, err))
|
|
96
98
|
end
|
|
99
|
+
local ok, runtimeErr = pcall(chunk)
|
|
100
|
+
if not ok then
|
|
101
|
+
print(("^6[LTBridge ${n}] ^1ERROR: Runtime error in module: %s\\n%s^7"):format(fullPath, runtimeErr))
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
for i = 1, #modules do
|
|
106
|
+
loadModule(modules[i])
|
|
97
107
|
end
|
|
98
|
-
`;p&&
|
|
108
|
+
`;p&&D("modules/shared.lua",T("Shared",l.shared)),k&&D("modules/client.lua",T("Client",l.client)),d&&D("modules/server.lua",T("Server",l.server)),m(u,k,d,p,!0)}else{let l=T=>`LT = LT or {}
|
|
99
109
|
`+Array.from(oe[T]).join(`
|
|
100
110
|
`)+(oe[T].size>0?`
|
|
101
111
|
|
|
102
112
|
`:`
|
|
103
|
-
`);p&&
|
|
104
|
-
`+l("shared")+X.shared),k&&
|
|
105
|
-
`+l("client")+X.client),d&&
|
|
106
|
-
`+l("server")+X.server),m(u,k,d,p,!1)}gt(Ce,pe),console.log(`\x1B[32m\u2713\x1B[0m ${c.length} modules bundled in ${Date.now()-r}ms`)}function gt(u,i){let a=K.join(u,"modules");v.existsSync(a)&&Tn(a,u,i);let n=K.join(u,"README.txt");v.existsSync(n)&&!i.has("README.txt")&&v.removeSync(n)}function Tn(u,i,a){for(let n of v.readdirSync(u)){let t=K.join(u,n),r=K.relative(i,t).replace(/\\/g,"/");v.statSync(t).isDirectory()?(Tn(t,i,a),v.existsSync(t)&&v.readdirSync(t).length===0&&v.removeSync(t)):a.has(r)||v.removeSync(t)}}function ve(u,i){let a=u.split("/"),n="uncategorized",t=u;return u==="__init__"?(n="Core",t="init"):a.length>1?(n=a.slice(0,-1).join("/").replace(/^@/,""),t=a[a.length-1]):u.startsWith("@")?(n=u.replace(/^@/,""),t="init"):t=u.replace(/^@/,""),t==="init"?`imports/${n}/${i}.lua`:`imports/${n}/${t}/${i}.lua`}pn.exports={rebuildBundle:kt,generateFullApi:dn,getModuleExportMap:fn}});var kn=
|
|
107
|
-
`))}function $t(u,i,a){let n={cliVersion:i,modules:[...u.modules||[]].sort(),minify:u.minify
|
|
113
|
+
`);p&&D("modules/shared.lua",g("Shared")+`--- @diagnostic disable
|
|
114
|
+
`+l("shared")+X.shared),k&&D("modules/client.lua",g("Client")+`--- @diagnostic disable
|
|
115
|
+
`+l("client")+X.client),d&&D("modules/server.lua",g("Server")+`--- @diagnostic disable
|
|
116
|
+
`+l("server")+X.server),m(u,k,d,p,!1)}gt(Ce,pe),console.log(`\x1B[32m\u2713\x1B[0m ${c.length} modules bundled in ${Date.now()-r}ms`)}function gt(u,i){let a=K.join(u,"modules");v.existsSync(a)&&Tn(a,u,i);let n=K.join(u,"README.txt");v.existsSync(n)&&!i.has("README.txt")&&v.removeSync(n)}function Tn(u,i,a){for(let n of v.readdirSync(u)){let t=K.join(u,n),r=K.relative(i,t).replace(/\\/g,"/");v.statSync(t).isDirectory()?(Tn(t,i,a),v.existsSync(t)&&v.readdirSync(t).length===0&&v.removeSync(t)):a.has(r)||v.removeSync(t)}}function ve(u,i){let a=u.split("/"),n="uncategorized",t=u;return u==="__init__"?(n="Core",t="init"):a.length>1?(n=a.slice(0,-1).join("/").replace(/^@/,""),t=a[a.length-1]):u.startsWith("@")?(n=u.replace(/^@/,""),t="init"):t=u.replace(/^@/,""),t==="init"?`imports/${n}/${i}.lua`:`imports/${n}/${t}/${i}.lua`}pn.exports={rebuildBundle:kt,generateFullApi:dn,getModuleExportMap:fn}});var kn=U((To,mn)=>{var{getModuleData:St}=ne();function hn(u){let i=St(u);if(!i)return!1;for(let a of["shared","client","server"])if(i[a]&&i[a].stubs&&i[a].stubs.some(n=>n.metadata&&n.metadata.global))return!0;return!1}function Lt(u,i){if(!i||i.length===0)return null;if(i.length===1)return i[0];if(u.includes(".")){let n=u.split(".")[0].toLowerCase(),t=i.find(r=>r.toLowerCase().includes(n));if(t)return t}return i.find(n=>hn(n))||i[0]}mn.exports={pickExportModule:Lt,moduleHasGlobalStub:hn}});var Sn=U((po,gn)=>{var{getModuleRegistry:yt,getModuleData:bt}=ne(),{resolveDependencies:_t}=Ge(),{getModuleExportMap:Et}=Oe();function Ct(){let u=yt();return Object.keys(u).filter(i=>{if(i==="__init__")return!1;let a=bt(i);return!(a&&a.meta&&a.meta.internal===!0)})}function Ft(u,i){let a={};for(let n of u){let t=i[n],r=[];if(t){let s=t.split("/");for(let c=0;c<s.length-1;c++){let f=s[c];(f.startsWith("@")||f.startsWith("#"))&&(f=f.substring(1)),r.push(f)}}let e=r.length>0?r.join(" / "):"Uncategorized",o=n.split("/").pop();a[e]||(a[e]=[]),a[e].push({mod:n,name:o})}return a}function wt(u){let i=new Set;if(u&&u.length>0){let{graph:a}=_t(u,Et());for(let n of Object.values(a))for(let t of n)i.add(t)}return i}function xt(u,i){let n="@"+i.split(" / ").pop();return(u.length>1?u.filter(r=>r.mod!==n):u).sort((r,e)=>r.name.localeCompare(e.name))}gn.exports={getVisibleModules:Ct,buildModuleGroups:Ft,getDependencySets:wt,getFilteredSortedMods:xt}});var En=U((ho,_n)=>{var Bt=require("crypto"),Ae=require("fs-extra"),je=require("path"),Gt=je.join("ltbridge",".build-state.json");function Ln(u){return Bt.createHash("sha256").update(u).digest("hex").substring(0,16)}function yn(u){let i=Array.from(u).sort();return Ln(i.join(`
|
|
117
|
+
`))}function $t(u,i,a){let n={cliVersion:i,modules:[...u.modules||[]].sort(),minify:u.minify===!0,buildAsBundle:u.buildAsBundle===!0,debug:u.debug===!0,scanSignature:yn(a)};return Ln(JSON.stringify(n))}function bn(u){return je.join(u,Gt)}function Rt(u){let i=bn(u);if(!Ae.existsSync(i))return null;try{return JSON.parse(Ae.readFileSync(i,"utf-8"))}catch{return null}}function ye(u){return String(u).padStart(2,"0")}function At(u=new Date){let i=new Intl.DateTimeFormat(void 0,{timeZoneName:"shortOffset"}).formatToParts(u).find(a=>a.type==="timeZoneName")?.value||"";return`${ye(u.getDate())}.${ye(u.getMonth()+1)}.${u.getFullYear()} ${ye(u.getHours())}:${ye(u.getMinutes())}:${ye(u.getSeconds())}${i?" "+i:""}`}function It(u,i){let a=bn(u);Ae.ensureDirSync(je.dirname(a)),Ae.writeFileSync(a,JSON.stringify({fingerprint:i,updatedAt:At()},null,2))}_n.exports={computeBuildFingerprint:$t,computeScanSignature:yn,loadBuildState:Rt,saveBuildState:It}});var vn=U((mo,Vn)=>{var M=require("fs-extra"),N=require("path"),{version:ae}=xe(),{rebuildBundle:Fn,generateFullApi:wn,getModuleExportMap:De}=Oe(),{resolveDependencies:Nt}=Ge(),{getModuleRegistry:ce,getModuleData:xn}=ne(),{pickExportModule:Mt}=kn(),{getVisibleModules:Bn,buildModuleGroups:Gn,getDependencySets:$n,getFilteredSortedMods:Rn}=Sn(),{computeBuildFingerprint:An,loadBuildState:Pt,saveBuildState:In}=En(),We=require("prompts"),Q=N.join("ltbridge","ltbridge.config.json");async function Vt(u){let i=N.join(u,Q);if(M.existsSync(i)&&!(await We({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(`
|
|
108
118
|
\x1B[36m\u26A1 ltbridge v${ae}\x1B[0m \x1B[32mInitializing project...\x1B[0m
|
|
109
|
-
`);let n=await
|
|
119
|
+
`);let n=await We([{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:1},{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}]),t=n.buildMode===!0,r=n.minify===!0,e=n.debug===!0,o={version:ae,buildAsBundle:t,debug:e,minify:r,modules:[]};M.ensureDirSync(N.dirname(i)),M.writeFileSync(i,JSON.stringify(o,null,2)),console.log(`
|
|
110
120
|
\x1B[32m\u2713 Created configuration: ${Q}\x1B[0m`),console.log(`\x1B[90m\u2139 Build Mode: ${t?"bundle":"individual"}\x1B[0m`),console.log(`\x1B[90m\u2139 Minify: ${r?"enabled":"disabled"}\x1B[0m`),console.log(`\x1B[90m\u2139 Debug: ${e?"enabled":"disabled"}\x1B[0m
|
|
111
|
-
`),wn(u),fe(u,o)}function be(u){let i=
|
|
112
|
-
\x1B[36m\u26A1 ltbridge v${ae}\x1B[0m \x1B[32mbuilding for production...\x1B[0m`),fe(u,a,i)}function Ke(u){let i=new Set;function a(n){if(!M.existsSync(n))return;let t=M.readdirSync(n);for(let r of t){if(r==="ltbridge"||r==="node_modules"||r===".git")continue;let e=
|
|
113
|
-
\x1B[36m\u26A1 ltbridge v${ae}\x1B[0m \x1B[32mwatching for changes...\x1B[0m`),t({initial:!0});let o=require("chokidar").watch(u,{ignored:s=>Cn(u,s),persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:150,pollInterval:50}});o.on("ready",()=>{console.log(`\x1B[90m\u2139 Watching Lua files in ${
|
|
114
|
-
`)}),o.on("error",s=>{console.log(`\x1B[31m\u2716 Watcher error: ${s.message}\x1B[0m`)}),o.on("all",(s,c)=>{if(
|
|
121
|
+
`),wn(u),fe(u,o)}function be(u){let i=N.join(u,Q);return M.existsSync(i)||(console.log("\x1B[31m\u2716 Not an LTBridge initialized directory. Run 'ltbridge init' first.\x1B[0m"),process.exit(1)),JSON.parse(M.readFileSync(i,"utf-8"))}function _e(u,i){let a=N.join(u,Q);M.writeFileSync(a,JSON.stringify(i,null,2))}function Nn(u,i){if(!u.endsWith("*")){let t=Mn(u,i);return t?[t]:[]}let a=u.replace(/\\/g,"/").replace(/^@/,"").replace(/\*$/,"").toLowerCase(),n=[];for(let t of Object.keys(i)){if(t==="__init__")continue;if(t.replace(/^@/,"").toLowerCase().startsWith(a)){let e=!1,o=xn(t);o&&o.meta&&(e=o.meta.internal===!0),e||n.push(t)}}return n}function Mn(u,i){if(i[u])return u;let a=u.replace(/\\/g,"/").replace(/^@/,"").toLowerCase(),n=[];for(let e of Object.keys(i)){if(e.replace(/^@/,"").toLowerCase()===a)return e;let s=e.split("/"),c=s[s.length-1].toLowerCase();(c===a||c===a.replace(/^@/,""))&&n.push(e)}if(n.length===1)return n[0];n.length>1&&(console.log(`\x1B[31m\u2716 Ambiguous module name '${u}'.\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 t=De(),r=u.replace(/^LT\./,"");if(t[r]){let e=t[r];if(e.length===1)return e[0];console.log(`\x1B[31m\u2716 Ambiguous export name '${u}' provided by multiple modules.\x1B[0m`),console.log("\x1B[90m\u2139 Please use the full module path to add it:\x1B[0m"),e.forEach(o=>console.log(` - ltbridge add ${o.replace(/^@/,"")}`)),process.exit(1)}return null}function vt(u,i){let a=be(u),n=ce(),t=Nn(i,n);t.length===0&&(console.log(`\x1B[31m\u2716 No modules found matching '${i}'.\x1B[0m`),process.exit(1));let r=0,e=!1;for(let o of t){if(o==="__init__")continue;let s=!1,c=xn(o);if(c&&c.meta&&(s=c.meta.internal===!0),s){i.endsWith("*")||(console.log(`\x1B[31m\u2716 Cannot manually add internal ghost module '${o}'.\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(a.modules.includes(o)){i.endsWith("*")||console.log(`\x1B[90m\u2139 Module '${o}' is already added.\x1B[0m`);continue}a.modules.push(o),console.log(`\x1B[32m\u2713 Added module '${o}'.\x1B[0m`),r++}r>0?(_e(u,a),fe(u,a,{skipApi:!0})):i.endsWith("*")?(e&&(console.log(`\x1B[31m\u2716 No addable modules matched '${i}' (internal-only modules are auto-managed).\x1B[0m`),process.exit(1)),console.log("\x1B[90m\u2139 All matching modules are already added.\x1B[0m")):e&&process.exit(1)}function Ot(u,i){let a=be(u),n=ce(),t=Nn(i,n);t.length===0&&(console.log(`\x1B[31m\u2716 No modules found matching '${i}'.\x1B[0m`),process.exit(1));let r=0;for(let e of t){if(!a.modules.includes(e)){i.endsWith("*")||console.log(`\x1B[90m\u2139 Module '${e}' is not currently added.\x1B[0m`);continue}a.modules=a.modules.filter(o=>o!==e),console.log(`\x1B[33m- Removed module '${e}'.\x1B[0m`),r++}r>0?(_e(u,a),fe(u,a,{skipApi:!0})):i.endsWith("*")&&console.log("\x1B[90m\u2139 No matching modules were currently added.\x1B[0m")}function jt(u,i={}){let a=be(u);console.log(`
|
|
122
|
+
\x1B[36m\u26A1 ltbridge v${ae}\x1B[0m \x1B[32mbuilding for production...\x1B[0m`),fe(u,a,i)}function Ke(u){let i=new Set;function a(n){if(!M.existsSync(n))return;let t=M.readdirSync(n);for(let r of t){if(r==="ltbridge"||r==="node_modules"||r===".git")continue;let e=N.join(n,r);if(M.statSync(e).isDirectory())a(e);else if(r.endsWith(".lua")){let s=M.readFileSync(e,"utf8"),c=/LT\.([a-zA-Z0-9_.]+)/g,f;for(;(f=c.exec(s))!==null;){let S=f[1];i.add(S);let k=S.split("."),d="";for(let p of k)d=d?d+"."+p:p,i.add(d)}}}}return a(u),i}function Pn(u){let i=ce(),a=Object.keys(i),n=De(),t=new Set;for(let r of u){let e="@"+r.replace(/\./g,"/");if(a.includes(e)){t.add(e);continue}if(n[r]){let o=Mt(r,n[r]);o&&t.add(o)}}return t}function fe(u,i,a={}){Fn(u,i,a);let n=Ke(u),t=An(i,ae,n);return In(u,t),t}function qt(u){let i=be(u);console.log("\x1B[90m\u2139 Scanning project for unused LT modules...\x1B[0m");let a=Ke(u),n=Pn(a),t=[],r=[];for(let e of i.modules)n.has(e)?t.push(e):r.push(e);r.length>0?(console.log(`\x1B[32m\u2713 Pruned ${r.length} unused modules: ${r.join(", ")}\x1B[0m`),i.modules=t,_e(u,i)):console.log("\x1B[90m\u2139 No unused modules found. Everything is tightly integrated!\x1B[0m"),fe(u,i,{skipApi:!0})}var qe=null,Ie=!1,Ue=!1;function Cn(u,i){if(!i)return!0;let a=N.resolve(u),n=N.resolve(N.isAbsolute(i)?i:N.join(a,i)),t=N.relative(a,n).replace(/\\/g,"/");if(t===""||t===".")return!1;if(t.startsWith("..")||t.includes("node_modules")||t==="ltbridge/modules"||t.startsWith("ltbridge/modules/")||t==="ltbridge/api.lua"||t==="fxmanifest.lua"||t==="__resource.lua")return!0;if(t.endsWith("ltbridge.config.json"))return!1;let r;try{r=M.statSync(n)}catch{return!0}return r.isDirectory()?!1:!t.endsWith(".lua")}function Ut(u,i={}){let a="",n=N.join(u,Q);M.existsSync(n)&&(a=M.readFileSync(n,"utf-8"));function t({initial:s=!1}={}){if(Ie){Ue=!0;return}let c=be(u),f=Ke(u),S=Pn(f),k=!1,d=new Set(c.modules);for(let y of S)d.has(y)||(d.add(y),k=!0);for(let y of c.modules)S.has(y)||(d.delete(y),k=!0);k&&(c.modules=Array.from(d));let p=An(c,ae,f);if(Pt(u)?.fingerprint===p){console.log(s?"\x1B[90m\u2139 Build up to date, skipping initial rebuild\x1B[0m":"\x1B[90m\u2139 No LTBridge changes detected, skipping build\x1B[0m");return}Ie=!0;try{a=JSON.stringify(c,null,2),k&&_e(u,c),Fn(u,c,{skipApi:!0,...i}),In(u,p)}finally{Ie=!1,Ue&&(Ue=!1,r())}}function r(){qe&&clearTimeout(qe),qe=setTimeout(()=>{try{t()}catch(s){console.log(`\x1B[31m\u2716 Watcher error: ${s.message}\x1B[0m`)}},400)}console.log(`
|
|
123
|
+
\x1B[36m\u26A1 ltbridge v${ae}\x1B[0m \x1B[32mwatching for changes...\x1B[0m`),t({initial:!0});let o=require("chokidar").watch(u,{ignored:s=>Cn(u,s),persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:150,pollInterval:50}});o.on("ready",()=>{console.log(`\x1B[90m\u2139 Watching Lua files in ${N.resolve(u)} (Ctrl+C to stop)\x1B[0m
|
|
124
|
+
`)}),o.on("error",s=>{console.log(`\x1B[31m\u2716 Watcher error: ${s.message}\x1B[0m`)}),o.on("all",(s,c)=>{if(Ie||!c||Cn(u,c)||s!=="change"&&s!=="add")return;let f=N.isAbsolute(c)?c:N.join(u,c),S=N.relative(u,f).replace(/\\/g,"/");if(S.endsWith("ltbridge.config.json")||S===N.basename(Q).replace(/\\/g,"/"))try{if(M.readFileSync(n,"utf-8")===a)return}catch{return}r()})}function Wt(u){let i=ce(),a=Bn(),n=null,t=N.join(u,Q);if(M.existsSync(t))try{n=JSON.parse(M.readFileSync(t,"utf-8"))}catch{}let r=n?new Set(n.modules):new Set,e=$n(n?n.modules:[]),o=new Set(a),s=new Set([...r].filter(k=>o.has(k))),c=new Set([...e].filter(k=>o.has(k)&&!s.has(k))),f=s.size+c.size;if(console.log(`
|
|
115
125
|
\x1B[1m\x1B[36m\u2139 LTBridge Modules List (${s.size} manual + ${c.size} auto = ${f} active / ${a.length} total)\x1B[0m
|
|
116
126
|
`),a.length===0){console.log(" No modules found in the repository.");return}let S=Gn(a,i);for(let k of Object.keys(S).sort()){console.log(`
|
|
117
|
-
\x1B[1m\x1B[35m\u{1F4C1} ${k}\x1B[0m`);let d=
|
|
127
|
+
\x1B[1m\x1B[35m\u{1F4C1} ${k}\x1B[0m`);let d=Rn(S[k],k);for(let{mod:p,name:h}of d){let y=r.has(p),w=e.has(p),G=" ",A="\x1B[90m";y?(G="\u2714",A="\x1B[32m"):w&&(G="\u2699",A="\x1B[33m"),process.stdout.write(` ${A}${G} ${h.padEnd(30)}\x1B[0m`),w&&!y?process.stdout.write(" \x1B[90m\u2699 Auto-Dependency\x1B[0m"):w&&y&&process.stdout.write(" \x1B[90m(Also a Dependency)\x1B[0m"),process.stdout.write(`
|
|
118
128
|
`)}}console.log(`
|
|
119
129
|
\x1B[90m(\u2714 = Installed | \u2699 = Auto Dependency)\x1B[0m
|
|
120
|
-
`)}async function
|
|
130
|
+
`)}async function Dt(u){let i=ce(),a=Bn(),n=null,t=N.join(u,Q);if(M.existsSync(t))try{n=JSON.parse(M.readFileSync(t,"utf-8"))}catch{}if(!n){console.log("\x1B[31m\u2716 Not an LTBridge initialized directory. Run 'ltbridge init' first.\x1B[0m");return}let r=new Set(n.modules||[]),e=$n(n.modules||[]),o=Gn(a,i),s=[];for(let d of Object.keys(o).sort()){s.push({title:`\x1B[1m\x1B[36m--- ${d.toUpperCase()} ---\x1B[0m`,value:`__group_${d}__`,disabled:!0});let p=Rn(o[d],d);for(let{mod:h,name:y}of p){let w=r.has(h),G=e.has(h),A=y;G&&!w?A=`${A} \x1B[90m(\u2699 Auto-Dependency [INCLUDED])\x1B[0m`:G&&w&&(A=`${A} \x1B[90m(Also a Dependency)\x1B[0m`),s.push({title:A,value:h,selected:w,disabled:G&&!w})}}let c=await We({type:"multiselect",name:"selectedModules",message:"Select LTBridge modules",choices:s,instructions:!1,hint:"- [Space] select. [Return] submit",min:0});if(!c.selectedModules){console.log("\x1B[90m\u2139 Module selection cancelled.\x1B[0m");return}let f=c.selectedModules.filter(d=>!d.startsWith("__group_")),S=f.filter(d=>!r.has(d)),k=Array.from(r).filter(d=>!f.includes(d));if(S.length===0&&k.length===0){console.log("\x1B[90m\u2139 No changes made to module selection.\x1B[0m");return}S.length>0&&console.log(`\x1B[32m\u2713 Adding: ${S.join(", ")}\x1B[0m`),k.length>0&&console.log(`\x1B[33m- Removing: ${k.join(", ")}\x1B[0m`),n.modules=f,_e(u,n),fe(u,n,{skipApi:!0})}function Kt(u,i){let a=ce(),n=Mn(i,a);n||(console.log(`\x1B[31m\u2716 Module '${i}' does not exist in the repository.\x1B[0m`),process.exit(1));let t=N.join(u,Q);if(!M.existsSync(t)){console.log("\x1B[31m\u2716 Not an LTBridge initialized directory. Run 'ltbridge init' first.\x1B[0m");return}let r={modules:[]};try{r=JSON.parse(M.readFileSync(t,"utf-8"))}catch{}let e=new Set(r.modules||[]),{graph:o}=Nt(r.modules||[],De()),s={};for(let[k,d]of Object.entries(o))for(let p of d)s[p]||(s[p]=[]),s[p].includes(k)||s[p].push(k);let c=e.has(n),f=s[n]||[],S=f.length>0;if(console.log(`
|
|
121
131
|
\x1B[1m\x1B[36m\u2139 Why is '${n}' included in your project?\x1B[0m`),!c&&!S){console.log(` \x1B[90m\u25CB This module is NOT currently included in your project build.\x1B[0m
|
|
122
|
-
`);return}if(c&&console.log(" \x1B[32m\u2714 You explicitly added it to your ltbridge.config.json\x1B[0m"),S){console.log(" \x1B[33m\u2699 It is automatically included as a dependency for the following modules:\x1B[0m");for(let k of f)console.log(` - ${k}`)}console.log("")}Vn.exports={initProject:Vt,addModule:vt,removeModule:Ot,refreshModules:jt,pruneModules:qt,watchProject:
|
|
132
|
+
`);return}if(c&&console.log(" \x1B[32m\u2714 You explicitly added it to your ltbridge.config.json\x1B[0m"),S){console.log(" \x1B[33m\u2699 It is automatically included as a dependency for the following modules:\x1B[0m");for(let k of f)console.log(` - ${k}`)}console.log("")}Vn.exports={initProject:Vt,addModule:vt,removeModule:Ot,refreshModules:jt,pruneModules:qt,watchProject:Ut,generateFullApi:wn,listModules:Wt,interactiveSelect:Dt,explainModule:Kt}});var{program:z}=require("commander"),{version:zt}=xe(),{initProject:Ht,addModule:Jt,removeModule:Zt,refreshModules:Qt,pruneModules:Xt,watchProject:Yt,generateFullApi:eo,listModules:no,interactiveSelect:to,explainModule:oo}=vn();z.name("ltbridge").description("LT Bridge CLI tool for managing Lua modules and intellisense stubs").version(zt);z.command("init").description("Initialize LTBridge in the current directory and generate Master API stubs").action(async()=>{let u=process.cwd();await Ht(u)});z.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(u=>{let i=process.cwd();u.watch?Yt(i,u):Qt(i,u)});z.command("api").description("Regenerate the API stubs for IDE intellisense (Internal use for developers)").action(()=>{let u=process.cwd();console.log(`
|
|
123
133
|
\x1B[36m\u26A1 ltbridge\x1B[0m \x1B[32mRegenerating API stubs...\x1B[0m`),eo(u),console.log(`\x1B[32m\u2713 API reference successfully updated.\x1B[0m
|
|
124
134
|
`)});z.command("add <name>").description("Add a module to your project").action(u=>{Jt(process.cwd(),u)});z.command("remove <name>").description("Remove a module from your project").action(u=>{Zt(process.cwd(),u)});z.command("why <name>").alias("explain").description("Explain why a module is included in your project (dependency graph)").action(u=>{oo(process.cwd(),u)});z.command("list").description("List installed and available modules").action(()=>{no(process.cwd())});z.command("prune").description("Prune unused modules from your project bundles").action(()=>{Xt(process.cwd())});process.argv.length<=2?to(process.cwd()):z.parse(process.argv);
|