@tslite/parser 0.1.0 → 0.2.0

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/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- 'use strict';var core=require('@tslite/core');var $=class extends core.TSLiteError{constructor(p,i,r){super("lex-error",`${p} (${i.line}:${i.column})`,{position:i,index:r});this.position=i;this.index=r;this.name="LexError";}},G=new Set(["const","if","else","return","async","await","true","false","null","typeof","let","var","function","class","new","for","while","do","this","throw","try","catch","finally","switch","case","break","continue","default","void","delete","instanceof","in","yield","import","export","extends","super","debugger","with"]),ve=["...","===","!==","=>","|>","?.","??","==","!=","<=",">=","&&","||","|","++","--","+=","-=","*=","/=","%=","+","-","*","/","%","<",">","!","?",":",".",",",";","=","(",")","[","]","{","}"],_=f=>f>="a"&&f<="z"||f>="A"&&f<="Z"||f==="_"||f==="$",be=f=>_(f)||f>="0"&&f<="9",F=f=>f>="0"&&f<="9",H=f=>F(f)||f>="a"&&f<="f"||f>="A"&&f<="F";function z(f){let x=[],p=0,i=1,r=0,b=()=>({line:i,column:r}),u=(l=0)=>f[p+l]??"",a=l=>{throw new $(l,b(),p)},s=()=>{let l=f[p++];return l==="\r"?(f[p]===`
2
- `&&p++,i++,r=0):l===`
3
- `||l==="\u2028"||l==="\u2029"?(i++,r=0):r++,l},w=l=>l===`
4
- `||l==="\r"||l==="\u2028"||l==="\u2029",y=()=>{for(;;){let l=u();if(l===" "||l===" "||l==="\f"||l==="\v"||w(l))s();else if(l==="/"&&u(1)==="/")for(;p<f.length&&!w(u());)s();else if(l==="/"&&u(1)==="*")for(s(),s();;){if(p>=f.length&&a("Unterminated block comment"),u()==="*"&&u(1)==="/"){s(),s();break}s();}else break}},h=(l,m,N,k)=>{x.push({type:l,value:m,start:N,end:p,loc:{start:k,end:b()}});},c=l=>{for(s();p<f.length;){let m=u();if(m===l)return s(),f.slice(S,p);if(w(m)&&a("Unterminated string literal"),m==="\\"){s(),p>=f.length&&a("Unterminated string literal"),s();continue}s();}return a("Unterminated string literal")},L=()=>{if(u()==="0"&&(u(1)==="x"||u(1)==="X")){for(s(),s(),H(u())||a("Invalid hexadecimal literal");H(u());)s();return}if(u()==="0"&&(u(1)==="b"||u(1)==="B")){for(s(),s(),u()!=="0"&&u()!=="1"&&a("Invalid binary literal");u()==="0"||u()==="1";)s();return}if(u()==="0"&&(u(1)==="o"||u(1)==="O")){for(s(),s(),u()>="0"&&u()<="7"||a("Invalid octal literal");u()>="0"&&u()<="7";)s();return}for(;F(u());)s();if(u()===".")for(s();F(u());)s();if(u()==="e"||u()==="E")for(s(),(u()==="+"||u()==="-")&&s(),F(u())||a("Invalid exponent");F(u());)s();},g=()=>{let l=p;for(;p<f.length;){let m=u();if(m==="`"){let N=f.slice(l,p);return s(),{raw:N,interp:false}}if(m==="$"&&u(1)==="{"){let N=f.slice(l,p);return s(),s(),{raw:N,interp:true}}if(m==="\\"){if(s(),p>=f.length)break;s();continue}s();}return a("Unterminated template literal")},S=0,v=0,d=[];for(;;){y(),S=p;let l=b();if(p>=f.length){h("EOF","",S,l);break}let m=u();if(_(m)){for(;be(u());)s();let k=f.slice(S,p);h(G.has(k)?"Keyword":"Identifier",k,S,l);continue}if(F(m)||m==="."&&F(u(1))){L(),h("Number",f.slice(S,p),S,l);continue}if(m==='"'||m==="'"){let k=c(m);h("String",k,S,l);continue}if(m==="`"){s();let{raw:k,interp:O}=g();O?(h("TemplateHead",k,S,l),d.push(v)):h("Template",k,S,l);continue}if(m==="{"){s(),h("Punctuator","{",S,l),v++;continue}if(m==="}"){if(d.length>0&&v===d[d.length-1]){d.pop(),s();let{raw:k,interp:O}=g();h(O?"TemplateMiddle":"TemplateTail",k,S,l),O&&d.push(v);continue}s(),h("Punctuator","}",S,l),v--;continue}if(m==="?"&&u(1)==="."&&F(u(2))){s(),h("Punctuator","?",S,l);continue}let N=ve.find(k=>f.startsWith(k,p));if(N){for(let k=0;k<N.length;k++)s();h("Punctuator",N,S,l);continue}a(`Unexpected character '${m}'`);}return x}var Y=f=>{let{peek:x,next:p,isP:i,isK:r,expectP:b,fail:u,unescape:a}=f,s=()=>{let v=0;for(let d=f.pos();d<f.tokens.length;d++){let l=f.tokens[d];if(l.type==="EOF")return false;if(l.type==="Punctuator"){if(["(","[","{","<"].includes(l.value))v++;else if([")","]","}",">"].includes(l.value)&&(v--,v===0)){let m=f.tokens[d+1];return !!m&&m.type==="Punctuator"&&m.value==="=>"}}}return false},w=()=>{b("<");let v=[];for(;!i(">");){let d=x();d.type!=="Identifier"&&u("Expected type parameter name"),p(),v.push(d.value),i(">")||b(",");}return b(">"),v},y=v=>{b("<");let d=[];for(;!i(">");)d.push(h(v)),i(">")||b(",");return b(">"),d},h=v=>{let d=c(v);if(!i("|"))return d;let l=[d];for(;i("|");)p(),l.push(c(v));return {t:"union",of:l}},c=v=>{let d=L(v);for(;i("[")&&x(1).type==="Punctuator"&&x(1).value==="]";)p(),p(),d={t:"array",items:d};return d},L=v=>{if(i("<")){let l=w(),m=new Set(v);return l.forEach(N=>m.add(N)),g(m)}if(i("(")){if(s())return g(v);p();let l=h(v);return b(")"),l}if(i("{"))return S(v);let d=x();if(d.type==="String")return p(),{t:"literal",value:a(d.value.slice(1,-1))};if(d.type==="Number")return p(),{t:"literal",value:Number(d.value)};if(r("true"))return p(),{t:"literal",value:true};if(r("false"))return p(),{t:"literal",value:false};if(r("null"))return p(),{t:"null"};if(d.type==="Identifier"){switch(p(),d.value){case "string":return {t:"string"};case "number":return {t:"number"};case "boolean":return {t:"boolean"};case "any":return {t:"any"};case "unknown":return {t:"unknown"};case "undefined":return {t:"undefined"}}let l=i("<")?y(v):[];return v.has(d.value)&&l.length===0?{t:"var",name:d.value}:{t:"apply",name:d.value,args:l}}return u(`Expected a type but got '${d.value||d.type}'`)},g=v=>{b("(");let d=[];for(;!i(")");){let m=x();m.type!=="Identifier"&&u("Expected parameter name in function type"),p();let N=i("?");N&&p(),b(":");let k=h(v);d.push({name:m.value,type:k,...N?{optional:true}:{}}),i(")")||b(",");}b(")"),b("=>");let l=h(v);return {t:"fn",params:d,returns:l}},S=v=>{b("{");let d={};for(;!i("}");){let l=x(),m;if(l.type==="Identifier"||l.type==="Keyword")p(),m=l.value;else if(l.type==="String")p(),m=a(l.value.slice(1,-1));else return u("Expected property name in object type");let N=i("?");N&&p(),b(":");let k=h(v);if(d[m]={type:k,...N?{optional:true}:{}},i(";")||i(","))p();else break}return b("}"),{t:"object",props:d}};return {parseType:h,parseTypeParamList:w}};var M=class extends core.TSLiteError{constructor(p,i,r){super("parse-error",`${p} (${i.line}:${i.column})`,{position:i,index:r});this.position=i;this.index=r;this.name="ParseError";}},xe={"??":1,"||":2,"&&":3,"==":4,"===":4,"!=":4,"!==":4,"<":5,"<=":5,">":5,">=":5,"+":6,"-":6,"*":7,"/":7,"%":7},ke=new Set(["??","||","&&"]),Te=new Set(["class","import","export","debugger","with"]),Se=new Set(["=","+=","-=","*=","/=","%="]);function X(f){let x=z(f),p=0,i=(e=0)=>x[Math.min(p+e,x.length-1)],r=()=>x[p++],b=()=>x[p-1],u=()=>i().type==="EOF",a=e=>i().type==="Punctuator"&&i().value===e,s=e=>i().type==="Keyword"&&i().value===e,w=(e,n=i())=>{throw new M(e,n.loc.start,n.start)},y=e=>(a(e)||w(`Expected '${e}' but got '${i().value||i().type}'`),r()),h=(e,n)=>{let t=b()??n;return Object.assign(e,{start:n.start,end:t.end,loc:{start:n.loc.start,end:t.loc.end}})},c=(e,n,t)=>Object.assign(e,{start:n.start,end:t.end,loc:{start:n.loc.start,end:t.loc.end}}),L=e=>{let n="";for(let t=0;t<e.length;t++){if(e[t]!=="\\"){n+=e[t];continue}let o=e[++t];switch(o){case "n":n+=`
5
- `;break;case "t":n+=" ";break;case "r":n+="\r";break;case "b":n+="\b";break;case "f":n+="\f";break;case "v":n+="\v";break;case "0":n+="\0";break;case "x":n+=String.fromCharCode(parseInt(e.slice(t+1,t+3),16)),t+=2;break;case "u":if(e[t+1]==="{"){let T=e.indexOf("}",t);n+=String.fromCodePoint(parseInt(e.slice(t+2,T),16)),t=T;}else n+=String.fromCharCode(parseInt(e.slice(t+1,t+5),16)),t+=4;break;default:n+=o;}}return n},g=()=>S(),S=()=>{let e=v(),n=i();if(n.type==="Punctuator"&&Se.has(n.value)){r();let t=S();return c({type:"AssignmentExpression",operator:n.value,left:e,right:t},e,t)}return e},v=()=>{let e=d();for(;a("|>");){r();let n=d();e=c({type:"CallExpression",callee:n,arguments:[e],optional:false},e,n);}return e},d=()=>{let e=l(0);if(!a("?"))return e;r();let n=g();y(":");let t=g();return c({type:"ConditionalExpression",test:e,consequent:n,alternate:t},e,t)},l=e=>{let n=m();for(;;){let t=i();if(t.type!=="Punctuator")break;let o=xe[t.value];if(!o||o<=e)break;r();let T=l(o);n=c({type:ke.has(t.value)?"LogicalExpression":"BinaryExpression",operator:t.value,left:n,right:T},n,T);}return n},m=()=>{let e=i();return e.type==="Punctuator"&&(e.value==="++"||e.value==="--")?(r(),h({type:"UpdateExpression",operator:e.value,prefix:true,argument:m()},e)):s("await")?(r(),h({type:"AwaitExpression",argument:m()},e)):s("typeof")||s("void")||s("delete")?(r(),h({type:"UnaryExpression",operator:e.value,prefix:true,argument:m()},e)):e.type==="Punctuator"&&(e.value==="!"||e.value==="-"||e.value==="+")?(r(),h({type:"UnaryExpression",operator:e.value,prefix:true,argument:m()},e)):N()},N=()=>{let e=k();for(;i().type==="Identifier"&&i().value==="as";){r();let n=D(new Set);e=c({type:"TSAsExpression",expression:e,typeAnnotation:n},e,b());}return e},k=()=>{let e=W(),n=false;for(;;)if(a("?."))if(r(),n=true,a("(")){let{args:t,close:o}=O();e=c({type:"CallExpression",callee:e,arguments:t,optional:true},e,o);}else if(a("[")){r();let t=g(),o=y("]");e=c({type:"MemberExpression",object:e,property:t,computed:true,optional:true},e,o);}else {let t=i();t.type!=="Identifier"&&t.type!=="Keyword"&&w("Expected property name after '?.'"),r();let o=h({type:"Identifier",name:t.value},t);e=c({type:"MemberExpression",object:e,property:o,computed:false,optional:true},e,o);}else if(a(".")){r();let t=i();t.type!=="Identifier"&&t.type!=="Keyword"&&w("Expected property name"),r();let o=h({type:"Identifier",name:t.value},t);e=c({type:"MemberExpression",object:e,property:o,computed:false,optional:false},e,o);}else if(a("[")){r();let t=g(),o=y("]");e=c({type:"MemberExpression",object:e,property:t,computed:true,optional:false},e,o);}else if(a("(")){let{args:t,close:o}=O();e=c({type:"CallExpression",callee:e,arguments:t,optional:false},e,o);}else if(a("++")||a("--")){let t=r();e=c({type:"UpdateExpression",operator:t.value,prefix:false,argument:e},e,t);}else break;return n?c({type:"ChainExpression",expression:e},e,e):e},O=()=>{y("(");let e=[];for(;!a(")");)e.push(V()),a(")")||y(",");return {args:e,close:y(")")}},V=()=>{if(a("...")){let e=r(),n=g();return c({type:"SpreadElement",argument:n},e,n)}return g()},j=()=>{let e=i();return e.type!=="Identifier"&&w("Expected identifier"),r(),h({type:"Identifier",name:e.value},e)},Z=()=>{let e=0;for(let n=p;n<x.length;n++){let t=x[n];if(t.type==="EOF")return false;if(t.type==="Punctuator"){if(t.value==="("||t.value==="["||t.value==="{")e++;else if((t.value===")"||t.value==="]"||t.value==="}")&&(e--,e===0)){let o=x[n+1];return !o||o.type!=="Punctuator"?false:o.value==="=>"?true:o.value===":"?J(n+2):false}}}return false},J=e=>{let n=0;for(let t=e;t<x.length;t++){let o=x[t];if(o.type==="EOF")return false;if(o.type==="Punctuator")if(["(","[","{","<"].includes(o.value))n++;else if([")","]","}",">"].includes(o.value)){if(n===0)return false;n--;}else {if(n===0&&o.value==="=>")return true;if(n===0&&(o.value===";"||o.value===","))return false}}return false},Q=(e=new Set)=>{y("(");let n=[];for(;!a(")");){if(a("...")){let t=r(),o=j();a(":")&&(r(),o.typeAnnotation=D(e)),n.push(c({type:"RestElement",argument:o},t,o));}else {let t=j();a(":")&&(r(),t.typeAnnotation=D(e)),n.push(t);}a(")")||y(",");}return y(")"),n},R=(e,n)=>{let t=a("(")?Q():[j()],o;a(":")&&(r(),o=D(new Set)),y("=>");let T=a("{")?K():g();return h({type:"ArrowFunctionExpression",params:t,body:T,async:e,expression:T.type!=="BlockStatement",generator:false,...o?{returnType:o}:{}},n)},ee=()=>{let e=y("["),n=[];for(;!a("]");){if(a(",")){r(),n.push(null);continue}n.push(V()),a("]")||y(",");}return c({type:"ArrayExpression",elements:n},e,y("]"))},te=()=>{let e=y("{"),n=[];for(;!a("}");){if(a("...")){let t=r(),o=g();n.push(c({type:"SpreadElement",argument:o},t,o));}else {let t=i(),o,T=false;if(a("["))T=true,r(),o=g(),y("]");else if(t.type==="String")r(),o=h({type:"Literal",value:L(t.value.slice(1,-1)),raw:t.value},t);else if(t.type==="Number")r(),o=h({type:"Literal",value:Number(t.value),raw:t.value},t);else if(t.type==="Identifier"||t.type==="Keyword")r(),o=h({type:"Identifier",name:t.value},t);else return w("Invalid property key");if(a(":")){r();let P=g();n.push(c({type:"Property",key:o,value:P,kind:"init",method:false,shorthand:false,computed:T},t,P));}else n.push(c({type:"Property",key:o,value:o,kind:"init",method:false,shorthand:true,computed:false},t,o));}a("}")||y(",");}return c({type:"ObjectExpression",properties:n},e,y("}"))},U=(e,n)=>({type:"TemplateElement",value:{raw:e,cooked:L(e)},tail:n}),ne=e=>{r();let n=[U(e.value,false)],t=[];for(;;){t.push(g());let o=i();if(o.type==="TemplateMiddle")r(),n.push(U(o.value,false));else if(o.type==="TemplateTail"){r(),n.push(U(o.value,true));break}else w("Expected `}` to close template interpolation");}return h({type:"TemplateLiteral",quasis:n,expressions:t},e)},W=()=>{let e=i();if(s("async")){let n=i(1);return n.value==="("||n.type==="Identifier"?(r(),R(true,e)):w("Unexpected 'async'")}if(a("(")&&Z()||e.type==="Identifier"&&i(1).type==="Punctuator"&&i(1).value==="=>")return R(false,e);if(e.type==="Number")return r(),h({type:"Literal",value:Number(e.value),raw:e.value},e);if(e.type==="String")return r(),h({type:"Literal",value:L(e.value.slice(1,-1)),raw:e.value},e);if(e.type==="Template")return r(),h({type:"TemplateLiteral",expressions:[],quasis:[U(e.value,true)]},e);if(e.type==="TemplateHead")return ne(e);if(e.type==="Keyword")return e.value==="true"?(r(),h({type:"Literal",value:true,raw:"true"},e)):e.value==="false"?(r(),h({type:"Literal",value:false,raw:"false"},e)):e.value==="null"?(r(),h({type:"Literal",value:null,raw:"null"},e)):e.value==="new"?re(e):e.value==="function"?w("Anonymous functions are not supported \u2014 use an arrow function"):w(`'${e.value}' is not supported in this language`);if(e.type==="Identifier")return r(),h({type:"Identifier",name:e.value},e);if(a("(")){r();let n=g();return y(")"),n}return a("[")?ee():a("{")?te():w(`Unexpected token '${e.value||e.type}'`)},re=e=>{r();let n=W();for(;;)if(a(".")){r();let t=i();t.type!=="Identifier"&&t.type!=="Keyword"&&w("Expected property name"),r();let o=h({type:"Identifier",name:t.value},t);n=c({type:"MemberExpression",object:n,property:o,computed:false,optional:false},n,o);}else if(a("[")){r();let t=g(),o=y("]");n=c({type:"MemberExpression",object:n,property:t,computed:true,optional:false},n,o);}else break;if(a("(")){let{args:t,close:o}=O();return c({type:"NewExpression",callee:n,arguments:t},e,o)}return c({type:"NewExpression",callee:n,arguments:[]},e,n)},{parseType:D,parseTypeParamList:oe}=Y({tokens:x,pos:()=>p,peek:i,next:r,isP:a,isK:s,expectP:y,fail:w,unescape:L}),se=()=>{let e=r(),n=j(),t=new Set,o=[];a("<")&&(o=oe(),o.forEach(E=>t.add(E))),y("=");let T=D(t),P=c({type:"TSTypeAliasDeclaration",id:n,typeParameters:o,typeAnnotation:T},e,b());return a(";")&&r(),P},C=()=>{let e=i();if(e.type==="Identifier"&&e.value==="type"&&i(1).type==="Identifier"&&i(2).type==="Punctuator"&&(i(2).value==="="||i(2).value==="<"))return se();if(s("const")||s("let")||s("var")){let o=ae();return a(";")&&r(),o}if(s("if"))return ce();if(s("for"))return ie();if(s("while"))return pe();if(s("do"))return le();if(s("break")||s("continue"))return ue();if(s("return"))return fe();if(s("throw"))return de();if(s("try"))return ye();if(s("switch"))return me();if(a("{"))return K();if((s("function")||s("async")&&i(1).type==="Keyword"&&i(1).value==="function")&&w("Function declarations are not supported \u2014 use 'const fn = () => \u2026'"),a(";"))return r(),h({type:"EmptyStatement"},e);e.type==="Keyword"&&Te.has(e.value)&&w(`'${e.value}' is not supported in this language`);let n=g(),t=a(";")?r():b();return c({type:"ExpressionStatement",expression:n},n,t)},ae=()=>{let e=r(),n=e.value,t=j();a(":")&&(r(),t.typeAnnotation=D(new Set));let o=null;a("=")?(r(),o=g()):n==="const"&&w("'const' declarations must be initialized");let T=c({type:"VariableDeclarator",id:t,init:o},t,o??t);return c({type:"VariableDeclaration",kind:n,declarations:[T]},e,o??t)},q=()=>i().type==="Identifier"&&i().value==="of",B=()=>s("in"),ie=()=>{let e=r();y("(");let n=null,t=null;if(!a(";"))if(s("const")||s("let")||s("var")){let E=r(),I=j();if(a(":")&&(r(),I.typeAnnotation=D(new Set)),q()||B()){let A=c({type:"VariableDeclarator",id:I,init:null},I,I);t=c({type:"VariableDeclaration",kind:E.value,declarations:[A]},E,I);}else {let A=null;a("=")?(r(),A=g()):E.value==="const"&&w("'const' declarations must be initialized");let he=c({type:"VariableDeclarator",id:I,init:A},I,A??I);n=c({type:"VariableDeclaration",kind:E.value,declarations:[he]},E,A??I);}}else {let E=g();q()||B()?t=E:n=E;}if(t){let E=B();r();let I=g();y(")");let A=C();return c(E?{type:"ForInStatement",left:t,right:I,body:A}:{type:"ForOfStatement",left:t,right:I,body:A,await:false},e,A)}y(";");let o=a(";")?null:g();y(";");let T=a(")")?null:g();y(")");let P=C();return c({type:"ForStatement",init:n,test:o,update:T,body:P},e,P)},le=()=>{let e=r(),n=C();s("while")||w("Expected 'while' after the 'do' body"),r(),y("(");let t=g(),o=y(")");return a(";")&&r(),c({type:"DoWhileStatement",body:n,test:t},e,o)},ue=()=>{let e=r(),n=e.value==="break"?"BreakStatement":"ContinueStatement",t=a(";")?r():b();return c({type:n,label:null},e,t)},pe=()=>{let e=r();y("(");let n=g();y(")");let t=C();return c({type:"WhileStatement",test:n,body:t},e,t)},ce=()=>{let e=r();y("(");let n=g();y(")");let t=C(),o=null;return s("else")&&(r(),o=C()),c({type:"IfStatement",test:n,consequent:t,alternate:o},e,o??t)},fe=()=>{let e=r(),n=null;!a(";")&&!a("}")&&!u()&&(n=g());let t=a(";")?r():b();return c({type:"ReturnStatement",argument:n},e,t)},de=()=>{let e=r(),n=g(),t=a(";")?r():b();return c({type:"ThrowStatement",argument:n},e,t)},ye=()=>{let e=r(),n=K(),t=null,o=null;if(s("catch")){let T=r(),P=null;a("(")&&(r(),P=j(),y(")"));let E=K();t=c({type:"CatchClause",param:P,body:E},T,E);}return s("finally")&&(r(),o=K()),!t&&!o&&w("'try' requires a 'catch' or 'finally' clause"),c({type:"TryStatement",block:n,handler:t,finalizer:o},e,o??t??n)},me=()=>{let e=r();y("(");let n=g();y(")"),y("{");let t=[];for(;!a("}")&&!u();){let T=i(),P=null;s("case")?(r(),P=g()):s("default")?r():w("Expected 'case' or 'default' in switch"),y(":");let E=[];for(;!a("}")&&!s("case")&&!s("default")&&!u();)E.push(C());t.push(c({type:"SwitchCase",test:P,consequent:E},T,b()??T));}let o=y("}");return c({type:"SwitchStatement",discriminant:n,cases:t},e,o)},K=()=>{let e=y("{"),n=[];for(;!a("}")&&!u();)n.push(C());return c({type:"BlockStatement",body:n},e,y("}"))};return {parseExpr:g,parseProgram:()=>{let e=i(),n=[];for(;!u();)n.push(C());return c({type:"Program",sourceType:"module",body:n},e,b()??e)},eof:u,fail:w}}function Ne(f){return X(f).parseProgram()}function Ee(f){let{parseExpr:x,eof:p,fail:i}=X(f),r=x();return p()||i("Unexpected token after expression"),r}exports.KEYWORDS=G;exports.LexError=$;exports.ParseError=M;exports.parse=Ne;exports.parseExpression=Ee;exports.tokenize=z;
1
+ 'use strict';var core=require('@tslite/core');var Q=class extends core.TSLiteError{constructor(l,i,o){super("lex-error",`${l} (${i.line}:${i.column})`,{position:i,index:o});this.position=i;this.index=o;this.name="LexError";}},de=new Set(["const","if","else","return","async","await","true","false","null","typeof","let","var","function","class","new","for","while","do","this","throw","try","catch","finally","switch","case","break","continue","default","void","delete","instanceof","in","yield","import","export","extends","super","debugger","with"]),Be=["...","===","!==","=>","?.","??","==","!=","<=",">=","&&","||","|","&","++","--","+=","-=","*=","/=","%=","**","<<","+","-","*","/","%","<",">","!","?",":",".",",",";","=","^","~","(",")","[","]","{","}"],oe=u=>u>="a"&&u<="z"||u>="A"&&u<="Z"||u==="_"||u==="$",ye=u=>oe(u)||u>="0"&&u<="9",M=u=>u>="0"&&u<="9",fe=u=>M(u)||u>="a"&&u<="f"||u>="A"&&u<="F",qe=u=>ye(u)||u==="-",ze=new Set(["(","[","{",",",";",":","?","=>","...","=","+","-","*","/","%","<","<=",">",">=","==","===","!=","!==","&&","||","??","!","+=","-=","*=","/=","%="]),Ve=new Set(["return","typeof","await","delete","void","in","instanceof","else","case","yield","throw"]);function se(u){let N=[],l=0,i=1,o=0,v=()=>({line:i,column:o}),d=(g=0)=>u[l+g]??"",A=g=>{throw new Q(g,v(),l)},r=()=>{let g=u[l++];return g==="\r"?(u[l]===`
2
+ `&&l++,i++,o=0):g===`
3
+ `||g==="\u2028"||g==="\u2029"?(i++,o=0):o++,g},b=g=>g===`
4
+ `||g==="\r"||g==="\u2028"||g==="\u2029",K=()=>{for(;;){let g=d();if(g===" "||g===" "||g==="\f"||g==="\v"||b(g))r();else if(g==="/"&&d(1)==="/")for(;l<u.length&&!b(d());)r();else if(g==="/"&&d(1)==="*")for(r(),r();;){if(l>=u.length&&A("Unterminated block comment"),d()==="*"&&d(1)==="/"){r(),r();break}r();}else break}},m=(g,C,L,k)=>{N.push({type:g,value:C,start:L,end:l,loc:{start:k,end:v()}}),q=g==="Punctuator"?ze.has(C):g==="Keyword"?Ve.has(C):g==="TemplateHead"||g==="TemplateMiddle";},y=g=>{for(r();l<u.length;){let C=d();if(C===g)return r(),u.slice(S,l);if(b(C)&&A("Unterminated string literal"),C==="\\"){r(),l>=u.length&&A("Unterminated string literal"),r();continue}r();}return A("Unterminated string literal")},P=()=>{if(d()==="0"&&(d(1)==="x"||d(1)==="X")){for(r(),r(),fe(d())||A("Invalid hexadecimal literal");fe(d());)r();return}if(d()==="0"&&(d(1)==="b"||d(1)==="B")){for(r(),r(),d()!=="0"&&d()!=="1"&&A("Invalid binary literal");d()==="0"||d()==="1";)r();return}if(d()==="0"&&(d(1)==="o"||d(1)==="O")){for(r(),r(),d()>="0"&&d()<="7"||A("Invalid octal literal");d()>="0"&&d()<="7";)r();return}for(;M(d());)r();if(d()===".")for(r();M(d());)r();if(d()==="e"||d()==="E")for(r(),(d()==="+"||d()==="-")&&r(),M(d())||A("Invalid exponent");M(d());)r();},c=()=>{let g=l;for(;l<u.length;){let C=d();if(C==="`"){let L=u.slice(g,l);return r(),{raw:L,interp:false}}if(C==="$"&&d(1)==="{"){let L=u.slice(g,l);return r(),r(),{raw:L,interp:true}}if(C==="\\"){if(r(),l>=u.length)break;r();continue}r();}return A("Unterminated template literal")},S=0,x=0,X=[],q=true,D="js",$=[],F=[];for(;;){if(D==="jsxChildren"){S=l;let k=v();if(l>=u.length){m("EOF","",S,k);break}let a=d();if(a==="<"){d(1)==="/"?(r(),r(),m("Punctuator","</",S,k),D="jsxCloseTag"):(r(),m("Punctuator","<",S,k),$.push("jsxChildren"),D="jsxOpenTag");continue}if(a==="{"){r(),m("Punctuator","{",S,k),F.push({level:x,restore:"jsxChildren"}),D="js";continue}for(;l<u.length&&d()!=="<"&&d()!=="{";)r();m("JSXText",u.slice(S,l),S,k);continue}if(D==="jsxOpenTag"||D==="jsxCloseTag"){K(),S=l;let k=v();if(l>=u.length){m("EOF","",S,k);break}let a=d();if(oe(a)){for(r();qe(d());)r();m("Identifier",u.slice(S,l),S,k);continue}if(a==="/"&&d(1)===">"){r(),r(),m("Punctuator","/>",S,k),D=$.pop()??"js";continue}if(a===">"){r(),m("Punctuator",">",S,k),D=D==="jsxCloseTag"?$.pop()??"js":"jsxChildren";continue}if(a==="{"){r(),m("Punctuator","{",S,k),F.push({level:x,restore:D}),D="js";continue}if(a==='"'||a==="'"){m("String",y(a),S,k);continue}if(a==="="||a==="."||a===":"){r(),m("Punctuator",a,S,k);continue}A(`Unexpected character '${a}' in JSX tag`);}K(),S=l;let g=v();if(l>=u.length){m("EOF","",S,g);break}let C=d();if(oe(C)){for(;ye(d());)r();let k=u.slice(S,l);m(de.has(k)?"Keyword":"Identifier",k,S,g);continue}if(M(C)||C==="."&&M(d(1))){P(),m("Number",u.slice(S,l),S,g);continue}if(C==='"'||C==="'"){let k=y(C);m("String",k,S,g);continue}if(C==="`"){r();let{raw:k,interp:a}=c();a?(m("TemplateHead",k,S,g),X.push(x)):m("Template",k,S,g);continue}if(C==="<"&&q){r(),m("Punctuator","<",S,g),$.push("js"),D="jsxOpenTag";continue}if(C==="{"){r(),m("Punctuator","{",S,g),x++;continue}if(C==="}"){if(X.length>0&&x===X[X.length-1]){X.pop(),r();let{raw:k,interp:a}=c();m(a?"TemplateMiddle":"TemplateTail",k,S,g),a&&X.push(x);continue}if(F.length>0&&x===F[F.length-1].level){let{restore:k}=F.pop();r(),m("Punctuator","}",S,g),D=k;continue}r(),m("Punctuator","}",S,g),x--;continue}if(C==="?"&&d(1)==="."&&M(d(2))){r(),m("Punctuator","?",S,g);continue}let L=Be.find(k=>u.startsWith(k,l));if(L){for(let k=0;k<L.length;k++)r();m("Punctuator",L,S,g);continue}A(`Unexpected character '${C}'`);}return N}var ae=(u=[])=>({vars:new Set(u),bounds:new Map,noCond:false,inferSink:null}),_=(u,N)=>{let l=new Set(u.vars),i=new Map(u.bounds);for(let o of N)l.add(o.name),o.bound||o.isConst?i.set(o.name,{bound:o.bound,isConst:o.isConst}):i.delete(o.name);return {vars:l,bounds:i,noCond:u.noCond,inferSink:u.inferSink}},We=(u,N)=>{let l=u.bounds.get(N);return l&&(l.bound||l.isConst)?{t:"var",name:N,...l.bound?{bound:l.bound}:{},...l.isConst?{isConst:true}:{}}:{t:"var",name:N}},me=u=>{let{peek:N,next:l,isP:i,isK:o,expectP:v,fail:d,unescape:A}=u,r=()=>{let a=u.pos(),p=u.tokens[a],f=u.tokens[a-1];return !!f&&!!p&&p.loc.start.line>f.loc.end.line},b=()=>{let a=0;for(let p=u.pos();p<u.tokens.length;p++){let f=u.tokens[p];if(f.type==="EOF")return false;if(f.type==="Punctuator"){if(["(","[","{","<"].includes(f.value))a++;else if([")","]","}",">"].includes(f.value)&&(a--,a===0)){let T=u.tokens[p+1];return !!T&&T.type==="Punctuator"&&T.value==="=>"}}}return false},K=()=>{let a=u.tokens,p=[],f=0,T=false;for(let E=u.pos();E<a.length;E++){let I=a[E];if(I.type==="EOF")break;if(I.type==="Punctuator"){if(I.value==="<")f++,f===1&&(T=true);else if(I.value===">"){if(f--,f===0)break}else I.value==="("||I.value==="["||I.value==="{"?(f++,T=false):I.value===")"||I.value==="]"||I.value==="}"?(f--,T=false):I.value===","&&f===1?T=true:T=false;continue}if(f===1&&T){if(I.type==="Keyword"&&I.value==="const")continue;if(I.type==="Identifier"){p.push(I.value),T=false;continue}}T=false;}return p},m=a=>{let p=_(a,K().map(T=>({name:T})));v("<");let f=[];for(;!i(">");){let T=o("const");T&&l();let E=N();E.type!=="Identifier"&&d("Expected type parameter name"),l();let I;o("extends")&&(l(),I=c(p)),i("=")&&(l(),c(p)),f.push({name:E.value,...I?{bound:I}:{},...T?{isConst:true}:{}}),i(">")||v(",");}return v(">"),f},y=a=>{v("<");let p=[];for(;!i(">");)p.push(c(a)),i(">")||v(",");return v(">"),p},P=a=>{let p=N();return p.type==="Identifier"&&p.value===a},c=a=>{let p=S(a);if(a.noCond||!o("extends")||r())return p;l();let f=[],T=S({...a,noCond:true,inferSink:f});v("?");let E=_(a,f.map(B=>({name:B}))),I=c(E);v(":");let z=c(E);return {t:"conditional",check:p,extends:T,then:I,else:z,...f.length?{infer:f}:{}}},S=a=>{i("|")&&l();let p=x(a);if(!i("|"))return p;let f=[p];for(;i("|");)l(),f.push(x(a));return {t:"union",of:f}},x=a=>{i("&")&&l();let p=X(a);if(!i("&"))return p;let f=[p];for(;i("&");)l(),f.push(X(a));return {t:"intersection",of:f}},X=a=>{if(P("keyof"))return l(),{t:"keyof",of:X(a)};if(P("infer")){l();let p=N();p.type!=="Identifier"&&d("Expected 'infer' variable name"),l();let f=a.inferSink;return f?(f.push(p.value),{t:"var",name:p.value}):d("'infer' is only allowed in the 'extends' clause of a conditional")}return q(a)},q=a=>{let p=D(a);for(;i("[")&&!r();)if(l(),i("]"))l(),p={t:"array",items:p};else {let f=c(a);v("]"),p={t:"index",obj:p,key:f};}return p},D=a=>{if(i("<")){let f=m(a),T=_(a,f);return F(T)}if(i("(")){if(b())return F(a);l();let f=c(a.noCond?{...a,noCond:false}:a);return v(")"),f}if(i("{"))return C()?L(a):k(a);if(i("["))return g(a);let p=N();if(p.type==="String")return l(),{t:"literal",value:A(p.value.slice(1,-1))};if(p.type==="Number")return l(),{t:"literal",value:Number(p.value)};if(o("true"))return l(),{t:"literal",value:true};if(o("false"))return l(),{t:"literal",value:false};if(o("null"))return l(),{t:"null"};if(o("void"))return l(),{t:"void"};if(p.type==="Identifier"){switch(l(),p.value){case "string":return {t:"string"};case "number":return {t:"number"};case "boolean":return {t:"boolean"};case "any":return {t:"any"};case "unknown":return {t:"unknown"};case "undefined":return {t:"undefined"};case "never":return {t:"union",of:[]}}let f=i("<")?y(a):[];return a.vars.has(p.value)&&f.length===0?We(a,p.value):p.value==="ReturnType"&&f.length===1?{t:"returnType",fn:f[0]}:p.value==="Parameters"&&f.length===1?{t:"parameters",fn:f[0]}:{t:"apply",name:p.value,args:f}}return d(`Expected a type but got '${p.value||p.type}'`)},$=a=>{v("(");let p=[];for(;!i(")");){let f=N();f.type!=="Identifier"&&d("Expected parameter name in function type"),l();let T=i("?");T&&l(),v(":");let E=c(a);p.push({name:f.value,type:E,...T?{optional:true}:{}}),i(")")||v(",");}return v(")"),p},F=a=>{let p=$(a);v("=>");let f=c(a);return {t:"fn",params:p,returns:f}},g=a=>{v("[");let p=[],f=[];for(;!i("]");){if(i("...")){l();let T=c(a);T.t==="array"?(p.push(T.items),f.push("rest")):(p.push(T),f.push("variadic"));}else {let T=c(a),E=i("?");E&&l(),p.push(T),f.push(E?"optional":"req");}i("]")||v(",");}return v("]"),f.some(T=>T!=="req")?{t:"tuple",elements:p,flags:f}:{t:"tuple",elements:p}},C=()=>{let a=u.tokens,p=u.pos()+1;return a[p]?.type==="Punctuator"&&(a[p]?.value==="+"||a[p]?.value==="-")&&p++,a[p]?.type==="Identifier"&&a[p]?.value==="readonly"&&p++,a[p]?.type==="Punctuator"&&a[p]?.value==="["&&a[p+1]?.type==="Identifier"&&a[p+2]?.type==="Keyword"&&a[p+2]?.value==="in"},L=a=>{v("{"),(i("+")||i("-"))&&l(),P("readonly")&&l(),v("[");let p=N();p.type!=="Identifier"&&d("Expected mapped type key name"),l(),o("in")||d("Expected 'in' in mapped type"),l();let f=c(a);P("as")&&d("Key remapping ('as') in mapped types is not supported"),v("]");let T=false,E=i("+")||i("-")?l().value:null;i("?")&&(l(),T=E!=="-"),v(":");let I=c(_(a,[{name:p.value}]));return (i(";")||i(","))&&l(),v("}"),{t:"mapped",key:p.value,over:f,body:I,optional:T}},k=a=>{v("{");let p={},f,T=[];for(;!i("}");){if(i("(")){let E=$(a);v(":");let I=c(a);T.push({t:"fn",params:E,returns:I});}else if(i("[")){l(),N().type!=="Identifier"&&d("Expected index signature parameter name"),l(),v(":");let E=N();(E.type!=="Identifier"||E.value!=="string"&&E.value!=="number")&&d("Index signature parameter type must be 'string' or 'number'"),l(),v("]"),v(":"),f={key:E.value,value:c(a)};}else {let E=N(),I;if(E.type==="Identifier"||E.type==="Keyword")l(),I=E.value;else if(E.type==="String")l(),I=A(E.value.slice(1,-1));else if(E.type==="Number")l(),I=E.value;else return d("Expected property name in object type");let z=i("?");z&&l(),v(":");let B=c(a);p[I]={type:B,...z?{optional:true}:{}};}if(i(";")||i(","))l();else break}return v("}"),T.length>0?Object.keys(p).length>0||f?d("Callable object types (call signatures mixed with members) are not supported"):T.length===1?T[0]:{t:"overload",signatures:T}:{t:"object",props:p,...f?{index:f}:{}}};return {parseType:a=>c(ae(a)),parseTypeParamList:()=>m(ae()),parseTypeInScope:a=>c(_(ae(),a))}};var ee=class extends core.TSLiteError{constructor(l,i,o){super("parse-error",`${l} (${i.line}:${i.column})`,{position:i,index:o});this.position=i;this.index=o;this.name="ParseError";}},Ge={"??":1,"||":2,"&&":3,"|":4,"^":5,"&":6,"==":7,"===":7,"!=":7,"!==":7,"<":8,"<=":8,">":8,">=":8,in:8,as:8,"<<":9,">>":9,">>>":9,"+":10,"-":10,"*":11,"/":11,"%":11,"**":12},He=new Set(["??","||","&&"]),Ye=new Set(["class","debugger","with"]),Ze=new Set(["=","+=","-=","*=","/=","%="]);function he(u){let N=se(u),l=0,i=(e=0)=>N[Math.min(l+e,N.length-1)],o=()=>N[l++],v=()=>N[l-1],d=()=>{let e=N[l],t=N[l-1];return !!e&&!!t&&e.loc.start.line>t.loc.end.line},A=()=>i().type==="EOF",r=e=>i().type==="Punctuator"&&i().value===e,b=e=>i().type==="Keyword"&&i().value===e,K=e=>i().type==="Identifier"&&i().value===e,m=(e,t=i())=>{throw new ee(e,t.loc.start,t.start)},y=e=>(r(e)||m(`Expected '${e}' but got '${i().value||i().type}'`),o()),P=(e,t)=>{let n=v()??t;return Object.assign(e,{start:t.start,end:n.end,loc:{start:t.loc.start,end:n.loc.end}})},c=(e,t,n)=>Object.assign(e,{start:t.start,end:n.end,loc:{start:t.loc.start,end:n.loc.end}}),S=e=>{let t="";for(let n=0;n<e.length;n++){if(e[n]!=="\\"){t+=e[n];continue}let s=e[++n];switch(s){case "n":t+=`
5
+ `;break;case "t":t+=" ";break;case "r":t+="\r";break;case "b":t+="\b";break;case "f":t+="\f";break;case "v":t+="\v";break;case "0":t+="\0";break;case "x":t+=String.fromCharCode(parseInt(e.slice(n+1,n+3),16)),n+=2;break;case "u":if(e[n+1]==="{"){let h=e.indexOf("}",n);t+=String.fromCodePoint(parseInt(e.slice(n+2,h),16)),n=h;}else t+=String.fromCharCode(parseInt(e.slice(n+1,n+5),16)),n+=4;break;default:t+=s;}}return t},x=(e=false)=>X(e),X=(e=false)=>{let t=q(e),n=i();if(n.type==="Punctuator"&&Ze.has(n.value)){o();let s=X();return c({type:"AssignmentExpression",operator:n.value,left:t,right:s},t,s)}return t},q=(e=false)=>{let t=$(0,e);if(!r("?"))return t;o();let n=x();y(":");let s=x();return c({type:"ConditionalExpression",test:t,consequent:n,alternate:s},t,s)},D=()=>{let e=i();if(e.type==="Keyword")return e.value==="in"?{op:"in",consume:1}:null;if(e.type==="Identifier")return e.value==="as"?{op:"as",consume:1}:null;if(e.type!=="Punctuator")return null;if(e.value===">"){let t=i(1);if(t.type==="Punctuator"&&t.value===">"&&e.end===t.start){let n=i(2);return n.type==="Punctuator"&&n.value===">"&&t.end===n.start?{op:">>>",consume:3}:{op:">>",consume:2}}return {op:">",consume:1}}return {op:e.value,consume:1}},$=(e,t=false)=>{let n=F();for(;;){let s=D();if(!s)break;let{op:h,consume:w}=s;if(h==="in"&&t)break;let j=Ge[h];if(!j||j<=e)break;if(h==="as"){if(d())break;o();let J=H(new Set);n=c({type:"TSAsExpression",expression:n,typeAnnotation:J},n,v());continue}for(let J=0;J<w;J++)o();let O=$(h==="**"?j-1:j,t);n=c({type:He.has(h)?"LogicalExpression":"BinaryExpression",operator:h,left:n,right:O},n,O);}return n},F=()=>{let e=i();return e.type==="Punctuator"&&(e.value==="++"||e.value==="--")?(o(),P({type:"UpdateExpression",operator:e.value,prefix:true,argument:F()},e)):b("await")?(o(),P({type:"AwaitExpression",argument:F()},e)):b("typeof")||b("void")||b("delete")||e.type==="Punctuator"&&(e.value==="!"||e.value==="-"||e.value==="+"||e.value==="~")?g(e):C()},g=e=>{o();let t=F();return r("**")&&m(`An unary expression with the '${e.value}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.`),P({type:"UnaryExpression",operator:e.value,prefix:true,argument:t},e)},C=()=>{let e=Te(),t=false;for(;;)if(r("?."))if(o(),t=true,r("(")){let{args:n,close:s}=L();e=c({type:"CallExpression",callee:e,arguments:n,optional:true},e,s);}else if(r("[")){o();let n=x(),s=y("]");e=c({type:"MemberExpression",object:e,property:n,computed:true,optional:true},e,s);}else {let n=i();n.type!=="Identifier"&&n.type!=="Keyword"&&m("Expected property name after '?.'"),o();let s=P({type:"Identifier",name:n.value},n);e=c({type:"MemberExpression",object:e,property:s,computed:false,optional:true},e,s);}else if(r(".")){o();let n=i();n.type!=="Identifier"&&n.type!=="Keyword"&&m("Expected property name"),o();let s=P({type:"Identifier",name:n.value},n);e=c({type:"MemberExpression",object:e,property:s,computed:false,optional:false},e,s);}else if(r("[")){o();let n=x(),s=y("]");e=c({type:"MemberExpression",object:e,property:n,computed:true,optional:false},e,s);}else if(r("(")){let{args:n,close:s}=L();e=c({type:"CallExpression",callee:e,arguments:n,optional:false},e,s);}else if(r("++")||r("--")){let n=o();e=c({type:"UpdateExpression",operator:n.value,prefix:false,argument:e},e,n);}else break;return t?c({type:"ChainExpression",expression:e},e,e):e},L=()=>{y("(");let e=[];for(;!r(")");)e.push(k()),r(")")||y(",");return {args:e,close:y(")")}},k=()=>{if(r("...")){let e=o(),t=x();return c({type:"SpreadElement",argument:t},e,t)}return x()},a=()=>{let e=i();return e.type!=="Identifier"&&m("Expected identifier"),o(),P({type:"Identifier",name:e.value},e)},p=e=>{let t=r("{")?f(e):r("[")?T(e):a();return r(":")&&(o(),t.typeAnnotation=H(e)),t},f=e=>{let t=y("{"),n=[];for(;!r("}");){if(r("...")){let h=o(),w=p(e);n.push(c({type:"RestElement",argument:w},h,w));}else {let h=a(),w,j=false;if(r(":")?(o(),w=p(e)):(w={...h},j=true),r("=")){o();let O=x();w=c({type:"AssignmentPattern",left:w,right:O},w,O);}n.push(c({type:"Property",key:h,value:w,kind:"init",shorthand:j,computed:false,method:false},h,w));}r("}")||y(",");}let s=y("}");return c({type:"ObjectPattern",properties:n},t,s)},T=e=>{let t=y("["),n=[];for(;!r("]");){if(r(",")){n.push(null),o();continue}if(r("...")){let h=o(),w=p(e);n.push(c({type:"RestElement",argument:w},h,w));}else {let h=p(e);if(r("=")){o();let w=x();h=c({type:"AssignmentPattern",left:h,right:w},h,w);}n.push(h);}r("]")||y(",");}let s=y("]");return c({type:"ArrayPattern",elements:n},t,s)},E=()=>{let e=0;for(let t=l;t<N.length;t++){let n=N[t];if(n.type==="EOF")return false;if(n.type==="Punctuator"){if(n.value==="("||n.value==="["||n.value==="{")e++;else if((n.value===")"||n.value==="]"||n.value==="}")&&(e--,e===0)){let s=N[t+1];return !s||s.type!=="Punctuator"?false:s.value==="=>"?true:s.value===":"?I(t+2):false}}}return false},I=e=>{let t=0;for(let n=e;n<N.length;n++){let s=N[n];if(s.type==="EOF")return false;if(s.type==="Punctuator")if(["(","[","{","<"].includes(s.value))t++;else if([")","]","}",">"].includes(s.value)){if(t===0)return false;t--;}else {if(t===0&&s.value==="=>")return true;if(t===0&&(s.value===";"||s.value===","))return false}}return false},z=(e=new Set)=>{y("(");let t=[];for(;!r(")");){if(r("...")){let n=o(),s=p(e);t.push(c({type:"RestElement",argument:s},n,s));}else {let n=p(e);if(r("=")){o();let s=x();n=c({type:"AssignmentPattern",left:n,right:s},n,s);}t.push(n);}r(")")||y(",");}return y(")"),t},B=(e,t)=>{let n=r("(")?z():[a()],s;r(":")&&(o(),s=H(new Set)),y("=>");let h=r("{")?W():x();return P({type:"ArrowFunctionExpression",params:n,body:h,async:e,expression:h.type!=="BlockStatement",generator:false,...s?{returnType:s}:{}},t)},ge=()=>{let e=y("["),t=[];for(;!r("]");){if(r(",")){o(),t.push(null);continue}t.push(k()),r("]")||y(",");}return c({type:"ArrayExpression",elements:t},e,y("]"))},ve=()=>{let e=y("{"),t=[];for(;!r("}");){if(r("...")){let n=o(),s=x();t.push(c({type:"SpreadElement",argument:s},n,s));}else {let n=i(),s,h=false;if(r("["))h=true,o(),s=x(),y("]");else if(n.type==="String")o(),s=P({type:"Literal",value:S(n.value.slice(1,-1)),raw:n.value},n);else if(n.type==="Number")o(),s=P({type:"Literal",value:Number(n.value),raw:n.value},n);else if(n.type==="Identifier"||n.type==="Keyword")o(),s=P({type:"Identifier",name:n.value},n);else return m("Invalid property key");if(r(":")){o();let w=x();t.push(c({type:"Property",key:s,value:w,kind:"init",method:false,shorthand:false,computed:h},n,w));}else t.push(c({type:"Property",key:s,value:s,kind:"init",method:false,shorthand:true,computed:false},n,s));}r("}")||y(",");}return c({type:"ObjectExpression",properties:t},e,y("}"))},G=(e,t)=>({type:"TemplateElement",value:{raw:e,cooked:S(e)},tail:t}),be=e=>{o();let t=[G(e.value,false)],n=[];for(;;){n.push(x());let s=i();if(s.type==="TemplateMiddle")o(),t.push(G(s.value,false));else if(s.type==="TemplateTail"){o(),t.push(G(s.value,true));break}else m("Expected `}` to close template interpolation");}return P({type:"TemplateLiteral",quasis:t,expressions:n},e)},V=()=>{let e=i();return e.type!=="Identifier"&&m(`Expected JSX identifier but got '${e.value||e.type}'`),P({type:"JSXIdentifier",name:o().value},e)},ie=()=>{let e=V();if(r(":")){o();let t=V();return c({type:"JSXNamespacedName",namespace:e,name:t},e,t)}for(;r(".");){o();let t=V();e=c({type:"JSXMemberExpression",object:e,property:t},e,t);}return e},U=e=>e.type==="JSXIdentifier"?e.name:e.type==="JSXNamespacedName"?`${U(e.namespace)}:${U(e.name)}`:`${U(e.object)}.${U(e.property)}`,Se=()=>{let e=i();if(e.type==="String")return o(),P({type:"Literal",value:S(e.value.slice(1,-1)),raw:e.value},e);if(r("{")){let t=o(),n=X(),s=y("}");return c({type:"JSXExpressionContainer",expression:n},t,s)}return r("<")?te():m(`Invalid JSX attribute value '${e.value||e.type}'`)},xe=()=>{let e=[];for(;!r(">")&&!r("/>")&&!A();){if(r("{")){let s=o();y("...");let h=X(),w=y("}");e.push(c({type:"JSXSpreadAttribute",argument:h},s,w));continue}let t=V();if(r(":")){o();let s=V();t=c({type:"JSXNamespacedName",namespace:t,name:s},t,s);}let n=null;r("=")&&(o(),n=Se()),e.push(c({type:"JSXAttribute",name:t,value:n},t,n??t));}return e},le=()=>{let e=[];for(;!(r("</")||A());){let t=i();if(t.type==="JSXText")o(),e.push(P({type:"JSXText",value:t.value,raw:t.value},t));else if(r("{")){let n=o();if(r("}")){let s=o(),h=P({type:"JSXEmptyExpression"},n);e.push(c({type:"JSXExpressionContainer",expression:h},n,s));}else {let s=X(),h=y("}");e.push(c({type:"JSXExpressionContainer",expression:s},n,h));}}else r("<")?e.push(te()):m(`Unexpected token in JSX children '${t.value||t.type}'`);}return e},te=()=>{let e=y("<");if(r(">")){let Z=o(),re=c({type:"JSXOpeningFragment"},e,Z),Ke=le(),Re=y("</"),ue=y(">"),Ue=c({type:"JSXClosingFragment"},Re,ue);return c({type:"JSXFragment",openingFragment:re,children:Ke,closingFragment:Ue},e,ue)}let t=ie(),n=xe();if(r("/>")){let Z=o(),re=c({type:"JSXOpeningElement",name:t,attributes:n,selfClosing:true},e,Z);return c({type:"JSXElement",openingElement:re,children:[],closingElement:null},e,Z)}let s=y(">"),h=c({type:"JSXOpeningElement",name:t,attributes:n,selfClosing:false},e,s),w=le(),j=y("</"),O=i(),J=ie();U(J)!==U(t)&&m(`JSX closing tag </${U(J)}> does not match opening <${U(t)}>`,O);let Y=y(">"),$e=c({type:"JSXClosingElement",name:J},j,Y);return c({type:"JSXElement",openingElement:h,children:w,closingElement:$e},e,Y)},Te=()=>{let e=i();if(b("async")){let t=i(1);return t.value==="("||t.type==="Identifier"?(o(),B(true,e)):m("Unexpected 'async'")}if(r("(")&&E()||e.type==="Identifier"&&i(1).type==="Punctuator"&&i(1).value==="=>")return B(false,e);if(e.type==="Number")return o(),P({type:"Literal",value:Number(e.value),raw:e.value},e);if(e.type==="String")return o(),P({type:"Literal",value:S(e.value.slice(1,-1)),raw:e.value},e);if(e.type==="Template")return o(),P({type:"TemplateLiteral",expressions:[],quasis:[G(e.value,true)]},e);if(e.type==="TemplateHead")return be(e);if(e.type==="Keyword")return e.value==="true"?(o(),P({type:"Literal",value:true,raw:"true"},e)):e.value==="false"?(o(),P({type:"Literal",value:false,raw:"false"},e)):e.value==="null"?(o(),P({type:"Literal",value:null,raw:"null"},e)):e.value==="new"?m("'new' is not supported \u2014 the language has no constructors (FP / portable IR). Use a factory function provided via DI (e.g. `now()` instead of `new Date()`)."):e.value==="function"?m("Anonymous functions are not supported \u2014 use an arrow function"):m(`'${e.value}' is not supported in this language`);if(e.type==="Identifier")return o(),P({type:"Identifier",name:e.value},e);if(r("(")){o();let t=x();return y(")"),t}return r("[")?ge():r("{")?ve():r("<")?te():m(`Unexpected token '${e.value||e.type}'`)},{parseType:H,parseTypeParamList:ke,parseTypeInScope:we}=me({tokens:N,pos:()=>l,peek:i,next:o,isP:r,isK:b,expectP:y,fail:m,unescape:S}),Ne=()=>{let e=o(),t=a(),n=[],s=[];r("<")&&(s=ke(),n=s.map(j=>j.name)),y("=");let h=we(s),w=c({type:"TSTypeAliasDeclaration",id:t,typeParameters:n,typeAnnotation:h},e,v());return r(";")&&o(),w},R=()=>{let e=i();if(e.type==="Identifier"&&e.value==="type"&&i(1).type==="Identifier"&&i(2).type==="Punctuator"&&(i(2).value==="="||i(2).value==="<"))return Ne();if(b("const")||b("let")||b("var")){let s=pe();return r(";")&&o(),s}if(b("if"))return Je();if(b("for"))return Ce();if(b("while"))return Oe();if(b("do"))return je();if(b("break")||b("continue"))return Ae();if(b("return"))return De();if(b("throw"))return Xe();if(b("try"))return Fe();if(b("switch"))return Le();if(b("import"))return Ee();if(b("export"))return Ie();if(r("{"))return W();if((b("function")||b("async")&&i(1).type==="Keyword"&&i(1).value==="function")&&m("Function declarations are not supported \u2014 use 'const fn = () => \u2026'"),r(";"))return o(),P({type:"EmptyStatement"},e);e.type==="Keyword"&&Ye.has(e.value)&&m(`'${e.value}' is not supported in this language`);let t=x(),n=r(";")?o():v();return c({type:"ExpressionStatement",expression:t},t,n)},pe=()=>{let e=o(),t=e.value,n=p(new Set),s=null;r("=")?(o(),s=x()):t==="const"&&m("'const' declarations must be initialized");let h=c({type:"VariableDeclarator",id:n,init:s},n,s??n);return c({type:"VariableDeclaration",kind:t,declarations:[h]},e,s??n)},Pe=()=>{let e=i();return e.type!=="String"&&m("Expected module specifier string"),o(),P({type:"Literal",value:S(e.value.slice(1,-1)),raw:e.value},e)},Ee=()=>{let e=o(),t=[];if(i().type!=="String"){if(i().type==="Identifier"){let s=a();t.push(c({type:"ImportDefaultSpecifier",local:s},s,s)),r(",")&&o();}if(r("*")){let s=o();K("as")||m("Expected 'as' after '*' in import"),o();let h=a();t.push(c({type:"ImportNamespaceSpecifier",local:h},s,h));}else if(r("{")){for(o();!r("}")&&!A();){let s=a(),h=s;if(K("as")&&(o(),h=a()),t.push(c({type:"ImportSpecifier",imported:s,local:h},s,h)),r(","))o();else break}y("}");}K("from")||m("Expected 'from' in import declaration"),o();}let n=Pe();return r(";")&&o(),P({type:"ImportDeclaration",specifiers:t,source:n},e)},Ie=()=>{let e=o();if(b("default")){o();let t=x();return r(";")&&o(),P({type:"ExportDefaultDeclaration",declaration:t},e)}if(b("const")||b("let")||b("var")){let t=pe();return r(";")&&o(),P({type:"ExportNamedDeclaration",declaration:t,specifiers:[],source:null},e)}if(r("{")){o();let t=[];for(;!r("}")&&!A();){let n=a(),s=n;if(K("as")&&(o(),s=a()),t.push(c({type:"ExportSpecifier",local:n,exported:s},n,s)),r(","))o();else break}return y("}"),r(";")&&o(),P({type:"ExportNamedDeclaration",declaration:null,specifiers:t,source:null},e)}return m("Expected 'const', '{', or 'default' after 'export'")},ce=()=>i().type==="Identifier"&&i().value==="of",ne=()=>b("in"),Ce=()=>{let e=o();y("(");let t=null,n=null;if(!r(";"))if(b("const")||b("let")||b("var")){let j=o(),O=a();if(r(":")&&(o(),O.typeAnnotation=H(new Set)),ce()||ne()){let J=c({type:"VariableDeclarator",id:O,init:null},O,O);n=c({type:"VariableDeclaration",kind:j.value,declarations:[J]},j,O);}else {let J=null;r("=")?(o(),J=x(true)):j.value==="const"&&m("'const' declarations must be initialized");let Y=c({type:"VariableDeclarator",id:O,init:J},O,J??O);t=c({type:"VariableDeclaration",kind:j.value,declarations:[Y]},j,J??O);}}else {let j=x(true);ce()||ne()?n=j:t=j;}if(n){let j=ne();o();let O=x();y(")");let J=R();return c(j?{type:"ForInStatement",left:n,right:O,body:J}:{type:"ForOfStatement",left:n,right:O,body:J,await:false},e,J)}y(";");let s=r(";")?null:x();y(";");let h=r(")")?null:x();y(")");let w=R();return c({type:"ForStatement",init:t,test:s,update:h,body:w},e,w)},je=()=>{let e=o(),t=R();b("while")||m("Expected 'while' after the 'do' body"),o(),y("(");let n=x(),s=y(")");return r(";")&&o(),c({type:"DoWhileStatement",body:t,test:n},e,s)},Ae=()=>{let e=o(),t=e.value==="break"?"BreakStatement":"ContinueStatement",n=r(";")?o():v();return c({type:t,label:null},e,n)},Oe=()=>{let e=o();y("(");let t=x();y(")");let n=R();return c({type:"WhileStatement",test:t,body:n},e,n)},Je=()=>{let e=o();y("(");let t=x();y(")");let n=R(),s=null;return b("else")&&(o(),s=R()),c({type:"IfStatement",test:t,consequent:n,alternate:s},e,s??n)},De=()=>{let e=o(),t=null;!r(";")&&!r("}")&&!A()&&(t=x());let n=r(";")?o():v();return c({type:"ReturnStatement",argument:t},e,n)},Xe=()=>{let e=o(),t=x(),n=r(";")?o():v();return c({type:"ThrowStatement",argument:t},e,n)},Fe=()=>{let e=o(),t=W(),n=null,s=null;if(b("catch")){let h=o(),w=null;r("(")&&(o(),w=a(),y(")"));let j=W();n=c({type:"CatchClause",param:w,body:j},h,j);}return b("finally")&&(o(),s=W()),!n&&!s&&m("'try' requires a 'catch' or 'finally' clause"),c({type:"TryStatement",block:t,handler:n,finalizer:s},e,s??n??t)},Le=()=>{let e=o();y("(");let t=x();y(")"),y("{");let n=[];for(;!r("}")&&!A();){let h=i(),w=null;b("case")?(o(),w=x()):b("default")?o():m("Expected 'case' or 'default' in switch"),y(":");let j=[];for(;!r("}")&&!b("case")&&!b("default")&&!A();)j.push(R());n.push(c({type:"SwitchCase",test:w,consequent:j},h,v()??h));}let s=y("}");return c({type:"SwitchStatement",discriminant:t,cases:n},e,s)},W=()=>{let e=y("{"),t=[];for(;!r("}")&&!A();)t.push(R());return c({type:"BlockStatement",body:t},e,y("}"))};return {parseExpr:x,parseProgram:()=>{let e=i(),t=[];for(;!A();)t.push(R());return c({type:"Program",sourceType:"module",body:t},e,v()??e)},eof:A,fail:m}}function Qe(u){return he(u).parseProgram()}function et(u){let{parseExpr:N,eof:l,fail:i}=he(u),o=N();return l()||i("Unexpected token after expression"),o}exports.KEYWORDS=de;exports.LexError=Q;exports.ParseError=ee;exports.parse=Qe;exports.parseExpression=et;exports.tokenize=se;
package/dist/index.d.cts CHANGED
@@ -12,7 +12,7 @@ interface SourceLocation {
12
12
  readonly start: Position;
13
13
  readonly end: Position;
14
14
  }
15
- type TokenType = "Identifier" | "Keyword" | "Number" | "String" | "Template" | "TemplateHead" | "TemplateMiddle" | "TemplateTail" | "Punctuator" | "EOF";
15
+ type TokenType = "Identifier" | "Keyword" | "Number" | "String" | "Template" | "TemplateHead" | "TemplateMiddle" | "TemplateTail" | "Punctuator" | "JSXText" | "EOF";
16
16
  interface Token {
17
17
  readonly type: TokenType;
18
18
  /** O lexema cru, como aparece na fonte (sem decodificar escapes). */
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ interface SourceLocation {
12
12
  readonly start: Position;
13
13
  readonly end: Position;
14
14
  }
15
- type TokenType = "Identifier" | "Keyword" | "Number" | "String" | "Template" | "TemplateHead" | "TemplateMiddle" | "TemplateTail" | "Punctuator" | "EOF";
15
+ type TokenType = "Identifier" | "Keyword" | "Number" | "String" | "Template" | "TemplateHead" | "TemplateMiddle" | "TemplateTail" | "Punctuator" | "JSXText" | "EOF";
16
16
  interface Token {
17
17
  readonly type: TokenType;
18
18
  /** O lexema cru, como aparece na fonte (sem decodificar escapes). */
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import {TSLiteError}from'@tslite/core';var $=class extends TSLiteError{constructor(p,i,r){super("lex-error",`${p} (${i.line}:${i.column})`,{position:i,index:r});this.position=i;this.index=r;this.name="LexError";}},G=new Set(["const","if","else","return","async","await","true","false","null","typeof","let","var","function","class","new","for","while","do","this","throw","try","catch","finally","switch","case","break","continue","default","void","delete","instanceof","in","yield","import","export","extends","super","debugger","with"]),ve=["...","===","!==","=>","|>","?.","??","==","!=","<=",">=","&&","||","|","++","--","+=","-=","*=","/=","%=","+","-","*","/","%","<",">","!","?",":",".",",",";","=","(",")","[","]","{","}"],_=f=>f>="a"&&f<="z"||f>="A"&&f<="Z"||f==="_"||f==="$",be=f=>_(f)||f>="0"&&f<="9",F=f=>f>="0"&&f<="9",H=f=>F(f)||f>="a"&&f<="f"||f>="A"&&f<="F";function z(f){let x=[],p=0,i=1,r=0,b=()=>({line:i,column:r}),u=(l=0)=>f[p+l]??"",a=l=>{throw new $(l,b(),p)},s=()=>{let l=f[p++];return l==="\r"?(f[p]===`
2
- `&&p++,i++,r=0):l===`
3
- `||l==="\u2028"||l==="\u2029"?(i++,r=0):r++,l},w=l=>l===`
4
- `||l==="\r"||l==="\u2028"||l==="\u2029",y=()=>{for(;;){let l=u();if(l===" "||l===" "||l==="\f"||l==="\v"||w(l))s();else if(l==="/"&&u(1)==="/")for(;p<f.length&&!w(u());)s();else if(l==="/"&&u(1)==="*")for(s(),s();;){if(p>=f.length&&a("Unterminated block comment"),u()==="*"&&u(1)==="/"){s(),s();break}s();}else break}},h=(l,m,N,k)=>{x.push({type:l,value:m,start:N,end:p,loc:{start:k,end:b()}});},c=l=>{for(s();p<f.length;){let m=u();if(m===l)return s(),f.slice(S,p);if(w(m)&&a("Unterminated string literal"),m==="\\"){s(),p>=f.length&&a("Unterminated string literal"),s();continue}s();}return a("Unterminated string literal")},L=()=>{if(u()==="0"&&(u(1)==="x"||u(1)==="X")){for(s(),s(),H(u())||a("Invalid hexadecimal literal");H(u());)s();return}if(u()==="0"&&(u(1)==="b"||u(1)==="B")){for(s(),s(),u()!=="0"&&u()!=="1"&&a("Invalid binary literal");u()==="0"||u()==="1";)s();return}if(u()==="0"&&(u(1)==="o"||u(1)==="O")){for(s(),s(),u()>="0"&&u()<="7"||a("Invalid octal literal");u()>="0"&&u()<="7";)s();return}for(;F(u());)s();if(u()===".")for(s();F(u());)s();if(u()==="e"||u()==="E")for(s(),(u()==="+"||u()==="-")&&s(),F(u())||a("Invalid exponent");F(u());)s();},g=()=>{let l=p;for(;p<f.length;){let m=u();if(m==="`"){let N=f.slice(l,p);return s(),{raw:N,interp:false}}if(m==="$"&&u(1)==="{"){let N=f.slice(l,p);return s(),s(),{raw:N,interp:true}}if(m==="\\"){if(s(),p>=f.length)break;s();continue}s();}return a("Unterminated template literal")},S=0,v=0,d=[];for(;;){y(),S=p;let l=b();if(p>=f.length){h("EOF","",S,l);break}let m=u();if(_(m)){for(;be(u());)s();let k=f.slice(S,p);h(G.has(k)?"Keyword":"Identifier",k,S,l);continue}if(F(m)||m==="."&&F(u(1))){L(),h("Number",f.slice(S,p),S,l);continue}if(m==='"'||m==="'"){let k=c(m);h("String",k,S,l);continue}if(m==="`"){s();let{raw:k,interp:O}=g();O?(h("TemplateHead",k,S,l),d.push(v)):h("Template",k,S,l);continue}if(m==="{"){s(),h("Punctuator","{",S,l),v++;continue}if(m==="}"){if(d.length>0&&v===d[d.length-1]){d.pop(),s();let{raw:k,interp:O}=g();h(O?"TemplateMiddle":"TemplateTail",k,S,l),O&&d.push(v);continue}s(),h("Punctuator","}",S,l),v--;continue}if(m==="?"&&u(1)==="."&&F(u(2))){s(),h("Punctuator","?",S,l);continue}let N=ve.find(k=>f.startsWith(k,p));if(N){for(let k=0;k<N.length;k++)s();h("Punctuator",N,S,l);continue}a(`Unexpected character '${m}'`);}return x}var Y=f=>{let{peek:x,next:p,isP:i,isK:r,expectP:b,fail:u,unescape:a}=f,s=()=>{let v=0;for(let d=f.pos();d<f.tokens.length;d++){let l=f.tokens[d];if(l.type==="EOF")return false;if(l.type==="Punctuator"){if(["(","[","{","<"].includes(l.value))v++;else if([")","]","}",">"].includes(l.value)&&(v--,v===0)){let m=f.tokens[d+1];return !!m&&m.type==="Punctuator"&&m.value==="=>"}}}return false},w=()=>{b("<");let v=[];for(;!i(">");){let d=x();d.type!=="Identifier"&&u("Expected type parameter name"),p(),v.push(d.value),i(">")||b(",");}return b(">"),v},y=v=>{b("<");let d=[];for(;!i(">");)d.push(h(v)),i(">")||b(",");return b(">"),d},h=v=>{let d=c(v);if(!i("|"))return d;let l=[d];for(;i("|");)p(),l.push(c(v));return {t:"union",of:l}},c=v=>{let d=L(v);for(;i("[")&&x(1).type==="Punctuator"&&x(1).value==="]";)p(),p(),d={t:"array",items:d};return d},L=v=>{if(i("<")){let l=w(),m=new Set(v);return l.forEach(N=>m.add(N)),g(m)}if(i("(")){if(s())return g(v);p();let l=h(v);return b(")"),l}if(i("{"))return S(v);let d=x();if(d.type==="String")return p(),{t:"literal",value:a(d.value.slice(1,-1))};if(d.type==="Number")return p(),{t:"literal",value:Number(d.value)};if(r("true"))return p(),{t:"literal",value:true};if(r("false"))return p(),{t:"literal",value:false};if(r("null"))return p(),{t:"null"};if(d.type==="Identifier"){switch(p(),d.value){case "string":return {t:"string"};case "number":return {t:"number"};case "boolean":return {t:"boolean"};case "any":return {t:"any"};case "unknown":return {t:"unknown"};case "undefined":return {t:"undefined"}}let l=i("<")?y(v):[];return v.has(d.value)&&l.length===0?{t:"var",name:d.value}:{t:"apply",name:d.value,args:l}}return u(`Expected a type but got '${d.value||d.type}'`)},g=v=>{b("(");let d=[];for(;!i(")");){let m=x();m.type!=="Identifier"&&u("Expected parameter name in function type"),p();let N=i("?");N&&p(),b(":");let k=h(v);d.push({name:m.value,type:k,...N?{optional:true}:{}}),i(")")||b(",");}b(")"),b("=>");let l=h(v);return {t:"fn",params:d,returns:l}},S=v=>{b("{");let d={};for(;!i("}");){let l=x(),m;if(l.type==="Identifier"||l.type==="Keyword")p(),m=l.value;else if(l.type==="String")p(),m=a(l.value.slice(1,-1));else return u("Expected property name in object type");let N=i("?");N&&p(),b(":");let k=h(v);if(d[m]={type:k,...N?{optional:true}:{}},i(";")||i(","))p();else break}return b("}"),{t:"object",props:d}};return {parseType:h,parseTypeParamList:w}};var M=class extends TSLiteError{constructor(p,i,r){super("parse-error",`${p} (${i.line}:${i.column})`,{position:i,index:r});this.position=i;this.index=r;this.name="ParseError";}},xe={"??":1,"||":2,"&&":3,"==":4,"===":4,"!=":4,"!==":4,"<":5,"<=":5,">":5,">=":5,"+":6,"-":6,"*":7,"/":7,"%":7},ke=new Set(["??","||","&&"]),Te=new Set(["class","import","export","debugger","with"]),Se=new Set(["=","+=","-=","*=","/=","%="]);function X(f){let x=z(f),p=0,i=(e=0)=>x[Math.min(p+e,x.length-1)],r=()=>x[p++],b=()=>x[p-1],u=()=>i().type==="EOF",a=e=>i().type==="Punctuator"&&i().value===e,s=e=>i().type==="Keyword"&&i().value===e,w=(e,n=i())=>{throw new M(e,n.loc.start,n.start)},y=e=>(a(e)||w(`Expected '${e}' but got '${i().value||i().type}'`),r()),h=(e,n)=>{let t=b()??n;return Object.assign(e,{start:n.start,end:t.end,loc:{start:n.loc.start,end:t.loc.end}})},c=(e,n,t)=>Object.assign(e,{start:n.start,end:t.end,loc:{start:n.loc.start,end:t.loc.end}}),L=e=>{let n="";for(let t=0;t<e.length;t++){if(e[t]!=="\\"){n+=e[t];continue}let o=e[++t];switch(o){case "n":n+=`
5
- `;break;case "t":n+=" ";break;case "r":n+="\r";break;case "b":n+="\b";break;case "f":n+="\f";break;case "v":n+="\v";break;case "0":n+="\0";break;case "x":n+=String.fromCharCode(parseInt(e.slice(t+1,t+3),16)),t+=2;break;case "u":if(e[t+1]==="{"){let T=e.indexOf("}",t);n+=String.fromCodePoint(parseInt(e.slice(t+2,T),16)),t=T;}else n+=String.fromCharCode(parseInt(e.slice(t+1,t+5),16)),t+=4;break;default:n+=o;}}return n},g=()=>S(),S=()=>{let e=v(),n=i();if(n.type==="Punctuator"&&Se.has(n.value)){r();let t=S();return c({type:"AssignmentExpression",operator:n.value,left:e,right:t},e,t)}return e},v=()=>{let e=d();for(;a("|>");){r();let n=d();e=c({type:"CallExpression",callee:n,arguments:[e],optional:false},e,n);}return e},d=()=>{let e=l(0);if(!a("?"))return e;r();let n=g();y(":");let t=g();return c({type:"ConditionalExpression",test:e,consequent:n,alternate:t},e,t)},l=e=>{let n=m();for(;;){let t=i();if(t.type!=="Punctuator")break;let o=xe[t.value];if(!o||o<=e)break;r();let T=l(o);n=c({type:ke.has(t.value)?"LogicalExpression":"BinaryExpression",operator:t.value,left:n,right:T},n,T);}return n},m=()=>{let e=i();return e.type==="Punctuator"&&(e.value==="++"||e.value==="--")?(r(),h({type:"UpdateExpression",operator:e.value,prefix:true,argument:m()},e)):s("await")?(r(),h({type:"AwaitExpression",argument:m()},e)):s("typeof")||s("void")||s("delete")?(r(),h({type:"UnaryExpression",operator:e.value,prefix:true,argument:m()},e)):e.type==="Punctuator"&&(e.value==="!"||e.value==="-"||e.value==="+")?(r(),h({type:"UnaryExpression",operator:e.value,prefix:true,argument:m()},e)):N()},N=()=>{let e=k();for(;i().type==="Identifier"&&i().value==="as";){r();let n=D(new Set);e=c({type:"TSAsExpression",expression:e,typeAnnotation:n},e,b());}return e},k=()=>{let e=W(),n=false;for(;;)if(a("?."))if(r(),n=true,a("(")){let{args:t,close:o}=O();e=c({type:"CallExpression",callee:e,arguments:t,optional:true},e,o);}else if(a("[")){r();let t=g(),o=y("]");e=c({type:"MemberExpression",object:e,property:t,computed:true,optional:true},e,o);}else {let t=i();t.type!=="Identifier"&&t.type!=="Keyword"&&w("Expected property name after '?.'"),r();let o=h({type:"Identifier",name:t.value},t);e=c({type:"MemberExpression",object:e,property:o,computed:false,optional:true},e,o);}else if(a(".")){r();let t=i();t.type!=="Identifier"&&t.type!=="Keyword"&&w("Expected property name"),r();let o=h({type:"Identifier",name:t.value},t);e=c({type:"MemberExpression",object:e,property:o,computed:false,optional:false},e,o);}else if(a("[")){r();let t=g(),o=y("]");e=c({type:"MemberExpression",object:e,property:t,computed:true,optional:false},e,o);}else if(a("(")){let{args:t,close:o}=O();e=c({type:"CallExpression",callee:e,arguments:t,optional:false},e,o);}else if(a("++")||a("--")){let t=r();e=c({type:"UpdateExpression",operator:t.value,prefix:false,argument:e},e,t);}else break;return n?c({type:"ChainExpression",expression:e},e,e):e},O=()=>{y("(");let e=[];for(;!a(")");)e.push(V()),a(")")||y(",");return {args:e,close:y(")")}},V=()=>{if(a("...")){let e=r(),n=g();return c({type:"SpreadElement",argument:n},e,n)}return g()},j=()=>{let e=i();return e.type!=="Identifier"&&w("Expected identifier"),r(),h({type:"Identifier",name:e.value},e)},Z=()=>{let e=0;for(let n=p;n<x.length;n++){let t=x[n];if(t.type==="EOF")return false;if(t.type==="Punctuator"){if(t.value==="("||t.value==="["||t.value==="{")e++;else if((t.value===")"||t.value==="]"||t.value==="}")&&(e--,e===0)){let o=x[n+1];return !o||o.type!=="Punctuator"?false:o.value==="=>"?true:o.value===":"?J(n+2):false}}}return false},J=e=>{let n=0;for(let t=e;t<x.length;t++){let o=x[t];if(o.type==="EOF")return false;if(o.type==="Punctuator")if(["(","[","{","<"].includes(o.value))n++;else if([")","]","}",">"].includes(o.value)){if(n===0)return false;n--;}else {if(n===0&&o.value==="=>")return true;if(n===0&&(o.value===";"||o.value===","))return false}}return false},Q=(e=new Set)=>{y("(");let n=[];for(;!a(")");){if(a("...")){let t=r(),o=j();a(":")&&(r(),o.typeAnnotation=D(e)),n.push(c({type:"RestElement",argument:o},t,o));}else {let t=j();a(":")&&(r(),t.typeAnnotation=D(e)),n.push(t);}a(")")||y(",");}return y(")"),n},R=(e,n)=>{let t=a("(")?Q():[j()],o;a(":")&&(r(),o=D(new Set)),y("=>");let T=a("{")?K():g();return h({type:"ArrowFunctionExpression",params:t,body:T,async:e,expression:T.type!=="BlockStatement",generator:false,...o?{returnType:o}:{}},n)},ee=()=>{let e=y("["),n=[];for(;!a("]");){if(a(",")){r(),n.push(null);continue}n.push(V()),a("]")||y(",");}return c({type:"ArrayExpression",elements:n},e,y("]"))},te=()=>{let e=y("{"),n=[];for(;!a("}");){if(a("...")){let t=r(),o=g();n.push(c({type:"SpreadElement",argument:o},t,o));}else {let t=i(),o,T=false;if(a("["))T=true,r(),o=g(),y("]");else if(t.type==="String")r(),o=h({type:"Literal",value:L(t.value.slice(1,-1)),raw:t.value},t);else if(t.type==="Number")r(),o=h({type:"Literal",value:Number(t.value),raw:t.value},t);else if(t.type==="Identifier"||t.type==="Keyword")r(),o=h({type:"Identifier",name:t.value},t);else return w("Invalid property key");if(a(":")){r();let P=g();n.push(c({type:"Property",key:o,value:P,kind:"init",method:false,shorthand:false,computed:T},t,P));}else n.push(c({type:"Property",key:o,value:o,kind:"init",method:false,shorthand:true,computed:false},t,o));}a("}")||y(",");}return c({type:"ObjectExpression",properties:n},e,y("}"))},U=(e,n)=>({type:"TemplateElement",value:{raw:e,cooked:L(e)},tail:n}),ne=e=>{r();let n=[U(e.value,false)],t=[];for(;;){t.push(g());let o=i();if(o.type==="TemplateMiddle")r(),n.push(U(o.value,false));else if(o.type==="TemplateTail"){r(),n.push(U(o.value,true));break}else w("Expected `}` to close template interpolation");}return h({type:"TemplateLiteral",quasis:n,expressions:t},e)},W=()=>{let e=i();if(s("async")){let n=i(1);return n.value==="("||n.type==="Identifier"?(r(),R(true,e)):w("Unexpected 'async'")}if(a("(")&&Z()||e.type==="Identifier"&&i(1).type==="Punctuator"&&i(1).value==="=>")return R(false,e);if(e.type==="Number")return r(),h({type:"Literal",value:Number(e.value),raw:e.value},e);if(e.type==="String")return r(),h({type:"Literal",value:L(e.value.slice(1,-1)),raw:e.value},e);if(e.type==="Template")return r(),h({type:"TemplateLiteral",expressions:[],quasis:[U(e.value,true)]},e);if(e.type==="TemplateHead")return ne(e);if(e.type==="Keyword")return e.value==="true"?(r(),h({type:"Literal",value:true,raw:"true"},e)):e.value==="false"?(r(),h({type:"Literal",value:false,raw:"false"},e)):e.value==="null"?(r(),h({type:"Literal",value:null,raw:"null"},e)):e.value==="new"?re(e):e.value==="function"?w("Anonymous functions are not supported \u2014 use an arrow function"):w(`'${e.value}' is not supported in this language`);if(e.type==="Identifier")return r(),h({type:"Identifier",name:e.value},e);if(a("(")){r();let n=g();return y(")"),n}return a("[")?ee():a("{")?te():w(`Unexpected token '${e.value||e.type}'`)},re=e=>{r();let n=W();for(;;)if(a(".")){r();let t=i();t.type!=="Identifier"&&t.type!=="Keyword"&&w("Expected property name"),r();let o=h({type:"Identifier",name:t.value},t);n=c({type:"MemberExpression",object:n,property:o,computed:false,optional:false},n,o);}else if(a("[")){r();let t=g(),o=y("]");n=c({type:"MemberExpression",object:n,property:t,computed:true,optional:false},n,o);}else break;if(a("(")){let{args:t,close:o}=O();return c({type:"NewExpression",callee:n,arguments:t},e,o)}return c({type:"NewExpression",callee:n,arguments:[]},e,n)},{parseType:D,parseTypeParamList:oe}=Y({tokens:x,pos:()=>p,peek:i,next:r,isP:a,isK:s,expectP:y,fail:w,unescape:L}),se=()=>{let e=r(),n=j(),t=new Set,o=[];a("<")&&(o=oe(),o.forEach(E=>t.add(E))),y("=");let T=D(t),P=c({type:"TSTypeAliasDeclaration",id:n,typeParameters:o,typeAnnotation:T},e,b());return a(";")&&r(),P},C=()=>{let e=i();if(e.type==="Identifier"&&e.value==="type"&&i(1).type==="Identifier"&&i(2).type==="Punctuator"&&(i(2).value==="="||i(2).value==="<"))return se();if(s("const")||s("let")||s("var")){let o=ae();return a(";")&&r(),o}if(s("if"))return ce();if(s("for"))return ie();if(s("while"))return pe();if(s("do"))return le();if(s("break")||s("continue"))return ue();if(s("return"))return fe();if(s("throw"))return de();if(s("try"))return ye();if(s("switch"))return me();if(a("{"))return K();if((s("function")||s("async")&&i(1).type==="Keyword"&&i(1).value==="function")&&w("Function declarations are not supported \u2014 use 'const fn = () => \u2026'"),a(";"))return r(),h({type:"EmptyStatement"},e);e.type==="Keyword"&&Te.has(e.value)&&w(`'${e.value}' is not supported in this language`);let n=g(),t=a(";")?r():b();return c({type:"ExpressionStatement",expression:n},n,t)},ae=()=>{let e=r(),n=e.value,t=j();a(":")&&(r(),t.typeAnnotation=D(new Set));let o=null;a("=")?(r(),o=g()):n==="const"&&w("'const' declarations must be initialized");let T=c({type:"VariableDeclarator",id:t,init:o},t,o??t);return c({type:"VariableDeclaration",kind:n,declarations:[T]},e,o??t)},q=()=>i().type==="Identifier"&&i().value==="of",B=()=>s("in"),ie=()=>{let e=r();y("(");let n=null,t=null;if(!a(";"))if(s("const")||s("let")||s("var")){let E=r(),I=j();if(a(":")&&(r(),I.typeAnnotation=D(new Set)),q()||B()){let A=c({type:"VariableDeclarator",id:I,init:null},I,I);t=c({type:"VariableDeclaration",kind:E.value,declarations:[A]},E,I);}else {let A=null;a("=")?(r(),A=g()):E.value==="const"&&w("'const' declarations must be initialized");let he=c({type:"VariableDeclarator",id:I,init:A},I,A??I);n=c({type:"VariableDeclaration",kind:E.value,declarations:[he]},E,A??I);}}else {let E=g();q()||B()?t=E:n=E;}if(t){let E=B();r();let I=g();y(")");let A=C();return c(E?{type:"ForInStatement",left:t,right:I,body:A}:{type:"ForOfStatement",left:t,right:I,body:A,await:false},e,A)}y(";");let o=a(";")?null:g();y(";");let T=a(")")?null:g();y(")");let P=C();return c({type:"ForStatement",init:n,test:o,update:T,body:P},e,P)},le=()=>{let e=r(),n=C();s("while")||w("Expected 'while' after the 'do' body"),r(),y("(");let t=g(),o=y(")");return a(";")&&r(),c({type:"DoWhileStatement",body:n,test:t},e,o)},ue=()=>{let e=r(),n=e.value==="break"?"BreakStatement":"ContinueStatement",t=a(";")?r():b();return c({type:n,label:null},e,t)},pe=()=>{let e=r();y("(");let n=g();y(")");let t=C();return c({type:"WhileStatement",test:n,body:t},e,t)},ce=()=>{let e=r();y("(");let n=g();y(")");let t=C(),o=null;return s("else")&&(r(),o=C()),c({type:"IfStatement",test:n,consequent:t,alternate:o},e,o??t)},fe=()=>{let e=r(),n=null;!a(";")&&!a("}")&&!u()&&(n=g());let t=a(";")?r():b();return c({type:"ReturnStatement",argument:n},e,t)},de=()=>{let e=r(),n=g(),t=a(";")?r():b();return c({type:"ThrowStatement",argument:n},e,t)},ye=()=>{let e=r(),n=K(),t=null,o=null;if(s("catch")){let T=r(),P=null;a("(")&&(r(),P=j(),y(")"));let E=K();t=c({type:"CatchClause",param:P,body:E},T,E);}return s("finally")&&(r(),o=K()),!t&&!o&&w("'try' requires a 'catch' or 'finally' clause"),c({type:"TryStatement",block:n,handler:t,finalizer:o},e,o??t??n)},me=()=>{let e=r();y("(");let n=g();y(")"),y("{");let t=[];for(;!a("}")&&!u();){let T=i(),P=null;s("case")?(r(),P=g()):s("default")?r():w("Expected 'case' or 'default' in switch"),y(":");let E=[];for(;!a("}")&&!s("case")&&!s("default")&&!u();)E.push(C());t.push(c({type:"SwitchCase",test:P,consequent:E},T,b()??T));}let o=y("}");return c({type:"SwitchStatement",discriminant:n,cases:t},e,o)},K=()=>{let e=y("{"),n=[];for(;!a("}")&&!u();)n.push(C());return c({type:"BlockStatement",body:n},e,y("}"))};return {parseExpr:g,parseProgram:()=>{let e=i(),n=[];for(;!u();)n.push(C());return c({type:"Program",sourceType:"module",body:n},e,b()??e)},eof:u,fail:w}}function Ne(f){return X(f).parseProgram()}function Ee(f){let{parseExpr:x,eof:p,fail:i}=X(f),r=x();return p()||i("Unexpected token after expression"),r}export{G as KEYWORDS,$ as LexError,M as ParseError,Ne as parse,Ee as parseExpression,z as tokenize};
1
+ import {TSLiteError}from'@tslite/core';var Q=class extends TSLiteError{constructor(l,i,o){super("lex-error",`${l} (${i.line}:${i.column})`,{position:i,index:o});this.position=i;this.index=o;this.name="LexError";}},de=new Set(["const","if","else","return","async","await","true","false","null","typeof","let","var","function","class","new","for","while","do","this","throw","try","catch","finally","switch","case","break","continue","default","void","delete","instanceof","in","yield","import","export","extends","super","debugger","with"]),Be=["...","===","!==","=>","?.","??","==","!=","<=",">=","&&","||","|","&","++","--","+=","-=","*=","/=","%=","**","<<","+","-","*","/","%","<",">","!","?",":",".",",",";","=","^","~","(",")","[","]","{","}"],oe=u=>u>="a"&&u<="z"||u>="A"&&u<="Z"||u==="_"||u==="$",ye=u=>oe(u)||u>="0"&&u<="9",M=u=>u>="0"&&u<="9",fe=u=>M(u)||u>="a"&&u<="f"||u>="A"&&u<="F",qe=u=>ye(u)||u==="-",ze=new Set(["(","[","{",",",";",":","?","=>","...","=","+","-","*","/","%","<","<=",">",">=","==","===","!=","!==","&&","||","??","!","+=","-=","*=","/=","%="]),Ve=new Set(["return","typeof","await","delete","void","in","instanceof","else","case","yield","throw"]);function se(u){let N=[],l=0,i=1,o=0,v=()=>({line:i,column:o}),d=(g=0)=>u[l+g]??"",A=g=>{throw new Q(g,v(),l)},r=()=>{let g=u[l++];return g==="\r"?(u[l]===`
2
+ `&&l++,i++,o=0):g===`
3
+ `||g==="\u2028"||g==="\u2029"?(i++,o=0):o++,g},b=g=>g===`
4
+ `||g==="\r"||g==="\u2028"||g==="\u2029",K=()=>{for(;;){let g=d();if(g===" "||g===" "||g==="\f"||g==="\v"||b(g))r();else if(g==="/"&&d(1)==="/")for(;l<u.length&&!b(d());)r();else if(g==="/"&&d(1)==="*")for(r(),r();;){if(l>=u.length&&A("Unterminated block comment"),d()==="*"&&d(1)==="/"){r(),r();break}r();}else break}},m=(g,C,L,k)=>{N.push({type:g,value:C,start:L,end:l,loc:{start:k,end:v()}}),q=g==="Punctuator"?ze.has(C):g==="Keyword"?Ve.has(C):g==="TemplateHead"||g==="TemplateMiddle";},y=g=>{for(r();l<u.length;){let C=d();if(C===g)return r(),u.slice(S,l);if(b(C)&&A("Unterminated string literal"),C==="\\"){r(),l>=u.length&&A("Unterminated string literal"),r();continue}r();}return A("Unterminated string literal")},P=()=>{if(d()==="0"&&(d(1)==="x"||d(1)==="X")){for(r(),r(),fe(d())||A("Invalid hexadecimal literal");fe(d());)r();return}if(d()==="0"&&(d(1)==="b"||d(1)==="B")){for(r(),r(),d()!=="0"&&d()!=="1"&&A("Invalid binary literal");d()==="0"||d()==="1";)r();return}if(d()==="0"&&(d(1)==="o"||d(1)==="O")){for(r(),r(),d()>="0"&&d()<="7"||A("Invalid octal literal");d()>="0"&&d()<="7";)r();return}for(;M(d());)r();if(d()===".")for(r();M(d());)r();if(d()==="e"||d()==="E")for(r(),(d()==="+"||d()==="-")&&r(),M(d())||A("Invalid exponent");M(d());)r();},c=()=>{let g=l;for(;l<u.length;){let C=d();if(C==="`"){let L=u.slice(g,l);return r(),{raw:L,interp:false}}if(C==="$"&&d(1)==="{"){let L=u.slice(g,l);return r(),r(),{raw:L,interp:true}}if(C==="\\"){if(r(),l>=u.length)break;r();continue}r();}return A("Unterminated template literal")},S=0,x=0,X=[],q=true,D="js",$=[],F=[];for(;;){if(D==="jsxChildren"){S=l;let k=v();if(l>=u.length){m("EOF","",S,k);break}let a=d();if(a==="<"){d(1)==="/"?(r(),r(),m("Punctuator","</",S,k),D="jsxCloseTag"):(r(),m("Punctuator","<",S,k),$.push("jsxChildren"),D="jsxOpenTag");continue}if(a==="{"){r(),m("Punctuator","{",S,k),F.push({level:x,restore:"jsxChildren"}),D="js";continue}for(;l<u.length&&d()!=="<"&&d()!=="{";)r();m("JSXText",u.slice(S,l),S,k);continue}if(D==="jsxOpenTag"||D==="jsxCloseTag"){K(),S=l;let k=v();if(l>=u.length){m("EOF","",S,k);break}let a=d();if(oe(a)){for(r();qe(d());)r();m("Identifier",u.slice(S,l),S,k);continue}if(a==="/"&&d(1)===">"){r(),r(),m("Punctuator","/>",S,k),D=$.pop()??"js";continue}if(a===">"){r(),m("Punctuator",">",S,k),D=D==="jsxCloseTag"?$.pop()??"js":"jsxChildren";continue}if(a==="{"){r(),m("Punctuator","{",S,k),F.push({level:x,restore:D}),D="js";continue}if(a==='"'||a==="'"){m("String",y(a),S,k);continue}if(a==="="||a==="."||a===":"){r(),m("Punctuator",a,S,k);continue}A(`Unexpected character '${a}' in JSX tag`);}K(),S=l;let g=v();if(l>=u.length){m("EOF","",S,g);break}let C=d();if(oe(C)){for(;ye(d());)r();let k=u.slice(S,l);m(de.has(k)?"Keyword":"Identifier",k,S,g);continue}if(M(C)||C==="."&&M(d(1))){P(),m("Number",u.slice(S,l),S,g);continue}if(C==='"'||C==="'"){let k=y(C);m("String",k,S,g);continue}if(C==="`"){r();let{raw:k,interp:a}=c();a?(m("TemplateHead",k,S,g),X.push(x)):m("Template",k,S,g);continue}if(C==="<"&&q){r(),m("Punctuator","<",S,g),$.push("js"),D="jsxOpenTag";continue}if(C==="{"){r(),m("Punctuator","{",S,g),x++;continue}if(C==="}"){if(X.length>0&&x===X[X.length-1]){X.pop(),r();let{raw:k,interp:a}=c();m(a?"TemplateMiddle":"TemplateTail",k,S,g),a&&X.push(x);continue}if(F.length>0&&x===F[F.length-1].level){let{restore:k}=F.pop();r(),m("Punctuator","}",S,g),D=k;continue}r(),m("Punctuator","}",S,g),x--;continue}if(C==="?"&&d(1)==="."&&M(d(2))){r(),m("Punctuator","?",S,g);continue}let L=Be.find(k=>u.startsWith(k,l));if(L){for(let k=0;k<L.length;k++)r();m("Punctuator",L,S,g);continue}A(`Unexpected character '${C}'`);}return N}var ae=(u=[])=>({vars:new Set(u),bounds:new Map,noCond:false,inferSink:null}),_=(u,N)=>{let l=new Set(u.vars),i=new Map(u.bounds);for(let o of N)l.add(o.name),o.bound||o.isConst?i.set(o.name,{bound:o.bound,isConst:o.isConst}):i.delete(o.name);return {vars:l,bounds:i,noCond:u.noCond,inferSink:u.inferSink}},We=(u,N)=>{let l=u.bounds.get(N);return l&&(l.bound||l.isConst)?{t:"var",name:N,...l.bound?{bound:l.bound}:{},...l.isConst?{isConst:true}:{}}:{t:"var",name:N}},me=u=>{let{peek:N,next:l,isP:i,isK:o,expectP:v,fail:d,unescape:A}=u,r=()=>{let a=u.pos(),p=u.tokens[a],f=u.tokens[a-1];return !!f&&!!p&&p.loc.start.line>f.loc.end.line},b=()=>{let a=0;for(let p=u.pos();p<u.tokens.length;p++){let f=u.tokens[p];if(f.type==="EOF")return false;if(f.type==="Punctuator"){if(["(","[","{","<"].includes(f.value))a++;else if([")","]","}",">"].includes(f.value)&&(a--,a===0)){let T=u.tokens[p+1];return !!T&&T.type==="Punctuator"&&T.value==="=>"}}}return false},K=()=>{let a=u.tokens,p=[],f=0,T=false;for(let E=u.pos();E<a.length;E++){let I=a[E];if(I.type==="EOF")break;if(I.type==="Punctuator"){if(I.value==="<")f++,f===1&&(T=true);else if(I.value===">"){if(f--,f===0)break}else I.value==="("||I.value==="["||I.value==="{"?(f++,T=false):I.value===")"||I.value==="]"||I.value==="}"?(f--,T=false):I.value===","&&f===1?T=true:T=false;continue}if(f===1&&T){if(I.type==="Keyword"&&I.value==="const")continue;if(I.type==="Identifier"){p.push(I.value),T=false;continue}}T=false;}return p},m=a=>{let p=_(a,K().map(T=>({name:T})));v("<");let f=[];for(;!i(">");){let T=o("const");T&&l();let E=N();E.type!=="Identifier"&&d("Expected type parameter name"),l();let I;o("extends")&&(l(),I=c(p)),i("=")&&(l(),c(p)),f.push({name:E.value,...I?{bound:I}:{},...T?{isConst:true}:{}}),i(">")||v(",");}return v(">"),f},y=a=>{v("<");let p=[];for(;!i(">");)p.push(c(a)),i(">")||v(",");return v(">"),p},P=a=>{let p=N();return p.type==="Identifier"&&p.value===a},c=a=>{let p=S(a);if(a.noCond||!o("extends")||r())return p;l();let f=[],T=S({...a,noCond:true,inferSink:f});v("?");let E=_(a,f.map(B=>({name:B}))),I=c(E);v(":");let z=c(E);return {t:"conditional",check:p,extends:T,then:I,else:z,...f.length?{infer:f}:{}}},S=a=>{i("|")&&l();let p=x(a);if(!i("|"))return p;let f=[p];for(;i("|");)l(),f.push(x(a));return {t:"union",of:f}},x=a=>{i("&")&&l();let p=X(a);if(!i("&"))return p;let f=[p];for(;i("&");)l(),f.push(X(a));return {t:"intersection",of:f}},X=a=>{if(P("keyof"))return l(),{t:"keyof",of:X(a)};if(P("infer")){l();let p=N();p.type!=="Identifier"&&d("Expected 'infer' variable name"),l();let f=a.inferSink;return f?(f.push(p.value),{t:"var",name:p.value}):d("'infer' is only allowed in the 'extends' clause of a conditional")}return q(a)},q=a=>{let p=D(a);for(;i("[")&&!r();)if(l(),i("]"))l(),p={t:"array",items:p};else {let f=c(a);v("]"),p={t:"index",obj:p,key:f};}return p},D=a=>{if(i("<")){let f=m(a),T=_(a,f);return F(T)}if(i("(")){if(b())return F(a);l();let f=c(a.noCond?{...a,noCond:false}:a);return v(")"),f}if(i("{"))return C()?L(a):k(a);if(i("["))return g(a);let p=N();if(p.type==="String")return l(),{t:"literal",value:A(p.value.slice(1,-1))};if(p.type==="Number")return l(),{t:"literal",value:Number(p.value)};if(o("true"))return l(),{t:"literal",value:true};if(o("false"))return l(),{t:"literal",value:false};if(o("null"))return l(),{t:"null"};if(o("void"))return l(),{t:"void"};if(p.type==="Identifier"){switch(l(),p.value){case "string":return {t:"string"};case "number":return {t:"number"};case "boolean":return {t:"boolean"};case "any":return {t:"any"};case "unknown":return {t:"unknown"};case "undefined":return {t:"undefined"};case "never":return {t:"union",of:[]}}let f=i("<")?y(a):[];return a.vars.has(p.value)&&f.length===0?We(a,p.value):p.value==="ReturnType"&&f.length===1?{t:"returnType",fn:f[0]}:p.value==="Parameters"&&f.length===1?{t:"parameters",fn:f[0]}:{t:"apply",name:p.value,args:f}}return d(`Expected a type but got '${p.value||p.type}'`)},$=a=>{v("(");let p=[];for(;!i(")");){let f=N();f.type!=="Identifier"&&d("Expected parameter name in function type"),l();let T=i("?");T&&l(),v(":");let E=c(a);p.push({name:f.value,type:E,...T?{optional:true}:{}}),i(")")||v(",");}return v(")"),p},F=a=>{let p=$(a);v("=>");let f=c(a);return {t:"fn",params:p,returns:f}},g=a=>{v("[");let p=[],f=[];for(;!i("]");){if(i("...")){l();let T=c(a);T.t==="array"?(p.push(T.items),f.push("rest")):(p.push(T),f.push("variadic"));}else {let T=c(a),E=i("?");E&&l(),p.push(T),f.push(E?"optional":"req");}i("]")||v(",");}return v("]"),f.some(T=>T!=="req")?{t:"tuple",elements:p,flags:f}:{t:"tuple",elements:p}},C=()=>{let a=u.tokens,p=u.pos()+1;return a[p]?.type==="Punctuator"&&(a[p]?.value==="+"||a[p]?.value==="-")&&p++,a[p]?.type==="Identifier"&&a[p]?.value==="readonly"&&p++,a[p]?.type==="Punctuator"&&a[p]?.value==="["&&a[p+1]?.type==="Identifier"&&a[p+2]?.type==="Keyword"&&a[p+2]?.value==="in"},L=a=>{v("{"),(i("+")||i("-"))&&l(),P("readonly")&&l(),v("[");let p=N();p.type!=="Identifier"&&d("Expected mapped type key name"),l(),o("in")||d("Expected 'in' in mapped type"),l();let f=c(a);P("as")&&d("Key remapping ('as') in mapped types is not supported"),v("]");let T=false,E=i("+")||i("-")?l().value:null;i("?")&&(l(),T=E!=="-"),v(":");let I=c(_(a,[{name:p.value}]));return (i(";")||i(","))&&l(),v("}"),{t:"mapped",key:p.value,over:f,body:I,optional:T}},k=a=>{v("{");let p={},f,T=[];for(;!i("}");){if(i("(")){let E=$(a);v(":");let I=c(a);T.push({t:"fn",params:E,returns:I});}else if(i("[")){l(),N().type!=="Identifier"&&d("Expected index signature parameter name"),l(),v(":");let E=N();(E.type!=="Identifier"||E.value!=="string"&&E.value!=="number")&&d("Index signature parameter type must be 'string' or 'number'"),l(),v("]"),v(":"),f={key:E.value,value:c(a)};}else {let E=N(),I;if(E.type==="Identifier"||E.type==="Keyword")l(),I=E.value;else if(E.type==="String")l(),I=A(E.value.slice(1,-1));else if(E.type==="Number")l(),I=E.value;else return d("Expected property name in object type");let z=i("?");z&&l(),v(":");let B=c(a);p[I]={type:B,...z?{optional:true}:{}};}if(i(";")||i(","))l();else break}return v("}"),T.length>0?Object.keys(p).length>0||f?d("Callable object types (call signatures mixed with members) are not supported"):T.length===1?T[0]:{t:"overload",signatures:T}:{t:"object",props:p,...f?{index:f}:{}}};return {parseType:a=>c(ae(a)),parseTypeParamList:()=>m(ae()),parseTypeInScope:a=>c(_(ae(),a))}};var ee=class extends TSLiteError{constructor(l,i,o){super("parse-error",`${l} (${i.line}:${i.column})`,{position:i,index:o});this.position=i;this.index=o;this.name="ParseError";}},Ge={"??":1,"||":2,"&&":3,"|":4,"^":5,"&":6,"==":7,"===":7,"!=":7,"!==":7,"<":8,"<=":8,">":8,">=":8,in:8,as:8,"<<":9,">>":9,">>>":9,"+":10,"-":10,"*":11,"/":11,"%":11,"**":12},He=new Set(["??","||","&&"]),Ye=new Set(["class","debugger","with"]),Ze=new Set(["=","+=","-=","*=","/=","%="]);function he(u){let N=se(u),l=0,i=(e=0)=>N[Math.min(l+e,N.length-1)],o=()=>N[l++],v=()=>N[l-1],d=()=>{let e=N[l],t=N[l-1];return !!e&&!!t&&e.loc.start.line>t.loc.end.line},A=()=>i().type==="EOF",r=e=>i().type==="Punctuator"&&i().value===e,b=e=>i().type==="Keyword"&&i().value===e,K=e=>i().type==="Identifier"&&i().value===e,m=(e,t=i())=>{throw new ee(e,t.loc.start,t.start)},y=e=>(r(e)||m(`Expected '${e}' but got '${i().value||i().type}'`),o()),P=(e,t)=>{let n=v()??t;return Object.assign(e,{start:t.start,end:n.end,loc:{start:t.loc.start,end:n.loc.end}})},c=(e,t,n)=>Object.assign(e,{start:t.start,end:n.end,loc:{start:t.loc.start,end:n.loc.end}}),S=e=>{let t="";for(let n=0;n<e.length;n++){if(e[n]!=="\\"){t+=e[n];continue}let s=e[++n];switch(s){case "n":t+=`
5
+ `;break;case "t":t+=" ";break;case "r":t+="\r";break;case "b":t+="\b";break;case "f":t+="\f";break;case "v":t+="\v";break;case "0":t+="\0";break;case "x":t+=String.fromCharCode(parseInt(e.slice(n+1,n+3),16)),n+=2;break;case "u":if(e[n+1]==="{"){let h=e.indexOf("}",n);t+=String.fromCodePoint(parseInt(e.slice(n+2,h),16)),n=h;}else t+=String.fromCharCode(parseInt(e.slice(n+1,n+5),16)),n+=4;break;default:t+=s;}}return t},x=(e=false)=>X(e),X=(e=false)=>{let t=q(e),n=i();if(n.type==="Punctuator"&&Ze.has(n.value)){o();let s=X();return c({type:"AssignmentExpression",operator:n.value,left:t,right:s},t,s)}return t},q=(e=false)=>{let t=$(0,e);if(!r("?"))return t;o();let n=x();y(":");let s=x();return c({type:"ConditionalExpression",test:t,consequent:n,alternate:s},t,s)},D=()=>{let e=i();if(e.type==="Keyword")return e.value==="in"?{op:"in",consume:1}:null;if(e.type==="Identifier")return e.value==="as"?{op:"as",consume:1}:null;if(e.type!=="Punctuator")return null;if(e.value===">"){let t=i(1);if(t.type==="Punctuator"&&t.value===">"&&e.end===t.start){let n=i(2);return n.type==="Punctuator"&&n.value===">"&&t.end===n.start?{op:">>>",consume:3}:{op:">>",consume:2}}return {op:">",consume:1}}return {op:e.value,consume:1}},$=(e,t=false)=>{let n=F();for(;;){let s=D();if(!s)break;let{op:h,consume:w}=s;if(h==="in"&&t)break;let j=Ge[h];if(!j||j<=e)break;if(h==="as"){if(d())break;o();let J=H(new Set);n=c({type:"TSAsExpression",expression:n,typeAnnotation:J},n,v());continue}for(let J=0;J<w;J++)o();let O=$(h==="**"?j-1:j,t);n=c({type:He.has(h)?"LogicalExpression":"BinaryExpression",operator:h,left:n,right:O},n,O);}return n},F=()=>{let e=i();return e.type==="Punctuator"&&(e.value==="++"||e.value==="--")?(o(),P({type:"UpdateExpression",operator:e.value,prefix:true,argument:F()},e)):b("await")?(o(),P({type:"AwaitExpression",argument:F()},e)):b("typeof")||b("void")||b("delete")||e.type==="Punctuator"&&(e.value==="!"||e.value==="-"||e.value==="+"||e.value==="~")?g(e):C()},g=e=>{o();let t=F();return r("**")&&m(`An unary expression with the '${e.value}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.`),P({type:"UnaryExpression",operator:e.value,prefix:true,argument:t},e)},C=()=>{let e=Te(),t=false;for(;;)if(r("?."))if(o(),t=true,r("(")){let{args:n,close:s}=L();e=c({type:"CallExpression",callee:e,arguments:n,optional:true},e,s);}else if(r("[")){o();let n=x(),s=y("]");e=c({type:"MemberExpression",object:e,property:n,computed:true,optional:true},e,s);}else {let n=i();n.type!=="Identifier"&&n.type!=="Keyword"&&m("Expected property name after '?.'"),o();let s=P({type:"Identifier",name:n.value},n);e=c({type:"MemberExpression",object:e,property:s,computed:false,optional:true},e,s);}else if(r(".")){o();let n=i();n.type!=="Identifier"&&n.type!=="Keyword"&&m("Expected property name"),o();let s=P({type:"Identifier",name:n.value},n);e=c({type:"MemberExpression",object:e,property:s,computed:false,optional:false},e,s);}else if(r("[")){o();let n=x(),s=y("]");e=c({type:"MemberExpression",object:e,property:n,computed:true,optional:false},e,s);}else if(r("(")){let{args:n,close:s}=L();e=c({type:"CallExpression",callee:e,arguments:n,optional:false},e,s);}else if(r("++")||r("--")){let n=o();e=c({type:"UpdateExpression",operator:n.value,prefix:false,argument:e},e,n);}else break;return t?c({type:"ChainExpression",expression:e},e,e):e},L=()=>{y("(");let e=[];for(;!r(")");)e.push(k()),r(")")||y(",");return {args:e,close:y(")")}},k=()=>{if(r("...")){let e=o(),t=x();return c({type:"SpreadElement",argument:t},e,t)}return x()},a=()=>{let e=i();return e.type!=="Identifier"&&m("Expected identifier"),o(),P({type:"Identifier",name:e.value},e)},p=e=>{let t=r("{")?f(e):r("[")?T(e):a();return r(":")&&(o(),t.typeAnnotation=H(e)),t},f=e=>{let t=y("{"),n=[];for(;!r("}");){if(r("...")){let h=o(),w=p(e);n.push(c({type:"RestElement",argument:w},h,w));}else {let h=a(),w,j=false;if(r(":")?(o(),w=p(e)):(w={...h},j=true),r("=")){o();let O=x();w=c({type:"AssignmentPattern",left:w,right:O},w,O);}n.push(c({type:"Property",key:h,value:w,kind:"init",shorthand:j,computed:false,method:false},h,w));}r("}")||y(",");}let s=y("}");return c({type:"ObjectPattern",properties:n},t,s)},T=e=>{let t=y("["),n=[];for(;!r("]");){if(r(",")){n.push(null),o();continue}if(r("...")){let h=o(),w=p(e);n.push(c({type:"RestElement",argument:w},h,w));}else {let h=p(e);if(r("=")){o();let w=x();h=c({type:"AssignmentPattern",left:h,right:w},h,w);}n.push(h);}r("]")||y(",");}let s=y("]");return c({type:"ArrayPattern",elements:n},t,s)},E=()=>{let e=0;for(let t=l;t<N.length;t++){let n=N[t];if(n.type==="EOF")return false;if(n.type==="Punctuator"){if(n.value==="("||n.value==="["||n.value==="{")e++;else if((n.value===")"||n.value==="]"||n.value==="}")&&(e--,e===0)){let s=N[t+1];return !s||s.type!=="Punctuator"?false:s.value==="=>"?true:s.value===":"?I(t+2):false}}}return false},I=e=>{let t=0;for(let n=e;n<N.length;n++){let s=N[n];if(s.type==="EOF")return false;if(s.type==="Punctuator")if(["(","[","{","<"].includes(s.value))t++;else if([")","]","}",">"].includes(s.value)){if(t===0)return false;t--;}else {if(t===0&&s.value==="=>")return true;if(t===0&&(s.value===";"||s.value===","))return false}}return false},z=(e=new Set)=>{y("(");let t=[];for(;!r(")");){if(r("...")){let n=o(),s=p(e);t.push(c({type:"RestElement",argument:s},n,s));}else {let n=p(e);if(r("=")){o();let s=x();n=c({type:"AssignmentPattern",left:n,right:s},n,s);}t.push(n);}r(")")||y(",");}return y(")"),t},B=(e,t)=>{let n=r("(")?z():[a()],s;r(":")&&(o(),s=H(new Set)),y("=>");let h=r("{")?W():x();return P({type:"ArrowFunctionExpression",params:n,body:h,async:e,expression:h.type!=="BlockStatement",generator:false,...s?{returnType:s}:{}},t)},ge=()=>{let e=y("["),t=[];for(;!r("]");){if(r(",")){o(),t.push(null);continue}t.push(k()),r("]")||y(",");}return c({type:"ArrayExpression",elements:t},e,y("]"))},ve=()=>{let e=y("{"),t=[];for(;!r("}");){if(r("...")){let n=o(),s=x();t.push(c({type:"SpreadElement",argument:s},n,s));}else {let n=i(),s,h=false;if(r("["))h=true,o(),s=x(),y("]");else if(n.type==="String")o(),s=P({type:"Literal",value:S(n.value.slice(1,-1)),raw:n.value},n);else if(n.type==="Number")o(),s=P({type:"Literal",value:Number(n.value),raw:n.value},n);else if(n.type==="Identifier"||n.type==="Keyword")o(),s=P({type:"Identifier",name:n.value},n);else return m("Invalid property key");if(r(":")){o();let w=x();t.push(c({type:"Property",key:s,value:w,kind:"init",method:false,shorthand:false,computed:h},n,w));}else t.push(c({type:"Property",key:s,value:s,kind:"init",method:false,shorthand:true,computed:false},n,s));}r("}")||y(",");}return c({type:"ObjectExpression",properties:t},e,y("}"))},G=(e,t)=>({type:"TemplateElement",value:{raw:e,cooked:S(e)},tail:t}),be=e=>{o();let t=[G(e.value,false)],n=[];for(;;){n.push(x());let s=i();if(s.type==="TemplateMiddle")o(),t.push(G(s.value,false));else if(s.type==="TemplateTail"){o(),t.push(G(s.value,true));break}else m("Expected `}` to close template interpolation");}return P({type:"TemplateLiteral",quasis:t,expressions:n},e)},V=()=>{let e=i();return e.type!=="Identifier"&&m(`Expected JSX identifier but got '${e.value||e.type}'`),P({type:"JSXIdentifier",name:o().value},e)},ie=()=>{let e=V();if(r(":")){o();let t=V();return c({type:"JSXNamespacedName",namespace:e,name:t},e,t)}for(;r(".");){o();let t=V();e=c({type:"JSXMemberExpression",object:e,property:t},e,t);}return e},U=e=>e.type==="JSXIdentifier"?e.name:e.type==="JSXNamespacedName"?`${U(e.namespace)}:${U(e.name)}`:`${U(e.object)}.${U(e.property)}`,Se=()=>{let e=i();if(e.type==="String")return o(),P({type:"Literal",value:S(e.value.slice(1,-1)),raw:e.value},e);if(r("{")){let t=o(),n=X(),s=y("}");return c({type:"JSXExpressionContainer",expression:n},t,s)}return r("<")?te():m(`Invalid JSX attribute value '${e.value||e.type}'`)},xe=()=>{let e=[];for(;!r(">")&&!r("/>")&&!A();){if(r("{")){let s=o();y("...");let h=X(),w=y("}");e.push(c({type:"JSXSpreadAttribute",argument:h},s,w));continue}let t=V();if(r(":")){o();let s=V();t=c({type:"JSXNamespacedName",namespace:t,name:s},t,s);}let n=null;r("=")&&(o(),n=Se()),e.push(c({type:"JSXAttribute",name:t,value:n},t,n??t));}return e},le=()=>{let e=[];for(;!(r("</")||A());){let t=i();if(t.type==="JSXText")o(),e.push(P({type:"JSXText",value:t.value,raw:t.value},t));else if(r("{")){let n=o();if(r("}")){let s=o(),h=P({type:"JSXEmptyExpression"},n);e.push(c({type:"JSXExpressionContainer",expression:h},n,s));}else {let s=X(),h=y("}");e.push(c({type:"JSXExpressionContainer",expression:s},n,h));}}else r("<")?e.push(te()):m(`Unexpected token in JSX children '${t.value||t.type}'`);}return e},te=()=>{let e=y("<");if(r(">")){let Z=o(),re=c({type:"JSXOpeningFragment"},e,Z),Ke=le(),Re=y("</"),ue=y(">"),Ue=c({type:"JSXClosingFragment"},Re,ue);return c({type:"JSXFragment",openingFragment:re,children:Ke,closingFragment:Ue},e,ue)}let t=ie(),n=xe();if(r("/>")){let Z=o(),re=c({type:"JSXOpeningElement",name:t,attributes:n,selfClosing:true},e,Z);return c({type:"JSXElement",openingElement:re,children:[],closingElement:null},e,Z)}let s=y(">"),h=c({type:"JSXOpeningElement",name:t,attributes:n,selfClosing:false},e,s),w=le(),j=y("</"),O=i(),J=ie();U(J)!==U(t)&&m(`JSX closing tag </${U(J)}> does not match opening <${U(t)}>`,O);let Y=y(">"),$e=c({type:"JSXClosingElement",name:J},j,Y);return c({type:"JSXElement",openingElement:h,children:w,closingElement:$e},e,Y)},Te=()=>{let e=i();if(b("async")){let t=i(1);return t.value==="("||t.type==="Identifier"?(o(),B(true,e)):m("Unexpected 'async'")}if(r("(")&&E()||e.type==="Identifier"&&i(1).type==="Punctuator"&&i(1).value==="=>")return B(false,e);if(e.type==="Number")return o(),P({type:"Literal",value:Number(e.value),raw:e.value},e);if(e.type==="String")return o(),P({type:"Literal",value:S(e.value.slice(1,-1)),raw:e.value},e);if(e.type==="Template")return o(),P({type:"TemplateLiteral",expressions:[],quasis:[G(e.value,true)]},e);if(e.type==="TemplateHead")return be(e);if(e.type==="Keyword")return e.value==="true"?(o(),P({type:"Literal",value:true,raw:"true"},e)):e.value==="false"?(o(),P({type:"Literal",value:false,raw:"false"},e)):e.value==="null"?(o(),P({type:"Literal",value:null,raw:"null"},e)):e.value==="new"?m("'new' is not supported \u2014 the language has no constructors (FP / portable IR). Use a factory function provided via DI (e.g. `now()` instead of `new Date()`)."):e.value==="function"?m("Anonymous functions are not supported \u2014 use an arrow function"):m(`'${e.value}' is not supported in this language`);if(e.type==="Identifier")return o(),P({type:"Identifier",name:e.value},e);if(r("(")){o();let t=x();return y(")"),t}return r("[")?ge():r("{")?ve():r("<")?te():m(`Unexpected token '${e.value||e.type}'`)},{parseType:H,parseTypeParamList:ke,parseTypeInScope:we}=me({tokens:N,pos:()=>l,peek:i,next:o,isP:r,isK:b,expectP:y,fail:m,unescape:S}),Ne=()=>{let e=o(),t=a(),n=[],s=[];r("<")&&(s=ke(),n=s.map(j=>j.name)),y("=");let h=we(s),w=c({type:"TSTypeAliasDeclaration",id:t,typeParameters:n,typeAnnotation:h},e,v());return r(";")&&o(),w},R=()=>{let e=i();if(e.type==="Identifier"&&e.value==="type"&&i(1).type==="Identifier"&&i(2).type==="Punctuator"&&(i(2).value==="="||i(2).value==="<"))return Ne();if(b("const")||b("let")||b("var")){let s=pe();return r(";")&&o(),s}if(b("if"))return Je();if(b("for"))return Ce();if(b("while"))return Oe();if(b("do"))return je();if(b("break")||b("continue"))return Ae();if(b("return"))return De();if(b("throw"))return Xe();if(b("try"))return Fe();if(b("switch"))return Le();if(b("import"))return Ee();if(b("export"))return Ie();if(r("{"))return W();if((b("function")||b("async")&&i(1).type==="Keyword"&&i(1).value==="function")&&m("Function declarations are not supported \u2014 use 'const fn = () => \u2026'"),r(";"))return o(),P({type:"EmptyStatement"},e);e.type==="Keyword"&&Ye.has(e.value)&&m(`'${e.value}' is not supported in this language`);let t=x(),n=r(";")?o():v();return c({type:"ExpressionStatement",expression:t},t,n)},pe=()=>{let e=o(),t=e.value,n=p(new Set),s=null;r("=")?(o(),s=x()):t==="const"&&m("'const' declarations must be initialized");let h=c({type:"VariableDeclarator",id:n,init:s},n,s??n);return c({type:"VariableDeclaration",kind:t,declarations:[h]},e,s??n)},Pe=()=>{let e=i();return e.type!=="String"&&m("Expected module specifier string"),o(),P({type:"Literal",value:S(e.value.slice(1,-1)),raw:e.value},e)},Ee=()=>{let e=o(),t=[];if(i().type!=="String"){if(i().type==="Identifier"){let s=a();t.push(c({type:"ImportDefaultSpecifier",local:s},s,s)),r(",")&&o();}if(r("*")){let s=o();K("as")||m("Expected 'as' after '*' in import"),o();let h=a();t.push(c({type:"ImportNamespaceSpecifier",local:h},s,h));}else if(r("{")){for(o();!r("}")&&!A();){let s=a(),h=s;if(K("as")&&(o(),h=a()),t.push(c({type:"ImportSpecifier",imported:s,local:h},s,h)),r(","))o();else break}y("}");}K("from")||m("Expected 'from' in import declaration"),o();}let n=Pe();return r(";")&&o(),P({type:"ImportDeclaration",specifiers:t,source:n},e)},Ie=()=>{let e=o();if(b("default")){o();let t=x();return r(";")&&o(),P({type:"ExportDefaultDeclaration",declaration:t},e)}if(b("const")||b("let")||b("var")){let t=pe();return r(";")&&o(),P({type:"ExportNamedDeclaration",declaration:t,specifiers:[],source:null},e)}if(r("{")){o();let t=[];for(;!r("}")&&!A();){let n=a(),s=n;if(K("as")&&(o(),s=a()),t.push(c({type:"ExportSpecifier",local:n,exported:s},n,s)),r(","))o();else break}return y("}"),r(";")&&o(),P({type:"ExportNamedDeclaration",declaration:null,specifiers:t,source:null},e)}return m("Expected 'const', '{', or 'default' after 'export'")},ce=()=>i().type==="Identifier"&&i().value==="of",ne=()=>b("in"),Ce=()=>{let e=o();y("(");let t=null,n=null;if(!r(";"))if(b("const")||b("let")||b("var")){let j=o(),O=a();if(r(":")&&(o(),O.typeAnnotation=H(new Set)),ce()||ne()){let J=c({type:"VariableDeclarator",id:O,init:null},O,O);n=c({type:"VariableDeclaration",kind:j.value,declarations:[J]},j,O);}else {let J=null;r("=")?(o(),J=x(true)):j.value==="const"&&m("'const' declarations must be initialized");let Y=c({type:"VariableDeclarator",id:O,init:J},O,J??O);t=c({type:"VariableDeclaration",kind:j.value,declarations:[Y]},j,J??O);}}else {let j=x(true);ce()||ne()?n=j:t=j;}if(n){let j=ne();o();let O=x();y(")");let J=R();return c(j?{type:"ForInStatement",left:n,right:O,body:J}:{type:"ForOfStatement",left:n,right:O,body:J,await:false},e,J)}y(";");let s=r(";")?null:x();y(";");let h=r(")")?null:x();y(")");let w=R();return c({type:"ForStatement",init:t,test:s,update:h,body:w},e,w)},je=()=>{let e=o(),t=R();b("while")||m("Expected 'while' after the 'do' body"),o(),y("(");let n=x(),s=y(")");return r(";")&&o(),c({type:"DoWhileStatement",body:t,test:n},e,s)},Ae=()=>{let e=o(),t=e.value==="break"?"BreakStatement":"ContinueStatement",n=r(";")?o():v();return c({type:t,label:null},e,n)},Oe=()=>{let e=o();y("(");let t=x();y(")");let n=R();return c({type:"WhileStatement",test:t,body:n},e,n)},Je=()=>{let e=o();y("(");let t=x();y(")");let n=R(),s=null;return b("else")&&(o(),s=R()),c({type:"IfStatement",test:t,consequent:n,alternate:s},e,s??n)},De=()=>{let e=o(),t=null;!r(";")&&!r("}")&&!A()&&(t=x());let n=r(";")?o():v();return c({type:"ReturnStatement",argument:t},e,n)},Xe=()=>{let e=o(),t=x(),n=r(";")?o():v();return c({type:"ThrowStatement",argument:t},e,n)},Fe=()=>{let e=o(),t=W(),n=null,s=null;if(b("catch")){let h=o(),w=null;r("(")&&(o(),w=a(),y(")"));let j=W();n=c({type:"CatchClause",param:w,body:j},h,j);}return b("finally")&&(o(),s=W()),!n&&!s&&m("'try' requires a 'catch' or 'finally' clause"),c({type:"TryStatement",block:t,handler:n,finalizer:s},e,s??n??t)},Le=()=>{let e=o();y("(");let t=x();y(")"),y("{");let n=[];for(;!r("}")&&!A();){let h=i(),w=null;b("case")?(o(),w=x()):b("default")?o():m("Expected 'case' or 'default' in switch"),y(":");let j=[];for(;!r("}")&&!b("case")&&!b("default")&&!A();)j.push(R());n.push(c({type:"SwitchCase",test:w,consequent:j},h,v()??h));}let s=y("}");return c({type:"SwitchStatement",discriminant:t,cases:n},e,s)},W=()=>{let e=y("{"),t=[];for(;!r("}")&&!A();)t.push(R());return c({type:"BlockStatement",body:t},e,y("}"))};return {parseExpr:x,parseProgram:()=>{let e=i(),t=[];for(;!A();)t.push(R());return c({type:"Program",sourceType:"module",body:t},e,v()??e)},eof:A,fail:m}}function Qe(u){return he(u).parseProgram()}function et(u){let{parseExpr:N,eof:l,fail:i}=he(u),o=N();return l()||i("Unexpected token after expression"),o}export{de as KEYWORDS,Q as LexError,ee as ParseError,Qe as parse,et as parseExpression,se as tokenize};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tslite/parser",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "TSLite parser — tokenizer + Pratt parser for the TSLite language (JS subset + pipe) into ESTree",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -40,13 +40,13 @@
40
40
  "access": "public"
41
41
  },
42
42
  "dependencies": {
43
- "@tslite/core": "0.1.0"
43
+ "@tslite/core": "0.2.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@tslite/checker": "0.1.0",
47
- "@tslite/capability": "0.1.0",
48
- "@tslite/printer": "0.1.0",
49
- "@tslite/interpret": "0.1.0"
46
+ "@tslite/checker": "0.2.1",
47
+ "@tslite/printer": "0.2.0",
48
+ "@tslite/interpret": "0.2.0",
49
+ "@tslite/capability": "0.2.0"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsup",