@devscholar/vbs-engine-js 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/vbs-engine.js +653 -391
- package/dist/vbs-engine.js.map +1 -1
- package/dist/vbs-engine.umd.cjs +22 -13
- package/dist/vbs-engine.umd.cjs.map +1 -1
- package/package.json +2 -2
package/dist/vbs-engine.umd.cjs
CHANGED
|
@@ -1,25 +1,34 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(L,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(L=typeof globalThis<"u"?globalThis:L||self,u(L.VbsEngine={}))})(this,(function(L){"use strict";var u=(r=>(r.EOF="EOF",r.Newline="Newline",r.WhiteSpace="WhiteSpace",r.Identifier="Identifier",r.Unknown="Unknown",r.StringLiteral="StringLiteral",r.NumberLiteral="NumberLiteral",r.DateLiteral="DateLiteral",r.BooleanLiteral="BooleanLiteral",r.NothingLiteral="NothingLiteral",r.NullLiteral="NullLiteral",r.EmptyLiteral="EmptyLiteral",r.Plus="Plus",r.Minus="Minus",r.Asterisk="Asterisk",r.Slash="Slash",r.Backslash="Backslash",r.Caret="Caret",r.Mod="Mod",r.Ampersand="Ampersand",r.Eq="Eq",r.Lt="Lt",r.Gt="Gt",r.Le="Le",r.Ge="Ge",r.Ne="Ne",r.Is="Is",r.And="And",r.Or="Or",r.Not="Not",r.Xor="Xor",r.Eqv="Eqv",r.Imp="Imp",r.LParen="LParen",r.RParen="RParen",r.LBrace="LBrace",r.RBrace="RBrace",r.LBracket="LBracket",r.RBracket="RBracket",r.Comma="Comma",r.Colon="Colon",r.Dot="Dot",r.Bang="Bang",r.Dim="Dim",r.ReDim="ReDim",r.Preserve="Preserve",r.Public="Public",r.Private="Private",r.Sub="Sub",r.Function="Function",r.End="End",r.Exit="Exit",r.Call="Call",r.Set="Set",r.Let="Let",r.Get="Get",r.If="If",r.Then="Then",r.Else="Else",r.ElseIf="ElseIf",r.For="For",r.To="To",r.Step="Step",r.Next="Next",r.Each="Each",r.In="In",r.Do="Do",r.Loop="Loop",r.While="While",r.Until="Until",r.Select="Select",r.Case="Case",r.On="On",r.Error="Error",r.Resume="Resume",r.Goto="Goto",r.With="With",r.Class="Class",r.Property="Property",r.New="New",r.Const="Const",r.Option="Option",r.Explicit="Explicit",r.ByRef="ByRef",r.ByVal="ByVal",r.Optional="Optional",r.ParamArray="ParamArray",r.Rem="Rem",r.Erase="Erase",r.As="As",r.Integer="Integer",r.Long="Long",r.Single="Single",r.Double="Double",r.Currency="Currency",r.String="String",r.Boolean="Boolean",r.Date="Date",r.Object="Object",r.Variant="Variant",r.Byte="Byte",r))(u||{});const he={dim:u.Dim,redim:u.ReDim,preserve:u.Preserve,public:u.Public,private:u.Private,sub:u.Sub,function:u.Function,end:u.End,exit:u.Exit,call:u.Call,set:u.Set,let:u.Let,get:u.Get,if:u.If,then:u.Then,else:u.Else,elseif:u.ElseIf,for:u.For,to:u.To,step:u.Step,next:u.Next,each:u.Each,in:u.In,do:u.Do,loop:u.Loop,while:u.While,until:u.Until,select:u.Select,case:u.Case,on:u.On,error:u.Error,resume:u.Resume,goto:u.Goto,with:u.With,class:u.Class,property:u.Property,new:u.New,const:u.Const,option:u.Option,explicit:u.Explicit,byref:u.ByRef,byval:u.ByVal,optional:u.Optional,paramarray:u.ParamArray,rem:u.Rem,erase:u.Erase,as:u.As,and:u.And,or:u.Or,not:u.Not,xor:u.Xor,eqv:u.Eqv,imp:u.Imp,is:u.Is,mod:u.Mod,integer:u.Integer,long:u.Long,single:u.Single,double:u.Double,currency:u.Currency,string:u.String,boolean:u.Boolean,date:u.Date,object:u.Object,variant:u.Variant,byte:u.Byte,true:u.BooleanLiteral,false:u.BooleanLiteral,nothing:u.NothingLiteral,null:u.NullLiteral,empty:u.EmptyLiteral};class j{source;pos=0;line=1;column=1;options;constructor(e,t={}){this.source=e,this.options={skipWhitespace:!0,skipNewlines:!1,...t}}get current(){return this.source[this.pos]??""}get peek(){return this.source[this.pos+1]??""}get isEOF(){return this.pos>=this.source.length}getLoc(){return{line:this.line,column:this.column,offset:this.pos}}advance(){const e=this.current;return this.pos++,e===`
|
|
2
2
|
`?(this.line++,this.column=1):this.column++,e}createToken(e,t,s,n){return{type:e,value:t,loc:{start:s,end:this.getLoc()},raw:n}}skipWhitespaceAndLineContinuation(){for(;;){for(;this.current===" "||this.current===" "||this.current==="\r";)this.advance();if(this.current==="_"&&(this.peek===`
|
|
3
3
|
`||this.peek==="\r")){this.advance(),this.peek==="\r"&&this.advance(),this.peek===`
|
|
4
4
|
`&&this.advance(),this.current===`
|
|
5
5
|
`&&this.advance();continue}break}}readString(e){const t=this.getLoc();this.advance();let s="";for(;!this.isEOF;)if(this.current===e)if(this.peek===e)s+=e,this.advance(),this.advance();else break;else{if(this.current===`
|
|
6
6
|
`)break;s+=this.advance()}return this.current===e&&this.advance(),this.createToken(u.StringLiteral,s,t,e+s+e)}readNumber(){const e=this.getLoc();let t="",s=!1,n=!1;if(this.current==="&"&&(this.peek==="h"||this.peek==="H")){for(this.advance(),this.advance();/[0-9a-fA-F]/.test(this.current);)t+=this.advance();const i=parseInt(t,16);return this.createToken(u.NumberLiteral,String(i),e,"&"+(this.source[e.offset+1]==="H"?"H":"h")+t)}if(this.current==="&"&&(this.peek==="o"||this.peek==="O")){for(this.advance(),this.advance();/[0-7]/.test(this.current);)t+=this.advance();const i=parseInt(t,8);return this.createToken(u.NumberLiteral,String(i),e,"&"+(this.source[e.offset+1]==="O"?"O":"o")+t)}for(;/[0-9]/.test(this.current);)t+=this.advance();if(this.current==="."&&/[0-9]/.test(this.peek))for(s=!0,t+=this.advance();/[0-9]/.test(this.current);)t+=this.advance();const a=this.current;if(a==="e"||a==="E"){n=!0,t+=this.advance();const i=this.current;for((i==="+"||i==="-")&&(t+=this.advance());/[0-9]/.test(this.current);)t+=this.advance()}return this.current==="#"&&!s&&!n?this.readDate(e,t):this.createToken(u.NumberLiteral,t,e,t)}readDate(e,t){let s=t??"";for(this.current==="#"&&this.advance();!this.isEOF&&this.current!=="#"&&this.current!==`
|
|
7
|
-
`;)s+=this.advance();return this.current==="#"&&this.advance(),this.createToken(u.DateLiteral,s.trim(),e,"#"+s+"#")}readIdentifier(){const e=this.getLoc();let t="";for(;/[a-zA-Z0-9_]/.test(this.current);)t+=this.advance();const s=t.toLowerCase(),n=
|
|
7
|
+
`;)s+=this.advance();return this.current==="#"&&this.advance(),this.createToken(u.DateLiteral,s.trim(),e,"#"+s+"#")}readIdentifier(){const e=this.getLoc();let t="";for(;/[a-zA-Z0-9_]/.test(this.current);)t+=this.advance();const s=t.toLowerCase(),n=he[s];return n?n===u.BooleanLiteral?this.createToken(u.BooleanLiteral,s,e,t):n===u.NothingLiteral?this.createToken(u.NothingLiteral,"nothing",e,t):n===u.NullLiteral?this.createToken(u.NullLiteral,"null",e,t):n===u.EmptyLiteral?this.createToken(u.EmptyLiteral,"empty",e,t):this.createToken(n,s,e,t):this.createToken(u.Identifier,t,e,t)}readRemComment(){const e=this.getLoc();let t="";for(;!this.isEOF&&this.current!==`
|
|
8
8
|
`;)t+=this.advance();return this.createToken(u.Rem,t,e,t)}readSingleLineComment(){for(;!this.isEOF&&this.current!==`
|
|
9
9
|
`;)this.advance()}nextToken(){for(;!this.isEOF;){if(this.options.skipWhitespace&&this.skipWhitespaceAndLineContinuation(),this.isEOF)return this.createToken(u.EOF,"",this.getLoc());if(this.current===`
|
|
10
10
|
`){const s=this.getLoc();if(this.advance(),this.options.skipNewlines)continue;return this.createToken(u.Newline,`
|
|
11
11
|
`,s,`
|
|
12
|
-
`)}if(this.current==="'"&&this.options.skipWhitespace){this.readSingleLineComment();continue}if(this.current==='"'||this.current==="'")return this.readString(this.current);if(this.current==="#"){const s=this.getLoc();return this.readDate(s)}if(this.current==="&"&&(this.peek==="h"||this.peek==="H"||this.peek==="o"||this.peek==="O"))return this.readNumber();if(/[0-9]/.test(this.current))return this.readNumber();if(this.current==="."&&/[0-9]/.test(this.peek))return this.readNumber();if(/[a-zA-Z_]/.test(this.current)){const s=this.readIdentifier();if(s.type===u.Rem){if(this.options.skipWhitespace){this.readRemComment();continue}return s}return s}const e=this.getLoc(),t=this.current;switch(t){case"+":return this.advance(),this.createToken(u.Plus,"+",e);case"-":return this.advance(),this.createToken(u.Minus,"-",e);case"*":return this.advance(),this.createToken(u.Asterisk,"*",e);case"/":return this.advance(),this.createToken(u.Slash,"/",e);case"\\":return this.advance(),this.createToken(u.Backslash,"\\",e);case"^":return this.advance(),this.createToken(u.Caret,"^",e);case"&":return this.advance(),this.createToken(u.Ampersand,"&",e);case"(":return this.advance(),this.createToken(u.LParen,"(",e);case")":return this.advance(),this.createToken(u.RParen,")",e);case"{":return this.advance(),this.createToken(u.LBrace,"{",e);case"}":return this.advance(),this.createToken(u.RBrace,"}",e);case"[":return this.advance(),this.createToken(u.LBracket,"[",e);case"]":return this.advance(),this.createToken(u.RBracket,"]",e);case",":return this.advance(),this.createToken(u.Comma,",",e);case":":return this.advance(),this.createToken(u.Colon,":",e);case".":return this.advance(),this.createToken(u.Dot,".",e);case"!":return this.advance(),this.createToken(u.Bang,"!",e);case"=":return this.advance(),this.createToken(u.Eq,"=",e);case"<":return this.advance(),this.current===">"?(this.advance(),this.createToken(u.Ne,"<>",e)):this.current==="="?(this.advance(),this.createToken(u.Le,"<=",e)):this.createToken(u.Lt,"<",e);case">":return this.advance(),this.current==="="?(this.advance(),this.createToken(u.Ge,">=",e)):this.createToken(u.Gt,">",e);default:return this.advance(),this.createToken(u.Unknown,t,e)}}return this.createToken(u.EOF,"",this.getLoc())}tokenize(){const e=[];for(;;){const t=this.nextToken();if(e.push(t),t.type===u.EOF)break}return e}}class J extends Error{token;expected;constructor(e,t,s){super(e),this.name="ParseError",this.token=t,s!==void 0&&(this.expected=s)}}class pe{tokens;pos=0;constructor(e){if(e.length===0)throw new Error("ParserState requires at least one token");this.tokens=e}get current(){return this.tokens[this.pos]??this.tokens[0]}get previous(){return this.tokens[this.pos-1]??this.tokens[0]}get isEOF(){return this.current.type==="EOF"}save(){return this.pos}restore(e){this.pos=e}advance(){return this.isEOF||this.pos++,this.previous}peek(e=0){return this.tokens[this.pos+e]??this.tokens[0]}check(e){return this.current.type===e}checkIdentifier(){return this.current.type==="Identifier"}checkAny(...e){return e.includes(this.current.type)}checkNewline(){return this.current.type==="Newline"}match(e){return this.check(e)?this.advance():null}matchAny(...e){return this.checkAny(...e)?this.advance():null}expect(e,t){if(this.check(e))return this.advance();throw new J(t??`Expected ${e}, got ${this.current.type}`,this.current,e)}expectAny(e,t){if(this.checkAny(...e))return this.advance();throw new J(t??`Expected one of ${e.join(", ")}, got ${this.current.type}`,this.current,e)}skipNewlines(){for(;this.match("Newline"););}skipOptionalNewlines(){this.skipNewlines()}skipStatementSeparators(){for(;this.matchAny("Newline","Colon"););}}function he(r){return{line:r.loc.start.line,column:r.loc.start.column}}function fe(r){return{line:r.loc.end.line,column:r.loc.end.column}}function f(r,e){return{start:he(r),end:fe(e)}}class ye{state;constructor(e){this.state=e}parseExpression(){return this.parseAssignment()}parseStatementExpression(){return this.parseStatementAssignment()}parseCallExpression(){return this.parseCall()}parseMemberExpression(){let e=this.parseIdentifierOnly();for(;;)if(this.state.check("Dot")){this.state.advance();const t=this.parsePropertyName();e={type:"MemberExpression",object:e,property:t,computed:!1,optional:!1,loc:f({loc:e.loc},{loc:t.loc})}}else if(this.state.check("Bang")){this.state.advance();const t=this.parsePropertyName();e={type:"MemberExpression",object:e,property:t,computed:!0,optional:!1,loc:f({loc:e.loc},{loc:t.loc})}}else if(this.state.check("LBracket")){this.state.advance();const t=this.parseExpression(),s=this.state.expect("RBracket");e={type:"MemberExpression",object:e,property:t,computed:!0,optional:!1,loc:f({loc:e.loc},s)}}else break;return e}parseIdentifierOnly(){if(this.state.check("Dot"))return this.parseWithMemberExpression();const e=this.state.expect("Identifier");return{type:"Identifier",name:e.value,loc:e.loc}}parseStatementAssignment(){if(this.state.check("Identifier")||this.state.check("Dot")){const e=this.state.save(),t=this.parseCall();if(t.type==="CallExpression")return this.continueStringConcat(t);if(this.state.check("Eq")&&(t.type==="Identifier"||t.type==="MemberExpression")){const s=this.state.advance(),n=this.parseStatementAssignment();return this.createAssignmentExpression(t,"=",n,s)}if((t.type==="Identifier"||t.type==="MemberExpression")&&this.isStatementCallArgumentStart()){const s=this.parseStatementCallArguments(),n={type:"CallExpression",callee:t,arguments:s,optional:!1,loc:f({loc:t.loc},this.state.previous)};return this.continueStringConcat(n)}this.state.restore(e)}return this.parseStringConcat()}continueStringConcat(e){for(;this.state.check("Ampersand");){this.state.advance();const t=this.parseLogicalOr();e={type:"BinaryExpression",operator:"&",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}isStatementCallArgumentStart(){return this.state.checkAny("StringLiteral","NumberLiteral","DateLiteral","BooleanLiteral","NothingLiteral","NullLiteral","EmptyLiteral","Identifier","LParen","New")}parseStatementCallArguments(){const e=[];for(;!this.state.checkAny("Newline","Colon","EOF")&&(e.push(this.parseExpression()),!!this.state.match("Comma")););return e}parseAssignment(){const e=this.parseStringConcat();if(this.state.checkAny("Eq")){const t=this.state.advance(),s=this.parseAssignment();return this.createAssignmentExpression(e,"=",s,t)}return e}createAssignmentExpression(e,t,s,n){return{type:"AssignmentExpression",operator:t,left:e,right:s,loc:f({loc:{start:e.loc.start,end:e.loc.end}},n)}}parseStringConcat(){let e=this.parseLogicalOr();for(;this.state.check("Ampersand");){this.state.advance();const t=this.parseLogicalOr();e={type:"BinaryExpression",operator:"&",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}parseLogicalOr(){let e=this.parseLogicalAnd();for(;this.state.check("Or");){this.state.advance();const t=this.parseLogicalAnd();e={type:"LogicalExpression",operator:"||",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}parseLogicalAnd(){let e=this.parseLogicalNot();for(;this.state.check("And");){this.state.advance();const t=this.parseLogicalNot();e={type:"LogicalExpression",operator:"&&",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}parseLogicalNot(){let e=this.parseComparison();for(;this.state.checkAny("Xor","Eqv","Imp");){const t=this.state.advance(),s=this.parseComparison();e={type:"LogicalExpression",operator:t.value.toLowerCase()==="xor"?"xor":t.value.toLowerCase()==="eqv"?"eqv":"imp",left:e,right:s,loc:f({loc:e.loc},{loc:s.loc})}}return e}parseComparison(){let e=this.parseIs();for(;this.state.checkAny("Eq","Lt","Gt","Le","Ge","Ne");){const t=this.state.advance(),s=this.parseIs();e={type:"BinaryExpression",operator:this.getComparisonOperator(t),left:e,right:s,loc:f({loc:e.loc},{loc:s.loc})}}return e}getComparisonOperator(e){switch(e.type){case"Eq":return"==";case"Lt":return"<";case"Gt":return">";case"Le":return"<=";case"Ge":return">=";case"Ne":return"!=";default:return"=="}}parseIs(){const e=this.parseConcatenation();if(this.state.check("Is")){this.state.advance();const t=this.parseConcatenation();return{type:"BinaryExpression",operator:"Is",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}parseConcatenation(){return this.parseAdditive()}parseAdditive(){let e=this.parseMultiplicative();for(;this.state.checkAny("Plus","Minus");){const t=this.state.advance(),s=this.parseMultiplicative();e={type:"BinaryExpression",operator:t.type==="Plus"?"+":"-",left:e,right:s,loc:f({loc:e.loc},{loc:s.loc})}}return e}parseMultiplicative(){let e=this.parseIntegerDivision();for(;this.state.checkAny("Asterisk","Slash");){const t=this.state.advance(),s=this.parseIntegerDivision();e={type:"BinaryExpression",operator:t.type==="Asterisk"?"*":"/",left:e,right:s,loc:f({loc:e.loc},{loc:s.loc})}}return e}parseIntegerDivision(){let e=this.parseMod();for(;this.state.check("Backslash");){this.state.advance();const t=this.parseMod();e={type:"BinaryExpression",operator:"\\",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}parseMod(){let e=this.parsePower();for(;this.state.check("Mod");){this.state.advance();const t=this.parsePower();e={type:"BinaryExpression",operator:"%",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}parsePower(){let e=this.parseUnary();for(;this.state.check("Caret");){this.state.advance();const t=this.parseUnary();e={type:"BinaryExpression",operator:"**",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}parseUnary(){if(this.state.check("Not")){const e=this.state.advance(),t=this.parseUnary();return{type:"UnaryExpression",operator:"!",prefix:!0,argument:t,loc:f(e,{loc:t.loc})}}if(this.state.check("Minus")){const e=this.state.advance(),t=this.parseUnary();return{type:"UnaryExpression",operator:"-",prefix:!0,argument:t,loc:f(e,{loc:t.loc})}}if(this.state.check("Plus")){const e=this.state.advance(),t=this.parseUnary();return{type:"UnaryExpression",operator:"+",prefix:!0,argument:t,loc:f(e,{loc:t.loc})}}return this.parsePostfix()}parsePostfix(){return this.parseCall()}parseCall(){let e=this.parsePrimary();for(;;)if(this.state.check("Dot")){this.state.advance();const t=this.parsePropertyName();e={type:"MemberExpression",object:e,property:t,computed:!1,optional:!1,loc:f({loc:e.loc},{loc:t.loc})}}else if(this.state.check("Bang")){this.state.advance();const t=this.parsePropertyName();e={type:"MemberExpression",object:e,property:t,computed:!0,optional:!1,loc:f({loc:e.loc},{loc:t.loc})}}else if(this.state.check("LParen")){this.state.advance();const t=this.parseArguments(),s=this.state.expect("RParen");e={type:"CallExpression",callee:e,arguments:t,optional:!1,loc:f({loc:e.loc},s)}}else if(this.state.check("LBracket")){this.state.advance();const t=this.parseExpression(),s=this.state.expect("RBracket");e={type:"MemberExpression",object:e,property:t,computed:!0,optional:!1,loc:f({loc:e.loc},s)}}else break;return e}parseArguments(){const e=[];if(!this.state.check("RParen"))for(;this.state.skipOptionalNewlines(),!this.state.check("RParen");)if(this.state.check("Comma")?e.push({type:"VbEmptyLiteral",value:void 0,raw:"",loc:this.state.current.loc}):e.push(this.parseExpression()),this.state.skipOptionalNewlines(),this.state.check("Comma"))this.state.advance();else break;return e}parsePrimary(){if(this.state.check("LParen"))return this.parseParenExpression();if(this.state.check("StringLiteral"))return this.parseStringLiteral();if(this.state.check("NumberLiteral"))return this.parseNumberLiteral();if(this.state.check("DateLiteral"))return this.parseDateLiteral();if(this.state.check("BooleanLiteral"))return this.parseBooleanLiteral();if(this.state.check("NothingLiteral"))return this.parseNothingLiteral();if(this.state.check("NullLiteral"))return this.parseNullLiteral();if(this.state.check("EmptyLiteral"))return this.parseEmptyLiteral();if(this.state.check("New"))return this.parseNewExpression();if(this.state.check("Dot"))return this.parseWithMemberExpression();if(this.state.check("Identifier"))return this.parseIdentifierOrCall();throw new Error(`Unexpected token: ${this.state.current.type}`)}parseWithMemberExpression(){const e=this.state.advance(),t=this.parsePropertyName();return{type:"MemberExpression",object:{type:"VbWithObject",loc:e.loc},property:t,computed:!1,optional:!1,loc:f(e,{loc:t.loc})}}parseParenExpression(){this.state.advance(),this.state.skipOptionalNewlines();const e=this.parseExpression();return this.state.skipOptionalNewlines(),this.state.expect("RParen"),e}parseStringLiteral(){const e=this.state.advance();return{type:"Literal",value:e.value,raw:e.raw??void 0,loc:e.loc}}parseNumberLiteral(){const e=this.state.advance();return{type:"Literal",value:e.value.includes(".")||e.value.includes("e")||e.value.includes("E")?parseFloat(e.value):parseInt(e.value,10),raw:e.raw??e.value,loc:e.loc}}parseDateLiteral(){const e=this.state.advance();return{type:"Literal",value:new Date(e.value),raw:e.raw??void 0,loc:e.loc}}parseBooleanLiteral(){const e=this.state.advance();return{type:"Literal",value:e.value.toLowerCase()==="true",raw:e.raw??void 0,loc:e.loc}}parseNothingLiteral(){const e=this.state.advance();return{type:"Literal",value:Symbol.for("Nothing"),raw:e.raw??void 0,loc:e.loc}}parseNullLiteral(){const e=this.state.advance();return{type:"Literal",value:null,raw:e.raw??void 0,loc:e.loc}}parseEmptyLiteral(){const e=this.state.advance();return{type:"VbEmptyLiteral",value:void 0,raw:e.raw??void 0,loc:e.loc}}parseNewExpression(){const e=this.state.advance(),t=this.parseIdentifier();let s=[];return this.state.check("LParen")&&(this.state.advance(),s=this.parseArguments(),this.state.expect("RParen")),{type:"VbNewExpression",callee:t,arguments:s,loc:f(e,this.state.previous)}}parseIdentifierOrCall(){const e=this.parseIdentifier();if(this.state.check("LParen")){this.state.advance();const t=this.parseArguments(),s=this.state.expect("RParen");return{type:"CallExpression",callee:e,arguments:t,optional:!1,loc:f({loc:e.loc},s)}}return e}parseIdentifier(){const e=this.state.expect("Identifier");return{type:"Identifier",name:e.value,loc:e.loc}}parsePropertyName(){const e=this.state.current;if(e.type==="Identifier"||e.type!=="EOF"&&e.type!=="Newline"&&e.type!=="LParen"&&e.type!=="RParen"&&e.type!=="Comma"&&e.type!=="Colon")return this.state.advance(),{type:"Identifier",name:e.value,loc:e.loc};throw new Error(`Expected property name, got ${e.type}`)}}class me{constructor(e,t){this.state=e,this.exprParser=t}parseDimStatement(){const e=this.state.advance();return{type:"VbDimStatement",declarations:this.parseVariableDeclarations(),visibility:"dim",loc:f(e,this.state.previous)}}parsePublicDimStatement(){const e=this.state.advance();return this.state.expect("Dim"),{type:"VbDimStatement",declarations:this.parseVariableDeclarations(),visibility:"public",loc:f(e,this.state.previous)}}parsePrivateDimStatement(){const e=this.state.advance();return this.state.expect("Dim"),{type:"VbDimStatement",declarations:this.parseVariableDeclarations(),visibility:"private",loc:f(e,this.state.previous)}}parseReDimStatement(){const e=this.state.advance(),t=this.state.match("Preserve")!==null;return{type:"VbReDimStatement",declarations:this.parseVariableDeclarations(),preserve:t,loc:f(e,this.state.previous)}}parseConstStatement(){const e=this.state.advance();return{type:"VbConstStatement",declarations:this.parseConstDeclarators(),visibility:"private",loc:f(e,this.state.previous)}}parsePublicConstStatement(){const e=this.state.advance();return this.state.expect("Const"),{type:"VbConstStatement",declarations:this.parseConstDeclarators(),visibility:"public",loc:f(e,this.state.previous)}}parsePrivateConstStatement(){const e=this.state.advance();return this.state.expect("Const"),{type:"VbConstStatement",declarations:this.parseConstDeclarators(),visibility:"private",loc:f(e,this.state.previous)}}parseVariableDeclarations(){const e=[];do{const t=this.parseVariableDeclarator();e.push(t)}while(this.state.match("Comma"));return e}parseVariableDeclarator(){const e=this.exprParser.parseIdentifier();let t=null,s=!1,n=[];this.state.check("LParen")&&(this.state.advance(),s=!0,n=this.parseArrayBounds(),this.state.expect("RParen")),this.state.match("Eq")&&(t=this.exprParser.parseExpression());let a;return this.state.check("As")&&(a=this.parseTypeAnnotation()),{type:"VbVariableDeclarator",id:e,init:t,isArray:s,arrayBounds:n.length>0?n:void 0,typeAnnotation:a,loc:f({loc:e.loc},this.state.previous)}}parseArrayBounds(){const e=[];do this.state.skipOptionalNewlines(),e.push(this.exprParser.parseExpression()),this.state.skipOptionalNewlines();while(this.state.match("Comma"));return e}parseTypeAnnotation(){this.state.expect("As");const e=this.state.current;let t="",s=!1;return this.state.checkAny("Integer","Long","Single","Double","Currency","String","Boolean","Date","Object","Variant","Byte","Identifier")&&(t=this.state.advance().value),this.state.check("LParen")&&(this.state.advance(),s=!0,this.state.expect("RParen")),{type:"VbTypeAnnotation",typeName:t,isArray:s,loc:f(e,this.state.previous)}}parseConstDeclarators(){const e=[];do{const t=this.parseConstDeclarator();e.push(t)}while(this.state.match("Comma"));return e}parseConstDeclarator(){const e=this.exprParser.parseIdentifier();this.state.expect("Eq");const t=this.exprParser.parseExpression();let s;return this.state.check("As")&&(s=this.parseTypeAnnotation()),{type:"VbConstDeclarator",id:e,init:t,typeAnnotation:s,loc:f({loc:e.loc},this.state.previous)}}}function ge(r){return["VbSubStatement","VbFunctionStatement","VbPropertyGetStatement","VbPropertyLetStatement","VbPropertySetStatement","VbDimStatement","VbConstStatement"].includes(r.type)}class be{constructor(e,t,s){this.state=e,this.exprParser=t,this.parseStatement=s}parseSubStatement(e){const t=this.state.current;this.state.expect("Sub");const s=this.exprParser.parseIdentifier(),n=this.parseParameters();this.state.skipNewlines();const a=this.parseBlock("End");return this.state.expect("End"),this.state.expect("Sub"),{type:"VbSubStatement",name:s,params:n,body:a,visibility:e??"public",loc:f(t,this.state.previous)}}parseFunctionStatement(e){const t=this.state.current;this.state.expect("Function");const s=this.exprParser.parseIdentifier(),n=this.parseParameters();this.state.skipNewlines();const a=this.parseBlock("End");return this.state.expect("End"),this.state.expect("Function"),{type:"VbFunctionStatement",name:s,params:n,body:a,visibility:e??"public",loc:f(t,this.state.previous)}}parseClassStatement(){const e=this.state.advance(),t=this.exprParser.parseIdentifier();this.state.skipNewlines();const s=this.parseClassBody();return this.state.expect("End"),this.state.expect("Class"),{type:"VbClassStatement",name:t,body:s,loc:f(e,this.state.previous)}}parsePropertyStatement(e){this.state.expect("Property");const t=e??"public";if(this.state.check("Get"))return this.parsePropertyGet(t);if(this.state.check("Let"))return this.parsePropertyLet(t);if(this.state.check("Set"))return this.parsePropertySet(t);throw new Error("Expected Get, Let, or Set after Property")}parsePropertyGet(e){this.state.expect("Get");const t=this.exprParser.parseIdentifier(),s=this.parseParameters();this.state.skipNewlines();const n=this.parseBlock("End");return this.state.expect("End"),this.state.expect("Property"),{type:"VbPropertyGetStatement",name:t,params:s,body:n,visibility:e,loc:f(this.state.previous,this.state.previous)}}parsePropertyLet(e){this.state.expect("Let");const t=this.exprParser.parseIdentifier(),s=this.parseParameters();this.state.skipNewlines();const n=this.parseBlock("End");return this.state.expect("End"),this.state.expect("Property"),{type:"VbPropertyLetStatement",name:t,params:s,body:n,visibility:e,loc:f(this.state.previous,this.state.previous)}}parsePropertySet(e){this.state.expect("Set");const t=this.exprParser.parseIdentifier(),s=this.parseParameters();this.state.skipNewlines();const n=this.parseBlock("End");return this.state.expect("End"),this.state.expect("Property"),{type:"VbPropertySetStatement",name:t,params:s,body:n,visibility:e,loc:f(this.state.previous,this.state.previous)}}parseParameters(){const e=[];if(!this.state.check("LParen"))return e;if(this.state.advance(),!this.state.check("RParen"))do{this.state.skipOptionalNewlines();const t=this.parseParameter();e.push(t),this.state.skipOptionalNewlines()}while(this.state.match("Comma"));return this.state.expect("RParen"),e}parseParameter(){let e=!0,t=!1,s=!1;this.state.check("Optional")&&(this.state.advance(),t=!0),this.state.check("ParamArray")&&(this.state.advance(),s=!0),this.state.check("ByRef")?(this.state.advance(),e=!0):this.state.check("ByVal")&&(this.state.advance(),e=!1);const n=this.exprParser.parseIdentifier();let a=!1,i;return this.state.check("LParen")&&(this.state.advance(),a=!0,this.state.expect("RParen")),this.state.match("Eq")&&(i=this.exprParser.parseExpression()),{type:"VbParameter",name:n,byRef:e,isArray:a,defaultValue:i,isOptional:t,isParamArray:s,loc:f({loc:n.loc},this.state.previous)}}parseBlock(e){const t=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!(e&&this.state.check(e)||this.state.isEOF));){const s=this.parseStatement();t.push(s)}return{type:"BlockStatement",body:t}}parseClassBody(){const e=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!(this.state.check("End")||this.state.isEOF));){const t=this.parseStatement();ge(t)&&e.push(t)}return e}}class ve{constructor(e,t,s){this.state=e,this.exprParser=t,this.parseStatement=s}parseIfStatement(){const e=this.state.advance(),t=this.exprParser.parseExpression();this.state.skipOptionalNewlines(),this.state.expect("Then");const s=this.state.checkNewline();if(this.state.skipOptionalNewlines(),s)return this.parseMultiLineIf(e,t);const n=this.parseSingleLineIfBody();let a=null;return this.state.check("Else")&&(this.state.advance(),a=this.parseSingleLineIfBody()),this.state.check("End")&&(this.state.advance(),this.state.expect("If")),{type:"IfStatement",test:t,consequent:n,alternate:a,loc:f(e,this.state.previous)}}parseMultiLineIf(e,t){this.state.skipNewlines();const s=this.parseIfBlock();let n=null;return this.state.check("ElseIf")?n=this.parseElseIfStatement():this.state.check("Else")&&(this.state.advance(),this.state.skipNewlines(),n=this.parseIfBlock()),this.state.expect("End"),this.state.expect("If"),{type:"IfStatement",test:t,consequent:s,alternate:n,loc:f(e,this.state.previous)}}parseForStatement(){const e=this.state.advance();return this.state.check("Each")?this.parseForEachStatement(e):this.parseForToStatement(e)}parseDoStatement(){const e=this.state.advance();let t=null,s=null;this.state.check("While")?(this.state.advance(),t=this.exprParser.parseExpression(),s="while-do"):this.state.check("Until")&&(this.state.advance(),t=this.exprParser.parseExpression(),s="until-do"),this.state.skipNewlines();const n=this.parseDoBody();return this.state.check("While")?(this.state.advance(),t=this.exprParser.parseExpression(),s="do-while"):this.state.check("Until")&&(this.state.advance(),t=this.exprParser.parseExpression(),s="do-until"),this.state.expect("Loop"),{type:"VbDoLoopStatement",body:n,test:t,testPosition:s,loc:f(e,this.state.previous)}}parseWhileStatement(){const e=this.state.advance(),t=this.exprParser.parseExpression();this.state.skipNewlines();const s=this.parseWhileBody();return{type:"WhileStatement",test:t,body:s,loc:f(e,this.state.previous)}}parseSelectStatement(){const e=this.state.advance();this.state.expect("Case");const t=this.exprParser.parseExpression();this.state.skipNewlines();const s=this.parseCaseClauses();return this.state.expect("End"),this.state.expect("Select"),{type:"VbSelectCaseStatement",discriminant:t,cases:s,loc:f(e,this.state.previous)}}parseSingleLineIfBody(){const e=[];for(;!this.state.isEOF&&!(this.state.checkNewline()||this.state.check("Else")||this.state.check("ElseIf")||this.state.check("End"));){const t=this.parseStatement();e.push(t)}return{type:"BlockStatement",body:e}}parseIfBlock(){const e=[];let t=0;for(;!this.state.isEOF;){if(this.state.skipStatementSeparators(),this.state.check("If")){const n=this.state.save();for(this.state.advance();!this.state.isEOF&&!this.state.check("Then");)this.state.advance();if(this.state.check("Then"))if(this.state.advance(),!this.state.checkNewline()){this.state.restore(n);const i=this.parseStatement();e.push(i);continue}else{for(this.state.restore(n),this.state.advance();!this.state.isEOF&&!this.state.check("Then");)this.state.advance();this.state.advance(),t++;continue}this.state.restore(n)}if(this.state.check("End")){const n=this.state.save();if(this.state.advance(),this.state.check("If")){if(t>0){t--,this.state.restore(n);const a=this.parseStatement();e.push(a);continue}this.state.restore(n);break}this.state.restore(n)}if(this.state.checkAny("Else","ElseIf")){if(t>0){const n=this.parseStatement();e.push(n);continue}break}if(this.state.isEOF)break;const s=this.parseStatement();e.push(s)}return{type:"BlockStatement",body:e}}parseElseIfStatement(){this.state.advance();const e=this.exprParser.parseExpression();this.state.skipOptionalNewlines(),this.state.expect("Then"),this.state.skipNewlines();const t=this.parseIfBlock();let s=null;return this.state.check("ElseIf")?s=this.parseElseIfStatement():this.state.check("Else")&&(this.state.advance(),this.state.skipNewlines(),s=this.parseIfBlock()),{type:"IfStatement",test:e,consequent:t,alternate:s,loc:f(this.state.previous,this.state.previous)}}parseForToStatement(e){const t=this.exprParser.parseIdentifier();this.state.expect("Eq");const s=this.exprParser.parseExpression();this.state.expect("To");const n=this.exprParser.parseExpression();let a=null;this.state.match("Step")&&(a=this.exprParser.parseExpression()),this.state.skipNewlines();const i=this.parseForBody();return{type:"VbForToStatement",left:t,init:s,to:n,step:a,body:i,loc:f(e,this.state.previous)}}parseForEachStatement(e){this.state.expect("Each");const t=this.exprParser.parseIdentifier();this.state.expect("In");const s=this.exprParser.parseExpression();this.state.skipNewlines();const n=this.parseForBody();return{type:"VbForEachStatement",left:t,right:s,body:n,loc:f(e,this.state.previous)}}parseForBody(){const e=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!(this.state.check("Next")||this.state.isEOF));){const t=this.parseStatement();e.push(t)}return this.state.expect("Next"),this.state.check("Identifier")&&this.state.advance(),{type:"BlockStatement",body:e}}parseDoBody(){const e=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!(this.state.checkAny("Loop","While","Until")||this.state.isEOF));){const t=this.parseStatement();e.push(t)}return{type:"BlockStatement",body:e}}parseWhileBody(){const e=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!(this.state.check("Wend")||this.state.isEOF));){const t=this.parseStatement();e.push(t)}return this.state.expect("Wend"),{type:"BlockStatement",body:e}}parseCaseClauses(){const e=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!this.state.check("End"));)if(this.state.check("Case")){const t=this.parseCaseClause();e.push(t)}else break;return e}parseCaseClause(){const e=this.state.advance();let t=null,s=!1;this.state.check("Else")?(this.state.advance(),s=!0):t=this.parseCaseExpressions(),this.state.skipNewlines();const n=this.parseCaseBody();return{type:"VbCaseClause",test:t,consequent:n,isElse:s,loc:f(e,this.state.previous)}}parseCaseExpressions(){const e=[];do if(this.state.check("Is")){this.state.advance();const t=this.state.advance(),s=this.exprParser.parseExpression();e.push({type:"BinaryExpression",operator:this.getComparisonOperator(t),left:{type:"Identifier",name:"__select_expr__"},right:s})}else e.push(this.exprParser.parseExpression());while(this.state.match("Comma"));return e.length===1?e[0]:e}getComparisonOperator(e){return{Eq:"==",Lt:"<",Gt:">",Le:"<=",Ge:">=",Ne:"!="}[e.type]??"=="}parseCaseBody(){const e=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!(this.state.check("Case")||this.state.check("End")||this.state.isEOF));){const t=this.parseStatement();e.push(t)}return e}}class de{constructor(e,t,s){this.state=e,this.exprParser=t,this.parseStatement=s}parseWithStatement(){const e=this.state.advance(),t=this.exprParser.parseExpression();this.state.skipNewlines();const s=this.parseWithBody();return this.state.expect("End"),this.state.expect("With"),{type:"VbWithStatement",object:t,body:s,loc:f(e,this.state.previous)}}parseExitStatement(){const e=this.state.advance(),t={Sub:"Sub",Function:"Function",Property:"Property",Do:"Do",For:"For",Select:"Select"},s=this.state.current,n=t[s.type];return n&&this.state.advance(),{type:"VbExitStatement",target:n??"Sub",loc:f(e,this.state.previous)}}parseOptionStatement(){const e=this.state.advance();return this.state.expect("Explicit"),{type:"VbOptionExplicitStatement",loc:f(e,this.state.previous)}}parseCallStatement(){const e=this.state.advance(),t=this.exprParser.parseMemberExpression();let s=[];return this.state.check("LParen")?(this.state.advance(),s=this.parseCallArguments(),this.state.expect("RParen")):this.state.checkAny("Newline","Colon","EOF")||(s=this.parseCallArgumentsNoParens()),{type:"VbCallStatement",callee:t,arguments:s,loc:f(e,this.state.previous)}}parseSetStatement(){const e=this.state.advance(),t=this.exprParser.parseCallExpression();this.state.expect("Eq");const s=this.exprParser.parseExpression();return{type:"ExpressionStatement",expression:{type:"AssignmentExpression",operator:"=",left:t,right:s,isSet:!0,loc:f(e,this.state.previous)},loc:f(e,this.state.previous)}}parseOnStatement(){const e=this.state.advance();if(this.state.expect("Error"),this.state.match("Resume"))return this.state.expect("Next"),{type:"VbOnErrorHandlerStatement",action:"resume_next",loc:f(e,this.state.previous)};if(this.state.match("Goto")){if(this.state.check("NumberLiteral")){const s=this.state.advance();if(String(s.value)==="0")return{type:"VbOnErrorHandlerStatement",action:"goto_0",loc:f(e,this.state.previous)}}return{type:"VbOnErrorHandlerStatement",action:"goto_label",label:this.exprParser.parseIdentifier(),loc:f(e,this.state.previous)}}throw new Error("Expected Resume Next or Goto after On Error")}parseResumeStatement(){const e=this.state.advance();return this.state.match("Next")?{type:"VbResumeStatement",target:"next",loc:f(e,this.state.previous)}:{type:"VbResumeStatement",target:null,loc:f(e,this.state.previous)}}parseExpressionStatement(){const e=this.exprParser.parseStatementExpression();return{type:"ExpressionStatement",expression:e,loc:e.loc}}parseWithBody(){const e=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!(this.state.check("End")&&this.state.peek(1).type==="With"||this.state.isEOF));){const t=this.parseStatement();e.push(t)}return{type:"BlockStatement",body:e}}parseCallArguments(){const e=[];if(!this.state.check("RParen"))for(;this.state.skipOptionalNewlines(),!this.state.check("RParen");)if(this.state.check("Comma")?e.push({type:"VbEmptyLiteral",value:void 0,raw:"",loc:this.state.current.loc}):e.push(this.exprParser.parseExpression()),this.state.skipOptionalNewlines(),this.state.check("Comma"))this.state.advance();else break;return e}parseCallArgumentsNoParens(){const e=[];for(;!this.state.checkAny("Newline","Colon","EOF")&&(e.push(this.exprParser.parseExpression()),!!this.state.match("Comma")););return e}}class Se{state;exprParser;declarationParser;procedureParser;controlFlowParser;statementsParser;constructor(e){this.state=e,this.exprParser=new ye(e),this.declarationParser=new me(e,this.exprParser),this.procedureParser=new be(e,this.exprParser,()=>this.parseStatement()),this.controlFlowParser=new ve(e,this.exprParser,()=>this.parseStatement()),this.statementsParser=new de(e,this.exprParser,()=>this.parseStatement())}parseStatement(){switch(this.state.skipNewlines(),this.state.current.type){case"Dim":return this.declarationParser.parseDimStatement();case"ReDim":return this.declarationParser.parseReDimStatement();case"Const":return this.declarationParser.parseConstStatement();case"Public":return this.parseVisibilityStatement();case"Private":return this.parseVisibilityStatement();case"Sub":return this.procedureParser.parseSubStatement();case"Function":return this.procedureParser.parseFunctionStatement();case"Class":return this.procedureParser.parseClassStatement();case"Property":return this.procedureParser.parsePropertyStatement();case"If":return this.controlFlowParser.parseIfStatement();case"For":return this.controlFlowParser.parseForStatement();case"Do":return this.controlFlowParser.parseDoStatement();case"While":return this.controlFlowParser.parseWhileStatement();case"Select":return this.controlFlowParser.parseSelectStatement();case"With":return this.statementsParser.parseWithStatement();case"Exit":return this.statementsParser.parseExitStatement();case"Option":return this.statementsParser.parseOptionStatement();case"Call":return this.statementsParser.parseCallStatement();case"Set":return this.statementsParser.parseSetStatement();case"On":return this.statementsParser.parseOnStatement();case"Resume":return this.statementsParser.parseResumeStatement();case"Goto":return this.parseGotoStatement();case"Colon":return this.state.advance(),this.parseStatement();default:return this.state.checkIdentifier()&&this.state.peek(1).type==="Colon"?this.parseLabelStatement():this.statementsParser.parseExpressionStatement()}}parseGotoStatement(){const e=this.state.advance();return{type:"VbGotoStatement",label:this.exprParser.parseIdentifier(),loc:f(e,this.state.previous)}}parseLabelStatement(){const e=this.state.advance();return this.state.expect("Colon"),{type:"VbLabelStatement",label:{type:"Identifier",name:e.value,loc:e.loc},loc:f(e,this.state.previous)}}parseVisibilityStatement(){const e=this.state.advance(),t=e.type==="Public"?"public":"private";if(this.state.check("Dim"))return this.declarationParser.parsePublicDimStatement();if(this.state.check("Const"))return t==="public"?this.declarationParser.parsePublicConstStatement():this.declarationParser.parsePrivateConstStatement();if(this.state.check("Sub"))return this.procedureParser.parseSubStatement(t);if(this.state.check("Function"))return this.procedureParser.parseFunctionStatement(t);if(this.state.check("Property"))return this.procedureParser.parsePropertyStatement(t);if(this.state.checkIdentifier())return{type:"VbDimStatement",declarations:this.declarationParser.parseVariableDeclarations(),visibility:t,loc:{start:e.loc.start,end:this.state.previous.loc.end}};throw new Error(`Expected Dim, Const, Sub, Function, or Property after ${t}`)}}class j{state;stmtParser;constructor(e){this.state=new pe(e),this.stmtParser=new Se(this.state)}parse(){const e=[];for(;!this.state.isEOF&&(this.state.skipNewlines(),!this.state.isEOF);){const s=this.stmtParser.parseStatement();e.push(s)}const t=this.state.current;return{type:"Program",body:e,sourceType:"script",loc:{start:{line:1,column:0},end:t.loc.end}}}}function T(r,e){const s=new F(r).tokenize();return new j(s).parse()}const m={type:"Empty",value:void 0},N={type:"Null",value:null},we={type:"Object",value:null};function C(r){return r===void 0?m:r===null?N:r===Symbol.for("Nothing")?we:typeof r=="boolean"?{type:"Boolean",value:r}:typeof r=="number"?Number.isInteger(r)?r>=-32768&&r<=32767?{type:"Integer",value:r}:{type:"Long",value:r}:{type:"Double",value:r}:typeof r=="string"?{type:"String",value:r}:r instanceof Date?{type:"Date",value:r}:Array.isArray(r)?{type:"Array",value:r}:typeof r=="object"?{type:"Object",value:r}:{type:"Variant",value:r}}function d(r){if(r.type==="Boolean")return r.value;if(r.type==="Empty")return!1;if(r.type==="Null")throw new Error("Type mismatch: Null cannot be converted to Boolean");if(r.type==="String"){const e=r.value;if(e==="")return!1;const t=parseFloat(e);return isNaN(t)?e.toLowerCase()!=="false":t!==0}return r.type==="Integer"||r.type==="Long"||r.type==="Double"||r.type==="Single"||r.type==="Byte"?r.value!==0:!0}function c(r){if(r.type==="Empty")return 0;if(r.type==="Null")throw new Error("Type mismatch: Null cannot be converted to Number");if(r.type==="Boolean")return r.value?-1:0;if(r.type==="Integer"||r.type==="Long"||r.type==="Double"||r.type==="Single"||r.type==="Byte"||r.type==="Currency")return r.value;if(r.type==="String"){const e=r.value.trim();if(e==="")return 0;const t=parseFloat(e);if(isNaN(t))throw new Error(`Type mismatch: "${e}" cannot be converted to Number`);return t}if(r.type==="Date")return r.value.getTime();throw new Error(`Type mismatch: ${r.type} cannot be converted to Number`)}function y(r){return r.type==="Empty"?"":r.type==="Null"?"Null":r.type==="Boolean"?r.value?"True":"False":r.type==="String"?r.value:r.type==="Integer"||r.type==="Long"||r.type==="Byte"?String(Math.floor(r.value)):r.type==="Double"||r.type==="Single"||r.type==="Currency"?String(r.value):r.type==="Date"?r.value.toLocaleString():r.type==="Object"?r.value===null?"Nothing":"[object]":r.type==="Array"?"[array]":String(r.value)}function xe(r){if(r.type==="Integer"||r.type==="Long"||r.type==="Double"||r.type==="Single"||r.type==="Currency"||r.type==="Byte")return!0;if(r.type==="String"){const e=r.value.trim();return e===""?!1:!isNaN(parseFloat(e))}return r.type==="Boolean"||r.type==="Empty"}function Ee(r){return r.type==="Empty"}function Ce(r){return r.type==="Null"}class ke{constructor(e,t,s=!1,n=!1,a=!1){this.name=e,this.value=t,this.isByRef=s,this.isArray=n,this.isConst=a}}class X{variables=new Map;parent;constructor(e=null){this.parent=e}declare(e,t,s={}){const n=new ke(e,t,s.isByRef??!1,s.isArray??!1,s.isConst??!1);return this.variables.set(e.toLowerCase(),n),n}get(e){const t=e.toLowerCase(),s=this.variables.get(t);if(s)return s;if(this.parent)return this.parent.get(e)}set(e,t){const s=e.toLowerCase(),n=this.variables.get(s);if(n){if(n.isConst)throw new Error(`Cannot assign to constant '${e}'`);n.value=t;return}if(this.parent){this.parent.set(e,t);return}this.declare(e,t)}has(e){const t=e.toLowerCase();return this.variables.has(t)?!0:this.parent?this.parent.has(e):!1}getParent(){return this.parent}getAllVariables(){const e=new Map;return this.parent&&this.parent.getAllVariables().forEach((s,n)=>e.set(n,s)),this.variables.forEach((t,s)=>e.set(s,t)),e}}class Le{functions=new Map;register(e,t,s={}){const n=e.toLowerCase();this.functions.set(n,{name:e,func:t,isSub:s.isSub??!1,minArgs:s.minArgs??0,maxArgs:s.maxArgs??1/0,params:s.params??[],isUserDefined:s.isUserDefined??!1})}get(e){return this.functions.get(e.toLowerCase())}has(e){return this.functions.has(e.toLowerCase())}call(e,t){const s=this.functions.get(e.toLowerCase());if(!s)throw new Error(`Undefined function or sub: ${e}`);if(t.length<s.minArgs)throw new Error(`${e} requires at least ${s.minArgs} argument(s)`);if(t.length>s.maxArgs)throw new Error(`${e} accepts at most ${s.maxArgs} argument(s)`);let n;return s.isUserDefined?n=s.func(t):n=s.func(...t),s.isSub?m:n??m}callWithRefs(e,t){const s=this.functions.get(e.toLowerCase());if(!s)throw new Error(`Undefined function or sub: ${e}`);if(t.length<s.minArgs)throw new Error(`${e} requires at least ${s.minArgs} argument(s)`);if(t.length>s.maxArgs)throw new Error(`${e} accepts at most ${s.maxArgs} argument(s)`);const n=t.map(i=>i.value);let a;s.isUserDefined?a=s.func(n):a=s.func(...n);for(let i=0;i<t.length&&i<s.params.length;i++){const o=s.params[i],l=t[i];o&&l&&o.byRef&&l.setValue&&n[i]!==l.value&&l.setValue(n[i])}return s.isSub?m:a??m}getAll(){return this.functions.entries()}getUserDefinedFunctions(){const e=new Map;for(const[t,s]of this.functions.entries())s.isUserDefined&&e.set(t,s);return e}}class Z{constructor(e,t=new Map,s=new Map,n){this.name=e,this.properties=t,this.methods=s,this.initializer=n}}class Q{constructor(e,t=null){this.classInfo=e,this.prototype=t,e.initializer&&e.initializer(this),e.properties.forEach((s,n)=>{this.propertyAccessors.set(n.toLowerCase(),s),!s.get&&!s.let&&!s.set&&this.properties.set(n.toLowerCase(),m)})}properties=new Map;propertyAccessors=new Map;getProperty(e){const t=e.toLowerCase(),s=this.propertyAccessors.get(t);if(s?.get)return s.get.call(this);if(s&&!s.get&&!s.let&&!s.set){const a=this.properties.get(t);if(a!==void 0)return a}const n=this.properties.get(t);return n!==void 0?n:this.prototype?this.prototype.getProperty(e):m}setProperty(e,t,s=!1){const n=e.toLowerCase(),a=this.propertyAccessors.get(n);if(a){if(s&&a.set){a.set.call(this,t);return}if(!s&&a.let){a.let.call(this,t);return}if(!a.get&&!a.let&&!a.set){this.properties.set(n,t);return}}this.properties.set(n,t)}hasProperty(e){const t=e.toLowerCase();return this.properties.has(t)||this.propertyAccessors.has(t)||(this.prototype?.hasProperty(e)??!1)}getMethod(e){return this.classInfo.methods.get(e.toLowerCase())}hasMethod(e){return this.classInfo.methods.has(e.toLowerCase())}setPropertiesFromObject(e){for(const[t,s]of Object.entries(e))this.properties.set(t.toLowerCase(),s)}}class Ie{classes=new Map;register(e){this.classes.set(e.name.toLowerCase(),e)}registerClass(e,t){const s=new Z(e);s.initializer=n=>{const a=t();if(a.type==="Object"&&a.value){const i=a.value;n.setPropertiesFromObject(i)}},this.classes.set(e.toLowerCase(),s)}get(e){return this.classes.get(e.toLowerCase())}has(e){return this.classes.has(e.toLowerCase())}createInstance(e,t){const s=this.classes.get(e.toLowerCase());if(!s)throw new Error(`Undefined class: ${e}`);const n=new Q(s),a=s.methods.get("class_initialize");a&&a.func.call(n);const i=s.properties.get("class_initialize");return i&&i.get&&i.get.call(n),n}}class ee{data;dimensions;lowerBounds;constructor(e,t){this.dimensions=e,this.lowerBounds=t??e.map(()=>0);const s=e.reduce((n,a)=>n*a,1);this.data=new Array(s).fill(m)}getIndex(e){if(e.length!==this.dimensions.length)throw new Error(`Array has ${this.dimensions.length} dimension(s), but ${e.length} index(es) provided`);let t=0,s=1;for(let n=this.dimensions.length-1;n>=0;n--){const a=this.lowerBounds[n],i=this.dimensions[n],o=e[n]-a;if(o<0||o>=i)throw new Error("Subscript out of range");t+=o*s,s*=i}return t}get(e){return this.data[this.getIndex(e)]??m}set(e,t){this.data[this.getIndex(e)]=t}getDimensions(){return this.dimensions.length}getBounds(e){if(e<1||e>this.dimensions.length)throw new Error("Invalid dimension");const t=e-1,s=this.lowerBounds[t],n=this.dimensions[t];return{lower:s,upper:s+n-1}}redim(e,t){const s=new Array(e.reduce((n,a)=>n*a,1)).fill(m);if(t){const n=Math.min(this.data.length,s.length);for(let a=0;a<n;a++)s[a]=this.data[a]}this.dimensions=e,this.data=s}toArray(){return[...this.data]}}function W(r){const e=r.map(t=>t+1);return new ee(e)}function G(r){const e=new ee([r.length]);return r.forEach((t,s)=>e.set([s],t)),e}class P extends Error{number;source;description;helpFile;helpContext;constructor(e,t,s=""){super(t),this.name="VbError",this.number=e,this.source=s,this.description=t}static fromError(e){return e instanceof P?e:new P(440,e.message,"Vbscript")}}const w={TypeMismatch:13,DivisionByZero:11,InvalidProcedureCall:5,ObjectRequired:424};function x(r,e,t){return new P(r,e,t)}function te(r,e){return r===void 0?{type:"Empty",value:void 0}:r===null?{type:"Null",value:null}:typeof r=="boolean"?{type:"Boolean",value:r}:typeof r=="number"?Number.isInteger(r)&&r>=-2147483648&&r<=2147483647?{type:"Long",value:r}:{type:"Double",value:r}:typeof r=="string"?{type:"String",value:r}:r instanceof Date?{type:"Date",value:r}:Array.isArray(r)?{type:"Array",value:r}:typeof r=="function"?{type:"Object",value:{type:"jsfunction",func:r,thisArg:e??null}}:typeof r=="object"?{type:"Object",value:r}:{type:"String",value:String(r)}}class Ne{globalScope;currentScope;functionRegistry;classRegistry;optionExplicit=!1;onErrorResumeNext=!1;lastError=null;err={number:0,description:"",source:""};currentInstance=null;inPropertyGet=!1;propertyGetName="";evaluate=null;checkTimeout=null;execute=null;executeGlobal=null;withStack=[];callStack=[];exitFlag="none";constructor(){this.globalScope=new X,this.currentScope=this.globalScope,this.functionRegistry=new Le,this.classRegistry=new Ie}pushScope(){const e=new X(this.currentScope);return this.currentScope=e,e}popScope(){this.currentScope.parent&&(this.currentScope=this.currentScope.parent)}pushWith(e){this.withStack.push(e)}popWith(){this.withStack.pop()}getCurrentWith(){return this.withStack[this.withStack.length-1]}pushCall(e){this.callStack.push(e)}popCall(){this.callStack.pop()}getCurrentCall(){return this.callStack[this.callStack.length-1]}setExitFlag(e){this.exitFlag=e}getExitFlag(){return this.exitFlag}clearExitFlag(){this.exitFlag="none"}setError(e){this.lastError=e,this.err.number=e.number,this.err.description=e.description,this.err.source=e.source}clearError(){this.lastError=null,this.err.number=0,this.err.description="",this.err.source=""}declareVariable(e,t=m){this.currentScope.declare(e,t)}getVariable(e){if(this.currentInstance&&this.currentInstance.hasProperty(e))return this.currentInstance.getProperty(e);const t=this.currentScope.get(e);if(t)return t.value;const s=e.toLowerCase();for(const a of Object.keys(globalThis))if(a.toLowerCase()===s){const i=globalThis[a];return te(i,globalThis)}const n=["eval","parseInt","parseFloat","isNaN","isFinite","decodeURI","decodeURIComponent","encodeURI","encodeURIComponent","escape","unescape"];for(const a of n)if(a.toLowerCase()===s&&a in globalThis){const i=globalThis[a];return te(i,globalThis)}if(this.optionExplicit)throw new P(500,`Variable is undefined: '${e}'`,"Vbscript");return m}setVariable(e,t){if(this.inPropertyGet&&e.toLowerCase()===this.propertyGetName){this.currentScope.set(e,t);return}if(this.currentInstance&&this.currentInstance.hasProperty(e)){this.currentInstance.setProperty(e,t);return}if(this.optionExplicit&&!this.currentScope.has(e)&&!(e.toLowerCase()in globalThis))throw new P(500,`Variable is undefined: '${e}'`,"Vbscript");this.currentScope.set(e,t)}hasVariable(e){return this.currentScope.has(e)?!0:e.toLowerCase()in globalThis}}function Pe(r){return r.type==="method"&&"object"in r&&"method"in r}function De(r){return r.type==="jsfunction"&&"func"in r}class re{constructor(e){this.context=e}evaluateProgram(e){let t=m;for(const s of e.body)s.type==="ExpressionStatement"?t=this.evaluate(s.expression):t=this.evaluate(s);return t}evaluate(e){switch(e.type){case"Identifier":return this.evaluateIdentifier(e);case"Literal":return this.evaluateLiteral(e);case"VbEmptyLiteral":return m;case"VbNewExpression":return this.evaluateNew(e);case"ThisExpression":return this.evaluateMe(e);case"VbWithObject":return this.evaluateWithObject(e);case"MemberExpression":return this.evaluateMember(e);case"CallExpression":return this.evaluateCallInternal(e.callee,e.arguments);case"BinaryExpression":return this.evaluateBinary(e);case"UnaryExpression":return this.evaluateUnary(e);case"LogicalExpression":return this.evaluateLogical(e);case"AssignmentExpression":return this.evaluateAssignment(e);case"ConditionalExpression":return this.evaluateConditional(e);default:return m}}evaluateCall(e,t){return this.evaluateCallInternal(e,t)}evaluateIdentifier(e){const t=e.name;return this.context.functionRegistry.has(t)?this.context.functionRegistry.call(t,[]):this.context.getVariable(t)}evaluateLiteral(e){return C(e.value)}evaluateNew(e){const t=e.callee.name,s=e.arguments.map(a=>this.evaluate(a));return{type:"Object",value:this.context.classRegistry.createInstance(t,s)}}evaluateMe(e){if(this.context.currentInstance)return{type:"Object",value:this.context.currentInstance};throw new Error("Me keyword not supported outside of class context")}evaluateWithObject(e){const t=this.context.getCurrentWith();if(!t)throw new Error("With object not available - must be inside a With statement");return t}evaluateMember(e){let t=this.evaluate(e.object);e.object.type==="VbWithObject"&&(t=this.evaluateWithObject(e.object));let s;if(e.computed){const n=this.evaluate(e.property);s=y(n)}else s=e.property.name;if(t.type==="Array")return this.getArrayElement(t,e.property);if(t.type==="Object")return this.getObjectProperty(t,s);throw x(w.ObjectRequired,"Object required","Vbscript")}getArrayElement(e,t){const s=e.value,n=c(this.evaluate(t));return s.get([Math.floor(n)])}getObjectProperty(e,t){const s=e.value;if(s===null)throw x(w.ObjectRequired,"Object required","Vbscript");if(typeof s.getProperty=="function")return s.hasMethod?.(t)?{type:"Object",value:{type:"method",object:s,method:t}}:s.getProperty(t);const n=s[t];return n===void 0?{type:"Empty",value:void 0}:typeof n=="function"?{type:"Object",value:{type:"jsfunction",func:n,thisArg:s}}:this.jsToVb(n)}jsToVb(e){return e===void 0?{type:"Empty",value:void 0}:e===null?{type:"Null",value:null}:typeof e=="boolean"?{type:"Boolean",value:e}:typeof e=="number"?Number.isInteger(e)&&e>=-2147483648&&e<=2147483647?{type:"Long",value:e}:{type:"Double",value:e}:typeof e=="string"?{type:"String",value:e}:e instanceof Date?{type:"Date",value:e}:Array.isArray(e)?{type:"Array",value:e}:typeof e=="object"?{type:"Object",value:e}:{type:"String",value:String(e)}}evaluateCallInternal(e,t){if(e.type==="Identifier"){const n=e.name;if(this.context.functionRegistry.has(n)){if(this.context.functionRegistry.get(n).params.some(h=>h.byRef)){const h=t.map(g=>{if(g.type==="Identifier"){const b=g.name,S=this.context.currentScope.get(b);return{value:S?S.value:this.context.getVariable(b),variableName:b,setValue:L=>{this.context.currentScope.has(b)?this.context.currentScope.set(b,L):this.context.setVariable(b,L)}}}return{value:this.evaluate(g)}});return this.context.functionRegistry.callWithRefs(n,h)}const p=t.map(h=>this.evaluate(h));return this.context.functionRegistry.call(n,p)}const a=this.context.currentScope.get(n);if(a){if(a.value.type==="Array"){const o=t.map(p=>Math.floor(c(this.evaluate(p))));return a.value.value.get(o)}if(a.value.type==="Object"&&a.value.value!==null){const o=a.value.value;if(o.hasMethod?.("default")&&o.getMethod){const l=o.getMethod("default"),p=t.map(h=>this.evaluate(h));return l.func(...p)}}}const i=this.context.getVariable(n);if(i.type==="Object"&&i.value!==null)return this.callObjectMethod(i,t);throw x(w.InvalidProcedureCall,"Invalid procedure call","Vbscript")}if(e.type==="MemberExpression"){const n=this.evaluateMember(e);if(n.type==="Object"&&n.value!==null)return this.callObjectMethod(n,t);throw x(w.InvalidProcedureCall,"Invalid procedure call","Vbscript")}const s=this.evaluate(e);if(s.type==="Object"&&s.value!==null)return this.callObjectMethod(s,t);throw x(w.InvalidProcedureCall,"Invalid procedure call","Vbscript")}callObjectMethod(e,t){const s=e.value;if(s===null)throw x(w.ObjectRequired,"Object required","Vbscript");if(Pe(s)){const n=t.map(a=>this.evaluate(a));return s.object.getMethod(s.method).func.call(s.object,...n)}if(De(s)){const n=t.map(i=>{const o=this.evaluate(i);return this.vbToJs(o)}),a=s.func.call(s.thisArg,...n);return this.jsToVb(a)}if(typeof s.call=="function"){const n=t.map(a=>this.evaluate(a));return s.call(...n)}throw x(w.InvalidProcedureCall,"Invalid procedure call","Vbscript")}vbToJs(e){switch(e.type){case"Empty":return;case"Null":return null;case"Boolean":case"Long":case"Double":case"Integer":case"String":return e.value;case"Date":return e.value instanceof Date?e.value:new Date(e.value);case"Array":return e.value;case"Object":const t=e.value;return t&&typeof t=="object"&&t.type==="vbref"?t.func:e.value;default:return e.value}}evaluateBinary(e){const t=this.evaluate(e.left),s=this.evaluate(e.right);switch(e.operator){case"+":return this.add(t,s);case"-":return this.subtract(t,s);case"*":return this.multiply(t,s);case"/":return this.divide(t,s);case"\\":return this.integerDivide(t,s);case"%":case"Mod":return this.modulo(t,s);case"**":case"^":return this.power(t,s);case"==":case"=":return this.equals(t,s);case"!=":case"<>":return this.notEquals(t,s);case"<":return this.lessThan(t,s);case"<=":return this.lessThanOrEqual(t,s);case">":return this.greaterThan(t,s);case">=":return this.greaterThanOrEqual(t,s);case"&":return{type:"String",value:y(t)+y(s)};case"Is":return{type:"Boolean",value:t.type==="Object"&&s.type==="Object"&&t.value===s.value};default:return m}}add(e,t){if(e.type==="Null"||t.type==="Null")return N;if(e.type==="String"||t.type==="String")return{type:"String",value:y(e)+y(t)};const s=c(e),n=c(t);return C(s+n)}subtract(e,t){if(e.type==="Null"||t.type==="Null")return N;const s=c(e),n=c(t);return C(s-n)}multiply(e,t){if(e.type==="Null"||t.type==="Null")return N;const s=c(e),n=c(t);return C(s*n)}divide(e,t){if(e.type==="Null"||t.type==="Null")return N;const s=c(e),n=c(t);if(n===0)throw x(w.DivisionByZero,"Division by zero","Vbscript");return{type:"Double",value:s/n}}integerDivide(e,t){if(e.type==="Null"||t.type==="Null")return N;const s=c(e),n=c(t);if(n===0)throw x(w.DivisionByZero,"Division by zero","Vbscript");return{type:"Long",value:Math.floor(s/n)}}modulo(e,t){if(e.type==="Null"||t.type==="Null")return N;const s=c(e),n=c(t);if(n===0)throw x(w.DivisionByZero,"Division by zero","Vbscript");return C(s%n)}power(e,t){if(e.type==="Null"||t.type==="Null")return N;const s=c(e),n=c(t);return{type:"Double",value:Math.pow(s,n)}}equals(e,t){return e.type==="Empty"&&t.type==="Empty"?{type:"Boolean",value:!0}:e.type==="Null"||t.type==="Null"?{type:"Boolean",value:!1}:e.type==="Object"&&t.type==="Object"?{type:"Boolean",value:e.value===t.value}:e.type==="String"||t.type==="String"?{type:"Boolean",value:y(e).toLowerCase()===y(t).toLowerCase()}:{type:"Boolean",value:c(e)===c(t)}}notEquals(e,t){return{type:"Boolean",value:!this.equals(e,t).value}}lessThan(e,t){return e.type==="String"||t.type==="String"?{type:"Boolean",value:y(e)<y(t)}:{type:"Boolean",value:c(e)<c(t)}}lessThanOrEqual(e,t){return e.type==="String"||t.type==="String"?{type:"Boolean",value:y(e)<=y(t)}:{type:"Boolean",value:c(e)<=c(t)}}greaterThan(e,t){return e.type==="String"||t.type==="String"?{type:"Boolean",value:y(e)>y(t)}:{type:"Boolean",value:c(e)>c(t)}}greaterThanOrEqual(e,t){return e.type==="String"||t.type==="String"?{type:"Boolean",value:y(e)>=y(t)}:{type:"Boolean",value:c(e)>=c(t)}}evaluateUnary(e){const t=this.evaluate(e.argument);switch(e.operator){case"-":return C(-c(t));case"+":return C(c(t));case"!":case"Not":return{type:"Boolean",value:!d(t)};default:return m}}evaluateLogical(e){switch(e.operator){case"&&":case"And":{const t=this.evaluate(e.left);return d(t)?this.evaluate(e.right):t}case"||":case"Or":{const t=this.evaluate(e.left);return d(t)?t:this.evaluate(e.right)}case"Xor":{const t=this.evaluate(e.left),s=this.evaluate(e.right);return{type:"Boolean",value:d(t)!==d(s)}}case"Eqv":{const t=this.evaluate(e.left),s=this.evaluate(e.right);return{type:"Boolean",value:d(t)===d(s)}}case"Imp":{const t=this.evaluate(e.left),s=this.evaluate(e.right);return{type:"Boolean",value:!d(t)||d(s)}}default:return m}}evaluateAssignment(e){const t=this.evaluate(e.right),s=e.isSet??!1;if(e.left.type==="Identifier"){if(s){const n=this.context.getVariable(e.left.name);this.callTerminateIfNeeded(n,t)}return this.context.setVariable(e.left.name,t),t}if(e.left.type==="MemberExpression")return this.assignToMember(e.left,t,s),t;throw new Error(`Invalid assignment target: ${e.left.type}`)}callTerminateIfNeeded(e,t){if(e.type==="Object"&&e.value instanceof Q&&(t.type!=="Object"||t.value!==e.value)){const s=e.value,n=s.classInfo.properties.get("class_terminate");n&&n.get&&n.get.call(s)}}assignToMember(e,t,s){let n=this.evaluate(e.object);e.object.type==="VbWithObject"&&(n=this.evaluateWithObject(e.object));let a;if(e.computed){const i=this.evaluate(e.property);a=y(i)}else a=e.property.name;if(n.type==="Array"){const i=n.value,o=c(this.evaluate(e.property));i.set([Math.floor(o)],t)}else if(n.type==="Object"){const i=n.value;if(i===null||typeof i!="object")throw x(w.ObjectRequired,"Object required","Vbscript");if(typeof i.setProperty=="function")i.setProperty(a,t,s);else{const o=this.vbToJs(t);i[a]=o}}else throw x(w.ObjectRequired,"Object required","Vbscript")}evaluateConditional(e){const t=this.evaluate(e.test);return d(t)?this.evaluate(e.consequent):this.evaluate(e.alternate)}}class E extends Error{constructor(e,t){super(e),this.type=e,this.value=t}}class _ extends E{constructor(e){super("goto"),this.labelName=e}}class Oe{constructor(e){this.context=e,this.exprEvaluator=new re(e)}exprEvaluator;execute(e){try{switch(e.type){case"ExpressionStatement":return this.executeExpressionStatement(e);case"BlockStatement":return this.executeBlockStatement(e);case"IfStatement":return this.executeIfStatement(e);case"VbDimStatement":return this.executeDimStatement(e);case"VbReDimStatement":return this.executeReDimStatement(e);case"VbConstStatement":return this.executeConstStatement(e);case"VbForToStatement":return this.executeForToStatement(e);case"VbForEachStatement":return this.executeForEachStatement(e);case"VbDoLoopStatement":return this.executeDoLoopStatement(e);case"VbSelectCaseStatement":return this.executeSelectCaseStatement(e);case"VbWithStatement":return this.executeWithStatement(e);case"VbExitStatement":return this.executeExitStatement(e);case"VbOptionExplicitStatement":return this.executeOptionExplicitStatement(e);case"VbSubStatement":return this.executeSubStatement(e);case"VbFunctionStatement":return this.executeFunctionStatement(e);case"VbClassStatement":return this.executeClassStatement(e);case"VbPropertyGetStatement":case"VbPropertyLetStatement":case"VbPropertySetStatement":return this.executePropertyStatement(e);case"VbOnErrorHandlerStatement":return this.executeOnErrorHandlerStatement(e);case"VbCallStatement":return this.executeCallStatement(e);case"VbGotoStatement":return this.executeGotoStatement(e);case"VbLabelStatement":return m;case"ReturnStatement":throw new E("return");default:throw new Error(`Unknown statement type: ${e.type}`)}}catch(t){if(t instanceof E)throw t;if(t instanceof P){if(this.context.setError(t),this.context.onErrorResumeNext)return m;throw t}const s=P.fromError(t);if(this.context.setError(s),this.context.onErrorResumeNext)return m;throw s}}executeExpressionStatement(e){return this.exprEvaluator.evaluate(e.expression)}executeCallStatement(e){return this.exprEvaluator.evaluateCall(e.callee,e.arguments)}executeBlockStatement(e){let t=m;for(const s of e.body)t=this.execute(s);return t}executeIfStatement(e){const t=this.exprEvaluator.evaluate(e.test);return d(t)?this.execute(e.consequent):e.alternate?this.execute(e.alternate):m}executeDimStatement(e){for(const t of e.declarations){let s=m;if(t.isArray&&t.arrayBounds){const n=t.arrayBounds.map(i=>{const o=this.exprEvaluator.evaluate(i);return c(o)});s={type:"Array",value:W(n)}}else t.init&&(s=this.exprEvaluator.evaluate(t.init));this.context.declareVariable(t.id.name,s)}return m}executeReDimStatement(e){for(const t of e.declarations){if(!t.isArray||!t.arrayBounds)continue;const s=t.arrayBounds.map(a=>{const i=this.exprEvaluator.evaluate(a);return c(i)}),n=this.context.currentScope.get(t.id.name);if(n&&n.value.type==="Array")n.value.value.redim(s,e.preserve);else{const a=W(s);this.context.setVariable(t.id.name,{type:"Array",value:a})}}return m}executeConstStatement(e){for(const t of e.declarations){const s=this.exprEvaluator.evaluate(t.init);this.context.currentScope.declare(t.id.name,s,{isConst:!0})}return m}executeForToStatement(e){const t=this.exprEvaluator.evaluate(e.init),s=this.exprEvaluator.evaluate(e.to),n=e.step?this.exprEvaluator.evaluate(e.step):C(1),a=c(t),i=c(s),o=c(n);this.context.declareVariable(e.left.name,C(a));const l=o>0?()=>c(this.context.getVariable(e.left.name))<=i:()=>c(this.context.getVariable(e.left.name))>=i;for(;l();){this.context.checkTimeout&&this.context.checkTimeout();try{this.execute(e.body)}catch(h){if(h instanceof E){if(h.type==="exit"&&this.context.getExitFlag()==="for"){this.context.clearExitFlag();break}if(h.type==="return")throw h}throw h}const p=c(this.context.getVariable(e.left.name));this.context.setVariable(e.left.name,C(p+o))}return m}executeForEachStatement(e){const t=this.exprEvaluator.evaluate(e.right);if(t.type!=="Array"&&t.type!=="Object")throw x(w.TypeMismatch,"Type mismatch: expected array or collection","Vbscript");let s;if(t.type==="Array")s=t.value.toArray();else{const n=t.value,a=n.getProperty("Count"),i=c(a);s=[];for(let o=0;o<i;o++)s.push(n.getProperty(String(o)))}this.context.declareVariable(e.left.name,m);for(const n of s){this.context.setVariable(e.left.name,n);try{this.execute(e.body)}catch(a){if(a instanceof E){if(a.type==="exit"&&this.context.getExitFlag()==="for"){this.context.clearExitFlag();break}if(a.type==="return")throw a}throw a}}return m}executeDoLoopStatement(e){const t=()=>{if(!e.test)return!0;const a=this.exprEvaluator.evaluate(e.test);return d(a)},s=e.testPosition==="while-do"||e.testPosition==="do-while",n=e.testPosition==="while-do"||e.testPosition==="until-do";for(;this.context.checkTimeout&&this.context.checkTimeout(),!(n&&!(s?t():!t()));){try{this.execute(e.body)}catch(a){if(a instanceof E){if(a.type==="exit"&&this.context.getExitFlag()==="do"){this.context.clearExitFlag();break}if(a.type==="return")throw a}throw a}if(!n&&!(s?t():!t()))break}return m}executeSelectCaseStatement(e){const t=this.exprEvaluator.evaluate(e.discriminant);for(const s of e.cases){if(s.isElse){for(const a of s.consequent)this.execute(a);return m}if(this.matchCase(s.test,t)){for(const a of s.consequent)this.execute(a);return m}}return m}matchCase(e,t){if(!e)return!1;const s=Array.isArray(e)?e:[e];for(const n of s)if(n.type==="BinaryExpression"&&"left"in n&&n.left.type==="Identifier"&&n.left.name==="__select_expr__"){const a=this.exprEvaluator.evaluate(n.right);switch(n.operator){case"==":if(d(this.equals(t,a)))return!0;break;case"<":if(c(t)<c(a))return!0;break;case">":if(c(t)>c(a))return!0;break;case"<=":if(c(t)<=c(a))return!0;break;case">=":if(c(t)>=c(a))return!0;break;case"!=":if(!d(this.equals(t,a)))return!0;break}}else{const a=this.exprEvaluator.evaluate(n);if(d(this.equals(t,a)))return!0}return!1}equals(e,t){if(e.type==="Empty"&&t.type==="Empty")return{type:"Boolean",value:!0};if(e.type==="Null"||t.type==="Null")return{type:"Boolean",value:!1};if(e.type==="String"||t.type==="String"){const s=e.type==="String"?e.value:String(c(e)),n=t.type==="String"?t.value:String(c(t));return{type:"Boolean",value:s.toLowerCase()===n.toLowerCase()}}return{type:"Boolean",value:c(e)===c(t)}}executeWithStatement(e){const t=this.exprEvaluator.evaluate(e.object);this.context.pushWith(t);try{this.execute(e.body)}finally{this.context.popWith()}return m}executeExitStatement(e){throw this.context.setExitFlag(e.target.toLowerCase()),new E("exit")}executeOptionExplicitStatement(e){return this.context.optionExplicit=!0,m}executeSubStatement(e){const t=e.name.name,s=this,n=function(i){s.context.pushScope(),s.context.pushCall(t);try{s.bindParameters(e.params,i),s.executeBlockStatement(e.body),s.updateByRefArgs(e.params,i)}catch(o){if(o instanceof E&&o.type==="return")s.updateByRefArgs(e.params,i);else throw o}finally{s.context.popCall(),s.context.popScope()}return m},a=e.params.map(i=>({name:i.name.name,byRef:i.byRef,isArray:i.isArray,isOptional:i.isOptional,isParamArray:i.isParamArray}));return this.context.functionRegistry.register(t,n,{isSub:!0,params:a,isUserDefined:!0}),m}executeFunctionStatement(e){const t=e.name.name,s=this,n=function(i){s.context.pushScope(),s.context.pushCall(t),s.context.declareVariable(t,m);let o=m;try{s.bindParameters(e.params,i),s.executeBlockStatement(e.body),s.updateByRefArgs(e.params,i),o=s.context.getVariable(t)}catch(l){if(l instanceof E&&l.type==="return")s.updateByRefArgs(e.params,i),o=s.context.getVariable(t);else throw l}finally{s.context.popCall(),s.context.popScope()}return o},a=e.params.map(i=>({name:i.name.name,byRef:i.byRef,isArray:i.isArray,isOptional:i.isOptional,isParamArray:i.isParamArray}));return this.context.functionRegistry.register(t,n,{params:a,isUserDefined:!0}),m}bindParameters(e,t){let s=0;for(const n of e)if(n.isParamArray){const a=[];for(;s<t.length;)a.push(t[s++]);const i=W([a.length]);a.forEach((o,l)=>i.set([l],o)),this.context.declareVariable(n.name.name,{type:"Array",value:i})}else{let a;s<t.length?a=t[s++]:n.defaultValue?a=this.exprEvaluator.evaluate(n.defaultValue):(n.isOptional,a=m),this.context.declareVariable(n.name.name,a)}}updateByRefArgs(e,t){let s=0;for(const n of e){if(n.isParamArray)break;s<t.length&&n.byRef&&(t[s]=this.context.getVariable(n.name.name)),s++}}executeClassStatement(e){const t=e.name.name,s=new Z(t),n=this;let a,i;for(const o of e.body)if(o.type==="VbDimStatement")for(const l of o.declarations)s.properties.set(l.id.name.toLowerCase(),{name:l.id.name});else if(o.type==="VbSubStatement"){const l=o,p=o.name.name.toLowerCase();if(p==="class_initialize"){a={name:"Class_Initialize",get:function(){const h=n.context.currentInstance;n.context.currentInstance=this,n.context.pushScope();try{n.executeBlockStatement(l.body)}finally{n.context.popScope(),n.context.currentInstance=h}return m}};continue}if(p==="class_terminate"){i={name:"Class_Terminate",get:function(){const h=n.context.currentInstance;n.context.currentInstance=this,n.context.pushScope();try{n.executeBlockStatement(l.body)}finally{n.context.popScope(),n.context.currentInstance=h}return m}};continue}s.methods.set(p,{name:o.name.name,func:function(...h){const g=n.context.currentInstance;n.context.currentInstance=this,n.context.pushScope();try{n.bindParameters(l.params,h),n.executeBlockStatement(l.body)}finally{n.context.popScope(),n.context.currentInstance=g}return m},isSub:!0})}else if(o.type==="VbFunctionStatement"){const l=o;s.methods.set(o.name.name.toLowerCase(),{name:o.name.name,func:function(...p){const h=n.context.currentInstance;n.context.currentInstance=this,n.context.pushScope(),n.context.declareVariable(l.name.name,m),n.bindParameters(l.params,p);let g=m;try{n.executeBlockStatement(l.body),g=n.context.getVariable(l.name.name)}catch(b){if(b instanceof E&&b.type==="return")g=n.context.getVariable(l.name.name);else throw b}finally{n.context.popScope(),n.context.currentInstance=h}return g},isSub:!1})}else if(o.type==="VbPropertyGetStatement"){const l=o,p=o.name.name.toLowerCase(),h=s.properties.get(p)||{name:o.name.name};h.get=function(){const g=n.context.currentInstance,b=n.context.inPropertyGet,S=n.context.propertyGetName;n.context.currentInstance=this,n.context.inPropertyGet=!0,n.context.propertyGetName=l.name.name.toLowerCase(),n.context.pushScope(),n.context.declareVariable(l.name.name,m);try{return n.executeBlockStatement(l.body),n.context.currentScope.get(l.name.name)?.value??m}finally{n.context.popScope(),n.context.currentInstance=g,n.context.inPropertyGet=b,n.context.propertyGetName=S}},s.properties.set(p,h)}else if(o.type==="VbPropertyLetStatement"){const l=o,p=o.name.name.toLowerCase(),h=s.properties.get(p)||{name:o.name.name};h.let=function(g){const b=n.context.currentInstance;n.context.currentInstance=this,n.context.pushScope(),n.context.declareVariable(l.name.name,m);const S=l.params[0];S&&n.context.declareVariable(S.name.name,g);try{n.executeBlockStatement(l.body)}finally{n.context.popScope(),n.context.currentInstance=b}},s.properties.set(p,h)}else if(o.type==="VbPropertySetStatement"){const l=o,p=o.name.name.toLowerCase(),h=s.properties.get(p)||{name:o.name.name};h.set=function(g){const b=n.context.currentInstance;n.context.currentInstance=this,n.context.pushScope(),n.context.declareVariable(l.name.name,m);const S=l.params[0];S&&n.context.declareVariable(S.name.name,g);try{n.executeBlockStatement(l.body)}finally{n.context.popScope(),n.context.currentInstance=b}},s.properties.set(p,h)}return a&&s.properties.set("class_initialize",a),i&&s.properties.set("class_terminate",i),this.context.classRegistry.register(s),m}executePropertyStatement(e){return m}executeOnErrorHandlerStatement(e){return e.action==="resume_next"?this.context.onErrorResumeNext=!0:e.action==="goto_0"&&(this.context.onErrorResumeNext=!1,this.context.clearError()),m}executeGotoStatement(e){throw new _(e.label.name.toLowerCase())}}const B=new Map([["af",1078],["sq",1052],["ar-ae",14337],["ar-bh",15361],["ar-dz",5121],["ar-eg",3073],["ar-iq",2049],["ar-jo",11265],["ar-kw",13313],["ar-lb",12289],["ar-ly",4097],["ar-ma",6145],["ar-om",8193],["ar-qa",16385],["ar-sa",1025],["ar-sy",10241],["ar-tn",7169],["ar-ye",9217],["hy",1067],["az",1068],["az-Latn",1068],["az-Cyrl",2092],["eu",1069],["be",1059],["bg",1026],["ca",1027],["zh-cn",2052],["zh-hk",3076],["zh-mo",5124],["zh-sg",4100],["zh-tw",1028],["zh",2052],["hr",1050],["cs",1029],["da",1030],["nl-nl",1043],["nl-be",2067],["nl",1043],["en-au",3081],["en-bz",10249],["en-ca",4105],["en-cb",9225],["en-ie",6153],["en-jm",8201],["en-nz",5129],["en-ph",13321],["en-za",7177],["en-tt",11273],["en-gb",2057],["en-us",1033],["en",1033],["et",1061],["fa",1065],["fi",1035],["fo",1080],["fr-fr",1036],["fr-be",2060],["fr-ca",3084],["fr-lu",5132],["fr-ch",4108],["fr",1036],["gd-ie",2108],["gd",1084],["de-de",1031],["de-at",3079],["de-li",5127],["de-lu",4103],["de-ch",2055],["de",1031],["el",1032],["he",1037],["hi",1081],["hu",1038],["is",1039],["id",1057],["it-it",1040],["it-ch",2064],["it",1040],["ja",1041],["ko",1042],["lv",1062],["lt",1063],["mk",1071],["ms-my",1086],["ms-bn",2110],["ms",1086],["mt",1082],["mr",1102],["no",1044],["nb",1044],["nn",2068],["pl",1045],["pt-pt",2070],["pt-br",1046],["pt",1046],["rm",1047],["ro",1048],["ro-md",2072],["ru",1049],["ru-md",2073],["sa",1103],["sr-Cyrl",3098],["sr-Latn",2074],["sr",3098],["tn",1074],["sl",1060],["sk",1051],["sb",1070],["es-es",1034],["es-ar",11274],["es-bo",16394],["es-cl",13322],["es-co",9226],["es-cr",5130],["es-do",7178],["es-ec",12298],["es-gt",4106],["es-hn",18442],["es-mx",2058],["es-ni",19466],["es-pa",6154],["es-pe",10250],["es-pr",20490],["es-py",15370],["es-sv",17418],["es-uy",14346],["es-ve",8202],["es",1034],["sx",1072],["sw",1089],["sv-se",1053],["sv-fi",2077],["sv",1053],["ta",1097],["tt",1092],["th",1054],["tr",1055],["ts",1073],["uk",1058],["ur",1056],["uz-Cyrl",2115],["uz-Latn",1091],["uz",1091],["vi",1066],["xh",1076],["yi",1085],["zu",1077]]),se=new Map;B.forEach((r,e)=>{se.set(r,e)});let V=null;function Be(r){return r.toLowerCase().replace(/_/g,"-")}function q(r){for(const e of B.keys())if(e.toLowerCase()===r)return e}function U(){if(V)return V;const r=Intl.DateTimeFormat().resolvedOptions().locale||"en-US",e=Be(r),t=q(e);if(t)return t;const s=e.split("-")[0]??"en",n=q(s);return n||"en"}function z(){const r=U();return{type:"Long",value:B.get(r)??1033}}function Ve(r){const e=typeof r.value=="number"?r.value:parseInt(String(r.value),10);if(isNaN(e)){const s=String(r.value).toLowerCase(),n=q(s);return n?(V=n,{type:"Long",value:B.get(n)??1033}):z()}const t=se.get(e);return t?(V=t,{type:"Long",value:e}):z()}function O(){return U()}const ne=new Map([["en-us","USD"],["en-gb","GBP"],["en-au","AUD"],["en-ca","CAD"],["en-nz","NZD"],["en-za","ZAR"],["de-de","EUR"],["de-at","EUR"],["de-ch","CHF"],["fr-fr","EUR"],["fr-be","EUR"],["fr-ca","CAD"],["fr-ch","CHF"],["ja","JPY"],["zh-cn","CNY"],["zh-tw","TWD"],["zh-hk","HKD"],["ko","KRW"],["it","EUR"],["es","EUR"],["es-mx","MXN"],["pt-br","BRL"],["pt-pt","EUR"],["ru","RUB"],["pl","PLN"],["nl","EUR"],["sv","SEK"],["da","DKK"],["no","NOK"],["fi","EUR"],["cs","CZK"],["hu","HUF"],["tr","TRY"],["th","THB"],["id","IDR"],["ms","MYR"],["vi","VND"],["in","INR"],["hi","INR"],["ar-sa","SAR"],["ar-eg","EGP"],["ar-ae","AED"],["he","ILS"],["en-ie","EUR"],["en-ph","PHP"],["en-in","INR"]]);function Me(){const r=U(),e=ne.get(r);if(e)return e;const t=r.split("-")[0]??"en",s=ne.get(t);return s||"USD"}const Ae={GetLocale:z,SetLocale:Ve};function Re(r,e){const t=[];let s=0;for(;s<e.length;){const n=e[s].toLowerCase();let a=1;for(;s+a<e.length&&e[s+a].toLowerCase()===n;)a++;switch(n){case"y":a>=4||a===3?t.push(r.getFullYear().toString()):t.push(r.getFullYear().toString().slice(-2));break;case"m":if(a>=4){const i=["January","February","March","April","May","June","July","August","September","October","November","December"];t.push(i[r.getMonth()])}else if(a===3){const i=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];t.push(i[r.getMonth()])}else a===2?t.push((r.getMonth()+1).toString().padStart(2,"0")):t.push((r.getMonth()+1).toString());break;case"d":if(a>=4){const i=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];t.push(i[r.getDay()])}else if(a===3){const i=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];t.push(i[r.getDay()])}else a===2?t.push(r.getDate().toString().padStart(2,"0")):t.push(r.getDate().toString());break;case"h":a>=2?t.push((r.getHours()%12||12).toString().padStart(2,"0")):t.push((r.getHours()%12||12).toString());break;case"n":a>=2?t.push(r.getMinutes().toString().padStart(2,"0")):t.push(r.getMinutes().toString());break;case"s":a>=2?t.push(r.getSeconds().toString().padStart(2,"0")):t.push(r.getSeconds().toString());break;case"q":t.push(Math.floor(r.getMonth()/3+1).toString());break;case"w":t.push((r.getDay()+1).toString());break;case"a":a>=2?t.push(r.getHours()>=12?"PM":"AM"):t.push(r.getHours()>=12?"P":"A");break;default:t.push(e.substring(s,s+a))}s+=a}return t.join("")}function Fe(r,e){let t=e,s="",n="";const a=e.indexOf(";");if(a!==-1){t=e.substring(0,a);const i=e.substring(a+1),o=i.indexOf(";");o!==-1?(s=i.substring(0,o),n=i.substring(o+1)):s=i}return r===0&&n?M(0,n):r<0&&s?M(Math.abs(r),s):r<0?"-"+M(Math.abs(r),t):M(r,t)}function M(r,e){let t=e.includes("%");t&&(r*=100);const s=e.toLowerCase();let n=s.indexOf("."),a=0;if(n!==-1){let g=n+1;for(;g<e.length&&(e[g]==="0"||e[g]==="#");)a++,g++}let i=Math.floor(Math.abs(r)),o=a>0?Math.round((Math.abs(r)-i)*Math.pow(10,a)):0;o>=Math.pow(10,a)&&(i++,o=0);let l=i.toString();s.indexOf(",")!==-1&&(l=l.replace(/\B(?=(\d{3})+(?!\d))/g,","));let h=l;if(a>0){const g=o.toString().padStart(a,"0");h+="."+g}return t&&(h+="%"),h}function je(r,e){return e===">"||e.toLowerCase()===">"?r.toUpperCase():e==="<"||e.toLowerCase()==="<"?r.toLowerCase():r}const Te={Len:r=>({type:"Long",value:y(r).length}),Left:(r,e)=>{const t=y(r),s=Math.max(0,Math.floor(c(e)));return{type:"String",value:t.substring(0,s)}},Right:(r,e)=>{const t=y(r),s=Math.max(0,Math.floor(c(e)));return{type:"String",value:t.substring(t.length-s)}},Mid:(r,e,t)=>{const s=y(r),n=Math.max(1,Math.floor(c(e)))-1;if(t){const a=Math.floor(c(t));return{type:"String",value:s.substring(n,n+a)}}return{type:"String",value:s.substring(n)}},InStr:(r,e,t,s)=>{let n=1,a,i,o=0;e===void 0?(a="",i=y(r)):t===void 0?(a=y(r),i=y(e)):(n=Math.max(1,Math.floor(c(r))),a=y(e),i=y(t),s&&(o=Math.floor(c(s))));let l;return o===0?l=a.indexOf(i,n-1):l=a.toLowerCase().indexOf(i.toLowerCase(),n-1),{type:"Long",value:l+1}},InStrRev:(r,e,t,s)=>{const n=y(r),a=y(e),i=t?Math.floor(c(t)):n.length,o=s?Math.floor(c(s)):0;let l;return o===0?l=n.lastIndexOf(a,i-1):l=n.toLowerCase().lastIndexOf(a.toLowerCase(),i-1),{type:"Long",value:l+1}},LCase:r=>({type:"String",value:y(r).toLowerCase()}),UCase:r=>({type:"String",value:y(r).toUpperCase()}),LTrim:r=>({type:"String",value:y(r).replace(/^\s+/,"")}),RTrim:r=>({type:"String",value:y(r).replace(/\s+$/,"")}),Trim:r=>({type:"String",value:y(r).trim()}),Replace:(r,e,t,s,n,a)=>{const i=y(r),o=y(e),l=y(t),p=s?Math.max(1,Math.floor(c(s)))-1:0,h=n?Math.floor(c(n)):-1,g=a?Math.floor(c(a)):0;let b="",S=0,L=p;const vt=g===0?i:i.toLowerCase(),dt=g===0?o:o.toLowerCase();for(;L<i.length;){if(h!==-1&&S>=h){b+=i.substring(L);break}vt.substring(L,L+o.length)===dt?(b+=l,L+=o.length,S++):(b+=i[L],L++)}return{type:"String",value:b}},StrReverse:r=>({type:"String",value:y(r).split("").reverse().join("")}),Space:r=>{const e=Math.max(0,Math.floor(c(r)));return{type:"String",value:" ".repeat(e)}},String:(r,e)=>{const t=Math.max(0,Math.floor(c(r))),s=y(e);return{type:"String",value:(s.length>0?s[0]:" ").repeat(t)}},Asc:r=>{const e=y(r);return{type:"Integer",value:e.length>0?e.charCodeAt(0):0}},AscW:r=>{const e=y(r);return{type:"Integer",value:e.length>0?e.charCodeAt(0):0}},Chr:r=>{const e=Math.floor(c(r));return{type:"String",value:String.fromCharCode(e)}},ChrW:r=>{const e=Math.floor(c(r));return{type:"String",value:String.fromCharCode(e)}},StrComp:(r,e,t)=>{const s=y(r),n=y(e),a=t?Math.floor(c(t)):0;let i;if(a===1)i=s.toLowerCase().localeCompare(n.toLowerCase());else if(a===2){const o=O();i=s.localeCompare(n,o,{sensitivity:"base"})}else i=s.localeCompare(n);return{type:"Integer",value:i}},Split:(r,e,t,s)=>{const n=y(r),a=e?y(e):" ",i=t?Math.floor(c(t)):-1,o=n.split(a);let l;return i>0&&o.length>i?(l=o.slice(0,i-1),l.push(o.slice(i-1).join(a))):l=o,{type:"Array",value:G(l.map(h=>({type:"String",value:h})))}},Join:(r,e)=>{const t=e?y(e):" ";if(r.type==="Array"){const s=r.value;return typeof s=="object"&&s!==null&&"toArray"in s?{type:"String",value:s.toArray().map(i=>y(i)).join(t)}:{type:"String",value:s.map(a=>y(a)).join(t)}}return{type:"String",value:""}},Format:(r,e)=>{if(r.type==="Empty"||r.type==="Null")return{type:"String",value:""};const t=e?y(e):"";return t?r.type==="Date"&&r.value instanceof Date?{type:"String",value:Re(r.value,t)}:r.type==="Boolean"?{type:"String",value:r.value?"True":"False"}:["Integer","Long","Single","Double","Currency","Byte"].includes(r.type)?{type:"String",value:Fe(c(r),t)}:r.type==="String"?{type:"String",value:je(y(r),t)}:{type:"String",value:y(r)}:{type:"String",value:y(r)}},LSet:(r,e)=>{const t=y(r),s=Math.max(0,Math.floor(c(e)));return t.length>=s?{type:"String",value:t.substring(0,s)}:{type:"String",value:t.padEnd(s," ")}},RSet:(r,e)=>{const t=y(r),s=Math.max(0,Math.floor(c(e)));return t.length>=s?{type:"String",value:t.substring(0,s)}:{type:"String",value:t.padStart(s," ")}}},We={Abs:r=>{const e=c(r);return C(Math.abs(e))},Sgn:r=>{const e=c(r);return{type:"Integer",value:e>0?1:e<0?-1:0}},Sqr:r=>{const e=c(r);if(e<0)throw new Error("Invalid procedure call or argument: Sqr");return{type:"Double",value:Math.sqrt(e)}},Int:r=>{const e=c(r);return{type:"Long",value:Math.floor(e)}},Fix:r=>{const e=c(r);return{type:"Long",value:e>=0?Math.floor(e):Math.ceil(e)}},Round:(r,e)=>{const t=c(r),s=e?Math.floor(c(e)):0,n=Math.pow(10,s);return{type:"Double",value:Math.round(t*n)/n}},Atn:r=>{const e=c(r);return{type:"Double",value:Math.atan(e)}},Cos:r=>{const e=c(r);return{type:"Double",value:Math.cos(e)}},Sin:r=>{const e=c(r);return{type:"Double",value:Math.sin(e)}},Tan:r=>{const e=c(r);return{type:"Double",value:Math.tan(e)}},Exp:r=>{const e=c(r);return{type:"Double",value:Math.exp(e)}},Log:r=>{const e=c(r);if(e<=0)throw new Error("Invalid procedure call or argument: Log");return{type:"Double",value:Math.log(e)}},Rnd:r=>({type:"Single",value:Math.random()}),Randomize:r=>m,Oct:r=>({type:"String",value:Math.floor(c(r)).toString(8)}),Hex:r=>({type:"String",value:Math.floor(c(r)).toString(16).toUpperCase()})},Ge={vbCr:{type:"String",value:"\r"},vbCrLf:{type:"String",value:`\r
|
|
12
|
+
`)}if(this.current==="'"&&this.options.skipWhitespace){this.readSingleLineComment();continue}if(this.current==='"'||this.current==="'")return this.readString(this.current);if(this.current==="#"){const s=this.getLoc();return this.readDate(s)}if(this.current==="&"&&(this.peek==="h"||this.peek==="H"||this.peek==="o"||this.peek==="O"))return this.readNumber();if(/[0-9]/.test(this.current))return this.readNumber();if(this.current==="."&&/[0-9]/.test(this.peek))return this.readNumber();if(/[a-zA-Z_]/.test(this.current)){const s=this.readIdentifier();if(s.type===u.Rem){if(this.options.skipWhitespace){this.readRemComment();continue}return s}return s}const e=this.getLoc(),t=this.current;switch(t){case"+":return this.advance(),this.createToken(u.Plus,"+",e);case"-":return this.advance(),this.createToken(u.Minus,"-",e);case"*":return this.advance(),this.createToken(u.Asterisk,"*",e);case"/":return this.advance(),this.createToken(u.Slash,"/",e);case"\\":return this.advance(),this.createToken(u.Backslash,"\\",e);case"^":return this.advance(),this.createToken(u.Caret,"^",e);case"&":return this.advance(),this.createToken(u.Ampersand,"&",e);case"(":return this.advance(),this.createToken(u.LParen,"(",e);case")":return this.advance(),this.createToken(u.RParen,")",e);case"{":return this.advance(),this.createToken(u.LBrace,"{",e);case"}":return this.advance(),this.createToken(u.RBrace,"}",e);case"[":return this.advance(),this.createToken(u.LBracket,"[",e);case"]":return this.advance(),this.createToken(u.RBracket,"]",e);case",":return this.advance(),this.createToken(u.Comma,",",e);case":":return this.advance(),this.createToken(u.Colon,":",e);case".":return this.advance(),this.createToken(u.Dot,".",e);case"!":return this.advance(),this.createToken(u.Bang,"!",e);case"=":return this.advance(),this.createToken(u.Eq,"=",e);case"<":return this.advance(),this.current===">"?(this.advance(),this.createToken(u.Ne,"<>",e)):this.current==="="?(this.advance(),this.createToken(u.Le,"<=",e)):this.createToken(u.Lt,"<",e);case">":return this.advance(),this.current==="="?(this.advance(),this.createToken(u.Ge,">=",e)):this.createToken(u.Gt,">",e);default:return this.advance(),this.createToken(u.Unknown,t,e)}}return this.createToken(u.EOF,"",this.getLoc())}tokenize(){const e=[];for(;;){const t=this.nextToken();if(e.push(t),t.type===u.EOF)break}return e}}class X extends Error{token;expected;constructor(e,t,s){super(e),this.name="ParseError",this.token=t,s!==void 0&&(this.expected=s)}}class fe{tokens;pos=0;constructor(e){if(e.length===0)throw new Error("ParserState requires at least one token");this.tokens=e}get current(){return this.tokens[this.pos]??this.tokens[0]}get previous(){return this.tokens[this.pos-1]??this.tokens[0]}get isEOF(){return this.current.type==="EOF"}save(){return this.pos}restore(e){this.pos=e}advance(){return this.isEOF||this.pos++,this.previous}peek(e=0){return this.tokens[this.pos+e]??this.tokens[0]}check(e){return this.current.type===e}checkIdentifier(){return this.current.type==="Identifier"}checkAny(...e){return e.includes(this.current.type)}checkNewline(){return this.current.type==="Newline"}match(e){return this.check(e)?this.advance():null}matchAny(...e){return this.checkAny(...e)?this.advance():null}expect(e,t){if(this.check(e))return this.advance();throw new X(t??`Expected ${e}, got ${this.current.type}`,this.current,e)}expectAny(e,t){if(this.checkAny(...e))return this.advance();throw new X(t??`Expected one of ${e.join(", ")}, got ${this.current.type}`,this.current,e)}skipNewlines(){for(;this.match("Newline"););}skipOptionalNewlines(){this.skipNewlines()}skipStatementSeparators(){for(;this.matchAny("Newline","Colon"););}}function ye(r){return{line:r.loc.start.line,column:r.loc.start.column}}function me(r){return{line:r.loc.end.line,column:r.loc.end.column}}function f(r,e){return{start:ye(r),end:me(e)}}class ge{state;constructor(e){this.state=e}parseExpression(){return this.parseAssignment()}parseStatementExpression(){return this.parseStatementAssignment()}parseCallExpression(){return this.parseCall()}parseMemberExpression(){let e=this.parseIdentifierOnly();for(;;)if(this.state.check("Dot")){this.state.advance();const t=this.parsePropertyName();e={type:"MemberExpression",object:e,property:t,computed:!1,optional:!1,loc:f({loc:e.loc},{loc:t.loc})}}else if(this.state.check("Bang")){this.state.advance();const t=this.parsePropertyName();e={type:"MemberExpression",object:e,property:t,computed:!0,optional:!1,loc:f({loc:e.loc},{loc:t.loc})}}else if(this.state.check("LBracket")){this.state.advance();const t=this.parseExpression(),s=this.state.expect("RBracket");e={type:"MemberExpression",object:e,property:t,computed:!0,optional:!1,loc:f({loc:e.loc},s)}}else break;return e}parseIdentifierOnly(){if(this.state.check("Dot"))return this.parseWithMemberExpression();const e=this.state.expect("Identifier");return{type:"Identifier",name:e.value,loc:e.loc}}parseStatementAssignment(){if(this.state.check("Identifier")||this.state.check("Dot")){const e=this.state.save(),t=this.parseCall();if(t.type==="CallExpression")return this.continueStringConcat(t);if(this.state.check("Eq")&&(t.type==="Identifier"||t.type==="MemberExpression")){const s=this.state.advance(),n=this.parseStatementAssignment();return this.createAssignmentExpression(t,"=",n,s)}if((t.type==="Identifier"||t.type==="MemberExpression")&&this.isStatementCallArgumentStart()){const s=this.parseStatementCallArguments(),n={type:"CallExpression",callee:t,arguments:s,optional:!1,loc:f({loc:t.loc},this.state.previous)};return this.continueStringConcat(n)}this.state.restore(e)}return this.parseStringConcat()}continueStringConcat(e){for(;this.state.check("Ampersand");){this.state.advance();const t=this.parseLogicalOr();e={type:"BinaryExpression",operator:"&",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}isStatementCallArgumentStart(){return this.state.checkAny("StringLiteral","NumberLiteral","DateLiteral","BooleanLiteral","NothingLiteral","NullLiteral","EmptyLiteral","Identifier","LParen","New")}parseStatementCallArguments(){const e=[];for(;!this.state.checkAny("Newline","Colon","EOF")&&(e.push(this.parseExpression()),!!this.state.match("Comma")););return e}parseAssignment(){const e=this.parseStringConcat();if(this.state.checkAny("Eq")){const t=this.state.advance(),s=this.parseAssignment();return this.createAssignmentExpression(e,"=",s,t)}return e}createAssignmentExpression(e,t,s,n){return{type:"AssignmentExpression",operator:t,left:e,right:s,loc:f({loc:{start:e.loc.start,end:e.loc.end}},n)}}parseStringConcat(){let e=this.parseLogicalOr();for(;this.state.check("Ampersand");){this.state.advance();const t=this.parseLogicalOr();e={type:"BinaryExpression",operator:"&",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}parseLogicalOr(){let e=this.parseLogicalAnd();for(;this.state.check("Or");){this.state.advance();const t=this.parseLogicalAnd();e={type:"LogicalExpression",operator:"||",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}parseLogicalAnd(){let e=this.parseLogicalNot();for(;this.state.check("And");){this.state.advance();const t=this.parseLogicalNot();e={type:"LogicalExpression",operator:"&&",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}parseLogicalNot(){let e=this.parseComparison();for(;this.state.checkAny("Xor","Eqv","Imp");){const t=this.state.advance(),s=this.parseComparison();e={type:"LogicalExpression",operator:t.value.toLowerCase()==="xor"?"xor":t.value.toLowerCase()==="eqv"?"eqv":"imp",left:e,right:s,loc:f({loc:e.loc},{loc:s.loc})}}return e}parseComparison(){let e=this.parseIs();for(;this.state.checkAny("Eq","Lt","Gt","Le","Ge","Ne");){const t=this.state.advance(),s=this.parseIs();e={type:"BinaryExpression",operator:this.getComparisonOperator(t),left:e,right:s,loc:f({loc:e.loc},{loc:s.loc})}}return e}getComparisonOperator(e){switch(e.type){case"Eq":return"==";case"Lt":return"<";case"Gt":return">";case"Le":return"<=";case"Ge":return">=";case"Ne":return"!=";default:return"=="}}parseIs(){const e=this.parseConcatenation();if(this.state.check("Is")){this.state.advance();const t=this.parseConcatenation();return{type:"BinaryExpression",operator:"Is",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}parseConcatenation(){return this.parseAdditive()}parseAdditive(){let e=this.parseMultiplicative();for(;this.state.checkAny("Plus","Minus");){const t=this.state.advance(),s=this.parseMultiplicative();e={type:"BinaryExpression",operator:t.type==="Plus"?"+":"-",left:e,right:s,loc:f({loc:e.loc},{loc:s.loc})}}return e}parseMultiplicative(){let e=this.parseIntegerDivision();for(;this.state.checkAny("Asterisk","Slash");){const t=this.state.advance(),s=this.parseIntegerDivision();e={type:"BinaryExpression",operator:t.type==="Asterisk"?"*":"/",left:e,right:s,loc:f({loc:e.loc},{loc:s.loc})}}return e}parseIntegerDivision(){let e=this.parseMod();for(;this.state.check("Backslash");){this.state.advance();const t=this.parseMod();e={type:"BinaryExpression",operator:"\\",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}parseMod(){let e=this.parsePower();for(;this.state.check("Mod");){this.state.advance();const t=this.parsePower();e={type:"BinaryExpression",operator:"%",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}parsePower(){let e=this.parseUnary();for(;this.state.check("Caret");){this.state.advance();const t=this.parseUnary();e={type:"BinaryExpression",operator:"**",left:e,right:t,loc:f({loc:e.loc},{loc:t.loc})}}return e}parseUnary(){if(this.state.check("Not")){const e=this.state.advance(),t=this.parseUnary();return{type:"UnaryExpression",operator:"!",prefix:!0,argument:t,loc:f(e,{loc:t.loc})}}if(this.state.check("Minus")){const e=this.state.advance(),t=this.parseUnary();return{type:"UnaryExpression",operator:"-",prefix:!0,argument:t,loc:f(e,{loc:t.loc})}}if(this.state.check("Plus")){const e=this.state.advance(),t=this.parseUnary();return{type:"UnaryExpression",operator:"+",prefix:!0,argument:t,loc:f(e,{loc:t.loc})}}return this.parsePostfix()}parsePostfix(){return this.parseCall()}parseCall(){let e=this.parsePrimary();for(;;)if(this.state.check("Dot")){this.state.advance();const t=this.parsePropertyName();e={type:"MemberExpression",object:e,property:t,computed:!1,optional:!1,loc:f({loc:e.loc},{loc:t.loc})}}else if(this.state.check("Bang")){this.state.advance();const t=this.parsePropertyName();e={type:"MemberExpression",object:e,property:t,computed:!0,optional:!1,loc:f({loc:e.loc},{loc:t.loc})}}else if(this.state.check("LParen")){this.state.advance();const t=this.parseArguments(),s=this.state.expect("RParen");e={type:"CallExpression",callee:e,arguments:t,optional:!1,loc:f({loc:e.loc},s)}}else if(this.state.check("LBracket")){this.state.advance();const t=this.parseExpression(),s=this.state.expect("RBracket");e={type:"MemberExpression",object:e,property:t,computed:!0,optional:!1,loc:f({loc:e.loc},s)}}else break;return e}parseArguments(){const e=[];if(!this.state.check("RParen"))for(;this.state.skipOptionalNewlines(),!this.state.check("RParen");)if(this.state.check("Comma")?e.push({type:"VbEmptyLiteral",value:void 0,raw:"",loc:this.state.current.loc}):e.push(this.parseExpression()),this.state.skipOptionalNewlines(),this.state.check("Comma"))this.state.advance();else break;return e}parsePrimary(){if(this.state.check("LParen"))return this.parseParenExpression();if(this.state.check("StringLiteral"))return this.parseStringLiteral();if(this.state.check("NumberLiteral"))return this.parseNumberLiteral();if(this.state.check("DateLiteral"))return this.parseDateLiteral();if(this.state.check("BooleanLiteral"))return this.parseBooleanLiteral();if(this.state.check("NothingLiteral"))return this.parseNothingLiteral();if(this.state.check("NullLiteral"))return this.parseNullLiteral();if(this.state.check("EmptyLiteral"))return this.parseEmptyLiteral();if(this.state.check("New"))return this.parseNewExpression();if(this.state.check("Dot"))return this.parseWithMemberExpression();if(this.state.check("Identifier"))return this.parseIdentifierOrCall();throw new Error(`Unexpected token: ${this.state.current.type}`)}parseWithMemberExpression(){const e=this.state.advance(),t=this.parsePropertyName();return{type:"MemberExpression",object:{type:"VbWithObject",loc:e.loc},property:t,computed:!1,optional:!1,loc:f(e,{loc:t.loc})}}parseParenExpression(){this.state.advance(),this.state.skipOptionalNewlines();const e=this.parseExpression();return this.state.skipOptionalNewlines(),this.state.expect("RParen"),e}parseStringLiteral(){const e=this.state.advance();return{type:"Literal",value:e.value,raw:e.raw??void 0,loc:e.loc}}parseNumberLiteral(){const e=this.state.advance();return{type:"Literal",value:e.value.includes(".")||e.value.includes("e")||e.value.includes("E")?parseFloat(e.value):parseInt(e.value,10),raw:e.raw??e.value,loc:e.loc}}parseDateLiteral(){const e=this.state.advance();return{type:"Literal",value:new Date(e.value),raw:e.raw??void 0,loc:e.loc}}parseBooleanLiteral(){const e=this.state.advance();return{type:"Literal",value:e.value.toLowerCase()==="true",raw:e.raw??void 0,loc:e.loc}}parseNothingLiteral(){const e=this.state.advance();return{type:"Literal",value:Symbol.for("Nothing"),raw:e.raw??void 0,loc:e.loc}}parseNullLiteral(){const e=this.state.advance();return{type:"Literal",value:null,raw:e.raw??void 0,loc:e.loc}}parseEmptyLiteral(){const e=this.state.advance();return{type:"VbEmptyLiteral",value:void 0,raw:e.raw??void 0,loc:e.loc}}parseNewExpression(){const e=this.state.advance(),t=this.parseIdentifier();let s=[];return this.state.check("LParen")&&(this.state.advance(),s=this.parseArguments(),this.state.expect("RParen")),{type:"VbNewExpression",callee:t,arguments:s,loc:f(e,this.state.previous)}}parseIdentifierOrCall(){const e=this.parseIdentifier();if(this.state.check("LParen")){this.state.advance();const t=this.parseArguments(),s=this.state.expect("RParen");return{type:"CallExpression",callee:e,arguments:t,optional:!1,loc:f({loc:e.loc},s)}}return e}parseIdentifier(){const e=this.state.expect("Identifier");return{type:"Identifier",name:e.value,loc:e.loc}}parsePropertyName(){const e=this.state.current;if(e.type==="Identifier"||e.type!=="EOF"&&e.type!=="Newline"&&e.type!=="LParen"&&e.type!=="RParen"&&e.type!=="Comma"&&e.type!=="Colon")return this.state.advance(),{type:"Identifier",name:e.value,loc:e.loc};throw new Error(`Expected property name, got ${e.type}`)}}class ve{constructor(e,t){this.state=e,this.exprParser=t}parseDimStatement(){const e=this.state.advance();return{type:"VbDimStatement",declarations:this.parseVariableDeclarations(),visibility:"dim",loc:f(e,this.state.previous)}}parsePublicDimStatement(){const e=this.state.advance();return this.state.expect("Dim"),{type:"VbDimStatement",declarations:this.parseVariableDeclarations(),visibility:"public",loc:f(e,this.state.previous)}}parsePrivateDimStatement(){const e=this.state.advance();return this.state.expect("Dim"),{type:"VbDimStatement",declarations:this.parseVariableDeclarations(),visibility:"private",loc:f(e,this.state.previous)}}parseReDimStatement(){const e=this.state.advance(),t=this.state.match("Preserve")!==null;return{type:"VbReDimStatement",declarations:this.parseVariableDeclarations(),preserve:t,loc:f(e,this.state.previous)}}parseEraseStatement(){const e=this.state.advance();return{type:"VbEraseStatement",arrayName:this.exprParser.parseIdentifier(),loc:f(e,this.state.previous)}}parseConstStatement(){const e=this.state.advance();return{type:"VbConstStatement",declarations:this.parseConstDeclarators(),visibility:"private",loc:f(e,this.state.previous)}}parsePublicConstStatement(){const e=this.state.advance();return this.state.expect("Const"),{type:"VbConstStatement",declarations:this.parseConstDeclarators(),visibility:"public",loc:f(e,this.state.previous)}}parsePrivateConstStatement(){const e=this.state.advance();return this.state.expect("Const"),{type:"VbConstStatement",declarations:this.parseConstDeclarators(),visibility:"private",loc:f(e,this.state.previous)}}parseVariableDeclarations(){const e=[];do{const t=this.parseVariableDeclarator();e.push(t)}while(this.state.match("Comma"));return e}parseVariableDeclarator(){const e=this.exprParser.parseIdentifier();let t=null,s=!1,n=[];this.state.check("LParen")&&(this.state.advance(),s=!0,n=this.parseArrayBounds(),this.state.expect("RParen")),this.state.match("Eq")&&(t=this.exprParser.parseExpression());let a;return this.state.check("As")&&(a=this.parseTypeAnnotation()),{type:"VbVariableDeclarator",id:e,init:t,isArray:s,arrayBounds:n.length>0?n:void 0,typeAnnotation:a,loc:f({loc:e.loc},this.state.previous)}}parseArrayBounds(){const e=[];do this.state.skipOptionalNewlines(),e.push(this.exprParser.parseExpression()),this.state.skipOptionalNewlines();while(this.state.match("Comma"));return e}parseTypeAnnotation(){this.state.expect("As");const e=this.state.current;let t="",s=!1;return this.state.checkAny("Integer","Long","Single","Double","Currency","String","Boolean","Date","Object","Variant","Byte","Identifier")&&(t=this.state.advance().value),this.state.check("LParen")&&(this.state.advance(),s=!0,this.state.expect("RParen")),{type:"VbTypeAnnotation",typeName:t,isArray:s,loc:f(e,this.state.previous)}}parseConstDeclarators(){const e=[];do{const t=this.parseConstDeclarator();e.push(t)}while(this.state.match("Comma"));return e}parseConstDeclarator(){const e=this.exprParser.parseIdentifier();this.state.expect("Eq");const t=this.exprParser.parseExpression();let s;return this.state.check("As")&&(s=this.parseTypeAnnotation()),{type:"VbConstDeclarator",id:e,init:t,typeAnnotation:s,loc:f({loc:e.loc},this.state.previous)}}}function be(r){return["VbSubStatement","VbFunctionStatement","VbPropertyGetStatement","VbPropertyLetStatement","VbPropertySetStatement","VbDimStatement","VbConstStatement"].includes(r.type)}class de{constructor(e,t,s){this.state=e,this.exprParser=t,this.parseStatement=s}parseSubStatement(e){const t=this.state.current;this.state.expect("Sub");const s=this.exprParser.parseIdentifier(),n=this.parseParameters();this.state.skipNewlines();const a=this.parseBlock("End");return this.state.expect("End"),this.state.expect("Sub"),{type:"VbSubStatement",name:s,params:n,body:a,visibility:e??"public",loc:f(t,this.state.previous)}}parseFunctionStatement(e){const t=this.state.current;this.state.expect("Function");const s=this.exprParser.parseIdentifier(),n=this.parseParameters();this.state.skipNewlines();const a=this.parseBlock("End");return this.state.expect("End"),this.state.expect("Function"),{type:"VbFunctionStatement",name:s,params:n,body:a,visibility:e??"public",loc:f(t,this.state.previous)}}parseClassStatement(){const e=this.state.advance(),t=this.exprParser.parseIdentifier();this.state.skipNewlines();const s=this.parseClassBody();return this.state.expect("End"),this.state.expect("Class"),{type:"VbClassStatement",name:t,body:s,loc:f(e,this.state.previous)}}parsePropertyStatement(e){this.state.expect("Property");const t=e??"public";if(this.state.check("Get"))return this.parsePropertyGet(t);if(this.state.check("Let"))return this.parsePropertyLet(t);if(this.state.check("Set"))return this.parsePropertySet(t);throw new Error("Expected Get, Let, or Set after Property")}parsePropertyGet(e){this.state.expect("Get");const t=this.exprParser.parseIdentifier(),s=this.parseParameters();this.state.skipNewlines();const n=this.parseBlock("End");return this.state.expect("End"),this.state.expect("Property"),{type:"VbPropertyGetStatement",name:t,params:s,body:n,visibility:e,loc:f(this.state.previous,this.state.previous)}}parsePropertyLet(e){this.state.expect("Let");const t=this.exprParser.parseIdentifier(),s=this.parseParameters();this.state.skipNewlines();const n=this.parseBlock("End");return this.state.expect("End"),this.state.expect("Property"),{type:"VbPropertyLetStatement",name:t,params:s,body:n,visibility:e,loc:f(this.state.previous,this.state.previous)}}parsePropertySet(e){this.state.expect("Set");const t=this.exprParser.parseIdentifier(),s=this.parseParameters();this.state.skipNewlines();const n=this.parseBlock("End");return this.state.expect("End"),this.state.expect("Property"),{type:"VbPropertySetStatement",name:t,params:s,body:n,visibility:e,loc:f(this.state.previous,this.state.previous)}}parseParameters(){const e=[];if(!this.state.check("LParen"))return e;if(this.state.advance(),!this.state.check("RParen"))do{this.state.skipOptionalNewlines();const t=this.parseParameter();e.push(t),this.state.skipOptionalNewlines()}while(this.state.match("Comma"));return this.state.expect("RParen"),e}parseParameter(){let e=!0,t=!1,s=!1;this.state.check("Optional")&&(this.state.advance(),t=!0),this.state.check("ParamArray")&&(this.state.advance(),s=!0),this.state.check("ByRef")?(this.state.advance(),e=!0):this.state.check("ByVal")&&(this.state.advance(),e=!1);const n=this.exprParser.parseIdentifier();let a=!1,i;return this.state.check("LParen")&&(this.state.advance(),a=!0,this.state.expect("RParen")),this.state.match("Eq")&&(i=this.exprParser.parseExpression()),{type:"VbParameter",name:n,byRef:e,isArray:a,defaultValue:i,isOptional:t,isParamArray:s,loc:f({loc:n.loc},this.state.previous)}}parseBlock(e){const t=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!(e&&this.state.check(e)||this.state.isEOF));){const s=this.parseStatement();t.push(s)}return{type:"BlockStatement",body:t}}parseClassBody(){const e=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!(this.state.check("End")||this.state.isEOF));){const t=this.parseStatement();be(t)&&e.push(t)}return e}}class Se{constructor(e,t,s){this.state=e,this.exprParser=t,this.parseStatement=s}parseIfStatement(){const e=this.state.advance(),t=this.exprParser.parseExpression();this.state.skipOptionalNewlines(),this.state.expect("Then");const s=this.state.checkNewline();if(this.state.skipOptionalNewlines(),s)return this.parseMultiLineIf(e,t);const n=this.parseSingleLineIfBody();let a=null;return this.state.check("Else")&&(this.state.advance(),a=this.parseSingleLineIfBody()),this.state.check("End")&&(this.state.advance(),this.state.expect("If")),{type:"IfStatement",test:t,consequent:n,alternate:a,loc:f(e,this.state.previous)}}parseMultiLineIf(e,t){this.state.skipNewlines();const s=this.parseIfBlock();let n=null;return this.state.check("ElseIf")?n=this.parseElseIfStatement():this.state.check("Else")&&(this.state.advance(),this.state.skipNewlines(),n=this.parseIfBlock()),this.state.expect("End"),this.state.expect("If"),{type:"IfStatement",test:t,consequent:s,alternate:n,loc:f(e,this.state.previous)}}parseForStatement(){const e=this.state.advance();return this.state.check("Each")?this.parseForEachStatement(e):this.parseForToStatement(e)}parseDoStatement(){const e=this.state.advance();let t=null,s=null;this.state.check("While")?(this.state.advance(),t=this.exprParser.parseExpression(),s="while-do"):this.state.check("Until")&&(this.state.advance(),t=this.exprParser.parseExpression(),s="until-do"),this.state.skipNewlines();const n=this.parseDoBody();return this.state.check("While")?(this.state.advance(),t=this.exprParser.parseExpression(),s="do-while"):this.state.check("Until")&&(this.state.advance(),t=this.exprParser.parseExpression(),s="do-until"),this.state.expect("Loop"),{type:"VbDoLoopStatement",body:n,test:t,testPosition:s,loc:f(e,this.state.previous)}}parseWhileStatement(){const e=this.state.advance(),t=this.exprParser.parseExpression();this.state.skipNewlines();const s=this.parseWhileBody();return{type:"WhileStatement",test:t,body:s,loc:f(e,this.state.previous)}}parseSelectStatement(){const e=this.state.advance();this.state.expect("Case");const t=this.exprParser.parseExpression();this.state.skipNewlines();const s=this.parseCaseClauses();return this.state.expect("End"),this.state.expect("Select"),{type:"VbSelectCaseStatement",discriminant:t,cases:s,loc:f(e,this.state.previous)}}parseSingleLineIfBody(){const e=[];for(;!this.state.isEOF&&!(this.state.checkNewline()||this.state.check("Else")||this.state.check("ElseIf")||this.state.check("End"));){const t=this.parseStatement();e.push(t)}return{type:"BlockStatement",body:e}}parseIfBlock(){const e=[];let t=0;for(;!this.state.isEOF;){if(this.state.skipStatementSeparators(),this.state.check("If")){const n=this.state.save();for(this.state.advance();!this.state.isEOF&&!this.state.check("Then");)this.state.advance();if(this.state.check("Then"))if(this.state.advance(),!this.state.checkNewline()){this.state.restore(n);const i=this.parseStatement();e.push(i);continue}else{for(this.state.restore(n),this.state.advance();!this.state.isEOF&&!this.state.check("Then");)this.state.advance();this.state.advance(),t++;continue}this.state.restore(n)}if(this.state.check("End")){const n=this.state.save();if(this.state.advance(),this.state.check("If")){if(t>0){t--,this.state.restore(n);const a=this.parseStatement();e.push(a);continue}this.state.restore(n);break}this.state.restore(n)}if(this.state.checkAny("Else","ElseIf")){if(t>0){const n=this.parseStatement();e.push(n);continue}break}if(this.state.isEOF)break;const s=this.parseStatement();e.push(s)}return{type:"BlockStatement",body:e}}parseElseIfStatement(){this.state.advance();const e=this.exprParser.parseExpression();this.state.skipOptionalNewlines(),this.state.expect("Then"),this.state.skipNewlines();const t=this.parseIfBlock();let s=null;return this.state.check("ElseIf")?s=this.parseElseIfStatement():this.state.check("Else")&&(this.state.advance(),this.state.skipNewlines(),s=this.parseIfBlock()),{type:"IfStatement",test:e,consequent:t,alternate:s,loc:f(this.state.previous,this.state.previous)}}parseForToStatement(e){const t=this.exprParser.parseIdentifier();this.state.expect("Eq");const s=this.exprParser.parseExpression();this.state.expect("To");const n=this.exprParser.parseExpression();let a=null;this.state.match("Step")&&(a=this.exprParser.parseExpression()),this.state.skipNewlines();const i=this.parseForBody();return{type:"VbForToStatement",left:t,init:s,to:n,step:a,body:i,loc:f(e,this.state.previous)}}parseForEachStatement(e){this.state.expect("Each");const t=this.exprParser.parseIdentifier();this.state.expect("In");const s=this.exprParser.parseExpression();this.state.skipNewlines();const n=this.parseForBody();return{type:"VbForEachStatement",left:t,right:s,body:n,loc:f(e,this.state.previous)}}parseForBody(){const e=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!(this.state.check("Next")||this.state.isEOF));){const t=this.parseStatement();e.push(t)}return this.state.expect("Next"),this.state.check("Identifier")&&this.state.advance(),{type:"BlockStatement",body:e}}parseDoBody(){const e=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!(this.state.checkAny("Loop","While","Until")||this.state.isEOF));){const t=this.parseStatement();e.push(t)}return{type:"BlockStatement",body:e}}parseWhileBody(){const e=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!(this.state.check("Wend")||this.state.isEOF));){const t=this.parseStatement();e.push(t)}return this.state.expect("Wend"),{type:"BlockStatement",body:e}}parseCaseClauses(){const e=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!this.state.check("End"));)if(this.state.check("Case")){const t=this.parseCaseClause();e.push(t)}else break;return e}parseCaseClause(){const e=this.state.advance();let t=null,s=!1;this.state.check("Else")?(this.state.advance(),s=!0):t=this.parseCaseExpressions(),this.state.skipNewlines();const n=this.parseCaseBody();return{type:"VbCaseClause",test:t,consequent:n,isElse:s,loc:f(e,this.state.previous)}}parseCaseExpressions(){const e=[];do if(this.state.check("Is")){this.state.advance();const t=this.state.advance(),s=this.exprParser.parseExpression();e.push({type:"BinaryExpression",operator:this.getComparisonOperator(t),left:{type:"Identifier",name:"__select_expr__"},right:s})}else e.push(this.exprParser.parseExpression());while(this.state.match("Comma"));return e.length===1?e[0]:e}getComparisonOperator(e){return{Eq:"==",Lt:"<",Gt:">",Le:"<=",Ge:">=",Ne:"!="}[e.type]??"=="}parseCaseBody(){const e=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!(this.state.check("Case")||this.state.check("End")||this.state.isEOF));){const t=this.parseStatement();e.push(t)}return e}}class we{constructor(e,t,s){this.state=e,this.exprParser=t,this.parseStatement=s}parseWithStatement(){const e=this.state.advance(),t=this.exprParser.parseExpression();this.state.skipNewlines();const s=this.parseWithBody();return this.state.expect("End"),this.state.expect("With"),{type:"VbWithStatement",object:t,body:s,loc:f(e,this.state.previous)}}parseExitStatement(){const e=this.state.advance(),t={Sub:"Sub",Function:"Function",Property:"Property",Do:"Do",For:"For",Select:"Select"},s=this.state.current,n=t[s.type];return n&&this.state.advance(),{type:"VbExitStatement",target:n??"Sub",loc:f(e,this.state.previous)}}parseOptionStatement(){const e=this.state.advance();return this.state.expect("Explicit"),{type:"VbOptionExplicitStatement",loc:f(e,this.state.previous)}}parseCallStatement(){const e=this.state.advance(),t=this.exprParser.parseMemberExpression();let s=[];return this.state.check("LParen")?(this.state.advance(),s=this.parseCallArguments(),this.state.expect("RParen")):this.state.checkAny("Newline","Colon","EOF")||(s=this.parseCallArgumentsNoParens()),{type:"VbCallStatement",callee:t,arguments:s,loc:f(e,this.state.previous)}}parseSetStatement(){const e=this.state.advance(),t=this.exprParser.parseCallExpression();this.state.expect("Eq");const s=this.exprParser.parseExpression();return{type:"ExpressionStatement",expression:{type:"AssignmentExpression",operator:"=",left:t,right:s,isSet:!0,loc:f(e,this.state.previous)},loc:f(e,this.state.previous)}}parseOnStatement(){const e=this.state.advance();if(this.state.expect("Error"),this.state.match("Resume"))return this.state.expect("Next"),{type:"VbOnErrorHandlerStatement",action:"resume_next",loc:f(e,this.state.previous)};if(this.state.match("Goto")){if(this.state.check("NumberLiteral")){const s=this.state.advance();if(String(s.value)==="0")return{type:"VbOnErrorHandlerStatement",action:"goto_0",loc:f(e,this.state.previous)}}return{type:"VbOnErrorHandlerStatement",action:"goto_label",label:this.exprParser.parseIdentifier(),loc:f(e,this.state.previous)}}throw new Error("Expected Resume Next or Goto after On Error")}parseResumeStatement(){const e=this.state.advance();return this.state.match("Next")?{type:"VbResumeStatement",target:"next",loc:f(e,this.state.previous)}:{type:"VbResumeStatement",target:null,loc:f(e,this.state.previous)}}parseExpressionStatement(){const e=this.exprParser.parseStatementExpression();return{type:"ExpressionStatement",expression:e,loc:e.loc}}parseWithBody(){const e=[];for(;!this.state.isEOF&&(this.state.skipStatementSeparators(),!(this.state.check("End")&&this.state.peek(1).type==="With"||this.state.isEOF));){const t=this.parseStatement();e.push(t)}return{type:"BlockStatement",body:e}}parseCallArguments(){const e=[];if(!this.state.check("RParen"))for(;this.state.skipOptionalNewlines(),!this.state.check("RParen");)if(this.state.check("Comma")?e.push({type:"VbEmptyLiteral",value:void 0,raw:"",loc:this.state.current.loc}):e.push(this.exprParser.parseExpression()),this.state.skipOptionalNewlines(),this.state.check("Comma"))this.state.advance();else break;return e}parseCallArgumentsNoParens(){const e=[];for(;!this.state.checkAny("Newline","Colon","EOF")&&(e.push(this.exprParser.parseExpression()),!!this.state.match("Comma")););return e}}class xe{state;exprParser;declarationParser;procedureParser;controlFlowParser;statementsParser;constructor(e){this.state=e,this.exprParser=new ge(e),this.declarationParser=new ve(e,this.exprParser),this.procedureParser=new de(e,this.exprParser,()=>this.parseStatement()),this.controlFlowParser=new Se(e,this.exprParser,()=>this.parseStatement()),this.statementsParser=new we(e,this.exprParser,()=>this.parseStatement())}parseStatement(){switch(this.state.skipNewlines(),this.state.current.type){case"Dim":return this.declarationParser.parseDimStatement();case"ReDim":return this.declarationParser.parseReDimStatement();case"Erase":return this.declarationParser.parseEraseStatement();case"Const":return this.declarationParser.parseConstStatement();case"Public":return this.parseVisibilityStatement();case"Private":return this.parseVisibilityStatement();case"Sub":return this.procedureParser.parseSubStatement();case"Function":return this.procedureParser.parseFunctionStatement();case"Class":return this.procedureParser.parseClassStatement();case"Property":return this.procedureParser.parsePropertyStatement();case"If":return this.controlFlowParser.parseIfStatement();case"For":return this.controlFlowParser.parseForStatement();case"Do":return this.controlFlowParser.parseDoStatement();case"While":return this.controlFlowParser.parseWhileStatement();case"Select":return this.controlFlowParser.parseSelectStatement();case"With":return this.statementsParser.parseWithStatement();case"Exit":return this.statementsParser.parseExitStatement();case"Option":return this.statementsParser.parseOptionStatement();case"Call":return this.statementsParser.parseCallStatement();case"Set":return this.statementsParser.parseSetStatement();case"On":return this.statementsParser.parseOnStatement();case"Resume":return this.statementsParser.parseResumeStatement();case"Goto":return this.parseGotoStatement();case"Colon":return this.state.advance(),this.parseStatement();default:return this.state.checkIdentifier()&&this.state.peek(1).type==="Colon"?this.parseLabelStatement():this.statementsParser.parseExpressionStatement()}}parseGotoStatement(){const e=this.state.advance();return{type:"VbGotoStatement",label:this.exprParser.parseIdentifier(),loc:f(e,this.state.previous)}}parseLabelStatement(){const e=this.state.advance();return this.state.expect("Colon"),{type:"VbLabelStatement",label:{type:"Identifier",name:e.value,loc:e.loc},loc:f(e,this.state.previous)}}parseVisibilityStatement(){const e=this.state.advance(),t=e.type==="Public"?"public":"private";if(this.state.check("Dim"))return this.declarationParser.parsePublicDimStatement();if(this.state.check("Const"))return t==="public"?this.declarationParser.parsePublicConstStatement():this.declarationParser.parsePrivateConstStatement();if(this.state.check("Sub"))return this.procedureParser.parseSubStatement(t);if(this.state.check("Function"))return this.procedureParser.parseFunctionStatement(t);if(this.state.check("Property"))return this.procedureParser.parsePropertyStatement(t);if(this.state.checkIdentifier())return{type:"VbDimStatement",declarations:this.declarationParser.parseVariableDeclarations(),visibility:t,loc:{start:e.loc.start,end:this.state.previous.loc.end}};throw new Error(`Expected Dim, Const, Sub, Function, or Property after ${t}`)}}class T{state;stmtParser;constructor(e){this.state=new fe(e),this.stmtParser=new xe(this.state)}parse(){const e=[];for(;!this.state.isEOF&&(this.state.skipNewlines(),!this.state.isEOF);){const s=this.stmtParser.parseStatement();e.push(s)}const t=this.state.current;return{type:"Program",body:e,sourceType:"script",loc:{start:{line:1,column:0},end:t.loc.end}}}}function W(r,e){const s=new j(r).tokenize();return new T(s).parse()}class Ee{cache=new Map;maxSize;defaultTTL;constructor(e=100,t=300*1e3){this.maxSize=e,this.defaultTTL=t}hashSource(e){let t=5381;for(let s=0;s<e.length;s++)t=(t<<5)+t+e.charCodeAt(s);return t.toString(36)}get(e){const t=this.hashSource(e),s=this.cache.get(t);if(!s)return;const n=Date.now();if(n-s.lastAccessed>this.defaultTTL){this.cache.delete(t);return}return s.lastAccessed=n,s.accessCount++,s.ast}set(e,t){this.cache.size>=this.maxSize&&this.evictLRU();const s=this.hashSource(e),n=Date.now();this.cache.set(s,{ast:t,lastAccessed:n,accessCount:1})}has(e){const t=this.hashSource(e),s=this.cache.get(t);return s?Date.now()-s.lastAccessed>this.defaultTTL?(this.cache.delete(t),!1):!0:!1}evictLRU(){let e=null,t=1/0;for(const[s,n]of this.cache)n.lastAccessed<t&&(t=n.lastAccessed,e=s);e&&this.cache.delete(e)}clear(){this.cache.clear()}getStats(){let e=0;for(const t of this.cache.values())e+=t.accessCount;return{size:this.cache.size,maxSize:this.maxSize,totalAccessCount:e,averageAccessCount:this.cache.size>0?e/this.cache.size:0}}cleanup(){const e=Date.now();let t=0;for(const[s,n]of this.cache)e-n.lastAccessed>this.defaultTTL&&(this.cache.delete(s),t++);return t}}const A=new Ee,m={type:"Empty",value:void 0},N={type:"Null",value:null},Ce={type:"Object",value:null};function C(r){return r===void 0?m:r===null?N:r===Symbol.for("Nothing")?Ce:typeof r=="boolean"?{type:"Boolean",value:r}:typeof r=="number"?Number.isInteger(r)?r>=-32768&&r<=32767?{type:"Integer",value:r}:{type:"Long",value:r}:{type:"Double",value:r}:typeof r=="string"?{type:"String",value:r}:r instanceof Date?{type:"Date",value:r}:Array.isArray(r)?{type:"Array",value:r}:typeof r=="object"?{type:"Object",value:r}:{type:"Variant",value:r}}function d(r){if(r.type==="Boolean")return r.value;if(r.type==="Empty")return!1;if(r.type==="Null")throw new Error("Type mismatch: Null cannot be converted to Boolean");if(r.type==="String"){const e=r.value;if(e==="")return!1;const t=parseFloat(e);return isNaN(t)?e.toLowerCase()!=="false":t!==0}return r.type==="Integer"||r.type==="Long"||r.type==="Double"||r.type==="Single"||r.type==="Byte"?r.value!==0:!0}function l(r){if(r.type==="Empty")return 0;if(r.type==="Null")throw new Error("Type mismatch: Null cannot be converted to Number");if(r.type==="Boolean")return r.value?-1:0;if(r.type==="Integer"||r.type==="Long"||r.type==="Double"||r.type==="Single"||r.type==="Byte"||r.type==="Currency")return r.value;if(r.type==="String"){const e=r.value.trim();if(e==="")return 0;const t=parseFloat(e);if(isNaN(t))throw new Error(`Type mismatch: "${e}" cannot be converted to Number`);return t}if(r.type==="Date")return r.value.getTime();throw new Error(`Type mismatch: ${r.type} cannot be converted to Number`)}function y(r){return r.type==="Empty"?"":r.type==="Null"?"Null":r.type==="Boolean"?r.value?"True":"False":r.type==="String"?r.value:r.type==="Integer"||r.type==="Long"||r.type==="Byte"?String(Math.floor(r.value)):r.type==="Double"||r.type==="Single"||r.type==="Currency"?String(r.value):r.type==="Date"?r.value.toLocaleString():r.type==="Object"?r.value===null?"Nothing":"[object]":r.type==="Array"?"[array]":String(r.value)}function Ie(r){if(r.type==="Integer"||r.type==="Long"||r.type==="Double"||r.type==="Single"||r.type==="Currency"||r.type==="Byte")return!0;if(r.type==="String"){const e=r.value.trim();return e===""?!1:!isNaN(parseFloat(e))}return r.type==="Boolean"||r.type==="Empty"}function ke(r){return r.type==="Empty"}function Le(r){return r.type==="Null"}class Ne{constructor(e,t,s=!1,n=!1,a=!1){this.name=e,this.value=t,this.isByRef=s,this.isArray=n,this.isConst=a}}class Z{variables=new Map;parent;constructor(e=null){this.parent=e}declare(e,t,s={}){const n=new Ne(e,t,s.isByRef??!1,s.isArray??!1,s.isConst??!1);return this.variables.set(e.toLowerCase(),n),n}get(e){const t=e.toLowerCase(),s=this.variables.get(t);if(s)return s;if(this.parent)return this.parent.get(e)}set(e,t){const s=e.toLowerCase(),n=this.variables.get(s);if(n){if(n.isConst)throw new Error(`Cannot assign to constant '${e}'`);n.value=t;return}if(this.parent){this.parent.set(e,t);return}this.declare(e,t)}has(e){const t=e.toLowerCase();return this.variables.has(t)?!0:this.parent?this.parent.has(e):!1}getParent(){return this.parent}getAllVariables(){const e=new Map;return this.parent&&this.parent.getAllVariables().forEach((s,n)=>e.set(n,s)),this.variables.forEach((t,s)=>e.set(s,t)),e}}class Pe{functions=new Map;register(e,t,s={}){const n=e.toLowerCase();this.functions.set(n,{name:e,func:t,isSub:s.isSub??!1,minArgs:s.minArgs??0,maxArgs:s.maxArgs??1/0,params:s.params??[],isUserDefined:s.isUserDefined??!1})}get(e){return this.functions.get(e.toLowerCase())}has(e){return this.functions.has(e.toLowerCase())}call(e,t){const s=this.functions.get(e.toLowerCase());if(!s)throw new Error(`Undefined function or sub: ${e}`);if(t.length<s.minArgs)throw new Error(`${e} requires at least ${s.minArgs} argument(s)`);if(t.length>s.maxArgs)throw new Error(`${e} accepts at most ${s.maxArgs} argument(s)`);let n;return s.isUserDefined?n=s.func(t):n=s.func(...t),s.isSub?m:n??m}callWithRefs(e,t){const s=this.functions.get(e.toLowerCase());if(!s)throw new Error(`Undefined function or sub: ${e}`);if(t.length<s.minArgs)throw new Error(`${e} requires at least ${s.minArgs} argument(s)`);if(t.length>s.maxArgs)throw new Error(`${e} accepts at most ${s.maxArgs} argument(s)`);const n=t.map(i=>i.value);let a;s.isUserDefined?a=s.func(n):a=s.func(...n);for(let i=0;i<t.length&&i<s.params.length;i++){const o=s.params[i],c=t[i];o&&c&&o.byRef&&c.setValue&&n[i]!==c.value&&c.setValue(n[i])}return s.isSub?m:a??m}getAll(){return this.functions.entries()}getUserDefinedFunctions(){const e=new Map;for(const[t,s]of this.functions.entries())s.isUserDefined&&e.set(t,s);return e}}class Q{constructor(e,t=new Map,s=new Map,n){this.name=e,this.properties=t,this.methods=s,this.initializer=n}}class ee{constructor(e,t=null){this.classInfo=e,this.prototype=t,e.initializer&&e.initializer(this),e.properties.forEach((s,n)=>{this.propertyAccessors.set(n.toLowerCase(),s),!s.get&&!s.let&&!s.set&&this.properties.set(n.toLowerCase(),m)})}properties=new Map;propertyAccessors=new Map;getProperty(e){const t=e.toLowerCase(),s=this.propertyAccessors.get(t);if(s?.get)return s.get.call(this);if(s&&!s.get&&!s.let&&!s.set){const a=this.properties.get(t);if(a!==void 0)return a}const n=this.properties.get(t);return n!==void 0?n:this.prototype?this.prototype.getProperty(e):m}setProperty(e,t,s=!1){const n=e.toLowerCase(),a=this.propertyAccessors.get(n);if(a){if(s&&a.set){a.set.call(this,t);return}if(!s&&a.let){a.let.call(this,t);return}if(!a.get&&!a.let&&!a.set){this.properties.set(n,t);return}}this.properties.set(n,t)}hasProperty(e){const t=e.toLowerCase();return this.properties.has(t)||this.propertyAccessors.has(t)||(this.prototype?.hasProperty(e)??!1)}getMethod(e){return this.classInfo.methods.get(e.toLowerCase())}hasMethod(e){return this.classInfo.methods.has(e.toLowerCase())}setPropertiesFromObject(e){for(const[t,s]of Object.entries(e))this.properties.set(t.toLowerCase(),s)}}class De{classes=new Map;register(e){this.classes.set(e.name.toLowerCase(),e)}registerClass(e,t){const s=new Q(e);s.initializer=n=>{const a=t();if(a.type==="Object"&&a.value){const i=a.value;n.setPropertiesFromObject(i)}},this.classes.set(e.toLowerCase(),s)}get(e){return this.classes.get(e.toLowerCase())}has(e){return this.classes.has(e.toLowerCase())}createInstance(e,t){const s=this.classes.get(e.toLowerCase());if(!s)throw new Error(`Undefined class: ${e}`);const n=new ee(s),a=s.methods.get("class_initialize");a&&a.func.call(n);const i=s.properties.get("class_initialize");return i&&i.get&&i.get.call(n),n}}class te{data;dimensions;lowerBounds;constructor(e,t){this.dimensions=e,this.lowerBounds=t??e.map(()=>0);const s=e.reduce((n,a)=>n*a,1);this.data=new Array(s).fill(m)}getIndex(e){if(e.length!==this.dimensions.length)throw new Error(`Array has ${this.dimensions.length} dimension(s), but ${e.length} index(es) provided`);let t=0,s=1;for(let n=this.dimensions.length-1;n>=0;n--){const a=this.lowerBounds[n],i=this.dimensions[n],o=e[n]-a;if(o<0||o>=i)throw new Error("Subscript out of range");t+=o*s,s*=i}return t}get(e){return this.data[this.getIndex(e)]??m}set(e,t){this.data[this.getIndex(e)]=t}getDimensions(){return this.dimensions.length}getBounds(e){if(e<1||e>this.dimensions.length)throw new Error("Invalid dimension");const t=e-1,s=this.lowerBounds[t],n=this.dimensions[t];return{lower:s,upper:s+n-1}}redim(e,t){const s=new Array(e.reduce((n,a)=>n*a,1)).fill(m);if(t){const n=Math.min(this.data.length,s.length);for(let a=0;a<n;a++)s[a]=this.data[a]}this.dimensions=e,this.data=s}toArray(){return[...this.data]}erase(){this.data.fill(m)}}function G(r){const e=r.map(t=>t+1);return new te(e)}function _(r){const e=new te([r.length]);return r.forEach((t,s)=>e.set([s],t)),e}class P extends Error{number;source;description;helpFile;helpContext;constructor(e,t,s=""){super(t),this.name="VbError",this.number=e,this.source=s,this.description=t}static fromError(e){return e instanceof P?e:new P(440,e.message,"Vbscript")}}const w={TypeMismatch:13,DivisionByZero:11,InvalidProcedureCall:5,ObjectRequired:424};function x(r,e,t){return new P(r,e,t)}function re(r,e){return r===void 0?{type:"Empty",value:void 0}:r===null?{type:"Null",value:null}:typeof r=="boolean"?{type:"Boolean",value:r}:typeof r=="number"?Number.isInteger(r)&&r>=-2147483648&&r<=2147483647?{type:"Long",value:r}:{type:"Double",value:r}:typeof r=="string"?{type:"String",value:r}:r instanceof Date?{type:"Date",value:r}:Array.isArray(r)?{type:"Array",value:r}:typeof r=="function"?{type:"Object",value:{type:"jsfunction",func:r,thisArg:e??null}}:typeof r=="object"?{type:"Object",value:r}:{type:"String",value:String(r)}}class Oe{globalScope;currentScope;functionRegistry;classRegistry;optionExplicit=!1;onErrorResumeNext=!1;lastError=null;err={number:0,description:"",source:""};currentInstance=null;inPropertyGet=!1;propertyGetName="";evaluate=null;checkTimeout=null;execute=null;executeGlobal=null;withStack=[];callStack=[];exitFlag="none";constructor(){this.globalScope=new Z,this.currentScope=this.globalScope,this.functionRegistry=new Pe,this.classRegistry=new De}pushScope(){const e=new Z(this.currentScope);return this.currentScope=e,e}popScope(){this.currentScope.parent&&(this.currentScope=this.currentScope.parent)}pushWith(e){this.withStack.push(e)}popWith(){this.withStack.pop()}getCurrentWith(){return this.withStack[this.withStack.length-1]}pushCall(e){this.callStack.push(e)}popCall(){this.callStack.pop()}getCurrentCall(){return this.callStack[this.callStack.length-1]}setExitFlag(e){this.exitFlag=e}getExitFlag(){return this.exitFlag}clearExitFlag(){this.exitFlag="none"}setError(e){this.lastError=e,this.err.number=e.number,this.err.description=e.description,this.err.source=e.source}clearError(){this.lastError=null,this.err.number=0,this.err.description="",this.err.source=""}declareVariable(e,t=m){this.currentScope.declare(e,t)}getVariable(e){if(this.currentInstance&&this.currentInstance.hasProperty(e))return this.currentInstance.getProperty(e);const t=this.currentScope.get(e);if(t)return t.value;const s=e.toLowerCase();for(const a of Object.keys(globalThis))if(a.toLowerCase()===s){const i=globalThis[a];return re(i,globalThis)}const n=["eval","parseInt","parseFloat","isNaN","isFinite","decodeURI","decodeURIComponent","encodeURI","encodeURIComponent","escape","unescape"];for(const a of n)if(a.toLowerCase()===s&&a in globalThis){const i=globalThis[a];return re(i,globalThis)}if(this.optionExplicit)throw new P(500,`Variable is undefined: '${e}'`,"Vbscript");return m}setVariable(e,t){if(this.inPropertyGet&&e.toLowerCase()===this.propertyGetName){this.currentScope.set(e,t);return}if(this.currentInstance&&this.currentInstance.hasProperty(e)){this.currentInstance.setProperty(e,t);return}if(this.optionExplicit&&!this.currentScope.has(e)&&!(e.toLowerCase()in globalThis))throw new P(500,`Variable is undefined: '${e}'`,"Vbscript");this.currentScope.set(e,t)}hasVariable(e){return this.currentScope.has(e)?!0:e.toLowerCase()in globalThis}}const se=new Map;function Ae(r){for(const e of r)se.has(e)||se.set(e,{type:"String",value:e})}Ae(["true","false","empty","null","nothing","dim","redim","const","public","private","sub","function","class","end","exit","if","then","else","elseif","for","next","to","step","each","in","do","loop","while","until","wend","select","case","default","and","or","not","xor","eqv","imp","new","set","call","byval","byref","option","explicit","on","error","resume","with","property","get","let","msgbox","inputbox","i","j","k","n","x","y","z","count","index","item","key","value","name","text","data","result","obj","arr","str","num","val","document","window","console"]);function Ve(r){return r.type==="method"&&"object"in r&&"method"in r}function Be(r){return r.type==="jsfunction"&&"func"in r}class ne{constructor(e){this.context=e}evaluateProgram(e){let t=m;for(const s of e.body)s.type==="ExpressionStatement"?t=this.evaluate(s.expression):t=this.evaluate(s);return t}evaluate(e){switch(e.type){case"Identifier":return this.evaluateIdentifier(e);case"Literal":return this.evaluateLiteral(e);case"VbEmptyLiteral":return m;case"VbNewExpression":return this.evaluateNew(e);case"ThisExpression":return this.evaluateMe(e);case"VbWithObject":return this.evaluateWithObject(e);case"MemberExpression":return this.evaluateMember(e);case"CallExpression":return this.evaluateCallInternal(e.callee,e.arguments);case"BinaryExpression":return this.evaluateBinary(e);case"UnaryExpression":return this.evaluateUnary(e);case"LogicalExpression":return this.evaluateLogical(e);case"AssignmentExpression":return this.evaluateAssignment(e);case"ConditionalExpression":return this.evaluateConditional(e);default:return m}}evaluateCall(e,t){return this.evaluateCallInternal(e,t)}evaluateIdentifier(e){const t=e.name;return this.context.functionRegistry.has(t)?this.context.functionRegistry.call(t,[]):this.context.getVariable(t)}evaluateLiteral(e){return C(e.value)}evaluateNew(e){const t=e.callee.name,s=e.arguments.map(a=>this.evaluate(a));return{type:"Object",value:this.context.classRegistry.createInstance(t,s)}}evaluateMe(e){if(this.context.currentInstance)return{type:"Object",value:this.context.currentInstance};throw new Error("Me keyword not supported outside of class context")}evaluateWithObject(e){const t=this.context.getCurrentWith();if(!t)throw new Error("With object not available - must be inside a With statement");return t}evaluateMember(e){let t=this.evaluate(e.object);e.object.type==="VbWithObject"&&(t=this.evaluateWithObject(e.object));let s;if(e.computed){const n=this.evaluate(e.property);s=y(n)}else s=e.property.name;if(t.type==="Array")return this.getArrayElement(t,e.property);if(t.type==="Object")return this.getObjectProperty(t,s);throw x(w.ObjectRequired,"Object required","Vbscript")}getArrayElement(e,t){const s=e.value,n=l(this.evaluate(t));return s.get([Math.floor(n)])}getObjectProperty(e,t){const s=e.value;if(s===null)throw x(w.ObjectRequired,"Object required","Vbscript");if(typeof s.getProperty=="function")return s.hasMethod?.(t)?{type:"Object",value:{type:"method",object:s,method:t}}:s.getProperty(t);const n=s[t];return n===void 0?{type:"Empty",value:void 0}:typeof n=="function"?{type:"Object",value:{type:"jsfunction",func:n,thisArg:s}}:this.jsToVb(n)}jsToVb(e){return e===void 0?{type:"Empty",value:void 0}:e===null?{type:"Null",value:null}:typeof e=="boolean"?{type:"Boolean",value:e}:typeof e=="number"?Number.isInteger(e)&&e>=-2147483648&&e<=2147483647?{type:"Long",value:e}:{type:"Double",value:e}:typeof e=="string"?{type:"String",value:e}:e instanceof Date?{type:"Date",value:e}:Array.isArray(e)?{type:"Array",value:e}:typeof e=="object"?{type:"Object",value:e}:{type:"String",value:String(e)}}evaluateCallInternal(e,t){if(e.type==="Identifier"){const n=e.name;if(this.context.functionRegistry.has(n)){if(this.context.functionRegistry.get(n).params.some(h=>h.byRef)){const h=t.map(g=>{if(g.type==="Identifier"){const v=g.name,S=this.context.currentScope.get(v);return{value:S?S.value:this.context.getVariable(v),variableName:v,setValue:k=>{this.context.currentScope.has(v)?this.context.currentScope.set(v,k):this.context.setVariable(v,k)}}}return{value:this.evaluate(g)}});return this.context.functionRegistry.callWithRefs(n,h)}const p=t.map(h=>this.evaluate(h));return this.context.functionRegistry.call(n,p)}const a=this.context.currentScope.get(n);if(a){if(a.value.type==="Array"){const o=t.map(p=>Math.floor(l(this.evaluate(p))));return a.value.value.get(o)}if(a.value.type==="Object"&&a.value.value!==null){const o=a.value.value;if(o.hasMethod?.("default")&&o.getMethod){const c=o.getMethod("default"),p=t.map(h=>this.evaluate(h));return c.func(...p)}}}const i=this.context.getVariable(n);if(i.type==="Object"&&i.value!==null)return this.callObjectMethod(i,t);throw x(w.InvalidProcedureCall,"Invalid procedure call","Vbscript")}if(e.type==="MemberExpression"){const n=this.evaluateMember(e);if(n.type==="Object"&&n.value!==null)return this.callObjectMethod(n,t);throw x(w.InvalidProcedureCall,"Invalid procedure call","Vbscript")}const s=this.evaluate(e);if(s.type==="Object"&&s.value!==null)return this.callObjectMethod(s,t);throw x(w.InvalidProcedureCall,"Invalid procedure call","Vbscript")}callObjectMethod(e,t){const s=e.value;if(s===null)throw x(w.ObjectRequired,"Object required","Vbscript");if(Ve(s)){const n=t.map(a=>this.evaluate(a));return s.object.getMethod(s.method).func.call(s.object,...n)}if(Be(s)){const n=t.map(i=>{const o=this.evaluate(i);return this.vbToJs(o)}),a=s.func.call(s.thisArg,...n);return this.jsToVb(a)}if(typeof s.call=="function"){const n=t.map(a=>this.evaluate(a));return s.call(...n)}throw x(w.InvalidProcedureCall,"Invalid procedure call","Vbscript")}vbToJs(e){switch(e.type){case"Empty":return;case"Null":return null;case"Boolean":case"Long":case"Double":case"Integer":case"String":return e.value;case"Date":return e.value instanceof Date?e.value:new Date(e.value);case"Array":return e.value;case"Object":const t=e.value;return t&&typeof t=="object"&&t.type==="vbref"?t.func:e.value;default:return e.value}}evaluateBinary(e){const t=this.evaluate(e.left),s=this.evaluate(e.right);switch(e.operator){case"+":return this.add(t,s);case"-":return this.subtract(t,s);case"*":return this.multiply(t,s);case"/":return this.divide(t,s);case"\\":return this.integerDivide(t,s);case"%":case"Mod":return this.modulo(t,s);case"**":case"^":return this.power(t,s);case"==":case"=":return this.equals(t,s);case"!=":case"<>":return this.notEquals(t,s);case"<":return this.lessThan(t,s);case"<=":return this.lessThanOrEqual(t,s);case">":return this.greaterThan(t,s);case">=":return this.greaterThanOrEqual(t,s);case"&":return{type:"String",value:y(t)+y(s)};case"Is":return{type:"Boolean",value:t.type==="Object"&&s.type==="Object"&&t.value===s.value};default:return m}}add(e,t){if(e.type==="Null"||t.type==="Null")return N;if(e.type==="String"||t.type==="String")return{type:"String",value:y(e)+y(t)};const s=l(e),n=l(t);return C(s+n)}subtract(e,t){if(e.type==="Null"||t.type==="Null")return N;const s=l(e),n=l(t);return C(s-n)}multiply(e,t){if(e.type==="Null"||t.type==="Null")return N;const s=l(e),n=l(t);return C(s*n)}divide(e,t){if(e.type==="Null"||t.type==="Null")return N;const s=l(e),n=l(t);if(n===0)throw x(w.DivisionByZero,"Division by zero","Vbscript");return{type:"Double",value:s/n}}integerDivide(e,t){if(e.type==="Null"||t.type==="Null")return N;const s=l(e),n=l(t);if(n===0)throw x(w.DivisionByZero,"Division by zero","Vbscript");return{type:"Long",value:Math.floor(s/n)}}modulo(e,t){if(e.type==="Null"||t.type==="Null")return N;const s=l(e),n=l(t);if(n===0)throw x(w.DivisionByZero,"Division by zero","Vbscript");return C(s%n)}power(e,t){if(e.type==="Null"||t.type==="Null")return N;const s=l(e),n=l(t);return{type:"Double",value:Math.pow(s,n)}}equals(e,t){return e.type==="Empty"&&t.type==="Empty"?{type:"Boolean",value:!0}:e.type==="Null"||t.type==="Null"?{type:"Boolean",value:!1}:e.type==="Object"&&t.type==="Object"?{type:"Boolean",value:e.value===t.value}:e.type==="String"||t.type==="String"?{type:"Boolean",value:y(e).toLowerCase()===y(t).toLowerCase()}:{type:"Boolean",value:l(e)===l(t)}}notEquals(e,t){return{type:"Boolean",value:!this.equals(e,t).value}}lessThan(e,t){return e.type==="String"||t.type==="String"?{type:"Boolean",value:y(e)<y(t)}:{type:"Boolean",value:l(e)<l(t)}}lessThanOrEqual(e,t){return e.type==="String"||t.type==="String"?{type:"Boolean",value:y(e)<=y(t)}:{type:"Boolean",value:l(e)<=l(t)}}greaterThan(e,t){return e.type==="String"||t.type==="String"?{type:"Boolean",value:y(e)>y(t)}:{type:"Boolean",value:l(e)>l(t)}}greaterThanOrEqual(e,t){return e.type==="String"||t.type==="String"?{type:"Boolean",value:y(e)>=y(t)}:{type:"Boolean",value:l(e)>=l(t)}}evaluateUnary(e){const t=this.evaluate(e.argument);switch(e.operator){case"-":return C(-l(t));case"+":return C(l(t));case"!":case"Not":return{type:"Boolean",value:!d(t)};default:return m}}evaluateLogical(e){switch(e.operator){case"&&":case"And":{const t=this.evaluate(e.left);return d(t)?this.evaluate(e.right):t}case"||":case"Or":{const t=this.evaluate(e.left);return d(t)?t:this.evaluate(e.right)}case"Xor":{const t=this.evaluate(e.left),s=this.evaluate(e.right);return{type:"Boolean",value:d(t)!==d(s)}}case"Eqv":{const t=this.evaluate(e.left),s=this.evaluate(e.right);return{type:"Boolean",value:d(t)===d(s)}}case"Imp":{const t=this.evaluate(e.left),s=this.evaluate(e.right);return{type:"Boolean",value:!d(t)||d(s)}}default:return m}}evaluateAssignment(e){const t=this.evaluate(e.right),s=e.isSet??!1;if(e.left.type==="Identifier"){if(s){const n=this.context.getVariable(e.left.name);this.callTerminateIfNeeded(n,t)}return this.context.setVariable(e.left.name,t),t}if(e.left.type==="MemberExpression")return this.assignToMember(e.left,t,s),t;throw new Error(`Invalid assignment target: ${e.left.type}`)}callTerminateIfNeeded(e,t){if(e.type==="Object"&&e.value instanceof ee&&(t.type!=="Object"||t.value!==e.value)){const s=e.value,n=s.classInfo.properties.get("class_terminate");n&&n.get&&n.get.call(s)}}assignToMember(e,t,s){let n=this.evaluate(e.object);e.object.type==="VbWithObject"&&(n=this.evaluateWithObject(e.object));let a;if(e.computed){const i=this.evaluate(e.property);a=y(i)}else a=e.property.name;if(n.type==="Array"){const i=n.value,o=l(this.evaluate(e.property));i.set([Math.floor(o)],t)}else if(n.type==="Object"){const i=n.value;if(i===null||typeof i!="object")throw x(w.ObjectRequired,"Object required","Vbscript");if(typeof i.setProperty=="function")i.setProperty(a,t,s);else{const o=this.vbToJs(t);i[a]=o}}else throw x(w.ObjectRequired,"Object required","Vbscript")}evaluateConditional(e){const t=this.evaluate(e.test);return d(t)?this.evaluate(e.consequent):this.evaluate(e.alternate)}}class E extends Error{constructor(e,t){super(e),this.type=e,this.value=t}}class U extends E{constructor(e){super("goto"),this.labelName=e}}class Me{constructor(e){this.context=e,this.exprEvaluator=new ne(e)}exprEvaluator;execute(e){try{switch(e.type){case"ExpressionStatement":return this.executeExpressionStatement(e);case"BlockStatement":return this.executeBlockStatement(e);case"IfStatement":return this.executeIfStatement(e);case"VbDimStatement":return this.executeDimStatement(e);case"VbReDimStatement":return this.executeReDimStatement(e);case"VbEraseStatement":return this.executeEraseStatement(e);case"VbConstStatement":return this.executeConstStatement(e);case"VbForToStatement":return this.executeForToStatement(e);case"VbForEachStatement":return this.executeForEachStatement(e);case"VbDoLoopStatement":return this.executeDoLoopStatement(e);case"VbSelectCaseStatement":return this.executeSelectCaseStatement(e);case"VbWithStatement":return this.executeWithStatement(e);case"VbExitStatement":return this.executeExitStatement(e);case"VbOptionExplicitStatement":return this.executeOptionExplicitStatement(e);case"VbSubStatement":return this.executeSubStatement(e);case"VbFunctionStatement":return this.executeFunctionStatement(e);case"VbClassStatement":return this.executeClassStatement(e);case"VbPropertyGetStatement":case"VbPropertyLetStatement":case"VbPropertySetStatement":return this.executePropertyStatement(e);case"VbOnErrorHandlerStatement":return this.executeOnErrorHandlerStatement(e);case"VbCallStatement":return this.executeCallStatement(e);case"VbGotoStatement":return this.executeGotoStatement(e);case"VbLabelStatement":return m;case"ReturnStatement":throw new E("return");default:throw new Error(`Unknown statement type: ${e.type}`)}}catch(t){if(t instanceof E)throw t;if(t instanceof P){if(this.context.setError(t),this.context.onErrorResumeNext)return m;throw t}const s=P.fromError(t);if(this.context.setError(s),this.context.onErrorResumeNext)return m;throw s}}executeExpressionStatement(e){return this.exprEvaluator.evaluate(e.expression)}executeCallStatement(e){return this.exprEvaluator.evaluateCall(e.callee,e.arguments)}executeBlockStatement(e){let t=m;for(const s of e.body)t=this.execute(s);return t}executeIfStatement(e){const t=this.exprEvaluator.evaluate(e.test);return d(t)?this.execute(e.consequent):e.alternate?this.execute(e.alternate):m}executeDimStatement(e){for(const t of e.declarations){let s=m;if(t.isArray&&t.arrayBounds){const n=t.arrayBounds.map(i=>{const o=this.exprEvaluator.evaluate(i);return l(o)});s={type:"Array",value:G(n)}}else t.init&&(s=this.exprEvaluator.evaluate(t.init));this.context.declareVariable(t.id.name,s)}return m}executeReDimStatement(e){for(const t of e.declarations){if(!t.isArray||!t.arrayBounds)continue;const s=t.arrayBounds.map(a=>{const i=this.exprEvaluator.evaluate(a);return l(i)}),n=this.context.currentScope.get(t.id.name);if(n&&n.value.type==="Array")n.value.value.redim(s,e.preserve);else{const a=G(s);this.context.setVariable(t.id.name,{type:"Array",value:a})}}return m}executeEraseStatement(e){const t=e.arrayName.name,s=this.context.currentScope.get(t);if(!s)throw new Error(`Variable '${t}' not defined`);if(s.value.type!=="Array")throw new Error(`Type mismatch: '${t}' is not an array`);return s.value.value.erase(),m}executeConstStatement(e){for(const t of e.declarations){const s=this.exprEvaluator.evaluate(t.init);this.context.currentScope.declare(t.id.name,s,{isConst:!0})}return m}executeForToStatement(e){const t=this.exprEvaluator.evaluate(e.init),s=this.exprEvaluator.evaluate(e.to),n=e.step?this.exprEvaluator.evaluate(e.step):C(1),a=l(t),i=l(s),o=l(n);this.context.declareVariable(e.left.name,C(a));const c=o>0?()=>l(this.context.getVariable(e.left.name))<=i:()=>l(this.context.getVariable(e.left.name))>=i;for(;c();){this.context.checkTimeout&&this.context.checkTimeout();try{this.execute(e.body)}catch(h){if(h instanceof E){if(h.type==="exit"&&this.context.getExitFlag()==="for"){this.context.clearExitFlag();break}if(h.type==="return")throw h}throw h}const p=l(this.context.getVariable(e.left.name));this.context.setVariable(e.left.name,C(p+o))}return m}executeForEachStatement(e){const t=this.exprEvaluator.evaluate(e.right);if(t.type!=="Array"&&t.type!=="Object")throw x(w.TypeMismatch,"Type mismatch: expected array or collection","Vbscript");let s;if(t.type==="Array")s=t.value.toArray();else{const n=t.value,a=n.getProperty("Count"),i=l(a);s=[];for(let o=0;o<i;o++)s.push(n.getProperty(String(o)))}this.context.declareVariable(e.left.name,m);for(const n of s){this.context.setVariable(e.left.name,n);try{this.execute(e.body)}catch(a){if(a instanceof E){if(a.type==="exit"&&this.context.getExitFlag()==="for"){this.context.clearExitFlag();break}if(a.type==="return")throw a}throw a}}return m}executeDoLoopStatement(e){const t=()=>{if(!e.test)return!0;const a=this.exprEvaluator.evaluate(e.test);return d(a)},s=e.testPosition==="while-do"||e.testPosition==="do-while",n=e.testPosition==="while-do"||e.testPosition==="until-do";for(;this.context.checkTimeout&&this.context.checkTimeout(),!(n&&!(s?t():!t()));){try{this.execute(e.body)}catch(a){if(a instanceof E){if(a.type==="exit"&&this.context.getExitFlag()==="do"){this.context.clearExitFlag();break}if(a.type==="return")throw a}throw a}if(!n&&!(s?t():!t()))break}return m}executeSelectCaseStatement(e){const t=this.exprEvaluator.evaluate(e.discriminant);for(const s of e.cases){if(s.isElse){for(const a of s.consequent)this.execute(a);return m}if(this.matchCase(s.test,t)){for(const a of s.consequent)this.execute(a);return m}}return m}matchCase(e,t){if(!e)return!1;const s=Array.isArray(e)?e:[e];for(const n of s)if(n.type==="BinaryExpression"&&"left"in n&&n.left.type==="Identifier"&&n.left.name==="__select_expr__"){const a=this.exprEvaluator.evaluate(n.right);switch(n.operator){case"==":if(d(this.equals(t,a)))return!0;break;case"<":if(l(t)<l(a))return!0;break;case">":if(l(t)>l(a))return!0;break;case"<=":if(l(t)<=l(a))return!0;break;case">=":if(l(t)>=l(a))return!0;break;case"!=":if(!d(this.equals(t,a)))return!0;break}}else{const a=this.exprEvaluator.evaluate(n);if(d(this.equals(t,a)))return!0}return!1}equals(e,t){if(e.type==="Empty"&&t.type==="Empty")return{type:"Boolean",value:!0};if(e.type==="Null"||t.type==="Null")return{type:"Boolean",value:!1};if(e.type==="String"||t.type==="String"){const s=e.type==="String"?e.value:String(l(e)),n=t.type==="String"?t.value:String(l(t));return{type:"Boolean",value:s.toLowerCase()===n.toLowerCase()}}return{type:"Boolean",value:l(e)===l(t)}}executeWithStatement(e){const t=this.exprEvaluator.evaluate(e.object);this.context.pushWith(t);try{this.execute(e.body)}finally{this.context.popWith()}return m}executeExitStatement(e){throw this.context.setExitFlag(e.target.toLowerCase()),new E("exit")}executeOptionExplicitStatement(e){return this.context.optionExplicit=!0,m}executeSubStatement(e){const t=e.name.name,s=this,n=function(i){s.context.pushScope(),s.context.pushCall(t);try{s.bindParameters(e.params,i),s.executeBlockStatement(e.body),s.updateByRefArgs(e.params,i)}catch(o){if(o instanceof E&&o.type==="return")s.updateByRefArgs(e.params,i);else throw o}finally{s.context.popCall(),s.context.popScope()}return m},a=e.params.map(i=>({name:i.name.name,byRef:i.byRef,isArray:i.isArray,isOptional:i.isOptional,isParamArray:i.isParamArray}));return this.context.functionRegistry.register(t,n,{isSub:!0,params:a,isUserDefined:!0}),m}executeFunctionStatement(e){const t=e.name.name,s=this,n=function(i){s.context.pushScope(),s.context.pushCall(t),s.context.declareVariable(t,m);let o=m;try{s.bindParameters(e.params,i),s.executeBlockStatement(e.body),s.updateByRefArgs(e.params,i),o=s.context.getVariable(t)}catch(c){if(c instanceof E&&c.type==="return")s.updateByRefArgs(e.params,i),o=s.context.getVariable(t);else throw c}finally{s.context.popCall(),s.context.popScope()}return o},a=e.params.map(i=>({name:i.name.name,byRef:i.byRef,isArray:i.isArray,isOptional:i.isOptional,isParamArray:i.isParamArray}));return this.context.functionRegistry.register(t,n,{params:a,isUserDefined:!0}),m}bindParameters(e,t){let s=0;for(const n of e)if(n.isParamArray){const a=[];for(;s<t.length;)a.push(t[s++]);const i=G([a.length]);a.forEach((o,c)=>i.set([c],o)),this.context.declareVariable(n.name.name,{type:"Array",value:i})}else{let a;s<t.length?a=t[s++]:n.defaultValue?a=this.exprEvaluator.evaluate(n.defaultValue):(n.isOptional,a=m),this.context.declareVariable(n.name.name,a)}}updateByRefArgs(e,t){let s=0;for(const n of e){if(n.isParamArray)break;s<t.length&&n.byRef&&(t[s]=this.context.getVariable(n.name.name)),s++}}executeClassStatement(e){const t=e.name.name,s=new Q(t),n=this;let a,i;for(const o of e.body)if(o.type==="VbDimStatement")for(const c of o.declarations)s.properties.set(c.id.name.toLowerCase(),{name:c.id.name});else if(o.type==="VbSubStatement"){const c=o,p=o.name.name.toLowerCase();if(p==="class_initialize"){a={name:"Class_Initialize",get:function(){const h=n.context.currentInstance;n.context.currentInstance=this,n.context.pushScope();try{n.executeBlockStatement(c.body)}finally{n.context.popScope(),n.context.currentInstance=h}return m}};continue}if(p==="class_terminate"){i={name:"Class_Terminate",get:function(){const h=n.context.currentInstance;n.context.currentInstance=this,n.context.pushScope();try{n.executeBlockStatement(c.body)}finally{n.context.popScope(),n.context.currentInstance=h}return m}};continue}s.methods.set(p,{name:o.name.name,func:function(...h){const g=n.context.currentInstance;n.context.currentInstance=this,n.context.pushScope();try{n.bindParameters(c.params,h),n.executeBlockStatement(c.body)}finally{n.context.popScope(),n.context.currentInstance=g}return m},isSub:!0})}else if(o.type==="VbFunctionStatement"){const c=o;s.methods.set(o.name.name.toLowerCase(),{name:o.name.name,func:function(...p){const h=n.context.currentInstance;n.context.currentInstance=this,n.context.pushScope(),n.context.declareVariable(c.name.name,m),n.bindParameters(c.params,p);let g=m;try{n.executeBlockStatement(c.body),g=n.context.getVariable(c.name.name)}catch(v){if(v instanceof E&&v.type==="return")g=n.context.getVariable(c.name.name);else throw v}finally{n.context.popScope(),n.context.currentInstance=h}return g},isSub:!1})}else if(o.type==="VbPropertyGetStatement"){const c=o,p=o.name.name.toLowerCase(),h=s.properties.get(p)||{name:o.name.name};h.get=function(){const g=n.context.currentInstance,v=n.context.inPropertyGet,S=n.context.propertyGetName;n.context.currentInstance=this,n.context.inPropertyGet=!0,n.context.propertyGetName=c.name.name.toLowerCase(),n.context.pushScope(),n.context.declareVariable(c.name.name,m);try{return n.executeBlockStatement(c.body),n.context.currentScope.get(c.name.name)?.value??m}finally{n.context.popScope(),n.context.currentInstance=g,n.context.inPropertyGet=v,n.context.propertyGetName=S}},s.properties.set(p,h)}else if(o.type==="VbPropertyLetStatement"){const c=o,p=o.name.name.toLowerCase(),h=s.properties.get(p)||{name:o.name.name};h.let=function(g){const v=n.context.currentInstance;n.context.currentInstance=this,n.context.pushScope(),n.context.declareVariable(c.name.name,m);const S=c.params[0];S&&n.context.declareVariable(S.name.name,g);try{n.executeBlockStatement(c.body)}finally{n.context.popScope(),n.context.currentInstance=v}},s.properties.set(p,h)}else if(o.type==="VbPropertySetStatement"){const c=o,p=o.name.name.toLowerCase(),h=s.properties.get(p)||{name:o.name.name};h.set=function(g){const v=n.context.currentInstance;n.context.currentInstance=this,n.context.pushScope(),n.context.declareVariable(c.name.name,m);const S=c.params[0];S&&n.context.declareVariable(S.name.name,g);try{n.executeBlockStatement(c.body)}finally{n.context.popScope(),n.context.currentInstance=v}},s.properties.set(p,h)}return a&&s.properties.set("class_initialize",a),i&&s.properties.set("class_terminate",i),this.context.classRegistry.register(s),m}executePropertyStatement(e){return m}executeOnErrorHandlerStatement(e){return e.action==="resume_next"?this.context.onErrorResumeNext=!0:e.action==="goto_0"&&(this.context.onErrorResumeNext=!1,this.context.clearError()),m}executeGotoStatement(e){throw new U(e.label.name.toLowerCase())}}const V=new Map([["af",1078],["sq",1052],["ar-ae",14337],["ar-bh",15361],["ar-dz",5121],["ar-eg",3073],["ar-iq",2049],["ar-jo",11265],["ar-kw",13313],["ar-lb",12289],["ar-ly",4097],["ar-ma",6145],["ar-om",8193],["ar-qa",16385],["ar-sa",1025],["ar-sy",10241],["ar-tn",7169],["ar-ye",9217],["hy",1067],["az",1068],["az-Latn",1068],["az-Cyrl",2092],["eu",1069],["be",1059],["bg",1026],["ca",1027],["zh-cn",2052],["zh-hk",3076],["zh-mo",5124],["zh-sg",4100],["zh-tw",1028],["zh",2052],["hr",1050],["cs",1029],["da",1030],["nl-nl",1043],["nl-be",2067],["nl",1043],["en-au",3081],["en-bz",10249],["en-ca",4105],["en-cb",9225],["en-ie",6153],["en-jm",8201],["en-nz",5129],["en-ph",13321],["en-za",7177],["en-tt",11273],["en-gb",2057],["en-us",1033],["en",1033],["et",1061],["fa",1065],["fi",1035],["fo",1080],["fr-fr",1036],["fr-be",2060],["fr-ca",3084],["fr-lu",5132],["fr-ch",4108],["fr",1036],["gd-ie",2108],["gd",1084],["de-de",1031],["de-at",3079],["de-li",5127],["de-lu",4103],["de-ch",2055],["de",1031],["el",1032],["he",1037],["hi",1081],["hu",1038],["is",1039],["id",1057],["it-it",1040],["it-ch",2064],["it",1040],["ja",1041],["ko",1042],["lv",1062],["lt",1063],["mk",1071],["ms-my",1086],["ms-bn",2110],["ms",1086],["mt",1082],["mr",1102],["no",1044],["nb",1044],["nn",2068],["pl",1045],["pt-pt",2070],["pt-br",1046],["pt",1046],["rm",1047],["ro",1048],["ro-md",2072],["ru",1049],["ru-md",2073],["sa",1103],["sr-Cyrl",3098],["sr-Latn",2074],["sr",3098],["tn",1074],["sl",1060],["sk",1051],["sb",1070],["es-es",1034],["es-ar",11274],["es-bo",16394],["es-cl",13322],["es-co",9226],["es-cr",5130],["es-do",7178],["es-ec",12298],["es-gt",4106],["es-hn",18442],["es-mx",2058],["es-ni",19466],["es-pa",6154],["es-pe",10250],["es-pr",20490],["es-py",15370],["es-sv",17418],["es-uy",14346],["es-ve",8202],["es",1034],["sx",1072],["sw",1089],["sv-se",1053],["sv-fi",2077],["sv",1053],["ta",1097],["tt",1092],["th",1054],["tr",1055],["ts",1073],["uk",1058],["ur",1056],["uz-Cyrl",2115],["uz-Latn",1091],["uz",1091],["vi",1066],["xh",1076],["yi",1085],["zu",1077]]),ae=new Map;V.forEach((r,e)=>{ae.set(r,e)});let B=null;function Re(r){return r.toLowerCase().replace(/_/g,"-")}function q(r){for(const e of V.keys())if(e.toLowerCase()===r)return e}function z(){if(B)return B;const r=Intl.DateTimeFormat().resolvedOptions().locale||"en-US",e=Re(r),t=q(e);if(t)return t;const s=e.split("-")[0]??"en",n=q(s);return n||"en"}function Y(){const r=z();return{type:"Long",value:V.get(r)??1033}}function Fe(r){const e=typeof r.value=="number"?r.value:parseInt(String(r.value),10);if(isNaN(e)){const s=String(r.value).toLowerCase(),n=q(s);return n?(B=n,{type:"Long",value:V.get(n)??1033}):Y()}const t=ae.get(e);return t?(B=t,{type:"Long",value:e}):Y()}function O(){return z()}const ie=new Map([["en-us","USD"],["en-gb","GBP"],["en-au","AUD"],["en-ca","CAD"],["en-nz","NZD"],["en-za","ZAR"],["de-de","EUR"],["de-at","EUR"],["de-ch","CHF"],["fr-fr","EUR"],["fr-be","EUR"],["fr-ca","CAD"],["fr-ch","CHF"],["ja","JPY"],["zh-cn","CNY"],["zh-tw","TWD"],["zh-hk","HKD"],["ko","KRW"],["it","EUR"],["es","EUR"],["es-mx","MXN"],["pt-br","BRL"],["pt-pt","EUR"],["ru","RUB"],["pl","PLN"],["nl","EUR"],["sv","SEK"],["da","DKK"],["no","NOK"],["fi","EUR"],["cs","CZK"],["hu","HUF"],["tr","TRY"],["th","THB"],["id","IDR"],["ms","MYR"],["vi","VND"],["in","INR"],["hi","INR"],["ar-sa","SAR"],["ar-eg","EGP"],["ar-ae","AED"],["he","ILS"],["en-ie","EUR"],["en-ph","PHP"],["en-in","INR"]]);function je(){const r=z(),e=ie.get(r);if(e)return e;const t=r.split("-")[0]??"en",s=ie.get(t);return s||"USD"}const Te={GetLocale:Y,SetLocale:Fe};function We(r,e){const t=[];let s=0;for(;s<e.length;){const n=e[s].toLowerCase();let a=1;for(;s+a<e.length&&e[s+a].toLowerCase()===n;)a++;switch(n){case"y":a>=4||a===3?t.push(r.getFullYear().toString()):t.push(r.getFullYear().toString().slice(-2));break;case"m":if(a>=4){const i=["January","February","March","April","May","June","July","August","September","October","November","December"];t.push(i[r.getMonth()])}else if(a===3){const i=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];t.push(i[r.getMonth()])}else a===2?t.push((r.getMonth()+1).toString().padStart(2,"0")):t.push((r.getMonth()+1).toString());break;case"d":if(a>=4){const i=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];t.push(i[r.getDay()])}else if(a===3){const i=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];t.push(i[r.getDay()])}else a===2?t.push(r.getDate().toString().padStart(2,"0")):t.push(r.getDate().toString());break;case"h":a>=2?t.push((r.getHours()%12||12).toString().padStart(2,"0")):t.push((r.getHours()%12||12).toString());break;case"n":a>=2?t.push(r.getMinutes().toString().padStart(2,"0")):t.push(r.getMinutes().toString());break;case"s":a>=2?t.push(r.getSeconds().toString().padStart(2,"0")):t.push(r.getSeconds().toString());break;case"q":t.push(Math.floor(r.getMonth()/3+1).toString());break;case"w":t.push((r.getDay()+1).toString());break;case"a":a>=2?t.push(r.getHours()>=12?"PM":"AM"):t.push(r.getHours()>=12?"P":"A");break;default:t.push(e.substring(s,s+a))}s+=a}return t.join("")}function Ge(r,e){let t=e,s="",n="";const a=e.indexOf(";");if(a!==-1){t=e.substring(0,a);const i=e.substring(a+1),o=i.indexOf(";");o!==-1?(s=i.substring(0,o),n=i.substring(o+1)):s=i}return r===0&&n?M(0,n):r<0&&s?M(Math.abs(r),s):r<0?"-"+M(Math.abs(r),t):M(r,t)}function M(r,e){let t=e.includes("%");t&&(r*=100);const s=e.toLowerCase();let n=s.indexOf("."),a=0;if(n!==-1){let g=n+1;for(;g<e.length&&(e[g]==="0"||e[g]==="#");)a++,g++}let i=Math.floor(Math.abs(r)),o=a>0?Math.round((Math.abs(r)-i)*Math.pow(10,a)):0;o>=Math.pow(10,a)&&(i++,o=0);let c=i.toString();s.indexOf(",")!==-1&&(c=c.replace(/\B(?=(\d{3})+(?!\d))/g,","));let h=c;if(a>0){const g=o.toString().padStart(a,"0");h+="."+g}return t&&(h+="%"),h}function _e(r,e){return e===">"||e.toLowerCase()===">"?r.toUpperCase():e==="<"||e.toLowerCase()==="<"?r.toLowerCase():r}const Ue={Len:r=>({type:"Long",value:y(r).length}),Left:(r,e)=>{const t=y(r),s=Math.max(0,Math.floor(l(e)));return{type:"String",value:t.substring(0,s)}},Right:(r,e)=>{const t=y(r),s=Math.max(0,Math.floor(l(e)));return{type:"String",value:t.substring(t.length-s)}},Mid:(r,e,t)=>{const s=y(r),n=Math.max(1,Math.floor(l(e)))-1;if(t){const a=Math.floor(l(t));return{type:"String",value:s.substring(n,n+a)}}return{type:"String",value:s.substring(n)}},InStr:(r,e,t,s)=>{let n=1,a,i,o=0;e===void 0?(a="",i=y(r)):t===void 0?(a=y(r),i=y(e)):(n=Math.max(1,Math.floor(l(r))),a=y(e),i=y(t),s&&(o=Math.floor(l(s))));let c;return o===0?c=a.indexOf(i,n-1):c=a.toLowerCase().indexOf(i.toLowerCase(),n-1),{type:"Long",value:c+1}},InStrRev:(r,e,t,s)=>{const n=y(r),a=y(e),i=t?Math.floor(l(t)):n.length,o=s?Math.floor(l(s)):0;let c;return o===0?c=n.lastIndexOf(a,i-1):c=n.toLowerCase().lastIndexOf(a.toLowerCase(),i-1),{type:"Long",value:c+1}},LCase:r=>({type:"String",value:y(r).toLowerCase()}),UCase:r=>({type:"String",value:y(r).toUpperCase()}),LTrim:r=>({type:"String",value:y(r).replace(/^\s+/,"")}),RTrim:r=>({type:"String",value:y(r).replace(/\s+$/,"")}),Trim:r=>({type:"String",value:y(r).trim()}),Replace:(r,e,t,s,n,a)=>{const i=y(r),o=y(e),c=y(t),p=s?Math.max(1,Math.floor(l(s)))-1:0,h=n?Math.floor(l(n)):-1,g=a?Math.floor(l(a)):0;let v="",S=0,k=p;const Et=g===0?i:i.toLowerCase(),Ct=g===0?o:o.toLowerCase();for(;k<i.length;){if(h!==-1&&S>=h){v+=i.substring(k);break}Et.substring(k,k+o.length)===Ct?(v+=c,k+=o.length,S++):(v+=i[k],k++)}return{type:"String",value:v}},StrReverse:r=>({type:"String",value:y(r).split("").reverse().join("")}),Space:r=>{const e=Math.max(0,Math.floor(l(r)));return{type:"String",value:" ".repeat(e)}},String:(r,e)=>{const t=Math.max(0,Math.floor(l(r))),s=y(e);return{type:"String",value:(s.length>0?s[0]:" ").repeat(t)}},Asc:r=>{const e=y(r);return{type:"Integer",value:e.length>0?e.charCodeAt(0):0}},AscW:r=>{const e=y(r);return{type:"Integer",value:e.length>0?e.charCodeAt(0):0}},Chr:r=>{const e=Math.floor(l(r));return{type:"String",value:String.fromCharCode(e)}},ChrW:r=>{const e=Math.floor(l(r));return{type:"String",value:String.fromCharCode(e)}},StrComp:(r,e,t)=>{const s=y(r),n=y(e),a=t?Math.floor(l(t)):0;let i;if(a===1)i=s.toLowerCase().localeCompare(n.toLowerCase());else if(a===2){const o=O();i=s.localeCompare(n,o,{sensitivity:"base"})}else i=s.localeCompare(n);return{type:"Integer",value:i}},Split:(r,e,t,s)=>{const n=y(r),a=e?y(e):" ",i=t?Math.floor(l(t)):-1,o=n.split(a);let c;return i>0&&o.length>i?(c=o.slice(0,i-1),c.push(o.slice(i-1).join(a))):c=o,{type:"Array",value:_(c.map(h=>({type:"String",value:h})))}},Join:(r,e)=>{const t=e?y(e):" ";if(r.type==="Array"){const s=r.value;return typeof s=="object"&&s!==null&&"toArray"in s?{type:"String",value:s.toArray().map(i=>y(i)).join(t)}:{type:"String",value:s.map(a=>y(a)).join(t)}}return{type:"String",value:""}},Format:(r,e)=>{if(r.type==="Empty"||r.type==="Null")return{type:"String",value:""};const t=e?y(e):"";return t?r.type==="Date"&&r.value instanceof Date?{type:"String",value:We(r.value,t)}:r.type==="Boolean"?{type:"String",value:r.value?"True":"False"}:["Integer","Long","Single","Double","Currency","Byte"].includes(r.type)?{type:"String",value:Ge(l(r),t)}:r.type==="String"?{type:"String",value:_e(y(r),t)}:{type:"String",value:y(r)}:{type:"String",value:y(r)}},LSet:(r,e)=>{const t=y(r),s=Math.max(0,Math.floor(l(e)));return t.length>=s?{type:"String",value:t.substring(0,s)}:{type:"String",value:t.padEnd(s," ")}},RSet:(r,e)=>{const t=y(r),s=Math.max(0,Math.floor(l(e)));return t.length>=s?{type:"String",value:t.substring(0,s)}:{type:"String",value:t.padStart(s," ")}}},qe={Abs:r=>{const e=l(r);return C(Math.abs(e))},Sgn:r=>{const e=l(r);return{type:"Integer",value:e>0?1:e<0?-1:0}},Sqr:r=>{const e=l(r);if(e<0)throw new Error("Invalid procedure call or argument: Sqr");return{type:"Double",value:Math.sqrt(e)}},Int:r=>{const e=l(r);return{type:"Long",value:Math.floor(e)}},Fix:r=>{const e=l(r);return{type:"Long",value:e>=0?Math.floor(e):Math.ceil(e)}},Round:(r,e)=>{const t=l(r),s=e?Math.floor(l(e)):0,n=Math.pow(10,s);return{type:"Double",value:Math.round(t*n)/n}},Atn:r=>{const e=l(r);return{type:"Double",value:Math.atan(e)}},Cos:r=>{const e=l(r);return{type:"Double",value:Math.cos(e)}},Sin:r=>{const e=l(r);return{type:"Double",value:Math.sin(e)}},Tan:r=>{const e=l(r);return{type:"Double",value:Math.tan(e)}},Exp:r=>{const e=l(r);return{type:"Double",value:Math.exp(e)}},Log:r=>{const e=l(r);if(e<=0)throw new Error("Invalid procedure call or argument: Log");return{type:"Double",value:Math.log(e)}},Rnd:r=>({type:"Single",value:Math.random()}),Randomize:r=>m,Oct:r=>({type:"String",value:Math.floor(l(r)).toString(8)}),Hex:r=>({type:"String",value:Math.floor(l(r)).toString(16).toUpperCase()})},ze={vbCr:{type:"String",value:"\r"},vbCrLf:{type:"String",value:`\r
|
|
13
13
|
`},vbFormFeed:{type:"String",value:"\f"},vbLf:{type:"String",value:`
|
|
14
14
|
`},vbNewLine:{type:"String",value:`\r
|
|
15
|
-
`},vbNullChar:{type:"String",value:"\0"},vbTab:{type:"String",value:" "},vbVerticalTab:{type:"String",value:"\v"},vbNullString:{type:"String",value:""},vbObjectError:{type:"Long",value:-2147221504},vbSunday:{type:"Integer",value:1},vbMonday:{type:"Integer",value:2},vbTuesday:{type:"Integer",value:3},vbWednesday:{type:"Integer",value:4},vbThursday:{type:"Integer",value:5},vbFriday:{type:"Integer",value:6},vbSaturday:{type:"Integer",value:7},vbUseSystemDayOfWeek:{type:"Integer",value:0},vbFirstJan1:{type:"Integer",value:1},vbFirstFourDays:{type:"Integer",value:2},vbFirstFullWeek:{type:"Integer",value:3},vbBinaryCompare:{type:"Integer",value:0},vbTextCompare:{type:"Integer",value:1},vbDatabaseCompare:{type:"Integer",value:2},vbGeneralDate:{type:"Integer",value:0},vbLongDate:{type:"Integer",value:1},vbShortDate:{type:"Integer",value:2},vbLongTime:{type:"Integer",value:3},vbShortTime:{type:"Integer",value:4},vbEmpty:{type:"Integer",value:0},vbNull:{type:"Integer",value:1},vbInteger:{type:"Integer",value:2},vbLong:{type:"Integer",value:3},vbSingle:{type:"Integer",value:4},vbDouble:{type:"Integer",value:5},vbCurrency:{type:"Integer",value:6},vbDate:{type:"Integer",value:7},vbString:{type:"Integer",value:8},vbObject:{type:"Integer",value:9},vbError:{type:"Integer",value:10},vbBoolean:{type:"Integer",value:11},vbVariant:{type:"Integer",value:12},vbDataObject:{type:"Integer",value:13},vbDecimal:{type:"Integer",value:14},vbByte:{type:"Integer",value:17},vbArray:{type:"Integer",value:8192},vbOKOnly:{type:"Integer",value:0},vbOKCancel:{type:"Integer",value:1},vbAbortRetryIgnore:{type:"Integer",value:2},vbYesNoCancel:{type:"Integer",value:3},vbYesNo:{type:"Integer",value:4},vbRetryCancel:{type:"Integer",value:5},vbCritical:{type:"Integer",value:16},vbQuestion:{type:"Integer",value:32},vbExclamation:{type:"Integer",value:48},vbInformation:{type:"Integer",value:64},vbDefaultButton1:{type:"Integer",value:0},vbDefaultButton2:{type:"Integer",value:256},vbDefaultButton3:{type:"Integer",value:512},vbOK:{type:"Integer",value:1},vbCancel:{type:"Integer",value:2},vbAbort:{type:"Integer",value:3},vbRetry:{type:"Integer",value:4},vbIgnore:{type:"Integer",value:5},vbYes:{type:"Integer",value:6},vbNo:{type:"Integer",value:7}};function k(r){const e=new Date(1899,11,30);return new Date(e.getTime()+r*864e5)}const _e={Now:()=>({type:"Date",value:new Date}),Date:()=>{const r=new Date;return{type:"Date",value:new Date(r.getFullYear(),r.getMonth(),r.getDate())}},Time:()=>{const r=new Date;return{type:"Date",value:new Date(0,0,0,r.getHours(),r.getMinutes(),r.getSeconds())}},Year:r=>({type:"Integer",value:(r.type==="Date"?r.value:k(c(r))).getFullYear()}),Month:r=>({type:"Integer",value:(r.type==="Date"?r.value:k(c(r))).getMonth()+1}),Day:r=>({type:"Integer",value:(r.type==="Date"?r.value:k(c(r))).getDate()}),Weekday:(r,e)=>{const t=r.type==="Date"?r.value:k(c(r)),s=e?Math.floor(c(e)):1;let n=t.getDay()+1;return n=n-s+1,n<1&&(n+=7),{type:"Integer",value:n}},Hour:r=>({type:"Integer",value:(r.type==="Date"?r.value:k(c(r))).getHours()}),Minute:r=>({type:"Integer",value:(r.type==="Date"?r.value:k(c(r))).getMinutes()}),Second:r=>({type:"Integer",value:(r.type==="Date"?r.value:k(c(r))).getSeconds()}),DateAdd:(r,e,t)=>{const s=y(r).toLowerCase(),n=c(e),a=t.type==="Date"?new Date(t.value):k(c(t));switch(s){case"yyyy":a.setFullYear(a.getFullYear()+n);break;case"q":a.setMonth(a.getMonth()+n*3);break;case"m":a.setMonth(a.getMonth()+n);break;case"y":case"d":case"w":a.setDate(a.getDate()+n);break;case"ww":a.setDate(a.getDate()+n*7);break;case"h":a.setHours(a.getHours()+n);break;case"n":a.setMinutes(a.getMinutes()+n);break;case"s":a.setSeconds(a.getSeconds()+n);break}return{type:"Date",value:a}},DateDiff:(r,e,t,s,n)=>{const a=y(r).toLowerCase(),i=e.type==="Date"?e.value:k(c(e)),o=t.type==="Date"?t.value:k(c(t)),l=o.getTime()-i.getTime();let p;switch(a){case"yyyy":p=o.getFullYear()-i.getFullYear();break;case"q":p=Math.floor((o.getFullYear()-i.getFullYear())*4+(o.getMonth()-i.getMonth())/3);break;case"m":p=(o.getFullYear()-i.getFullYear())*12+(o.getMonth()-i.getMonth());break;case"y":case"d":p=Math.floor(l/864e5);break;case"w":p=Math.floor(l/864e5);break;case"ww":p=Math.floor(l/(864e5*7));break;case"h":p=Math.floor(l/36e5);break;case"n":p=Math.floor(l/6e4);break;case"s":p=Math.floor(l/1e3);break;default:p=0}return{type:"Long",value:p}},DatePart:(r,e,t,s)=>{const n=y(r).toLowerCase(),a=e.type==="Date"?e.value:k(c(e));let i;switch(n){case"yyyy":i=a.getFullYear();break;case"q":i=Math.floor(a.getMonth()/3)+1;break;case"m":i=a.getMonth()+1;break;case"y":const o=new Date(a.getFullYear(),0,1);i=Math.floor((a.getTime()-o.getTime())/864e5)+1;break;case"d":i=a.getDate();break;case"w":i=a.getDay()+1;break;case"ww":const l=new Date(a.getFullYear(),0,1);i=Math.floor((a.getTime()-l.getTime())/(864e5*7))+1;break;case"h":i=a.getHours();break;case"n":i=a.getMinutes();break;case"s":i=a.getSeconds();break;default:i=0}return{type:"Integer",value:i}},DateSerial:(r,e,t)=>{const s=Math.floor(c(r)),n=Math.floor(c(e)),a=Math.floor(c(t));return{type:"Date",value:new Date(s,n-1,a)}},TimeSerial:(r,e,t)=>{const s=Math.floor(c(r)),n=Math.floor(c(e)),a=Math.floor(c(t));return{type:"Date",value:new Date(0,0,0,s,n,a)}},DateValue:r=>{const e=new Date(y(r));if(isNaN(e.getTime()))throw new Error("Type mismatch: DateValue");return{type:"Date",value:new Date(e.getFullYear(),e.getMonth(),e.getDate())}},TimeValue:r=>{const e=new Date(y(r));if(isNaN(e.getTime()))throw new Error("Type mismatch: TimeValue");return{type:"Date",value:new Date(0,0,0,e.getHours(),e.getMinutes(),e.getSeconds())}},MonthName:(r,e)=>{const t=Math.floor(c(r)),s=["January","February","March","April","May","June","July","August","September","October","November","December"],n=e?c(e)!==0:!1,a=s[t-1]||"";return{type:"String",value:n?a.substring(0,3):a}},WeekdayName:(r,e,t)=>{const s=Math.floor(c(r)),n=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],a=e?c(e)!==0:!1,i=n[s-1]||"";return{type:"String",value:a?i.substring(0,3):i}},Timer:()=>{const r=new Date;return{type:"Single",value:r.getHours()*3600+r.getMinutes()*60+r.getSeconds()+r.getMilliseconds()/1e3}}},qe={CBool:r=>({type:"Boolean",value:d(r)}),CByte:r=>{const e=Math.floor(c(r));if(e<0||e>255)throw new Error("Overflow: CByte");return{type:"Byte",value:e}},CCur:r=>({type:"Currency",value:c(r)}),CDate:r=>{if(r.type==="Date")return r;const e=y(r),t=new Date(e);if(isNaN(t.getTime()))throw new Error("Type mismatch: CDate");return{type:"Date",value:t}},CDbl:r=>({type:"Double",value:c(r)}),CInt:r=>{const e=Math.round(c(r));if(e<-32768||e>32767)throw new Error("Overflow: CInt");return{type:"Integer",value:e}},CLng:r=>({type:"Long",value:Math.round(c(r))}),CSng:r=>({type:"Single",value:c(r)}),CStr:r=>({type:"String",value:y(r)}),CVar:r=>r,CVErr:r=>({type:"Error",value:c(r)}),Val:r=>{const t=y(r).trim().match(/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/);return t?{type:"Double",value:parseFloat(t[0])}:{type:"Double",value:0}},Str:r=>{const e=c(r),t=String(e);return e>=0?{type:"String",value:" "+t}:{type:"String",value:t}},FormatNumber:(r,e,t,s,n)=>{const a=c(r),i=e?Math.floor(c(e)):-1,o=t?c(t):-2,l=n?c(n):-2,p={minimumFractionDigits:i>=0?i:void 0,maximumFractionDigits:i>=0?i:void 0,useGrouping:l===0?!1:l===-1?!0:void 0};o===-1?p.minimumIntegerDigits=1:o===0&&(p.minimumIntegerDigits=2);const h=O();return{type:"String",value:a.toLocaleString(h,p)}},FormatCurrency:(r,e,t,s,n)=>{const a=c(r),i=e?Math.floor(c(e)):-1,o=t?c(t):-2,l=n?c(n):-2,p={style:"currency",currency:Me(),minimumFractionDigits:i>=0?i:2,maximumFractionDigits:i>=0?i:2,useGrouping:l===0?!1:l===-1?!0:void 0};o===-1?p.minimumIntegerDigits=1:o===0&&(p.minimumIntegerDigits=2);const h=O();return{type:"String",value:a.toLocaleString(h,p)}},FormatPercent:(r,e,t,s,n)=>{const a=c(r),i=e?Math.floor(c(e)):-1,o=t?c(t):-2,l=n?c(n):-2,p={style:"percent",minimumFractionDigits:i>=0?i:void 0,maximumFractionDigits:i>=0?i:void 0,useGrouping:l===0?!1:l===-1?!0:void 0};o===-1?p.minimumIntegerDigits=1:o===0&&(p.minimumIntegerDigits=2);const h=O();return{type:"String",value:a.toLocaleString(h,p)}},FormatDateTime:(r,e)=>{const t=r.type==="Date"?r.value:new Date(y(r)),s=e?Math.floor(c(e)):0,n=O();let a;switch(s){case 0:a=t.toLocaleString(n);break;case 1:a=t.toLocaleDateString(n,{weekday:"long",year:"numeric",month:"long",day:"numeric"});break;case 2:a=t.toLocaleDateString(n);break;case 3:a=t.toLocaleTimeString(n);break;case 4:a=t.toLocaleTimeString(n,{hour:"2-digit",minute:"2-digit"});break;default:a=t.toLocaleString()}return{type:"String",value:a}},Hex:r=>({type:"String",value:Math.floor(c(r)).toString(16).toUpperCase()}),Oct:r=>({type:"String",value:Math.floor(c(r)).toString(8)})},Ue={IsArray:r=>({type:"Boolean",value:r.type==="Array"}),IsDate:r=>{if(r.type==="Date")return{type:"Boolean",value:!0};if(r.type==="String"){const e=new Date(r.value);return{type:"Boolean",value:!isNaN(e.getTime())}}return{type:"Boolean",value:!1}},IsEmpty:r=>({type:"Boolean",value:Ee(r)}),IsNull:r=>({type:"Boolean",value:Ce(r)}),IsNumeric:r=>({type:"Boolean",value:xe(r)}),IsObject:r=>({type:"Boolean",value:r.type==="Object"}),VarType:r=>({type:"Integer",value:{Empty:0,Null:1,Integer:2,Long:3,Single:4,Double:5,Currency:6,Date:7,String:8,Object:9,Error:10,Boolean:11,Variant:12,Byte:17,Array:8192}[r.type]??12}),TypeName:r=>({type:"String",value:{Empty:"Empty",Null:"Null",Integer:"Integer",Long:"Long",Single:"Single",Double:"Double",Currency:"Currency",Date:"Date",String:"String",Object:"Object",Error:"Error",Boolean:"Boolean",Variant:"Variant",Byte:"Byte",Array:"Variant()"}[r.type]??"Variant"})},ze={Array:(...r)=>({type:"Array",value:G(r)}),LBound:(r,e)=>{if(r.type!=="Array")throw new Error("Type mismatch: LBound");const t=r.value,s=e?Math.floor(c(e)):1;return{type:"Long",value:t.getBounds(s).lower}},UBound:(r,e)=>{if(r.type!=="Array")throw new Error("Type mismatch: UBound");const t=r.value,s=e?Math.floor(c(e)):1;return{type:"Long",value:t.getBounds(s).upper}},IsArray:r=>({type:"Boolean",value:r.type==="Array"}),Filter:(r,e,t,s)=>{if(r.type!=="Array")throw new Error("Type mismatch: Filter");const n=r.value.toArray(),a=e.value.toLowerCase(),i=t?c(t)!==0:!0,o=n.filter(p=>{const g=p.value.toLowerCase().includes(a);return i?g:!g});return{type:"Array",value:G(o)}}},v={vbOK:1,vbCancel:2,vbAbort:3,vbRetry:4,vbYes:6,vbNo:7};function ae(r){const e=r??0,t=e&7,s=e&240,n=e&768;let a;switch(t){case 0:a="OK";break;case 1:a="OKCancel";break;case 2:a="AbortRetryIgnore";break;case 3:a="YesNoCancel";break;case 4:a="YesNo";break;case 5:a="RetryCancel";break;default:a="OK"}let i=null;switch(s){case 16:i="Critical";break;case 32:i="Question";break;case 48:i="Exclamation";break;case 64:i="Information";break}return{buttonType:a,iconType:i,defaultButton:n}}function $e(r){switch(r){case"Critical":return"[X] ";case"Question":return"[?] ";case"Exclamation":return"[!] ";case"Information":return"[i] ";default:return""}}function ie(r,e,t){let s=$e(e)+t;return r&&(s=`[${r}]
|
|
16
|
-
`+s),s}function
|
|
17
|
-
[
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
Default: ${h}`),{type:"String",value:""})})}function Ze(r){return{type:"Object",value:{classInfo:{name:"Match"},getProperty:e=>{const t=e.toLowerCase();return t==="firstindex"?{type:"Long",value:r.firstIndex}:t==="length"?{type:"Long",value:r.length}:t==="value"?{type:"String",value:r.value}:{type:"Empty",value:void 0}},hasProperty:e=>{const t=e.toLowerCase();return["firstindex","length","value"].includes(t)},getPropertyNames:()=>["FirstIndex","Length","Value"]}}}function $(r){const e=r.map(Ze);return{type:"Object",value:{classInfo:{name:"Matches"},getProperty:t=>{const s=parseInt(t,10);return!isNaN(s)&&s>=0&&s<e.length?e[s]??{type:"Empty",value:void 0}:{type:"Empty",value:void 0}},hasProperty:t=>{const s=parseInt(t,10);return!isNaN(s)&&s>=0&&s<e.length},hasMethod:t=>t.toLowerCase()==="count"||t.toLowerCase()==="item",getMethod:t=>{const s=t.toLowerCase();if(s==="count")return{func:()=>({type:"Long",value:r.length})};if(s==="item")return{func:n=>{const a=Math.floor(Number(n.value??0));return a>=0&&a<e.length?e[a]??{type:"Empty",value:void 0}:{type:"Empty",value:void 0}}};throw new Error(`Unknown Matches method: ${t}`)}}}}function oe(r){return{type:"Object",value:{classInfo:{name:"RegExp"},regexpState:r,getProperty:e=>{const t=e.toLowerCase();return t==="pattern"?{type:"String",value:r.pattern}:t==="global"?{type:"Boolean",value:r.global}:t==="ignorecase"?{type:"Boolean",value:r.ignoreCase}:t==="multiline"?{type:"Boolean",value:r.multiline}:{type:"Empty",value:void 0}},setProperty:(e,t)=>{const s=e.toLowerCase();s==="pattern"?r.pattern=String(t.value??""):s==="global"?r.global=!!t.value:s==="ignorecase"?r.ignoreCase=!!t.value:s==="multiline"&&(r.multiline=!!t.value)},hasProperty:e=>{const t=e.toLowerCase();return["pattern","global","ignorecase","multiline"].includes(t)},hasMethod:e=>["execute","test","replace"].includes(e.toLowerCase()),getMethod:e=>{const t=e.toLowerCase();if(t==="test")return{func:s=>{const n=String(s.value??"");if(!r.pattern)return{type:"Boolean",value:!1};try{const a=(r.ignoreCase?"i":"")+(r.multiline?"m":"");return{type:"Boolean",value:new RegExp(r.pattern,a).test(n)}}catch{return{type:"Boolean",value:!1}}}};if(t==="execute")return{func:s=>{const n=String(s.value??"");if(!r.pattern)return $([]);try{const a=(r.ignoreCase?"i":"")+(r.multiline?"m":"")+(r.global?"g":""),i=new RegExp(r.pattern,a),o=[];let l;for(;(l=i.exec(n))!==null&&(o.push({firstIndex:l.index,length:l[0].length,value:l[0],subMatches:l.slice(1).map(p=>p??"")}),!!r.global););return $(o)}catch{return $([])}}};if(t==="replace")return{func:(s,n)=>{const a=String(s.value??""),i=String(n.value??"");if(!r.pattern)return{type:"String",value:a};try{const o=(r.ignoreCase?"i":"")+(r.multiline?"m":"")+(r.global?"g":""),l=new RegExp(r.pattern,o);return{type:"String",value:a.replace(l,i)}}catch{return{type:"String",value:a}}}};throw new Error(`Unknown RegExp method: ${e}`)}}}}function Qe(r){r.classRegistry.registerClass("RegExp",()=>oe({pattern:"",global:!1,ignoreCase:!1,multiline:!1})),r.functionRegistry.register("RegExp",()=>oe({pattern:"",global:!1,ignoreCase:!1,multiline:!1}))}function et(r){Object.entries(Te).forEach(([t,s])=>{r.functionRegistry.register(t,s)}),Object.entries(We).forEach(([t,s])=>{r.functionRegistry.register(t,s)}),Object.entries(_e).forEach(([t,s])=>{r.functionRegistry.register(t,s)}),Object.entries(qe).forEach(([t,s])=>{r.functionRegistry.register(t,s)}),Object.entries(Ue).forEach(([t,s])=>{r.functionRegistry.register(t,s)}),Object.entries(ze).forEach(([t,s])=>{r.functionRegistry.register(t,s)}),Object.entries(Ge).forEach(([t,s])=>{r.globalScope.declare(t,s)}),Ke(r),Xe(r),Qe(r),Object.entries(Ae).forEach(([t,s])=>{r.functionRegistry.register(t,s)}),r.functionRegistry.register("ScriptEngine",()=>({type:"String",value:"VBScript"})),r.functionRegistry.register("ScriptEngineMajorVersion",()=>({type:"Integer",value:10})),r.functionRegistry.register("ScriptEngineMinorVersion",()=>({type:"Integer",value:8})),r.functionRegistry.register("ScriptEngineBuildVersion",()=>({type:"Long",value:16384})),r.functionRegistry.register("Eval",t=>{const s=String(t.value??t);return r.evaluate?.(s)??{type:"Empty",value:void 0}}),r.functionRegistry.register("Execute",t=>{const s=String(t.value??t);return r.execute?.(s)??{type:"Empty",value:void 0}},{isSub:!0}),r.functionRegistry.register("ExecuteGlobal",t=>{const s=String(t.value??t);return r.executeGlobal?.(s)??{type:"Empty",value:void 0}},{isSub:!0}),r.functionRegistry.register("Print",(...t)=>(console.log(...t.map(s=>s.value??s)),{type:"Empty",value:void 0}),{isSub:!0}),r.functionRegistry.register("GetRef",t=>{const s=String(t.value??t),n=r.functionRegistry;return{type:"Object",value:{type:"vbref",name:s,getProperty:a=>a.toLowerCase()==="name"?{type:"String",value:s}:{type:"Empty",value:void 0},hasProperty:a=>a.toLowerCase()==="name",call:(...a)=>n.call(s,a)}}}),r.functionRegistry.register("TypeName",t=>{if(t.type==="Object"&&t.value&&typeof t.value=="object"){const n=t.value;if(n.classInfo&&n.classInfo.name)return{type:"String",value:n.classInfo.name}}return{type:"String",value:{Empty:"Empty",Null:"Null",Integer:"Integer",Long:"Long",Single:"Single",Double:"Double",Currency:"Currency",Date:"Date",String:"String",Object:"Object",Error:"Error",Boolean:"Boolean",Variant:"Variant",Byte:"Byte",Array:"Variant()"}[t.type]??"Variant"}}),r.functionRegistry.register("VarType",t=>({type:"Integer",value:{Empty:0,Null:1,Integer:2,Long:3,Single:4,Double:5,Currency:6,Date:7,String:8,Object:9,Error:10,Boolean:11,Variant:12,Byte:17,Array:8192}[t.type]??12})),r.functionRegistry.register("IsEmpty",t=>({type:"Boolean",value:t.type==="Empty"})),r.functionRegistry.register("IsNull",t=>({type:"Boolean",value:t.type==="Null"})),r.functionRegistry.register("IsNumeric",t=>{if(["Integer","Long","Single","Double","Currency","Byte"].includes(t.type))return{type:"Boolean",value:!0};if(t.type==="String"){const n=Number(t.value);return{type:"Boolean",value:!isNaN(n)}}return{type:"Boolean",value:!1}}),r.functionRegistry.register("IsDate",t=>{if(t.type==="Date")return{type:"Boolean",value:!0};if(t.type==="String"){const s=new Date(t.value);return{type:"Boolean",value:!isNaN(s.getTime())}}return{type:"Boolean",value:!1}}),r.functionRegistry.register("IsObject",t=>({type:"Boolean",value:t.type==="Object"})),r.functionRegistry.register("IsArray",t=>({type:"Boolean",value:t.type==="Array"})),r.functionRegistry.register("Erase",t=>({type:"Empty",value:void 0}),{isSub:!0}),r.functionRegistry.register("GetObject",(t,s)=>({type:"Object",value:null})),r.functionRegistry.register("CreateObject",(t,s)=>({type:"Object",value:{className:String(t.value??t),properties:new Map}})),r.functionRegistry.register("LoadPicture",t=>{const s=String(t.value??t);return{type:"Object",value:{classInfo:{name:"IPictureDisp"},getProperty:a=>{const i=a.toLowerCase();return i==="handle"?{type:"Long",value:0}:i==="width"?{type:"Long",value:0}:i==="height"?{type:"Long",value:0}:i==="type"?{type:"Long",value:1}:{type:"Empty",value:void 0}},hasProperty:a=>{const i=a.toLowerCase();return["handle","width","height","type"].includes(i)},_path:s}}}),r.functionRegistry.register("RGB",(t,s,n)=>{const a=Math.max(0,Math.min(255,Math.floor(Number(t.value??0)))),i=Math.max(0,Math.min(255,Math.floor(Number(s.value??0)))),o=Math.max(0,Math.min(255,Math.floor(Number(n.value??0))));return{type:"Long",value:a+i*256+o*65536}}),r.functionRegistry.register("QBColor",t=>{const s=Math.floor(Number(t.value??0));return{type:"Long",value:[0,8388608,32768,8421376,128,8388736,32896,12632256,8421504,16711680,65280,16776960,255,16711935,65535,16777215][s]??0}});const e={getProperty:t=>{const s=t.toLowerCase();return s==="number"?{type:"Long",value:r.err.number}:s==="description"?{type:"String",value:r.err.description}:s==="source"?{type:"String",value:r.err.source}:{type:"Empty",value:void 0}},setProperty:(t,s)=>{const n=t.toLowerCase();n==="number"?r.err.number=Number(s.value)||0:n==="description"?r.err.description=String(s.value??""):n==="source"&&(r.err.source=String(s.value??""))},hasMethod:t=>t.toLowerCase()==="clear"||t.toLowerCase()==="raise",getMethod:t=>{const s=t.toLowerCase();if(s==="clear")return{func:()=>(r.clearError(),{type:"Empty",value:void 0})};if(s==="raise")return{func:(n,a,i)=>(r.err.number=Number(n.value)||0,r.err.source=a?String(a.value??""):"",r.err.description=i?String(i.value??""):"",{type:"Empty",value:void 0})};throw new Error(`Unknown Err method: ${t}`)}};r.globalScope.declare("Err",{type:"Object",value:e})}class tt{context;executor;maxExecutionTime=-1;startTime=0;constructor(){this.context=new Ne,this.executor=new Oe(this.context),et(this.context)}setMaxExecutionTime(e){this.maxExecutionTime=e}checkTimeout(){if(this.maxExecutionTime>0&&Date.now()-this.startTime>this.maxExecutionTime)throw new Error(`Script execution timed out after ${this.maxExecutionTime}ms`)}collectLabels(e){const t=new Map;for(let s=0;s<e.length;s++){const n=e[s];if(n.type==="VbLabelStatement"){const a=n;t.set(a.label.name.toLowerCase(),{index:s,statement:a})}}return t}run(e){this.startTime=Date.now();let t=m;const s=e.body,n=this.collectLabels(s);let a=0;const i=s.length*1e4;let o=0;for(;a<s.length;){if(o++>i)throw new Error("Possible infinite loop detected (too many goto jumps)");this.checkTimeout();const l=s[a];try{t=this.executor.execute(l),a++}catch(p){if(p instanceof _){const h=n.get(p.labelName);if(h){a=h.index+1;continue}throw new Error(`Label not found: ${p.labelName}`)}throw p instanceof E,p}}return t}getVariable(e){return this.context.getVariable(e)}setVariable(e,t){this.context.setVariable(e,t)}registerFunction(e,t){this.context.functionRegistry.register(e,t)}evaluate(e){try{const t=T(e);return new re(this.context).evaluateProgram(t)}catch(t){return console.error("Eval error:",t),{type:"Empty",value:void 0}}}getContext(){return this.context}executeStatements(e){const t=this.collectLabels(e);let s=m,n=0;const a=e.length*1e4;let i=0;for(;n<e.length;){if(i++>a)throw new Error("Possible infinite loop detected (too many goto jumps)");this.checkTimeout();const o=e[n];try{s=this.executor.execute(o),n++}catch(l){if(l instanceof _){const p=t.get(l.labelName);if(p){n=p.index+1;continue}throw new Error(`Label not found: ${l.labelName}`)}throw l instanceof E,l}}return s}executeInCurrentScope(e){const t=T(e);return this.executeStatements(t.body)}executeInGlobalScope(e){const t=this.context.currentScope;this.context.currentScope=this.context.globalScope;try{const s=T(e);return this.executeStatements(s.body)}finally{this.context.currentScope=t}}}function D(r){switch(r.type){case"Empty":return;case"Null":return null;case"Boolean":case"Long":case"Double":case"Integer":case"String":case"Date":return r.value;case"Array":return r.value.toArray().map(D);case"Object":return r.value;default:return r.value}}function A(r,e){return r===void 0?{type:"Empty",value:void 0}:r===null?{type:"Null",value:null}:typeof r=="boolean"?{type:"Boolean",value:r}:typeof r=="number"?Number.isInteger(r)&&r>=-2147483648&&r<=2147483647?{type:"Long",value:r}:{type:"Double",value:r}:typeof r=="string"?{type:"String",value:r}:r instanceof Date?{type:"Date",value:r}:Array.isArray(r)?{type:"Array",value:r}:typeof r=="function"?{type:"Object",value:{type:"jsfunction",func:r,thisArg:e??null}}:typeof r=="object"?{type:"Object",value:r}:{type:"String",value:String(r)}}function ce(r){if(typeof window>"u")return{originalSetTimeout:null,originalSetInterval:null};const e=window.setTimeout,t=window.setInterval;return window.setTimeout=function(s,n,a,...i){if(typeof s=="string"){const o=typeof a=="string"?a.toLowerCase():null,l=typeof n=="number"?n:0;return o==="vbscript"||o==="vbs"?e.call(window,()=>{r._getContext()?.functionRegistry?.has(s)?r.run(s):r.executeStatement(s)},l):e.call(window,()=>{r._getContext()?.functionRegistry?.has(s)?r.run(s):r.executeStatement(s)},l)}return e.call(window,s,n,...[a,...i].filter(o=>o!==void 0))},window.setInterval=function(s,n,a,...i){if(typeof s=="string"){const o=typeof a=="string"?a.toLowerCase():null,l=typeof n=="number"?n:0;return o==="vbscript"||o==="vbs"?t.call(window,()=>{r._getContext()?.functionRegistry?.has(s)?r.run(s):r.executeStatement(s)},l):t.call(window,()=>{r._getContext()?.functionRegistry?.has(s)?r.run(s):r.executeStatement(s)},l)}return t.call(window,s,n,...[a,...i].filter(o=>o!==void 0))},{originalSetTimeout:e,originalSetInterval:t}}function rt(r){typeof window>"u"||(r.originalSetTimeout&&(window.setTimeout=r.originalSetTimeout),r.originalSetInterval&&(window.setInterval=r.originalSetInterval))}function st(r){if(typeof window>"u")return{originalEval:null};const e=window.eval;return window.vbsEval=function(t){return r.eval(String(t))},window.eval=function(t,s){if(typeof s=="string"){const n=s.toLowerCase();if(n==="vbscript"||n==="vbs")return r.eval(String(t))}return e.call(window,String(t))},{originalEval:e}}function nt(r){typeof window>"u"||(r.originalEval&&(window.eval=r.originalEval),delete window.vbsEval)}function at(r){if(typeof window>"u")return{navigateHandler:null,clickHandler:null};let e=null,t=null;return"navigation"in window&&window.navigation?(e=s=>{const a=s.destination?.url;if(a&&a.toLowerCase().startsWith("vbscript:")){s.preventDefault();const i=a.substring(9);try{r.executeStatement(i)}catch(o){console.error("VBScript protocol error:",o)}}},window.navigation.addEventListener("navigate",e)):(t=s=>{const n=s.target;if(n.tagName==="A"||n.tagName==="AREA"){const a=n.getAttribute("href");if(a&&a.toLowerCase().startsWith("vbscript:")){s.preventDefault();const i=a.substring(9);try{r.executeStatement(i)}catch(o){console.error("VBScript protocol error:",o)}}}},document.addEventListener("click",t,!0)),{navigateHandler:e,clickHandler:t}}function it(r){typeof window>"u"||(r.navigateHandler&&"navigation"in window&&window.navigation&&window.navigation.removeEventListener("navigate",r.navigateHandler),r.clickHandler&&document.removeEventListener("click",r.clickHandler,!0))}function ot(r,e){const t=String(r.value??r),s=window.ActiveXObject;if(s)try{return{type:"Object",value:{type:"activex",object:new s(t),className:t}}}catch{throw new Error(`ActiveX component can't create object: '${t}'`)}throw new Error(`ActiveXObject is not supported in this browser environment. Cannot create: '${t}'`)}function ct(r,e){const t=window.ActiveXObject;if(t){const n=r?String(r.value??r):"",a=e?String(e.value??e):"";try{if(n)return{type:"Object",value:{type:"activex",object:new t(a||"Scripting.FileSystemObject"),className:a}}}catch{throw new Error(`ActiveX component can't create object: '${a||n}'`)}}const s=e?String(e.value??e):"";throw new Error(`ActiveXObject is not supported in this browser environment. Cannot get: '${s}'`)}function Y(r){const e=r.getAttribute("language"),t=r.getAttribute("type");return e?.toLowerCase()==="vbscript"||t?.toLowerCase()==="text/vbscript"||t?.toLowerCase()==="application/x-vbscript"}function lt(r,e,t){if(!Y(e))return;const s=e.textContent??"",n=e.getAttribute("for"),a=e.getAttribute("event");if(n&&a)H(r,n,a,s);else try{r.addCode(s),t?.()}catch(i){console.error("Vbscript error:",i)}}function H(r,e,t,s){const n=t.toLowerCase().replace(/^on/,""),a=()=>{const i=document.getElementById(e);if(i){const o=()=>{try{r.addCode(s)}catch(l){console.error("VBScript event handler error:",l)}};return i.addEventListener(n,o),!0}return!1};a()||(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{a()}):setTimeout(a,0))}function ut(r,e){if(typeof document>"u")return;document.querySelectorAll("script").forEach(s=>{lt(r,s,e)})}function K(r,e){const t=e.attributes;for(let s=0;s<t.length;s++){const n=t[s];if(!n)continue;const a=n.name.toLowerCase();if(a.startsWith("on")&&a.length>2){const i=n.value.trim();if(i.toLowerCase().startsWith("vbscript:")){const o=i.substring(9).trim();e[a]=()=>{try{r.executeStatement(o)}catch(l){console.error("VBScript event handler error:",l)}}}}}}function pt(r){if(typeof document>"u")return;document.querySelectorAll("*").forEach(t=>{K(r,t)})}function ht(r){if(r in globalThis){const t=globalThis[r];if(t&&typeof t.addEventListener=="function")return t}const e=r.toLowerCase();for(const t of Object.keys(globalThis))if(t.toLowerCase()===e){const s=globalThis[t];if(s&&typeof s.addEventListener=="function")return s}if(typeof document<"u"){const t=document.getElementById(r);if(t)return t;const s=document.querySelectorAll("[id]");for(let n=0;n<s.length;n++){const a=s[n];if(a&&a.id.toLowerCase()===e)return a}}return null}function R(r,e){if(typeof window>"u")return;const t=r._getContext()?.functionRegistry;if(!t)return;const s=t.getUserDefinedFunctions?.();if(s)for(const[n]of s){const a=n.toLowerCase().indexOf("_on");if(a>0){const i=n.substring(0,a),o=n.substring(a+3),l=ht(i);if(l){const p=o.toLowerCase();if(e.has(n)){const g=e.get(n);g.target.removeEventListener(p,g.handler)}const h=()=>{try{r._getContext()?.functionRegistry.call(n,[])}catch(g){console.error(`VBScript ${n} error:`,g)}};l.addEventListener(p,h),e.set(n,{target:l,handler:h})}}}}function ft(r){r.forEach(({target:e,handler:t},s)=>{const n=s.toLowerCase().indexOf("_on");if(n>0){const a=s.substring(n+3).toLowerCase();e.removeEventListener(a,t)}}),r.clear()}function yt(r,e,t){const s=new MutationObserver(n=>{n.forEach(a=>{a.addedNodes.forEach(i=>{if(i.nodeType===Node.ELEMENT_NODE){const o=i;if(e.parseScriptElement&&o.tagName.toLowerCase()==="script"&&Y(o)){const l=o.textContent??"",p=o.getAttribute("for"),h=o.getAttribute("event");if(p&&h)H(r,p,h,l);else try{r.addCode(l),e.injectGlobalThis&&e.parseEventSubNames&&R(r,t)}catch(g){console.error("Vbscript error:",g)}}e.parseInlineEventAttributes&&K(r,o),e.parseScriptElement&&o.querySelectorAll("script").forEach(p=>{if(Y(p)){const h=p.textContent??"",g=p.getAttribute("for"),b=p.getAttribute("event");if(g&&b)H(r,g,b,h);else try{r.addCode(h),e.injectGlobalThis&&e.parseEventSubNames&&R(r,t)}catch(S){console.error("Vbscript error:",S)}}}),e.parseInlineEventAttributes&&o.querySelectorAll("*").forEach(p=>{K(r,p)})}})})});return s.observe(document.documentElement,{childList:!0,subtree:!0}),{observer:s}}function mt(r){r.observer.disconnect()}function gt(r,e){const t={originalSetTimeout:null,originalSetInterval:null},s={originalEval:null};let n={navigateHandler:null,clickHandler:null},a=null;const i=new Map;return r._registerFunction("MsgBox",He()),r._registerFunction("InputBox",Je()),r._registerFunction("CreateObject",ot),r._registerFunction("GetObject",ct),e.overrideJSEvalFunctions&&(t.originalSetTimeout=ce(r).originalSetTimeout,t.originalSetInterval=ce(r).originalSetInterval,s.originalEval=st(r).originalEval),e.parseVbsProtocol&&(n=at(r)),e.parseScriptElement&&ut(r),e.parseInlineEventAttributes&&pt(r),e.injectGlobalThis&&e.parseEventSubNames&&R(r,i),(e.parseScriptElement||e.parseInlineEventAttributes)&&(a=yt(r,e,i)),document.readyState==="loading"&&document.addEventListener("DOMContentLoaded",()=>{e.injectGlobalThis&&e.parseEventSubNames&&R(r,i)}),()=>{a&&mt(a),ft(i),(n.navigateHandler||n.clickHandler)&&it(n),e.overrideJSEvalFunctions&&(rt(t),nt(s))}}class le{interpreter;options;browserCleanup=null;lastError=null;constructor(e={}){this.options={maxExecutionTime:e.maxExecutionTime??-1,injectGlobalThis:e.injectGlobalThis??!0,mode:e.mode??"general",parseScriptElement:e.parseScriptElement??!0,parseInlineEventAttributes:e.parseInlineEventAttributes??!0,parseEventSubNames:e.parseEventSubNames??!0,overrideJSEvalFunctions:e.overrideJSEvalFunctions??!0,parseVbsProtocol:e.parseVbsProtocol??!0},this.interpreter=new tt,this.interpreter.getContext().evaluate=t=>this.interpreter.evaluate(t),this.interpreter.getContext().execute=t=>this.interpreter.executeInCurrentScope(t),this.interpreter.getContext().executeGlobal=t=>this.interpreter.executeInGlobalScope(t),this.options.maxExecutionTime>0&&this.setMaxExecutionTime(this.options.maxExecutionTime),this.options.mode==="browser"&&typeof window<"u"&&this.initializeBrowserMode()}initializeBrowserMode(){this.browserCleanup=gt(this,this.options)}setMaxExecutionTime(e){this.interpreter.setMaxExecutionTime(e),this.interpreter.getContext().checkTimeout=()=>this.interpreter.checkTimeout()}get error(){return this.lastError}clearError(){this.lastError=null}addCode(e){this.clearError();try{const s=new F(e).tokenize(),a=new j(s).parse();this.interpreter.run(a),this.syncFunctionsToGlobalThis()}catch(t){this.handleError(t)}}executeStatement(e){this.clearError();try{const s=new F(e).tokenize(),a=new j(s).parse();this.interpreter.run(a)}catch(t){this.handleError(t)}}run(e,...t){this.clearError();try{const n=this.interpreter.getContext().functionRegistry,a=t.map(o=>A(o)),i=n.call(e,a);return D(i)}catch(s){this.handleError(s);return}}addObject(e,t,s=!0){this.clearError();try{const n=A(t);if(this.interpreter.setVariable(e,n),s&&typeof t=="object"&&t!==null){const a=t;for(const i of Object.keys(a)){const o=`${e}.${i}`,l=a[i];typeof l=="function"&&this.interpreter.registerFunction(o,(...p)=>{const h=p.map(D),g=l(...h);return A(g)})}}}catch(n){this.handleError(n)}}eval(e){this.clearError();try{const t=this.interpreter.evaluate(e);return D(t)}catch(t){this.handleError(t);return}}destroy(){this.browserCleanup&&(this.browserCleanup(),this.browserCleanup=null)}_registerFunction(e,t){this.interpreter.registerFunction(e,t)}_getContext(){return this.interpreter.getContext()}_getVariable(e){return this.interpreter.getVariable(e)}handleError(e){e instanceof Error?this.lastError={number:-1,description:e.message}:this.lastError={number:-1,description:String(e)}}syncFunctionsToGlobalThis(){if(typeof globalThis>"u"||!this.options.injectGlobalThis)return;const e=this.interpreter.getContext();if(!e)return;const t=e.functionRegistry;if(!t)return;const s=t.getUserDefinedFunctions?.();if(s){for(const[,n]of s){const a=n.name;a in globalThis||(globalThis[a]=(...i)=>this.run(a,...i))}if(e.globalScope){const n=e.globalScope.getAllVariables();for(const[a,i]of n)i.value&&i.value.type!=="Empty"&&(a in globalThis||(globalThis[a]=D(i.value)))}}}}function bt(r){return new le().eval(r)}I.VbsEngine=le,I.evalVbscript=bt,I.jsToVb=A,I.vbToJs=D,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})}));
|
|
15
|
+
`},vbNullChar:{type:"String",value:"\0"},vbTab:{type:"String",value:" "},vbVerticalTab:{type:"String",value:"\v"},vbNullString:{type:"String",value:""},vbObjectError:{type:"Long",value:-2147221504},vbSunday:{type:"Integer",value:1},vbMonday:{type:"Integer",value:2},vbTuesday:{type:"Integer",value:3},vbWednesday:{type:"Integer",value:4},vbThursday:{type:"Integer",value:5},vbFriday:{type:"Integer",value:6},vbSaturday:{type:"Integer",value:7},vbUseSystemDayOfWeek:{type:"Integer",value:0},vbFirstJan1:{type:"Integer",value:1},vbFirstFourDays:{type:"Integer",value:2},vbFirstFullWeek:{type:"Integer",value:3},vbBinaryCompare:{type:"Integer",value:0},vbTextCompare:{type:"Integer",value:1},vbDatabaseCompare:{type:"Integer",value:2},vbGeneralDate:{type:"Integer",value:0},vbLongDate:{type:"Integer",value:1},vbShortDate:{type:"Integer",value:2},vbLongTime:{type:"Integer",value:3},vbShortTime:{type:"Integer",value:4},vbEmpty:{type:"Integer",value:0},vbNull:{type:"Integer",value:1},vbInteger:{type:"Integer",value:2},vbLong:{type:"Integer",value:3},vbSingle:{type:"Integer",value:4},vbDouble:{type:"Integer",value:5},vbCurrency:{type:"Integer",value:6},vbDate:{type:"Integer",value:7},vbString:{type:"Integer",value:8},vbObject:{type:"Integer",value:9},vbError:{type:"Integer",value:10},vbBoolean:{type:"Integer",value:11},vbVariant:{type:"Integer",value:12},vbDataObject:{type:"Integer",value:13},vbDecimal:{type:"Integer",value:14},vbByte:{type:"Integer",value:17},vbArray:{type:"Integer",value:8192},vbOKOnly:{type:"Integer",value:0},vbOKCancel:{type:"Integer",value:1},vbAbortRetryIgnore:{type:"Integer",value:2},vbYesNoCancel:{type:"Integer",value:3},vbYesNo:{type:"Integer",value:4},vbRetryCancel:{type:"Integer",value:5},vbCritical:{type:"Integer",value:16},vbQuestion:{type:"Integer",value:32},vbExclamation:{type:"Integer",value:48},vbInformation:{type:"Integer",value:64},vbDefaultButton1:{type:"Integer",value:0},vbDefaultButton2:{type:"Integer",value:256},vbDefaultButton3:{type:"Integer",value:512},vbOK:{type:"Integer",value:1},vbCancel:{type:"Integer",value:2},vbAbort:{type:"Integer",value:3},vbRetry:{type:"Integer",value:4},vbIgnore:{type:"Integer",value:5},vbYes:{type:"Integer",value:6},vbNo:{type:"Integer",value:7}};function I(r){const e=new Date(1899,11,30);return new Date(e.getTime()+r*864e5)}const Ye={Now:()=>({type:"Date",value:new Date}),Date:()=>{const r=new Date;return{type:"Date",value:new Date(r.getFullYear(),r.getMonth(),r.getDate())}},Time:()=>{const r=new Date;return{type:"Date",value:new Date(0,0,0,r.getHours(),r.getMinutes(),r.getSeconds())}},Year:r=>({type:"Integer",value:(r.type==="Date"?r.value:I(l(r))).getFullYear()}),Month:r=>({type:"Integer",value:(r.type==="Date"?r.value:I(l(r))).getMonth()+1}),Day:r=>({type:"Integer",value:(r.type==="Date"?r.value:I(l(r))).getDate()}),Weekday:(r,e)=>{const t=r.type==="Date"?r.value:I(l(r)),s=e?Math.floor(l(e)):1;let n=t.getDay()+1;return n=n-s+1,n<1&&(n+=7),{type:"Integer",value:n}},Hour:r=>({type:"Integer",value:(r.type==="Date"?r.value:I(l(r))).getHours()}),Minute:r=>({type:"Integer",value:(r.type==="Date"?r.value:I(l(r))).getMinutes()}),Second:r=>({type:"Integer",value:(r.type==="Date"?r.value:I(l(r))).getSeconds()}),DateAdd:(r,e,t)=>{const s=y(r).toLowerCase(),n=l(e),a=t.type==="Date"?new Date(t.value):I(l(t));switch(s){case"yyyy":a.setFullYear(a.getFullYear()+n);break;case"q":a.setMonth(a.getMonth()+n*3);break;case"m":a.setMonth(a.getMonth()+n);break;case"y":case"d":case"w":a.setDate(a.getDate()+n);break;case"ww":a.setDate(a.getDate()+n*7);break;case"h":a.setHours(a.getHours()+n);break;case"n":a.setMinutes(a.getMinutes()+n);break;case"s":a.setSeconds(a.getSeconds()+n);break}return{type:"Date",value:a}},DateDiff:(r,e,t,s,n)=>{const a=y(r).toLowerCase(),i=e.type==="Date"?e.value:I(l(e)),o=t.type==="Date"?t.value:I(l(t)),c=o.getTime()-i.getTime();let p;switch(a){case"yyyy":p=o.getFullYear()-i.getFullYear();break;case"q":p=Math.floor((o.getFullYear()-i.getFullYear())*4+(o.getMonth()-i.getMonth())/3);break;case"m":p=(o.getFullYear()-i.getFullYear())*12+(o.getMonth()-i.getMonth());break;case"y":case"d":p=Math.floor(c/864e5);break;case"w":p=Math.floor(c/864e5);break;case"ww":p=Math.floor(c/(864e5*7));break;case"h":p=Math.floor(c/36e5);break;case"n":p=Math.floor(c/6e4);break;case"s":p=Math.floor(c/1e3);break;default:p=0}return{type:"Long",value:p}},DatePart:(r,e,t,s)=>{const n=y(r).toLowerCase(),a=e.type==="Date"?e.value:I(l(e));let i;switch(n){case"yyyy":i=a.getFullYear();break;case"q":i=Math.floor(a.getMonth()/3)+1;break;case"m":i=a.getMonth()+1;break;case"y":const o=new Date(a.getFullYear(),0,1);i=Math.floor((a.getTime()-o.getTime())/864e5)+1;break;case"d":i=a.getDate();break;case"w":i=a.getDay()+1;break;case"ww":const c=new Date(a.getFullYear(),0,1);i=Math.floor((a.getTime()-c.getTime())/(864e5*7))+1;break;case"h":i=a.getHours();break;case"n":i=a.getMinutes();break;case"s":i=a.getSeconds();break;default:i=0}return{type:"Integer",value:i}},DateSerial:(r,e,t)=>{const s=Math.floor(l(r)),n=Math.floor(l(e)),a=Math.floor(l(t));return{type:"Date",value:new Date(s,n-1,a)}},TimeSerial:(r,e,t)=>{const s=Math.floor(l(r)),n=Math.floor(l(e)),a=Math.floor(l(t));return{type:"Date",value:new Date(0,0,0,s,n,a)}},DateValue:r=>{const e=new Date(y(r));if(isNaN(e.getTime()))throw new Error("Type mismatch: DateValue");return{type:"Date",value:new Date(e.getFullYear(),e.getMonth(),e.getDate())}},TimeValue:r=>{const e=new Date(y(r));if(isNaN(e.getTime()))throw new Error("Type mismatch: TimeValue");return{type:"Date",value:new Date(0,0,0,e.getHours(),e.getMinutes(),e.getSeconds())}},MonthName:(r,e)=>{const t=Math.floor(l(r)),s=["January","February","March","April","May","June","July","August","September","October","November","December"],n=e?l(e)!==0:!1,a=s[t-1]||"";return{type:"String",value:n?a.substring(0,3):a}},WeekdayName:(r,e,t)=>{const s=Math.floor(l(r)),n=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],a=e?l(e)!==0:!1,i=n[s-1]||"";return{type:"String",value:a?i.substring(0,3):i}},Timer:()=>{const r=new Date;return{type:"Single",value:r.getHours()*3600+r.getMinutes()*60+r.getSeconds()+r.getMilliseconds()/1e3}}},$e={CBool:r=>({type:"Boolean",value:d(r)}),CByte:r=>{const e=Math.floor(l(r));if(e<0||e>255)throw new Error("Overflow: CByte");return{type:"Byte",value:e}},CCur:r=>({type:"Currency",value:l(r)}),CDate:r=>{if(r.type==="Date")return r;const e=y(r),t=new Date(e);if(isNaN(t.getTime()))throw new Error("Type mismatch: CDate");return{type:"Date",value:t}},CDbl:r=>({type:"Double",value:l(r)}),CInt:r=>{const e=Math.round(l(r));if(e<-32768||e>32767)throw new Error("Overflow: CInt");return{type:"Integer",value:e}},CLng:r=>({type:"Long",value:Math.round(l(r))}),CSng:r=>({type:"Single",value:l(r)}),CStr:r=>({type:"String",value:y(r)}),CVar:r=>r,CVErr:r=>({type:"Error",value:l(r)}),Val:r=>{const t=y(r).trim().match(/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/);return t?{type:"Double",value:parseFloat(t[0])}:{type:"Double",value:0}},Str:r=>{const e=l(r),t=String(e);return e>=0?{type:"String",value:" "+t}:{type:"String",value:t}},FormatNumber:(r,e,t,s,n)=>{const a=l(r),i=e?Math.floor(l(e)):-1,o=t?l(t):-2,c=n?l(n):-2,p={minimumFractionDigits:i>=0?i:void 0,maximumFractionDigits:i>=0?i:void 0,useGrouping:c===0?!1:c===-1?!0:void 0};o===-1?p.minimumIntegerDigits=1:o===0&&(p.minimumIntegerDigits=2);const h=O();return{type:"String",value:a.toLocaleString(h,p)}},FormatCurrency:(r,e,t,s,n)=>{const a=l(r),i=e?Math.floor(l(e)):-1,o=t?l(t):-2,c=n?l(n):-2,p={style:"currency",currency:je(),minimumFractionDigits:i>=0?i:2,maximumFractionDigits:i>=0?i:2,useGrouping:c===0?!1:c===-1?!0:void 0};o===-1?p.minimumIntegerDigits=1:o===0&&(p.minimumIntegerDigits=2);const h=O();return{type:"String",value:a.toLocaleString(h,p)}},FormatPercent:(r,e,t,s,n)=>{const a=l(r),i=e?Math.floor(l(e)):-1,o=t?l(t):-2,c=n?l(n):-2,p={style:"percent",minimumFractionDigits:i>=0?i:void 0,maximumFractionDigits:i>=0?i:void 0,useGrouping:c===0?!1:c===-1?!0:void 0};o===-1?p.minimumIntegerDigits=1:o===0&&(p.minimumIntegerDigits=2);const h=O();return{type:"String",value:a.toLocaleString(h,p)}},FormatDateTime:(r,e)=>{const t=r.type==="Date"?r.value:new Date(y(r)),s=e?Math.floor(l(e)):0,n=O();let a;switch(s){case 0:a=t.toLocaleString(n);break;case 1:a=t.toLocaleDateString(n,{weekday:"long",year:"numeric",month:"long",day:"numeric"});break;case 2:a=t.toLocaleDateString(n);break;case 3:a=t.toLocaleTimeString(n);break;case 4:a=t.toLocaleTimeString(n,{hour:"2-digit",minute:"2-digit"});break;default:a=t.toLocaleString()}return{type:"String",value:a}},Hex:r=>({type:"String",value:Math.floor(l(r)).toString(16).toUpperCase()}),Oct:r=>({type:"String",value:Math.floor(l(r)).toString(8)})},He={IsArray:r=>({type:"Boolean",value:r.type==="Array"}),IsDate:r=>{if(r.type==="Date")return{type:"Boolean",value:!0};if(r.type==="String"){const e=new Date(r.value);return{type:"Boolean",value:!isNaN(e.getTime())}}return{type:"Boolean",value:!1}},IsEmpty:r=>({type:"Boolean",value:ke(r)}),IsNull:r=>({type:"Boolean",value:Le(r)}),IsNumeric:r=>({type:"Boolean",value:Ie(r)}),IsObject:r=>({type:"Boolean",value:r.type==="Object"}),VarType:r=>({type:"Integer",value:{Empty:0,Null:1,Integer:2,Long:3,Single:4,Double:5,Currency:6,Date:7,String:8,Object:9,Error:10,Boolean:11,Variant:12,Byte:17,Array:8192}[r.type]??12}),TypeName:r=>({type:"String",value:{Empty:"Empty",Null:"Null",Integer:"Integer",Long:"Long",Single:"Single",Double:"Double",Currency:"Currency",Date:"Date",String:"String",Object:"Object",Error:"Error",Boolean:"Boolean",Variant:"Variant",Byte:"Byte",Array:"Variant()"}[r.type]??"Variant"})},Ke={Array:(...r)=>({type:"Array",value:_(r)}),LBound:(r,e)=>{if(r.type!=="Array")throw new Error("Type mismatch: LBound");const t=r.value,s=e?Math.floor(l(e)):1;return{type:"Long",value:t.getBounds(s).lower}},UBound:(r,e)=>{if(r.type!=="Array")throw new Error("Type mismatch: UBound");const t=r.value,s=e?Math.floor(l(e)):1;return{type:"Long",value:t.getBounds(s).upper}},IsArray:r=>({type:"Boolean",value:r.type==="Array"}),Filter:(r,e,t,s)=>{if(r.type!=="Array")throw new Error("Type mismatch: Filter");const n=r.value.toArray(),a=e.value.toLowerCase(),i=t?l(t)!==0:!0,o=n.filter(p=>{const g=p.value.toLowerCase().includes(a);return i?g:!g});return{type:"Array",value:_(o)}}},b={vbOK:1,vbCancel:2,vbAbort:3,vbRetry:4,vbIgnore:5,vbYes:6,vbNo:7};function oe(r){const e=r??0,t=e&7,s=e&240,n=e&768;let a;switch(t){case 0:a="OK";break;case 1:a="OKCancel";break;case 2:a="AbortRetryIgnore";break;case 3:a="YesNoCancel";break;case 4:a="YesNo";break;case 5:a="RetryCancel";break;default:a="OK"}let i=null;switch(s){case 16:i="Critical";break;case 32:i="Question";break;case 48:i="Exclamation";break;case 64:i="Information";break}return{buttonType:a,iconType:i,defaultButton:n}}function Je(r){switch(r){case"Critical":return"[X] ";case"Question":return"[?] ";case"Exclamation":return"[!] ";case"Information":return"[i] ";default:return""}}function ce(r,e,t){let s=Je(e)+t;return r&&(s=`[${r}]
|
|
16
|
+
`+s),s}function Xe(r,e){const t=[];switch(r){case"OK":t.push("OK");break;case"OKCancel":t.push(e===256?"OK (default), Cancel":"OK, Cancel (default)");break;case"YesNo":t.push(e===256?"Yes (default), No":"Yes, No (default)");break;case"YesNoCancel":e===512?t.push("Yes, No, Cancel (default)"):e===256?t.push("Yes (default), No, Cancel"):t.push("Yes, No (default), Cancel");break;case"RetryCancel":t.push(e===256?"Retry (default), Cancel":"Retry, Cancel (default)");break;case"AbortRetryIgnore":e===512?t.push("Abort, Retry, Ignore (default)"):e===256?t.push("Abort, Retry (default), Ignore"):t.push("Abort (default), Retry, Ignore");break}return t}function Ze(){return function(r,e,t){const s=String(r.value??r),n=e?Number(e.value??e):0,a=t?String(t.value??t):"VBScript",{buttonType:i,iconType:o}=oe(n),c=ce(a,o,s);if(i==="OK")return alert(c),{type:"Integer",value:b.vbOK};if(i==="OKCancel")return{type:"Integer",value:confirm(c)?b.vbOK:b.vbCancel};if(i==="YesNo")return{type:"Integer",value:confirm(c+`
|
|
17
|
+
[OK]=Yes / [Cancel]=No`)?b.vbYes:b.vbNo};if(i==="YesNoCancel"){const p=window.prompt(c+`
|
|
18
|
+
|
|
19
|
+
Enter: Y (Yes) / N (No) / C (Cancel) or invalid value for cancel`,"");if(p===null)return{type:"Integer",value:b.vbCancel};const h=p.trim().toUpperCase();return h==="Y"||h==="YES"?{type:"Integer",value:b.vbYes}:h==="N"||h==="NO"?{type:"Integer",value:b.vbNo}:h==="C"||h==="CANCEL"||h===""?{type:"Integer",value:b.vbCancel}:{type:"Integer",value:b.vbCancel}}if(i==="RetryCancel")return{type:"Integer",value:confirm(c+`
|
|
20
|
+
[OK]=Retry / [Cancel]=Cancel`)?b.vbRetry:b.vbCancel};if(i==="AbortRetryIgnore"){const p=window.prompt(c+`
|
|
21
|
+
|
|
22
|
+
Enter: A (Abort) / R (Retry) / I (Ignore)`,"");if(p===null)return{type:"Integer",value:b.vbCancel};const h=p.trim().toUpperCase();return h==="A"||h==="ABORT"?{type:"Integer",value:b.vbAbort}:h==="R"||h==="RETRY"?{type:"Integer",value:b.vbRetry}:h==="I"||h==="IGNORE"||h===""?{type:"Integer",value:b.vbIgnore}:{type:"Integer",value:b.vbIgnore}}return alert(c),{type:"Integer",value:b.vbOK}}}function Qe(r){r.functionRegistry.register("MsgBox",(e,t,s)=>{const n=String(e.value??e),a=t?Number(t.value??t):0,i=s?String(s.value??s):null,{buttonType:o,iconType:c,defaultButton:p}=oe(a),h=ce(i,c,n);if(o==="OK")return typeof alert<"u"?alert(h):console.log(h),{type:"Integer",value:b.vbOK};if(typeof window<"u"&&typeof window.confirm=="function"){if(o==="OKCancel")return{type:"Integer",value:confirm(h)?b.vbOK:b.vbCancel};if(o==="YesNo")return{type:"Integer",value:confirm(h+`
|
|
23
|
+
[OK]=Yes / [Cancel]=No`)?b.vbYes:b.vbNo};if(o==="YesNoCancel"&&typeof window.prompt=="function"){const g=window.prompt(h+`
|
|
24
|
+
|
|
25
|
+
Enter: Y (Yes) / N (No) / C (Cancel) or invalid value for cancel`,"");if(g===null)return{type:"Integer",value:b.vbCancel};const v=g.trim().toUpperCase();return v==="Y"||v==="YES"?{type:"Integer",value:b.vbYes}:v==="N"||v==="NO"?{type:"Integer",value:b.vbNo}:{type:"Integer",value:b.vbCancel}}if(o==="RetryCancel")return{type:"Integer",value:confirm(h+`
|
|
26
|
+
[OK]=Retry / [Cancel]=Cancel`)?b.vbRetry:b.vbCancel};if(o==="AbortRetryIgnore"&&typeof window.prompt=="function"){const g=window.prompt(h+`
|
|
27
|
+
|
|
28
|
+
Enter: A (Abort) / R (Retry) / I (Ignore)`,"");if(g===null)return{type:"Integer",value:b.vbCancel};const v=g.trim().toUpperCase();return v==="A"||v==="ABORT"?{type:"Integer",value:b.vbAbort}:v==="R"||v==="RETRY"?{type:"Integer",value:b.vbRetry}:v==="I"||v==="IGNORE"||v===""?{type:"Integer",value:b.vbIgnore}:{type:"Integer",value:b.vbIgnore}}}return console.log(h+`
|
|
29
|
+
`+Xe(o,p).join(" ")),{type:"Integer",value:b.vbCancel}},{isSub:!1})}function et(){return function(r,e,t,s,n,a,i){const o=String(r.value??r),c=e?String(e.value??e):"Input",p=t?String(t.value??t):"";return{type:"String",value:window.prompt(`[${c}]
|
|
30
|
+
${o}`,p)??""}}}function tt(r){r.functionRegistry.register("InputBox",(e,t,s,n,a,i,o)=>{const c=String(e.value??e),p=t?String(t.value??t):"Input",h=s?String(s.value??s):"";return typeof window<"u"&&typeof window.prompt=="function"?{type:"String",value:window.prompt(`[${p}]
|
|
31
|
+
${c}`,h)??""}:(console.log(`[${p}]
|
|
32
|
+
${c}
|
|
33
|
+
Default: ${h}`),{type:"String",value:""})})}function rt(r){return{type:"Object",value:{classInfo:{name:"Match"},getProperty:e=>{const t=e.toLowerCase();return t==="firstindex"?{type:"Long",value:r.firstIndex}:t==="length"?{type:"Long",value:r.length}:t==="value"?{type:"String",value:r.value}:{type:"Empty",value:void 0}},hasProperty:e=>{const t=e.toLowerCase();return["firstindex","length","value"].includes(t)},getPropertyNames:()=>["FirstIndex","Length","Value"]}}}function $(r){const e=r.map(rt);return{type:"Object",value:{classInfo:{name:"Matches"},getProperty:t=>{const s=parseInt(t,10);return!isNaN(s)&&s>=0&&s<e.length?e[s]??{type:"Empty",value:void 0}:{type:"Empty",value:void 0}},hasProperty:t=>{const s=parseInt(t,10);return!isNaN(s)&&s>=0&&s<e.length},hasMethod:t=>t.toLowerCase()==="count"||t.toLowerCase()==="item",getMethod:t=>{const s=t.toLowerCase();if(s==="count")return{func:()=>({type:"Long",value:r.length})};if(s==="item")return{func:n=>{const a=Math.floor(Number(n.value??0));return a>=0&&a<e.length?e[a]??{type:"Empty",value:void 0}:{type:"Empty",value:void 0}}};throw new Error(`Unknown Matches method: ${t}`)}}}}function le(r){return{type:"Object",value:{classInfo:{name:"RegExp"},regexpState:r,getProperty:e=>{const t=e.toLowerCase();return t==="pattern"?{type:"String",value:r.pattern}:t==="global"?{type:"Boolean",value:r.global}:t==="ignorecase"?{type:"Boolean",value:r.ignoreCase}:t==="multiline"?{type:"Boolean",value:r.multiline}:{type:"Empty",value:void 0}},setProperty:(e,t)=>{const s=e.toLowerCase();s==="pattern"?r.pattern=String(t.value??""):s==="global"?r.global=!!t.value:s==="ignorecase"?r.ignoreCase=!!t.value:s==="multiline"&&(r.multiline=!!t.value)},hasProperty:e=>{const t=e.toLowerCase();return["pattern","global","ignorecase","multiline"].includes(t)},hasMethod:e=>["execute","test","replace"].includes(e.toLowerCase()),getMethod:e=>{const t=e.toLowerCase();if(t==="test")return{func:s=>{const n=String(s.value??"");if(!r.pattern)return{type:"Boolean",value:!1};try{const a=(r.ignoreCase?"i":"")+(r.multiline?"m":"");return{type:"Boolean",value:new RegExp(r.pattern,a).test(n)}}catch{return{type:"Boolean",value:!1}}}};if(t==="execute")return{func:s=>{const n=String(s.value??"");if(!r.pattern)return $([]);try{const a=(r.ignoreCase?"i":"")+(r.multiline?"m":"")+(r.global?"g":""),i=new RegExp(r.pattern,a),o=[];let c;for(;(c=i.exec(n))!==null&&(o.push({firstIndex:c.index,length:c[0].length,value:c[0],subMatches:c.slice(1).map(p=>p??"")}),!!r.global););return $(o)}catch{return $([])}}};if(t==="replace")return{func:(s,n)=>{const a=String(s.value??""),i=String(n.value??"");if(!r.pattern)return{type:"String",value:a};try{const o=(r.ignoreCase?"i":"")+(r.multiline?"m":"")+(r.global?"g":""),c=new RegExp(r.pattern,o);return{type:"String",value:a.replace(c,i)}}catch{return{type:"String",value:a}}}};throw new Error(`Unknown RegExp method: ${e}`)}}}}function st(r){r.classRegistry.registerClass("RegExp",()=>le({pattern:"",global:!1,ignoreCase:!1,multiline:!1})),r.functionRegistry.register("RegExp",()=>le({pattern:"",global:!1,ignoreCase:!1,multiline:!1}))}function nt(r){Object.entries(Ue).forEach(([t,s])=>{r.functionRegistry.register(t,s)}),Object.entries(qe).forEach(([t,s])=>{r.functionRegistry.register(t,s)}),Object.entries(Ye).forEach(([t,s])=>{r.functionRegistry.register(t,s)}),Object.entries($e).forEach(([t,s])=>{r.functionRegistry.register(t,s)}),Object.entries(He).forEach(([t,s])=>{r.functionRegistry.register(t,s)}),Object.entries(Ke).forEach(([t,s])=>{r.functionRegistry.register(t,s)}),Object.entries(ze).forEach(([t,s])=>{r.globalScope.declare(t,s)}),Qe(r),tt(r),st(r),Object.entries(Te).forEach(([t,s])=>{r.functionRegistry.register(t,s)}),r.functionRegistry.register("ScriptEngine",()=>({type:"String",value:"VBScript"})),r.functionRegistry.register("ScriptEngineMajorVersion",()=>({type:"Integer",value:10})),r.functionRegistry.register("ScriptEngineMinorVersion",()=>({type:"Integer",value:8})),r.functionRegistry.register("ScriptEngineBuildVersion",()=>({type:"Long",value:16384})),r.functionRegistry.register("Eval",t=>{const s=String(t.value??t);return r.evaluate?.(s)??{type:"Empty",value:void 0}}),r.functionRegistry.register("Execute",t=>{const s=String(t.value??t);return r.execute?.(s)??{type:"Empty",value:void 0}},{isSub:!0}),r.functionRegistry.register("ExecuteGlobal",t=>{const s=String(t.value??t);return r.executeGlobal?.(s)??{type:"Empty",value:void 0}},{isSub:!0}),r.functionRegistry.register("Print",(...t)=>(console.log(...t.map(s=>s.value??s)),{type:"Empty",value:void 0}),{isSub:!0}),r.functionRegistry.register("GetRef",t=>{const s=String(t.value??t),n=r.functionRegistry;return{type:"Object",value:{type:"vbref",name:s,getProperty:a=>a.toLowerCase()==="name"?{type:"String",value:s}:{type:"Empty",value:void 0},hasProperty:a=>a.toLowerCase()==="name",call:(...a)=>n.call(s,a)}}}),r.functionRegistry.register("TypeName",t=>{if(t.type==="Object"&&t.value&&typeof t.value=="object"){const n=t.value;if(n.classInfo&&n.classInfo.name)return{type:"String",value:n.classInfo.name}}return{type:"String",value:{Empty:"Empty",Null:"Null",Integer:"Integer",Long:"Long",Single:"Single",Double:"Double",Currency:"Currency",Date:"Date",String:"String",Object:"Object",Error:"Error",Boolean:"Boolean",Variant:"Variant",Byte:"Byte",Array:"Variant()"}[t.type]??"Variant"}}),r.functionRegistry.register("VarType",t=>({type:"Integer",value:{Empty:0,Null:1,Integer:2,Long:3,Single:4,Double:5,Currency:6,Date:7,String:8,Object:9,Error:10,Boolean:11,Variant:12,Byte:17,Array:8192}[t.type]??12})),r.functionRegistry.register("IsEmpty",t=>({type:"Boolean",value:t.type==="Empty"})),r.functionRegistry.register("IsNull",t=>({type:"Boolean",value:t.type==="Null"})),r.functionRegistry.register("IsNumeric",t=>{if(["Integer","Long","Single","Double","Currency","Byte"].includes(t.type))return{type:"Boolean",value:!0};if(t.type==="String"){const n=Number(t.value);return{type:"Boolean",value:!isNaN(n)}}return{type:"Boolean",value:!1}}),r.functionRegistry.register("IsDate",t=>{if(t.type==="Date")return{type:"Boolean",value:!0};if(t.type==="String"){const s=new Date(t.value);return{type:"Boolean",value:!isNaN(s.getTime())}}return{type:"Boolean",value:!1}}),r.functionRegistry.register("IsObject",t=>({type:"Boolean",value:t.type==="Object"})),r.functionRegistry.register("IsArray",t=>({type:"Boolean",value:t.type==="Array"})),r.functionRegistry.register("Erase",t=>({type:"Empty",value:void 0}),{isSub:!0}),r.functionRegistry.register("GetObject",(t,s)=>({type:"Object",value:null})),r.functionRegistry.register("CreateObject",(t,s)=>({type:"Object",value:{className:String(t.value??t),properties:new Map}})),r.functionRegistry.register("LoadPicture",t=>{const s=String(t.value??t);return{type:"Object",value:{classInfo:{name:"IPictureDisp"},getProperty:a=>{const i=a.toLowerCase();return i==="handle"?{type:"Long",value:0}:i==="width"?{type:"Long",value:0}:i==="height"?{type:"Long",value:0}:i==="type"?{type:"Long",value:1}:{type:"Empty",value:void 0}},hasProperty:a=>{const i=a.toLowerCase();return["handle","width","height","type"].includes(i)},_path:s}}}),r.functionRegistry.register("RGB",(t,s,n)=>{const a=Math.max(0,Math.min(255,Math.floor(Number(t.value??0)))),i=Math.max(0,Math.min(255,Math.floor(Number(s.value??0)))),o=Math.max(0,Math.min(255,Math.floor(Number(n.value??0))));return{type:"Long",value:a+i*256+o*65536}}),r.functionRegistry.register("QBColor",t=>{const s=Math.floor(Number(t.value??0));return{type:"Long",value:[0,8388608,32768,8421376,128,8388736,32896,12632256,8421504,16711680,65280,16776960,255,16711935,65535,16777215][s]??0}});const e={getProperty:t=>{const s=t.toLowerCase();return s==="number"?{type:"Long",value:r.err.number}:s==="description"?{type:"String",value:r.err.description}:s==="source"?{type:"String",value:r.err.source}:{type:"Empty",value:void 0}},setProperty:(t,s)=>{const n=t.toLowerCase();n==="number"?r.err.number=Number(s.value)||0:n==="description"?r.err.description=String(s.value??""):n==="source"&&(r.err.source=String(s.value??""))},hasMethod:t=>t.toLowerCase()==="clear"||t.toLowerCase()==="raise",getMethod:t=>{const s=t.toLowerCase();if(s==="clear")return{func:()=>(r.clearError(),{type:"Empty",value:void 0})};if(s==="raise")return{func:(n,a,i)=>(r.err.number=Number(n.value)||0,r.err.source=a?String(a.value??""):"",r.err.description=i?String(i.value??""):"",{type:"Empty",value:void 0})};throw new Error(`Unknown Err method: ${t}`)}};r.globalScope.declare("Err",{type:"Object",value:e})}class at{context;executor;maxExecutionTime=-1;startTime=0;constructor(){this.context=new Oe,this.executor=new Me(this.context),nt(this.context)}setMaxExecutionTime(e){this.maxExecutionTime=e}checkTimeout(){if(this.maxExecutionTime>0&&Date.now()-this.startTime>this.maxExecutionTime)throw new Error(`Script execution timed out after ${this.maxExecutionTime}ms`)}collectLabels(e){const t=new Map;for(let s=0;s<e.length;s++){const n=e[s];if(n.type==="VbLabelStatement"){const a=n;t.set(a.label.name.toLowerCase(),{index:s,statement:a})}}return t}run(e){this.startTime=Date.now();let t=m;const s=e.body,n=this.collectLabels(s);let a=0;const i=s.length*1e4;let o=0;for(;a<s.length;){if(o++>i)throw new Error("Possible infinite loop detected (too many goto jumps)");this.checkTimeout();const c=s[a];try{t=this.executor.execute(c),a++}catch(p){if(p instanceof U){const h=n.get(p.labelName);if(h){a=h.index+1;continue}throw new Error(`Label not found: ${p.labelName}`)}throw p instanceof E,p}}return t}getVariable(e){return this.context.getVariable(e)}setVariable(e,t){this.context.setVariable(e,t)}registerFunction(e,t){this.context.functionRegistry.register(e,t)}evaluate(e){try{const t=W(e);return new ne(this.context).evaluateProgram(t)}catch(t){return console.error("Eval error:",t),{type:"Empty",value:void 0}}}getContext(){return this.context}executeStatements(e){const t=this.collectLabels(e);let s=m,n=0;const a=e.length*1e4;let i=0;for(;n<e.length;){if(i++>a)throw new Error("Possible infinite loop detected (too many goto jumps)");this.checkTimeout();const o=e[n];try{s=this.executor.execute(o),n++}catch(c){if(c instanceof U){const p=t.get(c.labelName);if(p){n=p.index+1;continue}throw new Error(`Label not found: ${c.labelName}`)}throw c instanceof E,c}}return s}executeInCurrentScope(e){const t=W(e);return this.executeStatements(t.body)}executeInGlobalScope(e){const t=this.context.currentScope;this.context.currentScope=this.context.globalScope;try{const s=W(e);return this.executeStatements(s.body)}finally{this.context.currentScope=t}}}function D(r){switch(r.type){case"Empty":return;case"Null":return null;case"Boolean":case"Long":case"Double":case"Integer":case"String":case"Date":return r.value;case"Array":return r.value.toArray().map(D);case"Object":return r.value;default:return r.value}}function R(r,e){return r===void 0?{type:"Empty",value:void 0}:r===null?{type:"Null",value:null}:typeof r=="boolean"?{type:"Boolean",value:r}:typeof r=="number"?Number.isInteger(r)&&r>=-2147483648&&r<=2147483647?{type:"Long",value:r}:{type:"Double",value:r}:typeof r=="string"?{type:"String",value:r}:r instanceof Date?{type:"Date",value:r}:Array.isArray(r)?{type:"Array",value:r}:typeof r=="function"?{type:"Object",value:{type:"jsfunction",func:r,thisArg:e??null}}:typeof r=="object"?{type:"Object",value:r}:{type:"String",value:String(r)}}function ue(r){if(typeof window>"u")return{originalSetTimeout:null,originalSetInterval:null};const e=window.setTimeout,t=window.setInterval;return window.setTimeout=function(s,n,a,...i){if(typeof s=="string"){const o=typeof a=="string"?a.toLowerCase():null,c=typeof n=="number"?n:0;return o==="vbscript"||o==="vbs"?e.call(window,()=>{r._getContext()?.functionRegistry?.has(s)?r.run(s):r.executeStatement(s)},c):e.call(window,()=>{r._getContext()?.functionRegistry?.has(s)?r.run(s):r.executeStatement(s)},c)}return e.call(window,s,n,...[a,...i].filter(o=>o!==void 0))},window.setInterval=function(s,n,a,...i){if(typeof s=="string"){const o=typeof a=="string"?a.toLowerCase():null,c=typeof n=="number"?n:0;return o==="vbscript"||o==="vbs"?t.call(window,()=>{r._getContext()?.functionRegistry?.has(s)?r.run(s):r.executeStatement(s)},c):t.call(window,()=>{r._getContext()?.functionRegistry?.has(s)?r.run(s):r.executeStatement(s)},c)}return t.call(window,s,n,...[a,...i].filter(o=>o!==void 0))},{originalSetTimeout:e,originalSetInterval:t}}function it(r){typeof window>"u"||(r.originalSetTimeout&&(window.setTimeout=r.originalSetTimeout),r.originalSetInterval&&(window.setInterval=r.originalSetInterval))}function ot(r){if(typeof window>"u")return{originalEval:null};const e=window.eval;return window.vbsEval=function(t){return r.eval(String(t))},window.eval=function(t,s){if(typeof s=="string"){const n=s.toLowerCase();if(n==="vbscript"||n==="vbs")return r.eval(String(t))}return e.call(window,String(t))},{originalEval:e}}function ct(r){typeof window>"u"||(r.originalEval&&(window.eval=r.originalEval),delete window.vbsEval)}function lt(r){if(typeof window>"u")return{navigateHandler:null,clickHandler:null};let e=null,t=null;return"navigation"in window&&window.navigation?(e=s=>{const a=s.destination?.url;if(a&&a.toLowerCase().startsWith("vbscript:")){s.preventDefault();const i=a.substring(9);try{r.executeStatement(i)}catch(o){console.error("VBScript protocol error:",o)}}},window.navigation.addEventListener("navigate",e)):(t=s=>{const n=s.target;if(n.tagName==="A"||n.tagName==="AREA"){const a=n.getAttribute("href");if(a&&a.toLowerCase().startsWith("vbscript:")){s.preventDefault();const i=a.substring(9);try{r.executeStatement(i)}catch(o){console.error("VBScript protocol error:",o)}}}},document.addEventListener("click",t,!0)),{navigateHandler:e,clickHandler:t}}function ut(r){typeof window>"u"||(r.navigateHandler&&"navigation"in window&&window.navigation&&window.navigation.removeEventListener("navigate",r.navigateHandler),r.clickHandler&&document.removeEventListener("click",r.clickHandler,!0))}function pt(r,e){const t=String(r.value??r),s=window.ActiveXObject;if(s)try{return{type:"Object",value:{type:"activex",object:new s(t),className:t}}}catch{throw new Error(`ActiveX component can't create object: '${t}'`)}throw new Error(`ActiveXObject is not supported in this browser environment. Cannot create: '${t}'`)}function ht(r,e){const t=window.ActiveXObject;if(t){const n=r?String(r.value??r):"",a=e?String(e.value??e):"";try{if(n)return{type:"Object",value:{type:"activex",object:new t(a||"Scripting.FileSystemObject"),className:a}}}catch{throw new Error(`ActiveX component can't create object: '${a||n}'`)}}const s=e?String(e.value??e):"";throw new Error(`ActiveXObject is not supported in this browser environment. Cannot get: '${s}'`)}function H(r){const e=r.getAttribute("language"),t=r.getAttribute("type");return e?.toLowerCase()==="vbscript"||t?.toLowerCase()==="text/vbscript"||t?.toLowerCase()==="text/vbs"||t?.toLowerCase()==="application/x-vbscript"}function ft(r){let e=r.textContent??"";if(e=e.trim(),e.startsWith("<!--")){const t=e.indexOf("//-->");t!==-1?e=e.substring(4,t).trim():e.endsWith("-->")&&(e=e.substring(4,e.length-3).trim())}return e}function yt(r,e,t){if(!H(e))return;const s=ft(e),n=e.getAttribute("for"),a=e.getAttribute("event");if(n&&a)K(r,n,a,s);else try{r.addCode(s),t?.()}catch(i){console.error("Vbscript error:",i)}}function K(r,e,t,s){const n=t.toLowerCase().replace(/^on/,""),a=()=>{const i=document.getElementById(e);if(i){const o=()=>{try{r.addCode(s)}catch(c){console.error("VBScript event handler error:",c)}};return i.addEventListener(n,o),!0}return!1};a()||(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{a()}):setTimeout(a,0))}function mt(r,e){if(typeof document>"u")return;document.querySelectorAll("script").forEach(s=>{yt(r,s,e)})}function J(r,e){const t=e.attributes;for(let s=0;s<t.length;s++){const n=t[s];if(!n)continue;const a=n.name.toLowerCase();if(a.startsWith("on")&&a.length>2){const i=n.value.trim();if(i.toLowerCase().startsWith("vbscript:")){const o=i.substring(9).trim();e[a]=()=>{try{r.executeStatement(o)}catch(c){console.error("VBScript event handler error:",c)}}}}}}function gt(r){if(typeof document>"u")return;document.querySelectorAll("*").forEach(t=>{J(r,t)})}function vt(r){if(r in globalThis){const t=globalThis[r];if(t&&typeof t.addEventListener=="function")return t}const e=r.toLowerCase();for(const t of Object.keys(globalThis))if(t.toLowerCase()===e){const s=globalThis[t];if(s&&typeof s.addEventListener=="function")return s}if(typeof document<"u"){const t=document.getElementById(r);if(t)return t;const s=document.querySelectorAll("[id]");for(let n=0;n<s.length;n++){const a=s[n];if(a&&a.id.toLowerCase()===e)return a}}return null}function F(r,e){if(typeof window>"u")return;const t=r._getContext()?.functionRegistry;if(!t)return;const s=t.getUserDefinedFunctions?.();if(s)for(const[n]of s){const a=n.toLowerCase().indexOf("_on");if(a>0){const i=n.substring(0,a),o=n.substring(a+3),c=vt(i);if(c){const p=o.toLowerCase();if(e.has(n)){const g=e.get(n);g.target.removeEventListener(p,g.handler)}const h=()=>{try{r._getContext()?.functionRegistry.call(n,[])}catch(g){console.error(`VBScript ${n} error:`,g)}};c.addEventListener(p,h),e.set(n,{target:c,handler:h})}}}}function bt(r){r.forEach(({target:e,handler:t},s)=>{const n=s.toLowerCase().indexOf("_on");if(n>0){const a=s.substring(n+3).toLowerCase();e.removeEventListener(a,t)}}),r.clear()}function dt(r,e,t){const s=new MutationObserver(n=>{n.forEach(a=>{a.addedNodes.forEach(i=>{if(i.nodeType===Node.ELEMENT_NODE){const o=i;if(e.parseScriptElement&&o.tagName.toLowerCase()==="script"&&H(o)){const c=o.textContent??"",p=o.getAttribute("for"),h=o.getAttribute("event");if(p&&h)K(r,p,h,c);else try{r.addCode(c),e.injectGlobalThis&&e.parseEventSubNames&&F(r,t)}catch(g){console.error("Vbscript error:",g)}}e.parseInlineEventAttributes&&J(r,o),e.parseScriptElement&&o.querySelectorAll("script").forEach(p=>{if(H(p)){const h=p.textContent??"",g=p.getAttribute("for"),v=p.getAttribute("event");if(g&&v)K(r,g,v,h);else try{r.addCode(h),e.injectGlobalThis&&e.parseEventSubNames&&F(r,t)}catch(S){console.error("Vbscript error:",S)}}}),e.parseInlineEventAttributes&&o.querySelectorAll("*").forEach(p=>{J(r,p)})}})})});return s.observe(document.documentElement,{childList:!0,subtree:!0}),{observer:s}}function St(r){r.observer.disconnect()}function wt(r,e){const t={originalSetTimeout:null,originalSetInterval:null},s={originalEval:null};let n={navigateHandler:null,clickHandler:null},a=null;const i=new Map;return r._registerFunction("MsgBox",Ze()),r._registerFunction("InputBox",et()),r._registerFunction("CreateObject",pt),r._registerFunction("GetObject",ht),e.overrideJsEvalFunctions&&(t.originalSetTimeout=ue(r).originalSetTimeout,t.originalSetInterval=ue(r).originalSetInterval,s.originalEval=ot(r).originalEval),e.parseVbsProtocol&&(n=lt(r)),e.parseScriptElement&&mt(r),e.parseInlineEventAttributes&>(r),e.injectGlobalThis&&e.parseEventSubNames&&F(r,i),(e.parseScriptElement||e.parseInlineEventAttributes)&&(a=dt(r,e,i)),document.readyState==="loading"&&document.addEventListener("DOMContentLoaded",()=>{e.injectGlobalThis&&e.parseEventSubNames&&F(r,i)}),()=>{a&&St(a),bt(i),(n.navigateHandler||n.clickHandler)&&ut(n),e.overrideJsEvalFunctions&&(it(t),ct(s))}}class pe{interpreter;options;browserCleanup=null;lastError=null;constructor(e={}){this.options={maxExecutionTime:e.maxExecutionTime??-1,injectGlobalThis:e.injectGlobalThis??!0,mode:e.mode??"general",parseScriptElement:e.parseScriptElement??!0,parseInlineEventAttributes:e.parseInlineEventAttributes??!0,parseEventSubNames:e.parseEventSubNames??!0,overrideJsEvalFunctions:e.overrideJsEvalFunctions??!0,parseVbsProtocol:e.parseVbsProtocol??!0},this.interpreter=new at,this.interpreter.getContext().evaluate=t=>this.interpreter.evaluate(t),this.interpreter.getContext().execute=t=>this.interpreter.executeInCurrentScope(t),this.interpreter.getContext().executeGlobal=t=>this.interpreter.executeInGlobalScope(t),this.options.maxExecutionTime>0&&this.setMaxExecutionTime(this.options.maxExecutionTime),this.options.mode==="browser"&&typeof window<"u"&&this.initializeBrowserMode()}initializeBrowserMode(){this.browserCleanup=wt(this,this.options)}setMaxExecutionTime(e){this.interpreter.setMaxExecutionTime(e),this.interpreter.getContext().checkTimeout=()=>this.interpreter.checkTimeout()}get error(){return this.lastError}clearError(){this.lastError=null}addCode(e){this.clearError();try{let t=A.get(e);if(!t){const n=new j(e).tokenize();t=new T(n).parse(),A.set(e,t)}this.interpreter.run(t),this.syncFunctionsToGlobalThis()}catch(t){this.handleError(t)}}executeStatement(e){this.clearError();try{let t=A.get(e);if(!t){const n=new j(e).tokenize();t=new T(n).parse(),A.set(e,t)}this.interpreter.run(t)}catch(t){this.handleError(t)}}run(e,...t){this.clearError();try{const n=this.interpreter.getContext().functionRegistry,a=t.map(o=>R(o)),i=n.call(e,a);return D(i)}catch(s){this.handleError(s);return}}addObject(e,t,s=!0){this.clearError();try{const n=R(t);if(this.interpreter.setVariable(e,n),s&&typeof t=="object"&&t!==null){const a=t;for(const i of Object.keys(a)){const o=`${e}.${i}`,c=a[i];typeof c=="function"&&this.interpreter.registerFunction(o,(...p)=>{const h=p.map(D),g=c(...h);return R(g)})}}}catch(n){this.handleError(n)}}eval(e){this.clearError();try{const t=this.interpreter.evaluate(e);return D(t)}catch(t){this.handleError(t);return}}destroy(){this.browserCleanup&&(this.browserCleanup(),this.browserCleanup=null)}_registerFunction(e,t){this.interpreter.registerFunction(e,t)}_getContext(){return this.interpreter.getContext()}_getVariable(e){return this.interpreter.getVariable(e)}handleError(e){e instanceof Error?this.lastError={number:-1,description:e.message}:this.lastError={number:-1,description:String(e)}}syncFunctionsToGlobalThis(){if(typeof globalThis>"u"||!this.options.injectGlobalThis)return;const e=this.interpreter.getContext();if(!e)return;const t=e.functionRegistry;if(!t)return;const s=t.getUserDefinedFunctions?.();if(s){for(const[,n]of s){const a=n.name;a in globalThis||(globalThis[a]=(...i)=>this.run(a,...i))}if(e.globalScope){const n=e.globalScope.getAllVariables();for(const[a,i]of n)i.value&&i.value.type!=="Empty"&&(a in globalThis||(globalThis[a]=D(i.value)))}}}}function xt(r){return new pe().eval(r)}L.VbsEngine=pe,L.evalVbscript=xt,L.jsToVb=R,L.vbToJs=D,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}));
|
|
25
34
|
//# sourceMappingURL=vbs-engine.umd.cjs.map
|