@xnoxs/flux-lang 4.0.8 → 4.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/dist/flux.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * flux-lang v4.0.8
2
+ * flux-lang v4.0.3
3
3
  * Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.
4
4
  * (c) 2026 Flux Lang Contributors
5
5
  * Released under the MIT License
@@ -1461,7 +1461,7 @@ var require_parser = __commonJS({
1461
1461
  this.pos++;
1462
1462
  if (!this.at(T.IDENT, T.LBRACKET, T.LBRACE, T.LPAREN, T.FN, T.READONLY, T.TYPEOF)) return false;
1463
1463
  this.parseTypeAnn();
1464
- return this.check(T.NEWLINE) || this.check(T.EOF);
1464
+ return this.check(T.NEWLINE) || this.check(T.EOF) || this.check(T.COLON);
1465
1465
  } catch (_) {
1466
1466
  return false;
1467
1467
  } finally {
@@ -1500,6 +1500,7 @@ var require_parser = __commonJS({
1500
1500
  if (this._isColonReturnType()) {
1501
1501
  this.pos++;
1502
1502
  retType = this.parseTypeAnn();
1503
+ if (this.check(T.COLON)) this.pos++;
1503
1504
  if (this.check(T.NEWLINE)) this.pos++;
1504
1505
  if (this.check(T.INDENT)) {
1505
1506
  this.pos++;
package/dist/flux.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * flux-lang v4.0.8
2
+ * flux-lang v4.0.1
3
3
  * Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.
4
4
  * (c) 2026 Flux Lang Contributors
5
5
  * Released under the MIT License
@@ -283,7 +283,7 @@ var require_lexer = __commonJS({
283
283
  if (this.ch() === "\\") {
284
284
  this.adv();
285
285
  const e = this.adv();
286
- s += { n: "\n", t: " ", "`": "`", "\\": "\\" }[e] || "\\" + e;
286
+ s += { n: "\n", t: " ", "`": "`", "\\": "\\" }[e] || "\\" + e;
287
287
  } else {
288
288
  s += this.adv();
289
289
  }
@@ -319,7 +319,7 @@ var require_lexer = __commonJS({
319
319
  this.pos += 2;
320
320
  text += String.fromCharCode(parseInt(hex, 16));
321
321
  } else {
322
- text += { n: "\n", t: " ", r: "\r", '"': '"', "'": "'", "\\": "\\", "{": "{", "}": "}" }[e] || "\\" + e;
322
+ text += { n: "\n", t: " ", r: "\r", '"': '"', "'": "'", "\\": "\\", "{": "{", "}": "}" }[e] || "\\" + e;
323
323
  }
324
324
  } else if (this.ch() === "{") {
325
325
  parts.push({ type: "text", value: text });
@@ -407,8 +407,8 @@ var require_lexer = __commonJS({
407
407
  if (bol) {
408
408
  bol = false;
409
409
  let indent = 0;
410
- while (this.ch() === " " || this.ch() === " ") {
411
- indent += this.ch() === " " ? 4 : 1;
410
+ while (this.ch() === " " || this.ch() === " ") {
411
+ indent += this.ch() === " " ? 4 : 1;
412
412
  this.adv();
413
413
  }
414
414
  if (this.ch() === "\n" || !this.ch()) {
@@ -449,7 +449,7 @@ var require_lexer = __commonJS({
449
449
  }
450
450
  continue;
451
451
  }
452
- if (cur === " " || cur === " ") {
452
+ if (cur === " " || cur === " ") {
453
453
  this.adv();
454
454
  continue;
455
455
  }
@@ -524,7 +524,7 @@ var require_lexer = __commonJS({
524
524
  this.pos += 2;
525
525
  s += String.fromCharCode(parseInt(hex, 16));
526
526
  } else {
527
- s += { n: "\n", t: " ", r: "\r", "'": "'", "\\": "\\" }[e] || "\\" + e;
527
+ s += { n: "\n", t: " ", r: "\r", "'": "'", "\\": "\\" }[e] || "\\" + e;
528
528
  }
529
529
  } else {
530
530
  s += this.adv();
@@ -1466,7 +1466,7 @@ var require_parser = __commonJS({
1466
1466
  this.pos++;
1467
1467
  if (!this.at(T.IDENT, T.LBRACKET, T.LBRACE, T.LPAREN, T.FN, T.READONLY, T.TYPEOF)) return false;
1468
1468
  this.parseTypeAnn();
1469
- return this.check(T.NEWLINE) || this.check(T.EOF);
1469
+ return this.check(T.NEWLINE) || this.check(T.EOF) || this.check(T.COLON);
1470
1470
  } catch (_) {
1471
1471
  return false;
1472
1472
  } finally {
@@ -1505,6 +1505,7 @@ var require_parser = __commonJS({
1505
1505
  if (this._isColonReturnType()) {
1506
1506
  this.pos++;
1507
1507
  retType = this.parseTypeAnn();
1508
+ if (this.check(T.COLON)) this.pos++;
1508
1509
  if (this.check(T.NEWLINE)) this.pos++;
1509
1510
  if (this.check(T.INDENT)) {
1510
1511
  this.pos++;
@@ -3503,7 +3504,7 @@ var require_jsx = __commonJS({
3503
3504
  const next = this.src[this.pos + 1] || "";
3504
3505
  if (!(next === ">" || next >= "a" && next <= "z" || next >= "A" && next <= "Z")) return false;
3505
3506
  let i = this.pos - 1;
3506
- while (i >= 0 && (this.src[i] === " " || this.src[i] === " ")) i--;
3507
+ while (i >= 0 && (this.src[i] === " " || this.src[i] === " ")) i--;
3507
3508
  if (i < 0) return true;
3508
3509
  const prev = this.src[i];
3509
3510
  if ("=([{,:>\n?".includes(prev)) return true;
@@ -3732,7 +3733,7 @@ var require_jsx = __commonJS({
3732
3733
  }
3733
3734
  // ── Skip whitespace (not newlines) ────────────────────────────
3734
3735
  skipWs() {
3735
- while (this.pos < this.src.length && (this.src[this.pos] === " " || this.src[this.pos] === " ")) this.pos++;
3736
+ while (this.pos < this.src.length && (this.src[this.pos] === " " || this.src[this.pos] === " ")) this.pos++;
3736
3737
  }
3737
3738
  };
3738
3739
  var FLUX_H_BROWSER = `
@@ -4556,7 +4557,7 @@ ${innerCss}${ind}}
4556
4557
  const charAfter = this.src[this.pos + 3] || "";
4557
4558
  if (!/[a-zA-Z0-9_]/.test(charBefore) && !/[a-zA-Z0-9_]/.test(charAfter)) {
4558
4559
  let j = this.pos + 3;
4559
- while (j < this.src.length && (this.src[j] === " " || this.src[j] === " " || this.src[j] === "\n" || this.src[j] === "\r")) j++;
4560
+ while (j < this.src.length && (this.src[j] === " " || this.src[j] === " " || this.src[j] === "\n" || this.src[j] === "\r")) j++;
4560
4561
  if (this.src[j] === "{") {
4561
4562
  j++;
4562
4563
  let depth = 1;
package/dist/flux.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * flux-lang v4.0.8
2
+ * flux-lang v4.0.1
3
3
  * Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.
4
4
  * (c) 2026 Flux Lang Contributors
5
5
  * Released under the MIT License
@@ -19,7 +19,7 @@
19
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(c)}let s=this.line,r=this.col,a=this.ch();if(a===`
20
20
  `){if(this.adv(),t=!0,this.nestDepth===0){let c=this.tokens[this.tokens.length-1];c&&c.type!==o.NEWLINE&&c.type!==o.INDENT&&c.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
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 h="";for(;/[0-9a-fA-F_]/.test(this.ch());){let l=this.adv();l!=="_"&&(h+=l)}this.tok(o.NUMBER,parseInt(h||"0",16),s,r);continue}if(a==="0"&&(this.ch(1)==="b"||this.ch(1)==="B")){this.adv(),this.adv();let h="";for(;/[01_]/.test(this.ch());){let l=this.adv();l!=="_"&&(h+=l)}this.tok(o.NUMBER,parseInt(h||"0",2),s,r);continue}let c="";for(;this.pos<this.src.length&&!(this.ch()==="."&&this.ch(1)===".");)if(this.ch()>="0"&&this.ch()<="9"||this.ch()===".")c+=this.adv();else if(this.ch()==="_")this.adv();else if((this.ch()==="e"||this.ch()==="E")&&c.length>0){for(c+=this.adv(),(this.ch()==="+"||this.ch()==="-")&&(c+=this.adv());this.ch()>="0"&&this.ch()<="9";)c+=this.adv();break}else break;this.tok(o.NUMBER,parseFloat(c),s,r);continue}if(a==='"'){this.scanStr(s,r);continue}if(a==="`"){this.scanBacktick(s,r);continue}if(a==="'"){this.adv();let c="";for(;this.pos<this.src.length&&this.ch()!=="'";)if(this.ch()==="\\"){this.adv();let h=this.adv();if(h==="u"){let l=this.src.slice(this.pos,this.pos+4);this.pos+=4,c+=String.fromCharCode(parseInt(l,16))}else if(h==="x"){let l=this.src.slice(this.pos,this.pos+2);this.pos+=2,c+=String.fromCharCode(parseInt(l,16))}else c+={n:`
22
- `,t:" ",r:"\r","'":"'","\\":"\\"}[h]||"\\"+h}else c+=this.adv();this.ch()!=="'"&&this.err("Unterminated string"),this.adv(),this.tok(o.STRING,c,s,r);continue}if(a>="a"&&a<="z"||a>="A"&&a<="Z"||a==="_"){let c="";for(;/[a-zA-Z0-9_]/.test(this.ch());)c+=this.adv();if(c==="_"&&!/[a-zA-Z0-9_]/.test(this.ch())){this.tok(o.WILDCARD,"_",s,r);continue}let h=Object.prototype.hasOwnProperty.call(Lt,c)?Lt[c]:void 0;h==="__TRUE__"?this.tok(o.BOOL,!0,s,r):h==="__FALSE__"?this.tok(o.BOOL,!1,s,r):h==="__NULL__"?this.tok(o.NULL,null,s,r):h?this.tok(h,c,s,r):this.tok(o.IDENT,c,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 c=this.tokens[this.tokens.length-1];c&&(c.type===o.IDENT||c.type===o.NUMBER||c.type===o.STRING||c.type===o.BOOL||c.type===o.NULL||c.type===o.REGEX||c.type===o.RPAREN||c.type===o.RBRACKET||c.type===o.PLUSPLUS||c.type===o.MINUSMINUS||c.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}};Ct.exports={Lexer:Et,T:o,TokenType:o}});var et=_((bs,jt)=>{"use strict";var{T:i}=J(),Ft={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 Bt(n,t){return Ft[n]?Ft[n]:t!=null&&t!==n?`"${t}"`:`"${n.toLowerCase()}"`}var z=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}},Ne=["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"],Pt={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 we(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),c=new Uint8Array(r+1);for(let h=0;h<=r;h++)a[h]=h;for(let h=1;h<=s;h++){c[0]=h;let l=h;for(let p=1;p<=r;p++){let m=n[h-1]===t[p-1]?0:1;c[p]=Math.min(c[p-1]+1,a[p]+1,a[p-1]+m),c[p]<l&&(l=c[p])}if(l>e)return e+1;c.copyWithin(0,0,r+1),a.set(c)}return a[r]}function Mt(n){if(!n||n.length<2)return null;if(Object.prototype.hasOwnProperty.call(Pt,n)){let s=Pt[n];return s?`Did you mean "${s.fix}"? ${s.note}`:null}let t=3,e=null;for(let s of Ne){if(Math.abs(n.length-s.length)>2)continue;let r=we(n.toLowerCase(),s,2);r<t&&(t=r,e=s)}return e&&t<=2&&n!==e?`Did you mean "${e}"?`:null}var dt=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=Bt(t,null),r=Bt(e.type,e.value),a=new z(`Expected ${s} but got ${r}`,e);if(e.type===i.IDENT){let c=Mt(e.value);c&&(a.hint=c)}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 z(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}parseDecorators(){let t=[];for(;this.check(i.AT);){let e=this.skip(),s=this.eat(i.IDENT).value,r=[];if(this.check(i.LPAREN)){for(this.pos++;!this.check(i.RPAREN)&&!this.check(i.EOF)&&(r.push(this.parseExpr()),!!this.maybe(i.COMMA)););this.eat(i.RPAREN)}t.push({name:s,args:r,loc:e}),this.skipNewlines()}return t}parseOneStmt(){let t=this.check(i.AT)?this.parseDecorators():[],e=this.peek();switch(e.type){case i.VAR:case i.VAL:return this.parseVarDecl();case i.FN:{let s=this.parseFnDecl();return t.length&&(s.decorators=t),s}case i.ASYNC:{let s=this.parseAsyncFn();return t.length&&(s.decorators=t),s}case i.CLASS:{let s=this.parseClassDecl();return t.length&&(s.decorators=t),s}case i.DECLARE:return this.parseDeclareDecl();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 s=!this.check(i.NEWLINE)&&!this.check(i.EOF)&&this.check(i.IDENT)?this.skip().value:null;return this.skipNewlines(),{type:"BreakStmt",label:s,loc:e}}case i.CONTINUE:{this.skip();let s=!this.check(i.NEWLINE)&&!this.check(i.EOF)&&this.check(i.IDENT)?this.skip().value:null;return this.skipNewlines(),{type:"ContinueStmt",label:s,loc:e}}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 s={[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(s,e.type)){let r=s[e.type],a=new z(r.msg,e);throw r.hint&&(a.hint=r.hint),a}if(e.type===i.IDENT&&this.peek(1).type===i.COLON){let r=this.peek(2).type;if(r===i.FOR||r===i.WHILE){let a=this.skip().value;this.pos++;let c=this.parseOneStmt();return{type:"LabeledStmt",label:a,body:c,loc:e}}}if(e.type===i.IDENT){let r=this.peek(1).type;if(!(r===i.DOT||r===i.LPAREN||r===i.LBRACKET||r===i.EQ||r===i.PLUSEQ||r===i.MINUSEQ||r===i.STAREQ||r===i.SLASHEQ||r===i.PERCENTEQ||r===i.ARROW||r===i.FATARROW||r===i.QUESTION||r===i.EQEQ||r===i.NEQ||r===i.AND||r===i.OR||r===i.PIPE)){let c=Mt(e.value);if(c){let h=new z(`Unexpected identifier "${e.value}"`,e);throw h.hint=c,h}}}return this.parseExprStmt()}}}parseVarDecl(){let t=this.peek().type===i.VAR?"var":"val",e=this.skip();if(this.check(i.LBRACE)){let c=this.parseObjectDestructurePattern();this.eat(i.EQ);let h=this.parseExpr();return this.skipNewlines(),{type:"DestructureDecl",kind:t,patternType:"object",pattern:c,init:h,loc:e}}if(this.check(i.LBRACKET)){let c=this.parseArrayDestructurePattern();this.eat(i.EQ);let h=this.parseExpr();return this.skipNewlines(),{type:"DestructureDecl",kind:t,patternType:"array",pattern:c,init:h,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 c=this.parseTypeAnn();this.eat(i.RBRACKET),this.eat(i.COLON);let h=this.parseTypeAnn();s.push(`[${a}: ${c}]: ${h}`)}else{let a=this.at(i.IDENT,i.STRING)?this.skip().value:this.eat(i.IDENT).value,c=!1;this.check(i.QUESTION)&&(this.pos++,c=!0),this.eat(i.COLON);let h=this.parseTypeAnn(),l=r?"readonly ":"";s.push(`${l}${a}${c?"?":""}: ${h}`)}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,c=[],h={};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)&&(h[p]=this.parseTypeAnn()),c.push(p),!this.maybe(i.COMMA))break}this.eat(i.RPAREN)}if(r.push({name:a,fields:c,fieldTypes:h}),!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(),c=null;if(this.check(i.ARROW))if(this.pos++,this._isTypeAnnBeforeColon()){c=this.parseTypeAnn();let h=this.parseBlock();return{type:"FnDecl",name:r,params:a,retType:c,body:h,inline:!1,async:t,loc:e}}else{let h=this.parseExpr();return this.skipNewlines(),{type:"FnDecl",name:r,params:a,retType:null,body:h,inline:!0,async:t,loc:e}}if(this.check(i.COLON)){if(this._isColonReturnType()){if(this.pos++,c=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:c,body:p,inline:!1,async:t,loc:e}}let l=this.parseOneStmt();return{type:"FnDecl",name:r,params:a,retType:c,body:[l],inline:!1,async:t,loc:e}}let h=this.parseBlock();return{type:"FnDecl",name:r,params:a,retType:null,body:h,inline:!1,async:t,loc:e}}this.err("Expected -> or : after function signature")}parseDeclareDecl(){let t=this.eat(i.DECLARE),e=this.peek();if(e.type===i.FN||e.type===i.ASYNC){let s=e.type===i.ASYNC;this.skip(),s&&this.eat(i.FN);let r=new Set([i.NEW,i.DELETE,i.FROM,i.AS,i.DEFAULT,i.IS,i.IN,i.TYPE]),a=this.check(i.IDENT)||r.has(this.peek().type)?this.skip().value:null,c=this.parseParamList(),h=null;return this.check(i.ARROW)?(this.pos++,h=this.parseTypeAnn()):this.check(i.COLON)&&(this.pos++,h=this.parseTypeAnn()),this.skipNewlines(),{type:"DeclareDecl",decl:{type:"FnDecl",name:a,params:c,retType:h,body:[],inline:!1,async:s,loc:e},loc:t}}if(e.type===i.VAL||e.type===i.VAR){let s=e.type===i.VAR?"var":"val";this.skip();let r=this.eat(i.IDENT).value,a=null;return this.maybe(i.COLON)&&(a=this.parseTypeAnn()),this.skipNewlines(),{type:"DeclareDecl",decl:{type:"VarDecl",kind:s,name:r,typeAnn:a,init:null,loc:e},loc:t}}if(e.type===i.CLASS){this.skip();let s=this.eat(i.IDENT).value;return this.skipNewlines(),{type:"DeclareDecl",decl:{type:"ClassDecl",name:s,fields:[],methods:[],loc:e},loc:t}}this.err("Expected fn, async fn, val, var, or class after declare")}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 c=null;if(!e&&this.maybe(i.EQ)&&(c=this.parseExpr()),t.push({name:s,typeAnn:a,optional:r,defaultVal:c,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 c=[],h=[];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),m=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 y=this.peek(),u=this.skip().value,d=this.eat(i.IDENT).value,g=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 T=this.parseBlock(),b={type:"FnDecl",name:d,params:g,retType:f,body:T,inline:!1,async:!1,modifiers:l,getset:u,loc:y};h.push(b)}else if(this.check(i.FN)){let y=this.parseFnDecl();y.modifiers=l,h.push(y)}else if(this.check(i.ASYNC)){let y=this.parseAsyncFn();y.modifiers=l,h.push(y)}else if(this.check(i.STATIC)&&(this.peek(1).type===i.FN||this.peek(1).type===i.ASYNC)){this.skip();let y=this.check(i.ASYNC)?this.parseAsyncFn():this.parseFnDecl();y.modifiers=l,y.modifiers.add("static"),h.push(y)}else if(this.check(i.VAR)||this.check(i.VAL)){let y=this.skip().type===i.VAR?"var":"val",u=this.eat(i.IDENT).value,d=!1,g=null;this.check(i.QUESTION)&&(this.pos++,d=!0),this.check(i.COLON)&&(this.pos++,g=this.parseTypeAnn());let f=null;this.check(i.EQ)&&(this.pos++,f=this.parseExpr()),this.skipNewlines(),c.push({name:u,typeAnn:g,optional:d,modifiers:l,init:f,fieldKind:y})}else if(this.check(i.IDENT)){let y=this.eat(i.IDENT).value,u=!1;this.check(i.QUESTION)&&(this.pos++,u=!0),this.eat(i.COLON);let d=this.parseTypeAnn();this.skipNewlines(),c.push({name:y,typeAnn:d,optional:u,modifiers:l,init:null})}else this.skip()}return this.maybe(i.DEDENT),{type:"ClassDecl",name:e,typeParams:a,superClass:s,interfaces:r,fields:c,methods:h,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 c=this.parseAccessModifiers();if(this.check(i.ASYNC)){this.pos++,this.eat(i.FN);let h=this.eat(i.IDENT).value,l=this.parseParamList(),p=null;this.maybe(i.ARROW)&&(p=this.parseTypeAnn()),this.skipNewlines(),a.push({kind:"method",name:h,params:l,retType:p,modifiers:c,isAsync:!0})}else if(this.check(i.FN)){this.eat(i.FN);let h=this.eat(i.IDENT).value,l=this.parseParamList(),p=null;this.maybe(i.ARROW)&&(p=this.parseTypeAnn()),this.skipNewlines(),a.push({kind:"method",name:h,params:l,retType:p,modifiers:c,isAsync:!1})}else if(this.check(i.IDENT)){let h=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:h,typeAnn:p,optional:l,modifiers:c})}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,c=null;this.maybe(i.EQ)?(c=this.parseExpr(),c.type==="NumberLit"&&(r=c.value)):c={type:"NumberLit",value:r},r++,this.skipNewlines(),s.push({name:a,value:c})}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 c=this.parseExpr(),h=this.parseBlock();r.push({cond:c,body:h}),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 h=[];for(;!this.check(i.RBRACKET)&&!this.check(i.EOF);){if(this.check(i.DOTDOTDOT)){this.pos++,h.push({rest:!0,name:this.eat(i.IDENT).value});break}if(h.push({name:this.eat(i.IDENT).value}),!this.maybe(i.COMMA))break}this.eat(i.RBRACKET),s="__item__",r={type:"array",names:h}}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(),c=this.parseBlock();return{type:"ForInStmt",var:s,varPattern:r,iter:a,body:c,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 c=this.parseExpr();this.skipNewlines(),s.push({pattern:r,guard:a,body:[{type:"ExprStmt",expr:c}],inline:!0})}else if(this.check(i.COLON)){let c=this.peek(1).type!==i.NEWLINE,h=this.parseBlock();s.push({pattern:r,guard:a,body:h,inline:c&&h.length===1&&h[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.check(i.IDENT)&&this.tokens[this.pos].value==="delete"?(this.pos++,{type:"UnaryExpr",op:"delete ",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 c=this.parseIndentedBlock();return{type:"LambdaExpr",params:[{name:e.type==="Identifier"?e.name:"_"}],body:c,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(c=>({name:c.type==="Identifier"?c.name:"_"}));if(this.check(i.NEWLINE)){let c=this.parseIndentedBlock();return{type:"LambdaExpr",params:r,body:c,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)})`)}}};jt.exports={Parser:dt,ParseError:z}});var xt=_((Ns,Wt)=>{"use strict";function Se(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 Ae=`
22
+ `,t:" ",r:"\r","'":"'","\\":"\\"}[h]||"\\"+h}else c+=this.adv();this.ch()!=="'"&&this.err("Unterminated string"),this.adv(),this.tok(o.STRING,c,s,r);continue}if(a>="a"&&a<="z"||a>="A"&&a<="Z"||a==="_"){let c="";for(;/[a-zA-Z0-9_]/.test(this.ch());)c+=this.adv();if(c==="_"&&!/[a-zA-Z0-9_]/.test(this.ch())){this.tok(o.WILDCARD,"_",s,r);continue}let h=Object.prototype.hasOwnProperty.call(Lt,c)?Lt[c]:void 0;h==="__TRUE__"?this.tok(o.BOOL,!0,s,r):h==="__FALSE__"?this.tok(o.BOOL,!1,s,r):h==="__NULL__"?this.tok(o.NULL,null,s,r):h?this.tok(h,c,s,r):this.tok(o.IDENT,c,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 c=this.tokens[this.tokens.length-1];c&&(c.type===o.IDENT||c.type===o.NUMBER||c.type===o.STRING||c.type===o.BOOL||c.type===o.NULL||c.type===o.REGEX||c.type===o.RPAREN||c.type===o.RBRACKET||c.type===o.PLUSPLUS||c.type===o.MINUSMINUS||c.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}};Ct.exports={Lexer:Et,T:o,TokenType:o}});var et=_((bs,jt)=>{"use strict";var{T:i}=J(),Ft={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 Bt(n,t){return Ft[n]?Ft[n]:t!=null&&t!==n?`"${t}"`:`"${n.toLowerCase()}"`}var z=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}},Ne=["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"],Pt={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 we(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),c=new Uint8Array(r+1);for(let h=0;h<=r;h++)a[h]=h;for(let h=1;h<=s;h++){c[0]=h;let l=h;for(let p=1;p<=r;p++){let m=n[h-1]===t[p-1]?0:1;c[p]=Math.min(c[p-1]+1,a[p]+1,a[p-1]+m),c[p]<l&&(l=c[p])}if(l>e)return e+1;c.copyWithin(0,0,r+1),a.set(c)}return a[r]}function Mt(n){if(!n||n.length<2)return null;if(Object.prototype.hasOwnProperty.call(Pt,n)){let s=Pt[n];return s?`Did you mean "${s.fix}"? ${s.note}`:null}let t=3,e=null;for(let s of Ne){if(Math.abs(n.length-s.length)>2)continue;let r=we(n.toLowerCase(),s,2);r<t&&(t=r,e=s)}return e&&t<=2&&n!==e?`Did you mean "${e}"?`:null}var dt=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=Bt(t,null),r=Bt(e.type,e.value),a=new z(`Expected ${s} but got ${r}`,e);if(e.type===i.IDENT){let c=Mt(e.value);c&&(a.hint=c)}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 z(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}parseDecorators(){let t=[];for(;this.check(i.AT);){let e=this.skip(),s=this.eat(i.IDENT).value,r=[];if(this.check(i.LPAREN)){for(this.pos++;!this.check(i.RPAREN)&&!this.check(i.EOF)&&(r.push(this.parseExpr()),!!this.maybe(i.COMMA)););this.eat(i.RPAREN)}t.push({name:s,args:r,loc:e}),this.skipNewlines()}return t}parseOneStmt(){let t=this.check(i.AT)?this.parseDecorators():[],e=this.peek();switch(e.type){case i.VAR:case i.VAL:return this.parseVarDecl();case i.FN:{let s=this.parseFnDecl();return t.length&&(s.decorators=t),s}case i.ASYNC:{let s=this.parseAsyncFn();return t.length&&(s.decorators=t),s}case i.CLASS:{let s=this.parseClassDecl();return t.length&&(s.decorators=t),s}case i.DECLARE:return this.parseDeclareDecl();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 s=!this.check(i.NEWLINE)&&!this.check(i.EOF)&&this.check(i.IDENT)?this.skip().value:null;return this.skipNewlines(),{type:"BreakStmt",label:s,loc:e}}case i.CONTINUE:{this.skip();let s=!this.check(i.NEWLINE)&&!this.check(i.EOF)&&this.check(i.IDENT)?this.skip().value:null;return this.skipNewlines(),{type:"ContinueStmt",label:s,loc:e}}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 s={[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(s,e.type)){let r=s[e.type],a=new z(r.msg,e);throw r.hint&&(a.hint=r.hint),a}if(e.type===i.IDENT&&this.peek(1).type===i.COLON){let r=this.peek(2).type;if(r===i.FOR||r===i.WHILE){let a=this.skip().value;this.pos++;let c=this.parseOneStmt();return{type:"LabeledStmt",label:a,body:c,loc:e}}}if(e.type===i.IDENT){let r=this.peek(1).type;if(!(r===i.DOT||r===i.LPAREN||r===i.LBRACKET||r===i.EQ||r===i.PLUSEQ||r===i.MINUSEQ||r===i.STAREQ||r===i.SLASHEQ||r===i.PERCENTEQ||r===i.ARROW||r===i.FATARROW||r===i.QUESTION||r===i.EQEQ||r===i.NEQ||r===i.AND||r===i.OR||r===i.PIPE)){let c=Mt(e.value);if(c){let h=new z(`Unexpected identifier "${e.value}"`,e);throw h.hint=c,h}}}return this.parseExprStmt()}}}parseVarDecl(){let t=this.peek().type===i.VAR?"var":"val",e=this.skip();if(this.check(i.LBRACE)){let c=this.parseObjectDestructurePattern();this.eat(i.EQ);let h=this.parseExpr();return this.skipNewlines(),{type:"DestructureDecl",kind:t,patternType:"object",pattern:c,init:h,loc:e}}if(this.check(i.LBRACKET)){let c=this.parseArrayDestructurePattern();this.eat(i.EQ);let h=this.parseExpr();return this.skipNewlines(),{type:"DestructureDecl",kind:t,patternType:"array",pattern:c,init:h,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 c=this.parseTypeAnn();this.eat(i.RBRACKET),this.eat(i.COLON);let h=this.parseTypeAnn();s.push(`[${a}: ${c}]: ${h}`)}else{let a=this.at(i.IDENT,i.STRING)?this.skip().value:this.eat(i.IDENT).value,c=!1;this.check(i.QUESTION)&&(this.pos++,c=!0),this.eat(i.COLON);let h=this.parseTypeAnn(),l=r?"readonly ":"";s.push(`${l}${a}${c?"?":""}: ${h}`)}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,c=[],h={};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)&&(h[p]=this.parseTypeAnn()),c.push(p),!this.maybe(i.COMMA))break}this.eat(i.RPAREN)}if(r.push({name:a,fields:c,fieldTypes:h}),!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)||this.check(i.COLON)):!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(),c=null;if(this.check(i.ARROW))if(this.pos++,this._isTypeAnnBeforeColon()){c=this.parseTypeAnn();let h=this.parseBlock();return{type:"FnDecl",name:r,params:a,retType:c,body:h,inline:!1,async:t,loc:e}}else{let h=this.parseExpr();return this.skipNewlines(),{type:"FnDecl",name:r,params:a,retType:null,body:h,inline:!0,async:t,loc:e}}if(this.check(i.COLON)){if(this._isColonReturnType()){if(this.pos++,c=this.parseTypeAnn(),this.check(i.COLON)&&this.pos++,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:c,body:p,inline:!1,async:t,loc:e}}let l=this.parseOneStmt();return{type:"FnDecl",name:r,params:a,retType:c,body:[l],inline:!1,async:t,loc:e}}let h=this.parseBlock();return{type:"FnDecl",name:r,params:a,retType:null,body:h,inline:!1,async:t,loc:e}}this.err("Expected -> or : after function signature")}parseDeclareDecl(){let t=this.eat(i.DECLARE),e=this.peek();if(e.type===i.FN||e.type===i.ASYNC){let s=e.type===i.ASYNC;this.skip(),s&&this.eat(i.FN);let r=new Set([i.NEW,i.DELETE,i.FROM,i.AS,i.DEFAULT,i.IS,i.IN,i.TYPE]),a=this.check(i.IDENT)||r.has(this.peek().type)?this.skip().value:null,c=this.parseParamList(),h=null;return this.check(i.ARROW)?(this.pos++,h=this.parseTypeAnn()):this.check(i.COLON)&&(this.pos++,h=this.parseTypeAnn()),this.skipNewlines(),{type:"DeclareDecl",decl:{type:"FnDecl",name:a,params:c,retType:h,body:[],inline:!1,async:s,loc:e},loc:t}}if(e.type===i.VAL||e.type===i.VAR){let s=e.type===i.VAR?"var":"val";this.skip();let r=this.eat(i.IDENT).value,a=null;return this.maybe(i.COLON)&&(a=this.parseTypeAnn()),this.skipNewlines(),{type:"DeclareDecl",decl:{type:"VarDecl",kind:s,name:r,typeAnn:a,init:null,loc:e},loc:t}}if(e.type===i.CLASS){this.skip();let s=this.eat(i.IDENT).value;return this.skipNewlines(),{type:"DeclareDecl",decl:{type:"ClassDecl",name:s,fields:[],methods:[],loc:e},loc:t}}this.err("Expected fn, async fn, val, var, or class after declare")}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 c=null;if(!e&&this.maybe(i.EQ)&&(c=this.parseExpr()),t.push({name:s,typeAnn:a,optional:r,defaultVal:c,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 c=[],h=[];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),m=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 y=this.peek(),u=this.skip().value,d=this.eat(i.IDENT).value,g=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 T=this.parseBlock(),b={type:"FnDecl",name:d,params:g,retType:f,body:T,inline:!1,async:!1,modifiers:l,getset:u,loc:y};h.push(b)}else if(this.check(i.FN)){let y=this.parseFnDecl();y.modifiers=l,h.push(y)}else if(this.check(i.ASYNC)){let y=this.parseAsyncFn();y.modifiers=l,h.push(y)}else if(this.check(i.STATIC)&&(this.peek(1).type===i.FN||this.peek(1).type===i.ASYNC)){this.skip();let y=this.check(i.ASYNC)?this.parseAsyncFn():this.parseFnDecl();y.modifiers=l,y.modifiers.add("static"),h.push(y)}else if(this.check(i.VAR)||this.check(i.VAL)){let y=this.skip().type===i.VAR?"var":"val",u=this.eat(i.IDENT).value,d=!1,g=null;this.check(i.QUESTION)&&(this.pos++,d=!0),this.check(i.COLON)&&(this.pos++,g=this.parseTypeAnn());let f=null;this.check(i.EQ)&&(this.pos++,f=this.parseExpr()),this.skipNewlines(),c.push({name:u,typeAnn:g,optional:d,modifiers:l,init:f,fieldKind:y})}else if(this.check(i.IDENT)){let y=this.eat(i.IDENT).value,u=!1;this.check(i.QUESTION)&&(this.pos++,u=!0),this.eat(i.COLON);let d=this.parseTypeAnn();this.skipNewlines(),c.push({name:y,typeAnn:d,optional:u,modifiers:l,init:null})}else this.skip()}return this.maybe(i.DEDENT),{type:"ClassDecl",name:e,typeParams:a,superClass:s,interfaces:r,fields:c,methods:h,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 c=this.parseAccessModifiers();if(this.check(i.ASYNC)){this.pos++,this.eat(i.FN);let h=this.eat(i.IDENT).value,l=this.parseParamList(),p=null;this.maybe(i.ARROW)&&(p=this.parseTypeAnn()),this.skipNewlines(),a.push({kind:"method",name:h,params:l,retType:p,modifiers:c,isAsync:!0})}else if(this.check(i.FN)){this.eat(i.FN);let h=this.eat(i.IDENT).value,l=this.parseParamList(),p=null;this.maybe(i.ARROW)&&(p=this.parseTypeAnn()),this.skipNewlines(),a.push({kind:"method",name:h,params:l,retType:p,modifiers:c,isAsync:!1})}else if(this.check(i.IDENT)){let h=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:h,typeAnn:p,optional:l,modifiers:c})}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,c=null;this.maybe(i.EQ)?(c=this.parseExpr(),c.type==="NumberLit"&&(r=c.value)):c={type:"NumberLit",value:r},r++,this.skipNewlines(),s.push({name:a,value:c})}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 c=this.parseExpr(),h=this.parseBlock();r.push({cond:c,body:h}),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 h=[];for(;!this.check(i.RBRACKET)&&!this.check(i.EOF);){if(this.check(i.DOTDOTDOT)){this.pos++,h.push({rest:!0,name:this.eat(i.IDENT).value});break}if(h.push({name:this.eat(i.IDENT).value}),!this.maybe(i.COMMA))break}this.eat(i.RBRACKET),s="__item__",r={type:"array",names:h}}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(),c=this.parseBlock();return{type:"ForInStmt",var:s,varPattern:r,iter:a,body:c,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 c=this.parseExpr();this.skipNewlines(),s.push({pattern:r,guard:a,body:[{type:"ExprStmt",expr:c}],inline:!0})}else if(this.check(i.COLON)){let c=this.peek(1).type!==i.NEWLINE,h=this.parseBlock();s.push({pattern:r,guard:a,body:h,inline:c&&h.length===1&&h[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.check(i.IDENT)&&this.tokens[this.pos].value==="delete"?(this.pos++,{type:"UnaryExpr",op:"delete ",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 c=this.parseIndentedBlock();return{type:"LambdaExpr",params:[{name:e.type==="Identifier"?e.name:"_"}],body:c,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(c=>({name:c.type==="Identifier"?c.name:"_"}));if(this.check(i.NEWLINE)){let c=this.parseIndentedBlock();return{type:"LambdaExpr",params:r,body:c,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)})`)}}};jt.exports={Parser:dt,ParseError:z}});var xt=_((Ns,Wt)=>{"use strict";function Se(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 Ae=`
23
23
  function _fmt(v, s) {
24
24
  if (s === ',') return (+v).toLocaleString();
25
25
  if (s === '%') return ((+v)*100).toFixed(0)+'%';
package/index.js CHANGED
@@ -3,17 +3,17 @@
3
3
  /**
4
4
  * Flux Lang — Public API
5
5
  *
6
- * const { transpile } = require('@xnoxs/flux-lang');
7
- * import { transpile, format, buildStdlib } from '@xnoxs/flux-lang';
6
+ * const { transpile } = require('flux-lang');
7
+ * import { transpile, format, buildStdlib } from 'flux-lang';
8
8
  */
9
9
 
10
- const { transpile } = require('./src/self/transpiler');
11
- const { format } = require('./src/self/formatter');
12
- const { buildStdlib, detectUsedSymbols, STDLIB_SYMBOLS } = require('./src/self/stdlib');
13
- const { Lexer } = require('./src/self/lexer');
14
- const { Parser } = require('./src/self/parser');
15
- const { bundle } = require('./src/self/bundler');
16
- const { loadConfig, mergeConfig } = require('./src/self/config');
10
+ const { transpile } = require('./src/transpiler');
11
+ const { format } = require('./src/formatter');
12
+ const { buildStdlib, detectUsedSymbols, STDLIB_SYMBOLS } = require('./src/stdlib');
13
+ const { Lexer } = require('./src/lexer');
14
+ const { Parser } = require('./src/parser');
15
+ const { bundle } = require('./src/bundler');
16
+ const { loadConfig, mergeConfig, defineConfig } = require('./src/config');
17
17
 
18
18
  module.exports = {
19
19
  transpile,
@@ -26,4 +26,5 @@ module.exports = {
26
26
  bundle,
27
27
  loadConfig,
28
28
  mergeConfig,
29
+ defineConfig,
29
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xnoxs/flux-lang",
3
- "version": "4.0.8",
3
+ "version": "4.1.1",
4
4
  "description": "Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.",
5
5
  "main": "dist/flux.cjs.js",
6
6
  "module": "dist/flux.esm.js",
@@ -9,8 +9,9 @@
9
9
  "flux": "./bin/flux.js"
10
10
  },
11
11
  "scripts": {
12
- "build": "node -e \"console.log(\"build skipped\")\"",
13
- "test": "node src/self/cli.js test tests/",
12
+ "build": "node scripts/build.js",
13
+ "prepublishOnly": "npm test && npm run build",
14
+ "test": "node src/cli.js test tests/",
14
15
  "test:file": "node src/cli.js test",
15
16
  "check": "node src/cli.js check tests/01_basics.test.flux",
16
17
  "bench": "node benchmarks/bench.js",
@@ -83,4 +84,4 @@
83
84
  "devDependencies": {
84
85
  "esbuild": "^0.28.1"
85
86
  }
86
- }
87
+ }
@@ -3,8 +3,6 @@
3
3
  // src/self/bundler.flux — written in Flux, compiled by stage-0
4
4
  //
5
5
  // Bundles multiple Flux modules into a single JS file.
6
- // Resolves all inter-file .flux imports recursively.
7
- // npm packages (non-relative imports) remain as require() calls.
8
6
  // ============================================================
9
7
 
10
8
  import Fs from "fs"
@@ -18,25 +16,17 @@ fn toModuleId(absPath):
18
16
  return '_flux_' + base.replace(/[^a-zA-Z0-9]/g, '_')
19
17
 
20
18
  fn extractModuleInfo(ast, fromFile):
21
- val imports = []
22
- val npmImports = []
23
- val exports = []
24
- val body = []
25
- val dir = Path.dirname(fromFile)
19
+ val imports = []
20
+ val exports = []
21
+ val body = []
22
+ val dir = Path.dirname(fromFile)
26
23
 
27
24
  for node in ast.body:
28
25
  if node.type == 'ImportDecl':
29
- val src = node.source
30
- // Relative import resolve as .flux file
31
- if src.startsWith('./') or src.startsWith('../'):
32
- var resolved = src
33
- if not resolved.endsWith('.flux'): resolved = resolved + '.flux'
34
- val absPath = Path.resolve(dir, resolved)
35
- imports.push({ names: node.names, source: node.source, absPath })
36
- else:
37
- // npm package import — keep as-is (require in output)
38
- npmImports.push({ names: node.names, source: src })
39
- body.push(node)
26
+ var src = node.source
27
+ if not src.endsWith('.flux'): src = src + '.flux'
28
+ val absPath = Path.resolve(dir, src)
29
+ imports.push({ names: node.names, source: node.source, absPath })
40
30
 
41
31
  else if node.type == 'ExportDecl':
42
32
  val inner = node.decl
@@ -48,7 +38,7 @@ fn extractModuleInfo(ast, fromFile):
48
38
  else:
49
39
  body.push(node)
50
40
 
51
- return { cleanAst: { type: 'Program', body }, imports, npmImports, exports }
41
+ return { cleanAst: { type: 'Program', body }, imports, exports }
52
42
 
53
43
  fn codegenModule(ast):
54
44
  val cg = makeCodeGen({ indent: ' ' })
@@ -90,7 +80,6 @@ export class Bundler:
90
80
  val info = extractModuleInfo(ast, absPath)
91
81
  self.modules.set(absPath, { cleanAst: info.cleanAst, imports: info.imports, exports: info.exports, source, absPath })
92
82
 
93
- // Recursively collect all .flux imports
94
83
  for imp in info.imports:
95
84
  self.collect(imp.absPath)
96
85
 
@@ -109,6 +98,12 @@ export class Bundler:
109
98
  lines.push('"use strict";')
110
99
  lines.push('')
111
100
 
101
+ // flux_modules resolver: patches Module._resolveFilename so require() looks in
102
+ // flux_modules/node_modules/ first (packages installed via `flux install`).
103
+ lines.push('// flux_modules resolver')
104
+ lines.push("(function(){var _p=require('path'),_fs=require('fs'),_M=require('module'),_d=_p.join(process.cwd(),'flux_modules','node_modules');if(_fs.existsSync(_d)){var _o=_M._resolveFilename.bind(_M);_M._resolveFilename=function(r,p,m,op){if(!r.startsWith('.')&&!r.startsWith('/')&&!r.startsWith('node:')){var _fp=_p.join(_d,r.split('/')[0]);if(_fs.existsSync(_fp)){try{return _o(_p.join(_d,r),p,m,op);}catch(_e){}}}return _o(r,p,m,op);};}})();")
105
+ lines.push('')
106
+
112
107
  lines.push('(function() {')
113
108
  lines.push('')
114
109
 
@@ -130,7 +125,7 @@ export class Bundler:
130
125
  for imp in mod.imports:
131
126
  val srcId = toModuleId(imp.absPath)
132
127
  for name in imp.names:
133
- val localName = name.alias ?? name.name
128
+ val localName = name.alias ?? name.name
134
129
  val importedName = name.name
135
130
  lines.push(' var ' + localName + ' = ' + srcId + '._exports ? ' + srcId + '._exports.' + importedName + ' : ' + srcId + '.' + importedName + ';')
136
131