ms-vite-plugin 1.4.60 → 1.4.61

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addVararg=c;function s(t){t.vararg=!0,o(t.body.body)}function e(t){switch(t.type){case"FuncExpr":s(t);break;case"UnaryExpr":e(t.arg);break;case"BinaryExpr":e(t.left),e(t.right);break;case"TableExpr":for(const a of t.fields)a.kind==="index"&&e(a.key),e(a.value);break;case"IndexExpr":e(t.object),e(t.index);break;case"MemberExpr":e(t.object);break;case"CallExpr":e(t.callee);for(const a of t.args)e(a);break;case"MethodCallExpr":e(t.object);for(const a of t.args)e(a);break;case"ParenExpr":e(t.exp);break;default:break}}function o(t){for(const a of t)switch(a.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if(a.type==="WhileStat"&&e(a.cond),a.type==="RepeatStat"&&e(a.cond),a.type==="ForNumStat"&&(e(a.start),e(a.end),a.step&&e(a.step)),a.type==="ForInStat")for(const r of a.exps)e(r);o(a.body.body);break;case"IfStat":for(const r of a.clauses)e(r.cond),o(r.body.body);a.elseBody&&o(a.elseBody.body);break;case"FuncStat":case"LocalFuncStat":s(a.func);break;case"LocalStat":if(a.exps)for(const r of a.exps)e(r);break;case"AssignStat":for(const r of a.vars)e(r);for(const r of a.exps)e(r);break;case"CallStat":e(a.exp);break;case"ReturnStat":for(const r of a.exps)e(r);break;default:break}}function c(t){o(t.body)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addVararg=c;function s(r){r.vararg=!0,t(r.body.body)}function a(r){switch(r.type){case"FuncExpr":s(r);break;case"UnaryExpr":a(r.arg);break;case"BinaryExpr":a(r.left),a(r.right);break;case"TableExpr":for(const e of r.fields)e.kind==="index"&&a(e.key),a(e.value);break;case"IndexExpr":a(r.object),a(r.index);break;case"MemberExpr":a(r.object);break;case"CallExpr":a(r.callee);for(const e of r.args)a(e);break;case"MethodCallExpr":a(r.object);for(const e of r.args)a(e);break;case"ParenExpr":a(r.exp);break;default:break}}function t(r){for(const e of r)switch(e.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if(e.type==="WhileStat"&&a(e.cond),e.type==="RepeatStat"&&a(e.cond),e.type==="ForNumStat"&&(a(e.start),a(e.end),e.step&&a(e.step)),e.type==="ForInStat")for(const o of e.exps)a(o);t(e.body.body);break;case"IfStat":for(const o of e.clauses)a(o.cond),t(o.body.body);e.elseBody&&t(e.elseBody.body);break;case"FuncStat":case"LocalFuncStat":s(e.func);break;case"LocalStat":if(e.exps)for(const o of e.exps)a(o);break;case"AssignStat":for(const o of e.vars)a(o);for(const o of e.exps)a(o);break;case"CallStat":a(e.exp);break;case"ReturnStat":for(const o of e.exps)a(o);break;default:break}}function c(r){t(r.body)}
@@ -1,12 +1,12 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyAntiTamper=i;const s=require("./parser");function d(n){return(n>>>0)%9e3+100}function i(n,o){const a=o>>>0,t=d(a),e=a%17+3,c=t*e,r=`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyAntiTamper=s;const o=require("./parser");function r(n){return(n>>>0)%9e3+100}function s(n,c){const a=c>>>0,l=r(a),e=a%17+3,t=l*e,d=`
2
2
  do
3
3
  local valid = true
4
- local acc = ${t}
5
- if acc * ${e} ~= ${c} then
4
+ local acc = ${l}
5
+ if acc * ${e} ~= ${t} then
6
6
  valid = false
7
7
  end
8
8
  local ok = pcall(function()
9
- return acc * ${e} == ${c}
9
+ return acc * ${e} == ${t}
10
10
  end)
11
11
  if not ok then
12
12
  valid = false
@@ -23,4 +23,4 @@ do
23
23
  error("Tamper Detected!")
24
24
  end
25
25
  end
26
- `,l=(0,s.parseLua)(r);n.body.unshift(...l.body)}
26
+ `,i=(0,o.parseLua)(d);n.body.unshift(...i.body)}
@@ -1,11 +1,11 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFoldMixParams=m,exports.foldEncrypt=p,exports.foldDecrypt=g,exports.emitFoldDecoderLua=q;const f=35184372088832n,s=[3,5,6,7,10,12,14,19,20,24];function m(t){const e=t>>>0||1;return{mul45:e%15*4+1,add45:e%99991*2+1,mul8:s[e%s.length],secret8:e%256}}function h(t,e){t.p=(t.p*BigInt(e.mul45)+BigInt(e.add45))%f;do t.q=t.q*e.mul8%257;while(t.q===1);const o=Number(t.p%256n),n=Number(t.p/256n%256n),c=Number(t.p/65536n%256n);return(o+n*(t.q%13)+c+t.q)%256}function a(t,e){return{p:BigInt(e>>>0)%f,q:(e>>>0)%255+2}}function b(t){const e=[];for(let o=0;o<t.length;o+=1){const n=t.charCodeAt(o);if(n<=255)e.push(n);else{const c=Buffer.from(t[o],"utf8");for(const l of c)e.push(l)}}return Buffer.from(e)}function p(t,e,o){const n=b(t),c=a(e,o);let l=e.secret8,r="";for(let u=0;u<n.length;u+=1){const i=h(c,e),d=n[u];r+=String.fromCharCode((d-i-l+512)%256),l=d}return r}function g(t,e,o){const n=a(e,o);let c=e.secret8;const l=Buffer.alloc(t.length);for(let r=0;r<t.length;r+=1){const u=h(n,e),i=(t.charCodeAt(r)+u+c)%256;l[r]=i,c=i}return l.toString("latin1")}function q(t,e){return`local ${e}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFoldMixParams=m,exports.foldEncrypt=q,exports.foldDecrypt=g,exports.emitFoldDecoderLua=b;const d=35184372088832n,i=[3,5,6,7,10,12,14,19,20,24];function m(e){const n=e>>>0||1;return{mul45:n%15*4+1,add45:n%99991*2+1,mul8:i[n%i.length],secret8:n%256}}function f(e,n){e.p=(e.p*BigInt(n.mul45)+BigInt(n.add45))%d;do e.q=e.q*n.mul8%257;while(e.q===1);const l=Number(e.p%256n),o=Number(e.p/256n%256n),t=Number(e.p/65536n%256n);return(l+o*(e.q%13)+t+e.q)%256}function p(e,n){return{p:BigInt(n>>>0)%d,q:(n>>>0)%255+2}}function h(e){const n=[];for(let l=0;l<e.length;l+=1){const o=e.charCodeAt(l);if(o<=255)n.push(o);else{const t=Buffer.from(e[l],"utf8");for(const c of t)n.push(c)}}return Buffer.from(n)}function q(e,n,l){const o=h(e),t=p(n,l);let c=n.secret8,r="";for(let u=0;u<o.length;u+=1){const a=f(t,n),s=o[u];r+=String.fromCharCode((s-a-c+512)%256),c=s}return r}function g(e,n,l){const o=p(n,l);let t=n.secret8;const c=Buffer.alloc(e.length);for(let r=0;r<e.length;r+=1){const u=f(o,n),a=(e.charCodeAt(r)+u+t)%256;c[r]=a,t=a}return c.toString("latin1")}function b(e,n){return`local ${n}
2
2
  do
3
- local mul45=${t.mul45}
4
- local add45=${t.add45}
5
- local mul8=${t.mul8}
6
- local secret8=${t.secret8}
3
+ local mul45=${e.mul45}
4
+ local add45=${e.add45}
5
+ local mul8=${e.mul8}
6
+ local secret8=${e.secret8}
7
7
  local cache={}
8
- ${e}=function(s,seed)
8
+ ${n}=function(s,seed)
9
9
  local hit=cache[seed]
10
10
  if hit then return hit end
11
11
  local p=seed%35184372088832
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compileChunk=M;class T{constructor(){Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"ops",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"consts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"protos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"upvals",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"numparams",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"isVararg",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"maxStack",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"top",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"frames",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"labels",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"gotos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"breaks",{enumerable:!0,configurable:!0,writable:!0,value:[]})}emit(t,r=0,o=0,i=0){return this.ops.push(t),this.code.push([0,r,o,i]),this.code.length-1}patch(t,r,o,i){const a=this.code[t];r!==void 0&&(a[1]=r),o!==void 0&&(a[2]=o),i!==void 0&&(a[3]=i)}kNil(){return this.intern({t:"nil"})}kBool(t){return this.intern({t:"bool",v:t})}kNum(t,r){return this.intern({t:"num",v:t,raw:r})}kStr(t){return this.intern({t:"str",v:t})}intern(t){for(let r=0;r<this.consts.length;r+=1){const o=this.consts[r];if(o.t===t.t&&(o.t==="nil"||o.t==="bool"&&t.t==="bool"&&o.v===t.v||o.t==="num"&&t.t==="num"&&o.v===t.v||o.t==="str"&&t.t==="str"&&o.v===t.v))return r+1}return this.consts.push(t),this.consts.length}alloc(t=1){const r=this.top;return this.top+=t,this.top-1>this.maxStack&&(this.maxStack=this.top-1),r}freeTo(t){this.top=t}pushFrame(){this.frames.push({locals:[],savedTop:this.top})}currentLocals(){return this.frames[this.frames.length-1]?.locals??[]}bind(t,r=!1){const o=this.alloc(1);return this.currentLocals().push({name:t,reg:o,close:r}),o}findLocal(t){for(let r=this.frames.length-1;r>=0;r-=1){const o=this.frames[r].locals;for(let i=o.length-1;i>=0;i-=1)if(o[i].name===t)return o[i].reg}}findUpval(t){for(let i=0;i<this.upvals.length;i+=1)if(this.upvals[i].name===t)return i+1;if(!this.parent)return;const r=this.parent.findLocal(t);if(r!==void 0)return this.upvals.push({name:t,inStack:!0,index:r}),this.upvals.length;const o=this.parent.findUpval(t);if(o!==void 0)return this.upvals.push({name:t,inStack:!1,index:o}),this.upvals.length}finish(){for(const t of this.gotos){const r=this.labels.get(t.name);if(r===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${t.name}::`);this.patch(t.pc,0,r-(t.pc+1))}return{code:this.code,ops:this.ops,consts:this.consts,protos:this.protos,upvals:this.upvals,numparams:this.numparams,isVararg:this.isVararg,maxStack:Math.max(this.maxStack,this.numparams,1)}}}const P={"+":"ADD","-":"SUB","*":"MUL","/":"DIV","//":"IDIV","%":"MOD","^":"POW","&":"BAND","|":"BOR","~":"BXOR","<<":"SHL",">>":"SHR","..":"CONCAT"},A={"-":"UNM","~":"BNOT",not:"NOT","#":"LEN"};function M(e){const t=new T;return t.isVararg=!0,t.pushFrame(),n(t,e.body),t.emit("RETURN",1,0),t.finish()}function g(e,t){const r=new T;r.parent=e,r.numparams=t.params.length,r.isVararg=t.vararg,r.pushFrame();for(const o of t.params)r.bind(o);return n(r,t.body.body),r.emit("RETURN",1,0),e.protos.push(r.finish()),e.protos.length}function n(e,t){for(const r of t)B(e,r)}function h(e,t){for(const r of t.locals)e.emit("CLOSE",r.reg);e.freeTo(t.savedTop)}function B(e,t){switch(t.type){case"EmptyStat":return;case"BreakStat":{if(e.breaks.length===0)throw new Error("break \u51FA\u73B0\u5728\u5FAA\u73AF\u5916");const r=e.emit("JMP",0,0);e.breaks[e.breaks.length-1].push(r);return}case"GotoStat":{const r=e.emit("JMP",0,0);e.gotos.push({name:t.name,pc:r});return}case"LabelStat":e.labels.set(t.name,e.code.length);return;case"DoStat":{e.pushFrame(),n(e,t.body.body),h(e,e.frames.pop());return}case"WhileStat":{const r=e.code.length,o=c(e,t.cond);e.emit("TEST",o,0,0);const i=e.emit("JMP",0,0);e.freeTo(o),e.breaks.push([]),e.pushFrame(),n(e,t.body.body),h(e,e.frames.pop()),e.emit("JMP",0,r-(e.code.length+1)),e.patch(i,0,e.code.length-(i+1)),b(e,e.breaks.pop(),e.code.length);return}case"RepeatStat":{const r=e.code.length;e.breaks.push([]),e.pushFrame(),n(e,t.body.body);const o=c(e,t.cond);e.emit("TEST",o,0,0),e.emit("JMP",0,r-(e.code.length+1)),h(e,e.frames.pop()),b(e,e.breaks.pop(),e.code.length);return}case"IfStat":{const r=[];for(let o=0;o<t.clauses.length;o+=1){const i=c(e,t.clauses[o].cond);e.emit("TEST",i,0,0);const a=e.emit("JMP",0,0);e.freeTo(i),e.pushFrame(),n(e,t.clauses[o].body.body),h(e,e.frames.pop()),(o<t.clauses.length-1||t.elseBody)&&r.push(e.emit("JMP",0,0)),e.patch(a,0,e.code.length-(a+1))}t.elseBody&&(e.pushFrame(),n(e,t.elseBody.body),h(e,e.frames.pop()));for(const o of r)e.patch(o,0,e.code.length-(o+1));return}case"ForNumStat":{const r=e.alloc(4);c(e,t.start,r),c(e,t.end,r+1),t.step?c(e,t.step,r+2):e.emit("LOADK",r+2,e.kNum(1,"1"));const o=e.emit("FORPREP",r,0);e.breaks.push([]),e.pushFrame();const i=e.bind(t.name);e.emit("MOVE",i,r+3),n(e,t.body.body),h(e,e.frames.pop());const a=e.emit("FORLOOP",r,0);e.patch(o,r,a-(o+1)),e.patch(a,r,o+1-(a+1)),b(e,e.breaks.pop(),e.code.length),e.freeTo(r);return}case"ForInStat":{const r=e.alloc(3);m(e,t.exps,r,3);const o=e.emit("TFORCALL",r,t.names.length),i=e.emit("TFORLOOP",r,0);e.breaks.push([]),e.pushFrame();for(let a=0;a<t.names.length;a+=1){const s=e.bind(t.names[a]);e.emit("MOVE",s,r+3+a)}n(e,t.body.body),h(e,e.frames.pop()),e.emit("JMP",0,o-(e.code.length+1)),e.patch(i,r,e.code.length-(i+1)),b(e,e.breaks.pop(),e.code.length),e.freeTo(r);return}case"FuncStat":{const r=g(e,t.func),o=e.alloc(1);e.emit("CLOSURE",o,r),N(e,t.name.base,t.name.fields,t.name.method,o),e.freeTo(o);return}case"LocalFuncStat":{const r=e.bind(t.name),o=g(e,t.func);e.emit("CLOSURE",r,o);return}case"LocalStat":{const r=t.names.length,o=[];if(t.exps&&t.exps.length>0){const i=e.top;m(e,t.exps,i,r);for(let a=0;a<r;a+=1){const s=e.bind(t.names[a].name,t.names[a].attr==="close");e.emit("MOVE",s,i+a),o.push(s)}e.freeTo(o[0]),e.top=o[r-1]+1}else for(const i of t.names){const a=e.bind(i.name,i.attr==="close");e.emit("LOADNIL",a),o.push(a)}return}case"AssignStat":{const r=e.top;m(e,t.exps,r,t.vars.length);for(let o=0;o<t.vars.length;o+=1)R(e,t.vars[o],r+o);e.freeTo(r);return}case"CallStat":{const r=e.top;c(e,t.exp,void 0,0),e.freeTo(r);return}case"ReturnStat":{if(t.exps.length===0){e.emit("RETURN",1,0);return}const r=e.top;m(e,t.exps,r,-1);const o=t.exps[t.exps.length-1],i=o.type==="CallExpr"||o.type==="MethodCallExpr"||o.type==="VarargExpr";e.emit("RETURN",r,i?-1:t.exps.length);return}}}function b(e,t,r){for(const o of t)e.patch(o,0,r-(o+1))}function N(e,t,r,o,i){if(r.length===0&&!o){y(e,t,i);return}let s=k(e,t);const l=o?[...r,o]:r;for(let u=0;u<l.length-1;u+=1){const p=e.alloc(1);e.emit("GETTABLE",p,s,-e.kStr(l[u])),s=p}e.emit("SETTABLE",s,-e.kStr(l[l.length-1]),i)}function y(e,t,r){const o=e.findLocal(t);if(o!==void 0){e.emit("MOVE",o,r);return}const i=e.findUpval(t);if(i!==void 0){e.emit("SETUPVAL",r,i);return}e.emit("SETGLOBAL",r,e.kStr(t))}function k(e,t,r){const o=r??e.alloc(1),i=e.findLocal(t);if(i!==void 0)return o!==i&&e.emit("MOVE",o,i),o;const a=e.findUpval(t);return a!==void 0?(e.emit("GETUPVAL",o,a),o):(e.emit("GETGLOBAL",o,e.kStr(t)),o)}function R(e,t,r){if(t.type==="NameExpr"){y(e,t.name,r);return}if(t.type==="MemberExpr"){const o=c(e,t.object);e.emit("SETTABLE",o,-e.kStr(t.field),r);return}if(t.type==="IndexExpr"){const o=c(e,t.object),i=c(e,t.index);e.emit("SETTABLE",o,i,r);return}throw new Error("\u975E\u6CD5\u8D4B\u503C\u5DE6\u503C")}function c(e,t,r,o=1){const i=r??e.alloc(1);switch(t.type){case"NilLiteral":return e.emit("LOADNIL",i),i;case"BoolLiteral":return e.emit("LOADBOOL",i,t.value?1:0),i;case"NumberLiteral":return e.emit("LOADK",i,e.kNum(t.value,t.raw)),i;case"StringLiteral":return e.emit("LOADK",i,e.kStr(t.value)),i;case"VarargExpr":return e.emit("VARARG",i,o),i;case"NameExpr":return k(e,t.name,i);case"ParenExpr":return c(e,t.exp,i,1);case"UnaryExpr":{const a=c(e,t.arg);return e.emit(A[t.op],i,a),i}case"BinaryExpr":return F(e,t.op,t.left,t.right,i);case"FuncExpr":{const a=g(e,t);return e.emit("CLOSURE",i,a),i}case"TableExpr":return x(e,t.fields,i);case"IndexExpr":{const a=c(e,t.object),s=c(e,t.index);return e.emit("GETTABLE",i,a,s),i}case"MemberExpr":{const a=c(e,t.object);return e.emit("GETTABLE",i,a,-e.kStr(t.field)),i}case"CallExpr":return v(e,t.callee,t.args,i,o,!1);case"MethodCallExpr":return v(e,t.object,t.args,i,o,t.method);default:throw new Error(`\u4E0D\u652F\u6301\u7684\u8868\u8FBE\u5F0F ${t.type}`)}}function F(e,t,r,o,i){if(t==="and"||t==="or"){c(e,r,i),e.emit("TEST",i,0,t==="and"?0:1);const u=e.emit("JMP",0,0);return c(e,o,i),e.patch(u,0,e.code.length-(u+1)),i}if(t==="=="||t==="~="||t==="<"||t===">"||t==="<="||t===">="){const u=c(e,r),p=c(e,o);let d="EQ",E=u,L=p;t==="<"||t===">="?d="LT":t==="<="||t===">"?d="LE":d="EQ",(t===">"||t===">=")&&(E=p,L=u);const j=t==="~=";e.emit(d,E,L,j?1:0);const O=e.emit("JMP",0,0);e.emit("LOADBOOL",i,1);const S=e.emit("JMP",0,0);return e.patch(O,0,e.code.length-(O+1)),e.emit("LOADBOOL",i,0),e.patch(S,0,e.code.length-(S+1)),i}const a=P[t];if(!a)throw new Error(`\u4E0D\u652F\u6301\u7684\u8FD0\u7B97\u7B26 ${t}`);const s=c(e,r),l=c(e,o);return e.emit(a,i,s,l),i}function w(e){return e.type==="CallExpr"||e.type==="MethodCallExpr"||e.type==="VarargExpr"}function v(e,t,r,o,i,a){const s=o,l=r.length>0&&w(r[r.length-1]);if(a){const u=c(e,t,s);return e.emit("SELF",s,u,-e.kStr(a)),m(e,r,s+2,-1),e.emit("CALL",s,l?-1:r.length+1,i),s}return c(e,t,s),m(e,r,s+1,-1),e.emit("CALL",s,l?-1:r.length,i),s}function m(e,t,r,o){const i=o>0?o:Math.max(t.length,1);if(e.top<r+i&&(e.top=r+i,e.top-1>e.maxStack&&(e.maxStack=e.top-1)),t.length===0){if(o>0)for(let a=0;a<o;a+=1)e.emit("LOADNIL",r+a);return}for(let a=0;a<t.length;a+=1){const s=a===t.length-1,l=s&&(o<0||o>t.length)?o===-1?-1:o-a:1;c(e,t[a],r+a,s?l:1)}if(o>t.length)for(let a=t.length;a<o;a+=1)e.emit("LOADNIL",r+a)}function x(e,t,r){e.emit("NEWTABLE",r);const o=[];for(const i of t)if(i.kind==="list")o.push(i.value);else if(i.kind==="name"){const a=c(e,i.value);e.emit("SETTABLE",r,-e.kStr(i.key),a)}else{const a=c(e,i.key),s=c(e,i.value);e.emit("SETTABLE",r,a,s)}if(o.length>0){const i=e.top;m(e,o,i,-1),e.emit("SETLIST",r,i,o.length),e.freeTo(i)}return r}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compileChunk=P;class O{constructor(){Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"ops",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"consts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"protos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"upvals",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"numparams",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"isVararg",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"maxStack",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"top",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"frames",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"labels",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"gotos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"breaks",{enumerable:!0,configurable:!0,writable:!0,value:[]})}emit(r,e=0,n=0,s=0){return this.ops.push(r),this.code.push([0,e,n,s]),this.code.length-1}patch(r,e,n,s){const o=this.code[r];e!==void 0&&(o[1]=e),n!==void 0&&(o[2]=n),s!==void 0&&(o[3]=s)}kNil(){return this.intern({t:"nil"})}kBool(r){return this.intern({t:"bool",v:r})}kNum(r,e){return this.intern({t:"num",v:r,raw:e})}kStr(r){return this.intern({t:"str",v:r})}intern(r){for(let e=0;e<this.consts.length;e+=1){const n=this.consts[e];if(n.t===r.t&&(n.t==="nil"||n.t==="bool"&&r.t==="bool"&&n.v===r.v||n.t==="num"&&r.t==="num"&&n.v===r.v||n.t==="str"&&r.t==="str"&&n.v===r.v))return e+1}return this.consts.push(r),this.consts.length}alloc(r=1){const e=this.top;return this.top+=r,this.top-1>this.maxStack&&(this.maxStack=this.top-1),e}freeTo(r){this.top=r}pushFrame(){this.frames.push({locals:[],savedTop:this.top})}currentLocals(){return this.frames[this.frames.length-1]?.locals??[]}bind(r,e=!1){const n=this.alloc(1);return this.currentLocals().push({name:r,reg:n,close:e}),n}findLocal(r){for(let e=this.frames.length-1;e>=0;e-=1){const n=this.frames[e].locals;for(let s=n.length-1;s>=0;s-=1)if(n[s].name===r)return n[s].reg}}findUpval(r){for(let s=0;s<this.upvals.length;s+=1)if(this.upvals[s].name===r)return s+1;if(!this.parent)return;const e=this.parent.findLocal(r);if(e!==void 0)return this.upvals.push({name:r,inStack:!0,index:e}),this.upvals.length;const n=this.parent.findUpval(r);if(n!==void 0)return this.upvals.push({name:r,inStack:!1,index:n}),this.upvals.length}finish(){for(const r of this.gotos){const e=this.labels.get(r.name);if(e===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${r.name}::`);this.patch(r.pc,0,e-(r.pc+1))}return{code:this.code,ops:this.ops,consts:this.consts,protos:this.protos,upvals:this.upvals,numparams:this.numparams,isVararg:this.isVararg,maxStack:Math.max(this.maxStack,this.numparams,1)}}}const k={"+":"ADD","-":"SUB","*":"MUL","/":"DIV","//":"IDIV","%":"MOD","^":"POW","&":"BAND","|":"BOR","~":"BXOR","<<":"SHL",">>":"SHR","..":"CONCAT"},A={"-":"UNM","~":"BNOT",not:"NOT","#":"LEN"};function P(t){const r=new O;return r.isVararg=!0,r.pushFrame(),u(r,t.body),r.emit("RETURN",1,0),r.finish()}function d(t,r){const e=new O;e.parent=t,e.numparams=r.params.length,e.isVararg=r.vararg,e.pushFrame();for(const n of r.params)e.bind(n);return u(e,r.body.body),e.emit("RETURN",1,0),t.protos.push(e.finish()),t.protos.length}function u(t,r){for(const e of r)B(t,e)}function p(t,r){for(const e of r.locals)t.emit("CLOSE",e.reg);t.freeTo(r.savedTop)}function B(t,r){switch(r.type){case"EmptyStat":return;case"BreakStat":{if(t.breaks.length===0)throw new Error("break \u51FA\u73B0\u5728\u5FAA\u73AF\u5916");const e=t.emit("JMP",0,0);t.breaks[t.breaks.length-1].push(e);return}case"GotoStat":{const e=t.emit("JMP",0,0);t.gotos.push({name:r.name,pc:e});return}case"LabelStat":t.labels.set(r.name,t.code.length);return;case"DoStat":{t.pushFrame(),u(t,r.body.body),p(t,t.frames.pop());return}case"WhileStat":{const e=t.code.length,n=i(t,r.cond);t.emit("TEST",n,0,0);const s=t.emit("JMP",0,0);t.freeTo(n),t.breaks.push([]),t.pushFrame(),u(t,r.body.body),p(t,t.frames.pop()),t.emit("JMP",0,e-(t.code.length+1)),t.patch(s,0,t.code.length-(s+1)),f(t,t.breaks.pop(),t.code.length);return}case"RepeatStat":{const e=t.code.length;t.breaks.push([]),t.pushFrame(),u(t,r.body.body);const n=i(t,r.cond);t.emit("TEST",n,0,0),t.emit("JMP",0,e-(t.code.length+1)),p(t,t.frames.pop()),f(t,t.breaks.pop(),t.code.length);return}case"IfStat":{const e=[];for(let n=0;n<r.clauses.length;n+=1){const s=i(t,r.clauses[n].cond);t.emit("TEST",s,0,0);const o=t.emit("JMP",0,0);t.freeTo(s),t.pushFrame(),u(t,r.clauses[n].body.body),p(t,t.frames.pop()),(n<r.clauses.length-1||r.elseBody)&&e.push(t.emit("JMP",0,0)),t.patch(o,0,t.code.length-(o+1))}r.elseBody&&(t.pushFrame(),u(t,r.elseBody.body),p(t,t.frames.pop()));for(const n of e)t.patch(n,0,t.code.length-(n+1));return}case"ForNumStat":{const e=t.alloc(4);i(t,r.start,e),i(t,r.end,e+1),r.step?i(t,r.step,e+2):t.emit("LOADK",e+2,t.kNum(1,"1"));const n=t.emit("FORPREP",e,0);t.breaks.push([]),t.pushFrame();const s=t.bind(r.name);t.emit("MOVE",s,e+3),u(t,r.body.body),p(t,t.frames.pop());const o=t.emit("FORLOOP",e,0);t.patch(n,e,o-(n+1)),t.patch(o,e,n+1-(o+1)),f(t,t.breaks.pop(),t.code.length),t.freeTo(e);return}case"ForInStat":{const e=t.alloc(3);h(t,r.exps,e,3);const n=t.emit("TFORCALL",e,r.names.length),s=t.emit("TFORLOOP",e,0);t.breaks.push([]),t.pushFrame();for(let o=0;o<r.names.length;o+=1){const a=t.bind(r.names[o]);t.emit("MOVE",a,e+3+o)}u(t,r.body.body),p(t,t.frames.pop()),t.emit("JMP",0,n-(t.code.length+1)),t.patch(s,e,t.code.length-(s+1)),f(t,t.breaks.pop(),t.code.length),t.freeTo(e);return}case"FuncStat":{const e=d(t,r.func),n=t.alloc(1);t.emit("CLOSURE",n,e),w(t,r.name.base,r.name.fields,r.name.method,n),t.freeTo(n);return}case"LocalFuncStat":{const e=t.bind(r.name),n=d(t,r.func);t.emit("CLOSURE",e,n);return}case"LocalStat":{const e=r.names.length,n=[];if(r.exps&&r.exps.length>0){const s=t.top;h(t,r.exps,s,e);for(let o=0;o<e;o+=1){const a=t.bind(r.names[o].name,r.names[o].attr==="close");t.emit("MOVE",a,s+o),n.push(a)}t.freeTo(n[0]),t.top=n[e-1]+1}else for(const s of r.names){const o=t.bind(s.name,s.attr==="close");t.emit("LOADNIL",o),n.push(o)}return}case"AssignStat":{const e=t.top;h(t,r.exps,e,r.vars.length);for(let n=0;n<r.vars.length;n+=1)F(t,r.vars[n],e+n);t.freeTo(e);return}case"CallStat":{const e=t.top;i(t,r.exp,void 0,0),t.freeTo(e);return}case"ReturnStat":{if(r.exps.length===0){t.emit("RETURN",1,0);return}const e=t.top;h(t,r.exps,e,-1);const n=r.exps[r.exps.length-1],s=n.type==="CallExpr"||n.type==="MethodCallExpr"||n.type==="VarargExpr";t.emit("RETURN",e,s?-1:r.exps.length);return}}}function f(t,r,e){for(const n of r)t.patch(n,0,e-(n+1))}function w(t,r,e,n,s){if(e.length===0&&!n){S(t,r,s);return}let o=T(t,r);const a=n?[...e,n]:e;for(let c=0;c<a.length-1;c+=1){const l=t.alloc(1);t.emit("GETTABLE",l,o,-t.kStr(a[c])),o=l}t.emit("SETTABLE",o,-t.kStr(a[a.length-1]),s)}function S(t,r,e){const n=t.findLocal(r);if(n!==void 0){t.emit("MOVE",n,e);return}const s=t.findUpval(r);if(s!==void 0){t.emit("SETUPVAL",e,s);return}t.emit("SETGLOBAL",e,t.kStr(r))}function T(t,r,e){const n=e??t.alloc(1),s=t.findLocal(r);if(s!==void 0)return n!==s&&t.emit("MOVE",n,s),n;const o=t.findUpval(r);return o!==void 0?(t.emit("GETUPVAL",n,o),n):(t.emit("GETGLOBAL",n,t.kStr(r)),n)}function F(t,r,e){if(r.type==="NameExpr"){S(t,r.name,e);return}if(r.type==="MemberExpr"){const n=i(t,r.object);t.emit("SETTABLE",n,-t.kStr(r.field),e);return}if(r.type==="IndexExpr"){const n=i(t,r.object),s=i(t,r.index);t.emit("SETTABLE",n,s,e);return}throw new Error("\u975E\u6CD5\u8D4B\u503C\u5DE6\u503C")}function i(t,r,e,n=1){const s=e??t.alloc(1);switch(r.type){case"NilLiteral":return t.emit("LOADNIL",s),s;case"BoolLiteral":return t.emit("LOADBOOL",s,r.value?1:0),s;case"NumberLiteral":return t.emit("LOADK",s,t.kNum(r.value,r.raw)),s;case"StringLiteral":return t.emit("LOADK",s,t.kStr(r.value)),s;case"VarargExpr":return t.emit("VARARG",s,n),s;case"NameExpr":return T(t,r.name,s);case"ParenExpr":return i(t,r.exp,s,1);case"UnaryExpr":{const o=i(t,r.arg);return t.emit(A[r.op],s,o),s}case"BinaryExpr":return M(t,r.op,r.left,r.right,s);case"FuncExpr":{const o=d(t,r);return t.emit("CLOSURE",s,o),s}case"TableExpr":return R(t,r.fields,s);case"IndexExpr":{const o=i(t,r.object),a=i(t,r.index);return t.emit("GETTABLE",s,o,a),s}case"MemberExpr":{const o=i(t,r.object);return t.emit("GETTABLE",s,o,-t.kStr(r.field)),s}case"CallExpr":return y(t,r.callee,r.args,s,n,!1);case"MethodCallExpr":return y(t,r.object,r.args,s,n,r.method);default:throw new Error(`\u4E0D\u652F\u6301\u7684\u8868\u8FBE\u5F0F ${r.type}`)}}function M(t,r,e,n,s){if(r==="and"||r==="or"){i(t,e,s),t.emit("TEST",s,0,r==="and"?0:1);const l=t.emit("JMP",0,0);return i(t,n,s),t.patch(l,0,t.code.length-(l+1)),s}if(r==="=="||r==="~="||r==="<"||r===">"||r==="<="||r===">="){const l=i(t,e),b=i(t,n);let m="EQ",g=l,E=b;r==="<"||r===">="?m="LT":r==="<="||r===">"?m="LE":m="EQ",(r===">"||r===">=")&&(g=b,E=l);const x=r==="~=";t.emit(m,g,E,x?1:0);const L=t.emit("JMP",0,0);t.emit("LOADBOOL",s,1);const v=t.emit("JMP",0,0);return t.patch(L,0,t.code.length-(L+1)),t.emit("LOADBOOL",s,0),t.patch(v,0,t.code.length-(v+1)),s}const o=k[r];if(!o)throw new Error(`\u4E0D\u652F\u6301\u7684\u8FD0\u7B97\u7B26 ${r}`);const a=i(t,e),c=i(t,n);return t.emit(o,s,a,c),s}function N(t){return t.type==="CallExpr"||t.type==="MethodCallExpr"||t.type==="VarargExpr"}function y(t,r,e,n,s,o){const a=n,c=e.length>0&&N(e[e.length-1]);if(o){const l=i(t,r,a);return t.emit("SELF",a,l,-t.kStr(o)),h(t,e,a+2,-1),t.emit("CALL",a,c?-1:e.length+1,s),a}return i(t,r,a),h(t,e,a+1,-1),t.emit("CALL",a,c?-1:e.length,s),a}function h(t,r,e,n){const s=n>0?n:Math.max(r.length,1);if(t.top<e+s&&(t.top=e+s,t.top-1>t.maxStack&&(t.maxStack=t.top-1)),r.length===0){if(n>0)for(let o=0;o<n;o+=1)t.emit("LOADNIL",e+o);return}for(let o=0;o<r.length;o+=1){const a=o===r.length-1,c=a&&(n<0||n>r.length)?n===-1?-1:n-o:1;i(t,r[o],e+o,a?c:1)}if(n>r.length)for(let o=r.length;o<n;o+=1)t.emit("LOADNIL",e+o)}function R(t,r,e){t.emit("NEWTABLE",e);const n=[];for(const s of r)if(s.kind==="list")n.push(s.value);else if(s.kind==="name"){const o=i(t,s.value);t.emit("SETTABLE",e,-t.kStr(s.key),o)}else{const o=i(t,s.key),a=i(t,s.value);t.emit("SETTABLE",e,o,a)}if(n.length>0){const s=t.top;h(t,n,s,-1),t.emit("SETLIST",e,s,n.length),t.freeTo(s)}return e}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyConstantArray=v;const o=require("./visit"),p="__C",y="__G";function g(l,i){const n=l.slice();let a=i>>>0||1;for(let r=n.length-1;r>0;r-=1){a=Math.imul(a,1664525)+1013904223>>>0;const t=a%(r+1),s=n[r];n[r]=n[t],n[t]=s}return n}function v(l,i,n){const a=[],r=new Set;if((0,o.mapChunk)(l,e=>(e.type==="StringLiteral"&&!r.has(e.value)&&(r.add(e.value),a.push(e.value)),e)),a.length===0)return;let t=n.shuffle?g(a,i):a.slice();const s=n.rotate?i%t.length:0;s>0&&(t=t.slice(s).concat(t.slice(0,s)));const c=new Map;for(let e=0;e<t.length;e+=1)c.set(t[e],e+1);(0,o.mapChunk)(l,e=>{if(e.type!=="StringLiteral")return e;const u=c.get(e.value);return u===void 0?e:{type:"CallExpr",callee:{type:"NameExpr",name:y},args:[{type:"NumberLiteral",raw:String(u),value:u}]}});const f=t.map(e=>({kind:"list",value:{type:"StringLiteral",value:e,encoded:!0}})),m={type:"LocalStat",names:[{name:p}],exps:[{type:"TableExpr",fields:f}]},d={type:"LocalFuncStat",name:y,func:{type:"FuncExpr",params:["i"],vararg:!1,body:{type:"Block",body:[{type:"ReturnStat",exps:[{type:"IndexExpr",object:{type:"NameExpr",name:p},index:{type:"NameExpr",name:"i"}}]}]}}};l.body.unshift(m,d)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyConstantArray=h;const i=require("./visit"),o="__C",y="__G";function g(l,s){const a=l.slice();let n=s>>>0||1;for(let r=a.length-1;r>0;r-=1){n=Math.imul(n,1664525)+1013904223>>>0;const t=n%(r+1),p=a[r];a[r]=a[t],a[t]=p}return a}function h(l,s,a){const n=[],r=new Set;if((0,i.mapChunk)(l,e=>(e.type==="StringLiteral"&&!r.has(e.value)&&(r.add(e.value),n.push(e.value)),e)),n.length===0)return;let t=a.shuffle?g(n,s):n.slice();const p=a.rotate?s%t.length:0;p>0&&(t=t.slice(p).concat(t.slice(0,p)));const c=new Map;for(let e=0;e<t.length;e+=1)c.set(t[e],e+1);(0,i.mapChunk)(l,e=>{if(e.type!=="StringLiteral")return e;const u=c.get(e.value);return u===void 0?e:{type:"CallExpr",callee:{type:"NameExpr",name:y},args:[{type:"NumberLiteral",raw:String(u),value:u}]}});const m=t.map(e=>({kind:"list",value:{type:"StringLiteral",value:e,encoded:!0}})),d={type:"LocalStat",names:[{name:o}],exps:[{type:"TableExpr",fields:m}]},f={type:"LocalFuncStat",name:y,func:{type:"FuncExpr",params:["i"],vararg:!1,body:{type:"Block",body:[{type:"ReturnStat",exps:[{type:"IndexExpr",object:{type:"NameExpr",name:o},index:{type:"NameExpr",name:"i"}}]}]}}};l.body.unshift(d,f)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.flattenControlFlow=R;function m(e){return{type:"NumberLiteral",raw:String(e),value:e}}function p(e){return{type:"NameExpr",name:e}}function c(e,a){return{type:"AssignStat",vars:e.map(t=>p(t)),exps:a}}function y(e,a){return c([e.stateName],[typeof a=="number"?m(a):a])}function F(e,a,t){return{type:"BinaryExpr",op:"or",left:{type:"BinaryExpr",op:"and",left:p(e),right:m(a)},right:m(t)}}function E(e,a,t){return{type:"BinaryExpr",op:e,left:a,right:t}}function d(e){const a=`__t${e.nextTemp}`;return e.nextTemp+=1,e.temps.push(a),a}function h(e){const a=e.nextState;return e.nextState+=1,e.states.set(a,[]),a}function r(e,a,t){e.states.get(a).push(t)}function L(e,a){for(const t of e)if(t.type==="LocalStat")for(const o of t.names)a.push(o.name);else if(t.type==="LocalFuncStat")a.push(t.name);else if(t.type==="ForNumStat")a.push(t.name),L(t.body.body,a);else if(t.type==="ForInStat")a.push(...t.names),L(t.body.body,a);else if(t.type==="DoStat"||t.type==="WhileStat"||t.type==="RepeatStat")L(t.body.body,a);else if(t.type==="IfStat"){for(const o of t.clauses)L(o.body.body,a);t.elseBody&&L(t.elseBody.body,a)}}function g(e,a,t,o){if(e.length===0)return a;const i=e.map(()=>h(t));for(let n=0;n<e.length;n+=1){const s=e[n];s.type==="LabelStat"&&t.userLabels.set(s.name,i[n])}for(let n=0;n<e.length;n+=1){const s=n+1<e.length?i[n+1]:a;C(t,i[n],e[n],s,o)}return i[0]}function C(e,a,t,o,i){switch(t.type){case"EmptyStat":case"LabelStat":r(e,a,y(e,o));return;case"AssignStat":case"CallStat":case"FuncStat":r(e,a,t),r(e,a,y(e,o));return;case"LocalStat":t.exps&&t.exps.length>0&&r(e,a,c(t.names.map(n=>n.name),t.exps)),r(e,a,y(e,o));return;case"LocalFuncStat":r(e,a,c([t.name],[t.func])),r(e,a,y(e,o));return;case"ReturnStat":r(e,a,t);return;case"BreakStat":r(e,a,y(e,i));return;case"GotoStat":{const n=e.userLabels.get(t.name);if(n===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${t.name}::`);r(e,a,y(e,n));return}case"DoStat":r(e,a,y(e,g(t.body.body,o,e,i)));return;case"IfStat":{const n=d(e);let s=a;for(let f=0;f<t.clauses.length;f+=1){const u=f===t.clauses.length-1,b=g(t.clauses[f].body.body,o,e,i);let S=o;u?t.elseBody&&(S=g(t.elseBody.body,o,e,i)):S=h(e),r(e,s,c([n],[t.clauses[f].cond])),r(e,s,y(e,F(n,b,S))),u||(s=S)}t.clauses.length===0&&r(e,a,y(e,o));return}case"WhileStat":{const n=d(e),s=g(t.body.body,a,e,o);r(e,a,c([n],[t.cond])),r(e,a,y(e,F(n,s,o)));return}case"RepeatStat":{const n=d(e),s=h(e),f=g(t.body.body,s,e,o);r(e,a,y(e,f)),r(e,s,c([n],[t.cond])),r(e,s,y(e,F(n,o,f)));return}case"ForNumStat":{const n=t.name,s=d(e),f=d(e),u=d(e),b=h(e),S=h(e),B=h(e),k=h(e),w=g(t.body.body,k,e,o);r(e,a,c([n],[t.start])),r(e,a,c([s],[t.end])),r(e,a,c([f],[t.step??m(1)])),r(e,a,y(e,b)),r(e,b,c([u],[E(">=",p(f),m(0))])),r(e,b,y(e,F(u,S,B))),r(e,S,c([u],[E("<=",p(n),p(s))])),r(e,S,y(e,F(u,w,o))),r(e,B,c([u],[E(">=",p(n),p(s))])),r(e,B,y(e,F(u,w,o))),r(e,k,c([n],[E("+",p(n),p(f))])),r(e,k,y(e,b));return}case"ForInStat":{const n=d(e),s=d(e),f=d(e),u=d(e),b=h(e),S=[c([f],[p(t.names[0])]),...t.body.body],B=g(S,b,e,o),k=t.exps.slice();for(;k.length<3;)k.push({type:"NilLiteral"});r(e,a,c([n,s,f],k.slice(0,3))),r(e,a,y(e,b)),r(e,b,{type:"AssignStat",vars:t.names.map(w=>p(w)),exps:[{type:"CallExpr",callee:p(n),args:[p(s),p(f)]}]}),r(e,b,c([u],[E("~=",p(t.names[0]),{type:"NilLiteral"})])),r(e,b,y(e,F(u,B,o)));return}default:r(e,a,y(e,o))}}function M(e,a){const t=e.slice();let o=a>>>0||1;for(let i=t.length-1;i>0;i-=1){o=Math.imul(o,1664525)+1013904223>>>0;const n=o%(i+1),s=t[i];t[i]=t[n],t[n]=s}return t}function I(e,a){if(e.length===0)return e;const t={states:new Map,temps:[],nextState:1,nextTemp:1,stateName:"__s",userLabels:new Map},o=[];L(e,o);const i=g(e,0,t,0),n=[...new Set([...o,...t.temps,t.stateName])],f=M([...t.states.keys()],a).map(u=>({cond:E("==",p(t.stateName),m(u)),body:{type:"Block",body:t.states.get(u)}}));return[{type:"LocalStat",names:n.map(u=>({name:u}))},c([t.stateName],[m(i)]),{type:"WhileStat",cond:E("~=",p(t.stateName),m(0)),body:{type:"Block",body:[{type:"IfStat",clauses:f}]}}]}function l(e,a){switch(e.type){case"FuncExpr":N(e.body.body,a),e.body.body=I(e.body.body,a);break;case"UnaryExpr":l(e.arg,a);break;case"BinaryExpr":l(e.left,a),l(e.right,a);break;case"TableExpr":for(const t of e.fields)t.kind==="index"&&l(t.key,a),l(t.value,a);break;case"IndexExpr":l(e.object,a),l(e.index,a);break;case"MemberExpr":l(e.object,a);break;case"CallExpr":l(e.callee,a);for(const t of e.args)l(t,a);break;case"MethodCallExpr":l(e.object,a);for(const t of e.args)l(t,a);break;case"ParenExpr":l(e.exp,a);break;default:break}}function N(e,a){for(const t of e)switch(t.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if((t.type==="WhileStat"||t.type==="RepeatStat")&&l(t.cond,a),t.type==="ForNumStat"&&(l(t.start,a),l(t.end,a),t.step&&l(t.step,a)),t.type==="ForInStat")for(const o of t.exps)l(o,a);N(t.body.body,a);break;case"IfStat":for(const o of t.clauses)l(o.cond,a),N(o.body.body,a);t.elseBody&&N(t.elseBody.body,a);break;case"FuncStat":case"LocalFuncStat":N(t.func.body.body,a),t.func.body.body=I(t.func.body.body,a);break;case"LocalStat":if(t.exps)for(const o of t.exps)l(o,a);break;case"AssignStat":for(const o of t.vars)l(o,a);for(const o of t.exps)l(o,a);break;case"CallStat":l(t.exp,a);break;case"ReturnStat":for(const o of t.exps)l(o,a);break;default:break}}function R(e,a){N(e.body,a),e.body=I(e.body,a)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.flattenControlFlow=C;function m(t){return{type:"NumberLiteral",raw:String(t),value:t}}function p(t){return{type:"NameExpr",name:t}}function f(t,s){return{type:"AssignStat",vars:t.map(e=>p(e)),exps:s}}function u(t,s){return f([t.stateName],[typeof s=="number"?m(s):s])}function k(t,s,e){return{type:"BinaryExpr",op:"or",left:{type:"BinaryExpr",op:"and",left:p(t),right:m(s)},right:m(e)}}function E(t,s,e){return{type:"BinaryExpr",op:t,left:s,right:e}}function S(t){const s=`__t${t.nextTemp}`;return t.nextTemp+=1,t.temps.push(s),s}function x(t){const s=t.nextState;return t.nextState+=1,t.states.set(s,[]),s}function r(t,s,e){t.states.get(s).push(e)}function B(t,s){for(const e of t)if(e.type==="LocalStat")for(const n of e.names)s.push(n.name);else if(e.type==="LocalFuncStat")s.push(e.name);else if(e.type==="ForNumStat")s.push(e.name),B(e.body.body,s);else if(e.type==="ForInStat")s.push(...e.names),B(e.body.body,s);else if(e.type==="DoStat"||e.type==="WhileStat"||e.type==="RepeatStat")B(e.body.body,s);else if(e.type==="IfStat"){for(const n of e.clauses)B(n.body.body,s);e.elseBody&&B(e.elseBody.body,s)}}function h(t,s,e,n){if(t.length===0)return s;const y=t.map(()=>x(e));for(let o=0;o<t.length;o+=1){const a=t[o];a.type==="LabelStat"&&e.userLabels.set(a.name,y[o])}for(let o=0;o<t.length;o+=1){const a=o+1<t.length?y[o+1]:s;I(e,y[o],t[o],a,n)}return y[0]}function I(t,s,e,n,y){switch(e.type){case"EmptyStat":case"LabelStat":r(t,s,u(t,n));return;case"AssignStat":case"CallStat":case"FuncStat":r(t,s,e),r(t,s,u(t,n));return;case"LocalStat":e.exps&&e.exps.length>0&&r(t,s,f(e.names.map(o=>o.name),e.exps)),r(t,s,u(t,n));return;case"LocalFuncStat":r(t,s,f([e.name],[e.func])),r(t,s,u(t,n));return;case"ReturnStat":r(t,s,e);return;case"BreakStat":r(t,s,u(t,y));return;case"GotoStat":{const o=t.userLabels.get(e.name);if(o===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${e.name}::`);r(t,s,u(t,o));return}case"DoStat":r(t,s,u(t,h(e.body.body,n,t,y)));return;case"IfStat":{const o=S(t);let a=s;for(let l=0;l<e.clauses.length;l+=1){const b=l===e.clauses.length-1,d=h(e.clauses[l].body.body,n,t,y);let i=n;b?e.elseBody&&(i=h(e.elseBody.body,n,t,y)):i=x(t),r(t,a,f([o],[e.clauses[l].cond])),r(t,a,u(t,k(o,d,i))),b||(a=i)}e.clauses.length===0&&r(t,s,u(t,n));return}case"WhileStat":{const o=S(t),a=h(e.body.body,s,t,n);r(t,s,f([o],[e.cond])),r(t,s,u(t,k(o,a,n)));return}case"RepeatStat":{const o=S(t),a=x(t),l=h(e.body.body,a,t,n);r(t,s,u(t,l)),r(t,a,f([o],[e.cond])),r(t,a,u(t,k(o,n,l)));return}case"ForNumStat":{const o=e.name,a=S(t),l=S(t),b=S(t),d=x(t),i=x(t),L=x(t),g=x(t),N=h(e.body.body,g,t,n);r(t,s,f([o],[e.start])),r(t,s,f([a],[e.end])),r(t,s,f([l],[e.step??m(1)])),r(t,s,u(t,d)),r(t,d,f([b],[E(">=",p(l),m(0))])),r(t,d,u(t,k(b,i,L))),r(t,i,f([b],[E("<=",p(o),p(a))])),r(t,i,u(t,k(b,N,n))),r(t,L,f([b],[E(">=",p(o),p(a))])),r(t,L,u(t,k(b,N,n))),r(t,g,f([o],[E("+",p(o),p(l))])),r(t,g,u(t,d));return}case"ForInStat":{const o=S(t),a=S(t),l=S(t),b=S(t),d=x(t),i=[f([l],[p(e.names[0])]),...e.body.body],L=h(i,d,t,n),g=e.exps.slice();for(;g.length<3;)g.push({type:"NilLiteral"});r(t,s,f([o,a,l],g.slice(0,3))),r(t,s,u(t,d)),r(t,d,{type:"AssignStat",vars:e.names.map(N=>p(N)),exps:[{type:"CallExpr",callee:p(o),args:[p(a),p(l)]}]}),r(t,d,f([b],[E("~=",p(e.names[0]),{type:"NilLiteral"})])),r(t,d,u(t,k(b,L,n)));return}default:r(t,s,u(t,n))}}function v(t,s){const e=t.slice();let n=s>>>0||1;for(let y=e.length-1;y>0;y-=1){n=Math.imul(n,1664525)+1013904223>>>0;const o=n%(y+1),a=e[y];e[y]=e[o],e[o]=a}return e}function w(t,s){if(t.length===0)return t;const e={states:new Map,temps:[],nextState:1,nextTemp:1,stateName:"__s",userLabels:new Map},n=[];B(t,n);const y=h(t,0,e,0),o=[...new Set([...n,...e.temps,e.stateName])],a=v([...e.states.keys()],s).map(l=>({cond:E("==",p(e.stateName),m(l)),body:{type:"Block",body:e.states.get(l)}}));return[{type:"LocalStat",names:o.map(l=>({name:l}))},f([e.stateName],[m(y)]),{type:"WhileStat",cond:E("~=",p(e.stateName),m(0)),body:{type:"Block",body:[{type:"IfStat",clauses:a}]}}]}function c(t,s){switch(t.type){case"FuncExpr":F(t.body.body,s),t.body.body=w(t.body.body,s);break;case"UnaryExpr":c(t.arg,s);break;case"BinaryExpr":c(t.left,s),c(t.right,s);break;case"TableExpr":for(const e of t.fields)e.kind==="index"&&c(e.key,s),c(e.value,s);break;case"IndexExpr":c(t.object,s),c(t.index,s);break;case"MemberExpr":c(t.object,s);break;case"CallExpr":c(t.callee,s);for(const e of t.args)c(e,s);break;case"MethodCallExpr":c(t.object,s);for(const e of t.args)c(e,s);break;case"ParenExpr":c(t.exp,s);break;default:break}}function F(t,s){for(const e of t)switch(e.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if((e.type==="WhileStat"||e.type==="RepeatStat")&&c(e.cond,s),e.type==="ForNumStat"&&(c(e.start,s),c(e.end,s),e.step&&c(e.step,s)),e.type==="ForInStat")for(const n of e.exps)c(n,s);F(e.body.body,s);break;case"IfStat":for(const n of e.clauses)c(n.cond,s),F(n.body.body,s);e.elseBody&&F(e.elseBody.body,s);break;case"FuncStat":case"LocalFuncStat":F(e.func.body.body,s),e.func.body.body=w(e.func.body.body,s);break;case"LocalStat":if(e.exps)for(const n of e.exps)c(n,s);break;case"AssignStat":for(const n of e.vars)c(n,s);for(const n of e.exps)c(n,s);break;case"CallStat":c(e.exp,s);break;case"ReturnStat":for(const n of e.exps)c(n,s);break;default:break}}function C(t,s){F(t.body,s),t.body=w(t.body,s)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFoldMixParams=exports.foldEncrypt=exports.foldDecrypt=exports.LuaParseError=exports.LuaLexError=exports.luaObfuscatorPresets=void 0,exports.obfuscateLua=g;const f=require("./addVararg"),l=require("./antiTamper"),d=require("./compiler"),y=require("./constantArray"),u=require("./flatten"),c=require("./minify"),a=require("./numbers"),m=require("./parser"),p=require("./rename"),b=require("./splitStrings"),L=require("./vmEmit"),_=require("./wrapInFunction");exports.luaObfuscatorPresets=["Minify","Weak","Medium","Strong"];function q(t){let n=2166136261;for(let r=0;r<t.length;r+=1)n=Math.imul(n^t.charCodeAt(r),16777619);return n>>>0||1}function i(t){return(0,m.parseLua)((0,L.emitVm)((0,d.compileChunk)(t)))}function o(t,n,r){(0,y.applyConstantArray)(t,n,{shuffle:r.shuffle,rotate:r.shuffle}),r.numbersOnVm&&(0,a.numbersToExpressions)(t,(n^2654435769)>>>0);for(let e=0;e<r.wraps;e+=1)(0,_.wrapInFunction)(t);return(0,p.renameLocals)(t),(0,c.minifyLua)(t)}function g(t,n){const r=q(t);let e=(0,m.parseLua)(t);return(0,p.renameLocals)(e),n==="Minify"?(0,c.minifyLua)(e):n==="Weak"?((0,u.flattenControlFlow)(e,r),e=i(e),o(e,r,{shuffle:!1,wraps:1,numbersOnVm:!1})):n==="Medium"?((0,f.addVararg)(e),(0,b.splitStrings)(e,r),(0,a.numbersToExpressions)(e,r),(0,l.applyAntiTamper)(e,r),(0,u.flattenControlFlow)(e,r),e=i(e),o(e,r,{shuffle:!0,wraps:1,numbersOnVm:!0})):((0,f.addVararg)(e),(0,b.splitStrings)(e,(r^2135587861)>>>0),(0,a.numbersToExpressions)(e,r),(0,l.applyAntiTamper)(e,(r^2246822507)>>>0),(0,u.flattenControlFlow)(e,(r^2246822507)>>>0),e=i(e),o(e,r,{shuffle:!0,wraps:2,numbersOnVm:!0}))}var x=require("./lexer");Object.defineProperty(exports,"LuaLexError",{enumerable:!0,get:function(){return x.LuaLexError}});var P=require("./parser");Object.defineProperty(exports,"LuaParseError",{enumerable:!0,get:function(){return P.LuaParseError}});var s=require("./strings");Object.defineProperty(exports,"foldDecrypt",{enumerable:!0,get:function(){return s.foldDecrypt}}),Object.defineProperty(exports,"foldEncrypt",{enumerable:!0,get:function(){return s.foldEncrypt}}),Object.defineProperty(exports,"createFoldMixParams",{enumerable:!0,get:function(){return s.createFoldMixParams}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFoldMixParams=exports.foldEncrypt=exports.foldDecrypt=exports.LuaParseError=exports.LuaLexError=exports.luaObfuscatorPresets=void 0,exports.obfuscateLua=g;const l=require("./addVararg"),f=require("./antiTamper"),b=require("./compiler"),y=require("./constantArray"),u=require("./flatten"),c=require("./minify"),a=require("./numbers"),p=require("./parser"),m=require("./rename"),d=require("./splitStrings"),L=require("./vmEmit"),q=require("./wrapInFunction");exports.luaObfuscatorPresets=["Minify","Weak","Medium","Strong"];function P(n){let t=2166136261;for(let r=0;r<n.length;r+=1)t=Math.imul(t^n.charCodeAt(r),16777619);return t>>>0||1}function o(n){return(0,p.parseLua)((0,L.emitVm)((0,b.compileChunk)(n)))}function i(n,t,r){(0,y.applyConstantArray)(n,t,{shuffle:r.shuffle,rotate:r.shuffle}),r.numbersOnVm&&(0,a.numbersToExpressions)(n,(t^2654435769)>>>0);for(let e=0;e<r.wraps;e+=1)(0,q.wrapInFunction)(n);return(0,m.renameLocals)(n),(0,c.minifyLua)(n)}function g(n,t){const r=P(n);let e=(0,p.parseLua)(n);return(0,m.renameLocals)(e),t==="Minify"?(0,c.minifyLua)(e):t==="Weak"?((0,u.flattenControlFlow)(e,r),e=o(e),i(e,r,{shuffle:!1,wraps:1,numbersOnVm:!1})):t==="Medium"?((0,l.addVararg)(e),(0,d.splitStrings)(e,r),(0,a.numbersToExpressions)(e,r),(0,f.applyAntiTamper)(e,r),(0,u.flattenControlFlow)(e,r),e=o(e),i(e,r,{shuffle:!0,wraps:1,numbersOnVm:!0})):((0,l.addVararg)(e),(0,d.splitStrings)(e,(r^2135587861)>>>0),(0,a.numbersToExpressions)(e,r),(0,f.applyAntiTamper)(e,(r^2246822507)>>>0),(0,u.flattenControlFlow)(e,(r^2246822507)>>>0),e=o(e),i(e,r,{shuffle:!0,wraps:2,numbersOnVm:!0}))}var E=require("./lexer");Object.defineProperty(exports,"LuaLexError",{enumerable:!0,get:function(){return E.LuaLexError}});var O=require("./parser");Object.defineProperty(exports,"LuaParseError",{enumerable:!0,get:function(){return O.LuaParseError}});var s=require("./strings");Object.defineProperty(exports,"foldDecrypt",{enumerable:!0,get:function(){return s.foldDecrypt}}),Object.defineProperty(exports,"foldEncrypt",{enumerable:!0,get:function(){return s.foldEncrypt}}),Object.defineProperty(exports,"createFoldMixParams",{enumerable:!0,get:function(){return s.createFoldMixParams}});
@@ -1,10 +1,10 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaLexError=void 0,exports.lexLua=N;const P=require("./reserved");class b extends Error{constructor(f,l,c){super(`${f} (${l}:${c})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:l}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:c}),this.name="LuaLexError"}}exports.LuaLexError=b;function N(L){const f=L.replace(/^\uFEFF/,""),l=[];let c=0,p=1,d=1;const t=(e=0)=>f[c+e]??"",w=()=>c>=f.length,n=()=>{const e=f[c++];return e===`
2
- `?(p+=1,d=1):d+=1,e},a=e=>{throw new b(e,p,d)},k=e=>e>="A"&&e<="Z"||e>="a"&&e<="z"||e==="_",h=e=>e>="0"&&e<="9",v=e=>h(e)||e>="a"&&e<="f"||e>="A"&&e<="F",g=e=>{const i=Buffer.from(e,"utf8");let r="";for(const o of i)r+=String.fromCharCode(o);return r},x=e=>e===" "||e===" "||e==="\r"||e===`
3
- `||e==="\f"||e==="\v",C=e=>{if(f[e]!=="[")return-1;let i=0,r=e+1;for(;f[r]==="=";)i+=1,r+=1;return f[r]==="["?i:-1},E=e=>{n();for(let r=0;r<e;r+=1)n();n(),t()==="\r"&&n(),t()===`
4
- `&&n();let i="";for(;!w();){if(t()==="]"){let r=c+1,o=0;for(;f[r]==="=";)o+=1,r+=1;if(o===e&&f[r]==="]"){n();for(let s=0;s<e;s+=1)n();return n(),i}}i+=g(n())}return a("\u672A\u95ED\u5408\u7684\u957F\u62EC\u53F7\u5B57\u7B26\u4E32\u6216\u6CE8\u91CA")},y=()=>{for(;!w()&&t()!==`
5
- `;)n()},O=e=>{n();let i="";for(;!w();){const r=t();if(r===e)return n(),i;if(r===`
6
- `)return a("\u77ED\u5B57\u7B26\u4E32\u5185\u51FA\u73B0\u672A\u8F6C\u4E49\u6362\u884C");if(r!=="\\"){i+=g(n());continue}n();const o=t();if(o==="a")n(),i+="\x07";else if(o==="b")n(),i+="\b";else if(o==="f")n(),i+="\f";else if(o==="n")n(),i+=`
7
- `;else if(o==="r")n(),i+="\r";else if(o==="t")n(),i+=" ";else if(o==="v")n(),i+="\v";else if(o==="\\"||o==='"'||o==="'"||o===`
8
- `)i+=n();else if(o==="\r")n(),t()===`
9
- `&&n(),i+=`
10
- `;else if(o==="x"){n();const s=t(),m=t(1);if(!v(s)||!v(m))return a("\u65E0\u6548\u7684 \\x \u8F6C\u4E49");n(),n(),i+=String.fromCharCode(parseInt(s+m,16))}else if(o==="u"){if(n(),t()!=="{")return a("\u65E0\u6548\u7684 \\u \u8F6C\u4E49");n();let s="";for(;v(t());)s+=n();if(t()!=="}"||s.length===0)return a("\u65E0\u6548\u7684 \\u{...} \u8F6C\u4E49");n(),i+=g(String.fromCodePoint(parseInt(s,16)))}else if(o==="z")for(n();x(t());)n();else if(h(o)){let s="";for(;h(t())&&s.length<3;)s+=n();const m=parseInt(s,10);if(m>255)return a("\u5341\u8FDB\u5236\u8F6C\u4E49\u8D85\u8FC7 255");i+=String.fromCharCode(m)}else return a(`\u65E0\u6548\u7684\u8F6C\u4E49\u5E8F\u5217 \\${o}`)}return a("\u672A\u95ED\u5408\u7684\u77ED\u5B57\u7B26\u4E32")},F=()=>{const e=p,i=d;let r="";if(t()==="0"&&(t(1)==="x"||t(1)==="X")){for(r+=n(),r+=n();v(t())||t()===".";)r+=n();if(t()==="p"||t()==="P")for(r+=n(),(t()==="+"||t()==="-")&&(r+=n());h(t());)r+=n()}else{for(;h(t())||t()===".";)r+=n();if(t()==="e"||t()==="E")for(r+=n(),(t()==="+"||t()==="-")&&(r+=n());h(t());)r+=n()}const s=Number(r);if(!Number.isFinite(s))throw new b(`\u65E0\u6548\u6570\u5B57 ${r}`,e,i);return{kind:"number",value:r,line:e,column:i,parsed:s}};for(;!w();){const e=t();if(x(e)){n();continue}if(e==="-"&&t(1)==="-"){const u=p,$=d;n(),n();const S=C(c);S>=0?E(S):y();continue}const i=p,r=d;if(e==="'"||e==='"'){const u=O(e);l.push({kind:"string",value:u,line:i,column:r,parsed:u});continue}const o=C(c);if(o>=0){const u=E(o);l.push({kind:"string",value:u,line:i,column:r,parsed:u});continue}if(h(e)||e==="."&&h(t(1))){l.push(F());continue}if(k(e)){let u="";for(;k(t())||h(t());)u+=n();l.push({kind:P.luaKeywords.has(u)?"keyword":"name",value:u,line:i,column:r});continue}const s=e+t(1);if(s+t(2)==="..."){n(),n(),n(),l.push({kind:"vararg",value:"...",line:i,column:r});continue}if(["//","<<",">>","==","~=","<=",">=","..","::"].includes(s)){n(),n(),l.push({kind:s,value:s,line:i,column:r});continue}if(["+","-","*","/","%","^","#","&","|","~","<",">","=","(",")","{","}","[","]",";",":",",","."].includes(e)){n(),l.push({kind:e,value:e,line:i,column:r});continue}a(`\u975E\u6CD5\u5B57\u7B26 ${JSON.stringify(e)}`)}return l.push({kind:"eof",value:"",line:p,column:d}),l}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaLexError=void 0,exports.lexLua=L;const D=require("./reserved");class F extends Error{constructor(l,s,c){super(`${l} (${s}:${c})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:s}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:c}),this.name="LuaLexError"}}exports.LuaLexError=F;function L(v){const l=v.replace(/^\uFEFF/,""),s=[];let c=0,m=1,d=1;const r=(u=0)=>l[c+u]??"",h=()=>c>=l.length,e=()=>{const u=l[c++];return u===`
2
+ `?(m+=1,d=1):d+=1,u},a=u=>{throw new F(u,m,d)},b=u=>u>="A"&&u<="Z"||u>="a"&&u<="z"||u==="_",E=u=>u>="0"&&u<="9",p=u=>E(u)||u>="a"&&u<="f"||u>="A"&&u<="F",C=u=>{const i=Buffer.from(u,"utf8");let n="";for(const t of i)n+=String.fromCharCode(t);return n},g=u=>u===" "||u===" "||u==="\r"||u===`
3
+ `||u==="\f"||u==="\v",B=u=>{if(l[u]!=="[")return-1;let i=0,n=u+1;for(;l[n]==="=";)i+=1,n+=1;return l[n]==="["?i:-1},k=u=>{e();for(let n=0;n<u;n+=1)e();e(),r()==="\r"&&e(),r()===`
4
+ `&&e();let i="";for(;!h();){if(r()==="]"){let n=c+1,t=0;for(;l[n]==="=";)t+=1,n+=1;if(t===u&&l[n]==="]"){e();for(let o=0;o<u;o+=1)e();return e(),i}}i+=C(e())}return a("\u672A\u95ED\u5408\u7684\u957F\u62EC\u53F7\u5B57\u7B26\u4E32\u6216\u6CE8\u91CA")},w=()=>{for(;!h()&&r()!==`
5
+ `;)e()},y=u=>{e();let i="";for(;!h();){const n=r();if(n===u)return e(),i;if(n===`
6
+ `)return a("\u77ED\u5B57\u7B26\u4E32\u5185\u51FA\u73B0\u672A\u8F6C\u4E49\u6362\u884C");if(n!=="\\"){i+=C(e());continue}e();const t=r();if(t==="a")e(),i+="\x07";else if(t==="b")e(),i+="\b";else if(t==="f")e(),i+="\f";else if(t==="n")e(),i+=`
7
+ `;else if(t==="r")e(),i+="\r";else if(t==="t")e(),i+=" ";else if(t==="v")e(),i+="\v";else if(t==="\\"||t==='"'||t==="'"||t===`
8
+ `)i+=e();else if(t==="\r")e(),r()===`
9
+ `&&e(),i+=`
10
+ `;else if(t==="x"){e();const o=r(),f=r(1);if(!p(o)||!p(f))return a("\u65E0\u6548\u7684 \\x \u8F6C\u4E49");e(),e(),i+=String.fromCharCode(parseInt(o+f,16))}else if(t==="u"){if(e(),r()!=="{")return a("\u65E0\u6548\u7684 \\u \u8F6C\u4E49");e();let o="";for(;p(r());)o+=e();if(r()!=="}"||o.length===0)return a("\u65E0\u6548\u7684 \\u{...} \u8F6C\u4E49");e(),i+=C(String.fromCodePoint(parseInt(o,16)))}else if(t==="z")for(e();g(r());)e();else if(E(t)){let o="";for(;E(r())&&o.length<3;)o+=e();const f=parseInt(o,10);if(f>255)return a("\u5341\u8FDB\u5236\u8F6C\u4E49\u8D85\u8FC7 255");i+=String.fromCharCode(f)}else return a(`\u65E0\u6548\u7684\u8F6C\u4E49\u5E8F\u5217 \\${t}`)}return a("\u672A\u95ED\u5408\u7684\u77ED\u5B57\u7B26\u4E32")},A=()=>{const u=m,i=d;let n="";if(r()==="0"&&(r(1)==="x"||r(1)==="X")){for(n+=e(),n+=e();p(r())||r()===".";)n+=e();if(r()==="p"||r()==="P")for(n+=e(),(r()==="+"||r()==="-")&&(n+=e());E(r());)n+=e()}else{for(;E(r())||r()===".";)n+=e();if(r()==="e"||r()==="E")for(n+=e(),(r()==="+"||r()==="-")&&(n+=e());E(r());)n+=e()}const t=Number(n);if(!Number.isFinite(t))throw new F(`\u65E0\u6548\u6570\u5B57 ${n}`,u,i);return{kind:"number",value:n,line:u,column:i,parsed:t}};for(;!h();){const u=r();if(g(u)){e();continue}if(u==="-"&&r(1)==="-"){const f=m,$=d;e(),e();const x=B(c);x>=0?k(x):w();continue}const i=m,n=d;if(u==="'"||u==='"'){const f=y(u);s.push({kind:"string",value:f,line:i,column:n,parsed:f});continue}const t=B(c);if(t>=0){const f=k(t);s.push({kind:"string",value:f,line:i,column:n,parsed:f});continue}if(E(u)||u==="."&&E(r(1))){s.push(A());continue}if(b(u)){let f="";for(;b(r())||E(r());)f+=e();s.push({kind:D.luaKeywords.has(f)?"keyword":"name",value:f,line:i,column:n});continue}const o=u+r(1);if(o+r(2)==="..."){e(),e(),e(),s.push({kind:"vararg",value:"...",line:i,column:n});continue}if(["//","<<",">>","==","~=","<=",">=","..","::"].includes(o)){e(),e(),s.push({kind:o,value:o,line:i,column:n});continue}if(["+","-","*","/","%","^","#","&","|","~","<",">","=","(",")","{","}","[","]",";",":",",","."].includes(u)){e(),s.push({kind:u,value:u,line:i,column:n});continue}a(`\u975E\u6CD5\u5B57\u7B26 ${JSON.stringify(u)}`)}return s.push({kind:"eof",value:"",line:m,column:d}),s}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.escapeLuaString=d,exports.minifyLua=f;const l=new Set(["and","or"]);function d(t){let r='"';for(let n=0;n<t.length;n+=1){const u=t.charCodeAt(n)&255;r+=`\\${String(u).padStart(3,"0")}`}return r+='"',r}class p{constructor(){Object.defineProperty(this,"parts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"last",{enumerable:!0,configurable:!0,writable:!0,value:"none"})}word(r){(this.last==="word"||this.last==="num")&&this.parts.push(" "),this.parts.push(r),this.last="word"}num(r){(this.last==="word"||this.last==="num")&&this.parts.push(" "),this.parts.push(r),this.last="num"}punct(r){r===".."&&this.last==="num"&&this.parts.push(" "),r==="="&&this.parts[this.parts.length-1]===">"&&this.parts.push(" "),this.parts.push(r),this.last="punct"}toString(){return this.parts.join("")}}function f(t){const r=new p;return s(r,t.body,!0),r.toString()}function o(t,r){s(t,r.body,!1)}function s(t,r,n){for(let u=0;u<r.length;u+=1)w(t,r[u]),u<r.length-1&&t.punct(";")}function w(t,r){switch(r.type){case"EmptyStat":t.punct(";");return;case"BreakStat":t.word("break");return;case"GotoStat":t.word("goto"),t.word(r.name);return;case"LabelStat":t.punct("::"),t.word(r.name),t.punct("::");return;case"DoStat":t.word("do"),o(t,r.body),t.word("end");return;case"WhileStat":t.word("while"),a(t,r.cond),t.word("do"),o(t,r.body),t.word("end");return;case"RepeatStat":t.word("repeat"),o(t,r.body),t.word("until"),a(t,r.cond);return;case"IfStat":for(let n=0;n<r.clauses.length;n+=1)t.word(n===0?"if":"elseif"),a(t,r.clauses[n].cond),t.word("then"),o(t,r.clauses[n].body);r.elseBody&&(t.word("else"),o(t,r.elseBody)),t.word("end");return;case"ForNumStat":t.word("for"),t.word(r.name),t.punct("="),a(t,r.start),t.punct(","),a(t,r.end),r.step&&(t.punct(","),a(t,r.step)),t.word("do"),o(t,r.body),t.word("end");return;case"ForInStat":t.word("for");for(let n=0;n<r.names.length;n+=1)n>0&&t.punct(","),t.word(r.names[n]);t.word("in"),c(t,r.exps),t.word("do"),o(t,r.body),t.word("end");return;case"FuncStat":t.word("function"),t.word(r.name.base);for(const n of r.name.fields)t.punct("."),t.word(n);r.name.method&&(t.punct(":"),t.word(r.name.method)),e(t,r.func,!!r.name.method);return;case"LocalFuncStat":t.word("local"),t.word("function"),t.word(r.name),e(t,r.func,!1);return;case"LocalStat":t.word("local");for(let n=0;n<r.names.length;n+=1)n>0&&t.punct(","),t.word(r.names[n].name),r.names[n].attr&&(t.punct("<"),t.word(r.names[n].attr),t.punct(">"));r.exps&&r.exps.length>0&&(t.punct("="),c(t,r.exps));return;case"AssignStat":c(t,r.vars),t.punct("="),c(t,r.exps);return;case"CallStat":a(t,r.exp);return;case"ReturnStat":t.word("return"),r.exps.length>0&&c(t,r.exps);return}}function e(t,r,n){t.punct("(");const u=n?r.params.filter(i=>i!=="self"):r.params;for(let i=0;i<u.length;i+=1)i>0&&t.punct(","),t.word(u[i]);r.vararg&&(u.length>0&&t.punct(","),t.punct("...")),t.punct(")"),o(t,r.body),t.word("end")}function c(t,r){for(let n=0;n<r.length;n+=1)n>0&&t.punct(","),a(t,r[n])}function a(t,r){switch(r.type){case"NilLiteral":t.word("nil");return;case"BoolLiteral":t.word(r.value?"true":"false");return;case"NumberLiteral":t.num(r.raw);return;case"StringLiteral":t.punct(d(r.value));return;case"VarargExpr":t.punct("...");return;case"NameExpr":t.word(r.name);return;case"UnaryExpr":r.op==="not"?t.word("not"):t.punct(r.op),a(t,r.arg);return;case"BinaryExpr":a(t,r.left),l.has(r.op)?t.word(r.op):t.punct(r.op),a(t,r.right);return;case"FuncExpr":t.word("function"),e(t,r,!1);return;case"TableExpr":t.punct("{");for(let n=0;n<r.fields.length;n+=1)n>0&&t.punct(","),h(t,r.fields[n]);t.punct("}");return;case"IndexExpr":a(t,r.object),t.punct("["),a(t,r.index),t.punct("]");return;case"MemberExpr":a(t,r.object),t.punct("."),t.word(r.field);return;case"CallExpr":a(t,r.callee),t.punct("("),c(t,r.args),t.punct(")");return;case"MethodCallExpr":a(t,r.object),t.punct(":"),t.word(r.method),t.punct("("),c(t,r.args),t.punct(")");return;case"ParenExpr":t.punct("("),a(t,r.exp),t.punct(")");return}}function h(t,r){if(r.kind==="index"){t.punct("["),a(t,r.key),t.punct("]"),t.punct("="),a(t,r.value);return}if(r.kind==="name"){t.word(r.key),t.punct("="),a(t,r.value);return}a(t,r.value)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.escapeLuaString=p,exports.minifyLua=w;const l=new Set(["and","or"]);function p(e){let n='"';for(let a=0;a<e.length;a+=1){const u=e.charCodeAt(a)&255;n+=`\\${String(u).padStart(3,"0")}`}return n+='"',n}class i{constructor(){Object.defineProperty(this,"parts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"last",{enumerable:!0,configurable:!0,writable:!0,value:"none"})}word(n){(this.last==="word"||this.last==="num")&&this.parts.push(" "),this.parts.push(n),this.last="word"}num(n){(this.last==="word"||this.last==="num")&&this.parts.push(" "),this.parts.push(n),this.last="num"}punct(n){n===".."&&this.last==="num"&&this.parts.push(" "),n==="="&&this.parts[this.parts.length-1]===">"&&this.parts.push(" "),this.parts.push(n),this.last="punct"}toString(){return this.parts.join("")}}function w(e){const n=new i;return d(n,e.body,!0),n.toString()}function r(e,n){d(e,n.body,!1)}function d(e,n,a){for(let u=0;u<n.length;u+=1)h(e,n[u]),u<n.length-1&&e.punct(";")}function h(e,n){switch(n.type){case"EmptyStat":e.punct(";");return;case"BreakStat":e.word("break");return;case"GotoStat":e.word("goto"),e.word(n.name);return;case"LabelStat":e.punct("::"),e.word(n.name),e.punct("::");return;case"DoStat":e.word("do"),r(e,n.body),e.word("end");return;case"WhileStat":e.word("while"),o(e,n.cond),e.word("do"),r(e,n.body),e.word("end");return;case"RepeatStat":e.word("repeat"),r(e,n.body),e.word("until"),o(e,n.cond);return;case"IfStat":for(let a=0;a<n.clauses.length;a+=1)e.word(a===0?"if":"elseif"),o(e,n.clauses[a].cond),e.word("then"),r(e,n.clauses[a].body);n.elseBody&&(e.word("else"),r(e,n.elseBody)),e.word("end");return;case"ForNumStat":e.word("for"),e.word(n.name),e.punct("="),o(e,n.start),e.punct(","),o(e,n.end),n.step&&(e.punct(","),o(e,n.step)),e.word("do"),r(e,n.body),e.word("end");return;case"ForInStat":e.word("for");for(let a=0;a<n.names.length;a+=1)a>0&&e.punct(","),e.word(n.names[a]);e.word("in"),s(e,n.exps),e.word("do"),r(e,n.body),e.word("end");return;case"FuncStat":e.word("function"),e.word(n.name.base);for(const a of n.name.fields)e.punct("."),e.word(a);n.name.method&&(e.punct(":"),e.word(n.name.method)),c(e,n.func,!!n.name.method);return;case"LocalFuncStat":e.word("local"),e.word("function"),e.word(n.name),c(e,n.func,!1);return;case"LocalStat":e.word("local");for(let a=0;a<n.names.length;a+=1)a>0&&e.punct(","),e.word(n.names[a].name),n.names[a].attr&&(e.punct("<"),e.word(n.names[a].attr),e.punct(">"));n.exps&&n.exps.length>0&&(e.punct("="),s(e,n.exps));return;case"AssignStat":s(e,n.vars),e.punct("="),s(e,n.exps);return;case"CallStat":o(e,n.exp);return;case"ReturnStat":e.word("return"),n.exps.length>0&&s(e,n.exps);return}}function c(e,n,a){e.punct("(");const u=a?n.params.filter(t=>t!=="self"):n.params;for(let t=0;t<u.length;t+=1)t>0&&e.punct(","),e.word(u[t]);n.vararg&&(u.length>0&&e.punct(","),e.punct("...")),e.punct(")"),r(e,n.body),e.word("end")}function s(e,n){for(let a=0;a<n.length;a+=1)a>0&&e.punct(","),o(e,n[a])}function o(e,n){switch(n.type){case"NilLiteral":e.word("nil");return;case"BoolLiteral":e.word(n.value?"true":"false");return;case"NumberLiteral":e.num(n.raw);return;case"StringLiteral":e.punct(p(n.value));return;case"VarargExpr":e.punct("...");return;case"NameExpr":e.word(n.name);return;case"UnaryExpr":n.op==="not"?e.word("not"):e.punct(n.op),o(e,n.arg);return;case"BinaryExpr":o(e,n.left),l.has(n.op)?e.word(n.op):e.punct(n.op),o(e,n.right);return;case"FuncExpr":e.word("function"),c(e,n,!1);return;case"TableExpr":e.punct("{");for(let a=0;a<n.fields.length;a+=1)a>0&&e.punct(","),f(e,n.fields[a]);e.punct("}");return;case"IndexExpr":o(e,n.object),e.punct("["),o(e,n.index),e.punct("]");return;case"MemberExpr":o(e,n.object),e.punct("."),e.word(n.field);return;case"CallExpr":o(e,n.callee),e.punct("("),s(e,n.args),e.punct(")");return;case"MethodCallExpr":o(e,n.object),e.punct(":"),e.word(n.method),e.punct("("),s(e,n.args),e.punct(")");return;case"ParenExpr":e.punct("("),o(e,n.exp),e.punct(")");return}}function f(e,n){if(n.kind==="index"){e.punct("["),o(e,n.key),e.punct("]"),e.punct("="),o(e,n.value);return}if(n.kind==="name"){e.word(n.key),e.punct("="),o(e,n.value);return}o(e,n.value)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.numbersToExpressions=s;const o=require("./visit");function l(r,i){const t=Math.abs(i)%9+2,e=r-t;if(r<0)return{type:"UnaryExpr",op:"-",arg:l(-r,i+3)};if(r<=2)return{type:"NumberLiteral",raw:String(r),value:r};if(i%3===0){const u=r%7+2,a=Math.floor(r/u),n=r-u*a,p={type:"BinaryExpr",op:"*",left:{type:"NumberLiteral",raw:String(u),value:u},right:{type:"NumberLiteral",raw:String(a),value:a}};return n===0?{type:"ParenExpr",exp:p}:{type:"ParenExpr",exp:{type:"BinaryExpr",op:"+",left:p,right:{type:"NumberLiteral",raw:String(n),value:n}}}}return{type:"ParenExpr",exp:{type:"BinaryExpr",op:"+",left:{type:"NumberLiteral",raw:String(t),value:t},right:{type:"NumberLiteral",raw:String(e),value:e}}}}function s(r,i){let t=0;(0,o.mapChunk)(r,e=>e.type!=="NumberLiteral"||!Number.isInteger(e.value)||!Number.isSafeInteger(e.value)?e:(t+=1,l(e.value,i+t*17)))}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.numbersToExpressions=o;const y=require("./visit");function l(e,a){const t=Math.abs(a)%9+2,r=e-t;if(e<0)return{type:"UnaryExpr",op:"-",arg:l(-e,a+3)};if(e<=2)return{type:"NumberLiteral",raw:String(e),value:e};if(a%3===0){const p=e%7+2,n=Math.floor(e/p),u=e-p*n,i={type:"BinaryExpr",op:"*",left:{type:"NumberLiteral",raw:String(p),value:p},right:{type:"NumberLiteral",raw:String(n),value:n}};return u===0?{type:"ParenExpr",exp:i}:{type:"ParenExpr",exp:{type:"BinaryExpr",op:"+",left:i,right:{type:"NumberLiteral",raw:String(u),value:u}}}}return{type:"ParenExpr",exp:{type:"BinaryExpr",op:"+",left:{type:"NumberLiteral",raw:String(t),value:t},right:{type:"NumberLiteral",raw:String(r),value:r}}}}function o(e,a){let t=0;(0,y.mapChunk)(e,r=>r.type!=="NumberLiteral"||!Number.isInteger(r.value)||!Number.isSafeInteger(r.value)?r:(t+=1,l(r.value,a+t*17)))}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OPCODE_NAMES=void 0,exports.shuffleOpcodes=S,exports.OPCODE_NAMES=["MOVE","LOADK","LOADBOOL","LOADNIL","GETGLOBAL","SETGLOBAL","GETTABLE","SETTABLE","NEWTABLE","SELF","ADD","SUB","MUL","DIV","IDIV","MOD","POW","BAND","BOR","BXOR","SHL","SHR","UNM","BNOT","NOT","LEN","CONCAT","JMP","EQ","LT","LE","TEST","CALL","RETURN","FORPREP","FORLOOP","TFORCALL","TFORLOOP","CLOSURE","VARARG","SETLIST","GETUPVAL","SETUPVAL","CLOSE"];function S(e){const E=exports.OPCODE_NAMES.map((O,L)=>L+1);let A=e>>>0||1;for(let O=E.length-1;O>0;O-=1){A=Math.imul(A,1664525)+1013904223>>>0;const L=A%(O+1),t=E[O];E[O]=E[L],E[L]=t}const T={};for(let O=0;O<exports.OPCODE_NAMES.length;O+=1)T[exports.OPCODE_NAMES[O]]=E[O];return T}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OPCODE_NAMES=void 0,exports.shuffleOpcodes=t,exports.OPCODE_NAMES=["MOVE","LOADK","LOADBOOL","LOADNIL","GETGLOBAL","SETGLOBAL","GETTABLE","SETTABLE","NEWTABLE","SELF","ADD","SUB","MUL","DIV","IDIV","MOD","POW","BAND","BOR","BXOR","SHL","SHR","UNM","BNOT","NOT","LEN","CONCAT","JMP","EQ","LT","LE","TEST","CALL","RETURN","FORPREP","FORLOOP","TFORCALL","TFORLOOP","CLOSURE","VARARG","SETLIST","GETUPVAL","SETUPVAL","CLOSE"];function t(S){const E=exports.OPCODE_NAMES.map((O,L)=>L+1);let A=S>>>0||1;for(let O=E.length-1;O>0;O-=1){A=Math.imul(A,1664525)+1013904223>>>0;const L=A%(O+1),e=E[O];E[O]=E[L],E[L]=e}const T={};for(let O=0;O<exports.OPCODE_NAMES.length;O+=1)T[exports.OPCODE_NAMES[O]]=E[O];return T}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaParseError=void 0,exports.parseLua=te;const Z=require("./ast"),ee=require("./lexer");class j extends Error{constructor(k,p,c){super(`${k} (${p}:${c})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:p}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:c}),this.name="LuaParseError"}}exports.LuaParseError=j;function te(E){const k=(0,ee.lexLua)(E);let p=0;const c=()=>k[p],s=(e,t)=>{const n=c();return!(n.kind!==e||t!==void 0&&n.value!==t)},S=e=>s("keyword",e),h=e=>{const t=c();throw new j(e,t.line,t.column)},r=(e,t)=>{const n=c();return n.kind!==e||t!==void 0&&n.value!==t?h(`\u671F\u671B ${t??e}\uFF0C\u5B9E\u9645 ${n.value||n.kind}`):(p+=1,n)},o=(e,t)=>{if(s(e,t)){const n=c();return p+=1,n}},u=e=>S(e)?(p+=1,!0):!1,a=()=>r("name").value,f=e=>{const t=[];for(;!s("eof")&&!(c().kind==="keyword"&&e.includes(c().value));){if(S("return")){t.push($()),o(";");break}const n=F();n&&t.push(n)}return{type:"Block",body:t}},$=()=>(r("keyword","return"),s("eof")||s(";")||c().kind==="keyword"&&["end","else","elseif","until"].includes(c().value)?{type:"ReturnStat",exps:[]}:{type:"ReturnStat",exps:x()}),F=()=>{if(o(";"))return{type:"EmptyStat"};if(u("break"))return{type:"BreakStat"};if(u("goto"))return{type:"GotoStat",name:a()};if(u("do")){const e=f(["end"]);return r("keyword","end"),{type:"DoStat",body:e}}if(u("while")){const e=i();r("keyword","do");const t=f(["end"]);return r("keyword","end"),{type:"WhileStat",cond:e,body:t}}if(u("repeat")){const e=f(["until"]);r("keyword","until");const t=i();return{type:"RepeatStat",body:e,cond:t}}if(u("if"))return U();if(u("for"))return A();if(u("function")){const e=M(),t=w(!!e.method);return{type:"FuncStat",name:e,func:t}}if(u("local")){if(u("function")){const e=a(),t=w(!1);return{type:"LocalFuncStat",name:e,func:t}}return O()}if(s("::")){r("::");const e=a();return r("::"),{type:"LabelStat",name:e}}return _()},U=()=>{const e=[],t=i();for(r("keyword","then"),e.push({cond:t,body:f(["elseif","else","end"])});u("elseif");){const l=i();r("keyword","then"),e.push({cond:l,body:f(["elseif","else","end"])})}let n;return u("else")&&(n=f(["end"])),r("keyword","end"),{type:"IfStat",clauses:e,elseBody:n}},A=()=>{const e=a();if(o("=")){const b=i();r(",");const g=i();let N;o(",")&&(N=i()),r("keyword","do");const Y=f(["end"]);return r("keyword","end"),{type:"ForNumStat",name:e,start:b,end:g,step:N,body:Y}}const t=[e];for(;o(",");)t.push(a());r("keyword","in");const n=x();r("keyword","do");const l=f(["end"]);return r("keyword","end"),{type:"ForInStat",names:t,exps:n,body:l}},M=()=>{const e=a(),t=[];for(;o(".");)t.push(a());let n;return o(":")&&(n=a()),{base:e,fields:t,method:n}},w=e=>{r("(");const t=[];e&&t.push("self");let n=!1;if(!s(")"))if(s("vararg"))r("vararg"),n=!0;else for(t.push(a());o(",");){if(s("vararg")){r("vararg"),n=!0;break}t.push(a())}r(")");const l=f(["end"]);return r("keyword","end"),{type:"FuncExpr",params:t,vararg:n,body:l}},O=()=>{const e=[v()];for(;o(",");)e.push(v());let t;return o("=")&&(t=x()),{type:"LocalStat",names:e,exps:t}},v=()=>{const e=a();if(o("<")){const t=a();return r(">"),t!=="const"&&t!=="close"&&h(`\u672A\u77E5\u5C5E\u6027 <${t}>`),{name:e,attr:t}}return{name:e}},_=()=>{const e=m();if(s("=")||s(",")){const t=[e];for(;o(",");)t.push(m());r("=");const n=x();return{type:"AssignStat",vars:t,exps:n}}return(0,Z.isCallExpression)(e)?{type:"CallStat",exp:e}:h("\u8BED\u53E5\u5FC5\u987B\u662F\u8D4B\u503C\u6216\u51FD\u6570\u8C03\u7528")},x=()=>{const e=[i()];for(;o(",");)e.push(i());return e},i=()=>I(),d=(e,t)=>{let n=e();for(;;){const l=c(),b=l.kind==="keyword"?l.value:l.kind;if(!t.includes(b))break;p+=1;const g=e();n={type:"BinaryExpr",op:b,left:n,right:g}}return n},I=()=>d(R,["or"]),R=()=>d(q,["and"]),q=()=>d(D,["<",">","<=",">=","~=","=="]),D=()=>d(G,["|"]),G=()=>d(K,["~"]),K=()=>d(T,["&"]),T=()=>d(L,["<<",">>"]),L=()=>{const e=V();return s("..")?(p+=1,{type:"BinaryExpr",op:"..",left:e,right:L()}):e},V=()=>d(W,["+","-"]),W=()=>d(y,["*","/","//","%"]),y=()=>u("not")?{type:"UnaryExpr",op:"not",arg:y()}:o("#")?{type:"UnaryExpr",op:"#",arg:y()}:o("-")?{type:"UnaryExpr",op:"-",arg:y()}:o("~")?{type:"UnaryExpr",op:"~",arg:y()}:z(),z=()=>{const e=H();return s("^")?(p+=1,{type:"BinaryExpr",op:"^",left:e,right:y()}):e},H=()=>{if(u("nil"))return{type:"NilLiteral"};if(u("true"))return{type:"BoolLiteral",value:!0};if(u("false"))return{type:"BoolLiteral",value:!1};if(s("number")){const e=r("number");return{type:"NumberLiteral",raw:e.value,value:e.parsed}}if(s("string"))return{type:"StringLiteral",value:r("string").parsed};if(o("vararg"))return{type:"VarargExpr"};if(u("function"))return w(!1);if(s("{")){let e=C();return e=B(e),e}return m()},B=e=>{let t=e;for(;;){if(o(".")){t={type:"MemberExpr",object:t,field:a()};continue}if(o("[")){const n=i();r("]"),t={type:"IndexExpr",object:t,index:n};continue}if(o(":")){const n=a(),l=P();t={type:"MethodCallExpr",object:t,method:n,args:l};continue}if(s("(")||s("{")||s("string")){t={type:"CallExpr",callee:t,args:P()};continue}break}return t},m=()=>B(J()),J=()=>{if(o("(")){const e=i();return r(")"),{type:"ParenExpr",exp:e}}return s("name")?{type:"NameExpr",name:a()}:h("\u671F\u671B\u8868\u8FBE\u5F0F")},P=()=>{if(s("string"))return[{type:"StringLiteral",value:r("string").parsed}];if(s("{"))return[C()];if(r("("),o(")"))return[];const e=x();return r(")"),e},C=()=>{r("{");const e=[];for(;!s("}")&&(e.push(Q()),!(!o(",")&&!o(";"))););return r("}"),{type:"TableExpr",fields:e}},Q=()=>{if(o("[")){const e=i();return r("]"),r("="),{kind:"index",key:e,value:i()}}if(s("name")&&k[p+1]?.kind==="="){const e=a();return r("="),{kind:"name",key:e,value:i()}}return{kind:"list",value:i()}},X=f([]);return r("eof"),{type:"Chunk",body:X.body}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaParseError=void 0,exports.parseLua=te;const Z=require("./ast"),ee=require("./lexer");class j extends Error{constructor(b,p,l){super(`${b} (${p}:${l})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:p}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:l}),this.name="LuaParseError"}}exports.LuaParseError=j;function te(E){const b=(0,ee.lexLua)(E);let p=0;const l=()=>b[p],u=(e,t)=>{const n=l();return!(n.kind!==e||t!==void 0&&n.value!==t)},w=e=>u("keyword",e),m=e=>{const t=l();throw new j(e,t.line,t.column)},r=(e,t)=>{const n=l();return n.kind!==e||t!==void 0&&n.value!==t?m(`\u671F\u671B ${t??e}\uFF0C\u5B9E\u9645 ${n.value||n.kind}`):(p+=1,n)},o=(e,t)=>{if(u(e,t)){const n=l();return p+=1,n}},a=e=>w(e)?(p+=1,!0):!1,s=()=>r("name").value,c=e=>{const t=[];for(;!u("eof")&&!(l().kind==="keyword"&&e.includes(l().value));){if(w("return")){t.push($()),o(";");break}const n=D();n&&t.push(n)}return{type:"Block",body:t}},$=()=>(r("keyword","return"),u("eof")||u(";")||l().kind==="keyword"&&["end","else","elseif","until"].includes(l().value)?{type:"ReturnStat",exps:[]}:{type:"ReturnStat",exps:k()}),D=()=>{if(o(";"))return{type:"EmptyStat"};if(a("break"))return{type:"BreakStat"};if(a("goto"))return{type:"GotoStat",name:s()};if(a("do")){const e=c(["end"]);return r("keyword","end"),{type:"DoStat",body:e}}if(a("while")){const e=i();r("keyword","do");const t=c(["end"]);return r("keyword","end"),{type:"WhileStat",cond:e,body:t}}if(a("repeat")){const e=c(["until"]);r("keyword","until");const t=i();return{type:"RepeatStat",body:e,cond:t}}if(a("if"))return N();if(a("for"))return U();if(a("function")){const e=I(),t=v(!!e.method);return{type:"FuncStat",name:e,func:t}}if(a("local")){if(a("function")){const e=s(),t=v(!1);return{type:"LocalFuncStat",name:e,func:t}}return M()}if(u("::")){r("::");const e=s();return r("::"),{type:"LabelStat",name:e}}return O()},N=()=>{const e=[],t=i();for(r("keyword","then"),e.push({cond:t,body:c(["elseif","else","end"])});a("elseif");){const d=i();r("keyword","then"),e.push({cond:d,body:c(["elseif","else","end"])})}let n;return a("else")&&(n=c(["end"])),r("keyword","end"),{type:"IfStat",clauses:e,elseBody:n}},U=()=>{const e=s();if(o("=")){const h=i();r(",");const g=i();let P;o(",")&&(P=i()),r("keyword","do");const Y=c(["end"]);return r("keyword","end"),{type:"ForNumStat",name:e,start:h,end:g,step:P,body:Y}}const t=[e];for(;o(",");)t.push(s());r("keyword","in");const n=k();r("keyword","do");const d=c(["end"]);return r("keyword","end"),{type:"ForInStat",names:t,exps:n,body:d}},I=()=>{const e=s(),t=[];for(;o(".");)t.push(s());let n;return o(":")&&(n=s()),{base:e,fields:t,method:n}},v=e=>{r("(");const t=[];e&&t.push("self");let n=!1;if(!u(")"))if(u("vararg"))r("vararg"),n=!0;else for(t.push(s());o(",");){if(u("vararg")){r("vararg"),n=!0;break}t.push(s())}r(")");const d=c(["end"]);return r("keyword","end"),{type:"FuncExpr",params:t,vararg:n,body:d}},M=()=>{const e=[S()];for(;o(",");)e.push(S());let t;return o("=")&&(t=k()),{type:"LocalStat",names:e,exps:t}},S=()=>{const e=s();if(o("<")){const t=s();return r(">"),t!=="const"&&t!=="close"&&m(`\u672A\u77E5\u5C5E\u6027 <${t}>`),{name:e,attr:t}}return{name:e}},O=()=>{const e=x();if(u("=")||u(",")){const t=[e];for(;o(",");)t.push(x());r("=");const n=k();return{type:"AssignStat",vars:t,exps:n}}return(0,Z.isCallExpression)(e)?{type:"CallStat",exp:e}:m("\u8BED\u53E5\u5FC5\u987B\u662F\u8D4B\u503C\u6216\u51FD\u6570\u8C03\u7528")},k=()=>{const e=[i()];for(;o(",");)e.push(i());return e},i=()=>R(),y=(e,t)=>{let n=e();for(;;){const d=l(),h=d.kind==="keyword"?d.value:d.kind;if(!t.includes(h))break;p+=1;const g=e();n={type:"BinaryExpr",op:h,left:n,right:g}}return n},R=()=>y(q,["or"]),q=()=>y(A,["and"]),A=()=>y(_,["<",">","<=",">=","~=","=="]),_=()=>y(G,["|"]),G=()=>y(T,["~"]),T=()=>y(V,["&"]),V=()=>y(B,["<<",">>"]),B=()=>{const e=W();return u("..")?(p+=1,{type:"BinaryExpr",op:"..",left:e,right:B()}):e},W=()=>y(z,["+","-"]),z=()=>y(f,["*","/","//","%"]),f=()=>a("not")?{type:"UnaryExpr",op:"not",arg:f()}:o("#")?{type:"UnaryExpr",op:"#",arg:f()}:o("-")?{type:"UnaryExpr",op:"-",arg:f()}:o("~")?{type:"UnaryExpr",op:"~",arg:f()}:H(),H=()=>{const e=J();return u("^")?(p+=1,{type:"BinaryExpr",op:"^",left:e,right:f()}):e},J=()=>{if(a("nil"))return{type:"NilLiteral"};if(a("true"))return{type:"BoolLiteral",value:!0};if(a("false"))return{type:"BoolLiteral",value:!1};if(u("number")){const e=r("number");return{type:"NumberLiteral",raw:e.value,value:e.parsed}}if(u("string"))return{type:"StringLiteral",value:r("string").parsed};if(o("vararg"))return{type:"VarargExpr"};if(a("function"))return v(!1);if(u("{")){let e=C();return e=F(e),e}return x()},F=e=>{let t=e;for(;;){if(o(".")){t={type:"MemberExpr",object:t,field:s()};continue}if(o("[")){const n=i();r("]"),t={type:"IndexExpr",object:t,index:n};continue}if(o(":")){const n=s(),d=L();t={type:"MethodCallExpr",object:t,method:n,args:d};continue}if(u("(")||u("{")||u("string")){t={type:"CallExpr",callee:t,args:L()};continue}break}return t},x=()=>F(K()),K=()=>{if(o("(")){const e=i();return r(")"),{type:"ParenExpr",exp:e}}return u("name")?{type:"NameExpr",name:s()}:m("\u671F\u671B\u8868\u8FBE\u5F0F")},L=()=>{if(u("string"))return[{type:"StringLiteral",value:r("string").parsed}];if(u("{"))return[C()];if(r("("),o(")"))return[];const e=k();return r(")"),e},C=()=>{r("{");const e=[];for(;!u("}")&&(e.push(Q()),!(!o(",")&&!o(";"))););return r("}"),{type:"TableExpr",fields:e}},Q=()=>{if(o("[")){const e=i();return r("]"),r("="),{kind:"index",key:e,value:i()}}if(u("name")&&b[p+1]?.kind==="="){const e=s();return r("="),{kind:"name",key:e,value:i()}}return{kind:"list",value:i()}},X=c([]);return r("eof"),{type:"Chunk",body:X.body}}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shortName=l,exports.renameLocals=h;const c=require("./reserved"),u=require("./scope"),o="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";function l(r){let e=r,t="";do t=o[e%o.length]+t,e=Math.floor(e/o.length)-1;while(e>=0);return c.luaKeywords.has(t)?`_${t}`:t}function h(r){let e=0;const t=new Set;(0,u.collectAndRename)(r,(n,s)=>{if(n.newName!==n.original)return;let a=l(e);for(e+=1;s.has(a)||t.has(a)||c.luaKeywords.has(a);)a=l(e),e+=1;n.newName=a,t.add(a),s.add(a)})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shortName=n,exports.renameLocals=d;const u=require("./reserved"),c=require("./scope"),l="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";function n(r){let e=r,t="";do t=l[e%l.length]+t,e=Math.floor(e/l.length)-1;while(e>=0);return u.luaKeywords.has(t)?`_${t}`:t}function d(r){let e=0;const t=new Set;(0,c.collectAndRename)(r,(o,s)=>{if(o.newName!==o.original)return;let a=n(e);for(e+=1;s.has(a)||t.has(a)||u.luaKeywords.has(a);)a=n(e),e+=1;o.newName=a,t.add(a),s.add(a)})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=e,exports.collectAndRename=g;function e(t,r){let n=t;for(;n;){const a=n.locals.get(r);if(a)return a;n=n.parent}}function i(t){return{parent:t,locals:new Map}}function S(t,r){const n=t.locals.get(r);if(n)return n;const a={original:r,newName:r};return t.locals.set(r,a),a}function g(t,r){const n=new Set,a={locals:new Map};y(t.body,a,n,r)}function f(t,r,n,a){y(t.body,r,n,a)}function y(t,r,n,a){for(const o of t)E(o,r,n,a)}function w(t,r,n,a){const o=i(r),l=t.params.slice();for(let b=0;b<l.length;b+=1){const u=S(o,l[b]);a(u,n),t.params[b]=u.newName}f(t.body,o,n,a)}function E(t,r,n,a){switch(t.type){case"EmptyStat":case"BreakStat":case"GotoStat":case"LabelStat":return;case"DoStat":f(t.body,i(r),n,a);return;case"WhileStat":c(t.cond,r,n,a),f(t.body,i(r),n,a);return;case"RepeatStat":{const o=i(r);f(t.body,o,n,a),c(t.cond,o,n,a);return}case"IfStat":for(const o of t.clauses)c(o.cond,r,n,a),f(o.body,i(r),n,a);t.elseBody&&f(t.elseBody,i(r),n,a);return;case"ForNumStat":{c(t.start,r,n,a),c(t.end,r,n,a),t.step&&c(t.step,r,n,a);const o=i(r),l=S(o,t.name);a(l,n),t.name=l.newName,f(t.body,o,n,a);return}case"ForInStat":{for(const l of t.exps)c(l,r,n,a);const o=i(r);for(let l=0;l<t.names.length;l+=1){const b=S(o,t.names[l]);a(b,n),t.names[l]=b.newName}f(t.body,o,n,a);return}case"FuncStat":{const o=e(r,t.name.base);o&&(t.name.base=o.newName),w(t.func,r,n,a);return}case"LocalFuncStat":{const o=S(r,t.name);a(o,n),t.name=o.newName,w(t.func,r,n,a);return}case"LocalStat":if(t.exps)for(const o of t.exps)c(o,r,n,a);for(let o=0;o<t.names.length;o+=1){const l=S(r,t.names[o].name);a(l,n),t.names[o].name=l.newName}return;case"AssignStat":for(const o of t.vars)c(o,r,n,a);for(const o of t.exps)c(o,r,n,a);return;case"CallStat":c(t.exp,r,n,a);return;case"ReturnStat":for(const o of t.exps)c(o,r,n,a);return}}function c(t,r,n,a){switch(t.type){case"NilLiteral":case"BoolLiteral":case"NumberLiteral":case"StringLiteral":case"VarargExpr":return;case"NameExpr":{const o=e(r,t.name);o&&(t.name=o.newName);return}case"UnaryExpr":c(t.arg,r,n,a);return;case"BinaryExpr":c(t.left,r,n,a),c(t.right,r,n,a);return;case"FuncExpr":w(t,r,n,a);return;case"TableExpr":for(const o of t.fields)o.kind==="index"&&c(o.key,r,n,a),c(o.value,r,n,a);return;case"IndexExpr":c(t.object,r,n,a),c(t.index,r,n,a);return;case"MemberExpr":c(t.object,r,n,a);return;case"CallExpr":c(t.callee,r,n,a);for(const o of t.args)c(o,r,n,a);return;case"MethodCallExpr":c(t.object,r,n,a);for(const o of t.args)c(o,r,n,a);return;case"ParenExpr":c(t.exp,r,n,a);return}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=i,exports.collectAndRename=b;function i(e,c){let o=e;for(;o;){const s=o.locals.get(c);if(s)return s;o=o.parent}}function r(e){return{parent:e,locals:new Map}}function f(e,c){const o=e.locals.get(c);if(o)return o;const s={original:c,newName:c};return e.locals.set(c,s),s}function b(e,c){const o=new Set,s={locals:new Map};d(e.body,s,o,c)}function l(e,c,o,s){d(e.body,c,o,s)}function d(e,c,o,s){for(const n of e)x(n,c,o,s)}function m(e,c,o,s){const n=r(c),t=e.params.slice();for(let u=0;u<t.length;u+=1){const p=f(n,t[u]);s(p,o),e.params[u]=p.newName}l(e.body,n,o,s)}function x(e,c,o,s){switch(e.type){case"EmptyStat":case"BreakStat":case"GotoStat":case"LabelStat":return;case"DoStat":l(e.body,r(c),o,s);return;case"WhileStat":a(e.cond,c,o,s),l(e.body,r(c),o,s);return;case"RepeatStat":{const n=r(c);l(e.body,n,o,s),a(e.cond,n,o,s);return}case"IfStat":for(const n of e.clauses)a(n.cond,c,o,s),l(n.body,r(c),o,s);e.elseBody&&l(e.elseBody,r(c),o,s);return;case"ForNumStat":{a(e.start,c,o,s),a(e.end,c,o,s),e.step&&a(e.step,c,o,s);const n=r(c),t=f(n,e.name);s(t,o),e.name=t.newName,l(e.body,n,o,s);return}case"ForInStat":{for(const t of e.exps)a(t,c,o,s);const n=r(c);for(let t=0;t<e.names.length;t+=1){const u=f(n,e.names[t]);s(u,o),e.names[t]=u.newName}l(e.body,n,o,s);return}case"FuncStat":{const n=i(c,e.name.base);n&&(e.name.base=n.newName),m(e.func,c,o,s);return}case"LocalFuncStat":{const n=f(c,e.name);s(n,o),e.name=n.newName,m(e.func,c,o,s);return}case"LocalStat":if(e.exps)for(const n of e.exps)a(n,c,o,s);for(let n=0;n<e.names.length;n+=1){const t=f(c,e.names[n].name);s(t,o),e.names[n].name=t.newName}return;case"AssignStat":for(const n of e.vars)a(n,c,o,s);for(const n of e.exps)a(n,c,o,s);return;case"CallStat":a(e.exp,c,o,s);return;case"ReturnStat":for(const n of e.exps)a(n,c,o,s);return}}function a(e,c,o,s){switch(e.type){case"NilLiteral":case"BoolLiteral":case"NumberLiteral":case"StringLiteral":case"VarargExpr":return;case"NameExpr":{const n=i(c,e.name);n&&(e.name=n.newName);return}case"UnaryExpr":a(e.arg,c,o,s);return;case"BinaryExpr":a(e.left,c,o,s),a(e.right,c,o,s);return;case"FuncExpr":m(e,c,o,s);return;case"TableExpr":for(const n of e.fields)n.kind==="index"&&a(n.key,c,o,s),a(n.value,c,o,s);return;case"IndexExpr":a(e.object,c,o,s),a(e.index,c,o,s);return;case"MemberExpr":a(e.object,c,o,s);return;case"CallExpr":a(e.callee,c,o,s);for(const n of e.args)a(n,c,o,s);return;case"MethodCallExpr":a(e.object,c,o,s);for(const n of e.args)a(n,c,o,s);return;case"ParenExpr":a(e.exp,c,o,s);return}}
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const m=require("child_process"),l=require("./cipher"),S=require("./flatten"),f=require("./minify"),r=require("./parser"),c=require("./index");let a=0;function n(e,t){e?console.log(`\u2705 ${t}`):(a+=1,console.error(`\u274C ${t}`))}const u=`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const p=require("child_process"),c=require("./cipher"),F=require("./flatten"),a=require("./minify"),o=require("./parser"),r=require("./index");let s=0;function e(u,n){u?console.log(`\u2705 ${n}`):(s+=1,console.error(`\u274C ${n}`))}const l=`
2
2
  local helper = require("device")
3
3
  local wait = 10
4
4
  Sleep(wait)
@@ -9,9 +9,9 @@ end
9
9
  if add(1, 2) == 3 then
10
10
  logi("ok")
11
11
  end
12
- `;function _(){const e=(0,l.createFoldMixParams)(42),t=["device","\u4F60\u597D","Sleep",""];for(const i of t){if(i.length===0)continue;const o=(0,l.foldEncrypt)(i,e,99),s=(0,l.foldDecrypt)(o,e,99),p=Buffer.from(i,"utf8").toString("latin1");n(s===p,`FoldMix \u5F80\u8FD4 ${i}`),n(!o.includes("device")||i!=="device","FoldMix \u8F7D\u8377\u4E0D\u542B\u660E\u6587 device")}}function b(){const e=(0,r.parseLua)(u),t=(0,f.minifyLua)(e),i=(0,r.parseLua)(t);n(i.body.length>0,"\u89E3\u6790\u5F80\u8FD4\u5F97\u5230\u975E\u7A7A AST"),n(t.includes("Sleep"),"Minify \u53D1\u5C04\u4FDD\u7559 Sleep")}function y(){const e=(0,c.obfuscateLua)(u,"Minify");n(e.includes("Sleep"),"Minify \u4E0D\u6539 Sleep"),n(e.includes("require"),"Minify \u4FDD\u7559 require"),n(!e.includes('"device"'),"Minify \u4E0D\u4FDD\u7559\u660E\u6587 device \u5B57\u9762\u91CF"),n(e.includes("\\100\\101\\118\\105\\099\\101"),"Minify \u7528\u5341\u8FDB\u5236\u8F6C\u4E49\u4FDD\u7559 device"),n(!/\bwait\b/.test(e),"Minify \u91CD\u547D\u540D\u5C40\u90E8 wait"),(0,r.parseLua)(e)}function M(){const t=(0,r.parseLua)(`local n=0
12
+ `;function E(){const u=(0,c.createFoldMixParams)(42),n=["device","\u4F60\u597D","Sleep",""];for(const t of n){if(t.length===0)continue;const i=(0,c.foldEncrypt)(t,u,99),d=(0,c.foldDecrypt)(i,u,99),D=Buffer.from(t,"utf8").toString("latin1");e(d===D,`FoldMix \u5F80\u8FD4 ${t}`),e(!i.includes("device")||t!=="device","FoldMix \u8F7D\u8377\u4E0D\u542B\u660E\u6587 device")}}function C(){const u=(0,o.parseLua)(l),n=(0,a.minifyLua)(u),t=(0,o.parseLua)(n);e(t.body.length>0,"\u89E3\u6790\u5F80\u8FD4\u5F97\u5230\u975E\u7A7A AST"),e(n.includes("Sleep"),"Minify \u53D1\u5C04\u4FDD\u7559 Sleep")}function S(){const u=(0,r.obfuscateLua)(l,"Minify");e(u.includes("Sleep"),"Minify \u4E0D\u6539 Sleep"),e(u.includes("require"),"Minify \u4FDD\u7559 require"),e(!u.includes('"device"'),"Minify \u4E0D\u4FDD\u7559\u660E\u6587 device \u5B57\u9762\u91CF"),e(u.includes("\\100\\101\\118\\105\\099\\101"),"Minify \u7528\u5341\u8FDB\u5236\u8F6C\u4E49\u4FDD\u7559 device"),e(!/\bwait\b/.test(u),"Minify \u91CD\u547D\u540D\u5C40\u90E8 wait"),(0,o.parseLua)(u)}function _(){const u=(0,o.parseLua)(`local n=0
13
13
  for i=1,3 do n=n+i end
14
- if n==6 then Sleep(n) else Sleep(0) end`);(0,S.flattenControlFlow)(t,1);const i=(0,f.minifyLua)(t);n(i.includes("while"),"\u5C55\u5E73\u540E\u662F\u72B6\u6001\u673A\u5FAA\u73AF"),n(!/for\s+i\s*=\s*1\s*,\s*3/.test(i),"\u5C55\u5E73\u540E\u4E0D\u518D\u662F for i=1,3"),n(!/if\s+n\s*==\s*6/.test(i),"\u5C55\u5E73\u540E\u4E0D\u518D\u662F if n==6")}function g(){const e=(0,c.obfuscateLua)(u,"Weak");n(e.includes("function"),"Weak \u542B Vmify \u89E3\u91CA\u5668"),n(!e.includes("Sleep(wait)"),"Weak \u4E0D\u518D\u4FDD\u7559\u660E\u6587 Sleep(wait)"),n(!e.includes("helper.tap"),"Weak \u4E0D\u518D\u4FDD\u7559 helper.tap \u6E90\u7801\u7ED3\u6784"),n(!/\bhelper\b/.test(e),"Weak \u6539\u6389\u5C40\u90E8 helper"),(0,r.parseLua)(e),n(!0,"Weak \u4EA7\u7269\u53EF\u518D\u89E3\u6790")}function h(){const e=(0,c.obfuscateLua)(u,"Medium");n(e.includes("function"),"Medium \u542B\u865A\u62DF\u673A"),n(!e.includes('logi("ok")'),"Medium \u52A0\u5BC6\u7528\u6237\u5B57\u7B26\u4E32"),n(!e.includes("Tamper Detected!")||e.includes("pcall"),"Medium \u542B\u5B8C\u6574\u6027\u68C0\u67E5\u6216\u5DF2\u7F16\u8FDB VM"),(0,r.parseLua)(e),n(!0,"Medium \u4EA7\u7269\u53EF\u518D\u89E3\u6790")}function L(){const t=(0,c.obfuscateLua)('local d=require("device"); Sleep(1)',"Strong");n(t.includes("function"),"Strong \u542B\u89E3\u91CA\u5668\u51FD\u6570"),n(!t.includes("Sleep(1)"),"Strong \u4E0D\u518D\u4FDD\u7559\u660E\u6587 Sleep(1) \u8C03\u7528"),(0,r.parseLua)(t),n(!0,"Strong \u4EA7\u7269\u662F\u5408\u6CD5 Lua")}function k(){const t=(0,c.obfuscateLua)(`
14
+ if n==6 then Sleep(n) else Sleep(0) end`);(0,F.flattenControlFlow)(u,1);const n=(0,a.minifyLua)(u);e(n.includes("while"),"\u5C55\u5E73\u540E\u662F\u72B6\u6001\u673A\u5FAA\u73AF"),e(!/for\s+i\s*=\s*1\s*,\s*3/.test(n),"\u5C55\u5E73\u540E\u4E0D\u518D\u662F for i=1,3"),e(!/if\s+n\s*==\s*6/.test(n),"\u5C55\u5E73\u540E\u4E0D\u518D\u662F if n==6")}function b(){const u=(0,r.obfuscateLua)(l,"Weak");e(u.includes("function"),"Weak \u542B Vmify \u89E3\u91CA\u5668"),e(!u.includes("Sleep(wait)"),"Weak \u4E0D\u518D\u4FDD\u7559\u660E\u6587 Sleep(wait)"),e(!u.includes("helper.tap"),"Weak \u4E0D\u518D\u4FDD\u7559 helper.tap \u6E90\u7801\u7ED3\u6784"),e(!/\bhelper\b/.test(u),"Weak \u6539\u6389\u5C40\u90E8 helper"),(0,o.parseLua)(u),e(!0,"Weak \u4EA7\u7269\u53EF\u518D\u89E3\u6790")}function m(){const u=(0,r.obfuscateLua)(l,"Medium");e(u.includes("function"),"Medium \u542B\u865A\u62DF\u673A"),e(!u.includes('logi("ok")'),"Medium \u52A0\u5BC6\u7528\u6237\u5B57\u7B26\u4E32"),e(!u.includes("Tamper Detected!")||u.includes("pcall"),"Medium \u542B\u5B8C\u6574\u6027\u68C0\u67E5\u6216\u5DF2\u7F16\u8FDB VM"),(0,o.parseLua)(u),e(!0,"Medium \u4EA7\u7269\u53EF\u518D\u89E3\u6790")}function g(){const u=(0,r.obfuscateLua)('local d=require("device"); Sleep(1)',"Strong");e(u.includes("function"),"Strong \u542B\u89E3\u91CA\u5668\u51FD\u6570"),e(!u.includes("Sleep(1)"),"Strong \u4E0D\u518D\u4FDD\u7559\u660E\u6587 Sleep(1) \u8C03\u7528"),(0,o.parseLua)(u),e(!0,"Strong \u4EA7\u7269\u662F\u5408\u6CD5 Lua")}function y(){const u=(0,r.obfuscateLua)(`
15
15
  local x <const> = 1
16
16
  local y = 10 // 3
17
17
  local z = y & 1 | 2
@@ -20,7 +20,7 @@ goto skip
20
20
  for i = 1, 2 do
21
21
  break
22
22
  end
23
- `,"Minify");(0,r.parseLua)(t),n(t.includes("<const>"),"Minify \u4FDD\u7559 <const>"),n(t.includes("//"),"Minify \u4FDD\u7559\u6574\u9664")}function q(e){const t=["/opt/homebrew/bin/lua","lua5.4","lua54","lua"];for(const i of t){const o=(0,m.spawnSync)(i,["-e",e],{encoding:"utf8"});if(!o.error)return{ok:o.status===0,out:(o.stdout||"")+(o.stderr||"")}}return{ok:!1,out:""}}function d(e){const i=(0,c.obfuscateLua)('local m=require("device"); Sleep(3)',e),o=`
23
+ `,"Minify");(0,o.parseLua)(u),e(u.includes("<const>"),"Minify \u4FDD\u7559 <const>"),e(u.includes("//"),"Minify \u4FDD\u7559\u6574\u9664")}function M(u){const n=["/opt/homebrew/bin/lua","lua5.4","lua54","lua"];for(const t of n){const i=(0,p.spawnSync)(t,["-e",u],{encoding:"utf8"});if(!i.error)return{ok:i.status===0,out:(i.stdout||"")+(i.stderr||"")}}return{ok:!1,out:""}}function f(u){const n=(0,r.obfuscateLua)('local m=require("device"); Sleep(3)',u),t=`
24
24
  local env = setmetatable({
25
25
  require = function(n) _G.__req = n; return {} end,
26
26
  Sleep = function(ms) _G.__slept = ms end,
@@ -28,12 +28,12 @@ local env = setmetatable({
28
28
  getmetatable = getmetatable, pcall = pcall, error = error,
29
29
  }, {__index = _G})
30
30
  env._ENV = env
31
- local fn, err = load(${JSON.stringify(i)}, "obf", "t", env)
31
+ local fn, err = load(${JSON.stringify(n)}, "obf", "t", env)
32
32
  if not fn then error(err) end
33
33
  fn()
34
34
  if _G.__req ~= "device" then error("require name "..tostring(_G.__req)) end
35
35
  if _G.__slept ~= 3 then error("Sleep "..tostring(_G.__slept)) end
36
- print("${e}-ok")
37
- `,s=q(o);if(!s.out&&s.ok===!1){console.log(`\u2139\uFE0F \u672C\u673A\u65E0 lua \u89E3\u91CA\u5668\uFF0C\u8DF3\u8FC7 ${e} \u8FD0\u884C\u65F6\u68C0\u67E5`);return}n(s.ok&&s.out.includes(`${e}-ok`),`${e} \u8FD0\u884C\u65F6\u8FD8\u539F require/Sleep: ${s.out.trim()}`)}_(),b(),y(),M(),g(),h(),L(),k(),d("Medium"),d("Strong"),a>0&&(console.error(`
38
- \u81EA\u68C0\u5931\u8D25 ${a} \u9879`),process.exit(1)),console.log(`
36
+ print("${u}-ok")
37
+ `,i=M(t);if(!i.out&&i.ok===!1){console.log(`\u2139\uFE0F \u672C\u673A\u65E0 lua \u89E3\u91CA\u5668\uFF0C\u8DF3\u8FC7 ${u} \u8FD0\u884C\u65F6\u68C0\u67E5`);return}e(i.ok&&i.out.includes(`${u}-ok`),`${u} \u8FD0\u884C\u65F6\u8FD8\u539F require/Sleep: ${i.out.trim()}`)}E(),C(),S(),_(),b(),m(),g(),y(),f("Medium"),f("Strong"),s>0&&(console.error(`
38
+ \u81EA\u68C0\u5931\u8D25 ${s} \u9879`),process.exit(1)),console.log(`
39
39
  \u81EA\u68C0\u901A\u8FC7`);
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.splitStrings=o;const s=require("./visit");function u(t){let r={type:"StringLiteral",value:t[0]};for(let n=1;n<t.length;n+=1)r={type:"BinaryExpr",op:"..",left:r,right:{type:"StringLiteral",value:t[n]}};return{type:"ParenExpr",exp:r}}function c(t,r){if(t.length<4)return[t];const n=r%2+2,e=Math.max(1,Math.ceil(t.length/n)),i=[];for(let l=0;l<t.length;l+=e)i.push(t.slice(l,l+e));return i}function o(t,r){let n=0;(0,s.mapChunk)(t,e=>{if(e.type!=="StringLiteral"||e.encoded||e.value.length<4)return e;n+=1;const i=c(e.value,r+n);return i.length<2?e:u(i)})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.splitStrings=p;const u=require("./visit");function a(e){let r={type:"StringLiteral",value:e[0]};for(let n=1;n<e.length;n+=1)r={type:"BinaryExpr",op:"..",left:r,right:{type:"StringLiteral",value:e[n]}};return{type:"ParenExpr",exp:r}}function o(e,r){if(e.length<4)return[e];const n=r%2+2,t=Math.max(1,Math.ceil(e.length/n)),l=[];for(let i=0;i<e.length;i+=t)l.push(e.slice(i,i+t));return l}function p(e,r){let n=0;(0,u.mapChunk)(e,t=>{if(t.type!=="StringLiteral"||t.encoded||t.value.length<4)return t;n+=1;const l=o(t.value,r+n);return l.length<2?t:a(l)})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.foldEncrypt=exports.foldDecrypt=exports.createFoldMixParams=void 0,exports.encryptStrings=y;const a=require("./cipher");Object.defineProperty(exports,"createFoldMixParams",{enumerable:!0,get:function(){return a.createFoldMixParams}}),Object.defineProperty(exports,"foldDecrypt",{enumerable:!0,get:function(){return a.foldDecrypt}}),Object.defineProperty(exports,"foldEncrypt",{enumerable:!0,get:function(){return a.foldEncrypt}});const i=require("./parser"),l=require("./visit"),c="__d";function d(t,o){let e=2166136261^o;for(let r=0;r<t.length;r+=1)e=Math.imul(e^t.charCodeAt(r),16777619);return e>>>0||1}function p(t,o,e){const r=(0,a.foldEncrypt)(t,o,e);return{type:"CallExpr",callee:{type:"NameExpr",name:c},args:[{type:"StringLiteral",value:r,encoded:!0},{type:"NumberLiteral",raw:String(e),value:e}]}}function y(t,o){const e=(0,a.createFoldMixParams)(o);let r=0;(0,l.mapChunk)(t,n=>n.type!=="StringLiteral"||n.encoded||n.value.length===0?n:(r+=1,p(n.value,e,d(n.value,r))));const u=(0,i.parseLua)((0,a.emitFoldDecoderLua)(e,c));t.body.unshift(...u.body)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.foldEncrypt=exports.foldDecrypt=exports.createFoldMixParams=void 0,exports.encryptStrings=y;const a=require("./cipher");Object.defineProperty(exports,"createFoldMixParams",{enumerable:!0,get:function(){return a.createFoldMixParams}}),Object.defineProperty(exports,"foldDecrypt",{enumerable:!0,get:function(){return a.foldDecrypt}}),Object.defineProperty(exports,"foldEncrypt",{enumerable:!0,get:function(){return a.foldEncrypt}});const u=require("./parser"),i=require("./visit"),o="__d";function d(t,l){let e=2166136261^l;for(let r=0;r<t.length;r+=1)e=Math.imul(e^t.charCodeAt(r),16777619);return e>>>0||1}function p(t,l,e){const r=(0,a.foldEncrypt)(t,l,e);return{type:"CallExpr",callee:{type:"NameExpr",name:o},args:[{type:"StringLiteral",value:r,encoded:!0},{type:"NumberLiteral",raw:String(e),value:e}]}}function y(t,l){const e=(0,a.createFoldMixParams)(l);let r=0;(0,i.mapChunk)(t,n=>n.type!=="StringLiteral"||n.encoded||n.value.length===0?n:(r+=1,p(n.value,e,d(n.value,r))));const c=(0,u.parseLua)((0,a.emitFoldDecoderLua)(e,o));t.body.unshift(...c.body)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mapExp=r,exports.mapFunc=o,exports.mapStats=c,exports.mapChunk=b;function r(t,e){switch(t.type){case"UnaryExpr":t.arg=r(t.arg,e);break;case"BinaryExpr":t.left=r(t.left,e),t.right=r(t.right,e);break;case"FuncExpr":o(t,e);break;case"TableExpr":for(const a of t.fields)a.kind==="index"&&(a.key=r(a.key,e)),a.value=r(a.value,e);break;case"IndexExpr":t.object=r(t.object,e),t.index=r(t.index,e);break;case"MemberExpr":t.object=r(t.object,e);break;case"CallExpr":t.callee=r(t.callee,e),t.args=t.args.map(a=>r(a,e));break;case"MethodCallExpr":t.object=r(t.object,e),t.args=t.args.map(a=>r(a,e));break;case"ParenExpr":t.exp=r(t.exp,e);break;default:break}return e(t)}function o(t,e){c(t.body.body,e)}function c(t,e){for(const a of t)switch(a.type){case"DoStat":c(a.body.body,e);break;case"WhileStat":a.cond=r(a.cond,e),c(a.body.body,e);break;case"RepeatStat":c(a.body.body,e),a.cond=r(a.cond,e);break;case"IfStat":for(const s of a.clauses)s.cond=r(s.cond,e),c(s.body.body,e);a.elseBody&&c(a.elseBody.body,e);break;case"ForNumStat":a.start=r(a.start,e),a.end=r(a.end,e),a.step&&(a.step=r(a.step,e)),c(a.body.body,e);break;case"ForInStat":a.exps=a.exps.map(s=>r(s,e)),c(a.body.body,e);break;case"FuncStat":o(a.func,e);break;case"LocalFuncStat":o(a.func,e);break;case"LocalStat":a.exps&&(a.exps=a.exps.map(s=>r(s,e)));break;case"AssignStat":a.vars=a.vars.map(s=>r(s,e)),a.exps=a.exps.map(s=>r(s,e));break;case"CallStat":a.exp=r(a.exp,e);break;case"ReturnStat":a.exps=a.exps.map(s=>r(s,e));break;default:break}}function b(t,e){c(t.body,e)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mapExp=s,exports.mapFunc=b,exports.mapStats=o,exports.mapChunk=p;function s(r,e){switch(r.type){case"UnaryExpr":r.arg=s(r.arg,e);break;case"BinaryExpr":r.left=s(r.left,e),r.right=s(r.right,e);break;case"FuncExpr":b(r,e);break;case"TableExpr":for(const a of r.fields)a.kind==="index"&&(a.key=s(a.key,e)),a.value=s(a.value,e);break;case"IndexExpr":r.object=s(r.object,e),r.index=s(r.index,e);break;case"MemberExpr":r.object=s(r.object,e);break;case"CallExpr":r.callee=s(r.callee,e),r.args=r.args.map(a=>s(a,e));break;case"MethodCallExpr":r.object=s(r.object,e),r.args=r.args.map(a=>s(a,e));break;case"ParenExpr":r.exp=s(r.exp,e);break;default:break}return e(r)}function b(r,e){o(r.body.body,e)}function o(r,e){for(const a of r)switch(a.type){case"DoStat":o(a.body.body,e);break;case"WhileStat":a.cond=s(a.cond,e),o(a.body.body,e);break;case"RepeatStat":o(a.body.body,e),a.cond=s(a.cond,e);break;case"IfStat":for(const c of a.clauses)c.cond=s(c.cond,e),o(c.body.body,e);a.elseBody&&o(a.elseBody.body,e);break;case"ForNumStat":a.start=s(a.start,e),a.end=s(a.end,e),a.step&&(a.step=s(a.step,e)),o(a.body.body,e);break;case"ForInStat":a.exps=a.exps.map(c=>s(c,e)),o(a.body.body,e);break;case"FuncStat":b(a.func,e);break;case"LocalFuncStat":b(a.func,e);break;case"LocalStat":a.exps&&(a.exps=a.exps.map(c=>s(c,e)));break;case"AssignStat":a.vars=a.vars.map(c=>s(c,e)),a.exps=a.exps.map(c=>s(c,e));break;case"CallStat":a.exp=s(a.exp,e);break;case"ReturnStat":a.exps=a.exps.map(c=>s(c,e));break;default:break}}function p(r,e){o(r.body,e)}
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.emitVm=j;const s=require("./cipher"),h=require("./minify"),f=require("./opcodes");function u(e){let n=2166136261^e.code.length;return n=Math.imul(n,16777619)^e.consts.length,n>>>0}function b(e,n,o){if(e.t==="nil")return"nil";if(e.t==="bool")return e.v?"true":"false";if(e.t==="num")return e.raw;const l=(0,s.foldEncrypt)(e.v,n,o);return`D(${(0,h.escapeLuaString)(l)},${o})`}function r(e,n,o,l){const c=e.code.map((t,a)=>{const d=e.ops[a];return`{${n[d]},${t[1]},${t[2]},${t[3]}}`}).join(","),i=e.consts.map((t,a)=>b(t,o,l+a*131>>>0||1)).join(","),R=e.protos.map((t,a)=>r(t,n,o,l+(a+1)*4099>>>0)).join(","),p=e.upvals.map(t=>`{${t.inStack?1:0},${t.index}}`).join(",");return`{p={${c}},k={${i}},t={${R}},u={${p}},n=${e.numparams},v=${e.isVararg?"true":"false"}}`}function j(e){const n=u(e)||1,o=(0,f.shuffleOpcodes)(n),l=(0,s.createFoldMixParams)(n),c=f.OPCODE_NAMES.join(","),i=f.OPCODE_NAMES.map(t=>String(o[t])).join(","),R=r(e,o,l,n);return`(function()
2
- ${(0,s.emitFoldDecoderLua)(l,"D")}
3
- local ${c}=${i}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.emitVm=j;const p=require("./cipher"),d=require("./minify"),s=require("./opcodes");function h(e){let n=2166136261^e.code.length;return n=Math.imul(n,16777619)^e.consts.length,n>>>0}function b(e,n,l){if(e.t==="nil")return"nil";if(e.t==="bool")return e.v?"true":"false";if(e.t==="num")return e.raw;const a=(0,p.foldEncrypt)(e.v,n,l);return`D(${(0,d.escapeLuaString)(a)},${l})`}function u(e,n,l,a){const i=e.code.map((t,o)=>{const r=e.ops[o];return`{${n[r]},${t[1]},${t[2]},${t[3]}}`}).join(","),c=e.consts.map((t,o)=>b(t,l,a+o*131>>>0||1)).join(","),R=e.protos.map((t,o)=>u(t,n,l,a+(o+1)*4099>>>0)).join(","),f=e.upvals.map(t=>`{${t.inStack?1:0},${t.index}}`).join(",");return`{p={${i}},k={${c}},t={${R}},u={${f}},n=${e.numparams},v=${e.isVararg?"true":"false"}}`}function j(e){const n=h(e)||1,l=(0,s.shuffleOpcodes)(n),a=(0,p.createFoldMixParams)(n),i=s.OPCODE_NAMES.join(","),c=s.OPCODE_NAMES.map(f=>String(l[f])).join(","),R=u(e,l,a,n);return`(function()
2
+ ${(0,p.emitFoldDecoderLua)(a,"D")}
3
+ local ${i}=${c}
4
4
  local function G(u)
5
5
  if u.R then
6
6
  return u.R[u.i]
package/docs/api/hid.md CHANGED
@@ -289,6 +289,27 @@ function setJitterValue(value: number): void;
289
289
  hid.setJitterValue(5);
290
290
  ```
291
291
 
292
+ ### setActionDelay - 设置动作延迟
293
+
294
+ 设置连续点击/滑动之间的等待毫秒。不调用时用固件默认(相对 200ms / 绝对 100ms)。
295
+
296
+ ```typescript
297
+ function setActionDelay(milliseconds: number): boolean;
298
+ ```
299
+
300
+ **参数:**
301
+ | 参数 | 类型 | 必需 | 默认值 | 描述 |
302
+ | ---- | ---- | ---- | ------ | ---- |
303
+ | `milliseconds` | number | 是 | `-1` | `0` 关闭,`>0` 覆盖毫秒,`-1` 恢复默认 |
304
+
305
+ **示例:**
306
+
307
+ ```javascript
308
+ hid.setActionDelay(0);
309
+ hid.click(100, 200);
310
+ hid.click(300, 400);
311
+ ```
312
+
292
313
  ## 基础触摸操作
293
314
 
294
315
  ### click - 点击操作
package/docs/apicn/hid.md CHANGED
@@ -289,6 +289,27 @@ function 设置抖动值(抖动值: 数字): 无返回值;
289
289
  $HID.设置抖动值(5);
290
290
  ```
291
291
 
292
+ ### 设置动作延迟
293
+
294
+ 设置连续点击/滑动之间的等待毫秒。不调用时用固件默认(相对 200ms / 绝对 100ms)。
295
+
296
+ ```typescript
297
+ function 设置动作延迟(毫秒: 数字): 布尔值;
298
+ ```
299
+
300
+ **参数:**
301
+ | 参数 | 类型 | 必需 | 默认值 | 描述 |
302
+ | ---- | ---- | ---- | ------ | ---- |
303
+ | `毫秒` | 数字 | 是 | `-1` | `0` 关闭,`>0` 覆盖毫秒,`-1` 恢复默认 |
304
+
305
+ **示例:**
306
+
307
+ ```javascript
308
+ $HID.设置动作延迟(0);
309
+ $HID.点击(100, 200);
310
+ $HID.点击(300, 400);
311
+ ```
312
+
292
313
  ## 基础触摸操作
293
314
 
294
315
  ### 点击
@@ -258,6 +258,29 @@ function setJitterValue(value) end
258
258
  hid.setJitterValue(5)
259
259
  ```
260
260
 
261
+ ### setActionDelay - 设置动作延迟
262
+
263
+ 设置连续点击/滑动之间的等待毫秒。不调用时用固件默认(相对 200ms / 绝对 100ms)。
264
+
265
+ ```lua
266
+ ---@param milliseconds number
267
+ ---@return boolean
268
+ function setActionDelay(milliseconds) end
269
+ ```
270
+
271
+ **参数:**
272
+ | 参数 | 类型 | 必需 | 默认值 | 描述 |
273
+ | ---- | ---- | ---- | ------ | ---- |
274
+ | `milliseconds` | number | 是 | `-1` | `0` 关闭,`>0` 覆盖毫秒,`-1` 恢复默认 |
275
+
276
+ **示例:**
277
+
278
+ ```lua
279
+ hid.setActionDelay(0)
280
+ hid.click(100, 200)
281
+ hid.click(300, 400)
282
+ ```
283
+
261
284
  ## 基础触摸操作
262
285
 
263
286
  ### click - 点击操作
@@ -298,6 +298,28 @@ from kuaijs import hid
298
298
  hid.setJitterValue(5)
299
299
  ```
300
300
 
301
+ ### setActionDelay - 设置动作延迟
302
+
303
+ 设置连续点击/滑动之间的等待毫秒。不调用时用固件默认(相对 200ms / 绝对 100ms)。
304
+
305
+ ```python
306
+ def setActionDelay(milliseconds: int) -> bool
307
+ ```
308
+
309
+ **参数:**
310
+ | 参数 | 类型 | 必需 | 默认值 | 描述 |
311
+ | ---- | ---- | ---- | ------ | ---- |
312
+ | `milliseconds` | int | 是 | `-1` | `0` 关闭,`>0` 覆盖毫秒,`-1` 恢复默认 |
313
+
314
+ **示例:**
315
+
316
+ ```python
317
+ from kuaijs import hid
318
+ hid.setActionDelay(0)
319
+ hid.click(100, 200)
320
+ hid.click(300, 400)
321
+ ```
322
+
301
323
  ## 基础触摸操作
302
324
 
303
325
  ### click - 点击操作
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-vite-plugin",
3
- "version": "1.4.60",
3
+ "version": "1.4.61",
4
4
  "type": "commonjs",
5
5
  "license": "MIT",
6
6
  "publishConfig": {