@xnoxs/flux-lang 3.1.1
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/CHANGELOG.md +103 -0
- package/README.md +1089 -0
- package/bin/flux.js +1397 -0
- package/dist/flux.cjs.js +6664 -0
- package/dist/flux.esm.js +6674 -0
- package/dist/flux.min.js +263 -0
- package/index.d.ts +202 -0
- package/index.js +26 -0
- package/package.json +77 -0
- package/scripts/build.js +76 -0
- package/src/bundler.js +216 -0
- package/src/checker.js +322 -0
- package/src/codegen.js +785 -0
- package/src/css-preprocessor.js +399 -0
- package/src/formatter.js +140 -0
- package/src/jsx.js +480 -0
- package/src/lexer.js +518 -0
- package/src/linter.js +758 -0
- package/src/mangler.js +280 -0
- package/src/parser.js +1671 -0
- package/src/self/bundler.flux +167 -0
- package/src/self/bundler.js +187 -0
- package/src/self/checker.flux +249 -0
- package/src/self/checker.js +338 -0
- package/src/self/codegen.flux +555 -0
- package/src/self/codegen.js +784 -0
- package/src/self/css-preprocessor.flux +373 -0
- package/src/self/css-preprocessor.js +387 -0
- package/src/self/formatter.flux +93 -0
- package/src/self/formatter.js +114 -0
- package/src/self/jsx.flux +430 -0
- package/src/self/jsx.js +396 -0
- package/src/self/lexer.flux +529 -0
- package/src/self/lexer.js +709 -0
- package/src/self/lexer.stage2.js +700 -0
- package/src/self/linter.flux +515 -0
- package/src/self/linter.js +804 -0
- package/src/self/mangler.flux +253 -0
- package/src/self/mangler.js +348 -0
- package/src/self/parser.flux +1146 -0
- package/src/self/parser.js +1571 -0
- package/src/self/sourcemap.flux +66 -0
- package/src/self/sourcemap.js +72 -0
- package/src/self/stdlib.flux +356 -0
- package/src/self/stdlib.js +396 -0
- package/src/self/test-runner.flux +201 -0
- package/src/self/test-runner.js +132 -0
- package/src/self/transpiler.flux +123 -0
- package/src/self/transpiler.js +83 -0
- package/src/self/type-checker.flux +821 -0
- package/src/self/type-checker.js +1106 -0
- package/src/sourcemap.js +82 -0
- package/src/stdlib.js +436 -0
- package/src/test-runner.js +239 -0
- package/src/transpiler.js +172 -0
- package/src/type-checker.js +1206 -0
package/dist/flux.min.js
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* flux-lang v3.1.1
|
|
3
|
+
* Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.
|
|
4
|
+
* (c) 2026 Flux Lang Contributors
|
|
5
|
+
* Released under the MIT License
|
|
6
|
+
*/
|
|
7
|
+
"use strict";var F=(n,t)=>()=>{try{return t||n((t={exports:{}}).exports,t),t.exports}catch(e){throw t=0,e}};var H=F((ns,Ot)=>{"use strict";var o={NUMBER:"NUMBER",STRING:"STRING",BOOL:"BOOL",NULL:"NULL",IDENT:"IDENT",VAR:"VAR",VAL:"VAL",FN:"FN",RETURN:"RETURN",IF:"IF",ELSE:"ELSE",FOR:"FOR",IN:"IN",WHILE:"WHILE",BREAK:"BREAK",CONTINUE:"CONTINUE",DO:"DO",CLASS:"CLASS",EXTENDS:"EXTENDS",SELF:"SELF",NEW:"NEW",INTERFACE:"INTERFACE",IMPLEMENTS:"IMPLEMENTS",PRIVATE:"PRIVATE",PUBLIC:"PUBLIC",PROTECTED:"PROTECTED",READONLY:"READONLY",STATIC:"STATIC",ABSTRACT:"ABSTRACT",OVERRIDE:"OVERRIDE",MATCH:"MATCH",WHEN:"WHEN",IMPORT:"IMPORT",EXPORT:"EXPORT",FROM:"FROM",AS:"AS",DEFAULT:"DEFAULT",AND:"AND",OR:"OR",NOT:"NOT",ASYNC:"ASYNC",AWAIT:"AWAIT",TRY:"TRY",CATCH:"CATCH",FINALLY:"FINALLY",THROW:"THROW",TYPEOF:"TYPEOF",INSTANCEOF:"INSTANCEOF",TYPE:"TYPE",ENUM:"ENUM",SATISFIES:"SATISFIES",IS:"IS",CONST:"CONST",PLUS:"PLUS",MINUS:"MINUS",STAR:"STAR",SLASH:"SLASH",PERCENT:"PERCENT",REGEX:"REGEX",STARSTAR:"STARSTAR",EQ:"EQ",EQEQ:"EQEQ",NEQ:"NEQ",EQEQEQ:"EQEQEQ",NEQEQ:"NEQEQ",LT:"LT",LTE:"LTE",GT:"GT",GTE:"GTE",PLUSEQ:"PLUSEQ",MINUSEQ:"MINUSEQ",STAREQ:"STAREQ",SLASHEQ:"SLASHEQ",PERCENTEQ:"PERCENTEQ",PLUSPLUS:"PLUSPLUS",MINUSMINUS:"MINUSMINUS",AMPERSAND:"AMPERSAND",ANDAND:"ANDAND",PIPEB:"PIPEB",OROR:"OROR",CARET:"CARET",TILDE:"TILDE",LSHIFT:"LSHIFT",RSHIFT:"RSHIFT",ARROW:"ARROW",FATARROW:"FATARROW",PIPE:"PIPE",DOTDOT:"DOTDOT",DOTDOTDOT:"DOTDOTDOT",WILDCARD:"WILDCARD",NULLISH:"NULLISH",QUESTIONDOT:"QUESTIONDOT",BANG:"BANG",AT:"AT",LPAREN:"LPAREN",RPAREN:"RPAREN",LBRACKET:"LBRACKET",RBRACKET:"RBRACKET",LBRACE:"LBRACE",RBRACE:"RBRACE",COMMA:"COMMA",DOT:"DOT",COLON:"COLON",QUESTION:"QUESTION",NEWLINE:"NEWLINE",INDENT:"INDENT",DEDENT:"DEDENT",EOF:"EOF"},It={var:o.VAR,val:o.VAL,fn:o.FN,return:o.RETURN,if:o.IF,else:o.ELSE,for:o.FOR,in:o.IN,while:o.WHILE,break:o.BREAK,continue:o.CONTINUE,do:o.DO,class:o.CLASS,extends:o.EXTENDS,self:o.SELF,new:o.NEW,interface:o.INTERFACE,implements:o.IMPLEMENTS,private:o.PRIVATE,public:o.PUBLIC,protected:o.PROTECTED,readonly:o.READONLY,static:o.STATIC,abstract:o.ABSTRACT,override:o.OVERRIDE,match:o.MATCH,when:o.WHEN,import:o.IMPORT,export:o.EXPORT,from:o.FROM,as:o.AS,default:o.DEFAULT,and:o.AND,or:o.OR,not:o.NOT,async:o.ASYNC,await:o.AWAIT,try:o.TRY,catch:o.CATCH,finally:o.FINALLY,throw:o.THROW,typeof:o.TYPEOF,instanceof:o.INSTANCEOF,type:o.TYPE,enum:o.ENUM,satisfies:o.SATISFIES,is:o.IS,const:o.CONST,true:"__TRUE__",false:"__FALSE__",null:"__NULL__"},ot=class extends Error{constructor(t,e,s){super(t),this.name="LexerError",this.line=e,this.col=s}},pt=class{constructor(t){this.src=t.replace(/\r\n/g,`
|
|
8
|
+
`).replace(/\r/g,`
|
|
9
|
+
`),this.pos=0,this.line=1,this.col=1,this.tokens=[],this.indentStack=[0],this.nestDepth=0}err(t){throw new ot(t,this.line,this.col)}ch(t=0){return this.src[this.pos+t]||""}adv(){let t=this.src[this.pos++];return t===`
|
|
10
|
+
`?(this.line++,this.col=1):this.col++,t}tok(t,e,s,r){this.tokens.push({type:t,value:e!==void 0?e:t,line:s||this.line,col:r||this.col})}applyIndent(t){if(this.nestDepth>0)return;let e=this.indentStack[this.indentStack.length-1];if(t>e)this.indentStack.push(t),this.tok(o.INDENT,t,this.line,1);else if(t<e){for(;this.indentStack.length>1&&this.indentStack[this.indentStack.length-1]>t;)this.indentStack.pop(),this.tok(o.DEDENT,null,this.line,1);this.indentStack[this.indentStack.length-1]!==t&&this.err(`Inconsistent indentation (${t} spaces)`)}}scanBacktick(t,e){this.adv();let s="";for(;this.pos<this.src.length&&this.ch()!=="`";)if(this.ch()==="\\"){this.adv();let l=this.adv();s+={n:`
|
|
11
|
+
`,t:" ","`":"`","\\":"\\"}[l]||"\\"+l}else s+=this.adv();this.ch()!=="`"&&this.err("Unterminated backtick string"),this.adv();let a=s.split(`
|
|
12
|
+
`).map(l=>l.trimEnd());for(;a.length&&!a[0].trim();)a.shift();for(;a.length&&!a[a.length-1].trim();)a.pop();let h=a.filter(l=>l.trim()).reduce((l,p)=>{let u=p.match(/^(\s*)/)[1].length;return Math.min(l,u)},1/0),c=a.map(l=>l.slice(h===1/0?0:h));this.tok(o.STRING,c.join(`
|
|
13
|
+
`),t,e)}scanStr(t,e){this.adv();let s=[],r="";for(;this.pos<this.src.length&&this.ch()!=='"';)if(this.ch()==="\\"){this.adv();let a=this.adv();r+={n:`
|
|
14
|
+
`,t:" ",'"':'"',"'":"'","\\":"\\","{":"{","}":"}"}[a]||"\\"+a}else if(this.ch()==="{"){s.push({type:"text",value:r}),r="",this.adv();let a=1,h="";for(;this.pos<this.src.length&&(this.ch()==="{"&&a++,!(this.ch()==="}"&&(a--,a===0)));)this.ch()==="\\"&&(this.src[this.pos+1]==='"'||this.src[this.pos+1]==="'")?(this.adv(),h+=this.adv()):h+=this.adv();this.ch()!=="}"&&this.err("Unclosed string interpolation"),this.adv(),s.push({type:"expr",value:h.trim()})}else r+=this.adv();this.ch()!=='"'&&this.err("Unterminated string"),this.adv(),s.push({type:"text",value:r}),s.some(a=>a.type==="expr")?this.tok(o.STRING,{template:!0,parts:s},t,e):this.tok(o.STRING,s.map(a=>a.value).join(""),t,e)}scanRegexBody(t,e){let s="",r=!1;for(;this.pos<this.src.length;){let h=this.ch();if(h===`
|
|
15
|
+
`&&this.err("Unterminated regex literal"),h==="\\"){s+=this.adv(),this.pos<this.src.length&&(s+=this.adv());continue}if(h==="["){r=!0,s+=this.adv();continue}if(h==="]"){r=!1,s+=this.adv();continue}if(h==="/"&&!r)break;s+=this.adv()}this.ch()!=="/"&&this.err("Unterminated regex literal"),this.adv();let a="";for(;/[gimsuy]/.test(this.ch());)a+=this.adv();this.tok(o.REGEX,{pattern:s,flags:a},t,e)}scanBlockComment(){for(this.adv(),this.adv();this.pos<this.src.length;){if(this.ch()==="*"&&this.ch(1)==="/"){this.adv(),this.adv();return}this.adv()}this.err("Unterminated block comment")}tokenize(){let t=!0;for(;this.pos<this.src.length;){if(t){t=!1;let h=0;for(;this.ch()===" "||this.ch()===" ";)h+=this.ch()===" "?4:1,this.adv();if(this.ch()===`
|
|
16
|
+
`||!this.ch()){this.ch()===`
|
|
17
|
+
`&&(this.adv(),t=!0);continue}if(this.ch()==="/"&&this.ch(1)==="/"){for(;this.pos<this.src.length&&this.ch()!==`
|
|
18
|
+
`;)this.adv();this.ch()===`
|
|
19
|
+
`&&(this.adv(),t=!0);continue}if(this.ch()==="/"&&this.ch(1)==="*"){this.scanBlockComment();continue}if(this.ch()==="|"&&this.ch(1)===">"||this.ch()==="."||this.ch()==="?"&&this.ch(1)==="."){let l=this.tokens[this.tokens.length-1];l&&l.type===o.NEWLINE&&this.tokens.pop()}else this.applyIndent(h)}let s=this.line,r=this.col,a=this.ch();if(a===`
|
|
20
|
+
`){if(this.adv(),t=!0,this.nestDepth===0){let h=this.tokens[this.tokens.length-1];h&&h.type!==o.NEWLINE&&h.type!==o.INDENT&&h.type!==o.DEDENT&&this.tok(o.NEWLINE,null,s,r)}continue}if(a===" "||a===" "){this.adv();continue}if(a==="/"&&this.ch(1)==="/"){for(;this.pos<this.src.length&&this.ch()!==`
|
|
21
|
+
`;)this.adv();continue}if(a==="/"&&this.ch(1)==="*"){this.scanBlockComment();continue}if(a>="0"&&a<="9"){if(a==="0"&&(this.ch(1)==="x"||this.ch(1)==="X")){this.adv(),this.adv();let c="";for(;/[0-9a-fA-F_]/.test(this.ch());){let l=this.adv();l!=="_"&&(c+=l)}this.tok(o.NUMBER,parseInt(c||"0",16),s,r);continue}if(a==="0"&&(this.ch(1)==="b"||this.ch(1)==="B")){this.adv(),this.adv();let c="";for(;/[01_]/.test(this.ch());){let l=this.adv();l!=="_"&&(c+=l)}this.tok(o.NUMBER,parseInt(c||"0",2),s,r);continue}let h="";for(;this.pos<this.src.length&&!(this.ch()==="."&&this.ch(1)===".");)if(this.ch()>="0"&&this.ch()<="9"||this.ch()===".")h+=this.adv();else if(this.ch()==="_")this.adv();else if((this.ch()==="e"||this.ch()==="E")&&h.length>0){for(h+=this.adv(),(this.ch()==="+"||this.ch()==="-")&&(h+=this.adv());this.ch()>="0"&&this.ch()<="9";)h+=this.adv();break}else break;this.tok(o.NUMBER,parseFloat(h),s,r);continue}if(a==='"'){this.scanStr(s,r);continue}if(a==="`"){this.scanBacktick(s,r);continue}if(a==="'"){this.adv();let h="";for(;this.pos<this.src.length&&this.ch()!=="'";)if(this.ch()==="\\"){this.adv();let c=this.adv();h+={n:`
|
|
22
|
+
`,t:" ",r:"\r","'":"'","\\":"\\"}[c]||"\\"+c}else h+=this.adv();this.ch()!=="'"&&this.err("Unterminated string"),this.adv(),this.tok(o.STRING,h,s,r);continue}if(a>="a"&&a<="z"||a>="A"&&a<="Z"||a==="_"){let h="";for(;/[a-zA-Z0-9_]/.test(this.ch());)h+=this.adv();if(h==="_"&&!/[a-zA-Z0-9_]/.test(this.ch())){this.tok(o.WILDCARD,"_",s,r);continue}let c=Object.prototype.hasOwnProperty.call(It,h)?It[h]:void 0;c==="__TRUE__"?this.tok(o.BOOL,!0,s,r):c==="__FALSE__"?this.tok(o.BOOL,!1,s,r):c==="__NULL__"?this.tok(o.NULL,null,s,r):c?this.tok(c,h,s,r):this.tok(o.IDENT,h,s,r);continue}switch(this.adv(),a){case"+":this.ch()==="+"?(this.adv(),this.tok(o.PLUSPLUS,"++",s,r)):this.ch()==="="?(this.adv(),this.tok(o.PLUSEQ,"+=",s,r)):this.tok(o.PLUS,"+",s,r);break;case"-":this.ch()==="-"?(this.adv(),this.tok(o.MINUSMINUS,"--",s,r)):this.ch()===">"?(this.adv(),this.tok(o.ARROW,"->",s,r)):this.ch()==="="?(this.adv(),this.tok(o.MINUSEQ,"-=",s,r)):this.tok(o.MINUS,"-",s,r);break;case"*":this.ch()==="*"?(this.adv(),this.tok(o.STARSTAR,"**",s,r)):this.ch()==="="?(this.adv(),this.tok(o.STAREQ,"*=",s,r)):this.tok(o.STAR,"*",s,r);break;case"/":if(this.ch()==="=")this.adv(),this.tok(o.SLASHEQ,"/=",s,r);else{let h=this.tokens[this.tokens.length-1];h&&(h.type===o.IDENT||h.type===o.NUMBER||h.type===o.STRING||h.type===o.BOOL||h.type===o.NULL||h.type===o.REGEX||h.type===o.RPAREN||h.type===o.RBRACKET||h.type===o.PLUSPLUS||h.type===o.MINUSMINUS||h.type===o.BANG)?this.tok(o.SLASH,"/",s,r):this.scanRegexBody(s,r)}break;case"%":this.ch()==="="?(this.adv(),this.tok(o.PERCENTEQ,"%=",s,r)):this.tok(o.PERCENT,"%",s,r);break;case"=":this.ch()==="="&&this.ch(1)==="="?(this.adv(),this.adv(),this.tok(o.EQEQEQ,"===",s,r)):this.ch()==="="?(this.adv(),this.tok(o.EQEQ,"==",s,r)):this.ch()===">"?(this.adv(),this.tok(o.FATARROW,"=>",s,r)):this.tok(o.EQ,"=",s,r);break;case"!":this.ch()==="="&&this.ch(1)==="="?(this.adv(),this.adv(),this.tok(o.NEQEQ,"!==",s,r)):this.ch()==="="?(this.adv(),this.tok(o.NEQ,"!=",s,r)):this.tok(o.BANG,"!",s,r);break;case"<":this.ch()==="<"?(this.adv(),this.tok(o.LSHIFT,"<<",s,r)):this.ch()==="="?(this.adv(),this.tok(o.LTE,"<=",s,r)):this.tok(o.LT,"<",s,r);break;case">":this.ch()===">"?(this.adv(),this.tok(o.RSHIFT,">>",s,r)):this.ch()==="="?(this.adv(),this.tok(o.GTE,">=",s,r)):this.tok(o.GT,">",s,r);break;case".":this.ch()==="."&&this.ch(1)==="."?(this.adv(),this.adv(),this.tok(o.DOTDOTDOT,"...",s,r)):this.ch()==="."?(this.adv(),this.tok(o.DOTDOT,"..",s,r)):this.tok(o.DOT,".",s,r);break;case"?":this.ch()==="."?(this.adv(),this.tok(o.QUESTIONDOT,"?.",s,r)):this.ch()==="?"?(this.adv(),this.tok(o.NULLISH,"??",s,r)):this.tok(o.QUESTION,"?",s,r);break;case"|":this.ch()===">"?(this.adv(),this.tok(o.PIPE,"|>",s,r)):this.ch()==="|"?(this.adv(),this.tok(o.OROR,"||",s,r)):this.tok(o.PIPEB,"|",s,r);break;case"&":this.ch()==="&"?(this.adv(),this.tok(o.ANDAND,"&&",s,r)):this.tok(o.AMPERSAND,"&",s,r);break;case"^":this.tok(o.CARET,"^",s,r);break;case"~":this.tok(o.TILDE,"~",s,r);break;case"@":this.tok(o.AT,"@",s,r);break;case";":break;case"(":this.nestDepth++,this.tok(o.LPAREN,"(",s,r);break;case")":this.nestDepth--,this.tok(o.RPAREN,")",s,r);break;case"[":this.nestDepth++,this.tok(o.LBRACKET,"[",s,r);break;case"]":this.nestDepth--,this.tok(o.RBRACKET,"]",s,r);break;case"{":this.nestDepth++,this.tok(o.LBRACE,"{",s,r);break;case"}":this.nestDepth--,this.tok(o.RBRACE,"}",s,r);break;case",":this.tok(o.COMMA,",",s,r);break;case":":this.tok(o.COLON,":",s,r);break;default:this.err(`Unknown character: '${a}'`)}}for(;this.indentStack.length>1;)this.indentStack.pop(),this.tok(o.DEDENT,null,this.line,1);let e=this.tokens[this.tokens.length-1];return e&&e.type!==o.NEWLINE&&e.type!==o.DEDENT&&this.tok(o.NEWLINE,null,this.line,this.col),this.tok(o.EOF,null,this.line,this.col),this.tokens}};Ot.exports={Lexer:pt,T:o,TokenType:o}});var K=F((as,_t)=>{"use strict";var{T:i}=H(),Dt={COLON:'":"',COMMA:'","',DOT:'"."',LPAREN:'"("',RPAREN:'")"',LBRACKET:'"["',RBRACKET:'"]"',LBRACE:'"{"',RBRACE:'"}"',ARROW:'"->"',FATARROW:'"=>"',EQ:'"="',EQEQ:'"=="',NEQ:'"!="',PLUS:'"+"',MINUS:'"-"',STAR:'"*"',SLASH:'"/"',PERCENT:'"%"',STARSTAR:'"**"',LT:'"<"',GT:'">"',LTE:'"<="',GTE:'">="',PIPE:'"|>"',PIPEB:'"|"',DOTDOT:'".."',DOTDOTDOT:'"..."',QUESTION:'"?"',BANG:'"!"',NEWLINE:"end of line",INDENT:"indented block",DEDENT:"end of block",EOF:"end of file",IDENT:"identifier",NUMBER:"number",STRING:"string",BOOL:"true/false",NULL:"null",FN:'"fn"',VAL:'"val"',VAR:'"var"',IF:'"if"',ELSE:'"else"',FOR:'"for"',WHILE:'"while"',IN:'"in"',RETURN:'"return"',CLASS:'"class"',NEW:'"new"',SELF:'"self"',IMPORT:'"import"',FROM:'"from"',EXPORT:'"export"',MATCH:'"match"',WHEN:'"when"',AND:'"and"',OR:'"or"',NOT:'"not"',ASYNC:'"async"',AWAIT:'"await"',TRY:'"try"',CATCH:'"catch"',FINALLY:'"finally"',THROW:'"throw"'};function $t(n,t){return Dt[n]?Dt[n]:t!=null&&t!==n?`"${t}"`:`"${n.toLowerCase()}"`}var U=class extends Error{constructor(t,e){super(t),this.name="ParseError",this.tok=e,this.line=e?e.line:null,this.col=e?e.col:null}},Ee=["val","var","fn","return","if","else","for","in","while","do","break","continue","match","when","class","extends","self","new","interface","implements","import","export","from","as","default","and","or","not","async","await","try","catch","finally","throw","type","enum","static","abstract","override","readonly","private","public","protected","true","false","null"],vt={function:{fix:"fn",note:'Flux uses "fn" instead of "function"'},func:{fix:"fn",note:'Flux uses "fn" for functions'},def:{fix:"fn",note:'Flux uses "fn" for functions (not "def" like Python)'},const:{fix:"val",note:'Flux uses "val" for immutable bindings (not "const")'},let:{fix:"var",note:'Flux uses "var" for mutable bindings (not "let")'},elif:{fix:"else if",note:'Flux uses "else if" (not "elif" like Python)'},elsif:{fix:"else if",note:'Flux uses "else if" (not "elsif")'},elseif:{fix:"else if",note:'Flux uses "else if" as two separate keywords'},switch:{fix:"match",note:'Flux uses "match/when" instead of "switch/case"'},case:{fix:"when",note:'Flux uses "when" inside a "match" block'},foreach:{fix:"for ... in",note:'Flux uses "for item in collection:" syntax'},forEach:{fix:"for ... in",note:'Flux uses "for item in collection:" syntax'},lambda:{fix:"fn",note:'Flux uses "fn" or the "->" arrow for inline functions'},struct:{fix:"class",note:'Flux uses "class" for data types (no structs)'},interface:null,print:null,Fn:{fix:"fn",note:"Flux keywords are lowercase"},FN:{fix:"fn",note:"Flux keywords are lowercase"},Val:{fix:"val",note:"Flux keywords are lowercase"},Var:{fix:"var",note:"Flux keywords are lowercase"},If:{fix:"if",note:"Flux keywords are lowercase"},Else:{fix:"else",note:"Flux keywords are lowercase"},For:{fix:"for",note:"Flux keywords are lowercase"},While:{fix:"while",note:"Flux keywords are lowercase"},Return:{fix:"return",note:"Flux keywords are lowercase"},Class:{fix:"class",note:"Flux keywords are lowercase"},Import:{fix:"import",note:"Flux keywords are lowercase"},Export:{fix:"export",note:"Flux keywords are lowercase"},New:{fix:"new",note:"Flux keywords are lowercase"},True:{fix:"true",note:"Flux keywords are lowercase"},False:{fix:"false",note:"Flux keywords are lowercase"},Null:{fix:"null",note:"Flux keywords are lowercase"},Async:{fix:"async",note:"Flux keywords are lowercase"},Await:{fix:"await",note:"Flux keywords are lowercase"},Match:{fix:"match",note:"Flux keywords are lowercase"},Try:{fix:"try",note:"Flux keywords are lowercase"},Catch:{fix:"catch",note:"Flux keywords are lowercase"}};function ke(n,t,e=2){if(Math.abs(n.length-t.length)>e)return e+1;let s=n.length,r=t.length,a=new Uint8Array(r+1),h=new Uint8Array(r+1);for(let c=0;c<=r;c++)a[c]=c;for(let c=1;c<=s;c++){h[0]=c;let l=c;for(let p=1;p<=r;p++){let u=n[c-1]===t[p-1]?0:1;h[p]=Math.min(h[p-1]+1,a[p]+1,a[p-1]+u),h[p]<l&&(l=h[p])}if(l>e)return e+1;h.copyWithin(0,0,r+1),a.set(h)}return a[r]}function Lt(n){if(!n||n.length<2)return null;if(Object.prototype.hasOwnProperty.call(vt,n)){let s=vt[n];return s?`Did you mean "${s.fix}"? ${s.note}`:null}let t=3,e=null;for(let s of Ee){if(Math.abs(n.length-s.length)>2)continue;let r=ke(n.toLowerCase(),s,2);r<t&&(t=r,e=s)}return e&&t<=2&&n!==e?`Did you mean "${e}"?`:null}var ut=class{constructor(t){this.tokens=t,this.pos=0}peek(t=0){return this.tokens[this.pos+t]||{type:i.EOF,value:null,line:0,col:0}}check(t){return this.peek().type===t}at(...t){return t.includes(this.peek().type)}eat(t){let e=this.peek();if(e.type!==t){let s=$t(t,null),r=$t(e.type,e.value),a=new U(`Expected ${s} but got ${r}`,e);if(e.type===i.IDENT){let h=Lt(e.value);h&&(a.hint=h)}throw a}return this.pos++,e}maybe(t){return this.check(t)?(this.pos++,!0):!1}skip(){return this.tokens[this.pos++]}skipNewlines(){for(;this.check(i.NEWLINE);)this.pos++}err(t){throw new U(t,this.peek())}parseBlock(){if(this.eat(i.COLON),this.check(i.NEWLINE)){this.pos++,this.eat(i.INDENT);let e=this.parseStmtList(()=>this.check(i.DEDENT)||this.check(i.EOF));return this.maybe(i.DEDENT),e}return[this.parseOneStmt()]}parseIndentedBlock(){this.eat(i.NEWLINE),this.eat(i.INDENT);let t=this.parseStmtList(()=>this.check(i.DEDENT)||this.check(i.EOF));return this.maybe(i.DEDENT),t}parse(){return this.skipNewlines(),{type:"Program",body:this.parseStmtList(()=>this.check(i.EOF))}}parseStmtList(t){let e=[];for(;!t()&&(this.skipNewlines(),!t());)e.push(this.parseOneStmt());return e}parseOneStmt(){let t=this.peek();switch(t.type){case i.VAR:case i.VAL:return this.parseVarDecl();case i.FN:return this.parseFnDecl();case i.ASYNC:return this.parseAsyncFn();case i.CLASS:return this.parseClassDecl();case i.IF:return this.parseIf();case i.FOR:return this.parseFor();case i.WHILE:return this.parseWhile();case i.DO:return this.parseDoWhile();case i.MATCH:return this.parseMatch();case i.RETURN:return this.parseReturn();case i.BREAK:{this.skip();let e=!this.check(i.NEWLINE)&&!this.check(i.EOF)&&this.check(i.IDENT)?this.skip().value:null;return this.skipNewlines(),{type:"BreakStmt",label:e,loc:t}}case i.CONTINUE:{this.skip();let e=!this.check(i.NEWLINE)&&!this.check(i.EOF)&&this.check(i.IDENT)?this.skip().value:null;return this.skipNewlines(),{type:"ContinueStmt",label:e,loc:t}}case i.IMPORT:return this.parseImport();case i.EXPORT:return this.parseExport();case i.TRY:return this.parseTryCatch();case i.THROW:return this.parseThrow();case i.TYPE:return this.parseTypeDecl();case i.INTERFACE:return this.parseInterfaceDecl();case i.ENUM:return this.parseEnumDecl();default:{let e={[i.CONST]:{msg:'"const" is not a Flux keyword',hint:'Did you mean "val"? Flux uses "val" for immutable bindings (not "const")'},[i.TYPEOF]:{msg:'"typeof" is an expression, not a statement'},[i.INSTANCEOF]:{msg:'"instanceof" is an expression, not a statement'},[i.SATISFIES]:{msg:'"satisfies" is a type expression, not a statement'}};if(Object.prototype.hasOwnProperty.call(e,t.type)){let s=e[t.type],r=new U(s.msg,t);throw s.hint&&(r.hint=s.hint),r}if(t.type===i.IDENT&&this.peek(1).type===i.COLON){let s=this.peek(2).type;if(s===i.FOR||s===i.WHILE){let r=this.skip().value;this.pos++;let a=this.parseOneStmt();return{type:"LabeledStmt",label:r,body:a,loc:t}}}if(t.type===i.IDENT){let s=this.peek(1).type;if(!(s===i.DOT||s===i.LPAREN||s===i.LBRACKET||s===i.EQ||s===i.PLUSEQ||s===i.MINUSEQ||s===i.STAREQ||s===i.SLASHEQ||s===i.PERCENTEQ||s===i.ARROW||s===i.FATARROW||s===i.QUESTION||s===i.EQEQ||s===i.NEQ||s===i.AND||s===i.OR||s===i.PIPE)){let a=Lt(t.value);if(a){let h=new U(`Unexpected identifier "${t.value}"`,t);throw h.hint=a,h}}}return this.parseExprStmt()}}}parseVarDecl(){let t=this.peek().type===i.VAR?"var":"val",e=this.skip();if(this.check(i.LBRACE)){let h=this.parseObjectDestructurePattern();this.eat(i.EQ);let c=this.parseExpr();return this.skipNewlines(),{type:"DestructureDecl",kind:t,patternType:"object",pattern:h,init:c,loc:e}}if(this.check(i.LBRACKET)){let h=this.parseArrayDestructurePattern();this.eat(i.EQ);let c=this.parseExpr();return this.skipNewlines(),{type:"DestructureDecl",kind:t,patternType:"array",pattern:h,init:c,loc:e}}let s=this.eat(i.IDENT).value,r=null;this.maybe(i.COLON)&&(r=this.parseTypeAnn());let a=null;return this.maybe(i.EQ)&&(a=this.parseExpr()),this.skipNewlines(),{type:"VarDecl",kind:t,name:s,typeAnn:r,init:a,loc:e}}parseObjectDestructurePattern(){this.eat(i.LBRACE);let t=[];for(;!this.check(i.RBRACE)&&!this.check(i.EOF);){let e=!1;this.check(i.DOTDOTDOT)&&(this.pos++,e=!0);let s=this.eat(i.IDENT).value;if(e){t.push({key:s,alias:s,rest:!0});break}let r=s;this.maybe(i.COLON)&&(r=this.eat(i.IDENT).value);let a=null;if(this.maybe(i.EQ)&&(a=this.parseExpr()),t.push({key:s,alias:r,defaultVal:a,rest:!1}),!this.maybe(i.COMMA))break}return this.eat(i.RBRACE),t}parseArrayDestructurePattern(){this.eat(i.LBRACKET);let t=[];for(;!this.check(i.RBRACKET)&&!this.check(i.EOF);){if(this.check(i.COMMA)){t.push(null),this.pos++;continue}let e=!1;this.check(i.DOTDOTDOT)&&(this.pos++,e=!0);let s=this.eat(i.IDENT).value,r=null;if(this.maybe(i.EQ)&&(r=this.parseExpr()),t.push({name:s,defaultVal:r,rest:e}),e||!this.maybe(i.COMMA))break}return this.eat(i.RBRACKET),t}parseTypeAnn(){let t=this._parseIntersectionType();for(;this.check(i.PIPEB);)this.pos++,t+=" | "+this._parseIntersectionType();return t}_parseIntersectionType(){let t=this._parseSingleType();for(;this.check(i.AMPERSAND);)this.pos++,t+=" & "+this._parseSingleType();return t}_parseSingleType(){let t=this.peek();if(t.type===i.LBRACKET){this.pos++;let s=[];for(;!this.check(i.RBRACKET)&&!this.check(i.EOF)&&(s.push(this.parseTypeAnn()),!!this.maybe(i.COMMA)););return this.eat(i.RBRACKET),"["+s.join(", ")+"]"}if(t.type===i.LBRACE){this.pos++;let s=[];for(;!this.check(i.RBRACE)&&!this.check(i.EOF);){let r=!1;if(this.check(i.READONLY)&&(this.pos++,r=!0),this.check(i.LBRACKET)){this.pos++;let a=this.eat(i.IDENT).value;this.eat(i.COLON);let h=this.parseTypeAnn();this.eat(i.RBRACKET),this.eat(i.COLON);let c=this.parseTypeAnn();s.push(`[${a}: ${h}]: ${c}`)}else{let a=this.at(i.IDENT,i.STRING)?this.skip().value:this.eat(i.IDENT).value,h=!1;this.check(i.QUESTION)&&(this.pos++,h=!0),this.eat(i.COLON);let c=this.parseTypeAnn(),l=r?"readonly ":"";s.push(`${l}${a}${h?"?":""}: ${c}`)}this.maybe(i.COMMA)}return this.eat(i.RBRACE),"{ "+s.join(", ")+" }"}if(t.type===i.LPAREN){this.pos++;let s=this.parseTypeAnn();return this.eat(i.RPAREN),"("+s+")"}if(t.type===i.IDENT&&t.value==="keyof")return this.pos++,"keyof "+this._parseSingleType();if(t.type===i.TYPEOF)return this.pos++,"typeof "+this.eat(i.IDENT).value;if(t.type===i.READONLY)return this.pos++,"readonly "+this._parseSingleType();if(t.type===i.IDENT&&t.value==="infer")return this.pos++,"infer "+this.eat(i.IDENT).value;if(t.type===i.FN){this.pos++;let s=[];if(this.check(i.LPAREN)){for(this.pos++;!this.check(i.RPAREN)&&!this.check(i.EOF);){let a;if(this.check(i.IDENT)&&this.peek(1).type===i.COLON?(this.pos+=2,a=this.parseTypeAnn()):a=this.parseTypeAnn(),s.push(a),!this.maybe(i.COMMA))break}this.eat(i.RPAREN)}let r="Void";return this.check(i.ARROW)&&(this.pos++,r=this.parseTypeAnn()),`fn(${s.join(", ")}) -> ${r}`}let e;if(t.type===i.IDENT||t.type===i.CONST||t.type===i.TYPE?e=this.skip().value:e=this.eat(i.IDENT).value,this.check(i.EXTENDS)){this.pos++;let s=this._parseSingleType();this.eat(i.QUESTION);let r=this.parseTypeAnn();this.eat(i.COLON);let a=this.parseTypeAnn();return`${e} extends ${s} ? ${r} : ${a}`}if(this.check(i.LT)){this.pos++;let s=[this._parseGenericArg()];for(;this.maybe(i.COMMA);)s.push(this._parseGenericArg());this.eat(i.GT),e+="<"+s.join(", ")+">"}for(;this.check(i.LBRACKET)&&this.peek(1).type===i.RBRACKET;)this.pos+=2,e+="[]";return this.check(i.QUESTION)&&this.peek(1).type!==i.DOT&&(this.pos++,e+="?"),e}_parseGenericArg(){return this.parseTypeAnn()}_isTypeAnnBeforeColon(){let t=s=>this.tokens[this.pos+s]||{type:i.EOF},e=0;if(t(e).type===i.LBRACKET||t(e).type===i.LBRACE||t(e).type===i.LPAREN){let s=0,r=new Set([i.LBRACKET,i.LBRACE,i.LPAREN,i.LT]),a=new Set([i.RBRACKET,i.RBRACE,i.RPAREN,i.GT]);for(;t(e).type!==i.EOF&&(r.has(t(e).type)&&s++,a.has(t(e).type)&&s--,e++,s!==0););for(t(e).type===i.QUESTION&&e++;t(e).type===i.PIPEB||t(e).type===i.AMPERSAND;){if(e++,t(e).type!==i.IDENT)return!1;e++}return t(e).type===i.COLON}if((t(e).type===i.TYPEOF||t(e).type===i.READONLY||t(e).type===i.IDENT&&(t(e).value==="keyof"||t(e).value==="readonly"))&&e++,t(e).type!==i.IDENT)return!1;if(e++,t(e).type===i.LT){e++;let s=1;for(;t(e).type!==i.EOF&&s>0;)t(e).type===i.LT&&s++,t(e).type===i.GT&&s--,e++}for(;t(e).type===i.LBRACKET&&t(e+1).type===i.RBRACKET;)e+=2;for(t(e).type===i.QUESTION&&e++;t(e).type===i.PIPEB;){if(e++,t(e).type!==i.IDENT)return!1;if(e++,t(e).type===i.LT){e++;let s=1;for(;t(e).type!==i.EOF&&s>0;)t(e).type===i.LT&&s++,t(e).type===i.GT&&s--,e++}for(;t(e).type===i.LBRACKET&&t(e+1).type===i.RBRACKET;)e+=2;t(e).type===i.QUESTION&&e++}return t(e).type===i.COLON}parseTypeDecl(){let t=this.eat(i.TYPE),e=this.eat(i.IDENT).value,s=[];if(this.check(i.LT)){for(this.pos++;!this.check(i.GT)&&!this.check(i.EOF)&&(s.push(this.eat(i.IDENT).value),!!this.maybe(i.COMMA)););this.eat(i.GT)}this.eat(i.EQ);let r=[];for(;;){let a=this.eat(i.IDENT).value,h=[],c={};if(this.check(i.LPAREN)){for(this.eat(i.LPAREN);!this.check(i.RPAREN)&&!this.check(i.EOF);){let l=this.peek(),p;if(l.type===i.IDENT||l.type in i?p=this.skip().value:this.err(`Expected field name, got '${l.type}'`),this.maybe(i.COLON)&&(c[p]=this.parseTypeAnn()),h.push(p),!this.maybe(i.COMMA))break}this.eat(i.RPAREN)}if(r.push({name:a,fields:h,fieldTypes:c}),!this.check(i.PIPEB))break;this.pos++}return this.skipNewlines(),{type:"TypeDecl",name:e,variants:r,loc:t}}_isColonReturnType(){let t=this.pos;try{return this.pos++,this.at(i.IDENT,i.LBRACKET,i.LBRACE,i.LPAREN,i.FN,i.READONLY,i.TYPEOF)?(this.parseTypeAnn(),this.check(i.NEWLINE)||this.check(i.EOF)):!1}catch{return!1}finally{this.pos=t}}parseFnDecl(t=!1){let e=this.eat(i.FN),s=new Set([i.NEW,i.DELETE,i.FROM,i.AS,i.DEFAULT,i.IS,i.IN,i.TYPE]),r=this.check(i.IDENT)||s.has(this.peek().type)?this.skip().value:null,a=this.parseParamList(),h=null;if(this.check(i.ARROW))if(this.pos++,this._isTypeAnnBeforeColon()){h=this.parseTypeAnn();let c=this.parseBlock();return{type:"FnDecl",name:r,params:a,retType:h,body:c,inline:!1,async:t,loc:e}}else{let c=this.parseExpr();return this.skipNewlines(),{type:"FnDecl",name:r,params:a,retType:null,body:c,inline:!0,async:t,loc:e}}if(this.check(i.COLON)){if(this._isColonReturnType()){if(this.pos++,h=this.parseTypeAnn(),this.check(i.NEWLINE)&&this.pos++,this.check(i.INDENT)){this.pos++;let p=this.parseStmtList(()=>this.check(i.DEDENT)||this.check(i.EOF));return this.maybe(i.DEDENT),{type:"FnDecl",name:r,params:a,retType:h,body:p,inline:!1,async:t,loc:e}}let l=this.parseOneStmt();return{type:"FnDecl",name:r,params:a,retType:h,body:[l],inline:!1,async:t,loc:e}}let c=this.parseBlock();return{type:"FnDecl",name:r,params:a,retType:null,body:c,inline:!1,async:t,loc:e}}this.err("Expected -> or : after function signature")}parseAsyncFn(){return this.eat(i.ASYNC),this.check(i.FN)||this.err("Expected fn after async"),this.parseFnDecl(!0)}parseParamList(){this.eat(i.LPAREN);let t=[];for(;!this.check(i.RPAREN)&&!this.check(i.EOF);){let e=!1;this.check(i.DOTDOTDOT)&&(this.pos++,e=!0);let s=this.eat(i.IDENT).value,r=!1,a=null;!e&&this.check(i.QUESTION)&&(this.pos++,r=!0),!e&&this.maybe(i.COLON)&&(a=this.parseTypeAnn());let h=null;if(!e&&this.maybe(i.EQ)&&(h=this.parseExpr()),t.push({name:s,typeAnn:a,optional:r,defaultVal:h,rest:e}),e||!this.maybe(i.COMMA))break}return this.eat(i.RPAREN),t}parseAccessModifiers(){let t=new Set,e=new Set([i.PRIVATE,i.PUBLIC,i.PROTECTED,i.READONLY,i.STATIC,i.ABSTRACT,i.OVERRIDE]);for(;e.has(this.peek().type);)t.add(this.skip().value);return t}parseClassDecl(){let t=this.eat(i.CLASS),e=this.eat(i.IDENT).value,s=null,r=[],a=[];if(this.check(i.LT)){for(this.pos++,a.push(this.eat(i.IDENT).value);this.maybe(i.COMMA);)a.push(this.eat(i.IDENT).value);this.eat(i.GT)}if(this.maybe(i.EXTENDS)&&(s=this.eat(i.IDENT).value),this.maybe(i.IMPLEMENTS))for(r.push(this.eat(i.IDENT).value);this.maybe(i.COMMA);)r.push(this.eat(i.IDENT).value);this.eat(i.COLON),this.check(i.NEWLINE)&&(this.pos++,this.eat(i.INDENT));let h=[],c=[];for(;!this.check(i.DEDENT)&&!this.check(i.EOF)&&(this.skipNewlines(),!(this.check(i.DEDENT)||this.check(i.EOF)));){let l=this.parseAccessModifiers(),p=this.check(i.IDENT)&&(this.peek().value==="get"||this.peek().value==="set")&&(this.peek(1).type===i.IDENT||this.peek(1).type===i.FN),u=this.check(i.FN)&&this.peek(1).type===i.IDENT&&(this.peek(1).value==="get"||this.peek(1).value==="set")&&this.peek(2).type===i.IDENT;if(p&&this.peek(1).type!==i.FN){let m=this.peek(),x=this.skip().value,S=this.eat(i.IDENT).value,N=this.parseParamList(),f=null;this.check(i.ARROW)?(this.pos++,this._isTypeAnnBeforeColon()&&(f=this.parseTypeAnn())):this.check(i.COLON)&&this._isColonReturnType()&&(this.pos++,f=this.parseTypeAnn());let d=this.parseBlock(),w={type:"FnDecl",name:S,params:N,retType:f,body:d,inline:!1,async:!1,modifiers:l,getset:x,loc:m};c.push(w)}else if(this.check(i.FN)){let m=this.parseFnDecl();m.modifiers=l,c.push(m)}else if(this.check(i.ASYNC)){let m=this.parseAsyncFn();m.modifiers=l,c.push(m)}else if(this.check(i.STATIC)&&(this.peek(1).type===i.FN||this.peek(1).type===i.ASYNC)){this.skip();let m=this.check(i.ASYNC)?this.parseAsyncFn():this.parseFnDecl();m.modifiers=l,m.modifiers.add("static"),c.push(m)}else if(this.check(i.IDENT)){let m=this.eat(i.IDENT).value,x=!1;this.check(i.QUESTION)&&(this.pos++,x=!0),this.eat(i.COLON);let S=this.parseTypeAnn();this.skipNewlines(),h.push({name:m,typeAnn:S,optional:x,modifiers:l})}else this.skip()}return this.maybe(i.DEDENT),{type:"ClassDecl",name:e,typeParams:a,superClass:s,interfaces:r,fields:h,methods:c,loc:t}}parseInterfaceDecl(){let t=this.eat(i.INTERFACE),e=this.eat(i.IDENT).value,s=[];if(this.check(i.LT)){for(this.pos++,s.push(this.eat(i.IDENT).value);this.maybe(i.COMMA);)s.push(this.eat(i.IDENT).value);this.eat(i.GT)}let r=[];if(this.maybe(i.EXTENDS))for(r.push(this.eat(i.IDENT).value);this.maybe(i.COMMA);)r.push(this.eat(i.IDENT).value);this.eat(i.COLON),this.check(i.NEWLINE)&&(this.pos++,this.eat(i.INDENT));let a=[];for(;!this.check(i.DEDENT)&&!this.check(i.EOF)&&(this.skipNewlines(),!(this.check(i.DEDENT)||this.check(i.EOF)));){let h=this.parseAccessModifiers();if(this.check(i.ASYNC)){this.pos++,this.eat(i.FN);let c=this.eat(i.IDENT).value,l=this.parseParamList(),p=null;this.maybe(i.ARROW)&&(p=this.parseTypeAnn()),this.skipNewlines(),a.push({kind:"method",name:c,params:l,retType:p,modifiers:h,isAsync:!0})}else if(this.check(i.FN)){this.eat(i.FN);let c=this.eat(i.IDENT).value,l=this.parseParamList(),p=null;this.maybe(i.ARROW)&&(p=this.parseTypeAnn()),this.skipNewlines(),a.push({kind:"method",name:c,params:l,retType:p,modifiers:h,isAsync:!1})}else if(this.check(i.IDENT)){let c=this.eat(i.IDENT).value,l=!1;this.check(i.QUESTION)&&(this.pos++,l=!0),this.eat(i.COLON);let p=this.parseTypeAnn();this.skipNewlines(),a.push({kind:"field",name:c,typeAnn:p,optional:l,modifiers:h})}else this.skip()}return this.maybe(i.DEDENT),{type:"InterfaceDecl",name:e,typeParams:s,superInterfaces:r,members:a,loc:t}}parseEnumDecl(){let t=this.eat(i.ENUM),e=this.eat(i.IDENT).value;this.eat(i.COLON),this.check(i.NEWLINE)&&(this.pos++,this.eat(i.INDENT));let s=[],r=0;for(;!this.check(i.DEDENT)&&!this.check(i.EOF)&&(this.skipNewlines(),!(this.check(i.DEDENT)||this.check(i.EOF)));){let a=this.eat(i.IDENT).value,h=null;this.maybe(i.EQ)?(h=this.parseExpr(),h.type==="NumberLit"&&(r=h.value)):h={type:"NumberLit",value:r},r++,this.skipNewlines(),s.push({name:a,value:h})}return this.maybe(i.DEDENT),{type:"EnumDecl",name:e,members:s,loc:t}}parseIf(){let t=this.eat(i.IF),e=this.parseExpr(),s=this.parseBlock(),r=[],a=null;for(this.skipNewlines();this.check(i.ELSE);)if(this.pos++,this.check(i.IF)){this.pos++;let h=this.parseExpr(),c=this.parseBlock();r.push({cond:h,body:c}),this.skipNewlines()}else{a=this.parseBlock();break}return{type:"IfStmt",cond:e,then:s,elseifs:r,else_:a,loc:t}}parseFor(){let t=this.eat(i.FOR),e=!1;this.check(i.AWAIT)&&(this.pos++,e=!0);let s,r=null;if(this.check(i.LBRACKET)){this.pos++;let c=[];for(;!this.check(i.RBRACKET)&&!this.check(i.EOF);){if(this.check(i.DOTDOTDOT)){this.pos++,c.push({rest:!0,name:this.eat(i.IDENT).value});break}if(c.push({name:this.eat(i.IDENT).value}),!this.maybe(i.COMMA))break}this.eat(i.RBRACKET),s="__item__",r={type:"array",names:c}}else s=this.eat(i.IDENT).value;this.check(i.IN)?this.pos++:this.check(i.IDENT)&&this.peek().value==="of"?(this.pos++,e=e):this.eat(i.IN);let a=this.parseExpr(),h=this.parseBlock();return{type:"ForInStmt",var:s,varPattern:r,iter:a,body:h,isAwait:e,loc:t}}parseWhile(){let t=this.eat(i.WHILE),e=this.parseExpr(),s=this.parseBlock();return{type:"WhileStmt",cond:e,body:s,loc:t}}parseDoWhile(){let t=this.eat(i.DO),e=this.parseBlock();this.skipNewlines(),this.eat(i.WHILE);let s=this.parseExpr();return this.skipNewlines(),{type:"DoWhileStmt",body:e,cond:s,loc:t}}parseMatch(){let t=this.eat(i.MATCH),e=this.parseExpr();this.eat(i.COLON),this.check(i.NEWLINE)&&this.pos++,this.eat(i.INDENT);let s=[];for(;!this.check(i.DEDENT)&&!this.check(i.EOF)&&(this.skipNewlines(),!(this.check(i.DEDENT)||this.check(i.EOF)));){this.eat(i.WHEN);let r=this.parsePattern(),a=null;if(this.check(i.IF)&&(this.pos++,a=this.parseExpr()),this.check(i.ARROW)){this.pos++;let h=this.parseExpr();this.skipNewlines(),s.push({pattern:r,guard:a,body:[{type:"ExprStmt",expr:h}],inline:!0})}else if(this.check(i.COLON)){let h=this.peek(1).type!==i.NEWLINE,c=this.parseBlock();s.push({pattern:r,guard:a,body:c,inline:h&&c.length===1&&c[0].type==="ExprStmt"})}}return this.maybe(i.DEDENT),{type:"MatchStmt",subject:e,arms:s,loc:t}}parsePattern(){if(this.check(i.WILDCARD))return this.skip(),{type:"WildcardPat"};if(this.check(i.IDENT)&&this.peek(1).type===i.LPAREN){let e=this.eat(i.IDENT).value;this.eat(i.LPAREN);let s=[];for(;!this.check(i.RPAREN)&&!this.check(i.EOF)&&(this.check(i.WILDCARD)?(s.push("_"),this.pos++):s.push(this.eat(i.IDENT).value),!!this.maybe(i.COMMA)););return this.eat(i.RPAREN),{type:"VariantPat",variant:e,bindings:s}}let t=this.parsePrimary();for(;this.check(i.DOT);){this.pos++;let e=this.skip().value;t={type:"MemberExpr",obj:t,prop:e}}if(this.check(i.DOTDOT)){this.pos++;let e=this.parsePrimary();return{type:"RangePat",start:t,end:e}}return{type:"LiteralPat",value:t}}parseReturn(){let t=this.eat(i.RETURN),e=null;return this.at(i.NEWLINE,i.EOF,i.DEDENT)||(e=this.parseExpr()),this.skipNewlines(),{type:"ReturnStmt",value:e,loc:t}}parseTryCatch(){let t=this.eat(i.TRY),e=this.parseBlock(),s=null,r=null,a=null;return this.skipNewlines(),this.check(i.CATCH)&&(this.pos++,this.check(i.LPAREN)&&(this.pos++,s=this.eat(i.IDENT).value,this.maybe(i.COLON)&&this.parseTypeAnn(),this.eat(i.RPAREN)),r=this.parseBlock(),this.skipNewlines()),this.check(i.FINALLY)&&(this.pos++,a=this.parseBlock()),{type:"TryCatchStmt",tryBody:e,catchParam:s,catchBody:r,finallyBody:a,loc:t}}parseThrow(){let t=this.eat(i.THROW),e=this.parseExpr();return this.skipNewlines(),{type:"ThrowStmt",value:e,loc:t}}parseImport(){if(this.eat(i.IMPORT),this.check(i.STAR)){this.pos++,this.eat(i.AS);let s=this.eat(i.IDENT).value;this.eat(i.FROM);let r=this.eat(i.STRING).value;return this.skipNewlines(),{type:"ImportDecl",names:[],defaultName:null,namespaceName:s,source:r}}if(this.check(i.IDENT)){let s=this.eat(i.IDENT).value;this.eat(i.FROM);let r=this.eat(i.STRING).value;return this.skipNewlines(),{type:"ImportDecl",names:[],defaultName:s,source:r}}let t=[];if(this.maybe(i.LBRACE)){for(;!this.check(i.RBRACE)&&!this.check(i.EOF);){let s=this.eat(i.IDENT).value,r=s;if(this.check(i.AS)&&(this.pos++,r=this.eat(i.IDENT).value),t.push({name:s,alias:r}),!this.maybe(i.COMMA))break}this.eat(i.RBRACE)}this.eat(i.FROM);let e=this.eat(i.STRING).value;return this.skipNewlines(),{type:"ImportDecl",names:t,defaultName:null,source:e}}parseExport(){if(this.eat(i.EXPORT),this.check(i.DEFAULT)&&(this.peek(1).type===i.FN||this.peek(1).type===i.ASYNC))return this.pos++,{type:"ExportDecl",isDefault:!0,decl:this.check(i.ASYNC)?(this.pos++,this.parseFnDecl(!0)):this.parseFnDecl()};if(this.check(i.DEFAULT)){this.pos++;let e=this.parseExpr();return this.skipNewlines(),{type:"ExportDecl",isDefault:!0,decl:e}}return this.check(i.ASYNC)?(this.pos++,this.check(i.FN)||this.err("Expected fn after async"),{type:"ExportDecl",isDefault:!1,decl:this.parseFnDecl(!0)}):{type:"ExportDecl",isDefault:!1,decl:this.parseOneStmt()}}parseExprStmt(){let t=this.parseExpr();return this.skipNewlines(),{type:"ExprStmt",expr:t}}parseExpr(){return this.parsePipe()}parsePipe(){let t=this.parseAssign();for(;;)if(this.check(i.PIPE)){this.pos++;let e=this.parseAssign();t={type:"PipeExpr",left:t,right:e}}else if(this.check(i.NEWLINE)){let e=1;for(;this.peek(e).type===i.NEWLINE;)e++;if(this.peek(e).type===i.PIPE){for(;this.check(i.NEWLINE);)this.pos++;this.pos++;let s=this.parseAssign();t={type:"PipeExpr",left:t,right:s}}else break}else break;return t}parseAssign(){let t=this.parseTernary(),s={[i.EQ]:"=",[i.PLUSEQ]:"+=",[i.MINUSEQ]:"-=",[i.STAREQ]:"*=",[i.SLASHEQ]:"/=",[i.PERCENTEQ]:"%="}[this.peek().type];return s?(this.pos++,{type:"AssignExpr",target:t,op:s,value:this.parseAssign()}):t}parseTernary(){let t=this.parseNullish();if(this.maybe(i.QUESTION)){let e=this.parseNullish();this.eat(i.COLON);let s=this.parseTernary();return{type:"TernaryExpr",cond:t,then:e,else_:s}}return t}parseNullish(){let t=this.parseOr();for(;this.check(i.NULLISH);){this.pos++;let e=this.parseOr();t={type:"BinaryExpr",op:"??",left:t,right:e}}return t}parseOr(){let t=this.parseAnd();for(;this.check(i.OR)||this.check(i.OROR);){this.pos++;let e=this.parseAnd();t={type:"BinaryExpr",op:"||",left:t,right:e}}return t}parseAnd(){let t=this.parseBitOr();for(;this.check(i.AND)||this.check(i.ANDAND);){this.pos++;let e=this.parseBitOr();t={type:"BinaryExpr",op:"&&",left:t,right:e}}return t}parseBitOr(){let t=this.parseBitXor();for(;this.check(i.PIPEB);){this.pos++;let e=this.parseBitXor();t={type:"BinaryExpr",op:"|",left:t,right:e}}return t}parseBitXor(){let t=this.parseBitAnd();for(;this.check(i.CARET);){this.pos++;let e=this.parseBitAnd();t={type:"BinaryExpr",op:"^",left:t,right:e}}return t}parseBitAnd(){let t=this.parseEq();for(;this.check(i.AMPERSAND);){this.pos++;let e=this.parseEq();t={type:"BinaryExpr",op:"&",left:t,right:e}}return t}parseEq(){let t=this.parseRel();for(;this.at(i.EQEQ,i.NEQ,i.EQEQEQ,i.NEQEQ);){let e=this.skip().value,s=this.parseRel();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parseRel(){let t=this.parseShift();for(;this.at(i.LT,i.LTE,i.GT,i.GTE)||this.check(i.IN);){let e=this.skip().value,s=this.parseShift();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parseShift(){let t=this.parseRange();for(;this.at(i.LSHIFT,i.RSHIFT);){let e=this.skip().value,s=this.parseRange();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parseRange(){let t=this.parseAdd();if(this.check(i.DOTDOT)){this.pos++;let e=this.parseAdd();return{type:"RangeExpr",start:t,end:e}}return t}parseAdd(){let t=this.parseMul();for(;this.at(i.PLUS,i.MINUS);){let e=this.skip().value,s=this.parseMul();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parseMul(){let t=this.parsePow();for(;this.at(i.STAR,i.SLASH,i.PERCENT);){let e=this.skip().value,s=this.parsePow();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parsePow(){let t=this.parseUnary();return this.check(i.STARSTAR)?(this.pos++,{type:"BinaryExpr",op:"**",left:t,right:this.parsePow()}):t}parseUnary(){return this.check(i.MINUS)?(this.pos++,{type:"UnaryExpr",op:"-",operand:this.parseUnary()}):this.check(i.NOT)?(this.pos++,{type:"UnaryExpr",op:"!",operand:this.parseUnary()}):this.check(i.BANG)?(this.pos++,{type:"UnaryExpr",op:"!",operand:this.parseUnary()}):this.check(i.TILDE)?(this.pos++,{type:"UnaryExpr",op:"~",operand:this.parseUnary()}):this.check(i.PLUSPLUS)?(this.pos++,{type:"UpdateExpr",op:"++",prefix:!0,operand:this.parseUnary()}):this.check(i.MINUSMINUS)?(this.pos++,{type:"UpdateExpr",op:"--",prefix:!0,operand:this.parseUnary()}):this.check(i.AWAIT)?(this.pos++,{type:"AwaitExpr",operand:this.parseUnary()}):this.check(i.TYPEOF)?(this.pos++,{type:"TypeofExpr",operand:this.parseUnary()}):this.parseLambdaOrPostfix()}parseLambdaOrPostfix(){let t=this.pos;if(this.check(i.IDENT)||this.check(i.WILDCARD)){let e=this.skip().value??"_";if(this.check(i.ARROW)){if(this.pos++,this.check(i.NEWLINE)){let r=this.parseIndentedBlock();return{type:"LambdaExpr",params:[{name:e}],body:r,block:!0}}let s=this.parseExpr();return{type:"LambdaExpr",params:[{name:e}],body:s}}this.pos=t}return this.parsePostfix()}parsePostfix(){let t=this.parsePrimary();t:for(;;)if(this.check(i.PLUSPLUS))this.pos++,t={type:"UpdateExpr",op:"++",prefix:!1,operand:t};else if(this.check(i.MINUSMINUS))this.pos++,t={type:"UpdateExpr",op:"--",prefix:!1,operand:t};else if(this.check(i.DOT)){this.pos++;let e=this.peek();e.type!==i.IDENT&&!(e.type in i)&&this.err(`Expected property name, got '${e.type}'`);let s=this.skip().value;t={type:"MemberExpr",obj:t,prop:s}}else if(this.check(i.QUESTIONDOT))if(this.pos++,this.check(i.LPAREN)){let e=this.parseArgList();t={type:"OptCallExpr",callee:t,args:e}}else if(this.check(i.LBRACKET)){this.pos++;let e=this.parseExpr();this.eat(i.RBRACKET),t={type:"OptIndexExpr",obj:t,idx:e}}else{let e=this.peek();e.type!==i.IDENT&&!(e.type in i)&&this.err(`Expected property name, got '${e.type}'`);let s=this.skip().value;t={type:"OptMemberExpr",obj:t,prop:s}}else if(this.check(i.INSTANCEOF)){this.pos++;let e=this.eat(i.IDENT).value;t={type:"BinaryExpr",op:"instanceof",left:t,right:{type:"Identifier",name:e}}}else if(this.check(i.AS))if(this.pos++,this.check(i.CONST))this.pos++,t={type:"AsConstExpr",expr:t};else{let e=this.parseTypeAnn();t={type:"CastExpr",expr:t,castType:e}}else if(this.check(i.SATISFIES)){this.pos++;let e=this.parseTypeAnn();t={type:"SatisfiesExpr",expr:t,satType:e}}else if(this.check(i.IS)){this.pos++;let e=this.parseTypeAnn();t={type:"IsExpr",expr:t,isType:e}}else if(this.check(i.BANG))this.pos++,t={type:"NonNullExpr",expr:t};else if(this.check(i.LBRACKET)){this.pos++;let e=this.parseExpr();this.eat(i.RBRACKET),t={type:"IndexExpr",obj:t,idx:e}}else if(this.check(i.LPAREN)){let e=this.parseArgList();if(this.check(i.ARROW)){this.pos++;let s=this.parseExpr();return{type:"LambdaExpr",params:e.map(a=>({name:a.type==="Identifier"?a.name:"_"})),body:s}}t={type:"CallExpr",callee:t,args:e}}else break t;return t}parseArgList(){this.eat(i.LPAREN);let t=[];for(;!this.check(i.RPAREN)&&!this.check(i.EOF)&&(this.check(i.DOTDOTDOT)?(this.pos++,t.push({type:"SpreadExpr",expr:this.parseExpr()})):t.push(this.parseExpr()),!!this.maybe(i.COMMA)););return this.eat(i.RPAREN),t}parsePrimary(){let t=this.peek();switch(t.type){case i.NUMBER:return this.pos++,{type:"NumberLit",value:t.value,loc:t};case i.BOOL:return this.pos++,{type:"BoolLit",value:t.value,loc:t};case i.NULL:return this.pos++,{type:"NullLit",loc:t};case i.SELF:return this.pos++,{type:"SelfExpr",loc:t};case i.WILDCARD:return this.pos++,{type:"Identifier",name:"_",loc:t};case i.IDENT:return this.pos++,{type:"Identifier",name:t.value,loc:t};case i.STRING:return this.pos++,t.value&&t.value.template?{type:"TemplateLit",parts:t.value.parts,loc:t}:{type:"StringLit",value:t.value,loc:t};case i.REGEX:return this.pos++,{type:"RegexLit",value:t.value,loc:t};case i.NEW:{this.pos++;let e=this.eat(i.IDENT).value,s=this.parseArgList();return{type:"NewExpr",callee:e,args:s}}case i.FN:{this.pos++;let e=this.parseParamList();if(this.check(i.ARROW)){if(this.pos++,this._isTypeAnnBeforeColon()){let r=this.parseTypeAnn(),a=this.parseBlock();return{type:"FnDecl",name:null,params:e,retType:r,body:a,inline:!1,async:!1,loc:t}}let s=this.parseExpr();return{type:"FnDecl",name:null,params:e,retType:null,body:s,inline:!0,async:!1,loc:t}}if(this.check(i.COLON)){let s=this.parseBlock();return{type:"FnDecl",name:null,params:e,retType:null,body:s,inline:!1,async:!1,loc:t}}this.err("Expected -> or : after anonymous fn")}case i.MATCH:return this.parseMatch();case i.LPAREN:{if(this.pos++,this.check(i.RPAREN)){if(this.pos++,this.check(i.ARROW)){if(this.pos++,this.check(i.NEWLINE)){let a=this.parseIndentedBlock();return{type:"LambdaExpr",params:[],body:a,block:!0}}let r=this.parseExpr();return{type:"LambdaExpr",params:[],body:r}}return{type:"NullLit"}}let e=this.parseExpr();if(this.check(i.RPAREN)){if(this.pos++,this.check(i.ARROW)){if(this.pos++,this.check(i.NEWLINE)){let h=this.parseIndentedBlock();return{type:"LambdaExpr",params:[{name:e.type==="Identifier"?e.name:"_"}],body:h,block:!0}}let r=this.parseExpr();return{type:"LambdaExpr",params:[{name:e.type==="Identifier"?e.name:"_"}],body:r}}return e}let s=[e];for(;this.maybe(i.COMMA);)s.push(this.parseExpr());if(this.eat(i.RPAREN),this.check(i.ARROW)){this.pos++;let r=s.map(h=>({name:h.type==="Identifier"?h.name:"_"}));if(this.check(i.NEWLINE)){let h=this.parseIndentedBlock();return{type:"LambdaExpr",params:r,body:h,block:!0}}let a=this.parseExpr();return{type:"LambdaExpr",params:r,body:a}}return s.length>1&&this.err(`Unexpected comma in expression \u2014 did you mean a lambda? Write (${s.map((r,a)=>"p"+a).join(", ")}) -> expr`),s[0]}case i.LBRACKET:{this.pos++;let e=[];for(;!this.check(i.RBRACKET)&&!this.check(i.EOF)&&(this.check(i.DOTDOTDOT)?(this.pos++,e.push({type:"SpreadExpr",expr:this.parseExpr()})):e.push(this.parseExpr()),!!this.maybe(i.COMMA)););return this.eat(i.RBRACKET),{type:"ArrayExpr",items:e}}case i.LBRACE:{this.pos++;let e=[];for(;!this.check(i.RBRACE)&&!this.check(i.EOF);){if(this.check(i.DOTDOTDOT)){if(this.pos++,e.push({spread:!0,value:this.parseExpr()}),!this.maybe(i.COMMA))break;continue}if(this.check(i.LBRACKET)){this.pos++;let r=this.parseExpr();this.eat(i.RBRACKET),this.eat(i.COLON);let a=this.parseExpr();if(e.push({computed:!0,keyExpr:r,value:a}),!this.maybe(i.COMMA))break;continue}let s=this.check(i.STRING)?this.eat(i.STRING).value:this.check(i.IDENT)?this.eat(i.IDENT).value:this.skip().value;if(!this.check(i.COLON))e.push({key:s,value:{type:"Identifier",name:s}});else{this.eat(i.COLON);let r=this.parseExpr();e.push({key:s,value:r})}if(!this.maybe(i.COMMA))break}return this.eat(i.RBRACE),{type:"ObjectExpr",pairs:e}}default:this.err(`Unexpected token: ${t.type} (${JSON.stringify(t.value)})`)}}};_t.exports={Parser:ut,ParseError:U}});var yt=F((hs,Ct)=>{"use strict";function de(n){let t=n.lastIndexOf(":");if(t<1)return null;let e=n.slice(t+1).trim();return e.length>0&&/[.<>^,dbeEfFgGoOxXs%bcn]/.test(e)&&/^([.<>^0\-+ #,]*[0-9]*\.?[0-9]*[dbeEfFgGoOxXs%bcn]?[,]?)$/.test(e)?{expr:n.slice(0,t).trim(),fmt:e}:null}var ge=`
|
|
23
|
+
function _fmt(v, s) {
|
|
24
|
+
if (s === ',') return (+v).toLocaleString();
|
|
25
|
+
if (s === '%') return ((+v)*100).toFixed(0)+'%';
|
|
26
|
+
var m = s.match(/^([0-9,]*)?\\.([0-9]+)([fdgGeEb%x])$/);
|
|
27
|
+
if (m) {
|
|
28
|
+
var d=+m[2], t=m[3], comma=s[0]===',';
|
|
29
|
+
if (t==='f'||t==='d') return comma ? (+v).toLocaleString(void 0,{minimumFractionDigits:d,maximumFractionDigits:d}) : (+v).toFixed(d);
|
|
30
|
+
if (t==='e'||t==='E') return (+v).toExponential(d);
|
|
31
|
+
if (t==='%') return ((+v)*100).toFixed(d)+'%';
|
|
32
|
+
if (t==='b') return Math.round(+v).toString(2);
|
|
33
|
+
if (t==='x') return Math.round(+v).toString(16);
|
|
34
|
+
}
|
|
35
|
+
var m2 = s.match(/^([0-9]*)d$/); if (m2) return Math.round(+v).toString();
|
|
36
|
+
return String(v);
|
|
37
|
+
}`,Y=class extends Error{constructor(t,e){super(`${t}${e?` [${e.type}]`:""}`),this.name="CodeGenError"}};function Te(n){let t={};for(let e of n.body){let s=e.type==="ExportDecl"?e.decl:e;s.type==="ClassDecl"&&(t[s.name]={fields:s.fields,superClass:s.superClass})}return t}function ft(n,t,e=new Set){return!n||!t[n]||e.has(n)?[]:(e.add(n),[...ft(t[n].superClass,t,e),...t[n].fields])}var mt=class{constructor(t={}){this.ind=t.indent||" ",this.level=0,this.lines=[],this.clsReg={},this.smBuilder=t.smBuilder||null,this._needsFmt=!1,this._loopDepth=0}i(){return this.ind.repeat(this.level)}emit(t){this.lines.push(this.i()+t)}emitRaw(t){this.lines.push(t)}blank(){this.lines.push("")}in(){this.level++}out(){this.level=Math.max(0,this.level-1)}_map(t){if(!this.smBuilder||!t)return;let e=this.lines.length,s=this.ind.repeat(this.level).length,r=(t.line||1)-1,a=(t.col||1)-1;this.smBuilder.addMapping(e,s,r,a)}generate(t){this.clsReg=Te(t),this.lines=[],this.level=0,this._needsFmt=!1,this.emit("// Generated by Flux Transpiler v3.1.0"),this.emit('"use strict";'),this.blank();for(let e of t.body)this.genStmt(e);return this._needsFmt&&this.lines.splice(2,0,ge),{code:this.lines.join(`
|
|
38
|
+
`),smBuilder:this.smBuilder}}genStmt(t){switch(this._map(t.loc),t.type){case"VarDecl":return this.genVar(t);case"DestructureDecl":return this.genDestructure(t);case"FnDecl":return this.genFn(t);case"ClassDecl":return this.genClass(t);case"IfStmt":return this.genIf(t);case"ForInStmt":return this.genFor(t);case"WhileStmt":return this.genWhile(t);case"MatchStmt":return this.genMatch(t);case"ReturnStmt":return this.genReturn(t);case"TryCatchStmt":return this.genTryCatch(t);case"ThrowStmt":return this.genThrow(t);case"DoWhileStmt":return this.genDoWhile(t);case"BreakStmt":return this.emit(t.label?`break ${t.label};`:"break;");case"ContinueStmt":return this.emit(t.label?`continue ${t.label};`:"continue;");case"LabeledStmt":return this.genLabeled(t);case"ImportDecl":return this.genImport(t);case"ExportDecl":return this.genExport(t);case"TypeDecl":return this.genTypeDecl(t);case"InterfaceDecl":return this.genInterfaceDecl(t);case"EnumDecl":return this.genEnumDecl(t);case"ExprStmt":return this.emit(this.genExpr(t.expr)+";");default:throw new Y(`Unknown statement: ${t.type}`,t)}}genVar(t){let e=t.kind==="val"?"const":"let",s=t.init?` = ${this.genExpr(t.init)}`:"";this.emit(`${e} ${t.name}${s};`)}genDestructure(t){let e=t.kind==="val"?"const":"let",s=this.genExpr(t.init);if(t.patternType==="object"){let r=t.pattern.map(a=>{if(a.rest)return`...${a.key}`;let h=a.alias!==a.key?`${a.key}: ${a.alias}`:a.key;return a.defaultVal&&(h+=` = ${this.genExpr(a.defaultVal)}`),h}).join(", ");this.emit(`${e} { ${r} } = ${s};`)}else{let r=t.pattern.map(a=>{if(!a)return"";if(a.rest)return`...${a.name}`;let h=a.name;return a.defaultVal&&(h+=` = ${this.genExpr(a.defaultVal)}`),h}).join(", ");this.emit(`${e} [${r}] = ${s};`)}}genFn(t,e=""){let s=t.async?"async ":"",r=t.name||"",a=t.params.map(h=>h.rest?`...${h.name}`:h.defaultVal?`${h.name} = ${this.genExpr(h.defaultVal)}`:h.name).join(", ");if(t.inline)this.emit(`${e}${s}function ${r}(${a}) { return ${this.genExpr(t.body)}; }`);else{this.emit(`${e}${s}function ${r}(${a}) {`),this.in();for(let h of t.body)this.genStmt(h);this.out(),this.emit("}")}}genClass(t){let e=t.superClass?` extends ${t.superClass}`:"";this.emit(`class ${t.name}${e} {`),this.in();let s=ft(t.name,this.clsReg);if(s.length>0){let r=s.map(a=>a.name).join(", ");if(this.emit(`constructor(${r}) {`),this.in(),t.superClass&&this.clsReg[t.superClass]){let a=ft(t.superClass,this.clsReg);a.length>0&&this.emit(`super(${a.map(h=>h.name).join(", ")});`)}for(let a of t.fields)this.emit(`this.${a.name} = ${a.name};`);this.out(),this.emit("}"),this.blank()}for(let r of t.methods){let a=r.async?"async ":"",h=r.modifiers&&r.modifiers.has("static")?"static ":"",c=r.getset?`${r.getset} `:"",l=r.params.map(p=>p.rest?`...${p.name}`:p.defaultVal?`${p.name} = ${this.genExpr(p.defaultVal)}`:p.name).join(", ");if(r.inline)this.emit(`${h}${a}${c}${r.name}(${l}) { return ${this.genExpr(r.body)}; }`);else{this.emit(`${h}${a}${c}${r.name}(${l}) {`),this.in();for(let p of r.body)this.genStmt(p);this.out(),this.emit("}")}this.blank()}this.out(),this.emit("}"),this.blank()}genIf(t){this.emit(`if (${this.genExpr(t.cond)}) {`),this.in(),t.then.forEach(e=>this.genStmt(e)),this.out(),this.emit("}");for(let e of t.elseifs)this.emitRaw(this.i()+`else if (${this.genExpr(e.cond)}) {`),this.in(),e.body.forEach(s=>this.genStmt(s)),this.out(),this.emit("}");t.else_&&(this.emitRaw(this.i()+"else {"),this.in(),t.else_.forEach(e=>this.genStmt(e)),this.out(),this.emit("}"))}genFor(t){let e=t.iter,s=t.label?`${t.label}: `:"";if(e.type==="RangeExpr"){let r=this.genExpr(e.start),a=this.genExpr(e.end);this.emit(`${s}for (let ${t.var} = ${r}; ${t.var} < ${a}; ${t.var}++) {`)}else t.isAwait?this.emit(`${s}for await (const ${t.var} of ${this.genExpr(e)}) {`):this.emit(`${s}for (const ${t.var} of ${this.genExpr(e)}) {`);if(this._loopDepth++,this.in(),t.varPattern){let r=t.varPattern;if(r.type==="array"){let a=r.names.map(h=>h.rest?`...${h.name}`:h.name).join(", ");this.emit(`const [${a}] = ${t.var};`)}}t.body.forEach(r=>this.genStmt(r)),this.out(),this._loopDepth--,this.emit("}")}genLabeled(t){t.body.label=t.label,this.genStmt(t.body)}genWhile(t){let e=t.label?`${t.label}: `:"";this.emit(`${e}while (${this.genExpr(t.cond)}) {`),this._loopDepth++,this.in(),t.body.forEach(s=>this.genStmt(s)),this.out(),this._loopDepth--,this.emit("}")}genMatch(t){let e=this.genExpr(t.subject),s=t.arms,r=!1;s.forEach((a,h)=>{let c=a.pattern,l=null,p=[];if(c.type==="WildcardPat")l=null;else if(c.type==="RangePat"){let u=this.genExpr(c.start),m=this.genExpr(c.end);l=`${e} >= ${u} && ${e} <= ${m}`}else if(c.type==="VariantPat")l=`${e}?.__type === "${c.variant}"`,p=c.bindings.map((u,m)=>`const ${u} = ${e}.__args[${m}];`);else{let u=this.genExpr(c.value);c.value.type==="Identifier"&&/^[A-Z]/.test(c.value.name)?l=`(${e} === ${u} || ${e}?.__type === "${c.value.name}")`:l=`${e} === ${u}`}if(a.guard){let u=this.genExpr(a.guard);if(p.length>0){let m=`(function(){ ${p.map(x=>x.replace("const ","var ")).join(" ")} return (${u}); }())`;l=l?`(${l}) && ${m}`:m}else l=l?`(${l}) && (${u})`:u}!r&&l?(this.emit(`if (${l}) {`),r=!0):!r&&!l?(this.emit("if (true) {"),r=!0):r&&l?this.emitRaw(this.i()+`else if (${l}) {`):this.emitRaw(this.i()+"else {"),this.in();for(let u of p)this.emit(u);if(a.inline){let u=this.genExpr(a.body[0].expr);this._loopDepth>0?this.emit(`${u};`):this.emit(`return ${u};`)}else a.body.forEach(u=>this.genStmt(u));this.out(),this.emit("}")})}genInterfaceDecl(t){this.blank(),this.emit(`// interface ${t.name}`),this.blank()}genEnumDecl(t){this.blank();let e=t.members.map(s=>{let r=this.genExpr(s.value);return`${s.name}: ${r}`}).join(", ");this.emit(`const ${t.name} = Object.freeze({ ${e} });`),this.blank()}genTypeDecl(t){this.blank(),this.emit(`// ADT type: ${t.name}`);for(let e of t.variants)if(e.fields.length===0)this.emit(`const ${e.name} = Object.freeze({ __type: "${e.name}", __args: [] });`);else{let s=e.fields.join(", "),r=`[${e.fields.join(", ")}]`,a=e.fields.map(h=>`${h}: ${h}`).join(", ");this.emit(`function ${e.name}(${s}) { return Object.freeze({ __type: "${e.name}", __args: ${r}, ${a} }); }`)}this.blank()}genReturn(t){t.value?this.emit(`return ${this.genExpr(t.value)};`):this.emit("return;")}genTryCatch(t){if(this.emit("try {"),this.in(),t.tryBody.forEach(e=>this.genStmt(e)),this.out(),this.emit("}"),t.catchBody){let e=t.catchParam?`(${t.catchParam})`:"(_err)";this.emitRaw(this.i()+`catch ${e} {`),this.in(),t.catchBody.forEach(s=>this.genStmt(s)),this.out(),this.emit("}")}t.finallyBody&&(this.emitRaw(this.i()+"finally {"),this.in(),t.finallyBody.forEach(e=>this.genStmt(e)),this.out(),this.emit("}"))}genThrow(t){this.emit(`throw ${this.genExpr(t.value)};`)}genDoWhile(t){this.emit("do {"),this.in();for(let e of t.body)this.genStmt(e);this.out(),this.emit(`} while (${this.genExpr(t.cond)});`)}genImport(t){let e=typeof t.source=="string"?t.source:String(t.source);if(t.namespaceName)this.emit(`const ${t.namespaceName} = require("${e}");`);else if(t.defaultName)this.emit(`const ${t.defaultName} = require("${e}");`);else if(t.names.length){let s=t.names.map(r=>typeof r=="string"?r:r.name!==r.alias?`${r.name}: ${r.alias}`:r.name).join(", ");this.emit(`const { ${s} } = require("${e}");`)}}genExport(t){if(t.isDefault){this.emit(`module.exports = ${this.genExpr(t.decl)};`);return}let e=t.decl;switch(e.type){case"FnDecl":{let s=e.async?"async ":"",r=e.params.map(a=>a.rest?`...${a.name}`:a.defaultVal?`${a.name} = ${this.genExpr(a.defaultVal)}`:a.name).join(", ");e.inline?this.emit(`${s}function ${e.name}(${r}) { return ${this.genExpr(e.body)}; }`):(this.emit(`${s}function ${e.name}(${r}) {`),this.in(),e.body.forEach(a=>this.genStmt(a)),this.out(),this.emit("}")),this.emit(`module.exports.${e.name} = ${e.name};`);break}case"ClassDecl":this.genClass(e),this.emit(`module.exports.${e.name} = ${e.name};`);break;case"TypeDecl":this.genTypeDecl(e);for(let s of e.variants)this.emit(`module.exports.${s.name} = ${s.name};`);break;case"InterfaceDecl":this.genInterfaceDecl(e);break;case"EnumDecl":this.genEnumDecl(e),this.emit(`module.exports.${e.name} = ${e.name};`);break;case"VarDecl":{let s=e.kind==="val"?"const":"let";this.emit(`${s} ${e.name} = ${this.genExpr(e.init)};`),this.emit(`module.exports.${e.name} = ${e.name};`);break}default:this.genStmt(e)}}genExpr(t){if(!t)return"undefined";switch(t.type){case"NumberLit":return String(t.value);case"BoolLit":return String(t.value);case"NullLit":return"null";case"SelfExpr":return"this";case"Identifier":return t.name==="print"?"console.log":t.name;case"StringLit":return JSON.stringify(t.value);case"RegexLit":return`/${t.value.pattern}/${t.value.flags}`;case"TemplateLit":return this.genTemplate(t.parts);case"BinaryExpr":return`(${this.genExpr(t.left)} ${t.op} ${this.genExpr(t.right)})`;case"UnaryExpr":return`${t.op}${this.genExpr(t.operand)}`;case"UpdateExpr":return t.prefix?`${t.op}${this.genExpr(t.operand)}`:`${this.genExpr(t.operand)}${t.op}`;case"TernaryExpr":return`(${this.genExpr(t.cond)} ? ${this.genExpr(t.then)} : ${this.genExpr(t.else_)})`;case"AssignExpr":return`${this.genExpr(t.target)} ${t.op} ${this.genExpr(t.value)}`;case"AwaitExpr":return`await ${this.genExpr(t.operand)}`;case"TypeofExpr":return`typeof ${this.genExpr(t.operand)}`;case"SpreadExpr":return`...${this.genExpr(t.expr)}`;case"CallExpr":{let e=this.genExpr(t.callee),s=t.args.map(r=>this.genExpr(r)).join(", ");return`${e}(${s})`}case"MemberExpr":{let e=this.genExpr(t.obj);return`${t.obj.type==="NumberLit"?`(${e})`:e}.${t.prop}`}case"OptMemberExpr":return`${this.genExpr(t.obj)}?.${t.prop}`;case"OptIndexExpr":return`${this.genExpr(t.obj)}?.[${this.genExpr(t.idx)}]`;case"OptCallExpr":{let e=t.args.map(s=>this.genExpr(s)).join(", ");return`${this.genExpr(t.callee)}?.(${e})`}case"IndexExpr":return`${this.genExpr(t.obj)}[${this.genExpr(t.idx)}]`;case"NewExpr":{let e=t.args.map(s=>this.genExpr(s)).join(", ");return`new ${t.callee}(${e})`}case"LambdaExpr":{let e=t.params.map(s=>s.rest?`...${s.name}`:s.name).join(", ");if(t.block){let s=this.lines.length,r=this.level;this.emit(`(${e}) => {`),this.in();for(let h of t.body)this.genStmt(h);this.out(),this.emit("}");let a=this.lines.splice(s).map(h=>h.trimStart()).join(" ");return this.level=r,a}return`(${e}) => ${this.genExpr(t.body)}`}case"FnDecl":{let e=t.async?"async ":"",s=t.params.map(r=>r.rest?`...${r.name}`:r.defaultVal?`${r.name} = ${this.genExpr(r.defaultVal)}`:r.name).join(", ");if(t.inline)return`${e}function(${s}) { return ${this.genExpr(t.body)}; }`;{let r=this.lines.length,a=this.level;this.emit(`${e}function(${s}) {`),this.in();for(let c of t.body)this.genStmt(c);this.out(),this.emit("}");let h=this.lines.splice(r).map(c=>c.trimStart()).join(" ");return this.level=a,h}}case"MatchStmt":{let e=this.lines.length,s=this.level,r=this._loopDepth;this._loopDepth=0,this.emit("(() => {"),this.in(),this.genMatch(t),this.out(),this.emit("})()"),this._loopDepth=r;let a=this.lines.splice(e).map(h=>h.trimStart()).join(" ");return this.level=s,a}case"ArrayExpr":return`[${t.items.map(e=>this.genExpr(e)).join(", ")}]`;case"ObjectExpr":return`{ ${t.pairs.map(s=>{if(s.spread)return`...${this.genExpr(s.value)}`;if(s.computed)return`[${this.genExpr(s.keyExpr)}]: ${this.genExpr(s.value)}`;let r=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(s.key),a=r?s.key:`"${s.key}"`;return r&&s.value&&s.value.type==="Identifier"&&s.value.name===s.key?s.key:`${a}: ${this.genExpr(s.value)}`}).join(", ")} }`;case"RangeExpr":return`Array.from({ length: ${this.genExpr(t.end)} - ${this.genExpr(t.start)} }, (_, i) => i + ${this.genExpr(t.start)})`;case"PipeExpr":return this.genPipe(t);case"CastExpr":return this.genExpr(t.expr);case"AsConstExpr":return`Object.freeze(${this.genExpr(t.expr)})`;case"SatisfiesExpr":return this.genExpr(t.expr);case"IsExpr":return this.genExpr(t.expr);case"NonNullExpr":return this.genExpr(t.expr);default:throw new Y(`Unknown expression: ${t.type}`,t)}}genTemplate(t){let{Lexer:e}=H(),{Parser:s}=K(),r="`";for(let a of t)if(a.type==="text")r+=a.value.replace(/`/g,"\\`").replace(/\$/g,"\\$");else{let h=de(a.value),c=h?h.expr:a.value,l=h?h.fmt:null;try{let p=new e(c).tokenize(),u=new s(p).parseExpr(),m=this.genExpr(u);l?(this._needsFmt=!0,r+=`\${_fmt(${m}, ${JSON.stringify(l)})}`):r+=`\${${m}}`}catch{r+=`\${${a.value}}`}}return r+="`",r}genPipe(t){let e=this.genExpr(t.left),s=t.right;if(s.type==="Identifier")return`${this.genExpr(s)}(${e})`;if(s.type==="CallExpr"){let r=this.genExpr(s.callee),a=s.args.map(h=>this.genExpr(h)).join(", ");return a?`${r}(${e}, ${a})`:`${r}(${e})`}return`(${this.genExpr(s)})(${e})`}};Ct.exports={CodeGenerator:mt,CodeGenError:Y}});var Bt=F((cs,Ft)=>{"use strict";var xe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function q(n){let t=n<0?-n<<1|1:n<<1,e="";do{let s=t&31;t>>>=5,t>0&&(s|=32),e+=xe[s]}while(t>0);return e}var Et=class{constructor(t,e){this.sourceFile=t,this.sourceContent=e,this.mappings=[]}addMapping(t,e,s,r){for(;this.mappings.length<=t;)this.mappings.push([]);this.mappings[t].push({genCol:e,srcLine:s,srcCol:r})}encodeMappings(){let t=0,e=0;return this.mappings.map(s=>{let r=0;return s.map(a=>{let h=[q(a.genCol-r),q(0),q(a.srcLine-t),q(a.srcCol-e)].join("");return r=a.genCol,t=a.srcLine,e=a.srcCol,h}).join(",")}).join(";")}toJSON(t=""){return{version:3,file:t,sourceRoot:"",sources:[this.sourceFile],sourcesContent:[this.sourceContent],names:[],mappings:this.encodeMappings()}}toString(t=""){return JSON.stringify(this.toJSON(t))}};Ft.exports={SourceMapBuilder:Et,encodeVLQ:q}});var Qt=F((os,Wt)=>{"use strict";var kt={bg:n=>`background:${n}`,fg:n=>`color:${n}`,color:n=>`color:${n}`,p:n=>`padding:${n}`,px:n=>`paddingLeft:${n},paddingRight:${n}`,py:n=>`paddingTop:${n},paddingBottom:${n}`,pt:n=>`paddingTop:${n}`,pb:n=>`paddingBottom:${n}`,pl:n=>`paddingLeft:${n}`,pr:n=>`paddingRight:${n}`,m:n=>`margin:${n}`,mx:n=>`marginLeft:${n},marginRight:${n}`,my:n=>`marginTop:${n},marginBottom:${n}`,mt:n=>`marginTop:${n}`,mb:n=>`marginBottom:${n}`,ml:n=>`marginLeft:${n}`,mr:n=>`marginRight:${n}`,radius:n=>`borderRadius:${n}`,w:n=>`width:${n}`,h:n=>`height:${n}`,"min-w":n=>`minWidth:${n}`,"max-w":n=>`maxWidth:${n}`,"min-h":n=>`minHeight:${n}`,"max-h":n=>`maxHeight:${n}`,gap:n=>`gap:${n}`,"col-gap":n=>`columnGap:${n}`,"row-gap":n=>`rowGap:${n}`,text:n=>`fontSize:${n}`,font:n=>`fontFamily:${n}`,weight:n=>`fontWeight:${n}`,tracking:n=>`letterSpacing:${n}`,leading:n=>`lineHeight:${n}`,shadow:n=>`boxShadow:${n}`,opacity:n=>`opacity:${n}`,border:n=>`border:${n}`,outline:n=>`outline:${n}`,transition:n=>`transition:${n}`,cursor:n=>`cursor:${n}`,overflow:n=>`overflow:${n}`,z:n=>`zIndex:${n}`,transform:n=>`transform:${n}`,direction:n=>`flexDirection:${n}`,align:n=>`alignItems:${n}`,justify:n=>`justifyContent:${n}`,"align-self":n=>`alignSelf:${n}`,"place-items":n=>`placeItems:${n}`,grow:n=>`flexGrow:${n}`,shrink:n=>`flexShrink:${n}`,basis:n=>`flexBasis:${n}`,cols:n=>`gridTemplateColumns:${n}`,rows:n=>`gridTemplateRows:${n}`,inset:n=>`inset:${n}`,top:n=>`top:${n}`,right:n=>`right:${n}`,bottom:n=>`bottom:${n}`,left:n=>`left:${n}`,"object-fit":n=>`objectFit:${n}`,"line-height":n=>`lineHeight:${n}`,"text-align":n=>`textAlign:${n}`,decoration:n=>`textDecoration:${n}`,clip:n=>`clipPath:${n}`,filter:n=>`filter:${n}`,backdrop:n=>`backdropFilter:${n}`,animation:n=>`animation:${n}`},J={flex:'display:"flex"',grid:'display:"grid"',block:'display:"block"',"inline-flex":'display:"inline-flex"',"inline-block":'display:"inline-block"',bold:"fontWeight:700",italic:'fontStyle:"italic"',underline:'textDecoration:"underline"',pointer:'cursor:"pointer"',hidden:'display:"none"',relative:'position:"relative"',absolute:'position:"absolute"',fixed:'position:"fixed"',sticky:'position:"sticky"',"flex-col":'flexDirection:"column"',"flex-row":'flexDirection:"row"',"flex-wrap":'flexWrap:"wrap"',"flex-1":"flex:1","w-full":'width:"100%"',"h-full":'height:"100%"',center:'textAlign:"center"',truncate:'overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"',"select-none":'userSelect:"none"',"no-wrap":'whiteSpace:"nowrap"',"no-list":'listStyle:"none"',"no-outline":'outline:"none"',"no-border":'border:"none"',"box-border":'boxSizing:"border-box"'},ls=new Set([...Object.keys(kt),...Object.keys(J)]),st=class{constructor(t){this.src=t,this.pos=0,this.out=""}transform(){for(;this.pos<this.src.length;)this.scanTop();return this.hasJsx=this.out!==this.src,this.out}scanTop(){let t=this.src[this.pos];if(t==="/"&&this.src[this.pos+1]==="/"){let e=this.src.indexOf(`
|
|
39
|
+
`,this.pos);e===-1?(this.out+=this.src.slice(this.pos),this.pos=this.src.length):(this.out+=this.src.slice(this.pos,e+1),this.pos=e+1);return}if(t==="/"&&this.src[this.pos+1]==="*"){let e=this.src.indexOf("*/",this.pos+2);e===-1?(this.out+=this.src.slice(this.pos),this.pos=this.src.length):(this.out+=this.src.slice(this.pos,e+2),this.pos=e+2);return}if(t==='"'){this.passString('"');return}if(t==="'"){this.passString("'");return}if(t==="`"){this.passTemplateLit();return}if(t==="<"&&this.isJsxStart()){let e=this.parseJsxElement();this.out+=e;return}this.out+=t,this.pos++}isJsxStart(){let t=this.src[this.pos+1]||"";if(!(t===">"||t>="a"&&t<="z"||t>="A"&&t<="Z"))return!1;let e=this.pos-1;for(;e>=0&&(this.src[e]===" "||this.src[e]===" ");)e--;if(e<0)return!0;let s=this.src[e];if(`=([{,:>
|
|
40
|
+
?`.includes(s))return!0;if(/[a-z]/.test(s)){let r=e;for(;r>=0&&/[a-z]/.test(this.src[r]);)r--;let a=this.src.slice(r+1,e+1);if(new Set(["return","not","and","or","val","var","await","yield","else","in","throw"]).has(a))return!0}return!1}passString(t){for(this.out+=t,this.pos++;this.pos<this.src.length;){let e=this.src[this.pos];if(e==="\\"){this.out+=e+(this.src[this.pos+1]||""),this.pos+=2;continue}if(e===t){this.out+=e,this.pos++;return}this.out+=e,this.pos++}}passTemplateLit(){for(this.out+="`",this.pos++;this.pos<this.src.length;){let t=this.src[this.pos];if(t==="\\"){this.out+=t+(this.src[this.pos+1]||""),this.pos+=2;continue}if(t==="`"){this.out+=t,this.pos++;return}this.out+=t,this.pos++}}parseJsxElement(){if(this.pos++,this.src[this.pos]===">"){this.pos++;let s=this.parseJsxChildren("");return this.expectClose(""),`_fluxH("",null${s.length?","+s.join(","):""})`}let t=this.readTagName(),e=this.parseJsxAttrs();if(this.src[this.pos]==="/"&&this.src[this.pos+1]===">")return this.pos+=2,`_fluxH("${t}",${e})`;if(this.src[this.pos]===">"){this.pos++;let s=this.parseJsxChildren(t);this.expectClose(t);let r=s.length?","+s.join(","):"";return`_fluxH("${t}",${e}${r})`}return`<${t}`}readTagName(){let t="";for(;this.pos<this.src.length;){let e=this.src[this.pos];if(/[a-zA-Z0-9\-_\.]/.test(e))t+=e,this.pos++;else break}return t}parseJsxAttrs(){this.skipWs();let t=[],e=[],s=null;for(;this.pos<this.src.length;){let r=this.src[this.pos];if(r===">"||r==="/"&&this.src[this.pos+1]===">"||(this.skipWs(),!/[a-zA-Z_\-]/.test(this.src[this.pos])))break;let a="";for(;this.pos<this.src.length&&/[a-zA-Z0-9\-_:]/.test(this.src[this.pos]);)a+=this.src[this.pos++];if(this.skipWs(),this.src[this.pos]!=="="){J[a]!==void 0?e.push(J[a]):t.push(`"${a}":true`);continue}this.pos++,this.skipWs();let h=this.src[this.pos],c=null,l=null;if(h==='"'||h==="'"){let p=h;this.pos++;let u="";for(;this.pos<this.src.length&&this.src[this.pos]!==p;)this.src[this.pos]==="\\"?(u+=this.src[this.pos]+this.src[this.pos+1],this.pos+=2):u+=this.src[this.pos++];this.pos++,c=u}else if(h==="{")l=this.readBraced();else{J[a]!==void 0?e.push(J[a]):t.push(`"${a}":true`),this.skipWs();continue}if(c!==null&&kt[a]){let p=kt[a](JSON.stringify(c));e.push(p)}else l!==null&&a==="style"?s=l:c!==null?t.push(`"${a}":${JSON.stringify(c)}`):t.push(`"${a}":${l}`);this.skipWs()}if(e.length>0||s!==null){let r=e.length>0?`{${e.join(",")}}`:null;s!==null&&r!==null?t.push(`"style":Object.assign(${s},${r})`):s!==null?t.push(`"style":${s}`):t.push(`"style":{${e.join(",")}}`)}return t.length?`{${t.join(",")}}`:"null"}readBraced(){this.pos++;let t=1,e="";for(;this.pos<this.src.length&&t>0;){let s=this.src[this.pos];if(s==="{"&&t++,s==="}"&&(t--,t===0)){this.pos++;break}e+=s,this.pos++}return e.trim()}parseJsxChildren(t){let e=[];for(;this.pos<this.src.length&&!(this.src[this.pos]==="<"&&this.src[this.pos+1]==="/");){if(this.src[this.pos]==="<"){let a=this.src[this.pos+1]||"";if(a>="a"&&a<="z"||a>="A"&&a<="Z"||a===">"){e.push(this.parseJsxElement());continue}}if(this.src[this.pos]==="{"){let a=this.readBraced();a.trim()&&e.push(a);continue}let s="";for(;this.pos<this.src.length;){let a=this.src[this.pos];if(a==="<"||a==="{")break;s+=a,this.pos++}let r=s.replace(/\s+/g," ").trim();r&&e.push(JSON.stringify(r))}return e}expectClose(t){if(this.src[this.pos]==="<"&&this.src[this.pos+1]==="/"){for(this.pos+=2;this.pos<this.src.length&&this.src[this.pos]!==">";)this.pos++;this.src[this.pos]===">"&&this.pos++}}skipWs(){for(;this.pos<this.src.length&&(this.src[this.pos]===" "||this.src[this.pos]===" ");)this.pos++}},Pt=`
|
|
41
|
+
function _fluxH(tag,props,...children){
|
|
42
|
+
if(tag===""){const f=document.createDocumentFragment();children.flat(Infinity).forEach(c=>{if(c==null)return;f.appendChild(c instanceof Node?c:document.createTextNode(String(c)));});return f;}
|
|
43
|
+
const el=document.createElement(tag);
|
|
44
|
+
if(props){for(const[k,v]of Object.entries(props)){if(k==="class"||k==="className"){el.className=v;}else if(k==="style"&&typeof v==="object"){Object.assign(el.style,v);}else if(k.startsWith("on")&&typeof v==="function"){el.addEventListener(k.slice(2).toLowerCase(),v);}else if(typeof v==="boolean"){if(v)el.setAttribute(k,"");}else{el.setAttribute(k,String(v));}}}
|
|
45
|
+
children.flat(Infinity).forEach(c=>{if(c==null)return;el.appendChild(c instanceof Node?c:document.createTextNode(String(c)));});
|
|
46
|
+
return el;
|
|
47
|
+
}`,Mt='\nfunction _fluxH(tag,props,...children){\n const VOID=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);\n if(tag==="")return children.flat(Infinity).map(c=>c==null?"":String(c)).join("");\n let attrs="";\n if(props){for(const[k,v]of Object.entries(props)){if(k==="class"||k==="className")attrs+=` class="${v}"`;else if(k==="style"&&typeof v==="object")attrs+=` style="${Object.entries(v).map(([p,val])=>p.replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+":"+val).join(";")}"`;else if(typeof v!=="function"&&typeof v!=="boolean")attrs+=` ${k}="${String(v).replace(/"/g,""")}"`;else if(v===true)attrs+=` ${k}`;}}\n const inner=children.flat(Infinity).map(c=>c==null?"":String(c)).join("");\n if(VOID.has(tag))return`<${tag}${attrs}>`;\n return`<${tag}${attrs}>${inner}</${tag}>`;\n}',jt=`
|
|
48
|
+
function _fluxCSS(css){const s=document.createElement("style");s.textContent=css;document.head.appendChild(s);return css;}`,Ut=`
|
|
49
|
+
function _fluxCSS(css){return css;}`;function be(n,t={}){let e=t.target||"browser",s=new st(n),r=s.transform(),a=s.hasJsx||n.includes("_fluxH")||n.includes("_fluxCSS");return{source:r,hasJsx:a,runtimeHelpers:(e==="browser"?Pt:Mt)+(e==="browser"?jt:Ut)}}Wt.exports={transformJsx:be,JsxPreprocessor:st,FLUX_H_BROWSER:Pt,FLUX_H_SERVER:Mt,FLUX_CSS_BROWSER:jt,FLUX_CSS_SERVER:Ut}});var Ht=F((ps,Vt)=>{"use strict";var X=new Set(["undefined","null","true","false","NaN","Infinity","arguments","this","super","console","document","window","navigator","location","history","screen","Math","JSON","Array","Object","String","Number","Boolean","Symbol","BigInt","Promise","Proxy","Reflect","WeakMap","WeakSet","WeakRef","Map","Set","Date","RegExp","Error","TypeError","RangeError","SyntaxError","URIError","EvalError","ReferenceError","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","atob","btoa","structuredClone","queueMicrotask","setTimeout","setInterval","clearTimeout","clearInterval","requestAnimationFrame","cancelAnimationFrame","fetch","XMLHttpRequest","WebSocket","EventSource","FormData","Headers","Request","Response","URL","URLSearchParams","Blob","File","FileReader","alert","confirm","prompt","Event","CustomEvent","Node","Element","HTMLElement","DocumentFragment","MutationObserver","IntersectionObserver","ResizeObserver","process","Buffer","require","module","exports","__dirname","__filename","global","globalThis","setImmediate","clearImmediate","queueMicrotask","TextEncoder","TextDecoder","AbortController","AbortSignal","performance","Http","Fs","Path","Url","Crypto","Os","Net","Stream","Events","Util","http","fs","path","url","crypto","os","net","stream","events","util","_fluxH","_fluxCSS","print"]);function it(n){let t="abcdefghijklmnopqrstuvwxyz",e="";for(n++;n>0;)e=t[(n-1)%26]+e,n=Math.floor((n-1)/26);return"_"+e}var dt=class{constructor(){this.map=new Map,this.counter=0,this.exported=new Set,this.imported=new Set}mangle(t){return this._collectExportedAndImported(t),this._collectDeclarations(t),this._walkProgram(t)}getMap(){return Object.fromEntries(this.map)}_collectExportedAndImported(t){for(let e of t.body){if(e.type==="ExportDecl"){let s=e.decl;s&&s.name&&this.exported.add(s.name),s&&s.type==="DestructureDecl"&&(s.pattern||[]).forEach(r=>r&&this.exported.add(r.alias||r.name||r.key))}e.type==="ImportDecl"&&(e.defaultName&&this.imported.add(e.defaultName),(e.names||[]).forEach(s=>this.imported.add(s)))}}_collectDeclarations(t){this._walkStmts(t.body,{toplevel:!0,collect:!0})}_walkProgram(t){let e=this._walkStmts(t.body,{toplevel:!0});return{...t,body:e}}_walkStmts(t,e={}){return t.map(s=>this._walkStmt(s,e))}_walkStmt(t,e={}){if(!t)return t;switch(t.type){case"VarDecl":return this._walkVarDecl(t,e);case"DestructureDecl":return this._walkDestructure(t,e);case"FnDecl":return this._walkFnDecl(t,e);case"ClassDecl":return this._walkClassDecl(t,e);case"IfStmt":return{...t,cond:this._walkExpr(t.cond),then:this._walkStmts(t.then),elseifs:t.elseifs.map(s=>({cond:this._walkExpr(s.cond),body:this._walkStmts(s.body)})),else_:t.else_?this._walkStmts(t.else_):null};case"ForInStmt":return{...t,var:this._mangleLocal(t.var),iter:this._walkExpr(t.iter),body:this._walkStmts(t.body)};case"WhileStmt":return{...t,cond:this._walkExpr(t.cond),body:this._walkStmts(t.body)};case"DoWhileStmt":return{...t,cond:this._walkExpr(t.cond),body:this._walkStmts(t.body)};case"MatchStmt":return{...t,subject:this._walkExpr(t.subject),arms:t.arms.map(s=>({...s,body:this._walkStmts(s.body)}))};case"ReturnStmt":return{...t,value:this._walkExpr(t.value)};case"ThrowStmt":return{...t,value:this._walkExpr(t.value)};case"TryCatchStmt":return{...t,tryBody:this._walkStmts(t.tryBody),catchParam:t.catchParam?this._mangleLocal(t.catchParam):null,catchBody:t.catchBody?this._walkStmts(t.catchBody):null,finallyBody:t.finallyBody?this._walkStmts(t.finallyBody):null};case"ExportDecl":{let s=t.decl;return{...t,decl:this._walkStmt(s,e)}}case"ImportDecl":return t;case"TypeDecl":return t;case"ExprStmt":return{...t,expr:this._walkExpr(t.expr)};case"BreakStmt":case"ContinueStmt":return t;default:return t}}_walkVarDecl(t,e){return e.collect?(this._registerName(t.name),t):{...t,name:this._mangleName(t.name),init:t.init?this._walkExpr(t.init):null}}_walkDestructure(t,e){if(e.collect)return(t.pattern||[]).forEach(s=>{s&&this._registerName(s.alias||s.name||s.key)}),t;if(t.patternType==="array"){let s=t.pattern.map(r=>r&&(r.rest?{...r,name:this._mangleName(r.name)}:{...r,name:this._mangleName(r.name),defaultVal:r.defaultVal?this._walkExpr(r.defaultVal):null}));return{...t,pattern:s,init:this._walkExpr(t.init)}}else{let s=t.pattern.map(r=>r&&(r.rest?{...r,key:r.key,alias:this._mangleName(r.alias||r.key)}:{...r,alias:this._mangleName(r.alias||r.key),defaultVal:r.defaultVal?this._walkExpr(r.defaultVal):null}));return{...t,pattern:s,init:this._walkExpr(t.init)}}}_walkFnDecl(t,e){if(e.collect&&t.name)return this._registerName(t.name),t;let s=t.name?this._mangleName(t.name):null,r=t.params.map(h=>({...h,name:this._mangleParam(h.name),defaultVal:h.defaultVal?this._walkExpr(h.defaultVal):null})),a=t.inline?this._walkExpr(t.body):this._walkStmts(t.body);return{...t,name:s,params:r,body:a}}_walkClassDecl(t,e){if(e.collect&&t.name)return this._registerName(t.name),t;let s=this._mangleName(t.name),r=t.methods.map(h=>{let c=h.params.map(p=>({...p,name:this._mangleParam(p.name),defaultVal:p.defaultVal?this._walkExpr(p.defaultVal):null})),l=h.inline?this._walkExpr(h.body):this._walkStmts(h.body);return{...h,params:c,body:l}}),a=t.superClass?this._mangleName(t.superClass):null;return{...t,name:s,superClass:a,methods:r}}_walkExpr(t){if(!t)return t;switch(t.type){case"Identifier":return{...t,name:this._mangleName(t.name)};case"NumberLit":case"BoolLit":case"NullLit":case"StringLit":case"SelfExpr":return t;case"TemplateLit":return{...t,parts:t.parts.map(e=>{if(e.type!=="expr")return e;let s=e.value;for(let[r,a]of this.map)s=s.replace(new RegExp(`(?<![\\w$])${r}(?![\\w$])`,"g"),a);return{...e,value:s}})};case"BinaryExpr":return{...t,left:this._walkExpr(t.left),right:this._walkExpr(t.right)};case"UnaryExpr":return{...t,operand:this._walkExpr(t.operand)};case"UpdateExpr":return{...t,operand:this._walkExpr(t.operand)};case"AwaitExpr":return{...t,operand:this._walkExpr(t.operand)};case"TypeofExpr":return{...t,operand:this._walkExpr(t.operand)};case"TernaryExpr":return{...t,cond:this._walkExpr(t.cond),then:this._walkExpr(t.then),else_:this._walkExpr(t.else_)};case"AssignExpr":return{...t,target:this._walkExpr(t.target),value:this._walkExpr(t.value)};case"SpreadExpr":return{...t,expr:this._walkExpr(t.expr)};case"PipeExpr":return{...t,left:this._walkExpr(t.left),right:this._walkExpr(t.right)};case"MemberExpr":return{...t,obj:this._walkExpr(t.obj)};case"OptMemberExpr":return{...t,obj:this._walkExpr(t.obj)};case"IndexExpr":return{...t,obj:this._walkExpr(t.obj),idx:this._walkExpr(t.idx)};case"OptIndexExpr":return{...t,obj:this._walkExpr(t.obj),idx:this._walkExpr(t.idx)};case"CallExpr":return{...t,callee:this._walkExpr(t.callee),args:t.args.map(e=>this._walkExpr(e))};case"OptCallExpr":return{...t,callee:this._walkExpr(t.callee),args:t.args.map(e=>this._walkExpr(e))};case"NewExpr":return{...t,callee:this._mangleName(t.callee),args:t.args.map(e=>this._walkExpr(e))};case"LambdaExpr":return{...t,params:t.params.map(e=>({...e,name:this._mangleParam(e.name)})),body:this._walkExpr(t.body)};case"FnDecl":return this._walkFnDecl(t,{});case"ArrayExpr":return{...t,items:t.items.map(e=>this._walkExpr(e))};case"ObjectExpr":return{...t,pairs:t.pairs.map(e=>({...e,value:this._walkExpr(e.value)}))};case"RangeExpr":return{...t,start:this._walkExpr(t.start),end:this._walkExpr(t.end)};default:return t}}_registerName(t){!t||X.has(t)||this.exported.has(t)||this.imported.has(t)||this.map.has(t)||this.map.set(t,it(this.counter++))}_mangleName(t){return!t||X.has(t)||this.exported.has(t)||this.imported.has(t)?t:this.map.has(t)?this.map.get(t):t}_mangleLocal(t){return!t||X.has(t)?t:(this.map.has(t)||this.map.set(t,it(this.counter++)),this.map.get(t))}_mangleParam(t){return!t||X.has(t)?t:(this.map.has(t)||this.map.set(t,it(this.counter++)),this.map.get(t))}};Vt.exports={Mangler:dt,SAFE:X,makeName:it}});var qt=F((us,Yt)=>{"use strict";var Kt={bg:"background",fg:"color",p:"padding",px:"padding-inline",py:"padding-block",pt:"padding-top",pb:"padding-bottom",pl:"padding-left",pr:"padding-right",m:"margin",mx:"margin-inline",my:"margin-block",mt:"margin-top",mb:"margin-bottom",ml:"margin-left",mr:"margin-right",radius:"border-radius",w:"width",h:"height","min-w":"min-width","max-w":"max-width","min-h":"min-height","max-h":"max-height",gap:"gap","col-gap":"column-gap","row-gap":"row-gap",text:"font-size",font:"font-family",weight:"font-weight",tracking:"letter-spacing",leading:"line-height",shadow:"box-shadow",opacity:"opacity",border:"border",outline:"outline",transition:"transition",cursor:"cursor",overflow:"overflow","overflow-x":"overflow-x","overflow-y":"overflow-y",z:"z-index",transform:"transform",content:"content",resize:"resize",appearance:"appearance","accent-color":"accent-color","object-fit":"object-fit",direction:"flex-direction",wrap:"flex-wrap",align:"align-items",justify:"justify-content","align-self":"align-self","justify-self":"justify-self",grow:"flex-grow",shrink:"flex-shrink",basis:"flex-basis",order:"order",cols:"grid-template-columns",rows:"grid-template-rows","col-span":"grid-column","row-span":"grid-row","place-items":"place-items","place-content":"place-content","list-style":"list-style","text-align":"text-align",decoration:"text-decoration","text-transform":"text-transform","white-space":"white-space","word-break":"word-break","user-select":"user-select","pointer-events":"pointer-events","vertical-align":"vertical-align",backdrop:"backdrop-filter",filter:"filter",clip:"clip-path",animation:"animation",position:"position",top:"top",right:"right",bottom:"bottom",left:"left",inset:"inset",color:"color",background:"background"},Z={flex:"display: flex",grid:"display: grid",block:"display: block",inline:"display: inline","inline-flex":"display: inline-flex","inline-block":"display: inline-block","inline-grid":"display: inline-grid",bold:"font-weight: 700",italic:"font-style: italic",relative:"position: relative",absolute:"position: absolute",fixed:"position: fixed",sticky:"position: sticky",hidden:"display: none",pointer:"cursor: pointer",underline:"text-decoration: underline","line-through":"text-decoration: line-through",capitalize:"text-transform: capitalize",uppercase:"text-transform: uppercase",lowercase:"text-transform: lowercase",truncate:"overflow: hidden; text-overflow: ellipsis; white-space: nowrap","select-none":"user-select: none","no-wrap":"white-space: nowrap","no-list":"list-style: none","no-outline":"outline: none","no-border":"border: none","no-bg":"background: transparent","no-padding":"padding: 0","no-margin":"margin: 0","no-resize":"resize: none",center:"text-align: center","items-center":"align-items: center","justify-center":"justify-content: center","place-center":"place-items: center","flex-col":"flex-direction: column","flex-row":"flex-direction: row","flex-wrap":"flex-wrap: wrap","flex-1":"flex: 1","w-full":"width: 100%","h-full":"height: 100%","w-screen":"width: 100vw","h-screen":"height: 100vh","box-border":"box-sizing: border-box"};function gt(n){let t=n.trim();return Kt[t]||t}function Tt(n){let t=n.trim();return t.length>=2&&(t[0]==='"'&&t[t.length-1]==='"'||t[0]==="'"&&t[t.length-1]==="'")?t.slice(1,-1):t}function zt(n,t){return n=n.trim(),!t||n.startsWith("@")||t.startsWith("@keyframes")||t.startsWith("@font-face")?n:n.includes("&")?n.replace(/&/g,t):t+" "+n}function Gt(n){let t=[];return n.split(";").forEach(e=>{let s=e.trim();if(!s||s.startsWith("//"))return;if(Z[s]){Z[s].split(";").forEach(a=>{let h=a.trim();h&&t.push(h)});return}let r=s.indexOf(":");if(r!==-1){let a=gt(s.slice(0,r)),h=Tt(s.slice(r+1));h!==""&&t.push(a+": "+h)}}),t}function bt(n,t){let e=" ".repeat(t||0),s=e+" ",r=n.split(`
|
|
50
|
+
`),a=new Map,h=[],c=[];function l(){return c.length?c[c.length-1]:null}function p(N,f){a.has(N)||a.set(N,[]),a.get(N).push(f)}function u(N,f){if(N.includes(";")){N.split(";").forEach(w=>{let b=w.trim();b&&u(b,f)});return}if(Z[N]){Z[N].split(";").forEach(w=>{let b=w.trim();b&&p(f,b)});return}let d=N.indexOf(":");if(d!==-1){let w=gt(N.slice(0,d)),b=Tt(N.slice(d+1));b!==""&&p(f,w+": "+b)}}function m(N){let f=1,d="",w=N;for(;w<r.length&&f>0;){let b=r[w++];for(let k of b)k==="{"?f++:k==="}"&&f--;if(f>0)d+=b+`
|
|
51
|
+
`;else{let k=b.lastIndexOf("}");k>0&&(d+=b.slice(0,k)+`
|
|
52
|
+
`)}}return{inner:d,nextI:w}}let x=0;for(;x<r.length;){let f=r[x++].trim();if(!f||f.startsWith("//"))continue;let d=f.indexOf("{"),w=f.lastIndexOf("}");if(f.startsWith("@keyframes")||f.startsWith("@font-face")){let b=d!==-1?f.slice(0,d).trim():f.trim(),k="";if(d!==-1&&w!==-1&&w>d)k=f.slice(d+1,w);else if(d!==-1){let I=m(x);x=I.nextI,k=I.inner}let A=k.split(`
|
|
53
|
+
`).map(I=>{let $=I.trim();if(!$||$==="{"||$==="}")return I;let et=$.indexOf(":");if(et!==-1&&!$.slice(0,et).includes("{")){let me=gt($.slice(0,et)),ye=Tt($.slice(et+1));return I.replace($,me+": "+ye)}return I}).join(`
|
|
54
|
+
`);h.push(`${e}${b} {
|
|
55
|
+
${A}${e}}
|
|
56
|
+
`);continue}if(f.startsWith("@media")||f.startsWith("@supports")||f.startsWith("@layer")){let b=d!==-1?f.slice(0,d).trim():f.trim(),k="";if(d!==-1&&w!==-1&&w>d)k=f.slice(d+1,w);else if(d!==-1){let I=m(x);x=I.nextI,k=I.inner}let A=bt(k,(t||0)+1);h.push(`${e}${b} {
|
|
57
|
+
${A}${e}}
|
|
58
|
+
`);continue}if(d!==-1&&w!==-1&&w>d){let b=f.slice(0,d).trim(),k=f.slice(d+1,w).trim(),A=zt(b,l());a.has(A)||a.set(A,[]),k&&Gt(k).forEach(I=>p(A,I));continue}if(d!==-1){let b=f.slice(0,d).trim(),k=zt(b,l());c.push(k),a.has(k)||a.set(k,[]);let A=f.slice(d+1).trim();A&&Gt(A).forEach(I=>p(k,I));continue}if(f==="}"||f==="};"){c.pop();continue}c.length>0&&u(f,l())}let S="";for(let[N,f]of a)if(f.length!==0){S+=`${e}${N} {
|
|
59
|
+
`;for(let d of f)S+=`${s}${d};
|
|
60
|
+
`;S+=`${e}}
|
|
61
|
+
`}for(let N of h)S+=N;return S}var xt=class{constructor(t){this.src=t,this.pos=0,this.out=""}transform(){for(;this.pos<this.src.length;)this.scan();return this.out}scan(){let t=this.src[this.pos];if(t==="/"&&this.src[this.pos+1]==="/"){let e=this.src.indexOf(`
|
|
62
|
+
`,this.pos);e===-1?(this.out+=this.src.slice(this.pos),this.pos=this.src.length):(this.out+=this.src.slice(this.pos,e+1),this.pos=e+1);return}if(t==="/"&&this.src[this.pos+1]==="*"){let e=this.src.indexOf("*/",this.pos+2);e===-1?(this.out+=this.src.slice(this.pos),this.pos=this.src.length):(this.out+=this.src.slice(this.pos,e+2),this.pos=e+2);return}if(t==='"'||t==="'"||t==="`"){this.passString(t);return}if(t==="c"&&this.src.slice(this.pos,this.pos+3)==="css"){let e=this.pos>0?this.src[this.pos-1]:`
|
|
63
|
+
`,s=this.src[this.pos+3]||"";if(!/[a-zA-Z0-9_]/.test(e)&&!/[a-zA-Z0-9_]/.test(s)){let r=this.pos+3;for(;r<this.src.length&&(this.src[r]===" "||this.src[r]===" "||this.src[r]===`
|
|
64
|
+
`||this.src[r]==="\r");)r++;if(this.src[r]==="{"){r++;let a=1,h=r;for(;r<this.src.length&&a>0;){let p=this.src[r];if(p==='"'||p==="'"||p==="`"){let u=p;for(r++;r<this.src.length&&this.src[r]!==u;)this.src[r]==="\\"&&r++,r++;r++}else p==="{"?(a++,r++):(p==="}"&&a--,r++)}let c=this.src.slice(h,r-1),l=bt(c);this.out+="`"+l.replace(/\\/g,"\\\\").replace(/`/g,"\\`")+"`",this.pos=r;return}}}this.out+=t,this.pos++}passString(t){for(this.out+=t,this.pos++;this.pos<this.src.length;){let e=this.src[this.pos];if(e==="\\"){this.out+=e+(this.src[this.pos+1]||""),this.pos+=2;continue}if(e===t){this.out+=e,this.pos++;return}this.out+=e,this.pos++}}};function Ne(n){return new xt(n).transform()}Yt.exports={transformCss:Ne,parseCssBlockContent:bt,CSS_PROP_MAP:Kt,CSS_BOOL_MAP:Z}});var Xt=F((fs,Jt)=>{"use strict";var rt=class{constructor(t,e,s=null){this.message=t,this.loc=e,this.hint=s,this.name="CheckError",e&&(this.line=e.line,this.col=e.col)}},O=class{constructor(t=null){this.parent=t,this.vars=new Map}define(t,e,s){this.vars.set(t,{kind:e,loc:s})}lookup(t){let e=this;for(;e;){if(e.vars.has(t))return e.vars.get(t);e=e.parent}return null}isVal(t){let e=this.lookup(t);return e&&e.kind==="val"}},Nt=class{constructor(){this.errors=[],this.warnings=[]}check(t){this.errors=[],this.warnings=[];let e=new O;return this.walkStmts(t.body,e),{errors:this.errors,warnings:this.warnings}}error(t,e,s=null){this.errors.push(new rt(t,e,s))}warn(t,e,s=null){this.warnings.push(new rt(t,e,s))}walkStmts(t,e){for(let s of t)this.walkStmt(s,e)}walkStmt(t,e){if(t)switch(t.type){case"VarDecl":t.init&&this.walkExpr(t.init,e),e.define(t.name,t.kind,t.loc);break;case"DestructureDecl":if(t.init&&this.walkExpr(t.init,e),t.patternType==="object")for(let s of t.pattern)e.define(s.alias,t.kind,t.loc);else for(let s of t.pattern)s&&e.define(s.name,t.kind,t.loc);break;case"FnDecl":{let s=new O(e);for(let r of t.params)s.define(r.name,"val",t.loc);t.name&&e.define(t.name,"val",t.loc),t.inline?this.walkExpr(t.body,s):this.walkStmts(t.body,s);break}case"ClassDecl":{e.define(t.name,"val",t.loc);let s=new O(e);for(let r of t.fields)s.define(r.name,"var",t.loc);for(let r of t.methods)this.walkStmt(r,s);break}case"TypeDecl":for(let s of t.variants)e.define(s.name,"val",t.loc);break;case"InterfaceDecl":e.define(t.name,"val",t.loc);break;case"EnumDecl":e.define(t.name,"val",t.loc);break;case"IfStmt":this.walkExpr(t.cond,e),this.walkStmts(t.then,new O(e));for(let s of t.elseifs)this.walkExpr(s.cond,e),this.walkStmts(s.body,new O(e));t.else_&&this.walkStmts(t.else_,new O(e));break;case"ForInStmt":{this.walkExpr(t.iter,e);let s=new O(e);s.define(t.var,"val",t.loc),this.walkStmts(t.body,s);break}case"WhileStmt":this.walkExpr(t.cond,e),this.walkStmts(t.body,new O(e));break;case"DoWhileStmt":this.walkStmts(t.body,new O(e)),this.walkExpr(t.cond,e);break;case"MatchStmt":this.walkExpr(t.subject,e);for(let s of t.arms){let r=new O(e);if(s.pattern.type==="VariantPat")for(let a of s.pattern.bindings)r.define(a,"val",t.loc);s.guard&&this.walkExpr(s.guard,r),this.walkStmts(s.body,r)}break;case"ReturnStmt":t.value&&this.walkExpr(t.value,e);break;case"ThrowStmt":this.walkExpr(t.value,e);break;case"TryCatchStmt":{if(this.walkStmts(t.tryBody,new O(e)),t.catchBody){let s=new O(e);t.catchParam&&s.define(t.catchParam,"val",t.loc),this.walkStmts(t.catchBody,s)}t.finallyBody&&this.walkStmts(t.finallyBody,new O(e));break}case"ImportDecl":t.defaultName&&e.define(t.defaultName,"val",t.loc),t.namespaceName&&e.define(t.namespaceName,"val",t.loc);for(let s of t.names)e.define(typeof s=="string"?s:s.alias,"val",t.loc);break;case"ExportDecl":this.walkStmt(t.isDefault?{type:"ExprStmt",expr:t.decl}:t.decl,e);break;case"ExprStmt":this.walkExpr(t.expr,e);break;case"BreakStmt":case"ContinueStmt":break;default:}}walkExpr(t,e){if(t)switch(t.type){case"AssignExpr":{let s=t.target;s.type==="Identifier"&&e.isVal(s.name)&&this.error(`Cannot reassign 'val ${s.name}' \u2014 val is immutable`,s.loc,`Use 'var ${s.name}' if you need a mutable variable`),this.walkExpr(t.target,e),this.walkExpr(t.value,e);break}case"UpdateExpr":t.operand.type==="Identifier"&&e.isVal(t.operand.name)&&this.error(`Cannot apply '${t.op}' to 'val ${t.operand.name}' \u2014 val is immutable`,t.operand.loc,`Use 'var ${t.operand.name}' if you need a mutable variable`),this.walkExpr(t.operand,e);break;case"BinaryExpr":case"PipeExpr":this.walkExpr(t.left,e),this.walkExpr(t.right,e);break;case"UnaryExpr":case"AwaitExpr":case"TypeofExpr":this.walkExpr(t.operand,e);break;case"TernaryExpr":this.walkExpr(t.cond,e),this.walkExpr(t.then,e),this.walkExpr(t.else_,e);break;case"CallExpr":case"OptCallExpr":this.walkExpr(t.callee,e);for(let s of t.args)this.walkExpr(s,e);break;case"MemberExpr":case"OptMemberExpr":this.walkExpr(t.obj,e);break;case"IndexExpr":case"OptIndexExpr":this.walkExpr(t.obj,e),this.walkExpr(t.idx,e);break;case"NewExpr":for(let s of t.args)this.walkExpr(s,e);break;case"ArrayExpr":for(let s of t.items)s&&this.walkExpr(s,e);break;case"ObjectExpr":for(let s of t.pairs)s.value&&this.walkExpr(s.value,e);break;case"SpreadExpr":this.walkExpr(t.expr,e);break;case"LambdaExpr":{let s=new O(e);for(let r of t.params)s.define(r.name,"val",null);this.walkExpr(t.body,s);break}case"FnDecl":{let s=new O(e);for(let r of t.params)s.define(r.name,"val",null);t.inline?this.walkExpr(t.body,s):this.walkStmts(t.body,s);break}case"TemplateLit":break;case"CastExpr":case"AsConstExpr":case"SatisfiesExpr":case"IsExpr":case"NonNullExpr":this.walkExpr(t.expr,e);break;case"RangeExpr":this.walkExpr(t.start,e),this.walkExpr(t.end,e);break;case"Identifier":case"NumberLit":case"BoolLit":case"NullLit":case"StringLit":case"SelfExpr":break;default:}}};Jt.exports={Checker:Nt}});var re=F((ms,ie)=>{"use strict";var D=Object.freeze({kind:"any"}),E=Object.freeze({kind:"unknown"}),tt=Object.freeze({kind:"never"}),v=Object.freeze({kind:"void"}),j=Object.freeze({kind:"null"}),_=Object.freeze({kind:"primitive",name:"String"}),M=Object.freeze({kind:"primitive",name:"Int"}),Q=Object.freeze({kind:"primitive",name:"Float"}),L=Object.freeze({kind:"primitive",name:"Number"}),P=Object.freeze({kind:"primitive",name:"Bool"});function C(...n){let t=[];for(let r of n)r&&r.kind==="union"?t.push(...r.members):r&&t.push(r);let e=new Set,s=t.filter(r=>{let a=g(r);return e.has(a)?!1:(e.add(a),!0)});return s.length===0?tt:s.length===1?s[0]:{kind:"union",members:s}}function te(...n){let t=[];for(let e of n)e&&e.kind==="intersection"?t.push(...e.members):e&&t.push(e);return t.length===1?t[0]:{kind:"intersection",members:t}}function z(n){return{kind:"generic",name:"Array",args:[n||E]}}function wt(n){return{kind:"tuple",types:n||[]}}function ee(n){return C(n,j)}function y(n){return{kind:"named",name:n}}function R(n,t){return{kind:"fn",params:n||[],ret:t||v}}function at(n){return{kind:"object",shape:n||new Map}}function se(n,t){return{kind:"record",key:n||_,val:t||E}}function we(n,t){return{kind:"literal",value:n,prim:t}}function g(n){if(!n)return"unknown";switch(n.kind){case"any":return"Any";case"unknown":return"Unknown";case"never":return"Never";case"void":return"Void";case"null":return"Null";case"primitive":return n.name;case"literal":return JSON.stringify(n.value);case"union":return n.members.map(g).join(" | ");case"intersection":return n.members.map(g).join(" & ");case"tuple":return"["+n.types.map(g).join(", ")+"]";case"object":return"{"+[...(n.shape||new Map).entries()].map(([t,e])=>`${t}: ${g(e)}`).join(", ")+"}";case"record":return`Record<${g(n.key)}, ${g(n.val)}>`;case"generic":return n.name+(n.args&&n.args.length?"<"+n.args.map(g).join(", ")+">":"");case"named":return n.name;case"fn":return`(${(n.params||[]).map(g).join(", ")}) -> ${g(n.ret)}`;case"keyof":return`keyof ${g(n.inner)}`;case"conditional":return`${g(n.check)} extends ${g(n.extends)} ? ${g(n.then)} : ${g(n.else)}`;default:return"unknown"}}function W(n,t){let e=[],s=0,r=0;for(let a=0;a<n.length;a++){let h=n[a];"<([{".includes(h)?s++:">)]}".includes(h)?s--:s===0&&n.slice(a,a+t.length)===t&&(e.push(n.slice(r,a)),r=a+t.length,a+=t.length-1)}return e.push(n.slice(r)),e.filter(a=>a.trim().length>0)}var Zt={String:_,string:_,Int:M,int:M,Float:Q,float:Q,Number:L,number:L,Bool:P,boolean:P,Boolean:P,bool:P,Void:v,void:v,Never:tt,never:tt,Any:D,any:D,Unknown:E,unknown:E,Null:j,null:j,undefined:v,Object:y("Object"),object:y("Object"),Symbol:y("Symbol"),symbol:y("Symbol"),BigInt:y("BigInt"),bigint:y("BigInt")};function T(n){if(!n)return null;n=n.trim(),n.startsWith("(")&&n.endsWith(")")&&(n=n.slice(1,-1).trim());let t=W(n," | ");if(t.length>1)return C(...t.map(T));let e=W(n," & ");if(e.length>1)return te(...e.map(T));let s=n.match(/^(\w+)\s+extends\s+(.+?)\s*\?\s*(.+?)\s*:\s*(.+)$/);if(s)return{kind:"conditional",check:T(s[1]),extends:T(s[2]),then:T(s[3]),else:T(s[4])};if(n.startsWith("keyof "))return{kind:"keyof",inner:T(n.slice(6))};if(n.startsWith("typeof "))return{kind:"typeof",name:n.slice(7)};if(n.startsWith("readonly "))return T(n.slice(9));if(n.startsWith("infer "))return D;let r=n.match(/^fn\(([^)]*)\)\s*->\s*(.+)$/)||n.match(/^\(([^)]*)\)\s*->\s*(.+)$/);if(r){let h=r[1].trim(),c=r[2].trim(),l=h?W(h,", ").map(p=>{let u=p.indexOf(":");return T(u>=0?p.slice(u+1).trim():p.trim())}):[];return R(l,T(c))}if(n.endsWith("?"))return ee(T(n.slice(0,-1)));if(n.endsWith("[]"))return z(T(n.slice(0,-2)));if(n.startsWith("[")&&n.endsWith("]")){let h=n.slice(1,-1);if(!h.trim())return wt([]);let c=W(h,", ");return wt(c.map(l=>T(l.replace(/^\.\.\./,"").trim())))}if(n.startsWith("{")&&n.endsWith("}")){let h=n.slice(1,-1).trim(),c=new Map;if(h){let l=W(h,", ");for(let p of l){let u=p.match(/^\[(\w+):\s*\w+\]:\s*(.+)$/);if(u){c.set("[index]",T(u[2]));continue}let m=p.indexOf(":");if(m>=0){let x=p.slice(0,m).trim().replace(/^readonly\s+/,""),S=x.replace(/\?$/,""),N=x.endsWith("?"),f=T(p.slice(m+1).trim());c.set(S,N?C(f,v):f)}}}return at(c)}let a=n.match(/^(\w+)<(.+)>$/s);if(a){let h=a[1],l=W(a[2],", ").map(p=>T(p.trim()));switch(h){case"Array":case"List":case"ReadonlyArray":return z(l[0]||E);case"NonNullable":return Se(l[0]);case"Partial":return{kind:"utility",util:"Partial",inner:l[0]};case"Required":return{kind:"utility",util:"Required",inner:l[0]};case"Readonly":return l[0];case"Record":return se(l[0]||_,l[1]||E);case"Pick":return{kind:"utility",util:"Pick",inner:l[0],keys:l[1]};case"Omit":return{kind:"utility",util:"Omit",inner:l[0],keys:l[1]};case"Exclude":return{kind:"utility",util:"Exclude",inner:l[0],keys:l[1]};case"Extract":return{kind:"utility",util:"Extract",inner:l[0],keys:l[1]};case"ReturnType":return{kind:"utility",util:"ReturnType",inner:l[0]};case"InstanceType":return{kind:"utility",util:"InstanceType",inner:l[0]};case"Parameters":return{kind:"utility",util:"Parameters",inner:l[0]};case"Awaited":return{kind:"utility",util:"Awaited",inner:l[0]};case"Promise":return{kind:"generic",name:"Promise",args:l};case"Map":return{kind:"generic",name:"Map",args:l};case"Set":return{kind:"generic",name:"Set",args:l};case"WeakMap":return{kind:"generic",name:"WeakMap",args:l};default:return{kind:"generic",name:h,args:l}}}return Zt[n]?Zt[n]:y(n)}function Se(n){return n?n.kind==="union"?C(...n.members.filter(t=>t.kind!=="null"&&t.kind!=="void")):n.kind==="null"||n.kind==="void"?tt:n:E}function Ae(n,t){return B(n,t)}function B(n,t){if(!n||!t||t.kind==="any"||n.kind==="any"||n.kind==="never"||t.kind==="unknown"||n.kind==="void"&&t.kind==="void"||n.kind==="null"&&t.kind==="null"||n.kind==="never"&&t.kind==="never")return!0;if(n.kind==="null"&&t.kind==="union")return t.members.some(e=>e.kind==="null"||e.kind==="any"||e.kind==="void");if(n.kind==="union")return n.members.every(e=>B(e,t));if(t.kind==="union")return t.members.some(e=>B(n,e));if(n.kind==="intersection")return n.members.some(e=>B(e,t));if(t.kind==="intersection")return t.members.every(e=>B(n,e));if(n.kind==="primitive"&&t.kind==="primitive")return!!(n.name===t.name||t.name==="Number"&&["Int","Float","Number"].includes(n.name)||t.name==="Float"&&n.name==="Int"||n.name==="Bool"&&t.name==="Boolean"||n.name==="Boolean"&&t.name==="Bool");if(n.kind==="literal"&&t.kind==="primitive")return{string:"String",number:"Number",boolean:"Bool"}[n.prim]===t.name||n.prim==="number"&&["Int","Float","Number"].includes(t.name);if(n.kind==="named"&&t.kind==="named")return n.name===t.name||t.name==="Object";if(n.kind==="generic"&&t.kind==="generic"){let e=new Set(["Array","List","ReadonlyArray"]);return n.name!==t.name&&!(e.has(n.name)&&e.has(t.name))||n.args.length!==t.args.length?!1:n.args.every((s,r)=>B(s,t.args[r]))}if(n.kind==="tuple"&&t.kind==="tuple")return n.types.length!==t.types.length?!1:n.types.every((e,s)=>B(e,t.types[s]));if(n.kind==="generic"&&n.name==="Array"&&t.kind==="tuple"){let e=n.args[0]||E;return e.kind==="unknown"?!0:t.types.every(s=>B(e,s))}if(n.kind==="object"&&t.kind==="object"){for(let[e,s]of t.shape)if(!n.shape.has(e)||!B(n.shape.get(e),s))return!1;return!0}return n.kind==="object"&&t.kind==="named"?!0:n.kind==="fn"&&t.kind==="fn"?t.ret&&n.ret?B(n.ret,t.ret):!0:(n.kind==="fn"||t.kind==="fn")&&(n.kind==="fn"||t.kind==="fn")?!0:n.kind==="record"&&t.kind==="record"?B(n.val,t.val):n.kind==="generic"&&t.kind==="generic"||t.kind==="utility"||n.kind==="utility"}function nt(n,t){return!n||n.kind==="unknown"?t||E:!t||t.kind==="unknown"||g(n)===g(t)?n:n.kind==="any"||t.kind==="any"?D:C(n,t)}var St=class n{constructor(t=null){this.parent=t,this.vars=new Map,this.retType=t?t.retType:null,this.isAsync=t?t.isAsync:!1}set(t,e){this.vars.set(t,e)}has(t){let e=this;for(;e;){if(e.vars.has(t))return!0;e=e.parent}return!1}get(t){let e=this;for(;e;){if(e.vars.has(t))return e.vars.get(t);e=e.parent}return null}child(){return new n(this)}childFn(t,e=!1){let s=new n(this);return s.retType=t,s.isAsync=e,s}narrow(t,e){let s=new n(this);return t&&e&&s.vars.set(t,e),s}},ht=class{constructor(t,e,s=null){this.message=t,this.name="TypeError",this.hint=s,e&&(this.line=e.line,this.col=e.col)}},At=class{constructor(){this.errors=[],this.warnings=[],this.interfaces=new Map,this.types=new Map,this.classes=new Map,this.enums=new Map,this.typeAliases=new Map}check(t){this.errors=[],this.warnings=[],this.interfaces.clear(),this.types.clear(),this.classes.clear(),this.enums.clear(),this.typeAliases.clear(),this._collectDeclarations(t.body),this._validateImplementations();let e=new St;return this._registerBuiltins(e),this._checkStmts(t.body,e),{errors:this.errors,warnings:this.warnings}}_err(t,e,s=null){this.errors.push(new ht(t,e,s))}_warn(t,e,s=null){this.warnings.push(new ht(t,e,s))}_collectDeclarations(t){for(let e of t){let s=e.type==="ExportDecl"?e.decl:e;if(s)switch(s.type){case"InterfaceDecl":this.interfaces.set(s.name,s);break;case"TypeDecl":this.types.set(s.name,s);break;case"ClassDecl":this.classes.set(s.name,s);break;case"EnumDecl":this.enums.set(s.name,s);break}}}_validateImplementations(){for(let[,t]of this.classes)for(let e of t.interfaces||[])this._checkInterfaceImpl(t,e)}_checkInterfaceImpl(t,e){let s=this.interfaces.get(e);if(!s){this._warn(`Class '${t.name}' implements unknown interface '${e}'`,t.loc,`Define 'interface ${e}' before use`);return}for(let r of s.members)if(r.kind==="method")t.methods.find(h=>h.name===r.name)||this._err(`Class '${t.name}' does not implement method '${r.name}()' required by interface '${e}'`,t.loc,`Add 'fn ${r.name}(${r.params.map(h=>h.name+(h.typeAnn?": "+h.typeAnn:"")).join(", ")})' to the class`);else if(r.kind==="field"&&!r.optional){let a=t.fields.find(c=>c.name===r.name),h=t.methods.find(c=>c.name===r.name);!a&&!h&&this._err(`Class '${t.name}' is missing field '${r.name}' required by interface '${e}'`,t.loc,`Add '${r.name}: ${r.typeAnn}' to the class`)}for(let r of s.superInterfaces||[])this._checkInterfaceImpl(t,r)}_isStructurallyCompatible(t,e){let s=this.interfaces.get(e);if(!s){let r=this.classes.get(e);if(!r)return!1;for(let a of r.fields){if(!t.has(a.name)&&!a.optional)return!1;if(a.typeAnn&&t.has(a.name)){let h=T(a.typeAnn),c=t.get(a.name);if(!this._isAssignable(c,h))return!1}}return!0}for(let r of s.members)if(r.kind==="field"&&!r.optional){if(!t.has(r.name))return!1;if(r.typeAnn){let a=T(r.typeAnn),h=t.get(r.name);if(!this._isAssignable(h,a))return!1}}return!0}_isAssignable(t,e){if(!t||!e||e.kind==="any"||t.kind==="any"||t.kind==="never"||e.kind==="unknown")return!0;if(t.kind==="unknown")return!1;if(t.kind==="object"&&e.kind==="named")return this._isStructurallyCompatible(t.shape,e.name);if(t.kind==="object"&&e.kind==="object"){for(let[s,r]of e.shape)if(!t.shape.has(s)||!this._isAssignable(t.shape.get(s),r))return!1;return!0}if(t.kind==="named"&&e.kind==="named"){if(t.name===e.name||e.name==="Object")return!0;let s=this.classes.get(t.name);if(s&&(s.interfaces||[]).includes(e.name)||s&&s.superClass===e.name)return!0;let r=this.interfaces.get(t.name);return!!(r&&(r.superInterfaces||[]).includes(e.name))}if(e.kind==="utility")switch(e.util){case"Partial":return!0;case"Required":return this._isAssignable(t,e.inner);case"NonNullable":return t.kind!=="null"&&t.kind!=="void";default:return!0}return t.kind==="utility"?!0:B(t,e)}_analyzeNarrowingCondition(t,e){if(!t)return null;if(t.type==="BinaryExpr"&&(t.op==="!="||t.op==="!==")&&t.left.type==="Identifier"&&(t.right.type==="NullLit"||t.right.type==="Identifier"&&t.right.name==="undefined")){let s=t.left.name,r=e.get(s);if(r&&r.kind==="union"){let a=C(...r.members.filter(h=>h.kind!=="null"&&h.kind!=="void"));return{varName:s,trueType:a,falseType:C(j,v)}}}if(t.type==="BinaryExpr"&&(t.op==="=="||t.op==="===")&&t.left.type==="Identifier"&&t.right.type==="NullLit"){let s=t.left.name,r=e.get(s);if(r&&r.kind==="union"){let a=C(...r.members.filter(h=>h.kind!=="null"&&h.kind!=="void"));return{varName:s,trueType:j,falseType:a}}}if(t.type==="BinaryExpr"&&(t.op==="==="||t.op==="==")&&t.left.type==="TypeofExpr"&&t.left.operand.type==="Identifier"&&t.right.type==="StringLit"){let s=t.left.operand.name,r=t.right.value,h={string:_,number:L,boolean:P,object:y("Object"),function:R([],D),undefined:v,bigint:y("BigInt"),symbol:y("Symbol")}[r]||E;return{varName:s,trueType:h,falseType:e.get(s)||E}}if(t.type==="BinaryExpr"&&t.op==="instanceof"&&t.left.type==="Identifier"){let s=t.left.name,r=t.right.type==="Identifier"?t.right.name:null;if(r)return{varName:s,trueType:y(r),falseType:e.get(s)||E}}if(t.type==="Identifier"){let s=t.name,r=e.get(s);if(r&&r.kind==="union"){let a=C(...r.members.filter(h=>h.kind!=="null"&&h.kind!=="void"));return{varName:s,trueType:a,falseType:C(j,v)}}}return null}_registerBuiltins(t){t.set("console",y("Console")),t.set("process",y("Process")),t.set("Math",y("Math")),t.set("JSON",y("JSON")),t.set("Date",y("Date")),t.set("Promise",y("Promise")),t.set("Error",y("Error")),t.set("Buffer",y("Buffer")),t.set("RegExp",y("RegExp")),t.set("Map",y("Map")),t.set("Set",y("Set")),t.set("WeakMap",y("WeakMap")),t.set("WeakSet",y("WeakSet")),t.set("Symbol",y("Symbol")),t.set("Proxy",y("Proxy")),t.set("Reflect",y("Reflect")),t.set("setTimeout",R([R([],v),L],v)),t.set("setInterval",R([R([],v),L],v)),t.set("clearTimeout",D),t.set("clearInterval",D),t.set("parseInt",R([_,M],M)),t.set("parseFloat",R([_],Q)),t.set("isNaN",R([L],P)),t.set("isFinite",R([L],P)),t.set("require",R([_],D)),t.set("fetch",R([_],D)),t.set("print",R([],v)),t.set("undefined",v),t.set("Infinity",L),t.set("NaN",L),t.set("globalThis",y("Object")),t.set("Object",y("Object")),t.set("Array",y("Array")),t.set("String",y("String")),t.set("Number",y("Number")),t.set("Boolean",y("Boolean")),t.set("Function",y("Function"))}_checkStmts(t,e){for(let s of t)this._checkStmt(s,e)}_checkStmt(t,e){if(t)switch(t.type){case"VarDecl":{let s=t.typeAnn?T(t.typeAnn):null,r=null;t.init&&(r=this._inferType(t.init,e)),s&&r&&r.kind!=="unknown"&&(this._isAssignable(r,s)||this._err(`Type '${g(r)}' is not assignable to '${t.name}: ${g(s)}'`,t.loc,`Change the value to match '${g(s)}' or update the annotation`)),e.set(t.name,s||r||E);break}case"DestructureDecl":{let s=t.init?this._inferType(t.init,e):E;if(t.patternType==="object")for(let r of t.pattern){let a=E;s.kind==="object"&&s.shape.has(r.key)&&(a=s.shape.get(r.key)),e.set(r.alias,a)}else for(let r=0;r<t.pattern.length;r++){let a=t.pattern[r];if(!a)continue;let h=E;s.kind==="tuple"&&s.types[r]?h=s.types[r]:s.kind==="generic"&&s.name==="Array"&&(h=s.args[0]||E),e.set(a.name,h)}break}case"FnDecl":{let s=t.retType?T(t.retType):null,r=t.params.map(h=>h.typeAnn?T(h.typeAnn):E);t.name&&e.set(t.name,R(r,s||E));let a=e.childFn(s,t.async);for(let h=0;h<t.params.length;h++)a.set(t.params[h].name,r[h]);if(t.inline){let h=this._inferType(t.body,a);s&&h&&h.kind!=="unknown"&&(this._isAssignable(h,s)||this._err(`Function '${t.name||"(anon)"}' returns '${g(h)}' but declared '${g(s)}'`,t.loc,"Fix return type or update the annotation"))}else this._checkStmts(t.body,a);break}case"ClassDecl":{e.set(t.name,y(t.name));let s=e.child(),r=new Map;for(let a of t.fields){let h=a.typeAnn?T(a.typeAnn):E;s.set(a.name,h),r.set(a.name,h)}s.set("self",at(r));for(let a of t.methods)this._checkStmt(a,s);break}case"TypeDecl":for(let s of t.variants)s.fields.length===0?e.set(s.name,y(t.name)):e.set(s.name,R(s.fields.map(()=>D),y(t.name)));break;case"InterfaceDecl":e.set(t.name,y(t.name));break;case"EnumDecl":e.set(t.name,y(t.name));break;case"IfStmt":{this._inferType(t.cond,e);let s=this._analyzeNarrowingCondition(t.cond,e),r=s?e.narrow(s.varName,s.trueType):e.child(),a=s?e.narrow(s.varName,s.falseType):e.child();this._checkStmts(t.then,r);for(let h of t.elseifs)this._inferType(h.cond,e),this._checkStmts(h.body,e.child());t.else_&&this._checkStmts(t.else_,a);break}case"ForInStmt":{let s=this._inferType(t.iter,e),r=e.child();s.kind==="generic"&&s.args.length>0?r.set(t.var,s.args[0]):s.kind==="tuple"&&s.types.length>0?r.set(t.var,C(...s.types)):r.set(t.var,E),this._checkStmts(t.body,r);break}case"WhileStmt":this._inferType(t.cond,e),this._checkStmts(t.body,e.child());break;case"DoWhileStmt":this._checkStmts(t.body,e.child()),this._inferType(t.cond,e);break;case"MatchStmt":this._inferType(t.subject,e);for(let s of t.arms){let r=e.child();if(s.pattern.type==="VariantPat")for(let a of s.pattern.bindings)r.set(a,E);s.guard&&this._inferType(s.guard,r),this._checkStmts(s.body,r)}break;case"ReturnStmt":{let s=e.retType;if(t.value){let r=this._inferType(t.value,e);if(s&&r&&r.kind!=="unknown"&&s.kind!=="unknown"){let a=e.isAsync&&s.kind==="generic"&&s.name==="Promise"?s.args[0]:s;this._isAssignable(r,a)||this._err(`Return type '${g(r)}' is not assignable to declared '${g(a)}'`,t.loc,"Fix return expression or update return type annotation")}}else s&&s.kind!=="void"&&s.kind!=="any"&&s.kind!=="unknown"&&this._warn(`Missing return value \u2014 function declares return type '${g(s)}'`,t.loc);break}case"ThrowStmt":this._inferType(t.value,e);break;case"TryCatchStmt":{if(this._checkStmts(t.tryBody,e.child()),t.catchBody){let s=e.child();t.catchParam&&s.set(t.catchParam,C(y("Error"),E)),this._checkStmts(t.catchBody,s)}t.finallyBody&&this._checkStmts(t.finallyBody,e.child());break}case"ImportDecl":t.defaultName&&e.set(t.defaultName,D),t.namespaceName&&e.set(t.namespaceName,D);for(let s of t.names)e.set(typeof s=="string"?s:s.alias,D);break;case"ExportDecl":this._checkStmt(t.decl,e);break;case"ExprStmt":this._inferType(t.expr,e);break;case"BreakStmt":case"ContinueStmt":break}}_inferType(t,e){if(!t)return v;switch(t.type){case"NumberLit":return Number.isInteger(t.value)?M:Q;case"StringLit":case"TemplateLit":return _;case"BoolLit":return P;case"NullLit":return j;case"RegexLit":return D;case"SelfExpr":return e.get("self")||E;case"Identifier":{let s=e.get(t.name);return s||(this.classes.has(t.name)||this.enums.has(t.name)||this.interfaces.has(t.name)?y(t.name):E)}case"ArrayExpr":{if(!t.items||t.items.length===0)return z(E);let s=t.items.filter(r=>r&&r.type!=="SpreadExpr").map(r=>this._inferType(r,e));return z(s.reduce(nt,E))}case"ObjectExpr":{let s=new Map;for(let r of t.pairs||[])r.spread||s.set(String(r.key),this._inferType(r.value,e));return at(s)}case"NewExpr":for(let s of t.args)this._inferType(s,e);return y(t.callee);case"CallExpr":{let s=this._inferType(t.callee,e);for(let r of t.args)this._inferType(r,e);return s&&s.kind==="fn"?(this._checkCallArgs(t,s,e),s.ret||E):E}case"OptCallExpr":this._inferType(t.callee,e);for(let s of t.args)this._inferType(s,e);return E;case"MemberExpr":case"OptMemberExpr":{let s=this._inferType(t.obj,e);return s.kind==="object"&&s.shape.has(t.prop)?s.shape.get(t.prop):E}case"IndexExpr":case"OptIndexExpr":{let s=this._inferType(t.obj,e);return this._inferType(t.idx,e),s.kind==="generic"&&s.args.length>0?s.args[0]:s.kind==="tuple"?C(...s.types):s.kind==="record"?s.val:E}case"BinaryExpr":{let s=this._inferType(t.left,e),r=this._inferType(t.right,e),a=t.op;if(["+","-","*","/","%","**"].includes(a)){if(s.kind==="primitive"&&s.name==="String"||r.kind==="primitive"&&r.name==="String")return _;if(s.kind==="unknown"||r.kind==="unknown")return E;if(s.kind==="any"||r.kind==="any")return L;if(s.kind==="primitive"&&r.kind==="primitive"){let h=s.name,c=r.name;if(h==="Int"&&c==="Int")return M;if(["Float","Int"].includes(h)&&["Float","Int"].includes(c))return Q}return L}return["===","!==","==","!=","<","<=",">",">=","&&","||","instanceof","in"].includes(a)?P:a==="??"?nt(s,r):["&","|","^","<<",">>"].includes(a)?M:E}case"UnaryExpr":{let s=this._inferType(t.operand,e);return t.op==="!"||t.op==="not"?P:t.op==="-"?s.kind==="primitive"&&s.name==="Int"?M:s.kind==="primitive"&&s.name==="Float"?Q:L:t.op==="~"?M:s}case"UpdateExpr":return this._inferType(t.operand,e),L;case"TernaryExpr":{let s=this._analyzeNarrowingCondition(t.cond,e),r=s?e.narrow(s.varName,s.trueType):e,a=s?e.narrow(s.varName,s.falseType):e;this._inferType(t.cond,e);let h=this._inferType(t.then,r),c=this._inferType(t.else_,a);return nt(h,c)}case"AssignExpr":{let s=this._inferType(t.value,e),r=this._inferType(t.target,e);return r&&r.kind!=="unknown"&&s&&s.kind!=="unknown"&&(this._isAssignable(s,r)||this._err(`Cannot assign '${g(s)}' to type '${g(r)}'`,t.target.loc||t.loc,"Ensure the value matches the declared type")),s}case"AwaitExpr":{let s=this._inferType(t.operand,e);return s.kind==="generic"&&s.name==="Promise"&&s.args[0]||E}case"TypeofExpr":return this._inferType(t.operand,e),_;case"PipeExpr":return this._inferType(t.left,e),this._inferType(t.right,e);case"SpreadExpr":return this._inferType(t.expr,e),E;case"RangeExpr":return this._inferType(t.start,e),this._inferType(t.end,e),z(M);case"LambdaExpr":{let s=e.child();for(let h of t.params)s.set(h.name,h.typeAnn?T(h.typeAnn):E);let r=this._inferType(t.body,s),a=t.params.map(h=>h.typeAnn?T(h.typeAnn):E);return R(a,r)}case"FnDecl":{let s=t.retType?T(t.retType):null,r=e.childFn(s,t.async);for(let h of t.params||[])r.set(h.name,h.typeAnn?T(h.typeAnn):E);let a=(t.params||[]).map(h=>h.typeAnn?T(h.typeAnn):E);if(t.inline){let h=this._inferType(t.body,r);return R(a,s||h)}return this._checkStmts(t.body,r),R(a,s||E)}case"CastExpr":return this._inferType(t.expr,e),t.castType?T(t.castType):D;case"SatisfiesExpr":case"NonNullExpr":case"AsConstExpr":{let s=this._inferType(t.expr,e);if(t.type==="SatisfiesExpr"&&t.satType){let r=T(t.satType);this._isAssignable(s,r)||this._err(`Type '${g(s)}' does not satisfy '${g(r)}'`,t.loc)}return s}case"IsExpr":return this._inferType(t.expr,e),P;default:return E}}_checkCallArgs(t,e,s){let r=t.args||[],a=e.params||[];for(let h=0;h<r.length;h++){let c=this._inferType(r[h],s),l=a[h]||D;l.kind!=="any"&&c&&c.kind!=="unknown"&&(this._isAssignable(c,l)||this._err(`Argument ${h+1}: '${g(c)}' is not assignable to '${g(l)}'`,t.loc,"Check function signature"))}}};ie.exports={FluxTypeChecker:At,parseAnnotation:T,typeStr:g,isAssignable:Ae,mergeTypes:nt,splitAtTopLevel:W,T_ANY:D,T_UNKNOWN:E,T_NEVER:tt,T_VOID:v,T_NULL:j,T_STRING:_,T_INT:M,T_FLOAT:Q,T_NUMBER:L,T_BOOL:P,T_UNION:C,T_INTERSECTION:te,T_ARRAY:z,T_TUPLE:wt,T_NULLABLE:ee,T_NAMED:y,T_FN:R,T_OBJECT:at,T_RECORD:se,T_LITERAL:we}});var Rt=F((ys,ne)=>{"use strict";var ct=["range","zip","enumerate","clamp","sum","product","flatten","chunk","unique","groupBy","sortBy","pick","omit","deepEqual","deepClone","sleep","retry","memoize","pipe","compose","partial","curry","capitalize","camelCase","snakeCase","kebabCase","truncate","pad","randInt","sample","shuffle","mapValues","filterValues","fromEntries","map","filter","reduce","forEach","find","findIndex","some","every","join","sort","flat","flatMap","includes"];function Re(n){let t=n?new Set(n.filter(s=>ct.includes(s))):new Set(ct);if(t.size===0)return"";let e=["// \u2500\u2500 Flux stdlib \u2500\u2500"];return t.has("map")&&e.push(`
|
|
65
|
+
function map(arr, fn) { return arr.map(fn); }`),t.has("filter")&&e.push(`
|
|
66
|
+
function filter(arr, fn) { return arr.filter(fn); }`),t.has("reduce")&&e.push(`
|
|
67
|
+
function reduce(arr, fn, init) { return arguments.length >= 3 ? arr.reduce(fn, init) : arr.reduce(fn); }`),t.has("forEach")&&e.push(`
|
|
68
|
+
function forEach(arr, fn) { arr.forEach(fn); return arr; }`),t.has("find")&&e.push(`
|
|
69
|
+
function find(arr, fn) { return arr.find(fn); }`),t.has("findIndex")&&e.push(`
|
|
70
|
+
function findIndex(arr, fn) { return arr.findIndex(fn); }`),t.has("some")&&e.push(`
|
|
71
|
+
function some(arr, fn) { return arr.some(fn); }`),t.has("every")&&e.push(`
|
|
72
|
+
function every(arr, fn) { return arr.every(fn); }`),t.has("join")&&e.push(`
|
|
73
|
+
function join(arr, sep) { return arr.join(sep != null ? sep : ','); }`),t.has("sort")&&e.push(`
|
|
74
|
+
function sort(arr, fn) { return arr.slice().sort(fn); }`),t.has("flat")&&e.push(`
|
|
75
|
+
function flat(arr, depth) { return arr.flat(depth != null ? depth : 1); }`),t.has("flatMap")&&e.push(`
|
|
76
|
+
function flatMap(arr, fn) { return arr.flatMap(fn); }`),t.has("includes")&&e.push(`
|
|
77
|
+
function includes(arr, val) { return arr.includes(val); }`),t.has("range")&&e.push(`
|
|
78
|
+
function range(start, end, step) {
|
|
79
|
+
if (arguments.length === 1) { end = start; start = 0; }
|
|
80
|
+
step = step || (end >= start ? 1 : -1);
|
|
81
|
+
const out = [];
|
|
82
|
+
if (step > 0) { for (let i = start; i < end; i += step) out.push(i); }
|
|
83
|
+
else { for (let i = start; i > end; i += step) out.push(i); }
|
|
84
|
+
return out;
|
|
85
|
+
}`),t.has("zip")&&e.push(`
|
|
86
|
+
function zip() {
|
|
87
|
+
const arrays = Array.from(arguments);
|
|
88
|
+
const len = Math.min.apply(null, arrays.map(function(a) { return a.length; }));
|
|
89
|
+
const out = [];
|
|
90
|
+
for (let i = 0; i < len; i++) out.push(arrays.map(function(a) { return a[i]; }));
|
|
91
|
+
return out;
|
|
92
|
+
}`),t.has("enumerate")&&e.push(`
|
|
93
|
+
function enumerate(arr, start) {
|
|
94
|
+
start = start || 0;
|
|
95
|
+
return arr.map(function(v, i) { return [i + start, v]; });
|
|
96
|
+
}`),t.has("flatten")&&e.push(`
|
|
97
|
+
function flatten(arr, depth) {
|
|
98
|
+
return depth == null ? arr.flat(Infinity) : arr.flat(depth);
|
|
99
|
+
}`),t.has("chunk")&&e.push(`
|
|
100
|
+
function chunk(arr, size) {
|
|
101
|
+
const out = [];
|
|
102
|
+
for (let i = 0; i < arr.length; i += size) out.push(arr.slice(i, i + size));
|
|
103
|
+
return out;
|
|
104
|
+
}`),t.has("unique")&&e.push(`
|
|
105
|
+
function unique(arr) {
|
|
106
|
+
return Array.from(new Set(arr));
|
|
107
|
+
}`),t.has("groupBy")&&e.push(`
|
|
108
|
+
function groupBy(arr, fn) {
|
|
109
|
+
return arr.reduce(function(acc, v) {
|
|
110
|
+
var k = typeof fn === 'function' ? fn(v) : v[fn];
|
|
111
|
+
(acc[k] = acc[k] || []).push(v);
|
|
112
|
+
return acc;
|
|
113
|
+
}, {});
|
|
114
|
+
}`),t.has("sortBy")&&e.push(`
|
|
115
|
+
function sortBy(arr, fn) {
|
|
116
|
+
return arr.slice().sort(function(a, b) {
|
|
117
|
+
var ka = typeof fn === 'function' ? fn(a) : a[fn];
|
|
118
|
+
var kb = typeof fn === 'function' ? fn(b) : b[fn];
|
|
119
|
+
return ka < kb ? -1 : ka > kb ? 1 : 0;
|
|
120
|
+
});
|
|
121
|
+
}`),t.has("clamp")&&e.push(`
|
|
122
|
+
function clamp(val, min, max) {
|
|
123
|
+
return Math.min(Math.max(val, min), max);
|
|
124
|
+
}`),t.has("sum")&&e.push(`
|
|
125
|
+
function sum(arr) {
|
|
126
|
+
return arr.reduce(function(a, b) { return a + b; }, 0);
|
|
127
|
+
}`),t.has("product")&&e.push(`
|
|
128
|
+
function product(arr) {
|
|
129
|
+
return arr.reduce(function(a, b) { return a * b; }, 1);
|
|
130
|
+
}`),t.has("randInt")&&e.push(`
|
|
131
|
+
function randInt(min, max) {
|
|
132
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
133
|
+
}`),t.has("sample")&&e.push(`
|
|
134
|
+
function sample(arr) {
|
|
135
|
+
return arr[Math.floor(Math.random() * arr.length)];
|
|
136
|
+
}`),t.has("shuffle")&&e.push(`
|
|
137
|
+
function shuffle(arr) {
|
|
138
|
+
var a = arr.slice();
|
|
139
|
+
for (var i = a.length - 1; i > 0; i--) {
|
|
140
|
+
var j = Math.floor(Math.random() * (i + 1));
|
|
141
|
+
var tmp = a[i]; a[i] = a[j]; a[j] = tmp;
|
|
142
|
+
}
|
|
143
|
+
return a;
|
|
144
|
+
}`),t.has("pick")&&e.push(`
|
|
145
|
+
function pick(obj, keys) {
|
|
146
|
+
var out = {};
|
|
147
|
+
keys.forEach(function(k) { if (Object.prototype.hasOwnProperty.call(obj, k)) out[k] = obj[k]; });
|
|
148
|
+
return out;
|
|
149
|
+
}`),t.has("omit")&&e.push(`
|
|
150
|
+
function omit(obj, keys) {
|
|
151
|
+
var ks = new Set(keys);
|
|
152
|
+
var out = {};
|
|
153
|
+
Object.keys(obj).forEach(function(k) { if (!ks.has(k)) out[k] = obj[k]; });
|
|
154
|
+
return out;
|
|
155
|
+
}`),t.has("mapValues")&&e.push(`
|
|
156
|
+
function mapValues(obj, fn) {
|
|
157
|
+
var out = {};
|
|
158
|
+
Object.keys(obj).forEach(function(k) { out[k] = fn(obj[k], k); });
|
|
159
|
+
return out;
|
|
160
|
+
}`),t.has("filterValues")&&e.push(`
|
|
161
|
+
function filterValues(obj, fn) {
|
|
162
|
+
var out = {};
|
|
163
|
+
Object.keys(obj).forEach(function(k) { if (fn(obj[k], k)) out[k] = obj[k]; });
|
|
164
|
+
return out;
|
|
165
|
+
}`),t.has("fromEntries")&&e.push(`
|
|
166
|
+
function fromEntries(entries) {
|
|
167
|
+
return Object.fromEntries(entries);
|
|
168
|
+
}`),t.has("deepEqual")&&e.push(`
|
|
169
|
+
function deepEqual(a, b) {
|
|
170
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
171
|
+
}`),t.has("deepClone")&&e.push(`
|
|
172
|
+
function deepClone(v) {
|
|
173
|
+
return JSON.parse(JSON.stringify(v));
|
|
174
|
+
}`),t.has("sleep")&&e.push(`
|
|
175
|
+
function sleep(ms) {
|
|
176
|
+
return new Promise(function(resolve) { setTimeout(resolve, ms); });
|
|
177
|
+
}`),t.has("retry")&&e.push(`
|
|
178
|
+
async function retry(fn, attempts, delay) {
|
|
179
|
+
attempts = attempts || 3;
|
|
180
|
+
delay = delay || 300;
|
|
181
|
+
for (var i = 0; i < attempts; i++) {
|
|
182
|
+
try { return await fn(); } catch(e) {
|
|
183
|
+
if (i === attempts - 1) throw e;
|
|
184
|
+
await sleep(delay * Math.pow(2, i));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}`),t.has("memoize")&&e.push(`
|
|
188
|
+
function memoize(fn) {
|
|
189
|
+
var cache = new Map();
|
|
190
|
+
return function() {
|
|
191
|
+
var key = JSON.stringify(arguments);
|
|
192
|
+
if (cache.has(key)) return cache.get(key);
|
|
193
|
+
var result = fn.apply(this, arguments);
|
|
194
|
+
cache.set(key, result);
|
|
195
|
+
return result;
|
|
196
|
+
};
|
|
197
|
+
}`),t.has("pipe")&&e.push(`
|
|
198
|
+
function pipe() {
|
|
199
|
+
var fns = Array.from(arguments);
|
|
200
|
+
return function(x) { return fns.reduce(function(v, f) { return f(v); }, x); };
|
|
201
|
+
}`),t.has("compose")&&e.push(`
|
|
202
|
+
function compose() {
|
|
203
|
+
var fns = Array.from(arguments);
|
|
204
|
+
return function(x) { return fns.reduceRight(function(v, f) { return f(v); }, x); };
|
|
205
|
+
}`),t.has("partial")&&e.push(`
|
|
206
|
+
function partial(fn) {
|
|
207
|
+
var args = Array.from(arguments).slice(1);
|
|
208
|
+
return function() { return fn.apply(this, args.concat(Array.from(arguments))); };
|
|
209
|
+
}`),t.has("curry")&&e.push(`
|
|
210
|
+
function curry(fn) {
|
|
211
|
+
return function curried() {
|
|
212
|
+
var args = Array.from(arguments);
|
|
213
|
+
if (args.length >= fn.length) return fn.apply(this, args);
|
|
214
|
+
return function() { return curried.apply(this, args.concat(Array.from(arguments))); };
|
|
215
|
+
};
|
|
216
|
+
}`),t.has("capitalize")&&e.push(`
|
|
217
|
+
function capitalize(s) {
|
|
218
|
+
return s ? s[0].toUpperCase() + s.slice(1) : s;
|
|
219
|
+
}`),t.has("camelCase")&&e.push(`
|
|
220
|
+
function camelCase(s) {
|
|
221
|
+
return s.replace(/[-_\\s]+(.)/g, function(_, c) { return c.toUpperCase(); }).replace(/^./, function(c) { return c.toLowerCase(); });
|
|
222
|
+
}`),t.has("snakeCase")&&e.push(`
|
|
223
|
+
function snakeCase(s) {
|
|
224
|
+
return s.replace(/([A-Z])/g, function(c) { return '_' + c.toLowerCase(); }).replace(/[-\\s]+/g, '_').replace(/^_/, '');
|
|
225
|
+
}`),t.has("kebabCase")&&e.push(`
|
|
226
|
+
function kebabCase(s) {
|
|
227
|
+
return s.replace(/([A-Z])/g, function(c) { return '-' + c.toLowerCase(); }).replace(/[_\\s]+/g, '-').replace(/^-/, '');
|
|
228
|
+
}`),t.has("truncate")&&e.push(`
|
|
229
|
+
function truncate(s, len, suffix) {
|
|
230
|
+
suffix = suffix != null ? suffix : '...';
|
|
231
|
+
if (s.length <= len) return s;
|
|
232
|
+
// FIX: guard against suffix longer than len to avoid negative slice index
|
|
233
|
+
var cut = len - suffix.length;
|
|
234
|
+
if (cut <= 0) return suffix.slice(0, len);
|
|
235
|
+
return s.slice(0, cut) + suffix;
|
|
236
|
+
}`),t.has("pad")&&e.push(`
|
|
237
|
+
function pad(s, len, char) {
|
|
238
|
+
char = char || ' ';
|
|
239
|
+
s = String(s);
|
|
240
|
+
var total = len - s.length;
|
|
241
|
+
if (total <= 0) return s;
|
|
242
|
+
var half = Math.floor(total / 2);
|
|
243
|
+
return char.repeat(half) + s + char.repeat(total - half);
|
|
244
|
+
}`),e.push(`// \u2500\u2500 end stdlib \u2500\u2500
|
|
245
|
+
`),e.join(`
|
|
246
|
+
`)}function Ie(n){return ct.filter(t=>new RegExp(`\\b${t}\\s*\\(`,"g").test(n))}ne.exports={buildStdlib:Re,detectUsedSymbols:Ie,STDLIB_SYMBOLS:ct}});var he=F((Es,ae)=>{"use strict";var{Lexer:Oe}=H(),{Parser:De}=K(),{CodeGenerator:$e}=yt(),{SourceMapBuilder:ve}=Bt(),{transformJsx:Le}=Qt(),{Mangler:_e}=Ht(),{transformCss:Ce}=qt(),{Checker:Fe}=Xt(),{FluxTypeChecker:Be}=re(),{buildStdlib:Pe,detectUsedSymbols:Me}=Rt();function je(n,t={}){let e={success:!1,output:"",sourceMap:null,ast:null,tokens:null,errors:[],typeErrors:[],typeWarnings:[],stage:null,nameMap:null};try{e.stage="css";let s=Ce(n);e.stage="jsx";let r=t.jsxTarget||"browser",a=t.jsx!==!1,h=s,c="";if(a){let k=Le(s,{target:r});h=k.source,c=k.hasJsx?k.runtimeHelpers:""}e.stage="lexer";let l=new Oe(h).tokenize();e.tokens=l,e.stage="parser";let p=new De(l).parse();if(e.ast=p,t.check){e.stage="checker";let A=new Fe().check(p);if(A.errors.length>0)return e.errors=A.errors,e.stage=null,e;e.typeWarnings=[...e.typeWarnings||[],...A.warnings]}if(t.typecheck!==!1){e.stage="typecheck";let A=new Be().check(p);e.typeErrors=A.errors,e.typeWarnings=[...e.typeWarnings||[],...A.warnings]}let u=p;if(t.mangle){e.stage="mangler";let k=new _e;u=k.mangle(p),e.nameMap=k.getMap()}e.stage="codegen";let m={indent:t.mangle?"":" "};t.sourcemap&&(m.smBuilder=new ve(t.sourceFile||"source.flux",n));let{code:x,smBuilder:S}=new $e(m).generate(u),N=t.stdlib!==!1,f="";if(N){let k=Me(x);k.length>0&&(f=Pe(k)+`
|
|
247
|
+
`)}let d=c?`// Flux JSX Runtime
|
|
248
|
+
"use strict";
|
|
249
|
+
${c}
|
|
250
|
+
`:"",w=c?x.replace(/^\/\/ Generated.*\n"use strict";\n/,""):x,b;if(S){let k=t.outputFile||"output.js",A=k+".map";e.sourceMap=S.toString(k),b=d+f+w+`
|
|
251
|
+
//# sourceMappingURL=${A}
|
|
252
|
+
`}else b=d+f+w;if(t.mangle){let k=b.split(`
|
|
253
|
+
`).map($=>$.trim()).filter($=>$.length>0),A=[],I=[];for(let $ of k)$.startsWith("//")&&I.length===0?A.push($):I.push($);b=[...A,I.join(" ")].join(`
|
|
254
|
+
`)}e.output=b,e.success=!0,e.stage=null}catch(s){e.errors.push({message:s.message,name:s.name,stage:e.stage,line:s.tok?s.tok.line:s.line||null,col:s.tok?s.tok.col:s.col||null,len:s.tok&&s.tok.value?String(s.tok.value).length:1,hint:s.hint||null})}return e}ae.exports={transpile:je}});var le=F((ks,ce)=>{"use strict";function Ue(n){let t=n.replace(/\r\n/g,`
|
|
255
|
+
`).replace(/\r/g,`
|
|
256
|
+
`).split(`
|
|
257
|
+
`),e=4;for(let l of t){let p=l.match(/^( +)\S/);if(p){let u=p[1].length;u>0&&u<e&&(e=u);break}}e<1&&(e=4);let s=t.map(l=>{let p=l.trimEnd();if(!p)return"";let u=p.match(/^( *)/),m=u?u[1].length:0,x=Math.round(m/e),S=p.trimStart(),N=S.startsWith("//")||S.startsWith("*")?S:We(S);return" ".repeat(x)+N}),r=[],a=0;for(let l of s)l===""?(a++,a<=1&&r.push("")):(a=0,r.push(l));let h=[];for(let l=0;l<r.length;l++){h.push(r[l]);let p=r[l].trimStart(),u=(r[l+1]||"").trimStart(),m=r[l].match(/^( *)/)[1].length;m<=4&&/^(fn |async fn |class |type )/.test(p)&&u!==""&&/^(fn |async fn |class |type )/.test(u),l>0&&r[l-1].match(/^( *)/)[1].length>=4&&m===0&&p!==""&&h[h.length-2]!==""&&h.splice(h.length-1,0,"")}let c=h;for(;c.length>0&&c[0]==="";)c.shift();for(;c.length>0&&c[c.length-1]==="";)c.pop();return c.push(""),c.join(`
|
|
258
|
+
`)}function We(n){if((n.match(/:/g)||[]).length>2)return n;let t=n;return t=t.replace(/([^=!<>+\-*/%])=(?!=|>)/g,"$1 = "),t=t.replace(/\s{2,}=/g," ="),t=t.replace(/([^\s]) +/g,"$1 "),t=t.replace(/,(?!\s)/g,", "),t=t.replace(/\s*->\s*/g," -> "),t=t.replace(/\s*=>\s*/g," => "),t=t.trimEnd(),t}function Qe(n,t){let e=n.split(`
|
|
259
|
+
`),s=t.split(`
|
|
260
|
+
`),r=[],a=Math.max(e.length,s.length);for(let h=0;h<a;h++){let c=e[h],l=s[h];c!==l&&r.push({line:h+1,original:c,formatted:l})}return r}ce.exports={format:Ue,diff:Qe}});var fe=F((ds,ue)=>{"use strict";var oe=require("fs"),V=require("path"),{Lexer:Ve}=H(),{Parser:He}=K(),{CodeGenerator:ze}=yt(),G=class extends Error{constructor(t,e){super(e?`[${V.basename(e)}] ${t}`:t),this.name="BundleError",this.file=e}};function Ge(n,t){let e=[],s=[],r=[],a=V.dirname(t);for(let h of n.body)if(h.type==="ImportDecl"){let c=h.source;c.endsWith(".flux")||(c+=".flux");let l=V.resolve(a,c);e.push({names:h.names,source:h.source,absPath:l})}else if(h.type==="ExportDecl"){let c=h.decl;c.type==="FnDecl"&&s.push(c.name),c.type==="ClassDecl"&&s.push(c.name),c.type==="VarDecl"&&s.push(c.name),r.push(c)}else r.push(h);return{cleanAst:{type:"Program",body:r},imports:e,exports:s}}function Ke(n){let{code:t}=new ze({indent:" "}).generate(n),e=t.split(`
|
|
261
|
+
`),s=e.findIndex(r=>r.trim()!==""&&!r.includes("Dihasilkan")&&!r.includes('"use strict"'));return e.slice(s).join(`
|
|
262
|
+
`)}function pe(n){return"_flux_"+V.basename(n,".flux").replace(/[^a-zA-Z0-9]/g,"_")}var lt=class{constructor(t,e={}){this.entryFile=V.resolve(t),this.options=e,this.modules=new Map,this.order=[],this.visited=new Set,this.inStack=new Set}bundle(){return this.collect(this.entryFile),this.link()}collect(t){if(this.visited.has(t))return;if(this.inStack.has(t))throw new G(`Dependensi sirkular terdeteksi: ${t}`,t);if(!oe.existsSync(t))throw new G(`File tidak ditemukan: ${t}`,t);this.inStack.add(t);let e=oe.readFileSync(t,"utf8"),s;try{let c=new Ve(e).tokenize();s=new He(c).parse()}catch(c){throw new G(`Error saat parsing: ${c.message}`,t)}let{cleanAst:r,imports:a,exports:h}=Ge(s,t);this.modules.set(t,{cleanAst:r,imports:a,exports:h,source:e,absPath:t});for(let c of a)this.collect(c.absPath);this.inStack.delete(t),this.visited.add(t),this.order.push(t)}link(){let t=[];this.options.banner!==!1&&(t.push("// Dihasilkan oleh Flux Bundler"),t.push(`// Entry: ${V.basename(this.entryFile)}`),t.push(`// Modul: ${this.order.length}`),t.push('"use strict";'),t.push("")),t.push("(function() {"),t.push("");for(let s of this.order){let{cleanAst:r,imports:a,exports:h}=this.modules.get(s),c=s===this.entryFile,l=pe(s),p=V.relative(process.cwd(),s);t.push(` // ${"\u2500".repeat(60)}`),t.push(` // Modul: ${p}`),t.push(` // ${"\u2500".repeat(60)}`),c||(t.push(` var ${l} = (function() {`),t.push(" var _exports = {};"),t.push(""));for(let m of a){let x=pe(m.absPath);if(m.names.length===1)t.push(` var ${m.names[0]} = ${x};`);else for(let S of m.names)t.push(` var ${S} = ${x}._exports ? ${x}._exports.${S} : ${x}.${S};`)}a.length>0&&t.push("");let u=Ke(r);if(t.push(u),!c){if(h.length>0){t.push("");for(let m of h)t.push(` _exports.${m} = ${m};`)}t.push(""),t.push(" return _exports;"),t.push(" })()"),t.push(` ${l}._exports = ${l};`)}t.push("")}return t.push("})();"),{code:t.join(`
|
|
263
|
+
`),modules:this.order.length}}};function Ye(n,t={}){let e={success:!1,code:"",modules:0,errors:[]};try{let s=new lt(n,t),{code:r,modules:a}=s.bundle();e.code=r,e.modules=a,e.success=!0}catch(s){e.errors.push({message:s.message,name:s.name,file:s.file||null})}return e}ue.exports={bundle:Ye,Bundler:lt,BundleError:G}});var{transpile:qe}=he(),{format:Je}=le(),{buildStdlib:Xe,detectUsedSymbols:Ze,STDLIB_SYMBOLS:ts}=Rt(),{Lexer:es}=H(),{Parser:ss}=K(),{bundle:is}=fe();module.exports={transpile:qe,format:Je,buildStdlib:Xe,detectUsedSymbols:Ze,STDLIB_SYMBOLS:ts,Lexer:es,Parser:ss,bundle:is};
|